Skip to content

Commit

Permalink
Merge pull request #20714 from ehsankianifar/Z_Accelerate-onSpinWait-…
Browse files Browse the repository at this point in the history
…inlining

Z: Accelerate inlining Thread.onSpinWait()
  • Loading branch information
r30shah authored Dec 10, 2024
2 parents bdf23b4 + 4e89f97 commit 1e928fe
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions runtime/compiler/z/codegen/J9CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4081,6 +4081,14 @@ J9::Z::CodeGenerator::inlineDirectCall(
return resultReg != NULL;
}
break;
case TR::java_lang_Thread_onSpinWait:
static const bool enableOSW = feGetEnv("TR_noPauseOnSpinWait") == NULL;
if (enableOSW)
{
resultReg = TR::TreeEvaluator::inlineOnSpinWait(node, cg);
return true;
}
break;

default:
break;
Expand Down
15 changes: 15 additions & 0 deletions runtime/compiler/z/codegen/J9TreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14801,3 +14801,18 @@ J9::Z::TreeEvaluator::inlineIntegerStringSize(TR::Node* node, TR::CodeGenerator*

return node->setRegister(lengthReg);
}

TR::Register*
J9::Z::TreeEvaluator::inlineOnSpinWait(TR::Node *node, TR::CodeGenerator *cg)
{
TR::Compilation *comp = cg->comp();
if (comp->getOption(TR_TraceCG))
{
traceMsg(comp, "Inlining Thread.onSpinWait call on node %p to NOP.\n", node);
}

// onSpinWait() method calls VM_AtomicSupport::yieldCPU() which is a simple NOP instruction on Z.
// Check omr/include_core/AtomicSupport.hpp for the JNI implementation.
TR::Instruction* cursor = new (cg->trHeapMemory()) TR::S390NOPInstruction(TR::InstOpCode::NOP, 2, node, cg);
return NULL;
}
14 changes: 14 additions & 0 deletions runtime/compiler/z/codegen/J9TreeEvaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ class OMR_EXTENSIBLE TreeEvaluator: public J9::TreeEvaluator
static TR::Register* inlineUTF16BEEncode (TR::Node *node, TR::CodeGenerator *cg);
static TR::Register *inlineCRC32CUpdateBytes(TR::Node *node, TR::CodeGenerator *cg, bool isDirectBuffer);

/**
* \brief
* Accelerate inlining onSpinWait() method.
*
* \details
* onSpinWait() method calls VM_AtomicSupport::yieldCPU() which is a simple NOP instruction on Z.
*
* \param node the method call node.
* \param cg the code generator.
*
* \return NULL
*/
static TR::Register *inlineOnSpinWait(TR::Node *node, TR::CodeGenerator *cg);

static TR::Register *zdloadEvaluator(TR::Node *node, TR::CodeGenerator *cg);
static TR::Register *zdloadiEvaluator(TR::Node *node, TR::CodeGenerator *cg);
static TR::Register *zdstoreEvaluator(TR::Node *node, TR::CodeGenerator *cg);
Expand Down

0 comments on commit 1e928fe

Please sign in to comment.