Skip to content

Commit

Permalink
Offheap Adjustments for Unsafe calls that are converted to atomic
Browse files Browse the repository at this point in the history
intrinsics during unsafeFastPath

During unsafeFastPath, some UnsafeAPI calls (such as Unsafe.getAndAdd())
are converted to atomic intrinsics (such as atomicFetchAndAdd). When
this occurs with offheap allocation enabled, and the object is an array,
load dataAddr.

Signed-off-by: midronij <[email protected]>
  • Loading branch information
midronij committed Oct 15, 2024
1 parent fcdc9d0 commit 318add6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions runtime/compiler/optimizer/UnsafeFastPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,19 @@ bool TR_UnsafeFastPath::tryTransformUnsafeAtomicCallInVarHandleAccessMethod(TR::
}
else
{
TR::Node* object = node->getChild(1);
TR::Node* offset = node->getChild(2);
unsafeAddress = comp()->target().is32Bit() ? TR::Node::create(node, TR::aiadd, 2, object, TR::Node::create(node, TR::l2i, 1, offset)) :
TR::Node::create(node, TR::aladd, 2, object, offset);
TR::Node *object = node->getChild(1);
TR::Node *offset = node->getChild(2);

TR::Node *baseAddr = object;

//load dataAddr only if offheap is enabled and object is array
#if defined(J9VM_GC_ENABLE_SPARSE_HEAP_ALLOCATION)
if (isUnsafeCallerAccessingArrayElement(callerMethod) && TR::Compiler->om.isOffHeapAllocationEnabled() && comp()->target().is64Bit())
baseAddr = TR::TransformUtil::generateDataAddrLoadTrees(comp(), object);
#endif /* J9VM_GC_ENABLE_SPARSE_HEAP_ALLOCATION */

unsafeAddress = comp()->target().is32Bit() ? TR::Node::create(node, TR::aiadd, 2, baseAddr, TR::Node::create(node, TR::l2i, 1, offset)) :
TR::Node::create(node, TR::aladd, 2, baseAddr, offset);
unsafeAddress->setIsInternalPointer(true);
}

Expand Down

0 comments on commit 318add6

Please sign in to comment.