Search in sources :

Example 36 with MethodInfo

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

the class DFATool method createPrologue.

private MethodInfo createPrologue() {
    // find ordering for class initializers
    ClinitOrder c = new ClinitOrder();
    appInfo.iterate(c);
    List<ClassInfo> order = c.findOrder();
    MethodInfo mainClass = appInfo.getMainMethod();
    // create prologue
    return buildPrologue(mainClass, statements, flow, order);
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo) ClinitOrder(com.jopdesign.common.tools.ClinitOrder) ClassInfo(com.jopdesign.common.ClassInfo)

Example 37 with MethodInfo

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

the class DFATool method buildPrologue.

private MethodInfo buildPrologue(MethodInfo mainMethod, List<InstructionHandle> statements, Flow flow, List<ClassInfo> clinits) {
    // we use a prologue sequence for startup
    InstructionList prologue = new InstructionList();
    ConstantPoolGen prologueCP = mainMethod.getConstantPoolGen();
    Instruction instr;
    int idx;
    // add magic initializers to prologue sequence
    if (!analyzeBootMethod) {
        instr = new ICONST(0);
        prologue.append(instr);
        instr = new ICONST(0);
        prologue.append(instr);
        idx = prologueCP.addMethodref("com.jopdesign.sys.GC", "init", "(II)V");
        instr = new INVOKESTATIC(idx);
        prologue.append(instr);
    }
    // add class initializers
    for (ClassInfo clinit : clinits) {
        MemberID cSig = appInfo.getClinitSignature(clinit.getClassName());
        idx = prologueCP.addMethodref(cSig.getClassName(), cSig.getMemberName(), cSig.getDescriptor().toString());
        instr = new INVOKESTATIC(idx);
        prologue.append(instr);
    }
    if (analyzeBootMethod) {
        // Let's just analyze the full boot method, so that the callgraph-builder is happy.
        // Doing this after clinit, so that we have DFA infos on fields in JVMHelp.init()
        idx = prologueCP.addMethodref("com.jopdesign.sys.Startup", "boot", "()V");
        instr = new INVOKESTATIC(idx);
        prologue.append(instr);
    }
    // add main method
    instr = new ACONST_NULL();
    prologue.append(instr);
    idx = prologueCP.addMethodref(mainMethod.getClassName(), mainMethod.getShortName(), mainMethod.getDescriptor().toString());
    instr = new INVOKESTATIC(idx);
    prologue.append(instr);
    //      // invoke startMission() to ensure analysis of threads
    //      idx = prologueCP.addMethodref("joprt.RtThread", "startMission", "()V");
    //      instr = new INVOKESTATIC(idx);
    //      prologue.append(instr);
    instr = new NOP();
    prologue.append(instr);
    prologue.setPositions(true);
    // add prologue to program structure
    for (Iterator l = prologue.iterator(); l.hasNext(); ) {
        InstructionHandle handle = (InstructionHandle) l.next();
        statements.add(handle);
        if (handle.getInstruction() instanceof GOTO) {
            GOTO g = (GOTO) handle.getInstruction();
            flow.addEdge(new FlowEdge(handle, g.getTarget(), FlowEdge.NORMAL_EDGE));
        } else if (handle.getNext() != null) {
            flow.addEdge(new FlowEdge(handle, handle.getNext(), FlowEdge.NORMAL_EDGE));
        }
    }
    MemberID pSig = new MemberID(prologueName, Descriptor.parse(prologueSig));
    MethodInfo mi = mainMethod.getClassInfo().createMethod(pSig, null, prologue);
    mi.setAccessType(AccessType.ACC_PRIVATE);
    return mi;
}
Also used : FlowEdge(com.jopdesign.dfa.framework.FlowEdge) INVOKESTATIC(org.apache.bcel.generic.INVOKESTATIC) GOTO(org.apache.bcel.generic.GOTO) InstructionList(org.apache.bcel.generic.InstructionList) Instruction(org.apache.bcel.generic.Instruction) BranchInstruction(org.apache.bcel.generic.BranchInstruction) ReturnInstruction(org.apache.bcel.generic.ReturnInstruction) NOP(org.apache.bcel.generic.NOP) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) MemberID(com.jopdesign.common.type.MemberID) Iterator(java.util.Iterator) MethodInfo(com.jopdesign.common.MethodInfo) ACONST_NULL(org.apache.bcel.generic.ACONST_NULL) ICONST(org.apache.bcel.generic.ICONST) ClassInfo(com.jopdesign.common.ClassInfo)

Example 38 with MethodInfo

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

the class CallGraph method getReachableImplementationsSet.

/**
     * Retrieve non-abstract methods reachable from the given call graph node.
     * All callgraph nodes reachable from nodes representing the given a method are collected
     * @param cgNode where to start
     * @return a list of all reachable implementations, sorted in DFS order
     */
public Set<MethodInfo> getReachableImplementationsSet(ExecutionContext cgNode) {
    Set<MethodInfo> implemented = new LinkedHashSet<MethodInfo>();
    DepthFirstIterator<ExecutionContext, ContextEdge> ti = new DepthFirstIterator<ExecutionContext, ContextEdge>(callGraph, cgNode);
    ti.setCrossComponentTraversal(false);
    while (ti.hasNext()) {
        MethodInfo m = ti.next().getMethodInfo();
        if (m == null)
            throw new AssertionError("Abstract method in callgraph");
        implemented.add(m);
    }
    return implemented;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DepthFirstIterator(org.jgrapht.traverse.DepthFirstIterator) MethodInfo(com.jopdesign.common.MethodInfo)

Example 39 with MethodInfo

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

the class CallGraph method getLargestMethod.

public ControlFlowGraph getLargestMethod() {
    ControlFlowGraph largest = null;
    int maxBytes = 0;
    for (ExecutionContext rootNode : rootNodes) {
        for (MethodInfo mi : this.getReachableImplementationsSet(rootNode.getMethodInfo())) {
            int bytes = mi.getCode().getNumberOfBytes();
            if (bytes > maxBytes) {
                largest = mi.getCode().getControlFlowGraph(false);
                maxBytes = bytes;
            }
        }
    }
    return largest;
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo)

Example 40 with MethodInfo

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

the class CallGraph method getReachableImplementationsSet.

/**
     * Retrieve non-abstract methods reachable from the given method.
     * All callgraph nodes reachable from nodes representing the given a method are collected
     *
     * @param rootMethod start method
     * @return a list of all reachable methods, sorted in topological order
     */
public Set<MethodInfo> getReachableImplementationsSet(MethodInfo rootMethod) {
    Set<MethodInfo> implemented = new LinkedHashSet<MethodInfo>();
    for (ExecutionContext cgNode : methodNodes.get(rootMethod).getInstances()) {
        DepthFirstIterator<ExecutionContext, ContextEdge> ti = new DepthFirstIterator<ExecutionContext, ContextEdge>(callGraph, cgNode);
        ti.setCrossComponentTraversal(false);
        while (ti.hasNext()) {
            MethodInfo m = ti.next().getMethodInfo();
            if (m == null)
                throw new AssertionError("Abstract method in callgraph");
            implemented.add(m);
        }
    }
    return implemented;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DepthFirstIterator(org.jgrapht.traverse.DepthFirstIterator) 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