diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ThreadLocalAllocation.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ThreadLocalAllocation.java index 9535f996f5b04..a1c44fce4de3a 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ThreadLocalAllocation.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ThreadLocalAllocation.java @@ -323,11 +323,17 @@ private static Object slowPathNewArrayLikeObjectWithoutAllocation0(DynamicHub hu Object array; if (!GenScavengeAllocationSupport.shouldAllocateInAlignedChunk(size)) { /* - * Large arrays go into their own unaligned chunk. Only arrays and stored continuations - * may be allocated in an unaligned chunk. + * Large arrays go into their own unaligned chunk. + * + * Instance objects with object reference fields, including hybrid objects such as pods, + * must not be allocated in unaligned chunks because field write barriers assume an + * aligned chunk. */ int layoutEncoding = hub.getLayoutEncoding(); - assert LayoutEncoding.isArray(layoutEncoding) || StoredContinuation.class.isAssignableFrom(DynamicHub.toClass(hub)); + if (!LayoutEncoding.isArray(layoutEncoding) && !StoredContinuation.class.isAssignableFrom(DynamicHub.toClass(hub))) { + throw VMError.shouldNotReachHere("Only arrays and StoredContinuation may be allocated in an unaligned chunk. " + + "Hybrid objects such as pods must be small enough to be allocated in an aligned chunk."); + } boolean needsZeroing = !HeapChunkProvider.areUnalignedChunksZeroed(); UnalignedHeapChunk.UnalignedHeader newTlabChunk = HeapImpl.getChunkProvider().produceUnalignedChunk(size); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/StoredContinuation.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/StoredContinuation.java index 2b9761c60e71e..a904321bcc313 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/StoredContinuation.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/StoredContinuation.java @@ -36,7 +36,12 @@ * * Stored continuations are {@link Hybrid} objects where the array part contains the raw stack data. * After writing the stack data into the object, we manually emit the correct GC write barriers for - * all the references (see {@link Heap#dirtyAllReferencesOf}). + * all the references (see {@link Heap#dirtyAllReferencesOf}). Following initialization, an object + * is considered effectively immutable, and only GC is expected to write the references it contains. + * Therefore, implicit write barriers intentionally do not support stored continuations, and they + * cannot have declared object reference fields. + * + * Objects of this type can reside in unaligned chunks. */ @Hybrid(componentType = Word.class) public final class StoredContinuation {