Skip to content

Commit d0322f8

Browse files
committed
[GR-48695] Backport to 23.0: Uncommitting of memory failed - should not reach here.
PullRequest: graal/15886
2 parents 5cecedb + 9929dac commit d0322f8

File tree

8 files changed

+36
-14
lines changed

8 files changed

+36
-14
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ static UnsignedWord getAlignedHeapChunkAlignment() {
123123
return getAlignedHeapChunkSize();
124124
}
125125

126+
@Fold
127+
public static UnsignedWord getMinUnalignedChunkSize() {
128+
return UnalignedHeapChunk.getChunkSizeForObject(HeapParameters.getLargeArrayThreshold());
129+
}
130+
126131
@Fold
127132
public static UnsignedWord getLargeArrayThreshold() {
128133
long largeArrayThreshold = SerialAndEpsilonGCOptions.LargeArrayThreshold.getValue();

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ public static Pointer getObjectEnd(UnalignedHeader that) {
105105
return HeapChunk.getEndPointer(that);
106106
}
107107

108-
public static UnsignedWord getOverhead() {
109-
return getObjectStartOffset();
110-
}
111-
112108
static UnsignedWord getChunkSizeForObject(UnsignedWord objectSize) {
113109
UnsignedWord objectStart = getObjectStartOffset();
114110
UnsignedWord alignment = WordFactory.unsigned(ConfigurationValues.getObjectLayout().getAlignment());

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/CEntryPointErrors.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ private CEntryPointErrors() {
5959
@Description("An argument was NULL.") //
6060
public static final int NULL_ARGUMENT = 2;
6161

62+
@Description("Memory allocation failed, the OS is probably out of memory.") //
63+
public static final int ALLOCATION_FAILED = 3;
64+
6265
@Description("The specified thread is not attached to the isolate.") //
6366
public static final int UNATTACHED_THREAD = 4;
6467

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/AbstractRuntimeCodeInstaller.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ protected Pointer allocateCodeMemory(long size) {
4747
}
4848

4949
protected void makeCodeMemoryExecutableReadOnly(Pointer start, UnsignedWord size) {
50-
RuntimeCodeInfoAccess.makeCodeMemoryExecutableReadOnly((CodePointer) start, size);
50+
int result = RuntimeCodeInfoAccess.makeCodeMemoryExecutableReadOnly((CodePointer) start, size);
51+
VMError.guarantee(result == 0, "Failed to make code memory read only.");
5152
}
5253

5354
protected void makeCodeMemoryExecutableWritable(Pointer start, UnsignedWord size) {
54-
RuntimeCodeInfoAccess.makeCodeMemoryExecutableWritable((CodePointer) start, size);
55+
int result = RuntimeCodeInfoAccess.makeCodeMemoryExecutableWritable((CodePointer) start, size);
56+
VMError.guarantee(result == 0, "Failed to make code memory writable.");
5557
}
5658

5759
protected static void doInstallPrepared(SharedMethod method, CodeInfo codeInfo, SubstrateInstalledCode installedCode) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/AbstractCommittedMemoryProvider.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.oracle.svm.core.Uninterruptible;
4343
import com.oracle.svm.core.c.function.CEntryPointErrors;
4444
import com.oracle.svm.core.code.RuntimeCodeCache;
45+
import com.oracle.svm.core.config.ConfigurationValues;
4546
import com.oracle.svm.core.heap.Heap;
4647
import com.oracle.svm.core.util.UnsignedUtils;
4748
import com.oracle.svm.core.util.VMError;
@@ -109,7 +110,7 @@ public Pointer allocateAlignedChunk(UnsignedWord nbytes, UnsignedWord alignment)
109110

110111
@Override
111112
public Pointer allocateUnalignedChunk(UnsignedWord nbytes) {
112-
return allocate(nbytes, WordFactory.unsigned(1), false);
113+
return allocate(nbytes, getAlignmentForUnalignedChunks(), false);
113114
}
114115

115116
@Override
@@ -172,6 +173,16 @@ private void free(PointerBase start, UnsignedWord nbytes) {
172173
}
173174
}
174175

176+
/**
177+
* Unaligned chunks also need some minimal alignment - otherwise, the data in the chunk header
178+
* or the Java heap object within the unaligned chunk would be misaligned.
179+
*/
180+
@Fold
181+
protected static UnsignedWord getAlignmentForUnalignedChunks() {
182+
int alignment = Math.max(ConfigurationValues.getTarget().wordSize, ConfigurationValues.getObjectLayout().getAlignment());
183+
return WordFactory.unsigned(alignment);
184+
}
185+
175186
private final VirtualMemoryTracker tracker = new VirtualMemoryTracker();
176187

177188
public static class VirtualMemoryTracker {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/os/CommittedMemoryProvider.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.graalvm.word.Pointer;
3333
import org.graalvm.word.PointerBase;
3434
import org.graalvm.word.UnsignedWord;
35-
import org.graalvm.word.WordFactory;
3635

3736
import com.oracle.svm.core.Uninterruptible;
3837
import com.oracle.svm.core.c.function.CEntryPointCreateIsolateParameters;
@@ -43,12 +42,6 @@
4342
* memory or swap space.
4443
*/
4544
public interface CommittedMemoryProvider {
46-
/**
47-
* Value for alignment parameters that indicates that no specific alignment is required (other
48-
* than the {@linkplain #getGranularity() granularity} usually).
49-
*/
50-
UnsignedWord UNALIGNED = WordFactory.unsigned(1);
51-
5245
@Fold
5346
static CommittedMemoryProvider get() {
5447
return ImageSingletons.lookup(CommittedMemoryProvider.class);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/PointerUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public static UnsignedWord absoluteDifference(PointerBase pointer1, PointerBase
101101
* @param y Another Pointer.
102102
* @return The whichever Pointer is smaller.
103103
*/
104+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
104105
public static <T extends PointerBase> T min(T x, T y) {
105106
return (((Pointer) x).belowOrEqual((Pointer) y)) ? x : y;
106107
}
@@ -112,6 +113,7 @@ public static <T extends PointerBase> T min(T x, T y) {
112113
* @param y Another Pointer.
113114
* @return The whichever Pointer is larger.
114115
*/
116+
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
115117
public static <T extends PointerBase> T max(T x, T y) {
116118
return (((Pointer) x).aboveOrEqual((Pointer) y)) ? x : y;
117119
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/VMError.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public static final class HostedError extends Error {
6464

6565
}
6666

67+
public static final String msgShouldNotReachHere = "should not reach here";
68+
public static final String msgShouldNotReachHereAtRuntime = msgShouldNotReachHere + ": this code is expected to be unreachable at runtime";
69+
6770
public static RuntimeException shouldNotReachHere() {
6871
throw new HostedError("should not reach here");
6972
}
@@ -80,6 +83,13 @@ public static RuntimeException shouldNotReachHere(String msg, Throwable cause) {
8083
throw new HostedError(msg, cause);
8184
}
8285

86+
/**
87+
* A hardcoded list of options (if, switch) did not handle the case actually provided.
88+
*/
89+
public static RuntimeException shouldNotReachHereAtRuntime() {
90+
throw new HostedError(msgShouldNotReachHereAtRuntime);
91+
}
92+
8393
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
8494
public static void guarantee(boolean condition) {
8595
if (!condition) {

0 commit comments

Comments
 (0)