Search in sources :

Example 21 with CFGNode

use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.

the class WCETAnalysis method runBlockingTimeAnalysis.

private void runBlockingTimeAnalysis(MethodInfo targetMethod) throws InvalidFlowFactException, LpSolveException, UnsupportedCacheModelException {
    GlobalAnalysis an = new GlobalAnalysis(wcetTool, ipetConfig);
    CacheCostCalculationMethod requestedCacheApprox = IPETConfig.getRequestedCacheApprox(config);
    /* Find all synchronized segments */
    Segment target = Segment.methodSegment(targetMethod, CallString.EMPTY, wcetTool, wcetTool.getCallstringLength(), wcetTool);
    ArrayList<SynchronizedBlockResult> sBlocks = new ArrayList<SynchronizedBlockResult>();
    for (ContextCFG ccfg : target.getCallGraphNodes()) {
        for (CFGNode cfgNode : ccfg.getCfg().vertexSet()) {
            if (cfgNode.getBasicBlock() == null)
                continue;
            for (InstructionHandle ih : cfgNode.getBasicBlock().getInstructions()) {
                if (ih.getInstruction() instanceof MONITORENTER) {
                    /* compute synchronized block WCET */
                    Segment synchronizedSegment = Segment.synchronizedSegment(ccfg, cfgNode, ih, wcetTool, wcetTool.getCallstringLength(), wcetTool);
                    wcet = an.computeWCET(targetMethod.getShortName(), synchronizedSegment, requestedCacheApprox);
                    sBlocks.add(new SynchronizedBlockResult(sBlocks.size(), synchronizedSegment, cfgNode, ih, wcet));
                }
            }
        }
    }
    /* check nested synchronized blocks */
    for (SynchronizedBlockResult sBlock : sBlocks) {
        for (SynchronizedBlockResult otherBlock : sBlocks) {
            if (sBlock == otherBlock)
                continue;
            for (SuperGraphEdge entryEdge : otherBlock.synchronizedSegment.getEntryEdges()) {
                if (sBlock.synchronizedSegment.includesEdge(entryEdge)) {
                    sBlock.nested.add(otherBlock);
                    break;
                }
            }
        }
    }
    System.out.println("=== Synchronized Blocks ===");
    for (SynchronizedBlockResult sBlock : sBlocks) {
        sBlock.dump(System.out);
    }
}
Also used : CacheCostCalculationMethod(com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) GlobalAnalysis(com.jopdesign.wcet.analysis.GlobalAnalysis) ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) ArrayList(java.util.ArrayList) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) MONITORENTER(org.apache.bcel.generic.MONITORENTER) Segment(com.jopdesign.common.code.Segment) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 22 with CFGNode

use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.

the class JavaOneProcessPerSupergraphTranslator method recordLoops.

// Global maximal nesting depth is given by the equation
//   node.gmnd = node.method.gmnd + (node.loop ? node.loop.nestingDepth : 0)
//   method.gmnd = max { cs.method.gmnd + cs.gmnd | cs <- method.callsites }
// Example:
//  main() { for() for() X: f(); }
//  f() { for() for(HOL) }
//  nesting depth of HOL is 2
//  gmnd of f is gmnd of X = 2 + gmnd of main = 2
//  gmnd of HOL is 4
private void recordLoops(TemplateBuilder tBuilder) {
    try {
        computeMethodNestingDepths();
    } catch (BadGraphException e) {
        throw new BadGraphError(e);
    }
    for (MethodInfo m : methodInfos) {
        ControlFlowGraph cfg = project.getFlowGraph(m);
        for (Entry<CFGNode, LoopBound> entry : cfg.buildLoopBoundMap().entrySet()) {
            CFGNode hol = entry.getKey();
            LoopBound lb = entry.getValue();
            int nesting = cfg.getLoopColoring().getLoopColor(hol).size();
            int gmnd = nesting + methodMNDs.get(m);
            tBuilder.addLoop(hol, gmnd, lb);
        }
    }
    if (config.debug)
        tBuilder.dumpLoops();
}
Also used : BadGraphException(com.jopdesign.common.misc.BadGraphException) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) BadGraphError(com.jopdesign.common.misc.BadGraphError) LoopBound(com.jopdesign.common.code.LoopBound) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) MethodInfo(com.jopdesign.common.MethodInfo)

Example 23 with CFGNode

use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.

the class MethodBuilder method buildEdge.

