Search in sources :

Example 56 with MethodInfo

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

the class ControlFlowGraph method addBasicBlock.

/*---------------------------------------------------------------------------*
     * CFG modify, compile, dispose
     *---------------------------------------------------------------------------*/
/**
 * Add a basic block to this graph. The instruction list of the block must not be empty.
 *
 * @param insertBefore insert the block at this position in the block list.
 * @param bb block to add
 * @return the new block node, either an InvokeNode, SpecialInvokeNode or BasicBlockNode, depending on the
 *   contained instructions.
 */
public BasicBlockNode addBasicBlock(int insertBefore, BasicBlock bb) {
    BasicBlockNode n;
    Instruction lastInstr = bb.getLastInstruction().getInstruction();
    InstructionHandle theInvoke = bb.getTheInvokeInstruction();
    // This needs to be done before creating the Node, else blocks.indexOf returns -1
    blocks.add(insertBefore, bb);
    if (theInvoke != null) {
        n = new InvokeNode(bb, theInvoke);
    } else if (appInfo.getProcessorModel().isImplementedInJava(methodInfo, lastInstr)) {
        MethodInfo javaImpl = appInfo.getProcessorModel().getJavaImplementation(appInfo, bb.getMethodInfo(), lastInstr);
        n = new SpecialInvokeNode(bb, javaImpl);
    } else {
        n = new BasicBlockNode(bb);
    }
    graph.addVertex(n);
    return n;
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo) InvokeInstruction(org.apache.bcel.generic.InvokeInstruction) Instruction(org.apache.bcel.generic.Instruction) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 57 with MethodInfo

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

the class InvokeSite method canInvoke.

/**
 * @param methodInfo a possible invokee
 * @return true if this invokeSite may invoke the method. Does not use the callgraph to check.
 *   For interface invoke sites this can return UNKNOWN if the class of the given method implementation
 *   does not implement the referenced interface.
 */
public Ternary canInvoke(MethodInfo methodInfo) {
    assert methodInfo != null;
    MethodRef invokeeRef = getInvokeeRef();
    MethodInfo method = invokeeRef.getMethodInfo();
    if (methodInfo.equals(method)) {
        return Ternary.TRUE;
    }
    if (!isVirtual()) {
        // and therefore cannot be invoked
        return Ternary.FALSE;
    }
    if (method == null) {
        return Ternary.UNKNOWN;
    }
    if (!methodInfo.getClassInfo().isSubclassOf(invokeeRef.getClassInfo())) {
        if (isInvokeInterface() && !methodInfo.getClassInfo().isInterface()) {
            // check the signature..
            if (!invokeeRef.getMethodSignature().equals(methodInfo.getMethodSignature())) {
                return Ternary.FALSE;
            }
            return Ternary.UNKNOWN;
        }
        return Ternary.FALSE;
    }
    return Ternary.valueOf(methodInfo.overrides(method, true));
}
Also used : MethodRef(com.jopdesign.common.type.MethodRef) MethodInfo(com.jopdesign.common.MethodInfo)

Example 58 with MethodInfo

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

the class SuperGraph method getCallSites.

/**
 * @return return all callsite invoke/return superedge pairs, grouped by the invoked method
 */
public Map<MethodInfo, List<Pair<SuperInvokeEdge, SuperReturnEdge>>> getCallSites() {
    Map<MethodInfo, List<Pair<SuperInvokeEdge, SuperReturnEdge>>> iMap = new LinkedHashMap<MethodInfo, List<Pair<SuperInvokeEdge, SuperReturnEdge>>>();
    for (ContextCFG node : superGraph.vertexSet()) {
        List<Pair<SuperInvokeEdge, SuperReturnEdge>> callSites = getCallSitesInvoking(node);
        MethodInfo invoked = node.getCfg().getMethodInfo();
        if (iMap.containsKey(invoked)) {
            callSites.addAll(iMap.get(invoked));
        }
        iMap.put(invoked, callSites);
    }
    return iMap;
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Pair(com.jopdesign.common.graphutils.Pair)

Example 59 with MethodInfo

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

the class CallGraph method buildCallGraph.

/**
 * Build a callgraph with all root methods of AppInfo.
 * This also adds all static initializers of all classes and all Runnable.run() methods
 * to the callgraph roots.
 *
 * @see AppInfo#getRootMethods()
 * @param appInfo the AppInfo to use
 * @param builder the builder class to use to build this graph
 * @return a freshly constructed callgraph.
 */
public static CallGraph buildCallGraph(AppInfo appInfo, CallgraphBuilder builder) {
    Collection<MethodInfo> rootMethods = appInfo.getRootMethods();
    Set<ExecutionContext> roots = new LinkedHashSet<ExecutionContext>(rootMethods.size());
    for (MethodInfo m : rootMethods) {
        roots.add(new ExecutionContext(m));
    }
    for (MethodInfo m : appInfo.getClinitMethods()) {
        roots.add(new ExecutionContext(m));
    }
    for (MethodInfo m : appInfo.getThreadRootMethods(false)) {
        roots.add(new ExecutionContext(m));
    }
    CallGraph cg = new CallGraph(roots, builder);
    cg.build();
    return cg;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MethodInfo(com.jopdesign.common.MethodInfo)

Example 60 with MethodInfo

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

the class CallGraph method getReachableImplementations.

/**
 * Get non-abstract methods, in topological order.
 *
 * Requires an acyclic callgraph.
 * @param rootMethod start with this method
 * @return a list of all non-abstract reachable methods, in topological order.
 */
public List<MethodInfo> getReachableImplementations(MethodInfo rootMethod) {
    List<MethodInfo> implemented = new ArrayList<MethodInfo>();
    Set<MethodInfo> reachable = getReachableImplementationsSet(rootMethod);
    TopologicalOrderIterator<ExecutionContext, ContextEdge> ti = topDownIterator();
    while (ti.hasNext()) {
        MethodInfo m = ti.next().getMethodInfo();
        if (m != null && reachable.contains(m))
            implemented.add(m);
    }
    return implemented;
}
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