Search in sources :

Example 51 with MethodInfo

use of com.jopdesign.common.MethodInfo in project jop by jop-devel.

the class MethodCacheAnalysis method isPersistenceRegion.

public boolean isPersistenceRegion(WCETTool wcetTool, MethodInfo m, CallString cs, EnumSet<PersistenceCheck> tests) {
    /* fast path for the optimizer (segments are still slow) */
    if (tests == EnumSet.of(PersistenceCheck.CountTotal)) {
        List<MethodInfo> methods = wcetTool.getCallGraph().getReachableImplementations(m, cs);
        long blocks = 0;
        for (MethodInfo reachable : methods) {
            blocks += methodCache.requiredNumberOfBlocks(reachable);
        }
        return methodCache.allFit(blocks);
    }
    Segment segment = Segment.methodSegment(m, cs, wcetTool, wcetTool.getCallstringLength(), wcetTool);
    return isPersistenceRegion(segment, tests);
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo) Segment(com.jopdesign.common.code.Segment)

Example 52 with MethodInfo

use of com.jopdesign.common.MethodInfo in project jop by jop-devel.

the class ObjectCacheAnalysis method getAccessEdges.

/**
 * Get all access sites per method
 */
public static Map<MethodInfo, Set<SuperGraph.SuperGraphEdge>> getAccessEdges(SuperGraph sg) {
    Map<MethodInfo, Set<SuperGraph.SuperGraphEdge>> accessEdges = new HashMap<MethodInfo, Set<SuperGraph.SuperGraphEdge>>();
    for (Entry<SuperGraph.SuperInvokeEdge, SuperGraph.SuperReturnEdge> invokeSite : sg.getSuperEdgePairs().entrySet()) {
        MethodInfo invoked = invokeSite.getKey().getInvokeNode().receiverFlowGraph().getMethodInfo();
        addToSet(accessEdges, invoked, invokeSite.getKey());
        MethodInfo invoker = invokeSite.getKey().getInvokeNode().invokerFlowGraph().getMethodInfo();
        addToSet(accessEdges, invoker, invokeSite.getValue());
    }
    return accessEdges;
}
Also used : EnumSet(java.util.EnumSet) MiscUtils.addToSet(com.jopdesign.common.misc.MiscUtils.addToSet) Set(java.util.Set) BoundedSet(com.jopdesign.dfa.framework.BoundedSetFactory.BoundedSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) SuperGraph(com.jopdesign.common.code.SuperGraph) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) SuperReturnEdge(com.jopdesign.common.code.SuperGraph.SuperReturnEdge) MethodInfo(com.jopdesign.common.MethodInfo) SuperInvokeEdge(com.jopdesign.common.code.SuperGraph.SuperInvokeEdge)

Example 53 with MethodInfo

use of com.jopdesign.common.MethodInfo in project jop by jop-devel.

the class WCETAnalysis method runMetrics.

