public final class InstrumentationSamplingFramework extends CompilerPhase
NOTE: This implementation uses yieldpoints to denote where checks should be placed (to transfer control into instrumented code). It is currently assumed that these are on method entries and backedges. When optimized yieldpoint placement exists either a) it should be turned off when using this phase, or b) this phase should detect its own check locations.
To avoid the complexity of duplicating exception handler maps, exception handler blocks are split and a check at the top of the handler. Thus exceptions from both the checking and duplicated code are handled by the same catch block, however the check at the top of the catch block ensures that the hander code has the opportunity to be sampled.
Modifier and Type | Field and Description |
---|---|
private RegisterOperand |
cbsReg
Temporary variables
|
private static Constructor<CompilerPhase> |
constructor
Constructor for this compiler phase
|
private static boolean |
DEBUG
These are local copies of optimizing compiler debug options that can be
set via the command line arguments.
|
private static boolean |
DEBUG2 |
container
Constructor and Description |
---|
InstrumentationSamplingFramework() |
Modifier and Type | Method and Description |
---|---|
private static void |
adjustPointersInDuplicatedCode(IR ir,
HashMap<BasicBlock,BasicBlock> origToDupMap)
Go through all blocks in duplicated code and adjust the edges as
follows:
All edges (in duplicated code) that go into a block with a
yieldpoint must jump to back to the original code.
|
private void |
appendLoad(BasicBlock bb,
IR ir)
Append a load of the global counter to the given basic block.
|
private void |
cleanUp(IR ir)
Cleans up the IR after the transformation is applied.
|
private void |
conditionalizeInstrumentationOperation(IR ir,
Instruction i,
BasicBlock bb)
Take an instrumentation operation (an instruction) and guard it
with a counter-based check.
|
private void |
createCheck(BasicBlock checkBB,
BasicBlock noInstBB,
BasicBlock instBB,
boolean fallthroughToInstBB,
IR ir)
Append a check to a basic block, and make it jump to the right places.
|
static void |
dumpCFG(IR ir) |
private void |
duplicateCode(IR ir,
HashMap<BasicBlock,BasicBlock> origToDupMap,
HashSet<BasicBlock> exceptionHandlerBlocks)
Make a duplicate of all basic blocks down at the bottom of the
code order.
|
Constructor<CompilerPhase> |
getClassConstructor()
Get a constructor object for this compiler phase
|
private static Instruction |
getFirstInstWithOperator(Operator operator,
BasicBlock bb)
Go through all instructions and find the first with the given
operator.
|
static Instruction |
getFirstInstWithYieldPoint(BasicBlock bb)
Go through all instructions and find one that is a yield point
|
String |
getName() |
private static RegisterOperand |
getOrCreateDupReg(RegisterOperand ro,
IR ir,
Map<Register,Register> dupMappings)
The given register a) does not span multiple basic block, and b)
is used in a basic block that is being duplicated.
|
private void |
insertCBSChecks(IR ir,
HashMap<BasicBlock,BasicBlock> origToDupMap,
HashSet<BasicBlock> exceptionHandlerBlocks)
In the checking code, insert CBS checks at each yieldpoint, to
transfer code into the duplicated (instrumented) code.
|
private static boolean |
isInstrumentationInstruction(Instruction i)
How to determine whether a given instruction is an
"instrumentation instruction".
|
static boolean |
isYieldpoint(Instruction i)
Is the given instruction a yieldpoint?
|
private static BasicBlock |
myCopyWithoutLinks(BasicBlock bb,
IR ir)
The same as BasicBlock.copyWithoutLinks except that it
renames all temp variables that are never used outside the basic
block.
|
void |
perform(IR ir)
This is the method that actually does the work of the phase.
|
private void |
performVariationFullDuplication(IR ir)
Perform the full duplication algorithm
|
private void |
performVariationNoDuplication(IR ir)
Perform the NoDuplication version of the framework (see
Arnold-Ryder PLDI 2001).
|
private void |
prependCounterReset(BasicBlock bb,
IR ir)
Prepend the code to reset the global counter to the given basic
block.
|
private void |
prependDecrement(BasicBlock bb,
IR ir)
Append a decrement of the global counter to the given basic block.
|
private void |
prependStore(BasicBlock bb,
IR ir)
Append a store of the global counter to the given basic block.
|
private static void |
removeInstrumentationFromOrig(IR ir,
HashMap<BasicBlock,BasicBlock> origToDupMap)
Remove instrumentation from the original version of all duplicated
basic blocks.
|
boolean |
shouldPerform(OptOptions options)
This method determines if the phase should be run, based on the
Options object it is passed.
|
private static void |
updateTemps(BasicBlock bb,
IR ir)
Given an basic block, rename all of the temporary registers that are
local to the block.
|
dumpIR, dumpIR, getCompilerPhaseConstructor, getCompilerPhaseConstructor, newExecution, performPhase, printingEnabled, reportAdditionalStats, setContainer, verify
private static boolean DEBUG
private static boolean DEBUG2
private RegisterOperand cbsReg
private static final Constructor<CompilerPhase> constructor
public InstrumentationSamplingFramework()
public Constructor<CompilerPhase> getClassConstructor()
getClassConstructor
in class CompilerPhase
public boolean shouldPerform(OptOptions options)
CompilerPhase
shouldPerform
in class CompilerPhase
options
- the compiler options for the compilationpublic String getName()
getName
in class CompilerPhase
public void perform(IR ir)
CompilerPhase
perform
in class CompilerPhase
ir
- the IR on which to apply the phaseprivate void cleanUp(IR ir)
ir
- the IR to clean upprivate void performVariationFullDuplication(IR ir)
ir
- the governing IRprivate void duplicateCode(IR ir, HashMap<BasicBlock,BasicBlock> origToDupMap, HashSet<BasicBlock> exceptionHandlerBlocks)
ir
- the governing IRorigToDupMap
- a map (initially empty) that will store the mapping
of original blocks to their duplicatesexceptionHandlerBlocks
- a set that (initially empty) that is used
to remember the exception handlers. Those need to be known because they
need special checks (see insertCBSChecks(IR, HashMap, HashSet)
.private void insertCBSChecks(IR ir, HashMap<BasicBlock,BasicBlock> origToDupMap, HashSet<BasicBlock> exceptionHandlerBlocks)
ir
- the governing IRorigToDupMap
- a mapping of baisc block blocks to their duplicatesexceptionHandlerBlocks
- a set that of exception handler basic blocksprivate void createCheck(BasicBlock checkBB, BasicBlock noInstBB, BasicBlock instBB, boolean fallthroughToInstBB, IR ir)
checkBB
- The block to append the CBS check to.noInstBB
- The basic block to jump to if the CBS check failsinstBB
- The basicBlock to jump to if the CBS check succeedsfallthroughToInstBB
- Should checkBB fallthrough to instBB
(otherwise it must fallthrough to noInstBB)ir
- the IR that contains the blocksprivate void appendLoad(BasicBlock bb, IR ir)
bb
- The block to append the load toir
- The IRprivate void prependStore(BasicBlock bb, IR ir)
bb
- The block to append the load toir
- The IRprivate void prependDecrement(BasicBlock bb, IR ir)
bb
- The block to append the load toir
- The IRprivate void prependCounterReset(BasicBlock bb, IR ir)
bb
- The block to append the load toir
- The IRprivate static Instruction getFirstInstWithOperator(Operator operator, BasicBlock bb)
operator
- The operator to look forbb
- The basic block in which to lookpublic static Instruction getFirstInstWithYieldPoint(BasicBlock bb)
bb
- The basic block in which to lookpublic static boolean isYieldpoint(Instruction i)
For now we ignore epilogue yieldpoints since we are only concerned with method entries and backedges.
i
- the instruction to examineprivate static void adjustPointersInDuplicatedCode(IR ir, HashMap<BasicBlock,BasicBlock> origToDupMap)
origToDupMap
- mapping of basic blocks to their duplicatesir
- the governing IRprivate static void removeInstrumentationFromOrig(IR ir, HashMap<BasicBlock,BasicBlock> origToDupMap)
The yieldpoints can also be removed from either the original or the duplicated code. If you remove them from the original, it will make it run faster (since it is executed more than the duplicated) however that means that you can't turn off the instrumentation or you could infinitely loop without executing yieldpoints!
ir
- the governing IRorigToDupMap
- mapping of basic blocks to their duplicatesprivate static BasicBlock myCopyWithoutLinks(BasicBlock bb, IR ir)
PRECONDITION: the spansBasicBlock bit must be correct by calling DefUse.recomputeSpansBasicBlock(IR);
bb
- the basic block to processir
- the IR that contains the blockprivate static void updateTemps(BasicBlock bb, IR ir)
bb
- the blockir
- the IR that contains the blockprivate static RegisterOperand getOrCreateDupReg(RegisterOperand ro, IR ir, Map<Register,Register> dupMappings)
ro
- the register operand to duplicateir
- the IR that contains the register operanddupMappings
- the mappings of registers to duplicatesprivate void performVariationNoDuplication(IR ir)
ir
- the IR to processprivate void conditionalizeInstrumentationOperation(IR ir, Instruction i, BasicBlock bb)
ir
- the IR that contains the instructioni
- the instructionbb
- the basic block that contains the instructionprivate static boolean isInstrumentationInstruction(Instruction i)
i
- an instructiontrue
if and only if this is an instrumentation instruction