Skip to content

Commit baf16d5

Browse files
author
Yi Zhang
committed
Change to use the API induceOSRAfterAndRecompile
Change OSRGuardInsertion to use the new API induceOSRAfterAndRecompile to request for OSR transition and recompilation when recompilation is allowed. An OSRGuard only gets fired when there is an invalidated code path, recompiling a new method body without the invalid code path and the patched guard should benefit performance. Signed-off-by: Yi Zhang <yizhang@ca.ibm.com>
1 parent 4662322 commit baf16d5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

runtime/compiler/optimizer/OSRGuardInsertion.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int32_t TR_OSRGuardInsertion::perform()
7272
if (trace())
7373
traceMsg(comp(), "No HCR guards to be removed - skipping\n");
7474
return 0;
75-
}
75+
}
7676

7777
TR_BitVector fearGeneratingNodes(comp()->getNodeCount(), trMemory(), stackAlloc);
7878
removeHCRGuards(fearGeneratingNodes);
@@ -194,7 +194,7 @@ void TR_OSRGuardInsertion::removeHCRGuards(TR_BitVector &fearGeneratingNodes)
194194
cursor->removeBranch(comp());
195195

196196
// Check whether there is another virtual guard, with the same branch destination
197-
// Based on the inliner, this guard should be in the prior block and there should
197+
// Based on the inliner, this guard should be in the prior block and there should
198198
// be no other predecessors
199199
//
200200
TR::Node *potentialGuard = NULL;
@@ -278,7 +278,7 @@ int32_t TR_OSRGuardInsertion::insertOSRGuards(TR_BitVector &fearGeneratingNodes)
278278
cursor = block->getEntry();
279279
continue;
280280
}
281-
281+
282282
// set the fearful state based on all successors - anyone who has an OSR edge is a source
283283
// of fear and we must add a patch point if we encounter a yield otherwise we are safe
284284
TR_SuccessorIterator sit(block);
@@ -325,7 +325,8 @@ int32_t TR_OSRGuardInsertion::insertOSRGuards(TR_BitVector &fearGeneratingNodes)
325325

326326
// If something went wrong with bookkeeping, due to the nature of the implicit OSR point,
327327
// this will return false
328-
bool induceOSR = comp()->getMethodSymbol()->induceOSRAfter(cursor, nodeBCI, guard, false, 0, &cfgEnd);
328+
bool induceOSR = comp()->allowRecompilation() ? comp()->getMethodSymbol()->induceOSRAfterAndRecompile(cursor, nodeBCI, guard, false, 0, &cfgEnd):
329+
comp()->getMethodSymbol()->induceOSRAfter(cursor, nodeBCI, guard, false, 0, &cfgEnd);
329330

330331
if (trace())
331332
{
@@ -426,7 +427,8 @@ int32_t TR_OSRGuardInsertion::insertOSRGuards(TR_BitVector &fearGeneratingNodes)
426427
guard->getNode()->getFirstChild()->setByteCodeInfo(guardBCI);
427428
guard->getNode()->getSecondChild()->setByteCodeInfo(guardBCI);
428429

429-
bool induceOSR = targetMethod->induceOSRAfter(inductionPoint, nodeBCI, guard, false, comp()->getOSRInductionOffset(cursor->getNode()), &cfgEnd);
430+
bool induceOSR = comp()->allowRecompilation() ? targetMethod->induceOSRAfterAndRecompile(inductionPoint, nodeBCI, guard, false, comp()->getOSRInductionOffset(cursor->getNode()), &cfgEnd):
431+
targetMethod->induceOSRAfter(inductionPoint, nodeBCI, guard, false, comp()->getOSRInductionOffset(cursor->getNode()), &cfgEnd);
430432

431433
if (trace() && induceOSR)
432434
traceMsg(comp(), " OSR induction added successfully\n");
@@ -497,7 +499,7 @@ void TR_OSRGuardInsertion::generateTriggeringRecompilationTrees(TR::TreeTop *osr
497499
void TR_OSRGuardInsertion::performRemat(TR::TreeTop *osrPoint, TR::TreeTop *osrGuard,
498500
TR::TreeTop *rematDest)
499501
{
500-
static const char *p = feGetEnv("TR_OSRRematBlockLimit");
502+
static const char *p = feGetEnv("TR_OSRRematBlockLimit");
501503
static uint32_t rematBlockLimit = p ? atoi(p) : defaultRematBlockLimit;
502504

503505
// The block containing the OSR point and the guard
@@ -524,7 +526,7 @@ void TR_OSRGuardInsertion::performRemat(TR::TreeTop *osrPoint, TR::TreeTop *osrG
524526

525527
// Collect remat candidates
526528
//
527-
uint32_t rematBlocks = 1;
529+
uint32_t rematBlocks = 1;
528530
TR::SparseBitVector seen(comp()->allocator());
529531
for (TR::TreeTop *cursor = realStart; cursor; cursor = cursor->getPrevTreeTop())
530532
{
@@ -544,7 +546,7 @@ void TR_OSRGuardInsertion::performRemat(TR::TreeTop *osrPoint, TR::TreeTop *osrG
544546
{
545547
if (trace())
546548
traceMsg(comp(), " remat block limit %d reached at block_%d, starting remat\n", rematBlockLimit, block->getNumber());
547-
break;
549+
break;
548550
}
549551

550552
TR::Block *next;
@@ -623,7 +625,7 @@ void TR_OSRGuardInsertion::performRemat(TR::TreeTop *osrPoint, TR::TreeTop *osrG
623625
// partially rematerialize the argument
624626
if (!*iter)
625627
continue;
626-
628+
627629
TR::TreeTop *storeTree = *iter;
628630
TR::Node *store = storeTree->getNode();
629631
if (trace())

0 commit comments

Comments
 (0)