private void buildEdge(ControlFlowGraph.CFGEdge edge) {
    Set<CFGNode> hols = cfg.getLoopColoring().getHeadOfLoops();
    Set<ControlFlowGraph.CFGEdge> backEdges = cfg.getLoopColoring().getBackEdges();
    Map<ControlFlowGraph.CFGEdge, LoopColoring.IterationBranchLabel<CFGNode>> edgeColoring = cfg.getLoopColoring().getIterationBranchEdges();
    CFGNode src = cfg.getEdgeSource(edge);
    CFGNode target = cfg.getEdgeTarget(edge);
    if (src == cfg.getEntry() && target == cfg.getExit())
        return;
    Transition transition = tBuilder.createTransition(nodeTemplates.get(src).getExit(), nodeTemplates.get(target).getEntry());
    TransitionAttributes attrs = transition.getAttrs();
    LoopColoring.IterationBranchLabel<CFGNode> edgeColor = edgeColoring.get(edge);
    if (jTrans.getConfig().useProgressMeasure) {
        if (src instanceof ControlFlowGraph.InvokeNode) {
            attrs.appendUpdate("pm := pm + 1");
        } else {
            RelativeProgress<CFGNode> progress = jTrans.getProgress(cfg.getMethodInfo()).get(edge);
            String progressExpr = "pm := pm + " + progress.staticDiff;
            for (Entry<CFGNode, Long> loopDiff : progress.loopDiff.entrySet()) {
                progressExpr += String.format(" - %d * %s", loopDiff.getValue(), tBuilder.getLoopVar(loopDiff.getKey()));
            }
            attrs.appendUpdate(progressExpr);
        }
    }
    if (edgeColor != null) {
        for (CFGNode loop : edgeColor.getContinues()) {
            attrs.appendGuard(tBuilder.contLoopGuard(loop));
            attrs.appendUpdate(tBuilder.incrLoopCounter(loop));
        }
        for (CFGNode loop : edgeColor.getExits()) {
            attrs.appendGuard(tBuilder.exitLoopGuard(loop));
            attrs.appendUpdate(tBuilder.resetLoopCounter(loop));
        }
    }
    if (hols.contains(target) && !backEdges.contains(edge)) {
        attrs.appendUpdate(tBuilder.resetLoopCounter(target));
    }
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) TransitionAttributes(com.jopdesign.wcet.uppaal.model.TransitionAttributes) CallString(com.jopdesign.common.code.CallString) LoopColoring(com.jopdesign.common.graphutils.LoopColoring) Transition(com.jopdesign.wcet.uppaal.model.Transition)

Example 24 with CFGNode

use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.

the class MethodBuilder method build.

public void build() {
    this.nodeTemplates = new HashMap<CFGNode, SubAutomaton>();
    this.tBuilder.addDescription("Template for method " + cfg.getMethodInfo());
    /* Translate the CFGs nodes */
    for (CFGNode node : cfg.vertexSet()) {
        node.accept(this);
    }
    /* Translate the CFGs edges */
    for (ControlFlowGraph.CFGEdge edge : cfg.edgeSet()) {
        buildEdge(edge);
    }
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph)

Example 25 with CFGNode

use of com.jopdesign.common.code.ControlFlowGraph.CFGNode in project jop by jop-devel.

the class SegmentTest method main.

