8343893: Test jdk/jfr/event/runtime/TestNativeMemoryUsageEvents.java failed: heap should have grown and NMT should show that: expected 0 > 0

Reviewed-by: gziemski, mgronlun, lmesnik
This commit is contained in:
Johan Sjölen 2024-11-22 08:55:27 +00:00
parent 50c099d69e
commit 2ea0364b6e
5 changed files with 34 additions and 11 deletions

View File

@ -179,15 +179,11 @@ const GrowableArrayCHeap<MemoryFileTracker::MemoryFile*, mtNMT>& MemoryFileTrack
};
void MemoryFileTracker::summary_snapshot(VirtualMemorySnapshot* snapshot) const {
for (int d = 0; d < _files.length(); d++) {
const MemoryFile* file = _files.at(d);
for (int i = 0; i < mt_number_of_tags; i++) {
VirtualMemory* snap = snapshot->by_type(NMTUtil::index_to_tag(i));
const VirtualMemory* current = file->_summary.by_type(NMTUtil::index_to_tag(i));
// Only account the committed memory.
snap->commit_memory(current->committed());
}
}
iterate_summary([&](MemTag tag, const VirtualMemory* current) {
VirtualMemory* snap = snapshot->by_type(tag);
// Only account the committed memory.
snap->commit_memory(current->committed());
});
}
void MemoryFileTracker::Instance::summary_snapshot(VirtualMemorySnapshot* snapshot) {

View File

@ -39,6 +39,8 @@
// The MemoryFileTracker tracks memory of 'memory files',
// storage with its own memory space separate from the process.
// A typical example of such a file is a memory mapped file.
// All memory is accounted as committed, there is no reserved memory.
// Any reserved memory is expected to exist in the VirtualMemoryTracker.
class MemoryFileTracker {
friend class NMTMemoryFileTrackerTest;
@ -72,6 +74,16 @@ public:
MemoryFile* make_file(const char* descriptive_name);
void free_file(MemoryFile* file);
template<typename F>
void iterate_summary(F f) const {
for (int d = 0; d < _files.length(); d++) {
const MemoryFile* file = _files.at(d);
for (int i = 0; i < mt_number_of_tags; i++) {
f(NMTUtil::index_to_tag(i), file->_summary.by_type(NMTUtil::index_to_tag(i)));
}
}
}
void summary_snapshot(VirtualMemorySnapshot* snapshot) const;
// Print detailed report of file
@ -99,6 +111,11 @@ public:
const NativeCallStack& stack, MemTag mem_tag);
static void free_memory(MemoryFile* device, size_t offset, size_t size);
template<typename F>
static void iterate_summary(F f) {
_tracker->iterate_summary(f);
};
static void summary_snapshot(VirtualMemorySnapshot* snapshot);
static void print_report_on(const MemoryFile* device, outputStream* stream, size_t scale);

View File

@ -24,6 +24,7 @@
#include "precompiled.hpp"
#include "nmt/mallocTracker.hpp"
#include "nmt/memoryFileTracker.hpp"
#include "nmt/nmtCommon.hpp"
#include "nmt/nmtUsage.hpp"
#include "nmt/threadStackTracker.hpp"
@ -90,6 +91,16 @@ void NMTUsage::update_vm_usage() {
_vm_total.reserved += vm->reserved();
_vm_total.committed += vm->committed();
}
{ // MemoryFileTracker addition
using MFT = MemoryFileTracker::Instance;
MFT::Locker lock;
MFT::iterate_summary([&](MemTag tag, const VirtualMemory* vm) {
int i = NMTUtil::tag_to_index(tag);
_vm_by_type[i].committed += vm->committed();
_vm_total.committed += vm->committed();
});
}
}
void NMTUsage::refresh() {

View File

@ -26,6 +26,7 @@
#define SHARE_NMT_NMTUSAGE_HPP
#include "memory/allocation.hpp"
#include "nmt/memTag.hpp"
#include "utilities/globalDefinitions.hpp"
struct NMTUsagePair {

View File

@ -38,5 +38,3 @@ sun/tools/jhsdb/heapconfig/JMapHeapConfigTest.java 8307393 generic-all
sun/tools/jhsdb/HeapDumpTestWithActiveProcess.java 8307393 generic-all
com/sun/jdi/ThreadMemoryLeakTest.java 8307402 generic-all
jdk/jfr/event/runtime/TestNativeMemoryUsageEvents.java 8343893 generic-all