Skip to content

Commit

Permalink
Merge pull request #2885 from liqunl/folding
Browse files Browse the repository at this point in the history
Fold VarHandle held in static final fields with fear
  • Loading branch information
andrewcraik authored Jan 11, 2019
2 parents eca2cd9 + 94cc386 commit ffbffce
Show file tree
Hide file tree
Showing 12 changed files with 428 additions and 91 deletions.
3 changes: 2 additions & 1 deletion runtime/compiler/compile/J9Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ J9::Compilation::Compilation(int32_t id,
_classForStaticFinalFieldModification(m),
_profileInfo(NULL),
_skippedJProfilingBlock(false),
_reloRuntime(reloRuntime)
_reloRuntime(reloRuntime),
_osrProhibitedOverRangeOfTrees(false)
{
_symbolValidationManager = new (self()->region()) TR::SymbolValidationManager(self()->region(), compilee);

Expand Down
5 changes: 5 additions & 0 deletions runtime/compiler/compile/J9Compilation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ class OMR_EXTENSIBLE Compilation : public OMR::CompilationConnector

TR::SymbolValidationManager *getSymbolValidationManager() { return _symbolValidationManager; }

// Flag to record if any optimization has prohibited OSR over a range of trees
void setOSRProhibitedOverRangeOfTrees() { _osrProhibitedOverRangeOfTrees = true; }
bool isOSRProhibitedOverRangeOfTrees() { return _osrProhibitedOverRangeOfTrees; }

private:
enum CachedClassPointerId
{
Expand Down Expand Up @@ -399,6 +403,7 @@ class OMR_EXTENSIBLE Compilation : public OMR::CompilationConnector
TR_RelocationRuntime *_reloRuntime;

TR::SymbolValidationManager *_symbolValidationManager;
bool _osrProhibitedOverRangeOfTrees;
};

}
Expand Down
4 changes: 1 addition & 3 deletions runtime/compiler/control/J9Options.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corp. and others
* Copyright (c) 2000, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -1069,8 +1069,6 @@ J9::Options::fePreProcess(void * base)
self()->setOption(TR_DisableTraps);
#endif

self()->setOption(TR_DisableGuardedStaticFinalFieldFolding);

if (self()->getOption(TR_AggressiveOpts))
self()->setOption(TR_DontDowngradeToCold, true);

Expand Down
27 changes: 4 additions & 23 deletions runtime/compiler/optimizer/FearPointAnalysis.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corp. and others
* Copyright (c) 2000, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -40,20 +40,6 @@ bool TR_FearPointAnalysis::virtualGuardsKillFear()
return kill;
}

static bool containsPrepareForOSR(TR::Block *block)
{
for (TR::TreeTop *tt = block->getEntry(); tt != block->getExit(); tt = tt->getNextTreeTop())
{
if (tt->getNode()->getOpCode().isCheck() || tt->getNode()->getOpCodeValue() == TR::treetop)
{
if (tt->getNode()->getFirstChild()->getOpCode().isCall()
&& tt->getNode()->getFirstChild()->getSymbolReference()->getReferenceNumber() == TR_prepareForOSR)
return true;
}
}
return false;
}

int32_t TR_FearPointAnalysis::getNumberOfBits() { return 1; }

