Skip to content

Commit 2ea0364

Browse files
committed
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
1 parent 50c099d commit 2ea0364

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

src/hotspot/share/nmt/memoryFileTracker.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,11 @@ const GrowableArrayCHeap<MemoryFileTracker::MemoryFile*, mtNMT>& MemoryFileTrack
179179
};
180180

181181
void MemoryFileTracker::summary_snapshot(VirtualMemorySnapshot* snapshot) const {
182-
for (int d = 0; d < _files.length(); d++) {
183-
const MemoryFile* file = _files.at(d);
184-
for (int i = 0; i < mt_number_of_tags; i++) {
185-
VirtualMemory* snap = snapshot->by_type(NMTUtil::index_to_tag(i));
186-
const VirtualMemory* current = file->_summary.by_type(NMTUtil::index_to_tag(i));
187-
// Only account the committed memory.
188-
snap->commit_memory(current->committed());
189-
}
190-
}
182+
iterate_summary([&](MemTag tag, const VirtualMemory* current) {
183+
VirtualMemory* snap = snapshot->by_type(tag);
184+
// Only account the committed memory.
185+
snap->commit_memory(current->committed());
186+
});
191187
}
192188

193189
void MemoryFileTracker::Instance::summary_snapshot(VirtualMemorySnapshot* snapshot) {

src/hotspot/share/nmt/memoryFileTracker.hpp

+17
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
// The MemoryFileTracker tracks memory of 'memory files',
4040
// storage with its own memory space separate from the process.
4141
// A typical example of such a file is a memory mapped file.
42+
// All memory is accounted as committed, there is no reserved memory.
43+
// Any reserved memory is expected to exist in the VirtualMemoryTracker.
4244
class MemoryFileTracker {
4345
friend class NMTMemoryFileTrackerTest;
4446

@@ -72,6 +74,16 @@ class MemoryFileTracker {
7274
MemoryFile* make_file(const char* descriptive_name);
7375
void free_file(MemoryFile* file);
7476

77+
template<typename F>
78+
void iterate_summary(F f) const {
79+
for (int d = 0; d < _files.length(); d++) {
80+
const MemoryFile* file = _files.at(d);
81+
for (int i = 0; i < mt_number_of_tags; i++) {
82+
f(NMTUtil::index_to_tag(i), file->_summary.by_type(NMTUtil::index_to_tag(i)));
83+
}
84+
}
85+
}
86+
7587
void summary_snapshot(VirtualMemorySnapshot* snapshot) const;
7688

7789
// Print detailed report of file
@@ -99,6 +111,11 @@ class MemoryFileTracker {
99111
const NativeCallStack& stack, MemTag mem_tag);
100112
static void free_memory(MemoryFile* device, size_t offset, size_t size);
101113

114+
template<typename F>
115+
static void iterate_summary(F f) {
116+
_tracker->iterate_summary(f);
117+
};
118+
102119
static void summary_snapshot(VirtualMemorySnapshot* snapshot);
103120

104121
static void print_report_on(const MemoryFile* device, outputStream* stream, size_t scale);

src/hotspot/share/nmt/nmtUsage.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "precompiled.hpp"
2626
#include "nmt/mallocTracker.hpp"
27+
#include "nmt/memoryFileTracker.hpp"
2728
#include "nmt/nmtCommon.hpp"
2829
#include "nmt/nmtUsage.hpp"
2930
#include "nmt/threadStackTracker.hpp"
@@ -90,6 +91,16 @@ void NMTUsage::update_vm_usage() {
9091
_vm_total.reserved += vm->reserved();
9192
_vm_total.committed += vm->committed();
9293
}
94+
95+
{ // MemoryFileTracker addition
96+
using MFT = MemoryFileTracker::Instance;
97+
MFT::Locker lock;
98+
MFT::iterate_summary([&](MemTag tag, const VirtualMemory* vm) {
99+
int i = NMTUtil::tag_to_index(tag);
100+
_vm_by_type[i].committed += vm->committed();
101+
_vm_total.committed += vm->committed();
102+
});
103+
}
93104
}
94105

95106
void NMTUsage::refresh() {

src/hotspot/share/nmt/nmtUsage.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define SHARE_NMT_NMTUSAGE_HPP
2727

2828
#include "memory/allocation.hpp"
29+
#include "nmt/memTag.hpp"
2930
#include "utilities/globalDefinitions.hpp"
3031

3132
struct NMTUsagePair {

test/jdk/ProblemList-zgc.txt

-2
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,3 @@ sun/tools/jhsdb/heapconfig/JMapHeapConfigTest.java 8307393 generic-all
3838
sun/tools/jhsdb/HeapDumpTestWithActiveProcess.java 8307393 generic-all
3939

4040
com/sun/jdi/ThreadMemoryLeakTest.java 8307402 generic-all
41-
42-
jdk/jfr/event/runtime/TestNativeMemoryUsageEvents.java 8343893 generic-all

0 commit comments

Comments
 (0)