Search in sources :

Example 26 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.

the class InstructionInterpreter method interpret.

private void interpret(InstructionList il, Map<InstructionHandle, T> start, boolean initialize) {
    if (initialize) {
        InstructionHandle ih = il.getStart();
        // set initial value for all instructions
        while (ih != null) {
            results.put(ih, analysis.bottom());
            ih = ih.getNext();
        }
        results.putAll(start);
    } else {
        // Set initial values for new instructions
        for (InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) {
            if (results.containsKey(ih))
                continue;
            if (ih.getPrev() == null) {
                // entry instruction, must always be merged with the initial state once, even
                // if this has an ingoing edge
                results.put(ih, analysis.initial(ih));
            } else {
                results.put(ih, analysis.bottom());
                // check for exception handler entry
                if (ih.hasTargeters()) {
                    for (InstructionTargeter targeter : ih.getTargeters()) {
                        if (targeter instanceof CodeExceptionGen && ((CodeExceptionGen) targeter).getHandlerPC().equals(ih)) {
                            results.put(ih, analysis.initial((CodeExceptionGen) targeter));
                            break;
                        }
                    }
                }
            }
        }
    }
    LinkedList<Edge> worklist = new LinkedList<Edge>();
    // setup the worklist
    for (InstructionHandle ih : start.keySet()) {
        if (initialize) {
            // when initializing, we start from the initial values, not from ingoing edges
            worklist.addAll(getOutEdges(ih));
        } else {
            // we continue from existing results
            List<Edge> inEdges = getInEdges(il, ih);
            if (inEdges.isEmpty()) {
                // entry instruction without ingoing edges, nothing to continue from
                worklist.addAll(getOutEdges(ih));
            } else {
                worklist.addAll(inEdges);
            }
        }
    }
    while (!worklist.isEmpty()) {
        Edge edge = worklist.removeFirst();
        InstructionHandle tail = edge.getTail();
        InstructionHandle head = edge.getHead();
        T tailValue = results.get(tail);
        T headValue = results.get(head);
        T transferred = analysis.transfer(tailValue, edge);
        if (!analysis.compare(transferred, headValue)) {
            T newValue = analysis.join(transferred, headValue);
            results.put(head, newValue);
            if (edge.getType() == EdgeType.EXIT_EDGE) {
                continue;
            }
            List<Edge> outEdges = getOutEdges(head);
            for (Edge outEdge : outEdges) {
                if (worklist.contains(outEdge)) {
                    continue;
                }
                if (outEdges.size() > 1) {
                    worklist.addLast(outEdge);
                } else {
                    worklist.addFirst(outEdge);
                }
            }
        }
    }
}
Also used : RET(org.apache.bcel.generic.RET) InstructionTargeter(org.apache.bcel.generic.InstructionTargeter) CodeExceptionGen(org.apache.bcel.generic.CodeExceptionGen) InstructionHandle(org.apache.bcel.generic.InstructionHandle) LinkedList(java.util.LinkedList)

Example 27 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.

the class InstructionInterpreter method getExitInstruction.

public InstructionHandle getExitInstruction() {
    InstructionHandle exit = (InstructionHandle) methodInfo.getCustomValue(KEY_NOP);
    if (exit == null) {
        exit = new InstructionList().append(new NOP());
        methodInfo.setCustomValue(KEY_NOP, exit);
    }
    return exit;
}
Also used : InstructionList(org.apache.bcel.generic.InstructionList) InstructionHandle(org.apache.bcel.generic.InstructionHandle) NOP(org.apache.bcel.generic.NOP)

Example 28 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.

the class SourceLineStorage method applySourceInfos.

private void applySourceInfos(MethodInfo method, List<SourceLineEntry> entries) {
    MethodCode code = method.getCode();
    InstructionHandle[] il = code.getInstructionList(true, false).getInstructionHandles();
    for (SourceLineEntry sle : entries) {
        sle.applyEntry(code, il);
    }
}
Also used : MethodCode(com.jopdesign.common.MethodCode) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 29 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.

the class ObjectCacheAnalysis method getSaturatedTypes.

/** Traverse vertex set. Collect those types where we could not resolve
	 * the symbolic object names. (Not too useful in the analysis, but useful
	 * for debugging)
	 */
public HashSet<String> getSaturatedTypes(Segment segment, LocalPointsToResult usedRefs) {
    HashSet<String> topTypes = new HashSet<String>();
    for (SuperGraphNode n : segment.getNodes()) {
        BasicBlock bb = n.getCFGNode().getBasicBlock();
        if (bb == null)
            continue;
        CallString cs = n.getContextCFG().getCallString();
        for (InstructionHandle ih : bb.getInstructions()) {
            BoundedSet<SymbolicAddress> refs;
            if (usedRefs.containsKey(ih)) {
                refs = usedRefs.get(ih, cs);
                String handleType = getHandleType(project, n.getCfg(), ih);
                if (handleType == null)
                    continue;
                if (refs.isSaturated()) {
                    topTypes.add(handleType);
                }
            }
        }
    }
    return topTypes;
}
Also used : BasicBlock(com.jopdesign.common.code.BasicBlock) SuperGraphNode(com.jopdesign.common.code.SuperGraph.SuperGraphNode) CallString(com.jopdesign.common.code.CallString) SymbolicAddress(com.jopdesign.dfa.analyses.SymbolicAddress) InstructionHandle(org.apache.bcel.generic.InstructionHandle) HashSet(java.util.HashSet) CallString(com.jopdesign.common.code.CallString)

Example 30 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.

the class OldClinitOrder method findDependencies.

