Search in sources :

Example 61 with MethodInfo

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

the class DefaultCallgraphBuilder method getInvokedMethods.

@Override
public Set<ExecutionContext> getInvokedMethods(ExecutionContext context) {
    CallString callstring = context.getCallString();
    MethodInfo method = context.getMethodInfo();
    if (!method.hasCode()) {
        // noinspection unchecked
        return (Set<ExecutionContext>) Collections.EMPTY_SET;
    }
    // TODO use only callstring length 1, split nodes only if required using DFA/.. later on?
    Set<ExecutionContext> newContexts = new LinkedHashSet<ExecutionContext>();
    invokeLoop: for (InvokeSite invokeSite : findInvokeSites(method.getCode())) {
        Set<MethodInfo> methods = getInvokedMethods(context, invokeSite);
        if (skipNatives) {
            for (MethodInfo impl : methods) {
                // to indicate that the candidates are not completely represented!
                if (impl.isNative()) {
                    continue invokeLoop;
                }
            }
        }
        for (MethodInfo impl : methods) {
            // System.out.println("Implemented Methods: "+impl+" from "+iNode.getBasicBlock().getMethodInfo().methodId+" in context "+callstring.toStringVerbose());
            CallString newCallString = callstring.push(invokeSite, callstringLength);
            newContexts.add(new ExecutionContext(impl, newCallString));
        }
    }
    return newContexts;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) MethodInfo(com.jopdesign.common.MethodInfo)

Example 62 with MethodInfo

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

the class Config method parseMethodList.

/**
 * @param methodNames comma separated list of method names, either fully qualified with or without descriptor, or
 *        method names of methods in the main class.
 * @return the set of methods represented by these names
 * @throws BadConfigurationException if a name is not resolvable
 */
public static List<MethodInfo> parseMethodList(String methodNames) throws BadConfigurationException {
    List<String> names = splitStringList(methodNames);
    List<MethodInfo> methods = new ArrayList<MethodInfo>(names.size());
    for (String name : names) {
        MemberID id = MemberID.parse(name);
        if (!id.hasClassName()) {
            ClassInfo main = AppInfo.getSingleton().getMainMethod().getClassInfo();
            Set<MethodInfo> m = main.getMethodInfos(id);
            if (m.isEmpty()) {
                throw new BadConfigurationException("Cannot find method '" + name + "' in main class " + main);
            }
            methods.addAll(m);
        } else {
            try {
                Collection<MethodInfo> infos = AppInfo.getSingleton().getMethodInfos(id);
                if (infos.isEmpty()) {
                    throw new BadConfigurationException("Cannot find methods for " + name);
                }
                methods.addAll(infos);
            } catch (MethodNotFoundException e) {
                throw new BadConfigurationException("Cannot find class for " + name, e);
            }
        }
    }
    return methods;
}
Also used : MemberID(com.jopdesign.common.type.MemberID) ArrayList(java.util.ArrayList) MethodInfo(com.jopdesign.common.MethodInfo) MethodNotFoundException(com.jopdesign.common.misc.MethodNotFoundException) ClassInfo(com.jopdesign.common.ClassInfo)

Example 63 with MethodInfo

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

the class DescendingClassTraverser method visitClass.

public boolean visitClass(ClassInfo classInfo) {
    if (!visitor.visitClass(classInfo)) {
        return returnOnSkipClass;
    }
    visitConstantPool(classInfo);
    // methods and fields are final, no need to call accept()
    for (FieldInfo f : classInfo.getFields()) {
        if (!visitor.visitField(f)) {
            continue;
        }
        bcelVisitor.setFieldInfo(f);
        visitAttributes(f.getAttributes());
        visitor.finishField(f);
    }
    for (MethodInfo m : classInfo.getMethods()) {
        if (!visitor.visitMethod(m)) {
            continue;
        }
        bcelVisitor.setMethodInfo(m);
        visitMethodCode(m);
        visitAttributes(m.getAttributes());
        visitor.finishMethod(m);
    }
    bcelVisitor.setClassInfo(classInfo);
    visitAttributes(classInfo.getAttributes());
    visitor.finishClass(classInfo);
    return true;
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo) FieldInfo(com.jopdesign.common.FieldInfo)

Example 64 with MethodInfo

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

the class SuperGraph method createSuperGraph.

private void createSuperGraph() {
    Stack<ContextCFG> todo = new Stack<ContextCFG>();
    todo.push(rootNode);
    superGraph.addVertex(rootNode);
    while (!todo.empty()) {
        ContextCFG current = todo.pop();
        if (!current.getCfg().areVirtualInvokesResolved()) {
            throw new AssertionError("Virtual dispatch nodes not yet supported for supergraph (file a bug)");
        }
        ControlFlowGraph currentCFG = current.getCfg();
        CallString currentCS = current.getCallString();
        Collection<CFGEdge> infeasibleEdges = infeasibleEdgeProvider.getInfeasibleEdges(currentCFG, currentCS);
        for (CFGNode node : current.getCfg().vertexSet()) {
            if (node instanceof ControlFlowGraph.InvokeNode) {
                /* skip node if all incoming edges are infeasible in the current call context */
                boolean infeasible = true;
                for (CFGEdge e : current.getCfg().incomingEdgesOf(node)) {
                    if (!infeasibleEdges.contains(e)) {
                        infeasible = false;
                    }
                }
                if (infeasible)
                    continue;
                ControlFlowGraph.InvokeNode iNode = (ControlFlowGraph.InvokeNode) node;
                Set<MethodInfo> impls = iNode.getImplementingMethods();
                if (impls.size() == 0) {
                    throw new AssertionError("No implementations for iNode available");
                } else if (impls.size() != 1) {
                    throw new AssertionError("Unresolved virtual Dispatch for " + iNode + ": " + impls);
                }
                for (MethodInfo impl : impls) {
                    ControlFlowGraph invokedCFG = cfgProvider.getFlowGraph(impl);
                    CallString invokedCS = currentCS.push(iNode, callstringLength);
                    /* skip node if receiver is infeasible in current call context */
                    if (infeasibleEdgeProvider.isInfeasibleReceiver(impl, invokedCS)) {
                        Logger.getLogger(this.getClass()).info("createSuperGraph(): infeasible receiver " + impl);
                        continue;
                    }
                    ContextCFG invoked = new ContextCFG(invokedCFG, invokedCS);
                    if (!superGraph.containsVertex(invoked)) {
                        superGraph.addVertex(invoked);
                        todo.push(invoked);
                    }
                    addEdge(iNode, current, invoked);
                }
            }
        }
    }
}
Also used : InvokeNode(com.jopdesign.common.code.ControlFlowGraph.InvokeNode) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) Stack(java.util.Stack) InvokeNode(com.jopdesign.common.code.ControlFlowGraph.InvokeNode) MethodInfo(com.jopdesign.common.MethodInfo) CFGEdge(com.jopdesign.common.code.ControlFlowGraph.CFGEdge)

Example 65 with MethodInfo

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

the class FIFOVarBlockCacheBuilder method initCache.

protected StringBuilder initCache(String NUM_METHODS) {
    List<Object> cacheElems = new ArrayList<Object>();
    for (int i = 0; i < numBlocks(); i++) cacheElems.add(NUM_METHODS);
    // TODO check: this has been "blocksOf(0)", check if this is the same!!
    MethodInfo method = project.getAppInfo().getMainMethod();
    if (assumeEmptyCache)
        cacheElems.set(blocksOf(method) - 1, 0);
    return SystemBuilder.constArray(cacheElems);
}
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