private void runMetrics(MethodInfo targetMethod) throws Exception {
    /* generate reports later for simple_fit */
    wcetTool.setGenerateWCETReport(false);
    /* check whether the largest method fits into the cache */
    List<MethodInfo> allMethods = wcetTool.getCallGraph().getReachableImplementations(targetMethod);
    MethodInfo largestMethod = MethodCacheAnalysis.checkCache(wcetTool, allMethods);
    int minWords = MiscUtils.bytesToWords(largestMethod.getCode().getNumberOfBytes());
    reportMetric("min-cache-size", largestMethod.getFQMethodName(), minWords);
    /* Compute cyclomatic complexity */
    exec.info("Cyclomatic complexity: " + wcetTool.computeCyclomaticComplexity(targetMethod));
    /* Fast, useful cache approximationx */
    CacheCostCalculationMethod cacheApprox = CacheCostCalculationMethod.ALL_FIT_SIMPLE;
    /* Perform a few standard analysis (MIN_CACHE_COSdT, ALWAYS_HIT, ALWAYS_MISS) without call strings */
    long start, stop;
    /* Tree based WCET analysis - has to be equal to ALWAYS_MISS if no flow facts are used */
    {
        start = System.nanoTime();
        TreeAnalysis treeAna = new TreeAnalysis(wcetTool, false);
        long treeWCET = treeAna.computeWCET(targetMethod);
        stop = System.nanoTime();
        reportMetric("progress-measure", treeAna.getMaxProgress(targetMethod));
        reportSpecial("wcet.tree", WcetCost.totalCost(treeWCET), start, stop, 0.0);
    }
    RecursiveWcetAnalysis<AnalysisContextLocal> an = new RecursiveWcetAnalysis<AnalysisContextLocal>(wcetTool, ipetConfig, new LocalAnalysis(wcetTool, ipetConfig));
    /* always miss */
    start = System.nanoTime();
    alwaysMissCost = an.computeCost(targetMethod, new AnalysisContextLocal(CacheCostCalculationMethod.ALWAYS_MISS));
    stop = System.nanoTime();
    reportSpecial("always-miss", alwaysMissCost, start, stop, LpSolveWrapper.getSolverTime());
    /* always hit */
    LpSolveWrapper.resetSolverTime();
    start = System.nanoTime();
    alwaysHitCost = an.computeCost(targetMethod, new AnalysisContextLocal(CacheCostCalculationMethod.ALWAYS_HIT));
    stop = System.nanoTime();
    reportSpecial("always-hit", alwaysHitCost, start, stop, LpSolveWrapper.getSolverTime());
    /* simple approx */
    wcetTool.setGenerateWCETReport(true);
    start = System.nanoTime();
    approxCost = an.computeCost(targetMethod, new AnalysisContextLocal(cacheApprox));
    stop = System.nanoTime();
    reportSpecial("recursive-report", approxCost, start, stop, LpSolveWrapper.getSolverTime());
    wcetTool.setGenerateWCETReport(false);
}
Also used : CacheCostCalculationMethod(com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod) MethodInfo(com.jopdesign.common.MethodInfo) AnalysisContextLocal(com.jopdesign.wcet.analysis.AnalysisContextLocal) RecursiveWcetAnalysis(com.jopdesign.wcet.analysis.RecursiveWcetAnalysis) LocalAnalysis(com.jopdesign.wcet.analysis.LocalAnalysis) TreeAnalysis(com.jopdesign.wcet.analysis.TreeAnalysis)

Example 54 with MethodInfo

use of com.jopdesign.common.MethodInfo in project jop by jop-devel.

the class WCETTool method computeCyclomaticComplexity.

// public File getOutFile(String file) {
// return new File(projectConfig.getOutDir(), file);
// }
/* FIXME: Slow, caching is missing */
public int computeCyclomaticComplexity(MethodInfo m) {
    ControlFlowGraph g = getFlowGraph(m);
    int nLocal = g.vertexSet().size();
    int eLocal = g.edgeSet().size();
    int pLocal = g.buildLoopBoundMap().size();
    int ccLocal = eLocal - nLocal + 2 * pLocal;
    int ccGlobal = 0;
    for (ExecutionContext n : this.getCallGraph().getReferencedMethods(m)) {
        MethodInfo impl = n.getMethodInfo();
        ccGlobal += 2 + computeCyclomaticComplexity(impl);
    }
    return ccLocal + ccGlobal;
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) MethodInfo(com.jopdesign.common.MethodInfo)

Example 55 with MethodInfo

use of com.jopdesign.common.MethodInfo in project jop by jop-devel.

the class ControlFlowGraph method resolveVirtualInvokes.

/**
 * resolve all virtual invoke nodes, and replace them by actual implementations.
 * <p>
 * This uses the context and the implementation finder passed to the constructor of this graph.
 * </p>
 *
 * @throws BadGraphException If the flow graph analysis (post replacement) fails
 */
