Search in sources :

Example 1 with RETURN

use of org.objectweb.asm.Opcodes.RETURN in project LanternServer by LanternPowered.

the class FieldAccessFactory method createSetter.

/**
 * Creates a setter {@link BiConsumer} for the given {@link Field}.
 *
 * @param field The field
 * @param <T> The target object type
 * @param <V> The field value type
 * @return The bi consumer
 */
public static <T, V> BiConsumer<T, V> createSetter(Field field) {
    checkNotNull(field, "field");
    field.setAccessible(true);
    boolean isFinal = Modifier.isFinal(field.getModifiers());
    // Better check is somebody changed the final modifier already
    if (!isFinal) {
        final Field[] fields = field.getDeclaringClass().getDeclaredFields();
        boolean isFound = false;
        for (Field field1 : fields) {
            // The same signature, now check if somebody tinkered with the field
            if (field.getName().equals(field1.getName()) && field.getType().equals(field1.getType())) {
                isFinal = Modifier.isFinal(field1.getModifiers());
                isFound = true;
                break;
            }
        }
        if (!isFound) {
            throw new IllegalStateException("Something funky happened with: " + field.getName());
        }
    } else {
        try {
            modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        } catch (IllegalAccessException e) {
            throw new IllegalStateException(e);
        }
    }
    // Final fields don't allow direct access, so MethodHandles will do the trick.
    if (isFinal) {
        try {
            final MethodHandle methodHandle = MethodHandleMagic.trustedLookup().in(field.getDeclaringClass()).unreflectSetter(field).asType(setterMethodType);
            return (a, b) -> {
                try {
                    methodHandle.invokeExact(a, b);
                } catch (Throwable throwable) {
                    throw new IllegalStateException(throwable);
                }
            };
        } catch (IllegalAccessException e) {
            throw new IllegalStateException(e);
        }
    }
    final ClassWriter cw = new ClassWriter(0);
    final String className = field.getName().replace('.', '/') + "$$LanternSetter$" + setterCounter.incrementAndGet();
    cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, className, "Ljava/lang/Object;Ljava/util/function/BiConsumer<Ljava/lang/Object;Ljava/lang/Object;>;", "java/lang/Object", new String[] { "java/util/function/BiConsumer" });
    // Add a empty constructor
    BytecodeUtils.visitEmptyConstructor(cw);
    // Generate the apply method
    final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "accept", "(Ljava/lang/Object;Ljava/lang/Object;)V", null, null);
    mv.visitCode();
    final String descriptor = Type.getDescriptor(field.getType());
    final String targetName = Type.getInternalName(field.getDeclaringClass());
    final boolean isStatic = Modifier.isStatic(field.getModifiers());
    if (!isStatic) {
        // Load the target parameter
        mv.visitVarInsn(ALOAD, 1);
        // Cast it
        mv.visitTypeInsn(CHECKCAST, targetName);
    }
    // Load the value parameter
    mv.visitVarInsn(ALOAD, 2);
    // Unbox the values in case they are primitives, otherwise cast
    GeneratorUtils.visitUnboxingMethod(mv, Type.getType(field.getType()));
    // Put the value into the field
    if (isStatic) {
        mv.visitFieldInsn(PUTSTATIC, targetName, field.getName(), descriptor);
    } else {
        mv.visitFieldInsn(PUTFIELD, targetName, field.getName(), descriptor);
    }
    // Return
    mv.visitInsn(RETURN);
    mv.visitMaxs(2, 3);
    mv.visitEnd();
    // Finish class generation
    cw.visitEnd();
    // Define the class and create a function instance
    final MethodHandles.Lookup lookup = MethodHandleMagic.trustedLookup().in(field.getDeclaringClass());
    final Class<?> functionClass = MethodHandleMagic.defineNestmateClass(lookup, cw.toByteArray());
    try {
        return (BiConsumer<T, V>) functionClass.newInstance();
    } catch (Exception e) {
        throw new IllegalStateException("Something went wrong!", e);
    }
}
Also used : ClassWriter(org.objectweb.asm.ClassWriter) MethodHandle(java.lang.invoke.MethodHandle) MethodVisitor(org.objectweb.asm.MethodVisitor) ACC_SUPER(org.objectweb.asm.Opcodes.ACC_SUPER) GETSTATIC(org.objectweb.asm.Opcodes.GETSTATIC) GeneratorUtils(org.spongepowered.api.util.generator.GeneratorUtils) V1_8(org.objectweb.asm.Opcodes.V1_8) Type(org.objectweb.asm.Type) Function(java.util.function.Function) Supplier(java.util.function.Supplier) PUTFIELD(org.objectweb.asm.Opcodes.PUTFIELD) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BiConsumer(java.util.function.BiConsumer) CHECKCAST(org.objectweb.asm.Opcodes.CHECKCAST) MethodHandles(java.lang.invoke.MethodHandles) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Field(java.lang.reflect.Field) Preconditions.checkState(com.google.common.base.Preconditions.checkState) GETFIELD(org.objectweb.asm.Opcodes.GETFIELD) Consumer(java.util.function.Consumer) MethodType(java.lang.invoke.MethodType) RETURN(org.objectweb.asm.Opcodes.RETURN) ACC_PUBLIC(org.objectweb.asm.Opcodes.ACC_PUBLIC) PUTSTATIC(org.objectweb.asm.Opcodes.PUTSTATIC) Modifier(java.lang.reflect.Modifier) ARETURN(org.objectweb.asm.Opcodes.ARETURN) ALOAD(org.objectweb.asm.Opcodes.ALOAD) ClassWriter(org.objectweb.asm.ClassWriter) MethodVisitor(org.objectweb.asm.MethodVisitor) Field(java.lang.reflect.Field) MethodHandles(java.lang.invoke.MethodHandles) BiConsumer(java.util.function.BiConsumer) MethodHandle(java.lang.invoke.MethodHandle)

Example 2 with RETURN

use of org.objectweb.asm.Opcodes.RETURN in project sonar-java by SonarSource.

the class BytecodeEGWalker method branchingState.

