Search in sources :

Example 46 with MethodInfo

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

the class TreeAnalysis method computeProgress.

/* FIXME: filter leaf methods is really a ugly hack,
         * but needs some work to play nice with uppaal eliminate-leaf-methods optimizations
         */
public void computeProgress(MethodInfo targetMethod, CallString cs) {
    List<MethodInfo> reachable = project.getCallGraph().getReachableImplementations(targetMethod, cs);
    Collections.reverse(reachable);
    for (MethodInfo mi : reachable) {
        ControlFlowGraph cfg = project.getFlowGraph(mi);
        Map<CFGNode, Long> localProgress = new HashMap<CFGNode, Long>();
        ProgressVisitor progressVisitor = new ProgressVisitor(maxProgress);
        for (CFGNode n : cfg.vertexSet()) {
            localProgress.put(n, progressVisitor.getProgress(n));
        }
        ProgressMeasure<CFGNode, CFGEdge> pm = new ProgressMeasure<CFGNode, ControlFlowGraph.CFGEdge>(cfg.getGraph(), cfg.getLoopColoring(), extractUBs(cfg.buildLoopBoundMap()), localProgress);
        long progress = pm.getMaxProgress().get(cfg.getExit());
        /* FIXME: _UGLY_ hack */
        if (filterLeafMethods && cfg.isLeafMethod()) {
            maxProgress.put(mi, 0L);
        } else {
            maxProgress.put(mi, progress);
        }
        relativeProgress.put(mi, pm.computeRelativeProgress());
    }
    System.out.println("Progress Measure (max): " + maxProgress.get(targetMethod));
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) HashMap(java.util.HashMap) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) MethodInfo(com.jopdesign.common.MethodInfo) ProgressMeasure(com.jopdesign.common.graphutils.ProgressMeasure) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge)

Example 47 with MethodInfo

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

the class ExecuteOnceAnalysis method analyze.

private void analyze() {
    inLoopSet = new HashMap<ExecutionContext, Set<MethodInfo>>();
    /* Top Down the Scope Graph */
    TopologicalOrderIterator<ExecutionContext, ContextEdge> iter = project.getCallGraph().topDownIterator();
    while (iter.hasNext()) {
        ExecutionContext scope = iter.next();
        scope = new ExecutionContext(scope.getMethodInfo());
        /* Remove call string */
        ControlFlowGraph cfg = project.getFlowGraph(scope.getMethodInfo());
        Set<MethodInfo> inLoop = new HashSet<MethodInfo>();
        for (CFGNode node : cfg.vertexSet()) {
            if (!(node instanceof ControlFlowGraph.InvokeNode))
                continue;
            ControlFlowGraph.InvokeNode iNode = (ControlFlowGraph.InvokeNode) node;
            if (!cfg.getLoopColoring().getLoopColor(node).isEmpty()) {
                for (MethodInfo impl : iNode.getImplementingMethods()) {
                    inLoop.add(impl);
                    inLoop.addAll(project.getCallGraph().getReachableImplementationsSet(impl));
                }
            }
        }
        inLoopSet.put(scope, inLoop);
    }
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext) HashSet(java.util.HashSet) Set(java.util.Set) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) MethodInfo(com.jopdesign.common.MethodInfo) ContextEdge(com.jopdesign.common.code.CallGraph.ContextEdge) HashSet(java.util.HashSet)

Example 48 with MethodInfo

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

the class ExecuteOnceAnalysis method isExecutedOnce.

public boolean isExecutedOnce(ExecutionContext scope, CFGNode node) {
    ControlFlowGraph cfg = node.getControlFlowGraph();
    scope = new ExecutionContext(scope.getMethodInfo());
    /* Remove call string */
    Set<MethodInfo> inLoopMethods = inLoopSet.get(scope);
    if (inLoopMethods == null) {
        Logger.getLogger("Object Cache Analysis").warning("No loop information for " + scope.getMethodInfo().getFQMethodName());
        return false;
    }
    if (!inLoopMethods.contains(cfg.getMethodInfo())) {
        return cfg.getLoopColoring().getLoopColor(node).size() == 0;
    } else {
        return false;
    }
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext) ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) MethodInfo(com.jopdesign.common.MethodInfo)

Example 49 with MethodInfo

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

the class MethodCacheAnalysis method checkCache.

/**
 * Check that cache is big enough to hold any method possibly invoked
 * Return largest method
 */
public static MethodInfo checkCache(WCETTool wcetTool, Iterable<MethodInfo> methods) throws AppInfoException {
    MethodCache methodCache = wcetTool.getWCETProcessorModel().getMethodCache();
    int maxWords = 0;
    MethodInfo largestMethod = null;
    // for (ClassInfo ci : project.getAppInfo().getClassInfos()) {
    for (MethodInfo mi : methods) {
        MethodCode code = mi.getCode();
        if (code == null)
            continue;
        // FIXME: using getNumberOfBytes(false) here to be compatible to old behaviour.
        // should probably be getNumberOfBytes()
        int size = code.getNumberOfBytes(false);
        int words = MiscUtils.bytesToWords(size);
        if (!methodCache.fitsInCache(words)) {
            throw new AppInfoException("Cache to small for target method: " + mi.getFQMethodName() + " / " + words + " words");
        }
        if (words >= maxWords) {
            largestMethod = mi;
            maxWords = words;
        }
    }
    return largestMethod;
}
Also used : MethodCache(com.jopdesign.wcet.jop.MethodCache) MethodInfo(com.jopdesign.common.MethodInfo) AppInfoException(com.jopdesign.common.misc.AppInfoException) MethodCode(com.jopdesign.common.MethodCode)

Example 50 with MethodInfo

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

the class MethodCacheAnalysis method getInvokeReturnMissCost.

/* utility functions */
/**
 * Get the maximum method cache miss penalty for invoking {@code invoked} and returning to {@code invoker}.<br/>
 * Also works with virtual invokes (taking the maximum cost)
 * @param invokeSite the invoke site
 * @param context call context
 * @return miss penalty in cycles
 */
public long getInvokeReturnMissCost(InvokeSite invokeSite, CallString context) {
    ControlFlowGraph invokerCfg = wcetTool.getFlowGraph(invokeSite.getInvoker());
    long rMiss = methodCache.getMissPenaltyOnReturn(invokerCfg.getNumberOfWords(), invokeSite.getInvokeeRef().getDescriptor().getType());
    long iMissMax = 0;
    for (MethodInfo target : wcetTool.findImplementations(invokeSite.getInvoker(), invokeSite.getInstructionHandle(), context)) {
        ControlFlowGraph invokedCfg = wcetTool.getFlowGraph(target);
        long iMiss = methodCache.getMissPenaltyOnInvoke(invokedCfg.getNumberOfWords(), invokeSite.getInstructionHandle().getInstruction());
        if (iMiss > iMissMax)
            iMissMax = iMiss;
    }
    return iMissMax + rMiss;
}
Also used : ControlFlowGraph(com.jopdesign.common.code.ControlFlowGraph) 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