From a969e13651bf264f16b1e5d9d59b062c04dde509 Mon Sep 17 00:00:00 2001 From: Robert Toyonaga Date: Tue, 8 Oct 2024 14:38:48 -0400 Subject: [PATCH] collect on allocation crossing max --- .../svm/core/genscavenge/AbstractCollectionPolicy.java | 4 ++-- .../svm/core/genscavenge/BasicCollectionPolicies.java | 6 +++--- .../com/oracle/svm/core/genscavenge/CollectionPolicy.java | 2 +- .../src/com/oracle/svm/core/genscavenge/GCImpl.java | 2 +- 4 files changed, 7 insertions(+), 7 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 0602142883fd..e1b485e9bdb1 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 @@ -87,11 +87,11 @@ protected AbstractCollectionPolicy(int initialNewRatio, int initialTenuringThres } @Override - public boolean shouldCollectOnAllocation() { + public boolean shouldCollectOnAllocation(UnsignedWord allocationSize) { if (sizes == null) { return false; // updateSizeParameters() has never been called } - UnsignedWord edenUsed = HeapImpl.getAccounting().getEdenUsedBytes(); + UnsignedWord edenUsed = HeapImpl.getAccounting().getEdenUsedBytes().add(allocationSize); return edenUsed.aboveOrEqual(edenSize); } 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 5bf00a10b5ff..6d622e43e2dc 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 @@ -57,8 +57,8 @@ protected static UnsignedWord m(long bytes) { } @Override - public boolean shouldCollectOnAllocation() { - UnsignedWord youngUsed = HeapImpl.getAccounting().getYoungUsedBytes(); + public boolean shouldCollectOnAllocation(UnsignedWord allocationSize) { + UnsignedWord youngUsed = HeapImpl.getAccounting().getYoungUsedBytes().add(allocationSize); return youngUsed.aboveOrEqual(getMaximumYoungGenerationSize()); } @@ -243,7 +243,7 @@ public String getName() { public static final class NeverCollect extends BasicPolicy { @Override - public boolean shouldCollectOnAllocation() { + public boolean shouldCollectOnAllocation(UnsignedWord allocationSize) { throw VMError.shouldNotReachHere("Caller is supposed to be aware of never-collect policy"); } 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 3a0e9b413401..6a92743bc0af 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 @@ -119,7 +119,7 @@ static boolean shouldCollectYoungGenSeparately(boolean defaultValue) { * {@code true} will initiate a safepoint during which {@link #shouldCollectCompletely} will be * called followed by the collection. */ - boolean shouldCollectOnAllocation(); + boolean shouldCollectOnAllocation(UnsignedWord allocationSize); /** * Called when an application provides a hint to the GC that it might be a good time to do a diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java index df8ca685efbb..182f2f1cce48 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java @@ -159,7 +159,7 @@ public void maybeCollectOnAllocation(UnsignedWord allocationSize) { if (hasNeverCollectPolicy()) { UnsignedWord edenUsed = HeapImpl.getAccounting().getEdenUsedBytes(); outOfMemory = edenUsed.aboveThan(GCImpl.getPolicy().getMaximumHeapSize()); - } else if (getPolicy().shouldCollectOnAllocation()) { + } else if (getPolicy().shouldCollectOnAllocation(allocationSize)) { AllocationRequiringGCEvent.emit(getCollectionEpoch(), allocationSize); outOfMemory = collectWithoutAllocating(GenScavengeGCCause.OnAllocation, false); }