Search in sources :

Example 91 with InstructionHandle

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;
}
Also used : ObjectCache(com.jopdesign.wcet.jop.ObjectCache) ObjectCacheCost(com.jopdesign.wcet.jop.ObjectCache.ObjectCacheCost) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) BasicBlock(com.jopdesign.common.code.BasicBlock) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) CallString(com.jopdesign.common.code.CallString) ObjectCacheCost(com.jopdesign.wcet.jop.ObjectCache.ObjectCacheCost) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 92 with InstructionHandle

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));
}
Also used : InstructionList(org.apache.bcel.generic.InstructionList) ILOAD(org.apache.bcel.generic.ILOAD) InstructionHandle(org.apache.bcel.generic.InstructionHandle) AppInfo(com.jopdesign.common.AppInfo) TestFramework(com.jopdesign.common.TestFramework) AppSetup(com.jopdesign.common.AppSetup) MethodInfo(com.jopdesign.common.MethodInfo) MethodCode(com.jopdesign.common.MethodCode) ClassInfo(com.jopdesign.common.ClassInfo)

Example 93 with InstructionHandle

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;
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) BasicBlock(com.jopdesign.common.code.BasicBlock) MethodInfo(com.jopdesign.common.MethodInfo) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 94 with InstructionHandle

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 + "]";
}
Also used : Instruction(org.apache.bcel.generic.Instruction) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 95 with InstructionHandle

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);*/
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) BranchHandle(org.apache.bcel.generic.BranchHandle) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Aggregations

InstructionHandle (org.apache.bcel.generic.InstructionHandle)103 InstructionList (org.apache.bcel.generic.InstructionList)26 MethodInfo (com.jopdesign.common.MethodInfo)20 CallString (com.jopdesign.common.code.CallString)20 Instruction (org.apache.bcel.generic.Instruction)13 MethodCode (com.jopdesign.common.MethodCode)12 ContextMap (com.jopdesign.dfa.framework.ContextMap)11 IntermediateEdge (org.candle.decompiler.intermediate.graph.edge.IntermediateEdge)11 Context (com.jopdesign.dfa.framework.Context)10 InvokeInstruction (org.apache.bcel.generic.InvokeInstruction)10 Iterator (java.util.Iterator)9 BranchInstruction (org.apache.bcel.generic.BranchInstruction)9 FieldInstruction (org.apache.bcel.generic.FieldInstruction)9 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)9 ReturnInstruction (org.apache.bcel.generic.ReturnInstruction)8 InstructionFinder (org.apache.bcel.util.InstructionFinder)8 ClassInfo (com.jopdesign.common.ClassInfo)7 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 LinkedList (java.util.LinkedList)7