Skip to content

Commit

Permalink
Fix for a missing allocationFence in transformArrayCloneCall()
Browse files Browse the repository at this point in the history
When we transform a clone() of an array object into a newarray and
arraycopy, we neglected to add an allocationFence. This change will
introduce an allocationFence after the arraycopy to ensure that all
threads see the new contents of memory on weak memory coherency
machines like POWER and AArch64.

Signed-off-by: Kevin Langman <langman@ca.ibm.com>
  • Loading branch information
klangman committed Sep 19, 2023
1 parent edcb5c6 commit d14f6e3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compiler/optimizer/ValuePropagationCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4136,6 +4136,15 @@ void OMR::ValuePropagation::transformArrayCloneCall(TR::TreeTop *callTree, OMR::

callTree->insertBefore(TR::TreeTop::create(comp(), TR::Node::create(callNode, TR::treetop, 1, newArray)));
callTree->insertBefore(TR::TreeTop::create(comp(), TR::Node::create(callNode, TR::treetop, 1, arraycopy)));

// Flush after the arraycopy so that the cloned array appears identical to the original before it's made
// visible to other threads, and because the obj allocation is allowed to use non-zeroed TLH, we need to
// make sure no thread sees stale memory contents from the array element section.
if (cg()->getEnforceStoreOrder())
{
TR::Node *allocationFence = TR::Node::createAllocationFence(newArray, newArray);
callTree->insertBefore(TR::TreeTop::create(comp(), allocationFence));
}
}

void OMR::ValuePropagation::transformConverterCall(TR::TreeTop *callTree)
Expand Down

0 comments on commit d14f6e3

Please sign in to comment.