File tree Expand file tree Collapse file tree 2 files changed +25
-10
lines changed
src/hotspot/share/services Expand file tree Collapse file tree 2 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,30 @@ size_t MallocMemorySnapshot::total_arena() const {
70
70
return amount;
71
71
}
72
72
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
+
73
97
// Make adjustment by subtracting chunks used by arenas
74
98
// from total chunks to get total free chunk size
75
99
void MallocMemorySnapshot::make_adjustment () {
Original file line number Diff line number Diff line change @@ -186,16 +186,7 @@ class MallocMemorySnapshot : public ResourceObj {
186
186
return s->by_type (mtThreadStack)->malloc_count ();
187
187
}
188
188
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);
199
190
200
191
// Make adjustment by subtracting chunks used by arenas
201
192
// from total chunks to get total free chunk size
You can’t perform that action at this time.
0 commit comments