Skip to content

Commit 0738b01

Browse files
committed
Fully initialize pods in allocation snippet or slow path.
1 parent abd76a6 commit 0738b01

File tree

7 files changed

+364
-71
lines changed

7 files changed

+364
-71
lines changed

compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/AllocationSnippets.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected Object newMultiArrayImpl(Word hub, int rank, int[] dimensions) {
112112
return callNewMultiArrayStub(hub, rank, dims);
113113
}
114114

115-
private UnsignedWord arrayAllocationSize(int length, int arrayBaseOffset, int log2ElementSize) {
115+
protected UnsignedWord arrayAllocationSize(int length, int arrayBaseOffset, int log2ElementSize) {
116116
int alignment = objectAlignment();
117117
return WordFactory.unsigned(arrayAllocationSize(length, arrayBaseOffset, log2ElementSize, alignment));
118118
}
@@ -379,7 +379,7 @@ public static FillContent fromBoolean(boolean fillContents) {
379379
}
380380

381381
public static class AllocationProfilingData {
382-
final AllocationSnippetCounters snippetCounters;
382+
public final AllocationSnippetCounters snippetCounters;
383383

384384
public AllocationProfilingData(AllocationSnippetCounters snippetCounters) {
385385
this.snippetCounters = snippetCounters;
@@ -395,9 +395,9 @@ public AllocationSnippetCounters(SnippetCounter.Group.Factory factory) {
395395
stub = new SnippetCounter(allocations, "stub", "alloc and zeroing via stub");
396396
}
397397

398-
final SnippetCounter unrolledInit;
399-
final SnippetCounter loopInit;
400-
final SnippetCounter bulkInit;
401-
final SnippetCounter stub;
398+
public final SnippetCounter unrolledInit;
399+
public final SnippetCounter loopInit;
400+
public final SnippetCounter bulkInit;
401+
public final SnippetCounter stub;
402402
}
403403
}

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.oracle.svm.core.genscavenge.UnalignedHeapChunk.UnalignedHeader;
5353
import com.oracle.svm.core.genscavenge.graal.nodes.FormatArrayNode;
5454
import com.oracle.svm.core.genscavenge.graal.nodes.FormatObjectNode;
55+
import com.oracle.svm.core.genscavenge.graal.nodes.FormatPodNode;
5556
import com.oracle.svm.core.graal.snippets.DeoptTester;
5657
import com.oracle.svm.core.heap.OutOfMemoryUtil;
5758
import com.oracle.svm.core.hub.DynamicHub;
@@ -223,6 +224,15 @@ private static Object slowPathNewInstanceWithoutAllocating(DynamicHub hub) {
223224

224225
@SubstrateForeignCallTarget(stubCallingConvention = false)
225226
private static Object slowPathNewArray(Word objectHeader, int length, int fillStartOffset) {
227+
return slowPathNewArrayImpl(objectHeader, length, fillStartOffset, null);
228+
}
229+
230+
@SubstrateForeignCallTarget(stubCallingConvention = false)
231+
private static Object slowPathNewPodInstance(Word objectHeader, int sizeWithoutRefMap, int fillStartOffset, byte[] referenceMap) {
232+
return slowPathNewArrayImpl(objectHeader, sizeWithoutRefMap, fillStartOffset, referenceMap);
233+
}
234+
235+
private static Object slowPathNewArrayImpl(Word objectHeader, int length, int fillStartOffset, byte[] podReferenceMap) {
226236
/*
227237
* Avoid stack overflow errors while producing memory chunks, because that could leave the
228238
* heap in an inconsistent state.
@@ -246,7 +256,7 @@ private static Object slowPathNewArray(Word objectHeader, int length, int fillSt
246256
throw OutOfMemoryUtil.reportOutOfMemoryError(outOfMemoryError);
247257
}
248258

249-
Object result = slowPathNewArrayWithoutAllocating(hub, length, size, fillStartOffset);
259+
Object result = slowPathNewArrayWithoutAllocating(hub, length, size, fillStartOffset, podReferenceMap);
250260
runSlowPathHooks();
251261
return result;
252262
} finally {
@@ -255,7 +265,7 @@ private static Object slowPathNewArray(Word objectHeader, int length, int fillSt
255265
}
256266

257267
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not allocate in the implementation of allocation.")
258-
private static Object slowPathNewArrayWithoutAllocating(DynamicHub hub, int length, UnsignedWord size, int fillStartOffset) {
268+
private static Object slowPathNewArrayWithoutAllocating(DynamicHub hub, int length, UnsignedWord size, int fillStartOffset, byte[] podReferenceMap) {
259269
DeoptTester.disableDeoptTesting();
260270
try {
261271
HeapImpl.exitIfAllocationDisallowed("ThreadLocalAllocation.slowPathNewArrayWithoutAllocating", DynamicHub.toClass(hub).getName());
@@ -265,16 +275,16 @@ private static Object slowPathNewArrayWithoutAllocating(DynamicHub hub, int leng
265275
/* Large arrays go into their own unaligned chunk. */
266276
boolean needsZeroing = !HeapChunkProvider.areUnalignedChunksZeroed();
267277
UnalignedHeapChunk.UnalignedHeader newTlabChunk = HeapImpl.getChunkProvider().produceUnalignedChunk(size);
268-
return allocateLargeArrayInNewTlab(hub, length, size, fillStartOffset, newTlabChunk, needsZeroing);
278+
return allocateLargeArrayInNewTlab(hub, length, size, fillStartOffset, newTlabChunk, needsZeroing, podReferenceMap);
269279
}
270280
/* Small arrays go into the regular aligned chunk. */
271281

272282
// We might have allocated in the caller and acquired a TLAB with enough space already
273283
// (but we need to check in an uninterruptible method to be safe)
274-
Object array = allocateSmallArrayInCurrentTlab(hub, length, size, fillStartOffset);
284+
Object array = allocateSmallArrayInCurrentTlab(hub, length, size, fillStartOffset, podReferenceMap);
275285
if (array == null) { // We need a new chunk.
276286
AlignedHeader newTlabChunk = HeapImpl.getChunkProvider().produceAlignedChunk();
277-
array = allocateSmallArrayInNewTlab(hub, length, size, fillStartOffset, newTlabChunk);
287+
array = allocateSmallArrayInNewTlab(hub, length, size, fillStartOffset, newTlabChunk, podReferenceMap);
278288
}
279289
return array;
280290
} finally {
@@ -290,22 +300,22 @@ private static Object allocateInstanceInNewTlab(DynamicHub hub, AlignedHeader ne
290300
}
291301

292302
@Uninterruptible(reason = "Holds uninitialized memory.")
293-
private static Object allocateSmallArrayInCurrentTlab(DynamicHub hub, int length, UnsignedWord size, int fillStartOffset) {
303+
private static Object allocateSmallArrayInCurrentTlab(DynamicHub hub, int length, UnsignedWord size, int fillStartOffset, byte[] podReferenceMap) {
294304
if (size.aboveThan(availableTlabMemory(getTlab()))) {
295305
return null;
296306
}
297307
Pointer memory = allocateRawMemoryInTlab(size, getTlab());
298-
return FormatArrayNode.formatArray(memory, DynamicHub.toClass(hub), length, false, false, FillContent.WITH_ZEROES, fillStartOffset, true);
308+
return formatArrayOrPod(memory, hub, length, false, FillContent.WITH_ZEROES, fillStartOffset, podReferenceMap);
299309
}
300310

301311
@Uninterruptible(reason = "Holds uninitialized memory.")
302-
private static Object allocateSmallArrayInNewTlab(DynamicHub hub, int length, UnsignedWord size, int fillStartOffset, AlignedHeader newTlabChunk) {
312+
private static Object allocateSmallArrayInNewTlab(DynamicHub hub, int length, UnsignedWord size, int fillStartOffset, AlignedHeader newTlabChunk, byte[] podReferenceMap) {
303313
Pointer memory = allocateRawMemoryInNewTlab(size, newTlabChunk);
304-
return FormatArrayNode.formatArray(memory, DynamicHub.toClass(hub), length, false, false, FillContent.WITH_ZEROES, fillStartOffset, true);
314+
return formatArrayOrPod(memory, hub, length, false, FillContent.WITH_ZEROES, fillStartOffset, podReferenceMap);
305315
}
306316

307317
@Uninterruptible(reason = "Holds uninitialized memory, modifies TLAB")
308-
private static Object allocateLargeArrayInNewTlab(DynamicHub hub, int length, UnsignedWord size, int fillStartOffset, UnalignedHeapChunk.UnalignedHeader newTlabChunk, boolean needsZeroing) {
318+
private static Object allocateLargeArrayInNewTlab(DynamicHub hub, int length, UnsignedWord size, int fillStartOffset, UnalignedHeader newTlabChunk, boolean needsZeroing, byte[] podReferenceMap) {
309319
ThreadLocalAllocation.Descriptor tlab = getTlab();
310320

311321
HeapChunk.setNext(newTlabChunk, tlab.getUnalignedChunk());
@@ -327,7 +337,16 @@ private static Object allocateLargeArrayInNewTlab(DynamicHub hub, int length, Un
327337
* any way.
328338
*/
329339
FillContent fillKind = needsZeroing ? FillContent.WITH_ZEROES : FillContent.DO_NOT_FILL;
330-
return FormatArrayNode.formatArray(memory, DynamicHub.toClass(hub), length, false, true, fillKind, fillStartOffset, true);
340+
return formatArrayOrPod(memory, hub, length, true, fillKind, fillStartOffset, podReferenceMap);
341+
}
342+
343+
@Uninterruptible(reason = "Holds uninitialized memory")
344+
private static Object formatArrayOrPod(Pointer memory, DynamicHub hub, int length, boolean unaligned, FillContent fillContent, int fillStartOffset, byte[] podReferenceMap) {
345+
Class<?> clazz = DynamicHub.toClass(hub);
346+
if (podReferenceMap != null) {
347+
return FormatPodNode.formatPod(memory, clazz, length, podReferenceMap, false, unaligned, fillStartOffset, true);
348+
}
349+
return FormatArrayNode.formatArray(memory, clazz, length, false, unaligned, fillContent, fillStartOffset, true);
331350
}
332351

333352
@Uninterruptible(reason = "Returns uninitialized memory, modifies TLAB", callerMustBe = true)

0 commit comments

Comments
 (0)