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

The following examples show how to use org.apache.bcel.Const#IASTORE . 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: DumbMethods.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Return index of stack entry that must be nonnegative.
 *
 * Return -1 if no stack entry is required to be nonnegative.
 */
private int stackEntryThatMustBeNonnegative(int seen) {
    switch (seen) {
    case Const.INVOKEINTERFACE:
        if ("java/util/List".equals(getClassConstantOperand())) {
            return getStackEntryOfListCallThatMustBeNonnegative();
        }
        break;
    case Const.INVOKEVIRTUAL:
        if ("java/util/LinkedList".equals(getClassConstantOperand())
                || "java/util/ArrayList".equals(getClassConstantOperand())) {
            return getStackEntryOfListCallThatMustBeNonnegative();
        }
        break;

    case Const.IALOAD:
    case Const.AALOAD:
    case Const.SALOAD:
    case Const.CALOAD:
    case Const.BALOAD:
    case Const.LALOAD:
    case Const.DALOAD:
    case Const.FALOAD:
        return 0;
    case Const.IASTORE:
    case Const.AASTORE:
    case Const.SASTORE:
    case Const.CASTORE:
    case Const.BASTORE:
    case Const.LASTORE:
    case Const.DASTORE:
    case Const.FASTORE:
        return 1;
    }
    return -1;
}
 
Example 2
Source File: BCELFactory.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
@Override
public void visitArrayInstruction( final ArrayInstruction i ) {
    final short opcode = i.getOpcode();
    final Type type = i.getType(_cp);
    final String kind = (opcode < Const.IASTORE) ? "Load" : "Store";
    _out.println("il.append(_factory.createArray" + kind + "(" + BCELifier.printType(type)
            + "));");
}
 
Example 3
Source File: Noise.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void sawOpcode(int seen) {
    int priority;
    switch (seen) {
    case Const.INVOKEINTERFACE:
    case Const.INVOKEVIRTUAL:
    case Const.INVOKESPECIAL:
    case Const.INVOKESTATIC:
        hq.pushHash(getClassConstantOperand());
        if (getNameConstantOperand().indexOf('$') == -1) {
            hq.pushHash(getNameConstantOperand());
        }
        hq.pushHash(getSigConstantOperand());

        priority = hq.getPriority();
        if (priority <= Priorities.LOW_PRIORITY) {
            accumulator.accumulateBug(new BugInstance(this, "NOISE_METHOD_CALL", priority).addClassAndMethod(this)
                    .addCalledMethod(this), this);
        }
        break;
    case Const.GETFIELD:
    case Const.PUTFIELD:
    case Const.GETSTATIC:
    case Const.PUTSTATIC:
        hq.pushHash(getClassConstantOperand());
        if (getNameConstantOperand().indexOf('$') == -1) {
            hq.pushHash(getNameConstantOperand());
        }
        hq.pushHash(getSigConstantOperand());
        priority = hq.getPriority();
        if (priority <= Priorities.LOW_PRIORITY) {
            accumulator.accumulateBug(new BugInstance(this, "NOISE_FIELD_REFERENCE", priority).addClassAndMethod(this)
                    .addReferencedField(this), this);
        }
        break;
    case Const.CHECKCAST:
    case Const.INSTANCEOF:
    case Const.NEW:
        hq.pushHash(getClassConstantOperand());
        break;
    case Const.IFEQ:
    case Const.IFNE:
    case Const.IFNONNULL:
    case Const.IFNULL:
    case Const.IF_ICMPEQ:
    case Const.IF_ICMPNE:
    case Const.IF_ICMPLE:
    case Const.IF_ICMPGE:
    case Const.IF_ICMPGT:
    case Const.IF_ICMPLT:
    case Const.IF_ACMPEQ:
    case Const.IF_ACMPNE:
    case Const.RETURN:
    case Const.ARETURN:
    case Const.IRETURN:
    case Const.MONITORENTER:
    case Const.MONITOREXIT:
    case Const.IINC:
    case Const.NEWARRAY:
    case Const.TABLESWITCH:
    case Const.LOOKUPSWITCH:
    case Const.LCMP:
    case Const.INEG:
    case Const.IADD:
    case Const.IMUL:
    case Const.ISUB:
    case Const.IDIV:
    case Const.IREM:
    case Const.IXOR:
    case Const.ISHL:
    case Const.ISHR:
    case Const.IUSHR:
    case Const.IAND:
    case Const.IOR:
    case Const.LAND:
    case Const.LOR:
    case Const.LADD:
    case Const.LMUL:
    case Const.LSUB:
    case Const.LDIV:
    case Const.LSHL:
    case Const.LSHR:
    case Const.LUSHR:
    case Const.AALOAD:
    case Const.AASTORE:
    case Const.IALOAD:
    case Const.IASTORE:
    case Const.BALOAD:
    case Const.BASTORE:
        hq.push(seen);
        priority = hq.getPriority();
        if (priority <= Priorities.LOW_PRIORITY) {
            accumulator.accumulateBug(
                    new BugInstance(this, "NOISE_OPERATION", priority).addClassAndMethod(this).addString(Const.getOpcodeName(seen)),
                    this);
        }
        break;
    default:
        break;
    }
}
 
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;
    }
}
 
Example 5
Source File: FindInconsistentSync2.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Determine whether or not the the given method is a getter method. I.e.,
 * if it just returns the value of an instance field.
 *
 * @param classContext
 *            the ClassContext for the class containing the method
 * @param method
 *            the method
 */
public static boolean isGetterMethod(ClassContext classContext, Method method) {
    MethodGen methodGen = classContext.getMethodGen(method);
    if (methodGen == null) {
        return false;
    }
    InstructionList il = methodGen.getInstructionList();
    // System.out.println("Checking getter method: " + method.getName());
    if (il.getLength() > 60) {
        return false;
    }

    int count = 0;
    for (InstructionHandle ih : il) {
        switch (ih.getInstruction().getOpcode()) {
        case Const.GETFIELD:
            count++;
            if (count > 1) {
                return false;
            }
            break;
        case Const.PUTFIELD:
        case Const.BALOAD:
        case Const.CALOAD:
        case Const.DALOAD:
        case Const.FALOAD:
        case Const.IALOAD:
        case Const.LALOAD:
        case Const.SALOAD:
        case Const.AALOAD:
        case Const.BASTORE:
        case Const.CASTORE:
        case Const.DASTORE:
        case Const.FASTORE:
        case Const.IASTORE:
        case Const.LASTORE:
        case Const.SASTORE:
        case Const.AASTORE:
        case Const.PUTSTATIC:
            return false;
        case Const.INVOKESTATIC:
        case Const.INVOKEVIRTUAL:
        case Const.INVOKEINTERFACE:
        case Const.INVOKESPECIAL:
        case Const.GETSTATIC:
            // no-op

        }
    }
    // System.out.println("Found getter method: " + method.getName());
    return true;
}