Search in sources :

Example 11 with ExecutionContext

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

the class ExecFrequencyAnalysis method getExecCount.

////////////////////////////////////////////////////////////////////////////////////
// Query the analysis results
////////////////////////////////////////////////////////////////////////////////////
@Override
public long getExecCount(MethodInfo methodInfo) {
    long count = 0;
    for (ExecutionContext ec : callGraph.getNodes(methodInfo)) {
        Long c = nodeCount.get(ec);
        count += c;
    }
    return count;
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext)

Example 12 with ExecutionContext

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

the class DFATool method runLocalAnalysis.

public <K, V> Map runLocalAnalysis(Analysis<K, V> localAnalysis, ExecutionContext scope) {
    Interpreter<K, V> interpreter = new Interpreter<K, V>(localAnalysis, this);
    if (scope == null)
        throw new AssertionError("No such method: " + scope);
    Context context = new Context();
    MethodCode entryCode = scope.getMethodInfo().getCode();
    context.stackPtr = entryCode.getMaxLocals();
    context.setMethodInfo(scope.getMethodInfo());
    context.setCallString(scope.getCallString());
    localAnalysis.initialize(scope.getMethodInfo(), context);
    /* Here used to be a extremely-hard-to-trackdown bug!
         * Without the boolean parameters, getInstructionList() will dispose
         * the CFG, a very bad idea during WCET analysis which relies on
         * pointer equality for CFG edges :(
         */
    InstructionHandle entry = entryCode.getInstructionList(false, false).getStart();
    interpreter.interpret(context, entry, new LinkedHashMap<InstructionHandle, ContextMap<K, V>>(), true);
    return localAnalysis.getResult();
}
Also used : Context(com.jopdesign.dfa.framework.Context) ExecutionContext(com.jopdesign.common.code.ExecutionContext) Interpreter(com.jopdesign.dfa.framework.Interpreter) MethodCode(com.jopdesign.common.MethodCode) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ContextMap(com.jopdesign.dfa.framework.ContextMap)

Example 13 with ExecutionContext

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

the class TreeAnalysis method extractUBs.

private Map<CFGNode, Long> extractUBs(Map<CFGNode, LoopBound> loopBounds) {
    Map<CFGNode, Long> ubMap = new HashMap<CFGNode, Long>();
    for (Entry<CFGNode, LoopBound> entry : loopBounds.entrySet()) {
        MethodInfo mi = entry.getKey().getControlFlowGraph().getMethodInfo();
        ExecutionContext eCtx = new ExecutionContext(mi);
        ubMap.put(entry.getKey(), entry.getValue().getUpperBound(eCtx));
    }
    return ubMap;
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) HashMap(java.util.HashMap) LoopBound(com.jopdesign.common.code.LoopBound) MethodInfo(com.jopdesign.common.MethodInfo)

Example 14 with ExecutionContext

use of com.jopdesign.common.code.ExecutionContext 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 15 with ExecutionContext

use of com.jopdesign.common.code.ExecutionContext 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)

Aggregations

ExecutionContext (com.jopdesign.common.code.ExecutionContext)34 MethodInfo (com.jopdesign.common.MethodInfo)15 ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)11 LinkedHashSet (java.util.LinkedHashSet)10 ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)6 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)6 Set (java.util.Set)4 MethodCode (com.jopdesign.common.MethodCode)3 BasicBlockNode (com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode)3 LoopBound (com.jopdesign.common.code.LoopBound)3 DFSTraverser (com.jopdesign.common.graphutils.DFSTraverser)3 EmptyDFSVisitor (com.jopdesign.common.graphutils.DFSTraverser.EmptyDFSVisitor)3 AppInfoError (com.jopdesign.common.misc.AppInfoError)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 InstructionHandle (org.apache.bcel.generic.InstructionHandle)3 ClassInfo (com.jopdesign.common.ClassInfo)2 BasicBlock (com.jopdesign.common.code.BasicBlock)2 CallGraph (com.jopdesign.common.code.CallGraph)2 InvokeSite (com.jopdesign.common.code.InvokeSite)2