@VisibleForTesting
ProgramState branchingState(Instruction terminator, ProgramState programState) {
    ProgramState.Pop pop;
    ProgramState ps;
    List<ProgramState.SymbolicValueSymbol> symbolicValueSymbols;
    switch(terminator.opcode) {
        case IFEQ:
        case IFNE:
        case IFLT:
        case IFGE:
        case IFGT:
        case IFLE:
            pop = programState.unstackValue(1);
            SymbolicValue svZero = new SymbolicValue();
            symbolicValueSymbols = ImmutableList.of(new ProgramState.SymbolicValueSymbol(svZero, null), pop.valuesAndSymbols.get(0));
            List<ProgramState> programStates = svZero.setConstraint(pop.state, DivisionByZeroCheck.ZeroConstraint.ZERO).stream().flatMap(s -> svZero.setConstraint(s, BooleanConstraint.FALSE).stream()).collect(Collectors.toList());
            Preconditions.checkState(programStates.size() == 1);
            ps = programStates.get(0);
            break;
        case IF_ICMPEQ:
        case IF_ICMPNE:
        case IF_ICMPLT:
        case IF_ICMPGE:
        case IF_ICMPGT:
        case IF_ICMPLE:
        case IF_ACMPEQ:
        case IF_ACMPNE:
            pop = programState.unstackValue(2);
            symbolicValueSymbols = pop.valuesAndSymbols;
            ps = pop.state;
            break;
        case IFNULL:
        case IFNONNULL:
            pop = programState.unstackValue(1);
            symbolicValueSymbols = ImmutableList.of(new ProgramState.SymbolicValueSymbol(SymbolicValue.NULL_LITERAL, null), pop.valuesAndSymbols.get(0));
            ps = pop.state;
            break;
        default:
            throw new IllegalStateException("Unexpected terminator " + terminator);
    }
    return ps.stackValue(constraintManager.createBinarySymbolicValue(terminator, symbolicValueSymbols));
}
Also used : ASTORE(org.objectweb.asm.Opcodes.ASTORE) ATHROW(org.objectweb.asm.Opcodes.ATHROW) DMUL(org.objectweb.asm.Opcodes.DMUL) F2D(org.objectweb.asm.Opcodes.F2D) LSHR(org.objectweb.asm.Opcodes.LSHR) IF_ICMPEQ(org.objectweb.asm.Opcodes.IF_ICMPEQ) F2I(org.objectweb.asm.Opcodes.F2I) IINC(org.objectweb.asm.Opcodes.IINC) IFGT(org.objectweb.asm.Opcodes.IFGT) LSHL(org.objectweb.asm.Opcodes.LSHL) IAND(org.objectweb.asm.Opcodes.IAND) DCMPL(org.objectweb.asm.Opcodes.DCMPL) LSTORE(org.objectweb.asm.Opcodes.LSTORE) TypedConstraint(org.sonar.java.se.constraint.TypedConstraint) DCMPG(org.objectweb.asm.Opcodes.DCMPG) IFNULL(org.objectweb.asm.Opcodes.IFNULL) FLOAD(org.objectweb.asm.Opcodes.FLOAD) INSTANCEOF(org.objectweb.asm.Opcodes.INSTANCEOF) IALOAD(org.objectweb.asm.Opcodes.IALOAD) DUP2_X2(org.objectweb.asm.Opcodes.DUP2_X2) DUP2_X1(org.objectweb.asm.Opcodes.DUP2_X1) PUTFIELD(org.objectweb.asm.Opcodes.PUTFIELD) IFEQ(org.objectweb.asm.Opcodes.IFEQ) Lists(com.google.common.collect.Lists) INVOKESTATIC(org.objectweb.asm.Opcodes.INVOKESTATIC) ACONST_NULL(org.objectweb.asm.Opcodes.ACONST_NULL) MethodBehavior(org.sonar.java.se.xproc.MethodBehavior) DALOAD(org.objectweb.asm.Opcodes.DALOAD) INEG(org.objectweb.asm.Opcodes.INEG) MONITORENTER(org.objectweb.asm.Opcodes.MONITORENTER) TABLESWITCH(org.objectweb.asm.Opcodes.TABLESWITCH) ICONST_5(org.objectweb.asm.Opcodes.ICONST_5) IMUL(org.objectweb.asm.Opcodes.IMUL) LOR(org.objectweb.asm.Opcodes.LOR) DASTORE(org.objectweb.asm.Opcodes.DASTORE) ICONST_4(org.objectweb.asm.Opcodes.ICONST_4) Opcodes(org.objectweb.asm.Opcodes) ICONST_3(org.objectweb.asm.Opcodes.ICONST_3) ICONST_2(org.objectweb.asm.Opcodes.ICONST_2) IFGE(org.objectweb.asm.Opcodes.IFGE) ICONST_1(org.objectweb.asm.Opcodes.ICONST_1) ICONST_0(org.objectweb.asm.Opcodes.ICONST_0) LADD(org.objectweb.asm.Opcodes.LADD) F2L(org.objectweb.asm.Opcodes.F2L) Printer(org.objectweb.asm.util.Printer) LREM(org.objectweb.asm.Opcodes.LREM) Preconditions(com.google.common.base.Preconditions) INVOKESPECIAL(org.objectweb.asm.Opcodes.INVOKESPECIAL) DNEG(org.objectweb.asm.Opcodes.DNEG) LDIV(org.objectweb.asm.Opcodes.LDIV) LLOAD(org.objectweb.asm.Opcodes.LLOAD) LCMP(org.objectweb.asm.Opcodes.LCMP) IXOR(org.objectweb.asm.Opcodes.IXOR) DSUB(org.objectweb.asm.Opcodes.DSUB) IFLE(org.objectweb.asm.Opcodes.IFLE) Loggers(org.sonar.api.utils.log.Loggers) LASTORE(org.objectweb.asm.Opcodes.LASTORE) FSTORE(org.objectweb.asm.Opcodes.FSTORE) INVOKEVIRTUAL(org.objectweb.asm.Opcodes.INVOKEVIRTUAL) Collectors(java.util.stream.Collectors) GETFIELD(org.objectweb.asm.Opcodes.GETFIELD) FNEG(org.objectweb.asm.Opcodes.FNEG) I2L(org.objectweb.asm.Opcodes.I2L) CASTORE(org.objectweb.asm.Opcodes.CASTORE) Instruction(org.sonar.java.bytecode.cfg.Instruction) GOTO(org.objectweb.asm.Opcodes.GOTO) I2S(org.objectweb.asm.Opcodes.I2S) Constraint(org.sonar.java.se.constraint.Constraint) ARETURN(org.objectweb.asm.Opcodes.ARETURN) IFLT(org.objectweb.asm.Opcodes.IFLT) IUSHR(org.objectweb.asm.Opcodes.IUSHR) Symbols(org.sonar.java.resolve.Symbols) IF_ACMPEQ(org.objectweb.asm.Opcodes.IF_ACMPEQ) LRETURN(org.objectweb.asm.Opcodes.LRETURN) DivisionByZeroCheck(org.sonar.java.se.checks.DivisionByZeroCheck) ConstraintManager(org.sonar.java.se.constraint.ConstraintManager) ImmutableList(com.google.common.collect.ImmutableList) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) LinkedList(java.util.LinkedList) BytecodeCFG(org.sonar.java.bytecode.cfg.BytecodeCFG) NOP(org.objectweb.asm.Opcodes.NOP) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader) MONITOREXIT(org.objectweb.asm.Opcodes.MONITOREXIT) Type(org.sonar.plugins.java.api.semantic.Type) ISUB(org.objectweb.asm.Opcodes.ISUB) ARRAYLENGTH(org.objectweb.asm.Opcodes.ARRAYLENGTH) DUP_X2(org.objectweb.asm.Opcodes.DUP_X2) DUP_X1(org.objectweb.asm.Opcodes.DUP_X1) AASTORE(org.objectweb.asm.Opcodes.AASTORE) SemanticModel(org.sonar.java.resolve.SemanticModel) BALOAD(org.objectweb.asm.Opcodes.BALOAD) PUTSTATIC(org.objectweb.asm.Opcodes.PUTSTATIC) ProgramPoint(org.sonar.java.se.ProgramPoint) CheckForNull(javax.annotation.CheckForNull) LMUL(org.objectweb.asm.Opcodes.LMUL) INVOKEINTERFACE(org.objectweb.asm.Opcodes.INVOKEINTERFACE) BASTORE(org.objectweb.asm.Opcodes.BASTORE) IF_ICMPNE(org.objectweb.asm.Opcodes.IF_ICMPNE) AALOAD(org.objectweb.asm.Opcodes.AALOAD) BooleanConstraint(org.sonar.java.se.constraint.BooleanConstraint) ExceptionUtils(org.sonar.java.se.ExceptionUtils) FCONST_0(org.objectweb.asm.Opcodes.FCONST_0) FCONST_1(org.objectweb.asm.Opcodes.FCONST_1) FCONST_2(org.objectweb.asm.Opcodes.FCONST_2) DCONST_0(org.objectweb.asm.Opcodes.DCONST_0) SIPUSH(org.objectweb.asm.Opcodes.SIPUSH) Set(java.util.Set) IF_ICMPLT(org.objectweb.asm.Opcodes.IF_ICMPLT) DLOAD(org.objectweb.asm.Opcodes.DLOAD) DUP(org.objectweb.asm.Opcodes.DUP) FCMPG(org.objectweb.asm.Opcodes.FCMPG) LAND(org.objectweb.asm.Opcodes.LAND) FCMPL(org.objectweb.asm.Opcodes.FCMPL) LCONST_0(org.objectweb.asm.Opcodes.LCONST_0) SASTORE(org.objectweb.asm.Opcodes.SASTORE) LALOAD(org.objectweb.asm.Opcodes.LALOAD) DCONST_1(org.objectweb.asm.Opcodes.DCONST_1) LCONST_1(org.objectweb.asm.Opcodes.LCONST_1) IOR(org.objectweb.asm.Opcodes.IOR) ObjectConstraint(org.sonar.java.se.constraint.ObjectConstraint) DSTORE(org.objectweb.asm.Opcodes.DSTORE) CALOAD(org.objectweb.asm.Opcodes.CALOAD) FMUL(org.objectweb.asm.Opcodes.FMUL) LONG_OR_DOUBLE(org.sonar.java.bytecode.se.BytecodeEGWalker.StackValueCategoryConstraint.LONG_OR_DOUBLE) I2B(org.objectweb.asm.Opcodes.I2B) IFNE(org.objectweb.asm.Opcodes.IFNE) IREM(org.objectweb.asm.Opcodes.IREM) I2C(org.objectweb.asm.Opcodes.I2C) I2D(org.objectweb.asm.Opcodes.I2D) SWAP(org.objectweb.asm.Opcodes.SWAP) I2F(org.objectweb.asm.Opcodes.I2F) IADD(org.objectweb.asm.Opcodes.IADD) ISTORE(org.objectweb.asm.Opcodes.ISTORE) Pair(org.sonar.java.se.Pair) LOOKUPSWITCH(org.objectweb.asm.Opcodes.LOOKUPSWITCH) IF_ICMPLE(org.objectweb.asm.Opcodes.IF_ICMPLE) INVOKEDYNAMIC(org.objectweb.asm.Opcodes.INVOKEDYNAMIC) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) Logger(org.sonar.api.utils.log.Logger) IDIV(org.objectweb.asm.Opcodes.IDIV) DREM(org.objectweb.asm.Opcodes.DREM) POP(org.objectweb.asm.Opcodes.POP) SALOAD(org.objectweb.asm.Opcodes.SALOAD) ISHR(org.objectweb.asm.Opcodes.ISHR) NEWARRAY(org.objectweb.asm.Opcodes.NEWARRAY) DADD(org.objectweb.asm.Opcodes.DADD) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) ICONST_M1(org.objectweb.asm.Opcodes.ICONST_M1) ISHL(org.objectweb.asm.Opcodes.ISHL) BehaviorCache(org.sonar.java.se.xproc.BehaviorCache) LNEG(org.objectweb.asm.Opcodes.LNEG) IRETURN(org.objectweb.asm.Opcodes.IRETURN) DDIV(org.objectweb.asm.Opcodes.DDIV) ALOAD(org.objectweb.asm.Opcodes.ALOAD) FALOAD(org.objectweb.asm.Opcodes.FALOAD) GETSTATIC(org.objectweb.asm.Opcodes.GETSTATIC) LSUB(org.objectweb.asm.Opcodes.LSUB) D2F(org.objectweb.asm.Opcodes.D2F) D2I(org.objectweb.asm.Opcodes.D2I) D2L(org.objectweb.asm.Opcodes.D2L) L2D(org.objectweb.asm.Opcodes.L2D) NEW(org.objectweb.asm.Opcodes.NEW) BytecodeCFGMethodVisitor(org.sonar.java.bytecode.cfg.BytecodeCFGMethodVisitor) MULTIANEWARRAY(org.objectweb.asm.Opcodes.MULTIANEWARRAY) FADD(org.objectweb.asm.Opcodes.FADD) BIPUSH(org.objectweb.asm.Opcodes.BIPUSH) IASTORE(org.objectweb.asm.Opcodes.IASTORE) FREM(org.objectweb.asm.Opcodes.FREM) List(java.util.List) FDIV(org.objectweb.asm.Opcodes.FDIV) DRETURN(org.objectweb.asm.Opcodes.DRETURN) LXOR(org.objectweb.asm.Opcodes.LXOR) FASTORE(org.objectweb.asm.Opcodes.FASTORE) IFNONNULL(org.objectweb.asm.Opcodes.IFNONNULL) FSUB(org.objectweb.asm.Opcodes.FSUB) LUSHR(org.objectweb.asm.Opcodes.LUSHR) IF_ACMPNE(org.objectweb.asm.Opcodes.IF_ACMPNE) ProgramState(org.sonar.java.se.ProgramState) Deque(java.util.Deque) IF_ICMPGT(org.objectweb.asm.Opcodes.IF_ICMPGT) ExplodedGraphWalker(org.sonar.java.se.ExplodedGraphWalker) LDC(org.objectweb.asm.Opcodes.LDC) CHECKCAST(org.objectweb.asm.Opcodes.CHECKCAST) DUP2(org.objectweb.asm.Opcodes.DUP2) ExplodedGraph(org.sonar.java.se.ExplodedGraph) L2F(org.objectweb.asm.Opcodes.L2F) ANEWARRAY(org.objectweb.asm.Opcodes.ANEWARRAY) L2I(org.objectweb.asm.Opcodes.L2I) RETURN(org.objectweb.asm.Opcodes.RETURN) ILOAD(org.objectweb.asm.Opcodes.ILOAD) FRETURN(org.objectweb.asm.Opcodes.FRETURN) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) POP2(org.objectweb.asm.Opcodes.POP2) IF_ICMPGE(org.objectweb.asm.Opcodes.IF_ICMPGE) ProgramState(org.sonar.java.se.ProgramState) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with RETURN

