use of org.jikesrvm.adaptive.measurements.instrumentation.StringEventCounterData in project JikesRVM by JikesRVM.
the class InsertInstructionCounters method perform.
/**
* Insert a counter on every instruction, and group counts by
* opcode type.
*
* @param ir the governing IR
*/
@Override
public final void perform(IR ir) {
// the boot image, or when instrumentation is disabled
if (!ir.method.isInterruptible() || ir.method.getDeclaringClass().isInBootImage() || !Instrumentation.instrumentationEnabled()) {
return;
}
// Get the data object that handles the counters
StringEventCounterData data = AOSDatabase.instructionCounterData;
// Create a vector of basic blocks up front because the blocks
// are modified as we iterate below.
ArrayList<BasicBlock> bbList = new ArrayList<BasicBlock>();
for (Enumeration<BasicBlock> bbe = ir.getBasicBlocks(); bbe.hasMoreElements(); ) {
BasicBlock bb = bbe.nextElement();
bbList.add(bb);
}
// Iterate through the basic blocks
for (BasicBlock bb : bbList) {
// Add instructions to vector so enumeration doesn't mess
// things up. There is probably a better way to do this, but
// it doesn't matter because this is a debugging phase.
ArrayList<Instruction> iList = new ArrayList<Instruction>();
Instruction inst = bb.firstInstruction();
while (inst != null && inst != bb.lastInstruction()) {
iList.add(inst);
inst = inst.nextInstructionInCodeOrder();
}
// Iterate through all the instructions in this block.
for (Instruction i : iList) {
// Skip dangerous instructions
if (i.operator() == LABEL || Prologue.conforms(i)) {
continue;
}
if (i.isBranch() || i.operator() == RETURN) {
// It's a branch, so you need to be careful how you insert the
// counter.
Instruction prev = i.prevInstructionInCodeOrder();
// must end with branches only. Solve by splitting block.
if (prev.isBranch()) {
// BasicBlock newBlock =
bb.splitNodeWithLinksAt(prev, ir);
bb.recomputeNormalOut(ir);
}
// Use the name of the operator as the name of the event
Instruction counterInst = data.getCounterInstructionForEvent(i.operator().toString());
// Insert the new instruction into the code order
i.insertBefore(counterInst);
} else {
// It's a non-branching instruction. Insert counter before
// the instruction.
// Use the name of the operator as the name of the event
Instruction counterInst = data.getCounterInstructionForEvent(i.operator().toString());
i.insertBefore(counterInst);
}
}
}
}
Aggregations