From 2ea0364b6e3f10977f7b607d239c29ee616a8f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Sj=C3=B6len?= Date: Fri, 22 Nov 2024 08:55:27 +0000 Subject: [PATCH] 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 --- src/hotspot/share/nmt/memoryFileTracker.cpp | 14 +++++--------- src/hotspot/share/nmt/memoryFileTracker.hpp | 17 +++++++++++++++++ src/hotspot/share/nmt/nmtUsage.cpp | 11 +++++++++++ src/hotspot/share/nmt/nmtUsage.hpp | 1 + test/jdk/ProblemList-zgc.txt | 2 -- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/hotspot/share/nmt/memoryFileTracker.cpp b/src/hotspot/share/nmt/memoryFileTracker.cpp index ede483ed337..0777d5aafc3 100644 --- a/src/hotspot/share/nmt/memoryFileTracker.cpp +++ b/src/hotspot/share/nmt/memoryFileTracker.cpp @@ -179,15 +179,11 @@ const GrowableArrayCHeap& 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) { diff --git a/src/hotspot/share/nmt/memoryFileTracker.hpp b/src/hotspot/share/nmt/memoryFileTracker.hpp index 42902701a16..94f9cb2006c 100644 --- a/src/hotspot/share/nmt/memoryFileTracker.hpp +++ b/src/hotspot/share/nmt/memoryFileTracker.hpp @@ -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 + 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 + 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); diff --git a/src/hotspot/share/nmt/nmtUsage.cpp b/src/hotspot/share/nmt/nmtUsage.cpp index a854f001593..aa1d681b8a5 100644 --- a/src/hotspot/share/nmt/nmtUsage.cpp +++ b/src/hotspot/share/nmt/nmtUsage.cpp @@ -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() { diff --git a/src/hotspot/share/nmt/nmtUsage.hpp b/src/hotspot/share/nmt/nmtUsage.hpp index 390d207250c..2011e7ed240 100644 --- a/src/hotspot/share/nmt/nmtUsage.hpp +++ b/src/hotspot/share/nmt/nmtUsage.hpp @@ -26,6 +26,7 @@ #define SHARE_NMT_NMTUSAGE_HPP #include "memory/allocation.hpp" +#include "nmt/memTag.hpp" #include "utilities/globalDefinitions.hpp" struct NMTUsagePair { diff --git a/test/jdk/ProblemList-zgc.txt b/test/jdk/ProblemList-zgc.txt index cab33229a5b..e81ac813747 100644 --- a/test/jdk/ProblemList-zgc.txt +++ b/test/jdk/ProblemList-zgc.txt @@ -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