Search in sources :

Example 11 with Instruction

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

the class ObjectCacheAnalysis method getHandleType.

public static String getHandleType(WCETTool project, ControlFlowGraph cfg, InstructionHandle ih) {
    ConstantPoolGen constPool = cfg.getMethodInfo().getConstantPoolGen();
    Instruction instr = ih.getInstruction();
    if (instr instanceof GETFIELD) {
        GETFIELD gf = (GETFIELD) instr;
        ReferenceType refty = gf.getReferenceType(constPool);
        return refty.toString();
    }
    if (!ALL_HANDLE_ACCESSES)
        return null;
    if (instr instanceof PUTFIELD) {
        PUTFIELD pf = (PUTFIELD) instr;
        ReferenceType refty = pf.getReferenceType(constPool);
        return refty.toString();
    }
    if (instr instanceof ArrayInstruction) {
        //ArrayInstruction ainstr = (ArrayInstruction) instr;
        return "[]";
    }
    if (instr instanceof ARRAYLENGTH) {
        //ARRAYLENGTH ainstr = (ARRAYLENGTH) instr;
        return "[]";
    }
    if (instr instanceof INVOKEINTERFACE || instr instanceof INVOKEVIRTUAL) {
        return "$header";
    }
    return null;
}
Also used : ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) GETFIELD(org.apache.bcel.generic.GETFIELD) ArrayInstruction(org.apache.bcel.generic.ArrayInstruction) ARRAYLENGTH(org.apache.bcel.generic.ARRAYLENGTH) INVOKEINTERFACE(org.apache.bcel.generic.INVOKEINTERFACE) PUTFIELD(org.apache.bcel.generic.PUTFIELD) Instruction(org.apache.bcel.generic.Instruction) FieldInstruction(org.apache.bcel.generic.FieldInstruction) ArrayInstruction(org.apache.bcel.generic.ArrayInstruction) ReferenceType(org.apache.bcel.generic.ReferenceType) INVOKEVIRTUAL(org.apache.bcel.generic.INVOKEVIRTUAL)

Example 12 with Instruction

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

the class ObjectCacheAnalysis method getCachedType.

public static Type getCachedType(WCETTool project, ControlFlowGraph cfg, InstructionHandle ih) {
    ConstantPoolGen constPool = cfg.getMethodInfo().getConstantPoolGen();
    Instruction instr = ih.getInstruction();
    if (instr instanceof GETFIELD) {
        GETFIELD gf = (GETFIELD) instr;
        return gf.getFieldType(constPool);
    }
    if (!ALL_HANDLE_ACCESSES) {
        return null;
    } else {
        throw new AssertionError("For O$, only getfield is supported right now");
    }
}
Also used : ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) GETFIELD(org.apache.bcel.generic.GETFIELD) Instruction(org.apache.bcel.generic.Instruction) FieldInstruction(org.apache.bcel.generic.FieldInstruction) ArrayInstruction(org.apache.bcel.generic.ArrayInstruction)

Example 13 with Instruction

use of org.apache.bcel.generic.Instruction in project fb-contrib by mebigfatguy.

the class CopiedOverriddenMethod method codeEquals.

/**
 * compares two code blocks to see if they are equal with regard to instructions and field accesses
 *
 * @param child
 *            the first code block
 * @param parent
 *            the second code block
 *
 * @return whether the code blocks are the same
 */
