From aaeb875c7af088ec998f274b5730f92448870aad Mon Sep 17 00:00:00 2001 From: Danny Lau Date: Wed, 7 Aug 2024 00:51:50 +0800 Subject: [PATCH] Improve Archive Region Calculation (#211) (#369) * improve archive region calculation (#211) * Add comment for Archive Region availability * Update parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java * Update parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java * Update parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java * Update parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java --------- Co-authored-by: Martijn Verburg --- .../gctoolkit/event/g1gc/G1GCPauseEvent.java | 17 +++++++++++++---- .../gctoolkit/parser/G1GCForwardReference.java | 1 + .../gctoolkit/parser/UnifiedG1GCParser.java | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1GCPauseEvent.java b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1GCPauseEvent.java index 579e991..f344bd3 100644 --- a/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1GCPauseEvent.java +++ b/api/src/main/java/com/microsoft/gctoolkit/event/g1gc/G1GCPauseEvent.java @@ -29,6 +29,7 @@ public abstract class G1GCPauseEvent extends G1GCEvent { private RegionSummary archiveRegion; private CPUSummary cpuSummary; + private int heapRegionSize; public G1GCPauseEvent(DateTimeStamp timeStamp, GarbageCollectionTypes type, GCCause cause, double duration) { super(timeStamp, type, cause, duration); @@ -102,10 +103,15 @@ public abstract class G1GCPauseEvent extends G1GCEvent { } else if (getSurvivor() == null) { return getHeap().minus(getEden()); } else { - return new MemoryPoolSummary(getHeap().getOccupancyBeforeCollection() - this.getEden().getOccupancyBeforeCollection() - getSurvivor().getOccupancyBeforeCollection(), - getHeap().getSizeBeforeCollection() - getEden().getSizeBeforeCollection() - getSurvivor().getOccupancyBeforeCollection(), - getHeap().getOccupancyAfterCollection() - getEden().getOccupancyAfterCollection() - getSurvivor().getOccupancyAfterCollection(), - getHeap().getSizeAfterCollection() - getEden().getSizeAfterCollection() - getSurvivor().getOccupancyAfterCollection()); + final RegionSummary summary = getArchiveRegionSummary(); + final long archiveRegionByteBefore = summary.getBefore() * heapRegionSize * 1024L; + final long archiveRegionByteAfter = summary.getAfter() * heapRegionSize * 1024L; + final long archiveRegionByteAssigned = summary.getAssigned() * heapRegionSize * 1024L; + + return new MemoryPoolSummary(getHeap().getOccupancyBeforeCollection() - this.getEden().getOccupancyBeforeCollection() - getSurvivor().getOccupancyBeforeCollection() - archiveRegionByteAssigned, + getHeap().getSizeBeforeCollection() - getEden().getSizeBeforeCollection() - getSurvivor().getOccupancyBeforeCollection() - archiveRegionByteBefore, + getHeap().getOccupancyAfterCollection() - getEden().getOccupancyAfterCollection() - getSurvivor().getOccupancyAfterCollection() - archiveRegionByteAssigned, + getHeap().getSizeAfterCollection() - getEden().getSizeAfterCollection() - getSurvivor().getOccupancyAfterCollection() - archiveRegionByteAfter); } } @@ -121,4 +127,7 @@ public abstract class G1GCPauseEvent extends G1GCEvent { return this.cpuSummary; } + public void addHeapRegionSize(int heapRegionSize) { + this.heapRegionSize = heapRegionSize; + } } diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCForwardReference.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCForwardReference.java index 699e501..a91b08f 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCForwardReference.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/G1GCForwardReference.java @@ -544,6 +544,7 @@ class G1GCForwardReference extends ForwardReference { SurvivorMemoryPoolSummary survivor = getSurvivorMemoryPoolSummary(); MemoryPoolSummary tenured = getMemoryPoolSummary(OLD_OCCUPANCY_BEFORE_COLLECTION); MemoryPoolSummary humongous = getMemoryPoolSummary(HUMONGOUS_OCCUPANCY_BEFORE_COLLECTION); + collection.addHeapRegionSize(heapRegionSize); if (heap != null && eden != null && survivor != null) { collection.addMemorySummary(eden, survivor, heap); } else if (eden == null && survivor == null && heap != null) { diff --git a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java index adfdcc8..9a75822 100644 --- a/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java +++ b/parser/src/main/java/com/microsoft/gctoolkit/parser/UnifiedG1GCParser.java @@ -494,6 +494,7 @@ public class UnifiedG1GCParser extends UnifiedGCLogParser implements UnifiedG1GC forwardReference.setHumongousRegionSummary(summary); break; case "Archive": + // Archive Region type is only available in JDK 14 and 17. forwardReference.setArchiveRegionSummary(summary); break; default: