Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Unsafe opaque and acquire/release put and get methods #20475

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions runtime/compiler/aarch64/codegen/J9TreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ generateSoftwareReadBarrier(TR::Node *node, TR::CodeGenerator *cg, bool isArdbar

generateLabelInstruction(cg, TR::InstOpCode::label, node, endLabel, deps);

bool needSync = (node->getSymbolReference()->getSymbol()->isSyncVolatile() && comp->target().isSMP());
if (needSync)
if (node->getSymbolReference()->getSymbol()->isAcquireRelease() &&
comp->target().isSMP())
{
// Issue an Acquire barrier after volatile load
generateSynchronizationInstruction(cg, TR::InstOpCode::dmb, node, TR::InstOpCode::ishld);
Expand Down Expand Up @@ -1213,8 +1213,6 @@ J9::ARM64::TreeEvaluator::awrtbarEvaluator(TR::Node *node, TR::CodeGenerator *cg

TR::Register *sourceRegister;
bool killSource = false;
bool isVolatileMode = (node->getSymbolReference()->getSymbol()->isSyncVolatile() && cg->comp()->target().isSMP());
bool isOrderedMode = (node->getSymbolReference()->getSymbol()->isShadow() && node->getSymbolReference()->getSymbol()->isOrdered() && cg->comp()->target().isSMP());

if (firstChild->getReferenceCount() > 1 && firstChild->getRegister() != NULL)
{
Expand All @@ -1234,14 +1232,15 @@ J9::ARM64::TreeEvaluator::awrtbarEvaluator(TR::Node *node, TR::CodeGenerator *cg

TR::MemoryReference *tempMR = TR::MemoryReference::createWithRootLoadOrStore(cg, node);

// Issue a StoreStore barrier before each volatile store.
if (isVolatileMode || isOrderedMode)
// Issue a StoreStore barrier before each volatile or release store.
if (node->getSymbolReference()->getSymbol()->isAcquireRelease() &&
cg->comp()->target().isSMP())
generateSynchronizationInstruction(cg, TR::InstOpCode::dmb, node, TR::InstOpCode::ishst);

generateMemSrc1Instruction(cg, TR::InstOpCode::strimmx, node, tempMR, sourceRegister, NULL);

// Issue a StoreLoad barrier after each volatile store.
if (isVolatileMode)
if (node->getSymbolReference()->getSymbol()->isVolatile() && cg->comp()->target().isSMP())
generateSynchronizationInstruction(cg, TR::InstOpCode::dmb, node, TR::InstOpCode::ish);

wrtbarEvaluator(node, sourceRegister, destinationRegister, firstChild->isNonNull(), cg);
Expand All @@ -1266,8 +1265,6 @@ J9::ARM64::TreeEvaluator::awrtbariEvaluator(TR::Node *node, TR::CodeGenerator *c
TR::Register *sourceRegister;
bool killSource = false;
bool usingCompressedPointers = TR::TreeEvaluator::getIndirectWrtbarValueNode(cg, node, secondChild, true);
bool isVolatileMode = (node->getSymbolReference()->getSymbol()->isSyncVolatile() && cg->comp()->target().isSMP());
bool isOrderedMode = (node->getSymbolReference()->getSymbol()->isShadow() && node->getSymbolReference()->getSymbol()->isOrdered() && cg->comp()->target().isSMP());

if (secondChild->getReferenceCount() > 1 && secondChild->getRegister() != NULL)
{
Expand Down Expand Up @@ -1301,14 +1298,15 @@ J9::ARM64::TreeEvaluator::awrtbariEvaluator(TR::Node *node, TR::CodeGenerator *c

TR::MemoryReference *tempMR = TR::MemoryReference::createWithRootLoadOrStore(cg, node);

// Issue a StoreStore barrier before each volatile store.
if (isVolatileMode || isOrderedMode)
// Issue a StoreStore barrier before each volatile or release store.
if (node->getSymbolReference()->getSymbol()->isAcquireRelease() &&
cg->comp()->target().isSMP())
generateSynchronizationInstruction(cg, TR::InstOpCode::dmb, node, TR::InstOpCode::ishst);

generateMemSrc1Instruction(cg, storeOp, node, tempMR, translatedSrcReg);

// Issue a StoreLoad barrier after each volatile store.
if (isVolatileMode)
if (node->getSymbolReference()->getSymbol()->isVolatile() && cg->comp()->target().isSMP())
generateSynchronizationInstruction(cg, TR::InstOpCode::dmb, node, TR::InstOpCode::ish);

wrtbarEvaluator(node, sourceRegister, destinationRegister, secondChild->isNonNull(), cg);
Expand Down Expand Up @@ -2636,20 +2634,23 @@ J9::ARM64::TreeEvaluator::flushEvaluator(TR::Node *node, TR::CodeGenerator *cg)
TR::Node *child = (node->getNumChildren() >= 1) ? node->getFirstChild() : NULL;
if (!child || (node->getOpCodeValue() != TR::monexit && child->getOpCodeValue() != TR::monexit))
{
// Iterate the next tree to see if there is a resolved volatile load/store node that has yet to be evaluated
// An unresolved volatile might not actually be a volatile access, and therefore can not replace the AllocationFence
// Iterate the next tree to see if there is a resolved volatile or acquire/release load/store node that has yet to be evaluated
// An unresolved volatile or acquire/release might not actually be a volatile or acquire/release access, and therefore can not replace the AllocationFence
// An node that is already evaluated will not actually emit a 'dmb' so it can not replace the AllocationFence
bool volatileAccessFound = false;
bool fencedAccessFound = false;
for (TR::PreorderNodeIterator it(tt, cg->comp()); it.currentTree() == tt; ++it)
{
node = it.currentNode();
if (node->getOpCode().hasSymbolReference() && !node->hasUnresolvedSymbolReference() && node->getSymbolReference()->getSymbol()->isVolatile() && !node->getRegister())
if (node->getOpCode().hasSymbolReference() &&
!node->hasUnresolvedSymbolReference() &&
node->getSymbolReference()->getSymbol()->isAcquireRelease()
&& !node->getRegister())
{
volatileAccessFound = true;
fencedAccessFound = true;
break;
}
}
if (!volatileAccessFound)
if (!fencedAccessFound)
{
// StoreStore barrier is required after publishing new object reference to other threads.
generateSynchronizationInstruction(cg, TR::InstOpCode::dmb, node, TR::InstOpCode::ishst);
Expand Down
16 changes: 2 additions & 14 deletions runtime/compiler/codegen/J9CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,18 +934,6 @@ J9::CodeGenerator::lowerTreeIfNeeded(
}
}

// J9
if (node->getOpCode().isCall() &&
node->isUnsafePutOrderedCall() &&
node->isDontInlinePutOrderedCall())
{
// Remove this treetop
tt->getPrevTreeTop()->setNextTreeTop(tt->getNextTreeTop());
tt->getNextTreeTop()->setPrevTreeTop(tt->getPrevTreeTop());
tt->getNode()->recursivelyDecReferenceCount();
return;
}

// J9
if (!self()->comp()->getOption(TR_DisableUnsafe) &&
node->getOpCode().isCall() &&
Expand Down Expand Up @@ -1051,7 +1039,7 @@ J9::CodeGenerator::lowerTreeIfNeeded(
{
TR::SymbolReference *symRef = node->getSymbolReference();
TR::Symbol *symbol = symRef->getSymbol();
if (symbol->isVolatile() && node->getDataType() == TR::Int64 && !symRef->isUnresolved() && self()->comp()->target().is32Bit() &&
if (symbol->isOpaque() && node->getDataType() == TR::Int64 && !symRef->isUnresolved() && self()->comp()->target().is32Bit() &&
!self()->getSupportsInlinedAtomicLongVolatiles())
{
bool isLoad = false;
Expand Down Expand Up @@ -1383,7 +1371,7 @@ J9::CodeGenerator::lowerTreeIfNeeded(
{
if ((node->getFirstChild()->getReferenceCount() == 1) &&
node->getFirstChild()->getOpCode().isLoadVar() &&
!node->getFirstChild()->getSymbolReference()->getSymbol()->isVolatile())
!node->getFirstChild()->getSymbolReference()->getSymbol()->isOpaque())
{
TR::Node::recreate(node->getFirstChild(), TR::PassThrough);
}
Expand Down
30 changes: 30 additions & 0 deletions runtime/compiler/codegen/J9RecognizedMethodsEnum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,36 @@
sun_misc_Unsafe_allocateInstance,
sun_misc_Unsafe_allocateUninitializedArray0,

jdk_internal_misc_Unsafe_getBooleanAcquire_jlObjectJ_Z,
jdk_internal_misc_Unsafe_getByteAcquire_jlObjectJ_B,
jdk_internal_misc_Unsafe_getCharAcquire_jlObjectJ_C,
jdk_internal_misc_Unsafe_getShortAcquire_jlObjectJ_S,
jdk_internal_misc_Unsafe_getIntAcquire_jlObjectJ_I,
jdk_internal_misc_Unsafe_getLongAcquire_jlObjectJ_J,
jdk_internal_misc_Unsafe_getFloatAcquire_jlObjectJ_F,
jdk_internal_misc_Unsafe_getDoubleAcquire_jlObjectJ_D,
jdk_internal_misc_Unsafe_getReferenceAcquire_jlObjectJ_jlObject,

jdk_internal_misc_Unsafe_getBooleanOpaque_jlObjectJ_Z,
jdk_internal_misc_Unsafe_getByteOpaque_jlObjectJ_B,
jdk_internal_misc_Unsafe_getCharOpaque_jlObjectJ_C,
jdk_internal_misc_Unsafe_getShortOpaque_jlObjectJ_S,
jdk_internal_misc_Unsafe_getIntOpaque_jlObjectJ_I,
jdk_internal_misc_Unsafe_getLongOpaque_jlObjectJ_J,
jdk_internal_misc_Unsafe_getFloatOpaque_jlObjectJ_F,
jdk_internal_misc_Unsafe_getDoubleOpaque_jlObjectJ_D,
jdk_internal_misc_Unsafe_getReferenceOpaque_jlObjectJ_jlObject,

jdk_internal_misc_Unsafe_putBooleanOpaque_jlObjectJZ_V,
jdk_internal_misc_Unsafe_putByteOpaque_jlObjectJB_V,
jdk_internal_misc_Unsafe_putCharOpaque_jlObjectJC_V,
jdk_internal_misc_Unsafe_putShortOpaque_jlObjectJS_V,
jdk_internal_misc_Unsafe_putIntOpaque_jlObjectJI_V,
jdk_internal_misc_Unsafe_putLongOpaque_jlObjectJJ_V,
jdk_internal_misc_Unsafe_putFloatOpaque_jlObjectJF_V,
jdk_internal_misc_Unsafe_putDoubleOpaque_jlObjectJD_V,
jdk_internal_misc_Unsafe_putReferenceOpaque_jlObjectJjlObject_V,

jdk_internal_misc_Unsafe_compareAndExchangeInt,
jdk_internal_misc_Unsafe_compareAndExchangeLong,
jdk_internal_misc_Unsafe_compareAndExchangeObject,
Expand Down
61 changes: 16 additions & 45 deletions runtime/compiler/compile/J9SymbolReferenceTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ J9::SymbolReferenceTable::SymbolReferenceTable(size_t sizeHint, TR::Compilation
_immutableInfo(c->trMemory()),
_immutableSymRefNumbers(c->trMemory(), _numImmutableClasses),
_dynamicMethodSymrefsByCallSiteIndex(c->trMemory()),
_unsafeJavaStaticSymRefs(NULL),
_unsafeJavaStaticVolatileSymRefs(NULL),
_unsafeJavaStaticSymRefs{},
_currentThreadDebugEventDataSymbol(0),
_currentThreadDebugEventDataSymbolRefs(c->trMemory()),
_constantPoolAddressSymbolRefs(c->trMemory()),
Expand Down Expand Up @@ -2248,24 +2247,15 @@ J9::SymbolReferenceTable::findOrCreateThreadDebugEventData(int32_t index)
}

TR::SymbolReference *
J9::SymbolReferenceTable::findUnsafeSymbolRef(TR::DataType type, bool javaObjectReference, bool javaStaticReference, bool isVolatile)
J9::SymbolReferenceTable::findUnsafeSymbolRef(TR::DataType type, bool javaObjectReference, bool javaStaticReference, TR::Symbol::MemoryOrdering ordering)
{
TR_Array<TR::SymbolReference *> * unsafeSymRefs = NULL;

if (isVolatile)
{
unsafeSymRefs =
javaStaticReference ?
_unsafeJavaStaticVolatileSymRefs :
_unsafeVolatileSymRefs;
}
else
{
unsafeSymRefs =
javaStaticReference ?
_unsafeJavaStaticSymRefs :
_unsafeSymRefs;
}
unsafeSymRefs =
javaStaticReference ?
_unsafeJavaStaticSymRefs[ordering] :
_unsafeSymRefs[ordering];


TR::SymbolReference * symRef = NULL;

Expand All @@ -2278,39 +2268,21 @@ J9::SymbolReferenceTable::findUnsafeSymbolRef(TR::DataType type, bool javaObject
}

TR::SymbolReference *
J9::SymbolReferenceTable::findOrCreateUnsafeSymbolRef(TR::DataType type, bool javaObjectReference, bool javaStaticReference, bool isVolatile)
J9::SymbolReferenceTable::findOrCreateUnsafeSymbolRef(TR::DataType type, bool javaObjectReference, bool javaStaticReference, TR::Symbol::MemoryOrdering ordering)
{
TR_Array<TR::SymbolReference *> * unsafeSymRefs = NULL;

if (isVolatile)
if (javaStaticReference)
{
if (javaStaticReference)
{
if (_unsafeJavaStaticVolatileSymRefs == NULL)
_unsafeJavaStaticVolatileSymRefs = new (trHeapMemory()) TR_Array<TR::SymbolReference *>(comp()->trMemory(), TR::NumAllTypes);
unsafeSymRefs = _unsafeJavaStaticVolatileSymRefs;
}
else
{
if (_unsafeVolatileSymRefs == NULL)
_unsafeVolatileSymRefs = new (trHeapMemory()) TR_Array<TR::SymbolReference *>(comp()->trMemory(), TR::NumAllTypes);
unsafeSymRefs = _unsafeVolatileSymRefs;
}
if (_unsafeJavaStaticSymRefs[ordering] == NULL)
_unsafeJavaStaticSymRefs[ordering] = new (trHeapMemory()) TR_Array<TR::SymbolReference *>(comp()->trMemory(), TR::NumAllTypes);
unsafeSymRefs = _unsafeJavaStaticSymRefs[ordering];
}
else
{
if (javaStaticReference)
{
if (_unsafeJavaStaticSymRefs == NULL)
_unsafeJavaStaticSymRefs = new (trHeapMemory()) TR_Array<TR::SymbolReference *>(comp()->trMemory(), TR::NumAllTypes);
unsafeSymRefs = _unsafeJavaStaticSymRefs;
}
else
{
if (_unsafeSymRefs == NULL)
_unsafeSymRefs = new (trHeapMemory()) TR_Array<TR::SymbolReference *>(comp()->trMemory(), TR::NumAllTypes);
unsafeSymRefs = _unsafeSymRefs;
}
if (_unsafeSymRefs[ordering] == NULL)
_unsafeSymRefs[ordering] = new (trHeapMemory()) TR_Array<TR::SymbolReference *>(comp()->trMemory(), TR::NumAllTypes);
unsafeSymRefs = _unsafeSymRefs[ordering];
}

TR::SymbolReference * symRef = (*unsafeSymRefs)[type];
Expand All @@ -2320,8 +2292,7 @@ J9::SymbolReferenceTable::findOrCreateUnsafeSymbolRef(TR::DataType type, bool ja
TR::Symbol * sym = TR::Symbol::createShadow(trHeapMemory(),type);
sym->setUnsafeShadowSymbol();
sym->setArrayShadowSymbol();
if (isVolatile)
sym->setVolatile();
sym->setMemoryOrdering(ordering);
(*unsafeSymRefs)[type] = symRef = new (trHeapMemory()) TR::SymbolReference(self(), sym, comp()->getMethodSymbol()->getResolvedMethodIndex(), -1);
aliasBuilder.unsafeSymRefNumbers().set(symRef->getReferenceNumber());
}
Expand Down
17 changes: 6 additions & 11 deletions runtime/compiler/compile/J9SymbolReferenceTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,13 @@ class SymbolReferenceTable : public OMR::SymbolReferenceTableConnector
* \param javaStaticReference
* Determines whether this symbol reference is referencing a Java object static field.
*
* \param isVolatile
* Determines whether this symbol should be treated with volatile semantics.
* \param mode
* Determines what access mode memory semantics this symbol should be treated with.
*
* \return
* The unsafe symbol reference with given constraints if it exists; <c>NULL</c> otherwise.
*/
TR::SymbolReference* findUnsafeSymbolRef(TR::DataType type, bool javaObjectReference = false, bool javaStaticReference = false, bool isVolatile = false);
TR::SymbolReference* findUnsafeSymbolRef(TR::DataType type, bool javaObjectReference, bool javaStaticReference, TR::Symbol::MemoryOrdering mode);

/** \brief
* Finds an unsafe symbol reference with given constraints if it exists, or creates one if no such symbol
Expand All @@ -359,7 +359,7 @@ class SymbolReferenceTable : public OMR::SymbolReferenceTableConnector
* \return
* The unsafe symbol reference with given constraints if it exists.
*/
TR::SymbolReference* findOrCreateUnsafeSymbolRef(TR::DataType type, bool javaObjectReference = false, bool javaStaticReference = false, bool isVolatile = false);
TR::SymbolReference* findOrCreateUnsafeSymbolRef(TR::DataType type, bool javaObjectReference = false, bool javaStaticReference = false, TR::Symbol::MemoryOrdering mode = TR::Symbol::TransparentSemantics);

TR::SymbolReference * findOrCreateImmutableGenericIntShadowSymbolReference(intptr_t offset); // "Immutable" means no aliasing issues; ie. reads from these shadows can be freely reordered wrt anything else

Expand Down Expand Up @@ -589,14 +589,9 @@ class SymbolReferenceTable : public OMR::SymbolReferenceTableConnector
TR_Array<TR_BitVector *> _immutableSymRefNumbers;

/** \brief
* Represents the set of symbol references to static fields of Java objects.
*/
TR_Array<TR::SymbolReference *> * _unsafeJavaStaticSymRefs;

/** \brief
* Represents the set of symbol references to static volatile fields of Java objects.
* Represents the set of symbol references to static fields of Java objects for each access mode.
*/
TR_Array<TR::SymbolReference *> * _unsafeJavaStaticVolatileSymRefs;
TR_Array<TR::SymbolReference *> * _unsafeJavaStaticSymRefs[TR::Symbol::LastMemoryOrdering+1];

ResolvedFieldShadows _resolvedFieldShadows;

Expand Down
Loading