Skip to content

Commit 9ad4082

Browse files
committed
Update heap sizes after a relevant runtime option value changes.
1 parent 518b8bc commit 9ad4082

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ static boolean shouldCollectYoungGenSeparately(boolean defaultValue) {
102102

103103
/**
104104
* (Re)computes minimum/maximum/initial sizes of space based on the available
105-
* {@linkplain PhysicalMemory physical memory} and current runtime option values. This method is
106-
* called after slow-path allocation (of a TLAB or a large object) and so allocation is allowed,
107-
* but can trigger a collection.
105+
* {@linkplain PhysicalMemory physical memory} and current runtime option values. This method
106+
* can be called directly or after a slow-path allocation (of a TLAB or a large object) and so
107+
* allocation is allowed, but may trigger a collection.
108108
*/
109109
void updateSizeParameters();
110110

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ public boolean printLocationInfo(Log log, UnsignedWord value, boolean allowJavaH
638638
return false;
639639
}
640640

641+
@Override
642+
public void updateSizeParameters() {
643+
GCImpl.getPolicy().updateSizeParameters();
644+
}
645+
641646
static Pointer getImageHeapStart() {
642647
int imageHeapOffsetInAddressSpace = Heap.getHeap().getImageHeapOffsetInAddressSpace();
643648
if (imageHeapOffsetInAddressSpace > 0) {
@@ -846,7 +851,7 @@ private long totalMemory() {
846851
@Substitute
847852
private long maxMemory() {
848853
PhysicalMemory.size(); // ensure physical memory size is set correctly and not estimated
849-
GCImpl.getPolicy().updateSizeParameters();
854+
Heap.getHeap().updateSizeParameters();
850855
return GCImpl.getPolicy().getMaximumHeapSize().rawValue();
851856
}
852857

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.oracle.svm.core.SubstrateGCOptions;
4040
import com.oracle.svm.core.SubstrateUtil;
4141
import com.oracle.svm.core.annotate.Uninterruptible;
42+
import com.oracle.svm.core.heap.Heap;
4243
import com.oracle.svm.core.option.HostedOptionKey;
4344
import com.oracle.svm.core.option.RuntimeOptionKey;
4445
import com.oracle.svm.core.option.RuntimeOptionValues;
@@ -48,11 +49,24 @@
4849
/** Constants and variables for the size and layout of the heap and behavior of the collector. */
4950
public final class HeapParameters {
5051
public static final class Options {
52+
static final class HeapSizeOptionKey<T> extends RuntimeOptionKey<T> {
53+
HeapSizeOptionKey(T defaultValue) {
54+
super(defaultValue);
55+
}
56+
57+
@Override
58+
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, T oldValue, T newValue) {
59+
if (!SubstrateUtil.HOSTED) {
60+
Heap.getHeap().updateSizeParameters();
61+
}
62+
}
63+
}
64+
5165
@Option(help = "The maximum heap size as percent of physical memory") //
52-
public static final RuntimeOptionKey<Integer> MaximumHeapSizePercent = new RuntimeOptionKey<>(80);
66+
public static final RuntimeOptionKey<Integer> MaximumHeapSizePercent = new HeapSizeOptionKey<>(80);
5367

5468
@Option(help = "The maximum size of the young generation as a percentage of the maximum heap size") //
55-
public static final RuntimeOptionKey<Integer> MaximumYoungGenerationSizePercent = new RuntimeOptionKey<>(10);
69+
public static final RuntimeOptionKey<Integer> MaximumYoungGenerationSizePercent = new HeapSizeOptionKey<>(10);
5670

5771
@Option(help = "The size of an aligned chunk.") //
5872
public static final HostedOptionKey<Long> AlignedHeapChunkSize = new HostedOptionKey<Long>(1L * 1024L * 1024L) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateGCOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.graalvm.compiler.options.OptionType;
3131
import org.graalvm.word.WordFactory;
3232

33+
import com.oracle.svm.core.heap.Heap;
3334
import com.oracle.svm.core.heap.HeapSizeVerifier;
3435
import com.oracle.svm.core.option.HostedOptionKey;
3536
import com.oracle.svm.core.option.RuntimeOptionKey;
@@ -59,6 +60,7 @@ public class SubstrateGCOptions {
5960
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Long oldValue, Long newValue) {
6061
if (!SubstrateUtil.HOSTED) {
6162
HeapSizeVerifier.verifyMinHeapSizeAgainstAddressSpace(WordFactory.unsigned(newValue));
63+
Heap.getHeap().updateSizeParameters();
6264
}
6365
}
6466
};
@@ -69,6 +71,7 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Long oldV
6971
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Long oldValue, Long newValue) {
7072
if (!SubstrateUtil.HOSTED) {
7173
HeapSizeVerifier.verifyMaxHeapSizeAgainstAddressSpace(WordFactory.unsigned(newValue));
74+
Heap.getHeap().updateSizeParameters();
7275
}
7376
}
7477
};
@@ -79,6 +82,7 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Long oldV
7982
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Long oldValue, Long newValue) {
8083
if (!SubstrateUtil.HOSTED) {
8184
HeapSizeVerifier.verifyMaxNewSizeAgainstAddressSpace(WordFactory.unsigned(newValue));
85+
Heap.getHeap().updateSizeParameters();
8286
}
8387
}
8488
};

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/Heap.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,10 @@ public List<Class<?>> getLoadedClasses() {
217217
* value and returns true. Otherwise, the method returns false.
218218
*/
219219
public abstract boolean printLocationInfo(Log log, UnsignedWord value, boolean allowJavaHeapAccess, boolean allowUnsafeOperations);
220+
221+
/**
222+
* (Re)computes minimum/maximum/initial sizes of space based on the available
223+
* {@linkplain PhysicalMemory physical memory} and current runtime option values.
224+
*/
225+
public abstract void updateSizeParameters();
220226
}

0 commit comments

Comments
 (0)