@@ -257,45 +257,48 @@ MM_VLHGCAccessBarrier::jniGetPrimitiveArrayCritical(J9VMThread* vmThread, jarray
257
257
J9JavaVM *javaVM = vmThread->javaVM ;
258
258
J9InternalVMFunctions *functions = javaVM->internalVMFunctions ;
259
259
VM_VMAccess::inlineEnterVMFromJNI (vmThread);
260
+ GC_ArrayObjectModel *indexableObjectModel = &_extensions->indexableObjectModel ;
260
261
261
262
J9IndexableObject *arrayObject = (J9IndexableObject*)J9_JNI_UNWRAP_REFERENCE (array);
262
263
bool shouldCopy = false ;
263
264
bool alwaysCopyInCritical = (javaVM->runtimeFlags & J9_RUNTIME_ALWAYS_COPY_JNI_CRITICAL) == J9_RUNTIME_ALWAYS_COPY_JNI_CRITICAL;
264
265
if (alwaysCopyInCritical) {
265
266
shouldCopy = true ;
266
- } else if (!_extensions-> indexableObjectModel . isInlineContiguousArraylet (arrayObject)) {
267
+ } else if (!indexableObjectModel-> isInlineContiguousArraylet (arrayObject)) {
267
268
/* an array having discontiguous extents is another reason to force the critical section to be a copy */
268
269
shouldCopy = true ;
269
270
}
270
271
271
272
#if defined(J9VM_GC_ENABLE_DOUBLE_MAP)
272
- bool successDoubleMap = false ;
273
- if (shouldCopy && _extensions->indexableObjectModel .isDoubleMappingEnabled ()) {
274
- if (_extensions->indexableObjectModel .numArraylets (arrayObject) > 1 ) {
275
- J9Object *firstLeafSlot = (J9Object *)((uintptr_t )_extensions->indexableObjectModel .getArrayoidPointer (arrayObject)[0 ]);
273
+ MM_EnvironmentVLHGC *env = MM_EnvironmentVLHGC::getEnvironment (vmThread);
274
+ bool contiguousDataAvailable = false ;
275
+ if (shouldCopy && indexableObjectModel->isDoubleMappingEnabled ()) {
276
+ if (indexableObjectModel->numArraylets (arrayObject) > 1 ) {
277
+ GC_SlotObject objectSlot (env->getOmrVM (), &indexableObjectModel->getArrayoidPointer (arrayObject)[0 ]);
278
+ J9Object *firstLeafSlot = objectSlot.readReferenceFromSlot ();
276
279
MM_HeapRegionDescriptorVLHGC *firstLeafRegionDescriptor = (MM_HeapRegionDescriptorVLHGC *)_extensions->heapRegionManager ->tableDescriptorForAddress (firstLeafSlot);
277
280
data = firstLeafRegionDescriptor->_identifier .address ;
278
281
279
282
if (NULL == data) {
280
283
/* Doublemap failed, but we still need to continue execution; therefore fallback to previous approach */
281
- successDoubleMap = false ;
284
+ contiguousDataAvailable = false ;
282
285
} else {
283
- successDoubleMap = true ;
286
+ contiguousDataAvailable = true ;
284
287
}
285
288
/* Corner case where there's only one arraylet leaf */
286
- } else if (_extensions-> indexableObjectModel . numArraylets (arrayObject) == 1 && _extensions-> indexableObjectModel . getSizeInElements (arrayObject) > 0 ) {
289
+ } else if (indexableObjectModel-> numArraylets (arrayObject) == 1 && indexableObjectModel-> getSizeInElements (arrayObject) > 0 ) {
287
290
/* Solo arraylet leaf is contiguous so we can simply return the data associated with it */
288
291
MM_JNICriticalRegion::enterCriticalRegion (vmThread, true );
289
292
Assert_MM_true (vmThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS);
290
- data = (J9Object *)((uintptr_t )_extensions->indexableObjectModel .getArrayoidPointer (arrayObject)[0 ]);
291
- successDoubleMap = true ;
293
+ GC_SlotObject objectSlot (env->getOmrVM (), &indexableObjectModel->getArrayoidPointer (arrayObject)[0 ]);
294
+ data = objectSlot.readReferenceFromSlot ();
295
+ contiguousDataAvailable = true ;
292
296
}
293
297
}
294
- if (!successDoubleMap )
298
+ if (!contiguousDataAvailable )
295
299
#endif /* J9VM_GC_ENABLE_DOUBLE_MAP */
296
300
{
297
301
if (shouldCopy) {
298
- GC_ArrayObjectModel* indexableObjectModel = &_extensions->indexableObjectModel ;
299
302
I_32 sizeInElements = (I_32)indexableObjectModel->getSizeInElements (arrayObject);
300
303
UDATA sizeInBytes = indexableObjectModel->getDataSizeInBytes (arrayObject);
301
304
data = functions->jniArrayAllocateMemoryFromThread (vmThread, sizeInBytes);
@@ -313,7 +316,7 @@ MM_VLHGCAccessBarrier::jniGetPrimitiveArrayCritical(J9VMThread* vmThread, jarray
313
316
MM_JNICriticalRegion::enterCriticalRegion (vmThread, true );
314
317
Assert_MM_true (vmThread->publicFlags & J9_PUBLIC_FLAGS_VM_ACCESS);
315
318
arrayObject = (J9IndexableObject*)J9_JNI_UNWRAP_REFERENCE (array);
316
- data = (void *)_extensions-> indexableObjectModel . getDataPointerForContiguous (arrayObject);
319
+ data = (void *)indexableObjectModel-> getDataPointerForContiguous (arrayObject);
317
320
if (NULL != isCopy) {
318
321
*isCopy = JNI_FALSE;
319
322
}
@@ -334,34 +337,40 @@ MM_VLHGCAccessBarrier::jniReleasePrimitiveArrayCritical(J9VMThread* vmThread, ja
334
337
J9JavaVM *javaVM = vmThread->javaVM ;
335
338
J9InternalVMFunctions *functions = javaVM->internalVMFunctions ;
336
339
VM_VMAccess::inlineEnterVMFromJNI (vmThread);
340
+ GC_ArrayObjectModel *indexableObjectModel = &_extensions->indexableObjectModel ;
337
341
338
342
J9IndexableObject *arrayObject = (J9IndexableObject*)J9_JNI_UNWRAP_REFERENCE (array);
339
343
bool shouldCopy = false ;
340
344
bool alwaysCopyInCritical = (javaVM->runtimeFlags & J9_RUNTIME_ALWAYS_COPY_JNI_CRITICAL) == J9_RUNTIME_ALWAYS_COPY_JNI_CRITICAL;
341
345
if (alwaysCopyInCritical) {
342
346
shouldCopy = true ;
343
- } else if (!_extensions-> indexableObjectModel . isInlineContiguousArraylet (arrayObject)) {
347
+ } else if (!indexableObjectModel-> isInlineContiguousArraylet (arrayObject)) {
344
348
/* an array having discontiguous extents is another reason to force the critical section to be a copy */
345
349
shouldCopy = true ;
346
350
}
347
351
#if defined(J9VM_GC_ENABLE_DOUBLE_MAP)
352
+ MM_EnvironmentVLHGC *env = MM_EnvironmentVLHGC::getEnvironment (vmThread);
348
353
bool successfulDoubleMap = false ;
349
- if (shouldCopy && (_extensions-> indexableObjectModel . numArraylets (arrayObject) == 1 )
350
- && _extensions-> indexableObjectModel . isDoubleMappingEnabled ()
351
- && (_extensions-> indexableObjectModel . getSizeInElements (arrayObject) > 0 )) {
354
+ if (shouldCopy && (indexableObjectModel-> numArraylets (arrayObject) == 1 )
355
+ && indexableObjectModel-> isDoubleMappingEnabled ()
356
+ && (indexableObjectModel-> getSizeInElements (arrayObject) > 0 )) {
352
357
/*
353
358
* Objects can not be moved if critical section is active
354
359
* This trace point will be generated if object has been moved or passed value of elems is corrupted
355
360
*/
356
- void *data = (J9Object *)((uintptr_t )_extensions->indexableObjectModel .getArrayoidPointer (arrayObject)[0 ]);
361
+ GC_SlotObject objectSlot (env->getOmrVM (), &indexableObjectModel->getArrayoidPointer (arrayObject)[0 ]);
362
+ void *data = objectSlot.readReferenceFromSlot ();
363
+
357
364
if (elems != data) {
358
365
Trc_MM_JNIReleasePrimitiveArrayCritical_invalid (vmThread, arrayObject, elems, data);
359
366
}
360
367
successfulDoubleMap = true ;
361
368
MM_JNICriticalRegion::exitCriticalRegion (vmThread, true );
362
- } else if (shouldCopy && _extensions->indexableObjectModel .isDoubleMappingEnabled ()
363
- && (_extensions->indexableObjectModel .numArraylets (arrayObject) > 1 )) {
364
- J9Object *firstLeafSlot = (J9Object *)((uintptr_t )_extensions->indexableObjectModel .getArrayoidPointer (arrayObject)[0 ]);
369
+ } else if (shouldCopy && indexableObjectModel->isDoubleMappingEnabled ()
370
+ && (indexableObjectModel->numArraylets (arrayObject) > 1 )) {
371
+ GC_SlotObject objectSlot (env->getOmrVM (), &indexableObjectModel->getArrayoidPointer (arrayObject)[0 ]);
372
+ J9Object *firstLeafSlot = objectSlot.readReferenceFromSlot ();
373
+
365
374
MM_HeapRegionDescriptorVLHGC *firstLeafRegionDescriptor = (MM_HeapRegionDescriptorVLHGC *)_extensions->heapRegionManager ->tableDescriptorForAddress (firstLeafSlot);
366
375
367
376
if (NULL == firstLeafRegionDescriptor->_identifier .address ) {
@@ -376,9 +385,8 @@ MM_VLHGCAccessBarrier::jniReleasePrimitiveArrayCritical(J9VMThread* vmThread, ja
376
385
{
377
386
if (shouldCopy) {
378
387
if (JNI_ABORT != mode) {
379
- GC_ArrayObjectModel* indexableObjectModel = &_extensions->indexableObjectModel ;
380
388
I_32 sizeInElements = (I_32)indexableObjectModel->getSizeInElements (arrayObject);
381
- _extensions-> indexableObjectModel . memcpyToArray (arrayObject, 0 , sizeInElements, elems);
389
+ indexableObjectModel-> memcpyToArray (arrayObject, 0 , sizeInElements, elems);
382
390
}
383
391
384
392
// Commit means copy the data but do not free the buffer.
@@ -397,7 +405,7 @@ MM_VLHGCAccessBarrier::jniReleasePrimitiveArrayCritical(J9VMThread* vmThread, ja
397
405
* Objects can not be moved if critical section is active
398
406
* This trace point will be generated if object has been moved or passed value of elems is corrupted
399
407
*/
400
- void *data = (void *)_extensions-> indexableObjectModel . getDataPointerForContiguous (arrayObject);
408
+ void *data = (void *)indexableObjectModel-> getDataPointerForContiguous (arrayObject);
401
409
if (elems != data) {
402
410
Trc_MM_JNIReleasePrimitiveArrayCritical_invalid (vmThread, arrayObject, elems, data);
403
411
}
0 commit comments