use of org.objectweb.asm.Opcodes.RETURN in project sonar-java by SonarSource.

the class BytecodeEGWalker method handleMethodInvocation.

private boolean handleMethodInvocation(Instruction instruction) {
    boolean isStatic = instruction.opcode == Opcodes.INVOKESTATIC;
    int arity = isStatic ? instruction.arity() : (instruction.arity() + 1);
    ProgramState.Pop pop = programState.unstackValue(arity);
    Preconditions.checkState(pop.values.size() == arity, "Arguments mismatch for INVOKE");
    // TODO use constraintManager.createMethodSymbolicValue to create relational SV for equals
    programState = pop.state;
    SymbolicValue returnSV = instruction.hasReturnValue() ? constraintManager.createSymbolicValue(instruction) : null;
    String signature = instruction.fieldOrMethod.completeSignature();
    MethodBehavior methodInvokedBehavior = behaviorCache.get(signature);
    enqueueUncheckedExceptions();
    // FIXME : empty yields here should not happen, for now act as if behavior was not resolved.
    if (methodInvokedBehavior != null && methodInvokedBehavior.isComplete() && !methodInvokedBehavior.yields().isEmpty()) {
        List<SymbolicValue> stack = Lists.reverse(pop.values);
        if (!isStatic) {
            // remove "thisSV" from stack before trying to apply any yield, as it should not match with arguments
            stack = stack.subList(1, stack.size());
        }
        List<SymbolicValue> arguments = stack;
        methodInvokedBehavior.happyPathYields().forEach(yield -> yield.statesAfterInvocation(arguments, Collections.emptyList(), programState, () -> returnSV).forEach(ps -> {
            checkerDispatcher.methodYield = yield;
            if (ps.peekValue() != null) {
                ps = setDoubleOrLong(ps, ps.peekValue(), instruction.isLongOrDoubleValue());
            }
            checkerDispatcher.addTransition(ps);
            checkerDispatcher.methodYield = null;
        }));
        methodInvokedBehavior.exceptionalPathYields().forEach(yield -> {
            Type exceptionType = yield.exceptionType(semanticModel);
            yield.statesAfterInvocation(arguments, Collections.emptyList(), programState, () -> constraintManager.createExceptionalSymbolicValue(exceptionType)).forEach(ps -> {
                ps.storeExitValue();
                enqueueExceptionHandlers(exceptionType, ps);
            });
        });
        return true;
    }
    if (methodInvokedBehavior != null) {
        methodInvokedBehavior.getDeclaredExceptions().forEach(exception -> {
            Type exceptionType = semanticModel.getClassType(exception);
            ProgramState ps = programState.stackValue(constraintManager.createExceptionalSymbolicValue(exceptionType));
            enqueueExceptionHandlers(exceptionType, ps);
        });
    }
    if (instruction.hasReturnValue()) {
        programState = programState.stackValue(returnSV);
        programState = setDoubleOrLong(returnSV, instruction.isLongOrDoubleValue());
    }
    return false;
}
Also used : ASTORE(org.objectweb.asm.Opcodes.ASTORE) ATHROW(org.objectweb.asm.Opcodes.ATHROW) DMUL(org.objectweb.asm.Opcodes.DMUL) F2D(org.objectweb.asm.Opcodes.F2D) LSHR(org.objectweb.asm.Opcodes.LSHR) IF_ICMPEQ(org.objectweb.asm.Opcodes.IF_ICMPEQ) F2I(org.objectweb.asm.Opcodes.F2I) IINC(org.objectweb.asm.Opcodes.IINC) IFGT(org.objectweb.asm.Opcodes.IFGT) LSHL(org.objectweb.asm.Opcodes.LSHL) IAND(org.objectweb.asm.Opcodes.IAND) DCMPL(org.objectweb.asm.Opcodes.DCMPL) LSTORE(org.objectweb.asm.Opcodes.LSTORE) TypedConstraint(org.sonar.java.se.constraint.TypedConstraint) DCMPG(org.objectweb.asm.Opcodes.DCMPG) IFNULL(org.objectweb.asm.Opcodes.IFNULL) FLOAD(org.objectweb.asm.Opcodes.FLOAD) INSTANCEOF(org.objectweb.asm.Opcodes.INSTANCEOF) IALOAD(org.objectweb.asm.Opcodes.IALOAD) DUP2_X2(org.objectweb.asm.Opcodes.DUP2_X2) DUP2_X1(org.objectweb.asm.Opcodes.DUP2_X1) PUTFIELD(org.objectweb.asm.Opcodes.PUTFIELD) IFEQ(org.objectweb.asm.Opcodes.IFEQ) Lists(com.google.common.collect.Lists) INVOKESTATIC(org.objectweb.asm.Opcodes.INVOKESTATIC) ACONST_NULL(org.objectweb.asm.Opcodes.ACONST_NULL) MethodBehavior(org.sonar.java.se.xproc.MethodBehavior) DALOAD(org.objectweb.asm.Opcodes.DALOAD) INEG(org.objectweb.asm.Opcodes.INEG) MONITORENTER(org.objectweb.asm.Opcodes.MONITORENTER) TABLESWITCH(org.objectweb.asm.Opcodes.TABLESWITCH) ICONST_5(org.objectweb.asm.Opcodes.ICONST_5) IMUL(org.objectweb.asm.Opcodes.IMUL) LOR(org.objectweb.asm.Opcodes.LOR) DASTORE(org.objectweb.asm.Opcodes.DASTORE) ICONST_4(org.objectweb.asm.Opcodes.ICONST_4) Opcodes(org.objectweb.asm.Opcodes) ICONST_3(org.objectweb.asm.Opcodes.ICONST_3) ICONST_2(org.objectweb.asm.Opcodes.ICONST_2) IFGE(org.objectweb.asm.Opcodes.IFGE) ICONST_1(org.objectweb.asm.Opcodes.ICONST_1) ICONST_0(org.objectweb.asm.Opcodes.ICONST_0) LADD(org.objectweb.asm.Opcodes.LADD) F2L(org.objectweb.asm.Opcodes.F2L) Printer(org.objectweb.asm.util.Printer) LREM(org.objectweb.asm.Opcodes.LREM) Preconditions(com.google.common.base.Preconditions) INVOKESPECIAL(org.objectweb.asm.Opcodes.INVOKESPECIAL) DNEG(org.objectweb.asm.Opcodes.DNEG) LDIV(org.objectweb.asm.Opcodes.LDIV) LLOAD(org.objectweb.asm.Opcodes.LLOAD) LCMP(org.objectweb.asm.Opcodes.LCMP) IXOR(org.objectweb.asm.Opcodes.IXOR) DSUB(org.objectweb.asm.Opcodes.DSUB) IFLE(org.objectweb.asm.Opcodes.IFLE) Loggers(org.sonar.api.utils.log.Loggers) LASTORE(org.objectweb.asm.Opcodes.LASTORE) FSTORE(org.objectweb.asm.Opcodes.FSTORE) INVOKEVIRTUAL(org.objectweb.asm.Opcodes.INVOKEVIRTUAL) Collectors(java.util.stream.Collectors) GETFIELD(org.objectweb.asm.Opcodes.GETFIELD) FNEG(org.objectweb.asm.Opcodes.FNEG) I2L(org.objectweb.asm.Opcodes.I2L) CASTORE(org.objectweb.asm.Opcodes.CASTORE) Instruction(org.sonar.java.bytecode.cfg.Instruction) GOTO(org.objectweb.asm.Opcodes.GOTO) I2S(org.objectweb.asm.Opcodes.I2S) Constraint(org.sonar.java.se.constraint.Constraint) ARETURN(org.objectweb.asm.Opcodes.ARETURN) IFLT(org.objectweb.asm.Opcodes.IFLT) IUSHR(org.objectweb.asm.Opcodes.IUSHR) Symbols(org.sonar.java.resolve.Symbols) IF_ACMPEQ(org.objectweb.asm.Opcodes.IF_ACMPEQ) LRETURN(org.objectweb.asm.Opcodes.LRETURN) DivisionByZeroCheck(org.sonar.java.se.checks.DivisionByZeroCheck) ConstraintManager(org.sonar.java.se.constraint.ConstraintManager) ImmutableList(com.google.common.collect.ImmutableList) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) LinkedList(java.util.LinkedList) BytecodeCFG(org.sonar.java.bytecode.cfg.BytecodeCFG) NOP(org.objectweb.asm.Opcodes.NOP) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader) MONITOREXIT(org.objectweb.asm.Opcodes.MONITOREXIT) Type(org.sonar.plugins.java.api.semantic.Type) ISUB(org.objectweb.asm.Opcodes.ISUB) ARRAYLENGTH(org.objectweb.asm.Opcodes.ARRAYLENGTH) DUP_X2(org.objectweb.asm.Opcodes.DUP_X2) DUP_X1(org.objectweb.asm.Opcodes.DUP_X1) AASTORE(org.objectweb.asm.Opcodes.AASTORE) SemanticModel(org.sonar.java.resolve.SemanticModel) BALOAD(org.objectweb.asm.Opcodes.BALOAD) PUTSTATIC(org.objectweb.asm.Opcodes.PUTSTATIC) ProgramPoint(org.sonar.java.se.ProgramPoint) CheckForNull(javax.annotation.CheckForNull) LMUL(org.objectweb.asm.Opcodes.LMUL) INVOKEINTERFACE(org.objectweb.asm.Opcodes.INVOKEINTERFACE) BASTORE(org.objectweb.asm.Opcodes.BASTORE) IF_ICMPNE(org.objectweb.asm.Opcodes.IF_ICMPNE) AALOAD(org.objectweb.asm.Opcodes.AALOAD) BooleanConstraint(org.sonar.java.se.constraint.BooleanConstraint) ExceptionUtils(org.sonar.java.se.ExceptionUtils) FCONST_0(org.objectweb.asm.Opcodes.FCONST_0) FCONST_1(org.objectweb.asm.Opcodes.FCONST_1) FCONST_2(org.objectweb.asm.Opcodes.FCONST_2) DCONST_0(org.objectweb.asm.Opcodes.DCONST_0) SIPUSH(org.objectweb.asm.Opcodes.SIPUSH) Set(java.util.Set) IF_ICMPLT(org.objectweb.asm.Opcodes.IF_ICMPLT) DLOAD(org.objectweb.asm.Opcodes.DLOAD) DUP(org.objectweb.asm.Opcodes.DUP) FCMPG(org.objectweb.asm.Opcodes.FCMPG) LAND(org.objectweb.asm.Opcodes.LAND) FCMPL(org.objectweb.asm.Opcodes.FCMPL) LCONST_0(org.objectweb.asm.Opcodes.LCONST_0) SASTORE(org.objectweb.asm.Opcodes.SASTORE) LALOAD(org.objectweb.asm.Opcodes.LALOAD) DCONST_1(org.objectweb.asm.Opcodes.DCONST_1) LCONST_1(org.objectweb.asm.Opcodes.LCONST_1) IOR(org.objectweb.asm.Opcodes.IOR) ObjectConstraint(org.sonar.java.se.constraint.ObjectConstraint) DSTORE(org.objectweb.asm.Opcodes.DSTORE) CALOAD(org.objectweb.asm.Opcodes.CALOAD) FMUL(org.objectweb.asm.Opcodes.FMUL) LONG_OR_DOUBLE(org.sonar.java.bytecode.se.BytecodeEGWalker.StackValueCategoryConstraint.LONG_OR_DOUBLE) I2B(org.objectweb.asm.Opcodes.I2B) IFNE(org.objectweb.asm.Opcodes.IFNE) IREM(org.objectweb.asm.Opcodes.IREM) I2C(org.objectweb.asm.Opcodes.I2C) I2D(org.objectweb.asm.Opcodes.I2D) SWAP(org.objectweb.asm.Opcodes.SWAP) I2F(org.objectweb.asm.Opcodes.I2F) IADD(org.objectweb.asm.Opcodes.IADD) ISTORE(org.objectweb.asm.Opcodes.ISTORE) Pair(org.sonar.java.se.Pair) LOOKUPSWITCH(org.objectweb.asm.Opcodes.LOOKUPSWITCH) IF_ICMPLE(org.objectweb.asm.Opcodes.IF_ICMPLE) INVOKEDYNAMIC(org.objectweb.asm.Opcodes.INVOKEDYNAMIC) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) Logger(org.sonar.api.utils.log.Logger) IDIV(org.objectweb.asm.Opcodes.IDIV) DREM(org.objectweb.asm.Opcodes.DREM) POP(org.objectweb.asm.Opcodes.POP) SALOAD(org.objectweb.asm.Opcodes.SALOAD) ISHR(org.objectweb.asm.Opcodes.ISHR) NEWARRAY(org.objectweb.asm.Opcodes.NEWARRAY) DADD(org.objectweb.asm.Opcodes.DADD) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) ICONST_M1(org.objectweb.asm.Opcodes.ICONST_M1) ISHL(org.objectweb.asm.Opcodes.ISHL) BehaviorCache(org.sonar.java.se.xproc.BehaviorCache) LNEG(org.objectweb.asm.Opcodes.LNEG) IRETURN(org.objectweb.asm.Opcodes.IRETURN) DDIV(org.objectweb.asm.Opcodes.DDIV) ALOAD(org.objectweb.asm.Opcodes.ALOAD) FALOAD(org.objectweb.asm.Opcodes.FALOAD) GETSTATIC(org.objectweb.asm.Opcodes.GETSTATIC) LSUB(org.objectweb.asm.Opcodes.LSUB) D2F(org.objectweb.asm.Opcodes.D2F) D2I(org.objectweb.asm.Opcodes.D2I) D2L(org.objectweb.asm.Opcodes.D2L) L2D(org.objectweb.asm.Opcodes.L2D) NEW(org.objectweb.asm.Opcodes.NEW) BytecodeCFGMethodVisitor(org.sonar.java.bytecode.cfg.BytecodeCFGMethodVisitor) MULTIANEWARRAY(org.objectweb.asm.Opcodes.MULTIANEWARRAY) FADD(org.objectweb.asm.Opcodes.FADD) BIPUSH(org.objectweb.asm.Opcodes.BIPUSH) IASTORE(org.objectweb.asm.Opcodes.IASTORE) FREM(org.objectweb.asm.Opcodes.FREM) List(java.util.List) FDIV(org.objectweb.asm.Opcodes.FDIV) DRETURN(org.objectweb.asm.Opcodes.DRETURN) LXOR(org.objectweb.asm.Opcodes.LXOR) FASTORE(org.objectweb.asm.Opcodes.FASTORE) IFNONNULL(org.objectweb.asm.Opcodes.IFNONNULL) FSUB(org.objectweb.asm.Opcodes.FSUB) LUSHR(org.objectweb.asm.Opcodes.LUSHR) IF_ACMPNE(org.objectweb.asm.Opcodes.IF_ACMPNE) ProgramState(org.sonar.java.se.ProgramState) Deque(java.util.Deque) IF_ICMPGT(org.objectweb.asm.Opcodes.IF_ICMPGT) ExplodedGraphWalker(org.sonar.java.se.ExplodedGraphWalker) LDC(org.objectweb.asm.Opcodes.LDC) CHECKCAST(org.objectweb.asm.Opcodes.CHECKCAST) DUP2(org.objectweb.asm.Opcodes.DUP2) ExplodedGraph(org.sonar.java.se.ExplodedGraph) L2F(org.objectweb.asm.Opcodes.L2F) ANEWARRAY(org.objectweb.asm.Opcodes.ANEWARRAY) L2I(org.objectweb.asm.Opcodes.L2I) RETURN(org.objectweb.asm.Opcodes.RETURN) ILOAD(org.objectweb.asm.Opcodes.ILOAD) FRETURN(org.objectweb.asm.Opcodes.FRETURN) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) POP2(org.objectweb.asm.Opcodes.POP2) IF_ICMPGE(org.objectweb.asm.Opcodes.IF_ICMPGE) Type(org.sonar.plugins.java.api.semantic.Type) MethodBehavior(org.sonar.java.se.xproc.MethodBehavior) ProgramState(org.sonar.java.se.ProgramState) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) TypedConstraint(org.sonar.java.se.constraint.TypedConstraint) Constraint(org.sonar.java.se.constraint.Constraint) ProgramPoint(org.sonar.java.se.ProgramPoint) BooleanConstraint(org.sonar.java.se.constraint.BooleanConstraint) ObjectConstraint(org.sonar.java.se.constraint.ObjectConstraint)

Example 4 with RETURN

use of org.objectweb.asm.Opcodes.RETURN in project sonar-java by SonarSource.

the class BytecodeEGWalker method enqueueExceptionHandlers.

private void enqueueExceptionHandlers(Type exceptionType, ProgramState ps) {
    List<BytecodeCFG.Block> blocksCatchingException = programPosition.block.successors().stream().map(b -> (BytecodeCFG.Block) b).filter(BytecodeCFG.Block::isCatchBlock).filter(b -> isExceptionHandledByBlock(exceptionType, b)).collect(Collectors.toList());
    if (!blocksCatchingException.isEmpty()) {
        blocksCatchingException.forEach(b -> enqueue(new ProgramPoint(b), ps));
        if (isCatchExhaustive(exceptionType, blocksCatchingException)) {
            return;
        }
    }
    // exception was not handled or was handled only partially, enqueue exit block with exceptional SV
    Preconditions.checkState(ps.peekValue() instanceof SymbolicValue.ExceptionalSymbolicValue, "Exception shall be on top of the stack");
    ps.storeExitValue();
    enqueue(new ProgramPoint(exitBlock), ps);
}
Also used : ASTORE(org.objectweb.asm.Opcodes.ASTORE) ATHROW(org.objectweb.asm.Opcodes.ATHROW) DMUL(org.objectweb.asm.Opcodes.DMUL) F2D(org.objectweb.asm.Opcodes.F2D) LSHR(org.objectweb.asm.Opcodes.LSHR) IF_ICMPEQ(org.objectweb.asm.Opcodes.IF_ICMPEQ) F2I(org.objectweb.asm.Opcodes.F2I) IINC(org.objectweb.asm.Opcodes.IINC) IFGT(org.objectweb.asm.Opcodes.IFGT) LSHL(org.objectweb.asm.Opcodes.LSHL) IAND(org.objectweb.asm.Opcodes.IAND) DCMPL(org.objectweb.asm.Opcodes.DCMPL) LSTORE(org.objectweb.asm.Opcodes.LSTORE) TypedConstraint(org.sonar.java.se.constraint.TypedConstraint) DCMPG(org.objectweb.asm.Opcodes.DCMPG) IFNULL(org.objectweb.asm.Opcodes.IFNULL) FLOAD(org.objectweb.asm.Opcodes.FLOAD) INSTANCEOF(org.objectweb.asm.Opcodes.INSTANCEOF) IALOAD(org.objectweb.asm.Opcodes.IALOAD) DUP2_X2(org.objectweb.asm.Opcodes.DUP2_X2) DUP2_X1(org.objectweb.asm.Opcodes.DUP2_X1) PUTFIELD(org.objectweb.asm.Opcodes.PUTFIELD) IFEQ(org.objectweb.asm.Opcodes.IFEQ) Lists(com.google.common.collect.Lists) INVOKESTATIC(org.objectweb.asm.Opcodes.INVOKESTATIC) ACONST_NULL(org.objectweb.asm.Opcodes.ACONST_NULL) MethodBehavior(org.sonar.java.se.xproc.MethodBehavior) DALOAD(org.objectweb.asm.Opcodes.DALOAD) INEG(org.objectweb.asm.Opcodes.INEG) MONITORENTER(org.objectweb.asm.Opcodes.MONITORENTER) TABLESWITCH(org.objectweb.asm.Opcodes.TABLESWITCH) ICONST_5(org.objectweb.asm.Opcodes.ICONST_5) IMUL(org.objectweb.asm.Opcodes.IMUL) LOR(org.objectweb.asm.Opcodes.LOR) DASTORE(org.objectweb.asm.Opcodes.DASTORE) ICONST_4(org.objectweb.asm.Opcodes.ICONST_4) Opcodes(org.objectweb.asm.Opcodes) ICONST_3(org.objectweb.asm.Opcodes.ICONST_3) ICONST_2(org.objectweb.asm.Opcodes.ICONST_2) IFGE(org.objectweb.asm.Opcodes.IFGE) ICONST_1(org.objectweb.asm.Opcodes.ICONST_1) ICONST_0(org.objectweb.asm.Opcodes.ICONST_0) LADD(org.objectweb.asm.Opcodes.LADD) F2L(org.objectweb.asm.Opcodes.F2L) Printer(org.objectweb.asm.util.Printer) LREM(org.objectweb.asm.Opcodes.LREM) Preconditions(com.google.common.base.Preconditions) INVOKESPECIAL(org.objectweb.asm.Opcodes.INVOKESPECIAL) DNEG(org.objectweb.asm.Opcodes.DNEG) LDIV(org.objectweb.asm.Opcodes.LDIV) LLOAD(org.objectweb.asm.Opcodes.LLOAD) LCMP(org.objectweb.asm.Opcodes.LCMP) IXOR(org.objectweb.asm.Opcodes.IXOR) DSUB(org.objectweb.asm.Opcodes.DSUB) IFLE(org.objectweb.asm.Opcodes.IFLE) Loggers(org.sonar.api.utils.log.Loggers) LASTORE(org.objectweb.asm.Opcodes.LASTORE) FSTORE(org.objectweb.asm.Opcodes.FSTORE) INVOKEVIRTUAL(org.objectweb.asm.Opcodes.INVOKEVIRTUAL) Collectors(java.util.stream.Collectors) GETFIELD(org.objectweb.asm.Opcodes.GETFIELD) FNEG(org.objectweb.asm.Opcodes.FNEG) I2L(org.objectweb.asm.Opcodes.I2L) CASTORE(org.objectweb.asm.Opcodes.CASTORE) Instruction(org.sonar.java.bytecode.cfg.Instruction) GOTO(org.objectweb.asm.Opcodes.GOTO) I2S(org.objectweb.asm.Opcodes.I2S) Constraint(org.sonar.java.se.constraint.Constraint) ARETURN(org.objectweb.asm.Opcodes.ARETURN) IFLT(org.objectweb.asm.Opcodes.IFLT) IUSHR(org.objectweb.asm.Opcodes.IUSHR) Symbols(org.sonar.java.resolve.Symbols) IF_ACMPEQ(org.objectweb.asm.Opcodes.IF_ACMPEQ) LRETURN(org.objectweb.asm.Opcodes.LRETURN) DivisionByZeroCheck(org.sonar.java.se.checks.DivisionByZeroCheck) ConstraintManager(org.sonar.java.se.constraint.ConstraintManager) ImmutableList(com.google.common.collect.ImmutableList) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) LinkedList(java.util.LinkedList) BytecodeCFG(org.sonar.java.bytecode.cfg.BytecodeCFG) NOP(org.objectweb.asm.Opcodes.NOP) SquidClassLoader(org.sonar.java.bytecode.loader.SquidClassLoader) MONITOREXIT(org.objectweb.asm.Opcodes.MONITOREXIT) Type(org.sonar.plugins.java.api.semantic.Type) ISUB(org.objectweb.asm.Opcodes.ISUB) ARRAYLENGTH(org.objectweb.asm.Opcodes.ARRAYLENGTH) DUP_X2(org.objectweb.asm.Opcodes.DUP_X2) DUP_X1(org.objectweb.asm.Opcodes.DUP_X1) AASTORE(org.objectweb.asm.Opcodes.AASTORE) SemanticModel(org.sonar.java.resolve.SemanticModel) BALOAD(org.objectweb.asm.Opcodes.BALOAD) PUTSTATIC(org.objectweb.asm.Opcodes.PUTSTATIC) ProgramPoint(org.sonar.java.se.ProgramPoint) CheckForNull(javax.annotation.CheckForNull) LMUL(org.objectweb.asm.Opcodes.LMUL) INVOKEINTERFACE(org.objectweb.asm.Opcodes.INVOKEINTERFACE) BASTORE(org.objectweb.asm.Opcodes.BASTORE) IF_ICMPNE(org.objectweb.asm.Opcodes.IF_ICMPNE) AALOAD(org.objectweb.asm.Opcodes.AALOAD) BooleanConstraint(org.sonar.java.se.constraint.BooleanConstraint) ExceptionUtils(org.sonar.java.se.ExceptionUtils) FCONST_0(org.objectweb.asm.Opcodes.FCONST_0) FCONST_1(org.objectweb.asm.Opcodes.FCONST_1) FCONST_2(org.objectweb.asm.Opcodes.FCONST_2) DCONST_0(org.objectweb.asm.Opcodes.DCONST_0) SIPUSH(org.objectweb.asm.Opcodes.SIPUSH) Set(java.util.Set) IF_ICMPLT(org.objectweb.asm.Opcodes.IF_ICMPLT) DLOAD(org.objectweb.asm.Opcodes.DLOAD) DUP(org.objectweb.asm.Opcodes.DUP) FCMPG(org.objectweb.asm.Opcodes.FCMPG) LAND(org.objectweb.asm.Opcodes.LAND) FCMPL(org.objectweb.asm.Opcodes.FCMPL) LCONST_0(org.objectweb.asm.Opcodes.LCONST_0) SASTORE(org.objectweb.asm.Opcodes.SASTORE) LALOAD(org.objectweb.asm.Opcodes.LALOAD) DCONST_1(org.objectweb.asm.Opcodes.DCONST_1) LCONST_1(org.objectweb.asm.Opcodes.LCONST_1) IOR(org.objectweb.asm.Opcodes.IOR) ObjectConstraint(org.sonar.java.se.constraint.ObjectConstraint) DSTORE(org.objectweb.asm.Opcodes.DSTORE) CALOAD(org.objectweb.asm.Opcodes.CALOAD) FMUL(org.objectweb.asm.Opcodes.FMUL) LONG_OR_DOUBLE(org.sonar.java.bytecode.se.BytecodeEGWalker.StackValueCategoryConstraint.LONG_OR_DOUBLE) I2B(org.objectweb.asm.Opcodes.I2B) IFNE(org.objectweb.asm.Opcodes.IFNE) IREM(org.objectweb.asm.Opcodes.IREM) I2C(org.objectweb.asm.Opcodes.I2C) I2D(org.objectweb.asm.Opcodes.I2D) SWAP(org.objectweb.asm.Opcodes.SWAP) I2F(org.objectweb.asm.Opcodes.I2F) IADD(org.objectweb.asm.Opcodes.IADD) ISTORE(org.objectweb.asm.Opcodes.ISTORE) Pair(org.sonar.java.se.Pair) LOOKUPSWITCH(org.objectweb.asm.Opcodes.LOOKUPSWITCH) IF_ICMPLE(org.objectweb.asm.Opcodes.IF_ICMPLE) INVOKEDYNAMIC(org.objectweb.asm.Opcodes.INVOKEDYNAMIC) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) Logger(org.sonar.api.utils.log.Logger) IDIV(org.objectweb.asm.Opcodes.IDIV) DREM(org.objectweb.asm.Opcodes.DREM) POP(org.objectweb.asm.Opcodes.POP) SALOAD(org.objectweb.asm.Opcodes.SALOAD) ISHR(org.objectweb.asm.Opcodes.ISHR) NEWARRAY(org.objectweb.asm.Opcodes.NEWARRAY) DADD(org.objectweb.asm.Opcodes.DADD) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) ICONST_M1(org.objectweb.asm.Opcodes.ICONST_M1) ISHL(org.objectweb.asm.Opcodes.ISHL) BehaviorCache(org.sonar.java.se.xproc.BehaviorCache) LNEG(org.objectweb.asm.Opcodes.LNEG) IRETURN(org.objectweb.asm.Opcodes.IRETURN) DDIV(org.objectweb.asm.Opcodes.DDIV) ALOAD(org.objectweb.asm.Opcodes.ALOAD) FALOAD(org.objectweb.asm.Opcodes.FALOAD) GETSTATIC(org.objectweb.asm.Opcodes.GETSTATIC) LSUB(org.objectweb.asm.Opcodes.LSUB) D2F(org.objectweb.asm.Opcodes.D2F) D2I(org.objectweb.asm.Opcodes.D2I) D2L(org.objectweb.asm.Opcodes.D2L) L2D(org.objectweb.asm.Opcodes.L2D) NEW(org.objectweb.asm.Opcodes.NEW) BytecodeCFGMethodVisitor(org.sonar.java.bytecode.cfg.BytecodeCFGMethodVisitor) MULTIANEWARRAY(org.objectweb.asm.Opcodes.MULTIANEWARRAY) FADD(org.objectweb.asm.Opcodes.FADD) BIPUSH(org.objectweb.asm.Opcodes.BIPUSH) IASTORE(org.objectweb.asm.Opcodes.IASTORE) FREM(org.objectweb.asm.Opcodes.FREM) List(java.util.List) FDIV(org.objectweb.asm.Opcodes.FDIV) DRETURN(org.objectweb.asm.Opcodes.DRETURN) LXOR(org.objectweb.asm.Opcodes.LXOR) FASTORE(org.objectweb.asm.Opcodes.FASTORE) IFNONNULL(org.objectweb.asm.Opcodes.IFNONNULL) FSUB(org.objectweb.asm.Opcodes.FSUB) LUSHR(org.objectweb.asm.Opcodes.LUSHR) IF_ACMPNE(org.objectweb.asm.Opcodes.IF_ACMPNE) ProgramState(org.sonar.java.se.ProgramState) Deque(java.util.Deque) IF_ICMPGT(org.objectweb.asm.Opcodes.IF_ICMPGT) ExplodedGraphWalker(org.sonar.java.se.ExplodedGraphWalker) LDC(org.objectweb.asm.Opcodes.LDC) CHECKCAST(org.objectweb.asm.Opcodes.CHECKCAST) DUP2(org.objectweb.asm.Opcodes.DUP2) ExplodedGraph(org.sonar.java.se.ExplodedGraph) L2F(org.objectweb.asm.Opcodes.L2F) ANEWARRAY(org.objectweb.asm.Opcodes.ANEWARRAY) L2I(org.objectweb.asm.Opcodes.L2I) RETURN(org.objectweb.asm.Opcodes.RETURN) ILOAD(org.objectweb.asm.Opcodes.ILOAD) FRETURN(org.objectweb.asm.Opcodes.FRETURN) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) POP2(org.objectweb.asm.Opcodes.POP2) IF_ICMPGE(org.objectweb.asm.Opcodes.IF_ICMPGE) ProgramPoint(org.sonar.java.se.ProgramPoint) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue)

