Skip to content

Commit 9c24b11

Browse files
mur47x111marwan-hallaoui
authored andcommitted
[GR-50952] Backport to 23.0 : Respect maximum eden size in AggressiveShrinkCollectionPolicy.
PullRequest: graal/15968
2 parents 0e80671 + 75ab50b commit 9c24b11

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AggressiveShrinkCollectionPolicy.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.graalvm.word.WordFactory;
3030

3131
import com.oracle.svm.core.heap.GCCause;
32-
import com.oracle.svm.core.option.HostedOptionKey;
32+
import com.oracle.svm.core.option.RuntimeOptionKey;
3333
import com.oracle.svm.core.util.UnsignedUtils;
3434

3535
/**
@@ -41,14 +41,16 @@ class AggressiveShrinkCollectionPolicy extends AdaptiveCollectionPolicy {
4141
public static final class Options {
4242
@Option(help = "Ratio of used bytes to total allocated bytes for eden space. Setting it to a smaller value " +
4343
"will trade more triggered hinted GCs for less resident set size.") //
44-
public static final HostedOptionKey<Double> UsedEdenProportionThreshold = new HostedOptionKey<>(0.75D);
44+
public static final RuntimeOptionKey<Double> UsedEdenProportionThreshold = new RuntimeOptionKey<>(0.75D);
4545
@Option(help = "Soft upper limit for used eden size. The hinted GC will be performed if the used eden size " +
4646
"exceeds this value.") //
47-
public static final HostedOptionKey<Integer> ExpectedEdenSize = new HostedOptionKey<>(32 * 1024 * 1024);
47+
public static final RuntimeOptionKey<Long> ExpectedEdenSize = new RuntimeOptionKey<>(32L * 1024L * 1024L);
4848
}
4949

50-
protected static final UnsignedWord INITIAL_HEAP_SIZE = WordFactory.unsigned(64 * 1024 * 1024);
51-
protected static final UnsignedWord FULL_GC_BONUS = WordFactory.unsigned(2 * 1024 * 1024);
50+
protected static final UnsignedWord INITIAL_HEAP_SIZE = WordFactory.unsigned(64L * 1024L * 1024L);
51+
protected static final UnsignedWord FULL_GC_BONUS = WordFactory.unsigned(2L * 1024L * 1024L);
52+
53+
protected static final UnsignedWord MAXIMUM_HEAP_SIZE = WordFactory.unsigned(16L * 1024L * 1024L * 1024L);
5254

5355
private UnsignedWord sizeBefore = WordFactory.zero();
5456
private GCCause lastGCCause = null;
@@ -73,7 +75,7 @@ public boolean shouldCollectOnRequest(GCCause cause, boolean fullGC) {
7375
// memory usage point.
7476
edenUsedBytes = edenUsedBytes.add(FULL_GC_BONUS);
7577
}
76-
return edenUsedBytes.aboveOrEqual(Options.ExpectedEdenSize.getValue()) ||
78+
return edenUsedBytes.aboveOrEqual(WordFactory.unsigned(Options.ExpectedEdenSize.getValue())) ||
7779
(UnsignedUtils.toDouble(edenUsedBytes) / UnsignedUtils.toDouble(edenSize) >= Options.UsedEdenProportionThreshold.getValue());
7880
}
7981
return super.shouldCollectOnRequest(cause, fullGC);
@@ -84,6 +86,15 @@ protected UnsignedWord getInitialHeapSize() {
8486
return INITIAL_HEAP_SIZE;
8587
}
8688

89+
@Override
90+
public UnsignedWord getMaximumHeapSize() {
91+
UnsignedWord initialSetup = super.getMaximumHeapSize();
92+
if (initialSetup.aboveThan(MAXIMUM_HEAP_SIZE)) {
93+
return MAXIMUM_HEAP_SIZE;
94+
}
95+
return initialSetup;
96+
}
97+
8798
@Override
8899
public void onCollectionBegin(boolean completeCollection, long requestingNanoTime) {
89100
sizeBefore = GCImpl.getChunkBytes();
@@ -125,7 +136,10 @@ protected void computeEdenSpaceSize(boolean completeCollection, GCCause cause) {
125136
} else {
126137
UnsignedWord sizeAfter = GCImpl.getChunkBytes();
127138
if (sizeBefore.notEqual(0) && sizeBefore.belowThan(sizeAfter.multiply(2))) {
128-
edenSize = alignUp(edenSize.multiply(2));
139+
UnsignedWord newEdenSize = UnsignedUtils.min(getMaximumEdenSize(), alignUp(edenSize.multiply(2)));
140+
if (edenSize.belowThan(newEdenSize)) {
141+
edenSize = newEdenSize;
142+
}
129143
} else {
130144
super.computeEdenSpaceSize(completeCollection, cause);
131145
}

0 commit comments

Comments
 (0)