bool TR_FearPointAnalysis::supportsGenAndKillSets() { return true; }
Expand Down Expand Up @@ -106,7 +92,7 @@ TR_FearPointAnalysis::TR_FearPointAnalysis(
if (treeTop->getNode()->getOpCodeValue() == TR::BBStart)
{
TR::Block *currentBlock = treeTop->getEnclosingBlock();
if (shouldSkipBlock(currentBlock))
if (currentBlock->isOSRCatchBlock() || currentBlock->isOSRCodeBlock())
{
treeTop = currentBlock->getExit();
continue;
Expand Down Expand Up @@ -197,7 +183,7 @@ void TR_FearPointAnalysis::computeFearFromBitVector(TR::Compilation *comp)
if (treeTop->getNode()->getOpCodeValue() == TR::BBStart)
{
TR::Block *currentBlock = treeTop->getEnclosingBlock();
if (shouldSkipBlock(currentBlock))
if (currentBlock->isOSRCatchBlock() || currentBlock->isOSRCodeBlock())
{
treeTop = currentBlock->getExit();
continue;
Expand All @@ -219,11 +205,6 @@ TR_SingleBitContainer *TR_FearPointAnalysis::generatedFear(TR::Node *node)
return returnValue;
}

bool TR_FearPointAnalysis::shouldSkipBlock(TR::Block *block)
{
return block->isOSRCatchBlock() || block->isOSRCodeBlock() || containsPrepareForOSR(block);
}

void TR_FearPointAnalysis::initializeGenAndKillSetInfo()
{
for (int32_t i = 0; i < comp()->getFlowGraph()->getNextNodeNumber(); ++i)
Expand All @@ -242,7 +223,7 @@ void TR_FearPointAnalysis::initializeGenAndKillSetInfo()
{
exceptingTTSeen = false;
currentBlock = treeTop->getEnclosingBlock();
if (shouldSkipBlock(currentBlock))
if (currentBlock->isOSRCatchBlock() || currentBlock->isOSRCodeBlock())
{
_regularKillSetInfo[currentBlock->getNumber()]->setAll(getNumberOfBits());
_exceptionKillSetInfo[currentBlock->getNumber()]->setAll(getNumberOfBits());
Expand Down
3 changes: 1 addition & 2 deletions runtime/compiler/optimizer/FearPointAnalysis.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corp. and others
* Copyright (c) 2000, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -40,7 +40,6 @@ class TR_FearPointAnalysis : public TR_BackwardUnionSingleBitContainerAnalysis
virtual void analyzeTreeTopsInBlockStructure(TR_BlockStructure *);
virtual bool postInitializationProcessing();
TR_SingleBitContainer *generatedFear(TR::Node *node);
bool shouldSkipBlock(TR::Block *block);

static bool virtualGuardsKillFear();

Expand Down
59 changes: 29 additions & 30 deletions runtime/compiler/optimizer/J9TransformUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1928,30 +1928,29 @@ J9::TransformUtil::createDiamondForCall(TR::Optimization* opt, TR::TreeTop *call
void J9::TransformUtil::removePotentialOSRPointHelperCalls(TR::Compilation* comp, TR::TreeTop* start, TR::TreeTop* end)
{
TR_ASSERT(start->getEnclosingBlock() == end->getEnclosingBlock(), "Does not support range across blocks");
TR_ASSERT(comp->supportsInduceOSR() && comp->isOSRTransitionTarget(TR::postExecutionOSR) && comp->getOSRMode() == TR::voluntaryOSR,
"removePotentialOSRPointHelperCalls only works in certain modes");

TR::TreeTop* ttAfterEnd = end->getNextTreeTop();
TR::TreeTop *tt = start;

if (comp->getOption(TR_EnableOSR) &&
comp->isOSRTransitionTarget(TR::postExecutionOSR) &&
comp->getOSRMode() == TR::voluntaryOSR)
do
{
TR::TreeTop *tt = start;
do
TR::Node *osrNode = NULL;
if (comp->isPotentialOSRPoint(tt->getNode(), &osrNode))
{
TR::Node *osrNode = NULL;
if (comp->isPotentialOSRPoint(tt->getNode(), &osrNode))
if (osrNode->isPotentialOSRPointHelperCall())
{
if (osrNode->isPotentialOSRPointHelperCall())
{
dumpOptDetails(comp, "Remove tt n%dn with potential osr point %p n%dn\n", tt->getNode()->getGlobalIndex(), osrNode, osrNode->getGlobalIndex());
TR::TreeTop* prevTT = tt->getPrevTreeTop();
TR::TransformUtil::removeTree(comp, tt);
tt = prevTT;
}
dumpOptDetails(comp, "Remove tt n%dn with potential osr point %p n%dn\n", tt->getNode()->getGlobalIndex(), osrNode, osrNode->getGlobalIndex());
TR::TreeTop* prevTT = tt->getPrevTreeTop();
TR::TransformUtil::removeTree(comp, tt);
tt = prevTT;
}
tt = tt->getNextTreeTop();
} while (tt != ttAfterEnd);
}
tt = tt->getNextTreeTop();
}
while (tt != ttAfterEnd);

}

/** \brief
Expand All @@ -1973,24 +1972,24 @@ void J9::TransformUtil::removePotentialOSRPointHelperCalls(TR::Compilation* comp
void J9::TransformUtil::prohibitOSROverRange(TR::Compilation* comp, TR::TreeTop* start, TR::TreeTop* end)
{
TR_ASSERT(start->getEnclosingBlock() == end->getEnclosingBlock(), "Does not support range across blocks");
TR_ASSERT(comp->supportsInduceOSR() && comp->isOSRTransitionTarget(TR::postExecutionOSR) && comp->getOSRMode() == TR::voluntaryOSR,
"prohibitOSROverRange only works in certain modes");

TR::TreeTop* ttAfterEnd = end->getNextTreeTop();
TR::TreeTop *tt = start;

if (comp->getOption(TR_EnableOSR) &&
comp->isOSRTransitionTarget(TR::postExecutionOSR) &&
comp->getOSRMode() == TR::voluntaryOSR)
do
{
TR::TreeTop *tt = start;
do
TR::Node *osrNode = NULL;
if (comp->isPotentialOSRPoint(tt->getNode(), &osrNode))
{
TR::Node *osrNode = NULL;
if (comp->isPotentialOSRPoint(tt->getNode(), &osrNode))
{
dumpOptDetails(comp, "Can no longer OSR at [%p] n%dn\n", osrNode, osrNode->getGlobalIndex());
osrNode->getByteCodeInfo().setDoNotProfile(true);
}
tt = tt->getNextTreeTop();
} while (tt != ttAfterEnd);
dumpOptDetails(comp, "Can no longer OSR at [%p] n%dn\n", osrNode, osrNode->getGlobalIndex());
// Record the prohibition so other opts are aware of the existence of dangerous region
comp->setOSRProhibitedOverRangeOfTrees();
osrNode->getByteCodeInfo().setDoNotProfile(true);
}
tt = tt->getNextTreeTop();
}
}
while (tt != ttAfterEnd);

}
Loading

0 comments on commit ffbffce

Please sign in to comment.