Search in sources :

Example 26 with Instruction

use of org.apache.bcel.generic.Instruction in project candle-decompiler by bradsdavis.

the class GoToIntermediate method toString.

@Override
public String toString() {
    String t = null;
    Instruction i = ((InstructionHandle) getInstruction()).getInstruction();
    return "Goto [" + this.getInstruction().getPosition() + " -> " + t + "]";
}
Also used : Instruction(org.apache.bcel.generic.Instruction) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 27 with Instruction

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

the class FieldCouldBeLocal method checkBlock.

/**
 * looks in this basic block for the first access to the fields in uncheckedFields. Once found the item is removed from uncheckedFields, and removed from
 * localizableFields if the access is a GETFIELD. If any unchecked fields remain, this method is recursively called on all outgoing edges of this basic
 * block.
 *
 * @param startBB
 *            this basic block
 * @param uncheckedFields
 *            the list of fields to look for
 */
private void checkBlock(BasicBlock startBB, Set<String> uncheckedFields) {
    Deque<BlockState> toBeProcessed = new ArrayDeque<>();
    toBeProcessed.addLast(new BlockState(startBB, uncheckedFields));
    visitedBlocks.set(startBB.getLabel());
    while (!toBeProcessed.isEmpty()) {
        if (localizableFields.isEmpty()) {
            return;
        }
        BlockState bState = toBeProcessed.removeFirst();
        BasicBlock bb = bState.getBasicBlock();
        InstructionIterator ii = bb.instructionIterator();
        while ((bState.getUncheckedFieldSize() > 0) && ii.hasNext()) {
            InstructionHandle ih = ii.next();
            Instruction ins = ih.getInstruction();
            if (ins instanceof FieldInstruction) {
                FieldInstruction fi = (FieldInstruction) ins;
                if (fi.getReferenceType(cpg).getSignature().equals(clsSig)) {
                    String fieldName = fi.getFieldName(cpg);
                    FieldInfo finfo = localizableFields.get(fieldName);
                    if ((finfo != null) && localizableFields.get(fieldName).hasAnnotation()) {
                        localizableFields.remove(fieldName);
                    } else {
                        boolean justRemoved = bState.removeUncheckedField(fieldName);
                        if (ins instanceof GETFIELD) {
                            if (justRemoved) {
                                localizableFields.remove(fieldName);
                                if (localizableFields.isEmpty()) {
                                    return;
                                }
                            }
                        } else if (finfo != null) {
                            finfo.setSrcLineAnnotation(SourceLineAnnotation.fromVisitedInstruction(clsContext, this, ih.getPosition()));
                        }
                    }
                }
            } else if (ins instanceof INVOKESPECIAL) {
                INVOKESPECIAL is = (INVOKESPECIAL) ins;
                ReferenceType rt = is.getReferenceType(cpg);
                if (Values.CONSTRUCTOR.equals(is.getMethodName(cpg))) {
                    if ((rt instanceof ObjectType) && ((ObjectType) rt).getClassName().startsWith(clsContext.getJavaClass().getClassName() + Values.INNER_CLASS_SEPARATOR)) {
                        localizableFields.clear();
                    }
                } else {
                    localizableFields.clear();
                }
            } else if (ins instanceof INVOKEVIRTUAL) {
                INVOKEVIRTUAL is = (INVOKEVIRTUAL) ins;
                ReferenceType rt = is.getReferenceType(cpg);
                if ((rt instanceof ObjectType) && ((ObjectType) rt).getClassName().equals(clsName)) {
                    String methodDesc = is.getName(cpg) + is.getSignature(cpg);
                    Set<String> fields = methodFieldModifiers.get(methodDesc);
                    if (fields != null) {
                        localizableFields.keySet().removeAll(fields);
                    }
                }
            }
        }
        if (bState.getUncheckedFieldSize() > 0) {
            Iterator<Edge> oei = cfg.outgoingEdgeIterator(bb);
            while (oei.hasNext()) {
                Edge e = oei.next();
                BasicBlock cb = e.getTarget();
                int label = cb.getLabel();
                if (!visitedBlocks.get(label)) {
                    toBeProcessed.addLast(new BlockState(cb, bState));
                    visitedBlocks.set(label);
                }
            }
        }
    }
}
Also used : BasicBlock(edu.umd.cs.findbugs.ba.BasicBlock) ToString(com.mebigfatguy.fbcontrib.utils.ToString) Instruction(org.apache.bcel.generic.Instruction) FieldInstruction(org.apache.bcel.generic.FieldInstruction) INVOKESPECIAL(org.apache.bcel.generic.INVOKESPECIAL) ArrayDeque(java.util.ArrayDeque) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ReferenceType(org.apache.bcel.generic.ReferenceType) InstructionIterator(edu.umd.cs.findbugs.ba.BasicBlock.InstructionIterator) GETFIELD(org.apache.bcel.generic.GETFIELD) ObjectType(org.apache.bcel.generic.ObjectType) FieldInstruction(org.apache.bcel.generic.FieldInstruction) Edge(edu.umd.cs.findbugs.ba.Edge) INVOKEVIRTUAL(org.apache.bcel.generic.INVOKEVIRTUAL)

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