Search in sources :

Example 41 with MethodInfo

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

the class CallGraph method buildCallGraph.

/**
     * Build a callgraph rooted at the given set of methods
     *
     * @param rootMethods The root methods of the callgraph
     * @param builder the builder class to use to build this graph
     * @return a freshly constructed callgraph.
     */
public static CallGraph buildCallGraph(Collection<MethodInfo> rootMethods, CallgraphBuilder builder) {
    List<ExecutionContext> roots = new ArrayList<ExecutionContext>(rootMethods.size());
    for (MethodInfo method : rootMethods) {
        roots.add(new ExecutionContext(method));
    }
    CallGraph cg = new CallGraph(roots, builder);
    cg.build();
    return cg;
}
Also used : ArrayList(java.util.ArrayList) MethodInfo(com.jopdesign.common.MethodInfo)

Example 42 with MethodInfo

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

the class ConstantPoolReferenceFinder method findReferencedMembers.

/**
     * Find all referenced members in a class.
     * @param classInfo the class to search.
     * @param checkMembers if false, do not check fields and methods. Else check everything.
     * @return a set of class names and class member signatures found in the class.
     */
public static Set<String> findReferencedMembers(ClassInfo classInfo, boolean checkMembers) {
    // Else we need to go into details..
    Set<String> members = new HashSet<String>();
    ClassMemberVisitor visitor = new ClassMemberVisitor(members);
    JavaClass javaClass = classInfo.compile();
    Set<Integer> ids = findPoolReferences(classInfo, javaClass);
    List<InvokeSite> invokes = new ArrayList<InvokeSite>();
    if (checkMembers) {
        for (Field field : javaClass.getFields()) {
            FieldInfo fieldInfo = classInfo.getFieldInfo(field.getName());
            // add members found in the field
            visitor.visitField(fieldInfo);
            // there are no invokesites in a field, only add found ids
            ids.addAll(findPoolReferences(fieldInfo, field));
        }
        for (Method method : javaClass.getMethods()) {
            MethodInfo methodInfo = classInfo.getMethodInfo(method.getName() + method.getSignature());
            // add members found in the method
            visitor.visitMethod(methodInfo);
            // add all ids for checking, add all invoke sites
            ids.addAll(findPoolReferences(methodInfo, method));
        }
    }
    // fill the members list with all found constantpool references
    visitor.visitClass(classInfo);
    visitPoolReferences(classInfo, visitor, ids);
    return members;
}
Also used : ArrayList(java.util.ArrayList) ConstantString(org.apache.bcel.classfile.ConstantString) Method(org.apache.bcel.classfile.Method) EnclosingMethod(com.jopdesign.common.bcel.EnclosingMethod) ConstantInteger(org.apache.bcel.classfile.ConstantInteger) Field(org.apache.bcel.classfile.Field) JavaClass(org.apache.bcel.classfile.JavaClass) MethodInfo(com.jopdesign.common.MethodInfo) ConstantMethodInfo(com.jopdesign.common.type.ConstantMethodInfo) InvokeSite(com.jopdesign.common.code.InvokeSite) ConstantFieldInfo(com.jopdesign.common.type.ConstantFieldInfo) FieldInfo(com.jopdesign.common.FieldInfo) HashSet(java.util.HashSet)

Example 43 with MethodInfo

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

the class UsedCodeFinder method markUsedMembers.

/**
     * Mark all used members, starting at all AppInfo roots.
     * <p>
     * To avoid marking unused Runnable.run methods, remove them from the callgraph roots first.
     * </p>
     *
     * @see #markUsedMembers(ClassInfo,boolean)
     * @see #markUsedMembers(MethodInfo)
     * @see #markUsedMembers(FieldInfo)
     */
public void markUsedMembers() {
    resetMarks();
    // This contains all application and JVM root methods and -classes
    for (MethodInfo root : appInfo.getRootMethods()) {
        // this also marks the containing class as used, and includes the main method
        markUsedMembers(root);
    }
    // but we need to add all Runnable.run() methods as root methods
    for (MethodInfo run : appInfo.getThreadRootMethods(true)) {
        markUsedMembers(run);
    }
    if (ignoredClasses.size() > 0) {
        int num = ignoredClasses.size();
        logger.info("Ignored " + num + " referenced " + (num == 1 ? "class: " : "classes: ") + ignoredClasses);
    }
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo)

Example 44 with MethodInfo

use of com.jopdesign.common.MethodInfo 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 45 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)

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