5252import com .oracle .svm .core .genscavenge .UnalignedHeapChunk .UnalignedHeader ;
5353import com .oracle .svm .core .genscavenge .graal .nodes .FormatArrayNode ;
5454import com .oracle .svm .core .genscavenge .graal .nodes .FormatObjectNode ;
55+ import com .oracle .svm .core .genscavenge .graal .nodes .FormatPodNode ;
5556import com .oracle .svm .core .graal .snippets .DeoptTester ;
5657import com .oracle .svm .core .heap .OutOfMemoryUtil ;
5758import 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