@@ -55,7 +55,7 @@ void MemReporterBase::print_total(size_t reserved, size_t committed, size_t peak
55
55
output ()->print (" reserved=" SIZE_FORMAT " %s, committed=" SIZE_FORMAT " %s" ,
56
56
amount_in_current_scale (reserved), scale, amount_in_current_scale (committed), scale);
57
57
if (peak != 0 ) {
58
- output ()->print (" , largest_committed =" SIZE_FORMAT " %s" , amount_in_current_scale (peak), scale);
58
+ output ()->print (" , peak =" SIZE_FORMAT " %s" , amount_in_current_scale (peak), scale);
59
59
}
60
60
}
61
61
@@ -93,9 +93,15 @@ void MemReporterBase::print_malloc(const MemoryCounter* c, MEMFLAGS flag) const
93
93
}
94
94
95
95
void MemReporterBase::print_virtual_memory (size_t reserved, size_t committed, size_t peak) const {
96
+ outputStream* out = output ();
96
97
const char * scale = current_scale ();
97
- output ()->print (" (mmap: reserved=" SIZE_FORMAT " %s, committed=" SIZE_FORMAT " %s, largest_committed=" SIZE_FORMAT " %s)" ,
98
- amount_in_current_scale (reserved), scale, amount_in_current_scale (committed), scale, amount_in_current_scale (peak), scale);
98
+ out->print (" (mmap: reserved=" SIZE_FORMAT " %s, committed=" SIZE_FORMAT " %s, " ,
99
+ amount_in_current_scale (reserved), scale, amount_in_current_scale (committed), scale);
100
+ if (peak == committed) {
101
+ out->print_raw (" at peak)" );
102
+ } else {
103
+ out->print (" peak=" SIZE_FORMAT " %s)" , amount_in_current_scale (peak), scale);
104
+ }
99
105
}
100
106
101
107
void MemReporterBase::print_malloc_line (const MemoryCounter* c) const {
@@ -204,74 +210,79 @@ void MemSummaryReporter::report_summary_of_type(MEMFLAGS flag,
204
210
committed_amount += _malloc_snapshot->malloc_overhead ();
205
211
}
206
212
207
- if (amount_in_current_scale (reserved_amount) > 0 ) {
208
- outputStream* out = output ();
209
- const char * scale = current_scale ();
210
- out->print (" -%26s (" , NMTUtil::flag_to_name (flag));
211
- print_total (reserved_amount, committed_amount);
213
+ // Omit printing if the current reserved value as well as all historical peaks (malloc, mmap committed, arena)
214
+ // fall below scale threshold
215
+ const size_t pk_vm = virtual_memory->peak_size ();
216
+ const size_t pk_malloc = malloc_memory->malloc_peak_size ();
217
+ const size_t pk_arena = malloc_memory->arena_peak_size ();
218
+
219
+ if (amount_in_current_scale (MAX4 (reserved_amount, pk_vm, pk_malloc, pk_arena)) == 0 ) {
220
+ return ;
221
+ }
222
+
223
+ outputStream* out = output ();
224
+ const char * scale = current_scale ();
225
+ out->print (" -%26s (" , NMTUtil::flag_to_name (flag));
226
+ print_total (reserved_amount, committed_amount);
212
227
#if INCLUDE_CDS
213
- if (flag == mtClassShared) {
214
- size_t read_only_bytes = FileMapInfo::readonly_total ();
215
- output ()->print (" , readonly=" SIZE_FORMAT " %s" ,
216
- amount_in_current_scale (read_only_bytes), scale);
217
- }
228
+ if (flag == mtClassShared) {
229
+ size_t read_only_bytes = FileMapInfo::readonly_total ();
230
+ output ()->print (" , readonly=" SIZE_FORMAT " %s" ,
231
+ amount_in_current_scale (read_only_bytes), scale);
232
+ }
218
233
#endif
219
- out->print_cr (" )" );
234
+ out->print_cr (" )" );
220
235
221
- if (flag == mtClass) {
222
- // report class count
223
- out->print_cr (" %27s (classes #" SIZE_FORMAT " )" ,
224
- " " , (_instance_class_count + _array_class_count));
225
- out->print_cr (" %27s ( instance classes #" SIZE_FORMAT " , array classes #" SIZE_FORMAT " )" ,
226
- " " , _instance_class_count, _array_class_count);
227
- } else if (flag == mtThread) {
228
- if (ThreadStackTracker::track_as_vm ()) {
229
- const VirtualMemory* thread_stack_usage =
230
- _vm_snapshot->by_type (mtThreadStack);
231
- // report thread count
232
- out->print_cr (" %27s (threads #" SIZE_FORMAT " )" , " " , ThreadStackTracker::thread_count ());
233
- out->print (" %27s (stack: " , " " );
234
- print_total (thread_stack_usage->reserved (), thread_stack_usage->committed (), thread_stack_usage->peak_size ());
235
- } else {
236
- MallocMemory* thread_stack_memory = _malloc_snapshot->by_type (mtThreadStack);
237
- const char * scale = current_scale ();
238
- // report thread count
239
- out->print_cr (" %27s (threads #" SIZE_FORMAT " )" , " " , thread_stack_memory->malloc_count ());
240
- out->print (" %27s (Stack: " SIZE_FORMAT " %s" , " " ,
241
- amount_in_current_scale (thread_stack_memory->malloc_size ()), scale);
242
- }
243
- out->print_cr (" )" );
236
+ if (flag == mtClass) {
237
+ // report class count
238
+ out->print_cr (" %27s (classes #" SIZE_FORMAT " )" ,
239
+ " " , (_instance_class_count + _array_class_count));
240
+ out->print_cr (" %27s ( instance classes #" SIZE_FORMAT " , array classes #" SIZE_FORMAT " )" ,
241
+ " " , _instance_class_count, _array_class_count);
242
+ } else if (flag == mtThread) {
243
+ if (ThreadStackTracker::track_as_vm ()) {
244
+ const VirtualMemory* thread_stack_usage =
245
+ _vm_snapshot->by_type (mtThreadStack);
246
+ // report thread count
247
+ out->print_cr (" %27s (threads #" SIZE_FORMAT " )" , " " , ThreadStackTracker::thread_count ());
248
+ out->print (" %27s (stack: " , " " );
249
+ print_total (thread_stack_usage->reserved (), thread_stack_usage->committed (), thread_stack_usage->peak_size ());
250
+ } else {
251
+ MallocMemory* thread_stack_memory = _malloc_snapshot->by_type (mtThreadStack);
252
+ const char * scale = current_scale ();
253
+ // report thread count
254
+ out->print_cr (" %27s (threads #" SIZE_FORMAT " )" , " " , thread_stack_memory->malloc_count ());
255
+ out->print (" %27s (Stack: " SIZE_FORMAT " %s" , " " ,
256
+ amount_in_current_scale (thread_stack_memory->malloc_size ()), scale);
244
257
}
258
+ out->print_cr (" )" );
259
+ }
245
260
246
- // report malloc'd memory
247
- if (amount_in_current_scale (malloc_memory->malloc_size ()) > 0
248
- || amount_in_current_scale (malloc_memory->malloc_peak_size ()) > 0 ) {
249
- print_malloc_line (malloc_memory->malloc_counter ());
250
- }
261
+ // report malloc'd memory
262
+ if (amount_in_current_scale (MAX2 (malloc_memory->malloc_size (), pk_malloc)) > 0 ) {
263
+ print_malloc_line (malloc_memory->malloc_counter ());
264
+ }
251
265
252
- if (amount_in_current_scale (virtual_memory->reserved ()) > 0
253
- DEBUG_ONLY (|| amount_in_current_scale (virtual_memory->peak_size ()) > 0 )) {
254
- print_virtual_memory_line (virtual_memory->reserved (), virtual_memory->committed (), virtual_memory->peak_size ());
255
- }
266
+ if (amount_in_current_scale (MAX2 (virtual_memory->reserved (), pk_vm)) > 0 ) {
267
+ print_virtual_memory_line (virtual_memory->reserved (), virtual_memory->committed (), virtual_memory->peak_size ());
268
+ }
256
269
257
- if (amount_in_current_scale (malloc_memory->arena_size ()) > 0
258
- DEBUG_ONLY (|| amount_in_current_scale (malloc_memory->arena_peak_size ()) > 0 )) {
259
- print_arena_line (malloc_memory->arena_counter ());
260
- }
270
+ if (amount_in_current_scale (MAX2 (malloc_memory->arena_size (), pk_arena)) > 0 ) {
271
+ print_arena_line (malloc_memory->arena_counter ());
272
+ }
261
273
262
- if (flag == mtNMT &&
263
- amount_in_current_scale (_malloc_snapshot->malloc_overhead ()) > 0 ) {
264
- out->print_cr (" %27s (tracking overhead=" SIZE_FORMAT " %s)" , " " ,
265
- amount_in_current_scale (_malloc_snapshot->malloc_overhead ()), scale);
266
- } else if (flag == mtClass) {
267
- // Metadata information
268
- report_metadata (Metaspace::NonClassType);
269
- if (Metaspace::using_class_space ()) {
270
- report_metadata (Metaspace::ClassType);
271
- }
274
+ if (flag == mtNMT &&
275
+ amount_in_current_scale (_malloc_snapshot->malloc_overhead ()) > 0 ) {
276
+ out->print_cr (" %27s (tracking overhead=" SIZE_FORMAT " %s)" , " " ,
277
+ amount_in_current_scale (_malloc_snapshot->malloc_overhead ()), scale);
278
+ } else if (flag == mtClass) {
279
+ // Metadata information
280
+ report_metadata (Metaspace::NonClassType);
281
+ if (Metaspace::using_class_space ()) {
282
+ report_metadata (Metaspace::ClassType);
272
283
}
273
- out->print_cr (" " );
274
284
}
285
+ out->print_cr (" " );
275
286
}
276
287
277
288
void MemSummaryReporter::report_metadata (Metaspace::MetadataType type) const {
@@ -321,9 +332,8 @@ int MemDetailReporter::report_malloc_sites() {
321
332
const MallocSite* malloc_site;
322
333
int num_omitted = 0 ;
323
334
while ((malloc_site = malloc_itr.next ()) != nullptr ) {
324
- // Don't report if site has never allocated less than one unit of whatever our scale is
325
- if (scale () > 1 && amount_in_current_scale (malloc_site->size ()) == 0
326
- DEBUG_ONLY (&& amount_in_current_scale (malloc_site->peak_size ()) == 0 )) {
335
+ // Omit printing if the current value and the historic peak value both fall below the reporting scale threshold
336
+ if (amount_in_current_scale (MAX2 (malloc_site->size (), malloc_site->peak_size ())) == 0 ) {
327
337
num_omitted ++;
328
338
continue ;
329
339
}
@@ -353,8 +363,10 @@ int MemDetailReporter::report_virtual_memory_allocation_sites() {
353
363
if (virtual_memory_site->reserved () == 0 ) {
354
364
continue ;
355
365
}
356
- // Don't report if site has reserved less than one unit of whatever our scale is
357
- if (scale () > 1 && amount_in_current_scale (virtual_memory_site->reserved ()) == 0 ) {
366
+ // Omit printing if the current value and the historic peak value both fall below the
367
+ // reporting scale threshold
368
+ if (amount_in_current_scale (MAX2 (virtual_memory_site->reserved (),
369
+ virtual_memory_site->peak_size ())) == 0 ) {
358
370
num_omitted++;
359
371
continue ;
360
372
}
@@ -386,7 +398,16 @@ void MemDetailReporter::report_virtual_memory_map() {
386
398
void MemDetailReporter::report_virtual_memory_region (const ReservedMemoryRegion* reserved_rgn) {
387
399
assert (reserved_rgn != nullptr , " null pointer" );
388
400
389
- // Don't report if size is too small
401
+ // We don't bother about reporting peaks here.
402
+ // That is because peaks - in the context of virtual memory, peak of committed areas - make little sense
403
+ // when we report *by region*, which are identified by their location in memory. There is a philosophical
404
+ // question about identity here: e.g. a committed region that has been split into three regions by
405
+ // uncommitting a middle section of it, should that still count as "having peaked" before the split? If
406
+ // yes, which of the three new regions would be the spiritual successor? Rather than introducing more
407
+ // complexity, we avoid printing peaks altogether. Note that peaks should still be printed when reporting
408
+ // usage *by callsite*.
409
+
410
+ // Don't report if size is too small.
390
411
if (amount_in_current_scale (reserved_rgn->size ()) == 0 ) return ;
391
412
392
413
outputStream* out = output ();
0 commit comments