Example usage for org.objectweb.asm Opcodes IFNULL

List of usage examples for org.objectweb.asm Opcodes IFNULL

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes IFNULL.

Prototype

int IFNULL

To view the source code for org.objectweb.asm Opcodes IFNULL.

Click Source Link

Usage

From source file:com.retroduction.carma.transformer.asm.ror.IFNULL_2_IFNONNULL_Transition.java

License:Open Source License

public IFNULL_2_IFNONNULL_Transition() {
    super();
    this.sourceInstruction = Opcodes.IFNULL;
    this.targetInstruction = Opcodes.IFNONNULL;
}

From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java

License:Open Source License

private static void writeDumpMethod(ClassWriter cw, String className, EnvSymbolNames symbolNames) {
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "dump",
            "(Ljava/lang/Appendable;)Ljava/lang/Appendable;", null, new String[] { "java/io/IOException" });
    mv.visitCode();//from   w  ww. ja  v a  2 s  .  co  m
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "within", Type.getType(HasAt.class).getDescriptor());
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.IFNULL, l1);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "within", Type.getType(HasAt.class).getDescriptor());
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(HasAt.class).getInternalName(), "at",
            "()Ljava/lang/String;");
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Appendable", "append",
            "(Ljava/lang/CharSequence;)Ljava/lang/Appendable;");
    mv.visitInsn(Opcodes.POP);
    Label l3 = new Label();
    mv.visitLabel(l3);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitLdcInsn("\n");
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Appendable", "append",
            "(Ljava/lang/CharSequence;)Ljava/lang/Appendable;");
    mv.visitInsn(Opcodes.POP);
    Label l4 = new Label();
    mv.visitJumpInsn(Opcodes.GOTO, l4);
    mv.visitLabel(l1);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitLdcInsn("Not within anything.\n");
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Appendable", "append",
            "(Ljava/lang/CharSequence;)Ljava/lang/Appendable;");
    mv.visitInsn(Opcodes.POP);
    mv.visitLabel(l4);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, className, "verboseDump", "Z");
    Label l5 = new Label();
    mv.visitJumpInsn(Opcodes.IFEQ, l5);
    int linebreaks = dumpFields(mv, className, EnvironmentClass.FVALUE, symbolNames, 0);
    dumpFields(mv, className, EnvironmentClass.FTYPE, symbolNames, linebreaks);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitLdcInsn("\n");
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Appendable", "append",
            "(Ljava/lang/CharSequence;)Ljava/lang/Appendable;");
    mv.visitInsn(Opcodes.POP);
    mv.visitLabel(l5);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitInsn(Opcodes.ARETURN);
    Label l9 = new Label();
    mv.visitLabel(l9);
    mv.visitLocalVariable("this", Naming.internalToDesc(className), null, l0, l9, 0);
    mv.visitLocalVariable("a", "Ljava/lang/Appendable;", null, l0, l9, 1);
    // See comment above on ClassWriter.COMPUTE_FRAMES
    mv.visitMaxs(2, 2);
    mv.visitEnd();
}

From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java

License:Open Source License

private static int dumpFields(MethodVisitor mv, String className, EnvironmentClass eClass,
        EnvSymbolNames symbolNames, int linebreaks) {
    for (String fieldName : symbolNames.getSymbolNames(eClass)) {
        Label l6 = new Label();
        mv.visitLabel(l6);//  www .ja v a 2 s .co  m
        mv.visitVarInsn(Opcodes.ALOAD, 1);
        mv.visitLdcInsn("(" + fieldName + " = ");
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Appendable", "append",
                "(Ljava/lang/CharSequence;)Ljava/lang/Appendable;");
        mv.visitInsn(Opcodes.POP);
        Label l7 = new Label();
        mv.visitLabel(l7);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        String idString = fieldName + eClass.namespace();
        mv.visitFieldInsn(Opcodes.GETFIELD, className, Naming.mangleIdentifier(idString), eClass.descriptor());
        Label l8 = new Label();
        mv.visitJumpInsn(Opcodes.IFNULL, l8);
        Label l9 = new Label();
        mv.visitLabel(l9);
        mv.visitVarInsn(Opcodes.ALOAD, 1);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, className, Naming.mangleIdentifier(idString), eClass.descriptor());
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, eClass.internalName(), "toString", "()Ljava/lang/String;");
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Appendable", "append",
                "(Ljava/lang/CharSequence;)Ljava/lang/Appendable;");
        mv.visitInsn(Opcodes.POP);
        Label afterNull = new Label();
        mv.visitJumpInsn(Opcodes.GOTO, afterNull);
        mv.visitLabel(l8);
        mv.visitVarInsn(Opcodes.ALOAD, 1);
        mv.visitLdcInsn("null");
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Appendable", "append",
                "(Ljava/lang/CharSequence;)Ljava/lang/Appendable;");
        mv.visitInsn(Opcodes.POP);
        mv.visitLabel(afterNull);
        mv.visitVarInsn(Opcodes.ALOAD, 1);
        mv.visitLdcInsn(") ");
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Appendable", "append",
                "(Ljava/lang/CharSequence;)Ljava/lang/Appendable;");
        mv.visitInsn(Opcodes.POP);
        linebreaks = (linebreaks + 1) % 5;
        if (linebreaks == 0) {
            mv.visitVarInsn(Opcodes.ALOAD, 1);
            mv.visitLdcInsn("\n");
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Appendable", "append",
                    "(Ljava/lang/CharSequence;)Ljava/lang/Appendable;");
            mv.visitInsn(Opcodes.POP);
        }
    }

    return linebreaks;
}

