From b454cc321a0456c070fd44f9c088fc8b69ec7174 Mon Sep 17 00:00:00 2001 From: Peter Hofer Date: Fri, 25 Nov 2022 16:45:37 +0100 Subject: [PATCH] Report correct generation capacities in SerialGCPerfData. --- .../genscavenge/AbstractCollectionPolicy.java | 15 ++++++++++++++- .../core/genscavenge/BasicCollectionPolicies.java | 15 +++++++++++++++ .../svm/core/genscavenge/CollectionPolicy.java | 6 ++++++ .../genscavenge/jvmstat/SerialGCPerfData.java | 11 +++++++---- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AbstractCollectionPolicy.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AbstractCollectionPolicy.java index 082e2752c1df..fc7055b66a41 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AbstractCollectionPolicy.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AbstractCollectionPolicy.java @@ -219,7 +219,7 @@ public UnsignedWord getMaximumYoungGenerationSize() { public UnsignedWord getCurrentHeapCapacity() { assert VMOperation.isGCInProgress() : "use only during GC"; guaranteeSizeParametersInitialized(); - return edenSize.add(survivorSize.multiply(2)).add(oldSize); + return edenSize.add(survivorSize).add(oldSize); } @Override @@ -229,6 +229,19 @@ public UnsignedWord getSurvivorSpacesCapacity() { return survivorSize; } + @Override + @Uninterruptible(reason = "Ensure reading a consistent value.") + public UnsignedWord getYoungGenerationCapacity() { + guaranteeSizeParametersInitialized(); + return edenSize.add(survivorSize); + } + + @Override + public UnsignedWord getOldGenerationCapacity() { + guaranteeSizeParametersInitialized(); + return oldSize; + } + @Override public UnsignedWord getMaximumFreeAlignedChunksSize() { assert VMOperation.isGCInProgress() : "use only during GC"; diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/BasicCollectionPolicies.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/BasicCollectionPolicies.java index 319f265fa49c..98377207f793 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/BasicCollectionPolicies.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/BasicCollectionPolicies.java @@ -151,6 +151,21 @@ public UnsignedWord getSurvivorSpacesCapacity() { return WordFactory.zero(); } + @Override + public UnsignedWord getYoungGenerationCapacity() { + return getMaximumYoungGenerationSize(); + } + + @Override + public UnsignedWord getOldGenerationCapacity() { + UnsignedWord heapCapacity = getCurrentHeapCapacity(); + UnsignedWord youngCapacity = getYoungGenerationCapacity(); + if (youngCapacity.aboveThan(heapCapacity)) { + return WordFactory.zero(); // should never happen unless options change in between + } + return heapCapacity.subtract(youngCapacity); + } + @Override public final UnsignedWord getMaximumFreeAlignedChunksSize() { return getMaximumYoungGenerationSize(); diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/CollectionPolicy.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/CollectionPolicy.java index 1739b5fada3d..7a726e002eaf 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/CollectionPolicy.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/CollectionPolicy.java @@ -158,6 +158,12 @@ static boolean shouldCollectYoungGenSeparately(boolean defaultValue) { */ UnsignedWord getSurvivorSpacesCapacity(); + /** The capacity of the young generation, comprising the eden and survivor spaces. */ + UnsignedWord getYoungGenerationCapacity(); + + /** The capacity of the old generation. */ + UnsignedWord getOldGenerationCapacity(); + /** * The maximum number of bytes that should be kept readily available for allocation or copying * during collections. diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/jvmstat/SerialGCPerfData.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/jvmstat/SerialGCPerfData.java index 44589cd183cd..4fe4410401eb 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/jvmstat/SerialGCPerfData.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/jvmstat/SerialGCPerfData.java @@ -28,6 +28,7 @@ import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; +import com.oracle.svm.core.genscavenge.CollectionPolicy; import com.oracle.svm.core.genscavenge.GCAccounting; import com.oracle.svm.core.genscavenge.GCImpl; import com.oracle.svm.core.genscavenge.HeapAccounting; @@ -94,12 +95,14 @@ public void allocate() { public void update() { GCAccounting accounting = GCImpl.getGCImpl().getAccounting(); HeapAccounting heapAccounting = HeapImpl.getHeapImpl().getAccounting(); + CollectionPolicy policy = GCImpl.getPolicy(); + policy.ensureSizeParametersInitialized(); - long maxNewSize = GCImpl.getPolicy().getMaximumYoungGenerationSize().rawValue(); + long maxNewSize = policy.getMaximumYoungGenerationSize().rawValue(); youngCollector.invocations.setValue(accounting.getIncrementalCollectionCount()); youngCollector.time.setValue(accounting.getIncrementalCollectionTotalNanos()); - youngGen.capacity.setValue(heapAccounting.getYoungUsedBytes().rawValue()); + youngGen.capacity.setValue(policy.getYoungGenerationCapacity().rawValue()); youngGen.maxCapacity.setValue(maxNewSize); youngGen.spaces[0].used.setValue(heapAccounting.getEdenUsedBytes().rawValue()); @@ -107,11 +110,11 @@ public void update() { youngGen.spaces[i].used.setValue(heapAccounting.getSurvivorSpaceAfterChunkBytes(i - 1).rawValue()); } - long maxOldSize = GCImpl.getPolicy().getMaximumHeapSize().rawValue() - maxNewSize; + long maxOldSize = policy.getMaximumHeapSize().rawValue() - maxNewSize; oldCollector.invocations.setValue(accounting.getCompleteCollectionCount()); oldCollector.time.setValue(accounting.getCompleteCollectionTotalNanos()); - oldGen.capacity.setValue(accounting.getOldGenerationAfterChunkBytes().rawValue()); + oldGen.capacity.setValue(policy.getOldGenerationCapacity().rawValue()); oldGen.maxCapacity.setValue(maxOldSize); oldGen.spaces[0].used.setValue(accounting.getOldGenerationAfterChunkBytes().rawValue());