public static void main(String[] args) {
    TestFramework testFramework = new TestFramework();
    AppSetup setup = testFramework.setupAppSetup("java/tools/test/test/cg1.zip", null);
    AppInfo appInfo = testFramework.setupAppInfo("wcet.devel.CallGraph1.run", true);
    SegmentTest testInst = new SegmentTest();
    testInst.appInfo = appInfo;
    MethodInfo mainMethod = appInfo.getMainMethod();
    /* count total number of CFG nodes */
    SuperGraph superGraph = new SuperGraph(testInst, testInst.getFlowGraph(mainMethod), 2);
    Segment segment = Segment.methodSegment(mainMethod, CallString.EMPTY, testInst, 2, superGraph.getInfeasibleEdgeProvider());
    int count = 0;
    for (ContextCFG cgNode : superGraph.getCallGraphNodes()) {
        try {
            cgNode.getCfg().exportDOT(new File("/tmp/cfg-" + cgNode.getCfg().getMethodInfo().getClassName() + "_" + cgNode.getCfg().getMethodInfo().getShortName() + ".dot"));
        } catch (IOException e) {
        }
        count += cgNode.getCfg().vertexSet().size();
    }
    checkEquals("[Segment 1] Expected node count", (count - 2), Iterators.size(segment.getNodes()));
    try {
        segment.exportDOT(new File("/tmp/cg1-segment.dot"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    /* root */
    ContextCFG root = superGraph.getRootNode();
    /* Build a segment cuts all invokes in those methods invoked by run() */
    Segment segment2;
    /* root entries */
    Set<SuperGraphEdge> entries = new HashSet<SuperGraphEdge>();
    Iterators.addAll(entries, superGraph.liftCFGEdges(root, root.getCfg().outgoingEdgesOf(root.getCfg().getEntry())));
    Set<SuperGraphEdge> exits = new HashSet<SuperGraphEdge>();
    int cfgNodeCandidateCount = root.getCfg().vertexSet().size();
    /* find callees */
    for (SuperEdge superEdge : superGraph.getCallGraph().outgoingEdgesOf(root)) {
        if (!(superEdge instanceof SuperInvokeEdge))
            continue;
        ContextCFG callee1 = superGraph.getCallGraph().getEdgeTarget(superEdge);
        cfgNodeCandidateCount += callee1.getCfg().vertexSet().size();
        /* find all edges from invoke nodes */
        for (CFGNode cfgNode : callee1.getCfg().vertexSet()) {
            if (cfgNode instanceof InvokeNode) {
                Iterators.addAll(exits, superGraph.outgoingEdgesOf(new SuperGraphNode(callee1, cfgNode)));
            }
        }
    }
    segment2 = new Segment(superGraph, entries, exits);
    exits = segment2.getExitEdges();
    /* reachable exits */
    try {
        segment2.exportDOT(new File("/tmp/cg1-segment2.dot"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    checkEquals("[Segment 2] Expected node count", 14, Iterators.size(segment2.getNodes()) + 2);
    checkLessEqual("[Segment 2] Expected node count <= |root + directly invoked|", Iterators.size(segment2.getNodes()) + 2, cfgNodeCandidateCount);
    /* Another segment, with entries the exits of the last segment, and exits all invokes in methods the entries */
    Segment segment3;
    entries = segment2.getExitEdges();
    exits = new HashSet<SuperGraphEdge>();
    cfgNodeCandidateCount = 0;
    for (SuperGraphEdge superEdge : entries) {
        SuperGraphNode node1 = superEdge.getTarget();
        for (SuperEdge superEdge2 : superGraph.getCallGraph().outgoingEdgesOf(node1.getContextCFG())) {
            if (!(superEdge2 instanceof SuperInvokeEdge))
                continue;
            ContextCFG callee2 = superGraph.getCallGraph().getEdgeTarget(superEdge2);
            /* find all edges from invoke nodes */
            for (CFGNode cfgNode : callee2.getCfg().vertexSet()) {
                if (cfgNode instanceof InvokeNode) {
                    Iterators.addAll(exits, superGraph.outgoingEdgesOf(new SuperGraphNode(callee2, cfgNode)));
                }
            }
        }
    }
    segment3 = new Segment(superGraph, entries, exits);
    try {
        segment3.exportDOT(new File("/tmp/cg1-segment3.dot"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    checkEquals("[Segment 2] 3 exits", 3, segment2.getExitEdges().size());
    checkEquals("[Segment 3] 3 entries", 3, segment3.getEntryEdges().size());
    checkEquals("[Segment 3] 4 exits", 4, segment3.getExitEdges().size());
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) IOException(java.io.IOException) SuperEdge(com.jopdesign.common.code.SuperGraph.SuperEdge) AppInfo(com.jopdesign.common.AppInfo) SuperInvokeEdge(com.jopdesign.common.code.SuperGraph.SuperInvokeEdge) TestFramework(com.jopdesign.common.TestFramework) ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) InvokeNode(com.jopdesign.common.code.ControlFlowGraph.InvokeNode) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) AppSetup(com.jopdesign.common.AppSetup) MethodInfo(com.jopdesign.common.MethodInfo) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)28 MethodInfo (com.jopdesign.common.MethodInfo)13 ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)13 CFGEdge (com.jopdesign.common.code.ControlFlowGraph.CFGEdge)10 LoopBound (com.jopdesign.common.code.LoopBound)7 ExecutionContext (com.jopdesign.common.code.ExecutionContext)6 HashMap (java.util.HashMap)6 InstructionHandle (org.apache.bcel.generic.InstructionHandle)6 SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)5 InvokeNode (com.jopdesign.common.code.ControlFlowGraph.InvokeNode)4 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 BasicBlock (com.jopdesign.common.code.BasicBlock)3 BasicBlockNode (com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 ClassInfo (com.jopdesign.common.ClassInfo)2 MethodCode (com.jopdesign.common.MethodCode)2 ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)2