diff --git a/runtime/compiler/optimizer/InlinerTempForJ9.cpp b/runtime/compiler/optimizer/InlinerTempForJ9.cpp index 722351e907c..9eb12a4f9af 100644 --- a/runtime/compiler/optimizer/InlinerTempForJ9.cpp +++ b/runtime/compiler/optimizer/InlinerTempForJ9.cpp @@ -999,9 +999,46 @@ TR_J9InlinerPolicy::genCodeForUnsafeGetPut(TR::Node* unsafeAddress, traceMsg(comp(),"\t\t Generating an isArray test as j9class of java/lang/Class is NULL"); directAccessBlock->getEntry()->insertTreeTopsBeforeMe(lowTagCmpBlock->getEntry(), lowTagCmpBlock->getExit()); lowTagCmpTree->getNode()->setBranchDestination(indirectAccessBlock->getEntry()); - } + } + lowTagCmpBlock->getEntry()->insertTreeTopsBeforeMe(isArrayBlock->getEntry(), isArrayBlock->getExit()); + + //reorder directAccess, arrayDirectAccess, and indirectAccess blocks to optimize fallthrough paths + // (want directAccess (i.e.: non array and non class object) case on fallthrough path) + if (arrayBlockNeeded) + { + //switch indirectAccessBlock and directAccessBlock + TR::Block *indirectPrevBlock = indirectAccessBlock->getEntry()->getPrevTreeTop()->getEnclosingBlock(); + TR::Block *indirectNextBlock = indirectAccessBlock->getExit()->getNextTreeTop()->getEnclosingBlock(); + TR::Block *directPrevBlock = directAccessBlock->getEntry()->getPrevTreeTop()->getEnclosingBlock(); + TR::Block *directNextBlock = directAccessBlock->getExit()->getNextTreeTop()->getEnclosingBlock(); + + indirectAccessBlock->getEntry()->setPrevTreeTop(directPrevBlock->getExit()); + directPrevBlock->getExit()->setNextTreeTop(indirectAccessBlock->getEntry()); + indirectAccessBlock->getExit()->setNextTreeTop(directNextBlock->getEntry()); + directNextBlock->getEntry()->setPrevTreeTop(indirectAccessBlock->getExit()); + + directAccessBlock->getEntry()->setPrevTreeTop(indirectPrevBlock->getExit()); + indirectPrevBlock->getExit()->setNextTreeTop(directAccessBlock->getEntry()); + directAccessBlock->getExit()->setNextTreeTop(indirectNextBlock->getEntry()); + indirectNextBlock->getEntry()->setPrevTreeTop(directAccessBlock->getExit()); + + if (indirectPrevBlock == lowTagCmpTree->getEnclosingBlock()) + { + //add goto to the end of indirectAccessBlock, since it's no longer on the fallthrough path + indirectAccessBlock->append(TR::TreeTop::create(comp(), TR::Node::create(indirectAccessBlock->getEntry()->getNode(), TR::Goto, 0, directAccessBlock->getExit()->getNextTreeTop()))); + + //since the directAccessBlock is now accessible via fallthrough, we need change the condition/destination + //of the conditional branch in the lowTagCmp block so that it can reach the indirectAccessBlock + TR::ILOpCodes lowTagCmpOpCode = lowTagCmpTree->getNode()->getOpCodeValue(); + TR::ILOpCodes newOpCode = lowTagCmpOpCode == TR::ificmpne ? TR::ificmpeq : TR::iflcmpeq; + + lowTagCmpTree->getNode()->getOpCode().setOpCodeValue(newOpCode); + lowTagCmpTree->getNode()->setBranchDestination(indirectAccessBlock->getEntry()); + } + } + cfg->addEdge(TR::CFGEdge::createEdge(isArrayBlock, lowTagCmpBlock, trMemory())); cfg->addEdge(TR::CFGEdge::createEdge(lowTagCmpBlock, indirectAccessBlock, trMemory())); cfg->addEdge(TR::CFGEdge::createEdge(isArrayBlock, arrayBlockNeeded ? arrayDirectAccessBlock : directAccessBlock, trMemory()));