Skip to content

Commit

Permalink
Use baseObj for Unsafe.CAS CardMarking for OffHeap on AArch64
Browse files Browse the repository at this point in the history
When evaluating Unsafe.CAS while running with Balanced GC and OffHeap
enabled, if the object child is the dataAddrPointer load, pass the
baseObj to VMCardCheckEvaluator for correct card marking.

The dstReg and temp2Reg in VMCardCheckEvaluator can share a reg,
adding the argument clobberDstReg to indicate if dstReg can be used
as the temp2Reg.

Not allocating temp2Reg and adding a dep for baseObjReg uses the same
number of registers.

Signed-off-by: Abdulrahman Alattas <[email protected]>
  • Loading branch information
rmnattas committed Sep 30, 2024
1 parent 5b929a9 commit 15acde9
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions runtime/compiler/aarch64/codegen/J9TreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,8 @@ VMCardCheckEvaluator(
TR::Register *dstReg,
TR_ARM64ScratchRegisterManager *srm,
TR::LabelSymbol *doneLabel,
TR::CodeGenerator *cg)
TR::CodeGenerator *cg,
bool clobberDstReg=false)
{
TR::Compilation *comp = cg->comp();

Expand All @@ -1014,7 +1015,11 @@ VMCardCheckEvaluator(
cg->generateDebugCounter(TR::DebugCounter::debugCounterName(comp, "wrtbarEvaluator:020VMCardCheckEvaluator:01markThreadActiveCheckDone"), *srm);
}

TR::Register *temp2Reg = srm->findOrCreateScratchRegister();
TR::Register *temp2Reg;
if (clobberDstReg)
temp2Reg = dstReg;
else
temp2Reg = srm->findOrCreateScratchRegister();
/*
* Generating code checking whether an object is in heap
*
Expand Down Expand Up @@ -5037,7 +5042,13 @@ static TR::Register *VMinlineCompareAndSwapObject(TR::Node *node, TR::CodeGenera
fourthChild = node->getChild(3);
fifthChild = node->getChild(4);

objReg = cg->evaluate(secondChild);
#if defined(J9VM_GC_ENABLE_SPARSE_HEAP_ALLOCATION)
bool isObjOffHeapDataAddr = (gcMode == gc_modron_wrtbar_cardmark_incremental && TR::Compiler->om.isOffHeapAllocationEnabled() && secondChild->isDataAddrPointer());
TR::Register *baseObjReg = NULL;
if (isObjOffHeapDataAddr)
TR::TreeEvaluator::stopUsingCopyReg(secondChild->getFirstChild(), baseObjReg, cg);
#endif /* defined(J9VM_GC_ENABLE_SPARSE_HEAP_ALLOCATION) */
objReg = cg->evaluate(secondChild);

if (thirdChild->getOpCode().isLoadConst() && thirdChild->getRegister() == NULL)
{
Expand Down Expand Up @@ -5200,11 +5211,20 @@ static TR::Register *VMinlineCompareAndSwapObject(TR::Node *node, TR::CodeGenera
generateCompareBranchInstruction(cg, TR::InstOpCode::cbzx, node, wrtBarSrcReg, doneLabel);
cg->generateDebugCounter(TR::DebugCounter::debugCounterName(comp, "wrtbarEvaluator:000srcNullChk:NonNull"), *srm);
}
VMCardCheckEvaluator(node, objReg, srm, doneLabel, cg);
#if defined(J9VM_GC_ENABLE_SPARSE_HEAP_ALLOCATION)
if (isObjOffHeapDataAddr)
VMCardCheckEvaluator(node, baseObjReg, srm, doneLabel, cg, true);
else
#endif /* defined(J9VM_GC_ENABLE_SPARSE_HEAP_ALLOCATION) */
VMCardCheckEvaluator(node, objReg, srm, doneLabel, cg);
}

TR_ARM64ScratchRegisterDependencyConditions scratchDeps;
scratchDeps.addDependency(cg, objReg, doWrtBar ? TR::RealRegister::x0 : TR::RealRegister::NoReg);
#if defined(J9VM_GC_ENABLE_SPARSE_HEAP_ALLOCATION)
if (isObjOffHeapDataAddr)
scratchDeps.addDependency(cg, baseObjReg, TR::RealRegister::NoReg);
#endif /* defined(J9VM_GC_ENABLE_SPARSE_HEAP_ALLOCATION) */
scratchDeps.addDependency(cg, wrtBarSrcReg, doWrtBar ? TR::RealRegister::x1 : TR::RealRegister::NoReg);
if (offsetInReg)
{
Expand Down

0 comments on commit 15acde9

Please sign in to comment.