Skip to content

Commit

Permalink
Z: Replace Thread.onSpinWait() with a nop instruction
Browse files Browse the repository at this point in the history
Accelerate inlining Thread.onSpinWait() on z.
Thread.onSpinWait() is a simple `nop` instruction on z.
Enabled by default. Disable by setting the `TR_noPauseOnSpinWait`
environment variable.

Signed-off-by: Ehsan Kiani Far <[email protected]>
  • Loading branch information
ehsankianifar committed Nov 22, 2024
1 parent ff43532 commit 077f69f
Show file tree
Hide file tree
Showing 3 changed files with 34 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 @@ -4043,6 +4043,14 @@ J9::Z::CodeGenerator::inlineDirectCall(
return resultReg != NULL;
}
break;
case TR::java_lang_Thread_onSpinWait:
static char *disableOSW = feGetEnv("TR_noPauseOnSpinWait");
if (!disableOSW)
{
resultReg = TR::TreeEvaluator::inlineOnSpinWait(node, cg);
return true;
}
break;

default:
break;
Expand Down
12 changes: 12 additions & 0 deletions runtime/compiler/z/codegen/J9TreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14665,3 +14665,15 @@ 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) {
// Thread.onSpinWait() on z is a simple "nop" instruction.
cg->generateNop(node);
static const bool printIt = feGetEnv("TR_showPauseOnSpinWait") != NULL;
if (printIt && comp->getOption(TR_TraceCG))
{
traceMsg(comp, "insert PAUSE for onSpinWait : node=%p, %s\n", node, comp->signature());
}
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 @@ -141,6 +141,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
*
* \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 077f69f

Please sign in to comment.