Example 5 with RETURN

use of org.objectweb.asm.Opcodes.RETURN in project groovy by apache.

the class AsmClassGenerator method visitStdMethod.

private void visitStdMethod(final MethodNode node, final boolean isConstructor, final Parameter[] parameters, final Statement code) {
    controller.getCompileStack().init(node.getVariableScope(), parameters);
    controller.getCallSiteWriter().makeSiteEntry();
    MethodVisitor mv = controller.getMethodVisitor();
    if (isConstructor && (code == null || !((ConstructorNode) node).firstStatementIsSpecialConstructorCall())) {
        boolean hasCallToSuper = false;
        if (code != null && controller.getClassNode().getOuterClass() != null) {
            // the call to super is already added so we must ensure not to add it twice
            if (code instanceof BlockStatement) {
                hasCallToSuper = ((BlockStatement) code).getStatements().stream().map(statement -> statement instanceof ExpressionStatement ? ((ExpressionStatement) statement).getExpression() : null).anyMatch(expression -> expression instanceof ConstructorCallExpression && ((ConstructorCallExpression) expression).isSuperCall());
            }
        }
        if (!hasCallToSuper) {
            if (code != null) {
                // GROOVY-9373
                controller.visitLineNumber(code.getLineNumber());
            }
            // add call to "super()"
            mv.visitVarInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKESPECIAL, controller.getInternalBaseClassName(), "<init>", "()V", false);
        }
    }
    if (code != null) {
        code.visit(this);
    }
    if (code == null || maybeFallsThrough(code)) {
        if (code != null) {
            // GROOVY-7647, GROOVY-9373
            controller.visitLineNumber(code.getLastLineNumber());
        }
        if (node.isVoidMethod()) {
            mv.visitInsn(RETURN);
        } else {
            ClassNode type = node.getReturnType();
            if (isPrimitiveType(type)) {
                mv.visitLdcInsn(Integer.valueOf(0));
                OperandStack operandStack = controller.getOperandStack();
                operandStack.push(ClassHelper.int_TYPE);
                operandStack.doGroovyCast(type);
                BytecodeHelper.doReturn(mv, type);
                operandStack.remove(1);
            } else {
                mv.visitInsn(ACONST_NULL);
                BytecodeHelper.doReturn(mv, type);
            }
        }
    }
    controller.getCompileStack().clear();
}
Also used : ASTORE(org.objectweb.asm.Opcodes.ASTORE) ATHROW(org.objectweb.asm.Opcodes.ATHROW) WriterController(org.codehaus.groovy.classgen.asm.WriterController) GeneralUtils.attrX(org.codehaus.groovy.ast.tools.GeneralUtils.attrX) GeneralUtils.classX(org.codehaus.groovy.ast.tools.GeneralUtils.classX) OptimizingStatementWriter(org.codehaus.groovy.classgen.asm.OptimizingStatementWriter) BytecodeHelper(org.codehaus.groovy.classgen.asm.BytecodeHelper) Map(java.util.Map) GeneralUtils.propX(org.codehaus.groovy.ast.tools.GeneralUtils.propX) Sealed(groovy.transform.Sealed) PropertyNode(org.codehaus.groovy.ast.PropertyNode) ACC_VARARGS(org.objectweb.asm.Opcodes.ACC_VARARGS) UnaryMinusExpression(org.codehaus.groovy.ast.expr.UnaryMinusExpression) ClosureListExpression(org.codehaus.groovy.ast.expr.ClosureListExpression) ClassHelper.isPrimitiveLong(org.codehaus.groovy.ast.ClassHelper.isPrimitiveLong) ArgumentListExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression) ClassNodeUtils.getField(org.apache.groovy.ast.tools.ClassNodeUtils.getField) MethodReferenceExpression(org.codehaus.groovy.ast.expr.MethodReferenceExpression) TernaryExpression(org.codehaus.groovy.ast.expr.TernaryExpression) AssertStatement(org.codehaus.groovy.ast.stmt.AssertStatement) T_BYTE(org.objectweb.asm.Opcodes.T_BYTE) SealedASTTransformation.sealedSkipAnnotation(org.codehaus.groovy.transform.SealedASTTransformation.sealedSkipAnnotation) ACC_SYNTHETIC(org.objectweb.asm.Opcodes.ACC_SYNTHETIC) TraceMethodVisitor(org.objectweb.asm.util.TraceMethodVisitor) ClassHelper.isPrimitiveDouble(org.codehaus.groovy.ast.ClassHelper.isPrimitiveDouble) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) ACC_FINAL(org.objectweb.asm.Opcodes.ACC_FINAL) ACC_PRIVATE(org.objectweb.asm.Opcodes.ACC_PRIVATE) InterfaceHelperClassNode(org.codehaus.groovy.ast.InterfaceHelperClassNode) ClassHelper.isPrimitiveShort(org.codehaus.groovy.ast.ClassHelper.isPrimitiveShort) ACC_PROTECTED(org.objectweb.asm.Opcodes.ACC_PROTECTED) T_INT(org.objectweb.asm.Opcodes.T_INT) PUTFIELD(org.objectweb.asm.Opcodes.PUTFIELD) PrefixExpression(org.codehaus.groovy.ast.expr.PrefixExpression) INVOKESTATIC(org.objectweb.asm.Opcodes.INVOKESTATIC) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) ACONST_NULL(org.objectweb.asm.Opcodes.ACONST_NULL) PostfixExpression(org.codehaus.groovy.ast.expr.PostfixExpression) GeneralUtils.maybeFallsThrough(org.codehaus.groovy.ast.tools.GeneralUtils.maybeFallsThrough) Expression(org.codehaus.groovy.ast.expr.Expression) DASTORE(org.objectweb.asm.Opcodes.DASTORE) ICONST_1(org.objectweb.asm.Opcodes.ICONST_1) UnaryPlusExpression(org.codehaus.groovy.ast.expr.UnaryPlusExpression) SourceUnit(org.codehaus.groovy.control.SourceUnit) ICONST_0(org.objectweb.asm.Opcodes.ICONST_0) ClassNode(org.codehaus.groovy.ast.ClassNode) ClassHelper.isStringType(org.codehaus.groovy.ast.ClassHelper.isStringType) BreakStatement(org.codehaus.groovy.ast.stmt.BreakStatement) ClassHelper.isPrimitiveInt(org.codehaus.groovy.ast.ClassHelper.isPrimitiveInt) GenericsType(org.codehaus.groovy.ast.GenericsType) ClassHelper.isPrimitiveBoolean(org.codehaus.groovy.ast.ClassHelper.isPrimitiveBoolean) ReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement) AnnotationConstantExpression(org.codehaus.groovy.ast.expr.AnnotationConstantExpression) BitwiseNegationExpression(org.codehaus.groovy.ast.expr.BitwiseNegationExpression) INVOKESPECIAL(org.objectweb.asm.Opcodes.INVOKESPECIAL) MopWriter(org.codehaus.groovy.classgen.asm.MopWriter) RecordComponentNode(org.codehaus.groovy.ast.RecordComponentNode) MethodVisitor(org.objectweb.asm.MethodVisitor) MapExpression(org.codehaus.groovy.ast.expr.MapExpression) AnnotatedNode(org.codehaus.groovy.ast.AnnotatedNode) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) ModuleNode(org.codehaus.groovy.ast.ModuleNode) TypeReference.newTypeReference(org.objectweb.asm.TypeReference.newTypeReference) LASTORE(org.objectweb.asm.Opcodes.LASTORE) ForStatement(org.codehaus.groovy.ast.stmt.ForStatement) T_SHORT(org.objectweb.asm.Opcodes.T_SHORT) MethodCallerMultiAdapter(org.codehaus.groovy.classgen.asm.MethodCallerMultiAdapter) INVOKEVIRTUAL(org.objectweb.asm.Opcodes.INVOKEVIRTUAL) NotExpression(org.codehaus.groovy.ast.expr.NotExpression) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) GETFIELD(org.objectweb.asm.Opcodes.GETFIELD) Objects(java.util.Objects) IfStatement(org.codehaus.groovy.ast.stmt.IfStatement) FieldExpression(org.codehaus.groovy.ast.expr.FieldExpression) T_LONG(org.objectweb.asm.Opcodes.T_LONG) ClassHelper.isPrimitiveByte(org.codehaus.groovy.ast.ClassHelper.isPrimitiveByte) ExpressionUtils(org.apache.groovy.ast.tools.ExpressionUtils) CASTORE(org.objectweb.asm.Opcodes.CASTORE) GOTO(org.objectweb.asm.Opcodes.GOTO) ARETURN(org.objectweb.asm.Opcodes.ARETURN) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) TypeReference(org.objectweb.asm.TypeReference) SealedASTTransformation.sealedNative(org.codehaus.groovy.transform.SealedASTTransformation.sealedNative) T_DOUBLE(org.objectweb.asm.Opcodes.T_DOUBLE) ThrowStatement(org.codehaus.groovy.ast.stmt.ThrowStatement) EmptyExpression(org.codehaus.groovy.ast.expr.EmptyExpression) LinkedList(java.util.LinkedList) TypeReference.newExceptionReference(org.objectweb.asm.TypeReference.newExceptionReference) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) OperandStack(org.codehaus.groovy.classgen.asm.OperandStack) ClassHelper(org.codehaus.groovy.ast.ClassHelper) SynchronizedStatement(org.codehaus.groovy.ast.stmt.SynchronizedStatement) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) Consumer(java.util.function.Consumer) ASTNode(org.codehaus.groovy.ast.ASTNode) TupleExpression(org.codehaus.groovy.ast.expr.TupleExpression) TypePath(org.objectweb.asm.TypePath) AASTORE(org.objectweb.asm.Opcodes.AASTORE) METHOD_TYPE_PARAMETER_BOUND(org.objectweb.asm.TypeReference.METHOD_TYPE_PARAMETER_BOUND) TryCatchStatement(org.codehaus.groovy.ast.stmt.TryCatchStatement) PUTSTATIC(org.objectweb.asm.Opcodes.PUTSTATIC) MethodPointerExpression(org.codehaus.groovy.ast.expr.MethodPointerExpression) WriterControllerFactory(org.codehaus.groovy.classgen.asm.WriterControllerFactory) ConstructorNode(org.codehaus.groovy.ast.ConstructorNode) MapEntryExpression(org.codehaus.groovy.ast.expr.MapEntryExpression) ClassHelper.isObjectType(org.codehaus.groovy.ast.ClassHelper.isObjectType) Arrays(java.util.Arrays) MethodCaller(org.codehaus.groovy.classgen.asm.MethodCaller) ACC_ENUM(org.objectweb.asm.Opcodes.ACC_ENUM) T_FLOAT(org.objectweb.asm.Opcodes.T_FLOAT) TypeReference.newSuperTypeReference(org.objectweb.asm.TypeReference.newSuperTypeReference) BASTORE(org.objectweb.asm.Opcodes.BASTORE) BytecodeVariable(org.codehaus.groovy.classgen.asm.BytecodeVariable) StringBuilderWriter(org.apache.groovy.io.StringBuilderWriter) CaseStatement(org.codehaus.groovy.ast.stmt.CaseStatement) PrintWriter(java.io.PrintWriter) GroovyRuntimeException(groovy.lang.GroovyRuntimeException) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) PackageNode(org.codehaus.groovy.ast.PackageNode) ExpressionUtils.isThisOrSuper(org.apache.groovy.ast.tools.ExpressionUtils.isThisOrSuper) GeneralUtils.callX(org.codehaus.groovy.ast.tools.GeneralUtils.callX) DUP(org.objectweb.asm.Opcodes.DUP) SASTORE(org.objectweb.asm.Opcodes.SASTORE) CastExpression(org.codehaus.groovy.ast.expr.CastExpression) BooleanExpression(org.codehaus.groovy.ast.expr.BooleanExpression) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) StaticMethodCallExpression(org.codehaus.groovy.ast.expr.StaticMethodCallExpression) TypeReference.newTypeParameterBoundReference(org.objectweb.asm.TypeReference.newTypeParameterBoundReference) LambdaExpression(org.codehaus.groovy.ast.expr.LambdaExpression) GeneralUtils.thisPropX(org.codehaus.groovy.ast.tools.GeneralUtils.thisPropX) ACC_STATIC(org.objectweb.asm.Opcodes.ACC_STATIC) SWAP(org.objectweb.asm.Opcodes.SWAP) WhileStatement(org.codehaus.groovy.ast.stmt.WhileStatement) ArrayList(java.util.ArrayList) MethodNode(org.codehaus.groovy.ast.MethodNode) ClassHelper.isPrimitiveFloat(org.codehaus.groovy.ast.ClassHelper.isPrimitiveFloat) T_BOOLEAN(org.objectweb.asm.Opcodes.T_BOOLEAN) POP(org.objectweb.asm.Opcodes.POP) Parameter(org.codehaus.groovy.ast.Parameter) NEWARRAY(org.objectweb.asm.Opcodes.NEWARRAY) ClassHelper.isClassType(org.codehaus.groovy.ast.ClassHelper.isClassType) ClassHelper.isPrimitiveType(org.codehaus.groovy.ast.ClassHelper.isPrimitiveType) ClassHelper.isPrimitiveChar(org.codehaus.groovy.ast.ClassHelper.isPrimitiveChar) GStringExpression(org.codehaus.groovy.ast.expr.GStringExpression) ALOAD(org.objectweb.asm.Opcodes.ALOAD) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) ACC_SUPER(org.objectweb.asm.Opcodes.ACC_SUPER) TypeReference.newFormalParameterReference(org.objectweb.asm.TypeReference.newFormalParameterReference) GETSTATIC(org.objectweb.asm.Opcodes.GETSTATIC) Type(org.objectweb.asm.Type) RangeExpression(org.codehaus.groovy.ast.expr.RangeExpression) NEW(org.objectweb.asm.Opcodes.NEW) ScriptBytecodeAdapter(org.codehaus.groovy.runtime.ScriptBytecodeAdapter) ClassVisitor(org.objectweb.asm.ClassVisitor) SpreadExpression(org.codehaus.groovy.ast.expr.SpreadExpression) ArrayExpression(org.codehaus.groovy.ast.expr.ArrayExpression) IASTORE(org.objectweb.asm.Opcodes.IASTORE) METHOD_RETURN(org.objectweb.asm.TypeReference.METHOD_RETURN) CatchStatement(org.codehaus.groovy.ast.stmt.CatchStatement) FIELD(org.objectweb.asm.TypeReference.FIELD) GroovyBugError(org.codehaus.groovy.GroovyBugError) List(java.util.List) BinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) ACC_PUBLIC(org.objectweb.asm.Opcodes.ACC_PUBLIC) Modifier(java.lang.reflect.Modifier) FASTORE(org.objectweb.asm.Opcodes.FASTORE) IFNONNULL(org.objectweb.asm.Opcodes.IFNONNULL) Writer(java.io.Writer) Optional(java.util.Optional) CLASS_TYPE_PARAMETER_BOUND(org.objectweb.asm.TypeReference.CLASS_TYPE_PARAMETER_BOUND) Statement(org.codehaus.groovy.ast.stmt.Statement) GeneralUtils.fieldX(org.codehaus.groovy.ast.tools.GeneralUtils.fieldX) FieldVisitor(org.objectweb.asm.FieldVisitor) METHOD_TYPE_PARAMETER(org.objectweb.asm.TypeReference.METHOD_TYPE_PARAMETER) TypeReference.newTypeParameterReference(org.objectweb.asm.TypeReference.newTypeParameterReference) Label(org.objectweb.asm.Label) HashMap(java.util.HashMap) T_CHAR(org.objectweb.asm.Opcodes.T_CHAR) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) DoWhileStatement(org.codehaus.groovy.ast.stmt.DoWhileStatement) ContinueStatement(org.codehaus.groovy.ast.stmt.ContinueStatement) CHECKCAST(org.objectweb.asm.Opcodes.CHECKCAST) SpreadMapExpression(org.codehaus.groovy.ast.expr.SpreadMapExpression) CLASS_TYPE_PARAMETER(org.objectweb.asm.TypeReference.CLASS_TYPE_PARAMETER) Iterator(java.util.Iterator) DUP2(org.objectweb.asm.Opcodes.DUP2) RecordComponentVisitor(org.objectweb.asm.RecordComponentVisitor) PROPERTY_OWNER(org.codehaus.groovy.transform.sc.StaticCompilationMetadataKeys.PROPERTY_OWNER) DeclarationExpression(org.codehaus.groovy.ast.expr.DeclarationExpression) ClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression) SwitchStatement(org.codehaus.groovy.ast.stmt.SwitchStatement) ANEWARRAY(org.objectweb.asm.Opcodes.ANEWARRAY) RETURN(org.objectweb.asm.Opcodes.RETURN) FieldNode(org.codehaus.groovy.ast.FieldNode) AttributeExpression(org.codehaus.groovy.ast.expr.AttributeExpression) V_PREVIEW(org.objectweb.asm.Opcodes.V_PREVIEW) RuntimeParserException(org.codehaus.groovy.syntax.RuntimeParserException) WideningCategories(org.codehaus.groovy.ast.tools.WideningCategories) ILOAD(org.objectweb.asm.Opcodes.ILOAD) Collections(java.util.Collections) OperandStack(org.codehaus.groovy.classgen.asm.OperandStack) InterfaceHelperClassNode(org.codehaus.groovy.ast.InterfaceHelperClassNode) ClassNode(org.codehaus.groovy.ast.ClassNode) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) ConstructorNode(org.codehaus.groovy.ast.ConstructorNode) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) ExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) TraceMethodVisitor(org.objectweb.asm.util.TraceMethodVisitor) MethodVisitor(org.objectweb.asm.MethodVisitor)