private boolean codeEquals(Code child, Code parent) {
    if (parent == null) {
        return false;
    }
    byte[] childBytes = child.getCode();
    byte[] parentBytes = parent.getCode();
    if ((childBytes == null) || (parentBytes == null)) {
        return false;
    }
    if (childBytes.length != parentBytes.length) {
        return false;
    }
    InstructionHandle[] childihs = new InstructionList(childBytes).getInstructionHandles();
    InstructionHandle[] parentihs = new InstructionList(parentBytes).getInstructionHandles();
    if (childihs.length != parentihs.length) {
        return false;
    }
    for (int i = 0; i < childihs.length; i++) {
        InstructionHandle childih = childihs[i];
        InstructionHandle parentih = parentihs[i];
        Instruction childin = childih.getInstruction();
        Instruction parentin = parentih.getInstruction();
        if (!childin.getName().equals(parentin.getName())) {
            return false;
        }
        if (childin instanceof FieldInstruction) {
            String childFName = ((FieldInstruction) childin).getFieldName(childPoolGen);
            String parentFName = ((FieldInstruction) parentin).getFieldName(parentPoolGen);
            if (!childFName.equals(parentFName)) {
                return false;
            }
            String childFSig = ((FieldInstruction) childin).getSignature(childPoolGen);
            String parentFSig = ((FieldInstruction) parentin).getSignature(parentPoolGen);
            if (!childFSig.equals(parentFSig)) {
                return false;
            }
            if (childFSig.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX) || childFSig.startsWith(Values.SIG_ARRAY_PREFIX)) {
                ReferenceType childRefType = ((FieldInstruction) childin).getReferenceType(childPoolGen);
                ReferenceType parentRefType = ((FieldInstruction) parentin).getReferenceType(parentPoolGen);
                if (!childRefType.getSignature().equals(parentRefType.getSignature())) {
                    return false;
                }
            }
        } else if (childin instanceof InvokeInstruction) {
            String childClassName = ((InvokeInstruction) childin).getClassName(childPoolGen);
            String parentClassName = ((InvokeInstruction) parentin).getClassName(parentPoolGen);
            if (!childClassName.equals(parentClassName)) {
                return false;
            }
            String childMethodName = ((InvokeInstruction) childin).getMethodName(childPoolGen);
            String parentMethodName = ((InvokeInstruction) parentin).getMethodName(parentPoolGen);
            if (!childMethodName.equals(parentMethodName)) {
                return false;
            }
            String childSignature = ((InvokeInstruction) childin).getSignature(childPoolGen);
            String parentSignature = ((InvokeInstruction) parentin).getSignature(parentPoolGen);
            if (!childSignature.equals(parentSignature)) {
                return false;
            }
        } else if (childin instanceof LDC) {
            Type childType = ((LDC) childin).getType(childPoolGen);
            Type parentType = ((LDC) parentin).getType(parentPoolGen);
            if (!childType.equals(parentType)) {
                return false;
            }
            Object childValue = ((LDC) childin).getValue(childPoolGen);
            Object parentValue = ((LDC) parentin).getValue(parentPoolGen);
            if (childValue instanceof ConstantClass) {
                ConstantClass childClass = (ConstantClass) childValue;
                ConstantClass parentClass = (ConstantClass) parentValue;
                if (!childClass.getBytes(childPoolGen.getConstantPool()).equals(parentClass.getBytes(parentPoolGen.getConstantPool()))) {
                    return false;
                }
            } else if (!childValue.equals(parentValue)) {
                return false;
            }
        // TODO: Other Constant types
        } else if (childin instanceof LDC2_W) {
            Type childType = ((LDC2_W) childin).getType(childPoolGen);
            Type parentType = ((LDC2_W) parentin).getType(parentPoolGen);
            if (!childType.equals(parentType)) {
                return false;
            }
            Object childValue = ((LDC2_W) childin).getValue(childPoolGen);
            Object parentValue = ((LDC2_W) parentin).getValue(parentPoolGen);
            if (!childValue.equals(parentValue)) {
                return false;
            }
        } else {
            if (!childin.equals(parentin)) {
                return false;
            }
        }
    }
    return true;
}
Also used : InstructionList(org.apache.bcel.generic.InstructionList) LDC(org.apache.bcel.generic.LDC) ToString(com.mebigfatguy.fbcontrib.utils.ToString) InvokeInstruction(org.apache.bcel.generic.InvokeInstruction) Instruction(org.apache.bcel.generic.Instruction) FieldInstruction(org.apache.bcel.generic.FieldInstruction) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ReferenceType(org.apache.bcel.generic.ReferenceType) InvokeInstruction(org.apache.bcel.generic.InvokeInstruction) ReferenceType(org.apache.bcel.generic.ReferenceType) Type(org.apache.bcel.generic.Type) BugType(com.mebigfatguy.fbcontrib.utils.BugType) LDC2_W(org.apache.bcel.generic.LDC2_W) FieldInstruction(org.apache.bcel.generic.FieldInstruction) ConstantClass(org.apache.bcel.classfile.ConstantClass)