private Set findDependencies(OldClassInfo cli, OldMethodInfo mi, boolean inRec) {
    //		System.out.println("find dep. in "+cli.clazz.getClassName()+":"+mi.getMethod().getName());
    Method method = mi.getMethod();
    Set depends = new HashSet();
    if (method.isNative() || method.isAbstract()) {
        // subclasses???? :-(
        return depends;
    }
    ConstantPool cpool = cli.clazz.getConstantPool();
    ConstantPoolGen cpoolgen = new ConstantPoolGen(cpool);
    MethodGen mg = new MethodGen(method, cli.clazz.getClassName(), cpoolgen);
    InstructionList il = mg.getInstructionList();
    InstructionFinder f = new InstructionFinder(il);
    // find instructions that access the constant pool
    // collect all indices to constants in ClassInfo
    String cpInstr = "CPInstruction";
    for (Iterator it = f.search(cpInstr); it.hasNext(); ) {
        InstructionHandle[] match = (InstructionHandle[]) it.next();
        InstructionHandle first = match[0];
        CPInstruction ii = (CPInstruction) first.getInstruction();
        int idx = ii.getIndex();
        Constant co = cpool.getConstant(idx);
        ConstantClass cocl = null;
        Set addDepends = null;
        String clname;
        OldClassInfo clinfo;
        OldMethodInfo minfo;
        switch(co.getTag()) {
            case Constants.CONSTANT_Class:
                cocl = (ConstantClass) co;
                clname = cocl.getBytes(cpool).replace('/', '.');
                clinfo = (OldClassInfo) ai.cliMap.get(clname);
                if (clinfo != null) {
                    minfo = clinfo.getMethodInfo("<init>()V");
                    if (minfo != null) {
                        addDepends = findDependencies(clinfo, minfo, true);
                    }
                }
                break;
            case Constants.CONSTANT_InterfaceMethodref:
                cocl = (ConstantClass) cpool.getConstant(((ConstantInterfaceMethodref) co).getClassIndex());
                break;
            case Constants.CONSTANT_Methodref:
                cocl = (ConstantClass) cpool.getConstant(((ConstantMethodref) co).getClassIndex());
                clname = cocl.getBytes(cpool).replace('/', '.');
                clinfo = (OldClassInfo) ai.cliMap.get(clname);
                int sigidx = ((ConstantMethodref) co).getNameAndTypeIndex();
                ConstantNameAndType signt = (ConstantNameAndType) cpool.getConstant(sigidx);
                String sigstr = signt.getName(cpool) + signt.getSignature(cpool);
                if (clinfo != null) {
                    minfo = clinfo.getMethodInfo(sigstr);
                    if (minfo != null) {
                        addDepends = findDependencies(clinfo, minfo, true);
                    }
                }
                break;
            case Constants.CONSTANT_Fieldref:
                cocl = (ConstantClass) cpool.getConstant(((ConstantFieldref) co).getClassIndex());
                break;
        }
        if (cocl != null) {
            clname = cocl.getBytes(cpool).replace('/', '.');
            OldClassInfo clinf = (OldClassInfo) ai.cliMap.get(clname);
            if (clinf != null) {
                if (clinf.getMethodInfo(OldAppInfo.clinitSig) != null) {
                    // don't add myself as dependency
                    if (clinf != cli) {
                        depends.add(clinf);
                    }
                }
            }
        }
        if (addDepends != null) {
            Iterator itAddDep = addDepends.iterator();
            while (itAddDep.hasNext()) {
                OldClassInfo addCli = (OldClassInfo) itAddDep.next();
                if (addCli == cli) {
                    throw new Error("cyclic indirect <clinit> dependency");
                }
                depends.add(addCli);
            }
        }
    }
    il.dispose();
    return depends;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InstructionList(org.apache.bcel.generic.InstructionList) Constant(org.apache.bcel.classfile.Constant) Method(org.apache.bcel.classfile.Method) InstructionFinder(org.apache.bcel.util.InstructionFinder) MethodGen(org.apache.bcel.generic.MethodGen) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ConstantNameAndType(org.apache.bcel.classfile.ConstantNameAndType) ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) CPInstruction(org.apache.bcel.generic.CPInstruction) ConstantMethodref(org.apache.bcel.classfile.ConstantMethodref) ConstantPool(org.apache.bcel.classfile.ConstantPool) Iterator(java.util.Iterator) ConstantClass(org.apache.bcel.classfile.ConstantClass) HashSet(java.util.HashSet)

Aggregations

InstructionHandle (org.apache.bcel.generic.InstructionHandle)103 InstructionList (org.apache.bcel.generic.InstructionList)26 MethodInfo (com.jopdesign.common.MethodInfo)20 CallString (com.jopdesign.common.code.CallString)20 Instruction (org.apache.bcel.generic.Instruction)13 MethodCode (com.jopdesign.common.MethodCode)12 ContextMap (com.jopdesign.dfa.framework.ContextMap)11 IntermediateEdge (org.candle.decompiler.intermediate.graph.edge.IntermediateEdge)11 Context (com.jopdesign.dfa.framework.Context)10 InvokeInstruction (org.apache.bcel.generic.InvokeInstruction)10 Iterator (java.util.Iterator)9 BranchInstruction (org.apache.bcel.generic.BranchInstruction)9 FieldInstruction (org.apache.bcel.generic.FieldInstruction)9 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)9 ReturnInstruction (org.apache.bcel.generic.ReturnInstruction)8 InstructionFinder (org.apache.bcel.util.InstructionFinder)8 ClassInfo (com.jopdesign.common.ClassInfo)7 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 LinkedList (java.util.LinkedList)7