Java Code Examples for org.apache.bcel.Const#ASTORE_2

The following examples show how to use org.apache.bcel.Const#ASTORE_2 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringConcatenation.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private boolean storeIntoRegister(int seen, int reg) {
    switch (seen) {
    case Const.ASTORE_0:
        return reg == 0;
    case Const.ASTORE_1:
        return reg == 1;
    case Const.ASTORE_2:
        return reg == 2;
    case Const.ASTORE_3:
        return reg == 3;
    case Const.ASTORE:
        return reg == getRegisterOperand();
    default:
        return false;
    }
}
 
Example 2
Source File: DismantleBytecode.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public boolean isRegisterStore(int opcode) {
    switch (opcode) {
    case Const.ISTORE_0:
    case Const.ISTORE_1:
    case Const.ISTORE_2:
    case Const.ISTORE_3:

    case Const.ASTORE_0:
    case Const.ASTORE_1:
    case Const.ASTORE_2:
    case Const.ASTORE_3:

    case Const.FSTORE_0:
    case Const.FSTORE_1:
    case Const.FSTORE_2:
    case Const.FSTORE_3:

    case Const.DSTORE_0:
    case Const.DSTORE_1:
    case Const.DSTORE_2:
    case Const.DSTORE_3:

    case Const.LSTORE_0:
    case Const.LSTORE_1:
    case Const.LSTORE_2:
    case Const.LSTORE_3:

    case Const.ISTORE:
    case Const.FSTORE:
    case Const.ASTORE:
    case Const.LSTORE:
    case Const.DSTORE:
        return true;
    default:
        return false;
    }
}
 
Example 3
Source File: SynchronizeAndNullCheckField.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    // System.out.println(getPC() + " " + Const.getOpcodeName(seen) + " " +
    // currState);
    switch (currState) {
    case 0:
        if (seen == Const.GETFIELD || seen == Const.GETSTATIC) {
            syncField = FieldAnnotation.fromReferencedField(this);
            currState = 1;
        }
        break;
    case 1:
        if (seen == Const.DUP) {
            currState = 2;
        } else {
            currState = 0;
        }
        break;
    case 2:
        if (seen == Const.ASTORE || seen == Const.ASTORE_0 || seen == Const.ASTORE_1 || seen == Const.ASTORE_2 || seen == Const.ASTORE_3) {
            currState = 3;
        } else {
            currState = 0;
        }
        break;
    case 3:
        if (seen == Const.MONITORENTER) {
            currState = 4;
        } else {
            currState = 0;
        }
        break;
    case 4:
        if (seen == Const.GETFIELD || seen == Const.GETSTATIC) {
            gottenField = FieldAnnotation.fromReferencedField(this);
            currState = 5;
        } else {
            currState = 0;
        }
        break;
    case 5:
        if ((seen == Const.IFNONNULL || seen == Const.IFNULL) && gottenField.equals(syncField)) {
            BugInstance bug = new BugInstance(this, "NP_SYNC_AND_NULL_CHECK_FIELD", NORMAL_PRIORITY).addClass(this)
                    .addMethod(this).addField(syncField).addSourceLine(this);
            bugReporter.reportBug(bug);
        } else {
            currState = 0;
        }
        break;
    default:
        currState = 0;
    }
}
 
Example 4
Source File: FindNoSideEffectMethods.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    if (!allowedFields.isEmpty() && seen == Const.PUTFIELD) {
        Item objItem = getStack().getStackItem(1);
        if (objItem.getRegisterNumber() == 0) {
            if (allowedFields.contains(getFieldDescriptorOperand())) {
                Item valueItem = getStack().getStackItem(0);
                if (!isNew(valueItem) && !valueItem.isNull()) {
                    allowedFields.remove(getFieldDescriptorOperand());
                }
            }
        }
    }
    if (status == SideEffectStatus.SIDE_EFFECT && allowedFields.isEmpty()) {
        // Nothing to do: skip the rest of the method
        throw new EarlyExitException();
    }
    if (status == SideEffectStatus.SIDE_EFFECT) {
        return;
    }
    switch (seen) {
    case Const.ASTORE:
    case Const.ASTORE_0:
    case Const.ASTORE_1:
    case Const.ASTORE_2:
    case Const.ASTORE_3:
        if (finallyTargets.contains(getPC())) {
            finallyExceptionRegisters.add(getRegisterOperand());
        }
        break;
    case Const.ATHROW: {
        Item exceptionItem = getStack().getStackItem(0);
        if (!finallyExceptionRegisters.remove(exceptionItem.getRegisterNumber())) {
            uselessVoidCandidate = false;
            try {
                JavaClass javaClass = exceptionItem.getJavaClass();
                if (javaClass != null && ALLOWED_EXCEPTIONS.contains(javaClass.getClassName())) {
                    break;
                }
            } catch (ClassNotFoundException e) {
            }
            status = SideEffectStatus.SIDE_EFFECT;
        }
        break;
    }
    case Const.PUTSTATIC:
        if (classInit) {
            if (getClassConstantOperand().equals(getClassName())) {
                break;
            }
        }
        status = SideEffectStatus.SIDE_EFFECT;
        break;
    case Const.INVOKEDYNAMIC:
        status = SideEffectStatus.SIDE_EFFECT;
        break;
    case Const.PUTFIELD:
        sawCall(getMethodCall(FIELD_STORE_STUB_METHOD), false);
        break;
    case Const.AASTORE:
    case Const.DASTORE:
    case Const.CASTORE:
    case Const.BASTORE:
    case Const.IASTORE:
    case Const.LASTORE:
    case Const.FASTORE:
    case Const.SASTORE:
        sawCall(getMethodCall(ARRAY_STORE_STUB_METHOD), false);
        break;
    case Const.INVOKESTATIC:
        if (changesOnlyNewObjects(getMethodDescriptorOperand())) {
            break;
        }
        sawCall(new MethodCall(getMethodDescriptorOperand(), TARGET_OTHER), false);
        break;
    case Const.INVOKESPECIAL:
    case Const.INVOKEINTERFACE:
    case Const.INVOKEVIRTUAL: {
        XMethod xMethodOperand = getXMethodOperand();
        MethodDescriptor methodDescriptorOperand = xMethodOperand == null ? getMethodDescriptorOperand()
                : xMethodOperand
                        .getMethodDescriptor();
        if (changesOnlyNewObjects(getMethodDescriptorOperand())) {
            break;
        }
        MethodCall methodCall = getMethodCall(methodDescriptorOperand);
        sawCall(methodCall, false);
        break;
    }
    default:
        break;
    }
}