Skip to content

Commit

Permalink
8298992: runtime/NMT/SummarySanityCheck.java failed with "Total commi…
Browse files Browse the repository at this point in the history
…tted (MMMMMM) did not match the summarized committed (NNNNNN)"

Reviewed-by: gziemski, stuefe
  • Loading branch information
Afshin Zafari committed Aug 30, 2023
1 parent cb3f968 commit bf63945
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
24 changes: 24 additions & 0 deletions src/hotspot/share/services/mallocTracker.cpp
Expand Up @@ -70,6 +70,30 @@ size_t MallocMemorySnapshot::total_arena() const {
return amount;
}

void MallocMemorySnapshot::copy_to(MallocMemorySnapshot* s) {
// Need to make sure that mtChunks don't get deallocated while the
// copy is going on, because their size is adjusted using this
// buffer in make_adjustment().
ThreadCritical tc;
size_t total_size;
size_t loop_counter = 0;
const size_t loop_limit = 100;
// It is observed that other threads can allocate during the loop of copying.
// This results in inconsistent total and sum of parts. So, the while-loop and
// the local total_size are used to find and try again a limited number of times.
// Acheiving fully consistent total and sum of parts requires to block all mallooc's during
// the copy which is a performance obstacle.
do {
total_size = 0;
s->_all_mallocs = _all_mallocs;
for (int index = 0; index < mt_number_of_types; index ++) {
s->_malloc[index] = _malloc[index];
total_size += _malloc[index].malloc_size();
}
} while(s->_all_mallocs.size() != total_size && ++loop_counter < loop_limit);
assert(s->_all_mallocs.size() == total_size, "Total != sum of parts");
}

// Make adjustment by subtracting chunks used by arenas
// from total chunks to get total free chunk size
void MallocMemorySnapshot::make_adjustment() {
Expand Down
11 changes: 1 addition & 10 deletions src/hotspot/share/services/mallocTracker.hpp
Expand Up @@ -186,16 +186,7 @@ class MallocMemorySnapshot : public ResourceObj {
return s->by_type(mtThreadStack)->malloc_count();
}

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

// Make adjustment by subtracting chunks used by arenas
// from total chunks to get total free chunk size
Expand Down

1 comment on commit bf63945

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.