Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/hotspot/share/services/mallocTracker.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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