Skip to content

Commit

Permalink
8269571: NMT should print total malloc bytes and invocation count
Browse files Browse the repository at this point in the history
Backport-of: 3ad20fcdfa35796c190ccbaf26872b0fe30d8c76
  • Loading branch information
tstuefe committed Oct 25, 2022
1 parent b6f8f49 commit bf866a4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/hotspot/share/services/mallocTracker.cpp
Expand Up @@ -60,6 +60,15 @@ size_t MemoryCounter::peak_size() const {
}
#endif

// Total malloc invocation count
size_t MallocMemorySnapshot::total_count() const {
size_t amount = 0;
for (int index = 0; index < mt_number_of_types; index ++) {
amount += _malloc[index].malloc_count();
}
return amount;
}

// Total malloc'd memory amount
size_t MallocMemorySnapshot::total() const {
size_t amount = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/services/mallocTracker.hpp
Expand Up @@ -153,6 +153,8 @@ class MallocMemorySnapshot : public ResourceObj {
return &_tracking_header;
}

// Total malloc invocation count
size_t total_count() const;
// Total malloc'd memory amount
size_t total() const;
// Total malloc'd memory used by arenas
Expand Down
19 changes: 14 additions & 5 deletions src/hotspot/share/services/memReporter.cpp
Expand Up @@ -98,10 +98,12 @@ void MemReporterBase::print_virtual_memory_region(const char* type, address base

void MemSummaryReporter::report() {
outputStream* out = output();
size_t total_reserved_amount = _malloc_snapshot->total() +
_vm_snapshot->total_reserved();
size_t total_committed_amount = _malloc_snapshot->total() +
_vm_snapshot->total_committed();
const size_t total_malloced_bytes = _malloc_snapshot->total();
const size_t total_mmap_reserved_bytes = _vm_snapshot->total_reserved();
const size_t total_mmap_committed_bytes = _vm_snapshot->total_committed();

size_t total_reserved_amount = total_malloced_bytes + total_mmap_reserved_bytes;
size_t total_committed_amount = total_malloced_bytes + total_mmap_committed_bytes;

// Overall total
out->print_cr("\nNative Memory Tracking:\n");
Expand All @@ -113,7 +115,14 @@ void MemSummaryReporter::report() {

out->print("Total: ");
print_total(total_reserved_amount, total_committed_amount);
out->print("\n");
out->cr();
out->print_cr(" malloc: " SIZE_FORMAT "%s #" SIZE_FORMAT,
amount_in_current_scale(total_malloced_bytes), current_scale(),
_malloc_snapshot->total_count());
out->print(" mmap: ");
print_total(total_mmap_reserved_bytes, total_mmap_committed_bytes);
out->cr();
out->cr();

// Summary by memory type
for (int index = 0; index < mt_number_of_types; index ++) {
Expand Down

1 comment on commit bf866a4

@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.