8301641: NativeMemoryUsageTotal event uses reserved value for committed field

Reviewed-by: eosterlund, stefank
This commit is contained in:
Stefan Johansson 2023-02-07 09:29:59 +00:00
parent 1aaf394b33
commit 77dbcd8569
2 changed files with 13 additions and 1 deletions

View File

@ -115,7 +115,7 @@ size_t NMTUsage::total_reserved() const {
}
size_t NMTUsage::total_committed() const {
return _malloc_total + _vm_total.reserved;
return _malloc_total + _vm_total.committed;
}
size_t NMTUsage::reserved(MEMFLAGS flag) const {

View File

@ -147,6 +147,17 @@ public class TestNativeMemoryUsageEvents {
assertGreaterThan(lastSample, firstSample, "heap should have grown and NMT should show that");
}
private static void verifyTotalDiffBetweenReservedAndCommitted(List<RecordedEvent> events) throws Exception {
RecordedEvent firstTotal = events.stream()
.filter(e -> e.getEventType().getName().equals(UsageTotalEvent))
.findFirst().orElse(null);
// Verify that the first total event has more reserved than committed memory.
long firstReserved = firstTotal.getLong("reserved");
long firstCommitted = firstTotal.getLong("committed");
assertGreaterThan(firstReserved, firstCommitted, "initial reserved should be greater than initial committed");
}
private static void verifyNoUsageEvents(List<RecordedEvent> events) throws Exception {
Events.hasNotEvent(events, UsageEvent);
Events.hasNotEvent(events, UsageTotalEvent);
@ -167,6 +178,7 @@ public class TestNativeMemoryUsageEvents {
if (nmtEnabled) {
verifyExpectedEventTypes(events);
verifyHeapGrowth(events);
verifyTotalDiffBetweenReservedAndCommitted(events);
} else {
verifyNoUsageEvents(events);
}