Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8281946: VM.native_memory should report size of shareable memory #11401

Closed
wants to merge 21 commits into from
Closed
Changes from 1 commit
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
38 changes: 21 additions & 17 deletions src/hotspot/share/services/memReporter.cpp
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@
*
*/
#include "precompiled.hpp"
#include "cds/filemap.hpp"
#include "memory/allocation.hpp"
#include "memory/metaspace.hpp"
#include "memory/metaspaceUtils.hpp"
@@ -40,19 +39,29 @@ size_t MemReporterBase::committed_total(const MallocMemory* malloc, const Virtua
return malloc->malloc_size() + malloc->arena_size() + vm->committed();
}

void MemReporterBase::print_total(size_t reserved, size_t committed) const {
const char* scale = current_scale();
output()->print("reserved=" SIZE_FORMAT "%s, committed=" SIZE_FORMAT "%s",
amount_in_current_scale(reserved), scale,
amount_in_current_scale(committed), scale);
// There can be upto two CDS archives which can contain readonly data. On Windows, pages are not
Copy link
Member

@tstuefe tstuefe Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MemReporterBase::readonly_total is CDS stuff, can you please move it into CDS and make it a query function there? Lets not leak more CDS knowledge into NMT than necessary.

Typo: upto

// shareable so the RO region may not actually be read only
size_t MemReporterBase::readonly_total(FileMapInfo* info) const {
size_t total = 0;
FileMapRegion* r;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed.

if (info!= NULL) {
FileMapRegion* r = info->region_at(MetaspaceShared::ro);
if (r->read_only()) {
total = r->used();
}
}
return total;
}

void MemReporterBase::print_total(size_t reserved, size_t committed, size_t read_only) const {
void MemReporterBase::print_total(size_t reserved, size_t committed, size_t read_only = 0) const {
const char* scale = current_scale();
output()->print("reserved=" SIZE_FORMAT "%s, committed=" SIZE_FORMAT "%s, readonly=" SIZE_FORMAT "%s",
output()->print("reserved=" SIZE_FORMAT "%s, committed=" SIZE_FORMAT "%s",
amount_in_current_scale(reserved), scale,
amount_in_current_scale(committed), scale,
amount_in_current_scale(read_only), scale);
amount_in_current_scale(committed), scale);
if (read_only > 0) {
output()->print(", readonly=" SIZE_FORMAT "%s",
amount_in_current_scale(read_only), scale);
}
}

void MemReporterBase::print_malloc(size_t amount, size_t count, MEMFLAGS flag) const {
@@ -114,13 +123,8 @@ void MemSummaryReporter::report() {

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

size_t read_only_bytes = 0;
FileMapRegion* r = FileMapInfo::current_info()->region_at(MetaspaceShared::ro);
// Region will be read-write on windows, otherwise this is a sanity check
if (!MetaspaceShared::use_windows_memory_mapping())
assert(r->read_only(), "Region should be read only");
read_only_bytes = r->used();
size_t read_only_bytes = readonly_total(FileMapInfo::current_info()); // static archive
read_only_bytes += readonly_total(FileMapInfo::dynamic_info()); // dynamic archive

// Overall total
out->print_cr("\nNative Memory Tracking:\n");
3 changes: 2 additions & 1 deletion src/hotspot/share/services/memReporter.hpp
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
#ifndef SHARE_SERVICES_MEMREPORTER_HPP
#define SHARE_SERVICES_MEMREPORTER_HPP

#include "cds/filemap.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary in the header. Please move to the cpp file.

#include "memory/metaspace.hpp"
#include "oops/instanceKlass.hpp"
#include "services/memBaseline.hpp"
@@ -77,9 +78,9 @@ class MemReporterBase : public StackObj {
// Calculate total reserved and committed amount
size_t reserved_total(const MallocMemory* malloc, const VirtualMemory* vm) const;
size_t committed_total(const MallocMemory* malloc, const VirtualMemory* vm) const;
size_t readonly_total(FileMapInfo* info) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary


// Print summary total, malloc and virtual memory
void print_total(size_t reserved, size_t committed) const;
void print_total(size_t reserved, size_t committed, size_t read_only) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default parameter should be placed in the function declaration (here) and not in the function definition (in the cpp file).

void print_malloc(size_t amount, size_t count, MEMFLAGS flag = mtNone) const;
void print_virtual_memory(size_t reserved, size_t committed) const;
14 changes: 9 additions & 5 deletions test/hotspot/jtreg/runtime/NMT/SummarySanityCheck.java
Original file line number Diff line number Diff line change
@@ -67,9 +67,9 @@ public static void main(String args[]) throws Exception {

// Match '- <mtType> (reserved=<reserved>KB, committed=<committed>KB)
Pattern mtTypePattern = Pattern.compile("-\\s+(?<typename>[\\w\\s]+)\\(reserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB\\)");
// Match 'Total: reserved=<reserved>KB, committed=<committed>KB'
// Match 'Total: reserved=<reserved>KB, committed=<committed>KB, readonly=<readonly>KB'
Pattern totalMemoryPattern = Pattern.compile("Total\\:\\sreserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB,\\sreadonly=(?<readonly>\\d+)KB");
// Match '- <mtType> (reserved=<reserved>KB, committed=<committed>KB)
// Match '- <mtType> (reserved=<reserved>KB, committed=<committed>KB, readonly<readonly>KB)
Pattern mtSharedPattern = Pattern.compile("-\\s+(?<typename>[\\w\\s]+)\\(reserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB,\\sreadonly=(?<readonly>\\d+)KB\\)");

for (int i = 0; i < lines.length; i++) {
@@ -80,6 +80,10 @@ public static void main(String args[]) throws Exception {
totalCommitted = Long.parseLong(totalMemoryMatcher.group("committed"));
totalReserved = Long.parseLong(totalMemoryMatcher.group("reserved"));
totalReadonly = Long.parseLong(totalMemoryMatcher.group("readonly"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totalReadonly is nowhere used. Remove it? Or add a check for it?


if (totalReadonly > totalCommitted) {
throwTestException("Total readonly was more than committed");
}
} else {
throwTestException("Failed to match the expected groups in 'Total' memory part");
}
@@ -97,9 +101,9 @@ public static void main(String args[]) throws Exception {
+ typeReserved + ") for mtType: " + typeMatcher.group("typename"));
}
// Make sure readonly is always less or equals
if (typeShared > typeReserved) {
throwTestException("Readonly (" + typeShared + ") was more than Reserved ("
+ typeReserved + ") for mtType: " + typeMatcher.group("typename"));
if (typeShared > typeCommitted) {
throwTestException("Readonly (" + typeShared + ") was more than Committed ("
+ typeCommitted + ") for mtType: " + typeMatcher.group("typename"));
}

// Add to total and compare them in the end