From bf63945ad1542dbdcbaf652a518a2381868244d8 Mon Sep 17 00:00:00 2001 From: Afshin Zafari Date: Wed, 30 Aug 2023 11:11:44 +0000 Subject: [PATCH] 8298992: runtime/NMT/SummarySanityCheck.java failed with "Total committed (MMMMMM) did not match the summarized committed (NNNNNN)" Reviewed-by: gziemski, stuefe --- src/hotspot/share/services/mallocTracker.cpp | 24 ++++++++++++++++++++ src/hotspot/share/services/mallocTracker.hpp | 11 +-------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/hotspot/share/services/mallocTracker.cpp b/src/hotspot/share/services/mallocTracker.cpp index bddfcfffc0820..363bc2bb41878 100644 --- a/src/hotspot/share/services/mallocTracker.cpp +++ b/src/hotspot/share/services/mallocTracker.cpp @@ -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() { diff --git a/src/hotspot/share/services/mallocTracker.hpp b/src/hotspot/share/services/mallocTracker.hpp index f4f824bb07c49..84bba30504384 100644 --- a/src/hotspot/share/services/mallocTracker.hpp +++ b/src/hotspot/share/services/mallocTracker.hpp @@ -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