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

The following examples show how to use org.apache.bcel.Const#ASTORE_0 . 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: SuspiciousThreadInterrupted.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void sawOpcode(int seen) {

    if (state == SEEN_POSSIBLE_THREAD) {
        if (seen == Const.POP) {
            state = SEEN_UNKNOWNCONTEXT_POP;
            return;
        } else {
            state = SEEN_NOTHING;
        }
    }
    switch (state) {
    case SEEN_NOTHING:
        if ((seen == Const.INVOKESTATIC) && "java/lang/Thread".equals(getClassConstantOperand())
                && "currentThread".equals(getNameConstantOperand()) && "()Ljava/lang/Thread;".equals(getSigConstantOperand())) {
            state = SEEN_CURRENTTHREAD;
        } else if ((seen == Const.INVOKESTATIC || seen == Const.INVOKEINTERFACE || seen == Const.INVOKEVIRTUAL || seen == Const.INVOKESPECIAL)
                && getSigConstantOperand().endsWith("Ljava/lang/Thread;")) {
            state = SEEN_POSSIBLE_THREAD;
        } else if (seen == Const.ALOAD) {
            if (localsWithCurrentThreadValue.get(getRegisterOperand())) {
                state = SEEN_CURRENTTHREAD;
            } else {
                state = SEEN_POSSIBLE_THREAD;
            }
        } else if ((seen >= Const.ALOAD_0) && (seen <= Const.ALOAD_3)) {
            if (localsWithCurrentThreadValue.get(seen - Const.ALOAD_0)) {
                state = SEEN_CURRENTTHREAD;
            } else {
                state = SEEN_POSSIBLE_THREAD;
            }
        } else if ((seen == Const.GETFIELD || seen == Const.GETSTATIC) && "Ljava/lang/Thread;".equals(getSigConstantOperand())) {
            state = SEEN_POSSIBLE_THREAD;
        }
        break;

    case SEEN_CURRENTTHREAD:
        if (seen == Const.POP) {
            state = SEEN_POP_AFTER_CURRENTTHREAD;
        } else if (seen == Const.ASTORE) {
            localsWithCurrentThreadValue.set(getRegisterOperand());
            state = SEEN_NOTHING;
        } else if ((seen >= Const.ASTORE_0) && (seen <= Const.ASTORE_3)) {
            localsWithCurrentThreadValue.set(seen - Const.ASTORE_0);
            state = SEEN_NOTHING;
        } else {
            state = SEEN_NOTHING;
        }
        break;

    default:
        if ((seen == Const.INVOKESTATIC) && "java/lang/Thread".equals(getClassConstantOperand())
                && "interrupted".equals(getNameConstantOperand()) && "()Z".equals(getSigConstantOperand())) {
            if (state == SEEN_POP_AFTER_CURRENTTHREAD) {
                bugReporter.reportBug(new BugInstance(this, "STI_INTERRUPTED_ON_CURRENTTHREAD", LOW_PRIORITY)
                        .addClassAndMethod(this).addSourceLine(this));
            } else if (state == SEEN_UNKNOWNCONTEXT_POP) {
                bugReporter.reportBug(new BugInstance(this, "STI_INTERRUPTED_ON_UNKNOWNTHREAD", NORMAL_PRIORITY)
                        .addClassAndMethod(this).addSourceLine(this));
            }
        }
        state = SEEN_NOTHING;
        break;
    }
}
 
Example 4
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 5
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;
    }
}