8281946: VM.native_memory should report size of shareable memory

Reviewed-by: stuefe, iklam
This commit is contained in:
Matias Saavedra Silva 2022-12-15 05:03:57 +00:00 committed by Ioi Lam
parent 3ef382416f
commit d1085d1be7
4 changed files with 35 additions and 2 deletions

View File

@ -2060,6 +2060,20 @@ size_t FileMapInfo::read_bytes(void* buffer, size_t count) {
return count;
}
// Get the total size in bytes of a read only region
size_t FileMapInfo::readonly_total() {
size_t total = 0;
if (current_info() != nullptr) {
FileMapRegion* r = FileMapInfo::current_info()->region_at(MetaspaceShared::ro);
if (r->read_only()) total += r->used();
}
if (dynamic_info() != nullptr) {
FileMapRegion* r = FileMapInfo::dynamic_info()->region_at(MetaspaceShared::ro);
if (r->read_only()) total += r->used();
}
return total;
}
static MemRegion *closed_heap_regions = NULL;
static MemRegion *open_heap_regions = NULL;
static int num_closed_heap_regions = 0;

View File

@ -460,6 +460,7 @@ public:
void write_bytes(const void* buffer, size_t count);
void write_bytes_aligned(const void* buffer, size_t count);
size_t read_bytes(void* buffer, size_t count);
static size_t readonly_total();
MapArchiveResult map_regions(int regions[], int num_regions, char* mapped_base_address, ReservedSpace rs);
void unmap_regions(int regions[], int num_regions);
void map_or_load_heap_regions() NOT_CDS_JAVA_HEAP_RETURN;

View File

@ -22,6 +22,7 @@
*
*/
#include "precompiled.hpp"
#include "cds/filemap.hpp"
#include "memory/allocation.hpp"
#include "memory/metaspace.hpp"
#include "memory/metaspaceUtils.hpp"
@ -205,6 +206,13 @@ void MemSummaryReporter::report_summary_of_type(MEMFLAGS flag,
const char* scale = current_scale();
out->print("-%26s (", NMTUtil::flag_to_name(flag));
print_total(reserved_amount, committed_amount);
#if INCLUDE_CDS
if (flag == mtClassShared) {
size_t read_only_bytes = FileMapInfo::readonly_total();
output()->print(", readonly=" SIZE_FORMAT "%s",
amount_in_current_scale(read_only_bytes), scale);
}
#endif
out->print_cr(")");
if (flag == mtClass) {

View File

@ -64,8 +64,8 @@ public class SummarySanityCheck {
long totalCommitted = 0, totalReserved = 0;
long totalCommittedSum = 0, totalReservedSum = 0;
// 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 '- <mtType> (reserved=<reserved>KB, committed=<committed>KB) and some times readonly=<readonly>KB
Pattern mtTypePattern = Pattern.compile("-\\s+(?<typename>[\\w\\s]+)\\(reserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB((,\\sreadonly=(?<readonly>\\d+)KB)|)\\)");
// Match 'Total: reserved=<reserved>KB, committed=<committed>KB'
Pattern totalMemoryPattern = Pattern.compile("Total\\:\\sreserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB");
@ -85,6 +85,16 @@ public class SummarySanityCheck {
long typeCommitted = Long.parseLong(typeMatcher.group("committed"));
long typeReserved = Long.parseLong(typeMatcher.group("reserved"));
// Only Shared class space has readonly component
if (lines[i].contains("Shared class space") && typeMatcher.group("readonly") != null) {
long typeReadOnly = Long.parseLong(typeMatcher.group("readonly"));
// Make sure readonly is always less or equal to committed
if (typeReadOnly > typeCommitted) {
throwTestException("Readonly (" + typeReadOnly + ") was more than Committed ("
+ typeCommitted + ") for mtType: " + typeMatcher.group("typename"));
}
}
// Make sure reserved is always less or equals
if (typeCommitted > typeReserved) {
throwTestException("Committed (" + typeCommitted + ") was more than Reserved ("