Skip to content

Commit f5d7bd7

Browse files
Make the null region optional.
1 parent c956846 commit f5d7bd7

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public int getPreferredAddressSpaceAlignment() {
431431
@Fold
432432
@Override
433433
public int getImageHeapOffsetInAddressSpace() {
434-
if (SubstrateOptions.SpawnIsolates.getValue() && CommittedMemoryProvider.get().guaranteesHeapPreferredAddressSpaceAlignment()) {
434+
if (SubstrateOptions.SpawnIsolates.getValue() && SubstrateOptions.UseNullRegion.getValue() && CommittedMemoryProvider.get().guaranteesHeapPreferredAddressSpaceAlignment()) {
435435
/*
436436
* The image heap will be mapped in a way that there is a memory protected gap between
437437
* the heap base and the start of the image heap. The gap won't need any memory in the
@@ -445,7 +445,7 @@ public int getImageHeapOffsetInAddressSpace() {
445445
@Fold
446446
@Override
447447
public int getImageHeapNullRegionSize() {
448-
if (SubstrateOptions.SpawnIsolates.getValue() && !CommittedMemoryProvider.get().guaranteesHeapPreferredAddressSpaceAlignment()) {
448+
if (SubstrateOptions.SpawnIsolates.getValue() && SubstrateOptions.UseNullRegion.getValue() && !CommittedMemoryProvider.get().guaranteesHeapPreferredAddressSpaceAlignment()) {
449449
/*
450450
* Prepend a single null page to the image heap so that there is a memory protected gap
451451
* between the heap base and the start of the image heap. The null page is placed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package com.oracle.svm.core.genscavenge;
2626

27+
import com.oracle.svm.core.config.ConfigurationValues;
2728
import com.oracle.svm.core.heap.Heap;
2829
import com.oracle.svm.core.image.ImageHeap;
2930
import com.oracle.svm.core.image.ImageHeapLayoutInfo;
@@ -34,7 +35,9 @@ public class LinearImageHeapLayouter extends AbstractImageHeapLayouter<LinearIma
3435
private final int nullRegionSize;
3536

3637
public LinearImageHeapLayouter(ImageHeapInfo heapInfo, long startOffset, int nullRegionSize) {
38+
assert startOffset >= 0;
3739
assert startOffset == 0 || startOffset >= Heap.getHeap().getImageHeapOffsetInAddressSpace() : "must be relative to the heap base";
40+
assert nullRegionSize >= 0;
3841
this.heapInfo = heapInfo;
3942
this.startOffset = startOffset;
4043
this.nullRegionSize = nullRegionSize;
@@ -52,8 +55,8 @@ protected LinearImageHeapPartition createPartition(String name, boolean contains
5255

5356
@Override
5457
protected ImageHeapLayoutInfo doLayout(ImageHeap imageHeap) {
55-
long beginOffset = startOffset;
56-
beginOffset += nullRegionSize;
58+
long beginOffset = startOffset + spaceReservedForNull();
59+
assert beginOffset >= ConfigurationValues.getObjectLayout().getAlignment() : "Zero designates null";
5760
LinearImageHeapAllocator allocator = new LinearImageHeapAllocator(beginOffset);
5861
for (LinearImageHeapPartition partition : getPartitions()) {
5962
partition.allocateObjects(allocator);
@@ -62,6 +65,13 @@ protected ImageHeapLayoutInfo doLayout(ImageHeap imageHeap) {
6265
return createLayoutInfo(startOffset, getWritablePrimitive().getStartOffset());
6366
}
6467

68+
private long spaceReservedForNull() {
69+
if (startOffset == 0 && nullRegionSize == 0) {
70+
return ConfigurationValues.getObjectLayout().getAlignment();
71+
}
72+
return nullRegionSize;
73+
}
74+
6575
/**
6676
* Store which objects are at the boundaries of the image heap partitions. Here, we also merge
6777
* the read-only reference partition with the read-only relocatable partition.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ public static boolean useLLVMBackend() {
428428
@Option(help = "When set to true, the image generator verifies that the image heap does not contain a home directory as a substring", type = User)//
429429
public static final HostedOptionKey<Boolean> DetectUserDirectoriesInImageHeap = new HostedOptionKey<>(false);
430430

431+
@Option(help = "Determines if a null region is present between the heap base and the image heap.", type = Expert)//
432+
public static final HostedOptionKey<Boolean> UseNullRegion = new HostedOptionKey<>(true);
433+
431434
@Option(help = "The interval in minutes between watchdog checks (0 disables the watchdog)", type = OptionType.Expert)//
432435
public static final HostedOptionKey<Integer> DeadlockWatchdogInterval = new HostedOptionKey<>(10);
433436
@Option(help = "Exit the image builder VM after printing call stacks", type = OptionType.Expert)//

0 commit comments

Comments
 (0)