use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.
the class ObjectCacheAnalysis method extractCost.
/**
*
* @param segment the segment analyzed
* @param lpCost the lp objective value
* @param flowMap the lp assignment for variables
* @param accessCostInfo information on object cache cost edges
* @param costModel the object cache cost model
* @param refMissEdges the object cache cost edges for references
* @param blockMissEdges the object cache cost edges for blocks
* @return
*/
private ObjectCache.ObjectCacheCost extractCost(Segment segment, long lpCost, Map<SuperGraphEdge, Long> flowMap, AccessCostInfo accessCostInfo, ObjectCacheCostModel costModel, Set<SuperGraphEdge> refMissEdges, Set<SuperGraphEdge> blockMissEdges) {
long missCount = 0;
/* miss count */
long totalMissCost = 0;
/* has to be equal to (cost - bypass cost) */
long bypassAccesses = 0;
/* bypassed fields accesses */
long fieldAccesses = 0;
/* cached fields accessed */
long totalBypassCost = 0;
for (SuperGraphEdge edge : segment.getEdges()) {
long edgeFreq = flowMap.get(edge);
SuperGraphNode node = edge.getTarget();
/* Compute cost for basic block */
BasicBlock bb = node.getCFGNode().getBasicBlock();
if (bb == null)
continue;
long missCost = accessCostInfo.getMissCost(node) * edgeFreq;
totalMissCost += missCost;
totalBypassCost += accessCostInfo.getBypassCost(node) * edgeFreq;
/* Calculate number of unpredictable always-miss accesses, and record them */
long alwaysMissCost = costModel.getReplaceLineCost() + costModel.getLoadCacheBlockCost();
if (alwaysMissCost > 0) {
missCount += missCost / alwaysMissCost;
}
/* count normal and bypass accesses in the basic block */
for (InstructionHandle ih : bb.getInstructions()) {
String handleType = getHandleType(project, node.getCfg(), ih);
if (handleType == null)
continue;
/* No getfield/handle access */
if (!isFieldCached(project, node.getCfg(), ih, maxCachedFieldIndex)) {
bypassAccesses += edgeFreq;
} else {
fieldAccesses += edgeFreq;
}
}
}
/* For each miss edge, there is an associated cost; moreover
* fill-word & single-field: missCount = sum of miss block variables
* fill-line: missCount = sum of miss object reference variables
*/
long totalRefMisses = 0;
for (SuperGraphEdge refMissEdge : refMissEdges) {
totalRefMisses += flowMap.get(refMissEdge);
}
totalMissCost += costModel.getReplaceLineCost() * totalRefMisses;
long totalBlockMisses = 0;
for (SuperGraphEdge blockMissEdge : blockMissEdges) {
totalBlockMisses += flowMap.get(blockMissEdge);
}
totalMissCost += costModel.getLoadCacheBlockCost() * totalBlockMisses;
missCount += totalBlockMisses;
if (totalMissCost + totalBypassCost != lpCost) {
WCETTool.logger.warn(String.format("Error in calculating missCost in all fit-area (misscount = %d): %d but should be %d (%d - %d)", missCount, totalMissCost, lpCost - totalBypassCost, lpCost, totalBypassCost));
}
ObjectCache.ObjectCacheCost ocCost = new ObjectCache.ObjectCacheCost(missCount, totalMissCost, bypassAccesses, totalBypassCost, fieldAccesses);
return ocCost;
}
use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.
the class HashTest method main.
public static void main(String[] args) {
TestFramework test = new TestFramework();
AppSetup setup = test.setupAppSetup();
AppInfo appInfo = test.setupAppInfo("common.code.HashTest", false);
ClassInfo testClass = appInfo.loadClass("common.TestFramework");
MethodInfo mainMethod = appInfo.getMainMethod();
MethodCode code = mainMethod.getCode();
InstructionHandle[] ih = code.getInstructionList().getInstructionHandles();
InvokeSite i1 = code.getInvokeSite(ih[1]);
InvokeSite i2 = code.getInvokeSite(ih[2]);
InvokeSite i3 = code.getInvokeSite(ih[3]);
InvokeSite i11 = code.getInvokeSite(ih[1]);
check(i1 == i11);
CallString c1 = new CallString(i1);
CallString c2 = new CallString(i2);
CallString c11 = new CallString(i1);
check(c1.equals(c11));
check(!c1.equals(c2));
ExecutionContext e1 = new ExecutionContext(mainMethod, c1);
ExecutionContext e2 = new ExecutionContext(mainMethod, c2);
ExecutionContext e11 = new ExecutionContext(mainMethod, c11);
check(e1.equals(e11));
check(!e1.equals(e2));
// TODO put stuff into maps, check contains() and get()
// modify instruction list, check if everything still works
InstructionList il = code.getInstructionList();
il.insert(new ILOAD(0));
il.insert(ih[2], new ILOAD(1));
ih = il.getInstructionHandles();
InvokeSite i12 = code.getInvokeSite(ih[2]);
InvokeSite i22 = code.getInvokeSite(ih[4]);
check(i12 == i1);
check(i22 == i2);
check(e1.equals(e11));
check(!e1.equals(e2));
il.setPositions();
check(c1.equals(c11));
check(!c1.equals(c2));
check(e1.equals(e11));
check(!e1.equals(e2));
}
use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.
the class ConstantCache method build.
public ConstantCache build() {
List<MethodInfo> methods = project.getCallGraph().getReachableImplementations(project.getTargetMethod());
for (int i = methods.size() - 1; i >= 0; i--) {
MethodInfo mi = methods.get(i);
ControlFlowGraph cfg = project.getFlowGraph(mi);
for (CFGNode n : cfg.vertexSet()) {
BasicBlock bb = n.getBasicBlock();
if (bb == null)
continue;
for (InstructionHandle ii : bb.getInstructions()) {
extractConstantAddresses(cfg, ii);
}
}
}
return this;
}
use of org.apache.bcel.generic.InstructionHandle in project candle-decompiler by bradsdavis.
the class GoToIntermediate method toString.
@Override
public String toString() {
String t = null;
Instruction i = ((InstructionHandle) getInstruction()).getInstruction();
return "Goto [" + this.getInstruction().getPosition() + " -> " + t + "]";
}
use of org.apache.bcel.generic.InstructionHandle in project candle-decompiler by bradsdavis.
the class IntermediateGraphFactory method visitBooleanBranchIntermediate.
@Override
public void visitBooleanBranchIntermediate(BooleanBranchIntermediate line) {
InstructionHandle next = line.getInstruction().getNext();
// find how that actually maps to the abstract line..
AbstractIntermediate nextIntermediate = ilc.getNext(next.getPosition());
igc.getGraph().addVertex(nextIntermediate);
BranchHandle bi = ((BranchHandle) line.getInstruction());
AbstractIntermediate targetIntermediate = ilc.getNext(bi.getTarget().getPosition());
igc.getGraph().addVertex(targetIntermediate);
AbstractIntermediate lowest = targetIntermediate.getInstruction().getPosition() < nextIntermediate.getInstruction().getPosition() ? targetIntermediate : nextIntermediate;
AbstractIntermediate highest = targetIntermediate.getInstruction().getPosition() > nextIntermediate.getInstruction().getPosition() ? targetIntermediate : nextIntermediate;
/*
//add true path... (Conditional) -> (True) -> (Node A)
BooleanBranchOutcome trueOutcome = new BooleanBranchOutcome(line.getInstruction(), line, Boolean.TRUE);
//line.setTrueBranch(trueOutcome);
igc.getGraph().addVertex(trueOutcome);
igc.getGraph().addEdge(line, trueOutcome);
igc.getGraph().addEdge(trueOutcome, lowest);
//add false path... (Conditional) -> (False) -> (Node A)
BooleanBranchOutcome falseOutcome = new BooleanBranchOutcome(line.getInstruction(), line, Boolean.FALSE);
//line.setFalseBranch(falseOutcome);
igc.getGraph().addVertex(falseOutcome);
igc.getGraph().addEdge(line, falseOutcome);
igc.getGraph().addEdge(falseOutcome, highest);*/
}
Aggregations