Aggregations

ALOAD (org.objectweb.asm.Opcodes.ALOAD)5 ARETURN (org.objectweb.asm.Opcodes.ARETURN)5 CHECKCAST (org.objectweb.asm.Opcodes.CHECKCAST)5 GETFIELD (org.objectweb.asm.Opcodes.GETFIELD)5 GETSTATIC (org.objectweb.asm.Opcodes.GETSTATIC)5 PUTFIELD (org.objectweb.asm.Opcodes.PUTFIELD)5 PUTSTATIC (org.objectweb.asm.Opcodes.PUTSTATIC)5 RETURN (org.objectweb.asm.Opcodes.RETURN)5 Collections (java.util.Collections)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 AASTORE (org.objectweb.asm.Opcodes.AASTORE)4 ACONST_NULL (org.objectweb.asm.Opcodes.ACONST_NULL)4 ANEWARRAY (org.objectweb.asm.Opcodes.ANEWARRAY)4 ASTORE (org.objectweb.asm.Opcodes.ASTORE)4 ATHROW (org.objectweb.asm.Opcodes.ATHROW)4 BASTORE (org.objectweb.asm.Opcodes.BASTORE)4 CASTORE (org.objectweb.asm.Opcodes.CASTORE)4 DASTORE (org.objectweb.asm.Opcodes.DASTORE)4 DUP (org.objectweb.asm.Opcodes.DUP)4