@SuppressWarnings({ "AccessingNonPublicFieldOfAnotherObject" })
public void resolveVirtualInvokes() throws BadGraphException {
    // Hack to make this optional
    if (virtualInvokesResolved)
        return;
    virtualInvokesResolved = true;
    clean = false;
    if (hasReturnNodes) {
        throw new AssertionError("Virtuals need to be resolved before inserting return nodes (file a bug)");
    }
    List<InvokeNode> virtualInvokes = new ArrayList<InvokeNode>();
    /* find virtual invokes */
    for (CFGNode n : this.graph.vertexSet()) {
        if (n instanceof InvokeNode) {
            InvokeNode in = (InvokeNode) n;
            if (in.isVirtual()) {
                virtualInvokes.add(in);
            }
        }
    }
    /* replace them */
    for (InvokeNode inv : virtualInvokes) {
        // Magic: this uses the context and the implementation finder passed to the constructor of this graph.
        Set<MethodInfo> impls = inv.getImplementingMethods();
        if (impls.size() == 0)
            internalError("No implementations for " + inv.referenced + " possibly invoked from " + inv.getBasicBlock().getMethodInfo());
        if (impls.size() == 1) {
            InvokeNode implNode = inv.createImplNode(impls.iterator().next(), inv);
            graph.addVertex(implNode);
            for (CFGEdge inEdge : graph.incomingEdgesOf(inv)) {
                graph.addEdge(graph.getEdgeSource(inEdge), implNode, new CFGEdge(inEdge.kind));
            }
            for (CFGEdge outEdge : graph.outgoingEdgesOf(inv)) {
                graph.addEdge(implNode, graph.getEdgeTarget(outEdge), new CFGEdge(outEdge.kind));
            }
        } else {
            /* more than one impl, create split/join nodes */
            CFGNode split = createSplitNode();
            graph.addVertex(split);
            for (CFGEdge inEdge : graph.incomingEdgesOf(inv)) {
                graph.addEdge(graph.getEdgeSource(inEdge), split, new CFGEdge(inEdge.kind));
            }
            CFGNode join = createJoinNode();
            graph.addVertex(join);
            for (CFGEdge outEdge : graph.outgoingEdgesOf(inv)) {
                graph.addEdge(join, graph.getEdgeTarget(outEdge), new CFGEdge(outEdge.kind));
            }
            for (MethodInfo impl : impls) {
                InvokeNode implNode = inv.createImplNode(impl, inv);
                graph.addVertex(implNode);
                graph.addEdge(split, implNode, new CFGEdge(EdgeKind.DISPATCH_EDGE));
                graph.addEdge(implNode, join, new CFGEdge(EdgeKind.RETURN_EDGE));
            }
        }
        graph.removeVertex(inv);
    }
    this.invalidate();
    this.check();
    this.analyseFlowGraph();
}
Also used : ArrayList(java.util.ArrayList) MethodInfo(com.jopdesign.common.MethodInfo)

Aggregations

MethodInfo (com.jopdesign.common.MethodInfo)108 LinkedHashSet (java.util.LinkedHashSet)21 InstructionHandle (org.apache.bcel.generic.InstructionHandle)20 ClassInfo (com.jopdesign.common.ClassInfo)19 ExecutionContext (com.jopdesign.common.code.ExecutionContext)16 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)13 ArrayList (java.util.ArrayList)13 CallString (com.jopdesign.common.code.CallString)12 ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)12 HashMap (java.util.HashMap)10 Set (java.util.Set)10 LinkedHashMap (java.util.LinkedHashMap)9 Instruction (org.apache.bcel.generic.Instruction)9 FieldInfo (com.jopdesign.common.FieldInfo)8 MethodCode (com.jopdesign.common.MethodCode)8 AppInfo (com.jopdesign.common.AppInfo)7 ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)7 InvokeSite (com.jopdesign.common.code.InvokeSite)7 MemberID (com.jopdesign.common.type.MemberID)7 Context (com.jopdesign.dfa.framework.Context)7