Example 14 with Instruction

use of org.apache.bcel.generic.Instruction 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 15 with Instruction

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

the class InstructionInterpreter method getInEdges.

private List<Edge> getInEdges(InstructionList il, InstructionHandle ih) {
    List<Edge> edges = new LinkedList<Edge>();
    InstructionHandle prev = ih.getPrev();
    if (prev != null) {
        // check if we can fall through from prev instruction
        Instruction instr = prev.getInstruction();
        if (!(instr instanceof UnconditionalBranch || instr instanceof Select || instr instanceof ReturnInstruction)) {
            if (instr instanceof BranchInstruction) {
                edges.add(new Edge(prev, ih, EdgeType.FALSE_EDGE));
            } else {
                edges.add(new Edge(prev, ih, EdgeType.NORMAL_EDGE));
            }
        }
    }
    // flow graph explicitly
    for (InstructionHandle targeter = il.getStart(); targeter != null; targeter = targeter.getNext()) {
        //      for the instruction for the exception handler
        if (!(targeter.getInstruction() instanceof BranchInstruction))
            continue;
        BranchInstruction bi = (BranchInstruction) targeter.getInstruction();
        if (bi.containsTarget(ih)) {
            edges.add(new Edge(targeter, ih, EdgeType.TRUE_EDGE));
        }
    }
    return edges;
}
Also used : ReturnInstruction(org.apache.bcel.generic.ReturnInstruction) UnconditionalBranch(org.apache.bcel.generic.UnconditionalBranch) BranchInstruction(org.apache.bcel.generic.BranchInstruction) Select(org.apache.bcel.generic.Select) BranchInstruction(org.apache.bcel.generic.BranchInstruction) Instruction(org.apache.bcel.generic.Instruction) ReturnInstruction(org.apache.bcel.generic.ReturnInstruction) LinkedList(java.util.LinkedList) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Aggregations

Instruction (org.apache.bcel.generic.Instruction)27 FieldInstruction (org.apache.bcel.generic.FieldInstruction)15 InstructionHandle (org.apache.bcel.generic.InstructionHandle)15 InvokeInstruction (org.apache.bcel.generic.InvokeInstruction)14 MethodInfo (com.jopdesign.common.MethodInfo)9 GETFIELD (org.apache.bcel.generic.GETFIELD)8 BranchInstruction (org.apache.bcel.generic.BranchInstruction)7 InstructionList (org.apache.bcel.generic.InstructionList)7 ReferenceType (org.apache.bcel.generic.ReferenceType)7 ReturnInstruction (org.apache.bcel.generic.ReturnInstruction)7 Type (org.apache.bcel.generic.Type)7 ConstantPoolGen (org.apache.bcel.generic.ConstantPoolGen)6 CallString (com.jopdesign.common.code.CallString)5 ConstantPushInstruction (org.apache.bcel.generic.ConstantPushInstruction)5 PUTFIELD (org.apache.bcel.generic.PUTFIELD)5 StoreInstruction (org.apache.bcel.generic.StoreInstruction)5 InvokeSite (com.jopdesign.common.code.InvokeSite)4 MethodRef (com.jopdesign.common.type.MethodRef)4 LDC (org.apache.bcel.generic.LDC)4 LocalVariableInstruction (org.apache.bcel.generic.LocalVariableInstruction)4