From source file:com.trigersoft.jaque.expression.ExpressionMethodVisitor.java

License:Apache License

@Override
public void visitJumpInsn(int opcode, Label label) {
    int etype;/*w w  w . jav  a 2  s  . c om*/
    switch (opcode) {
    case Opcodes.GOTO:

        go(label);

        return;
    default:
    case Opcodes.JSR:
        throw notLambda(opcode);
    case Opcodes.IFEQ:
        etype = ExpressionType.NotEqual; // Equal
        pushZeroConstantOrReduce();
        break;
    case Opcodes.IFNE:
        etype = ExpressionType.Equal; // NotEqual
        pushZeroConstantOrReduce();
        break;
    case Opcodes.IFLT:
        etype = ExpressionType.GreaterThanOrEqual; // LessThan
        pushZeroConstantOrReduce();
        break;
    case Opcodes.IFGE:
        etype = ExpressionType.LessThan; // GreaterThanOrEqual
        pushZeroConstantOrReduce();
        break;
    case Opcodes.IFGT:
        etype = ExpressionType.LessThanOrEqual; // GreaterThan
        pushZeroConstantOrReduce();
        break;
    case Opcodes.IFLE:
        etype = ExpressionType.GreaterThan; // LessThanOrEqual
        pushZeroConstantOrReduce();
        break;
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ACMPEQ: // ??
        etype = ExpressionType.NotEqual; // Equal
        break;
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ACMPNE: // ??
        etype = ExpressionType.Equal; // NotEqual
        break;
    case Opcodes.IF_ICMPLT:
        etype = ExpressionType.GreaterThanOrEqual; // LessThan
        break;
    case Opcodes.IF_ICMPGE:
        etype = ExpressionType.LessThan; // GreaterThanOrEqual
        break;
    case Opcodes.IF_ICMPGT:
        etype = ExpressionType.LessThanOrEqual; // GreaterThan
        break;
    case Opcodes.IF_ICMPLE:
        etype = ExpressionType.GreaterThan; // LessThanOrEqual
        break;
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        Expression e = Expression.isNull(_exprStack.pop());
        if (opcode == Opcodes.IFNULL) // IFNONNULL
            e = Expression.logicalNot(e);

        branch(label, e);

        return;
    }

    Expression second = _exprStack.pop();
    Expression first = _exprStack.pop();
    Expression e = Expression.binary(etype, first, second);

    branch(label, e);
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.ArrayTypeWidget.java

@Override
public ComparisonAdapter getComparisionAdapter() {
    return new ComparisonAdapter() {
        @Override/*ww w  .  j av  a2 s . c  o  m*/
        public void coerceBoolean(CodeEmitter scope, Label isTrue, Label isFalse, Label isNull) {
            // null or true
            if (isNullable()) {
                scope.getMethodVisitor().visitJumpInsn(Opcodes.IFNULL, isNull);
            } else {
                scope.pop(ArrayTypeWidget.this);
            }
            scope.getMethodVisitor().visitJumpInsn(Opcodes.GOTO, isTrue);
        }
    };
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExpressionHandler.java

@Override
public BytecodeExpression isNull(Location location, final BytecodeExpression input) {
    return new BaseTypeExpression(BaseTypeAdapter.BOOLEAN) {
        @Override// ww  w . ja  v  a 2 s  .  co m
        public void generate(CodeEmitter code) {
            MethodVisitor mv = code.getMethodVisitor();
            code.exec(input);
            // it's surprising to not evaluate even if we know input isn't nullable
            if (input.getType().isPrimitive()) {
                code.pop(input.getType());
                code.emitBooleanConstant(false);
            } else {
                Label done = new Label();
                Label isNull = new Label();
                mv.visitJumpInsn(Opcodes.IFNULL, isNull);
                code.emitBooleanConstant(false);
                mv.visitJumpInsn(Opcodes.GOTO, done);
                mv.visitLabel(isNull);
                code.emitBooleanConstant(true);
                mv.visitLabel(done);
            }
        }
    };
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java

public Unification unifyAs(TypeWidget typeWidget, BytecodeExpression left, BytecodeExpression right,
        Label leftNull, Label rightNull, Label bothNull) {
    left.generate(this);
    boolean distinct = (leftNull != bothNull) && right.getType().isNullable();
    Label leftIsNull = distinct ? new Label() : leftNull;
    boolean nullpossible = cast(typeWidget, left.getType(), leftIsNull);
    if (nullpossible && distinct) {
        Label skip = new Label();
        methodVisitor.visitJumpInsn(Opcodes.GOTO, skip);
        methodVisitor.visitLabel(leftIsNull);
        right.generate(this);
        methodVisitor.visitJumpInsn(Opcodes.IFNULL, bothNull);
        methodVisitor.visitJumpInsn(Opcodes.GOTO, leftNull);
        methodVisitor.visitLabel(skip);/*from  w  ww  . ja  v  a 2s  .  c  o  m*/
    }
    Label pop = new Label();
    right.generate(this);
    if (cast(typeWidget, right.getType(), pop)) {
        Label done = new Label();
        nullpossible = true;
        methodVisitor.visitJumpInsn(Opcodes.GOTO, done);
        methodVisitor.visitLabel(pop);
        // pop the left-value
        pop(typeWidget);
        methodVisitor.visitJumpInsn(Opcodes.GOTO, rightNull);
        methodVisitor.visitLabel(done);
    }
    return new Unification(typeWidget, nullpossible);
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java

public BinaryCoercion binaryCoercion(BytecodeExpression left, Class<?> leftClazz, BytecodeExpression right,
        Class<?> rightClazz, Label leftNull, Label rightNull, Label bothNull) {
    TypeWidget leftTarget = adapt(leftClazz);
    TypeWidget rightTarget = adapt(rightClazz);
    left.generate(this);
    boolean distinct = (leftNull != bothNull) && right.getType().isNullable();
    Label leftIsNull = distinct ? new Label() : leftNull;
    boolean leftMaybeNull = cast(leftTarget, left.getType(), leftIsNull);
    if (leftMaybeNull && distinct) {
        Label skip = new Label();
        methodVisitor.visitJumpInsn(Opcodes.GOTO, skip);
        methodVisitor.visitLabel(leftIsNull);
        right.generate(this);
        methodVisitor.visitJumpInsn(Opcodes.IFNULL, bothNull);
        methodVisitor.visitJumpInsn(Opcodes.GOTO, leftNull);
        methodVisitor.visitLabel(skip);/*from   w  w w .  j  a  v  a2  s . c o m*/
    }
    Label pop = new Label();
    right.generate(this);
    boolean rightMaybeNull = false;
    if (cast(rightTarget, right.getType(), pop)) {
        Label done = new Label();
        rightMaybeNull = true;
        methodVisitor.visitJumpInsn(Opcodes.GOTO, done);
        methodVisitor.visitLabel(pop);
        // pop the left-value
        pop(leftTarget);
        methodVisitor.visitJumpInsn(Opcodes.GOTO, rightNull);
        methodVisitor.visitLabel(done);
    }
    return new BinaryCoercion(leftMaybeNull, rightMaybeNull);
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.CodeEmitter.java

public boolean gotoIfNull(BytecodeExpression expr, Label isNull) {
    if (expr.getType().isNullable()) {
        exec(expr);// w  w w . j a  va 2s  .  c o m
        methodVisitor.visitJumpInsn(Opcodes.IFNULL, isNull);
        return true;
    }
    return false;
}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.BaseTypeWidget.java

@Override
public ComparisonAdapter getComparisionAdapter() {
    Preconditions.checkState(!isPrimitive(), "BaseTypeWidget should not be handling a primitive type");
    return new ComparisonAdapter() {
        @Override/*from   w w  w  .j av  a 2  s. c o m*/
        public void coerceBoolean(CodeEmitter scope, Label isTrue, Label isFalse, Label isNull) {
            // null or true
            if (isNullable()) {
                scope.getMethodVisitor().visitJumpInsn(Opcodes.IFNULL, isNull);
            } else {
                scope.pop(BaseTypeWidget.this);
            }
            scope.getMethodVisitor().visitJumpInsn(Opcodes.GOTO, isTrue);
        }
    };
}