Skip to content

Commit bf63945

Browse files
author
Afshin Zafari
committed
8298992: runtime/NMT/SummarySanityCheck.java failed with "Total committed (MMMMMM) did not match the summarized committed (NNNNNN)"
Reviewed-by: gziemski, stuefe
1 parent cb3f968 commit bf63945

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/hotspot/share/services/mallocTracker.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,30 @@ size_t MallocMemorySnapshot::total_arena() const {
7070
return amount;
7171
}
7272

73+
void MallocMemorySnapshot::copy_to(MallocMemorySnapshot* s) {
74+
// Need to make sure that mtChunks don't get deallocated while the
75+
// copy is going on, because their size is adjusted using this
76+
// buffer in make_adjustment().
77+
ThreadCritical tc;
78+
size_t total_size;
79+
size_t loop_counter = 0;
80+
const size_t loop_limit = 100;
81+
// It is observed that other threads can allocate during the loop of copying.
82+
// This results in inconsistent total and sum of parts. So, the while-loop and
83+
// the local total_size are used to find and try again a limited number of times.
84+
// Acheiving fully consistent total and sum of parts requires to block all mallooc's during
85+
// the copy which is a performance obstacle.
86+
do {
87+
total_size = 0;
88+
s->_all_mallocs = _all_mallocs;
89+
for (int index = 0; index < mt_number_of_types; index ++) {
90+
s->_malloc[index] = _malloc[index];
91+
total_size += _malloc[index].malloc_size();
92+
}
93+
} while(s->_all_mallocs.size() != total_size && ++loop_counter < loop_limit);
94+
assert(s->_all_mallocs.size() == total_size, "Total != sum of parts");
95+
}
96+
7397
// Make adjustment by subtracting chunks used by arenas
7498
// from total chunks to get total free chunk size
7599
void MallocMemorySnapshot::make_adjustment() {

src/hotspot/share/services/mallocTracker.hpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,7 @@ class MallocMemorySnapshot : public ResourceObj {
186186
return s->by_type(mtThreadStack)->malloc_count();
187187
}
188188

189-
void copy_to(MallocMemorySnapshot* s) {
190-
// Need to make sure that mtChunks don't get deallocated while the
191-
// copy is going on, because their size is adjusted using this
192-
// buffer in make_adjustment().
193-
ThreadCritical tc;
194-
s->_all_mallocs = _all_mallocs;
195-
for (int index = 0; index < mt_number_of_types; index ++) {
196-
s->_malloc[index] = _malloc[index];
197-
}
198-
}
189+
void copy_to(MallocMemorySnapshot* s);
199190

200191
// Make adjustment by subtracting chunks used by arenas
201192
// from total chunks to get total free chunk size

0 commit comments

Comments
 (0)