Skip to content

Commit 504c5d7

Browse files
committed
Adjust MaxSurvivorSpaces option depending on policy.
1 parent 8d3e262 commit 504c5d7

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242

4343
abstract class AbstractCollectionPolicy implements CollectionPolicy {
4444

45+
protected static final int MAX_TENURING_THRESHOLD = 15;
46+
47+
static int getMaxSurvivorSpaces(Integer optionValue) {
48+
assert optionValue == null || optionValue >= 0;
49+
return (optionValue != null) ? optionValue : AbstractCollectionPolicy.MAX_TENURING_THRESHOLD;
50+
}
51+
4552
/*
4653
* Constants that can be made options if desirable. These are -XX options in HotSpot, refer to
4754
* their descriptions for details. The values are HotSpot defaults unless labeled otherwise.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public static class Options {
5050
public static final HostedOptionKey<Long> AllocationBeforePhysicalMemorySize = new HostedOptionKey<>(1L * 1024L * 1024L);
5151
}
5252

53+
static int getMaxSurvivorSpaces(@SuppressWarnings("unused") Integer optionValue) {
54+
assert optionValue == null || optionValue >= 0;
55+
return 0; // override option (if set): 0 not supported
56+
}
57+
5358
private BasicCollectionPolicies() {
5459
}
5560

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,23 @@ final class Options {
4343
}
4444

4545
@Platforms(Platform.HOSTED_ONLY.class)
46-
static CollectionPolicy getInitialPolicy() {
46+
static String getInitialPolicyName() {
4747
if (SubstrateOptions.UseEpsilonGC.getValue()) {
48-
return new BasicCollectionPolicies.NeverCollect();
48+
return "NeverCollect";
4949
} else if (!SubstrateOptions.useRememberedSet()) {
50-
return new BasicCollectionPolicies.OnlyCompletely();
50+
return "OnlyCompletely";
5151
}
5252
String name = Options.InitialCollectionPolicy.getValue();
5353
String legacyPrefix = "com.oracle.svm.core.genscavenge.CollectionPolicy$";
5454
if (name.startsWith(legacyPrefix)) {
55-
name = name.substring(legacyPrefix.length());
55+
return name.substring(legacyPrefix.length());
5656
}
57+
return name;
58+
}
59+
60+
@Platforms(Platform.HOSTED_ONLY.class)
61+
static CollectionPolicy getInitialPolicy() {
62+
String name = getInitialPolicyName();
5763
switch (name) {
5864
case "Adaptive":
5965
return new AdaptiveCollectionPolicy();
@@ -71,6 +77,15 @@ static CollectionPolicy getInitialPolicy() {
7177
throw UserError.abort("Policy %s does not exist.", name);
7278
}
7379

80+
@Platforms(Platform.HOSTED_ONLY.class)
81+
static int getMaxSurvivorSpaces(Integer optionValue) {
82+
String name = getInitialPolicyName();
83+
if ("Adaptive".equals(name) || "Proportionate".equals(name)) {
84+
return AbstractCollectionPolicy.getMaxSurvivorSpaces(optionValue);
85+
}
86+
return BasicCollectionPolicies.getMaxSurvivorSpaces(optionValue);
87+
}
88+
7489
String getName();
7590

7691
/**

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
package com.oracle.svm.core.genscavenge;
2626

2727
import org.graalvm.collections.EconomicMap;
28+
import org.graalvm.collections.UnmodifiableEconomicMap;
2829
import org.graalvm.compiler.api.replacements.Fold;
2930
import org.graalvm.compiler.options.Option;
3031
import org.graalvm.compiler.options.OptionKey;
32+
import org.graalvm.compiler.options.OptionValues;
3133
import org.graalvm.compiler.word.Word;
3234
import org.graalvm.nativeimage.Platform;
3335
import org.graalvm.nativeimage.Platforms;
@@ -81,7 +83,20 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Long oldV
8183
public static final RuntimeOptionKey<Boolean> TraceHeapChunks = new RuntimeOptionKey<>(false);
8284

8385
@Option(help = "Maximum number of survivor spaces.") //
84-
public static final HostedOptionKey<Integer> MaxSurvivorSpaces = new HostedOptionKey<>(15);
86+
public static final HostedOptionKey<Integer> MaxSurvivorSpaces = new HostedOptionKey<Integer>(15) {
87+
@Override
88+
public Integer getValueOrDefault(UnmodifiableEconomicMap<OptionKey<?>, Object> values) {
89+
Integer value = (Integer) values.get(this);
90+
UserError.guarantee(value == null || value >= 0, "%s value must be greater than or equal to 0", getName());
91+
return CollectionPolicy.getMaxSurvivorSpaces(value);
92+
}
93+
94+
@Override
95+
public Integer getValue(OptionValues values) {
96+
assert checkDescriptorExists();
97+
return getValueOrDefault(values.getMap());
98+
}
99+
};
85100

86101
@Option(help = "Determines if a full GC collects the young generation separately or together with the old generation.") //
87102
public static final RuntimeOptionKey<Boolean> CollectYoungGenerationSeparately = new RuntimeOptionKey<>(false);

0 commit comments

Comments
 (0)