Example usage for org.objectweb.asm Opcodes IF_ICMPLT

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

Introduction

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

Prototype

int IF_ICMPLT

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

Click Source Link

Usage

From source file:com.nginious.http.xsp.expr.SubstrFunction.java

License:Apache License

/**
 * Creates bytecode for evaluating this substring function. The specified method visitor
 * and type are used for generating bytecode.
 * /*from   www .  j  a  v  a2 s. c  o  m*/
 * @param visitor the method visitor
 * @param type the type
 */
void compile(MethodVisitor visitor, Type type) {
    value.compile(visitor, Type.STRING);
    visitor.visitVarInsn(Opcodes.ASTORE, 1);
    value2.compile(visitor, Type.INT);
    visitor.visitVarInsn(Opcodes.ISTORE, 2);
    value3.compile(visitor, Type.INT);
    visitor.visitVarInsn(Opcodes.ISTORE, 3);

    Label nullLabel = new Label();
    Label notNullLabel = new Label();

    // check for null string
    visitor.visitVarInsn(Opcodes.ALOAD, 1);
    visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel);

    // start < 0
    Label label1 = new Label();
    visitor.visitLdcInsn(0);
    visitor.visitVarInsn(Opcodes.ILOAD, 2);
    visitor.visitJumpInsn(Opcodes.IF_ICMPLT, label1);
    visitor.visitLdcInsn(0);
    visitor.visitVarInsn(Opcodes.ISTORE, 2);

    // start > value.length
    Label label2 = new Label();
    visitor.visitLabel(label1);
    visitor.visitVarInsn(Opcodes.ALOAD, 1);
    visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "length", "()I");
    visitor.visitVarInsn(Opcodes.ILOAD, 2);
    visitor.visitJumpInsn(Opcodes.IF_ICMPGT, label2);
    visitor.visitVarInsn(Opcodes.ALOAD, 1);
    visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "length", "()I");
    visitor.visitVarInsn(Opcodes.ISTORE, 2);

    // end < start
    Label label3 = new Label();
    visitor.visitLabel(label2);
    visitor.visitVarInsn(Opcodes.ILOAD, 2);
    visitor.visitVarInsn(Opcodes.ILOAD, 3);
    visitor.visitJumpInsn(Opcodes.IF_ICMPLT, label3);
    visitor.visitVarInsn(Opcodes.ILOAD, 2);
    visitor.visitVarInsn(Opcodes.ISTORE, 3);

    // end > value1.length
    Label label4 = new Label();
    visitor.visitLabel(label3);
    visitor.visitVarInsn(Opcodes.ALOAD, 1);
    visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "length", "()I");
    visitor.visitVarInsn(Opcodes.ILOAD, 3);
    visitor.visitJumpInsn(Opcodes.IF_ICMPGT, label4);
    visitor.visitVarInsn(Opcodes.ALOAD, 1);
    visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "length", "()I");
    visitor.visitVarInsn(Opcodes.ISTORE, 3);

    // substr
    visitor.visitLabel(label4);
    visitor.visitVarInsn(Opcodes.ALOAD, 1);
    visitor.visitVarInsn(Opcodes.ILOAD, 2);
    visitor.visitVarInsn(Opcodes.ILOAD, 3);
    visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "substring", "(II)Ljava/lang/String;");
    visitor.visitJumpInsn(Opcodes.GOTO, notNullLabel);

    visitor.visitLabel(nullLabel);
    visitor.visitInsn(Opcodes.ACONST_NULL);

    visitor.visitLabel(notNullLabel);

}

From source file:com.nginious.http.xsp.ForEachTagPart.java

License:Apache License

/**
 * Creates bytecode in a separate method for evaluating this for each tag part.
 * /* w  w  w.j ava  2 s  . c  o m*/
 * @param intClassName the binary class name of the class being created
 * @param writer the class writer
 * @throws XspException if unable to create bytecode
 */
void compileMethod(String intClassName, ClassWriter writer) throws XspException {
    String[] exceptions = { "com/nginious/http/xsp/XspException" };
    MethodVisitor visitor = writer.visitMethod(Opcodes.ACC_PRIVATE, this.methodName,
            "(Lcom/nginious/http/HttpRequest;Lcom/nginious/http/HttpResponse;Ljava/lang/StringBuffer;)V", null,
            exceptions);
    visitor.visitCode();

    Label tryLabel = new Label();
    Label startCatchLabel = new Label();

    // Start try block
    visitor.visitTryCatchBlock(tryLabel, startCatchLabel, startCatchLabel, "java/lang/Exception");
    visitor.visitLabel(tryLabel);

    try {
        String expression = setValue.getExpressionContent();
        ExpressionParser parser = new ExpressionParser();
        TreeExpression expr = parser.parse(expression);

        if (expr.getType() != Type.ANY) {
            throw new XspException("Expression in attribute set in tag " + getName()
                    + " is not an attribute or bean property " + " at line " + getLocationDescriptor());
        }

        expr.compile(visitor, Type.ANY);
        visitor.visitTypeInsn(Opcodes.CHECKCAST, "java/util/Collection");
        visitor.visitVarInsn(Opcodes.ASTORE, 4);
    } catch (ExpressionException e) {
        throw new XspException("Invalid expression in attribute set in tag " + getName() + " at line "
                + getLocationDescriptor(), e);
    }

    Label labelOut = new Label();
    visitor.visitVarInsn(Opcodes.ALOAD, 4);
    visitor.visitJumpInsn(Opcodes.IFNULL, labelOut);

    // Start
    if (this.start != null) {
        start.compile(visitor, Type.INT);
    } else {
        visitor.visitLdcInsn((int) 0);
    }

    visitor.visitVarInsn(Opcodes.ISTORE, 5);

    // End
    if (this.end != null) {
        end.compile(visitor, Type.INT);
    } else {
        visitor.visitVarInsn(Opcodes.ALOAD, 4);
        visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Collection", "size", "()I");
    }

    visitor.visitVarInsn(Opcodes.ISTORE, 6);

    // Step
    if (this.step != null) {
        step.compile(visitor, Type.INT);
    } else {
        visitor.visitLdcInsn((int) 1);
    }

    visitor.visitVarInsn(Opcodes.ISTORE, 7);

    // Current pos
    visitor.visitLdcInsn(0);
    visitor.visitVarInsn(Opcodes.ISTORE, 8);

    visitor.visitVarInsn(Opcodes.ALOAD, 4);
    visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Collection", "iterator",
            "()Ljava/util/Iterator;");
    visitor.visitVarInsn(Opcodes.ASTORE, 9);

    Label labelStart = new Label();

    // Start of loop
    visitor.visitLabel(labelStart);

    // iterator.hasNext();
    visitor.visitVarInsn(Opcodes.ALOAD, 9);
    visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z");
    visitor.visitJumpInsn(Opcodes.IFEQ, labelOut);

    // iterator.next();
    visitor.visitVarInsn(Opcodes.ALOAD, 9);
    visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;");
    visitor.visitVarInsn(Opcodes.ASTORE, 10);

    // pos >= start && pos <= end && (pos - start) % step == 0
    Label labelIncr = new Label();

    visitor.visitVarInsn(Opcodes.ILOAD, 8);
    visitor.visitVarInsn(Opcodes.ILOAD, 5);
    visitor.visitJumpInsn(Opcodes.IF_ICMPLT, labelIncr);

    visitor.visitVarInsn(Opcodes.ILOAD, 8);
    visitor.visitVarInsn(Opcodes.ILOAD, 6);
    visitor.visitJumpInsn(Opcodes.IF_ICMPGT, labelIncr);

    visitor.visitVarInsn(Opcodes.ILOAD, 8);
    visitor.visitVarInsn(Opcodes.ILOAD, 5);
    visitor.visitInsn(Opcodes.ISUB);
    visitor.visitVarInsn(Opcodes.ILOAD, 7);
    visitor.visitInsn(Opcodes.IREM);
    visitor.visitJumpInsn(Opcodes.IFNE, labelIncr);

    visitor.visitVarInsn(Opcodes.ALOAD, 1);
    varName.compile(visitor, Type.STRING);
    visitor.visitVarInsn(Opcodes.ALOAD, 10);
    visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, "com/nginious/http/HttpRequest", "setAttribute",
            "(Ljava/lang/String;Ljava/lang/Object;)V");

    // Call sub parts
    for (XspPart part : this.contentParts) {
        part.compile(intClassName, writer, visitor);
    }

    // pos++
    visitor.visitLabel(labelIncr);
    visitor.visitIincInsn(8, 1);
    visitor.visitJumpInsn(Opcodes.GOTO, labelStart);

    visitor.visitLabel(labelOut);
    visitor.visitInsn(Opcodes.RETURN);

    visitor.visitLabel(startCatchLabel);

    visitor.visitVarInsn(Opcodes.ASTORE, 3);
    visitor.visitTypeInsn(Opcodes.NEW, "com/nginious/http/xsp/XspException");
    visitor.visitInsn(Opcodes.DUP);
    visitor.visitLdcInsn("Attribute set contains an invalid collection for tag " + getName() + " at "
            + getLocationDescriptor());
    visitor.visitVarInsn(Opcodes.ALOAD, 3);
    visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/nginious/http/xsp/XspException", "<init>",
            "(Ljava/lang/String;Ljava/lang/Throwable;)V");
    visitor.visitInsn(Opcodes.ATHROW);

    visitor.visitMaxs(11, 11);
    visitor.visitEnd();
}

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

License:Open Source License

public IF_ICMPGE_2_IF_ICMPLT_Transition() {
    super();
    this.sourceInstruction = Opcodes.IF_ICMPGE;
    this.targetInstruction = Opcodes.IF_ICMPLT;
}

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

License:Open Source License

public IF_ICMPLT_2_IF_ICMPGE_Transition() {
    super();
    this.sourceInstruction = Opcodes.IF_ICMPLT;
    this.targetInstruction = Opcodes.IF_ICMPGE;
}

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 .  j  a  va  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:de.codesourcery.asm.util.ASMUtil.java

License:Apache License

/**
 * Check whether an instruction is a conditional branch operation.
 *  //from  w  w w.j a  v a 2 s. c o  m
 * @param node
 * @return
 */
public static boolean isConditionalJump(AbstractInsnNode node) {
    if (node.getType() == AbstractInsnNode.JUMP_INSN) {
        switch (node.getOpcode()) {
        case Opcodes.IFEQ:
        case Opcodes.IFNE:
        case Opcodes.IFLT:
        case Opcodes.IFGE:
        case Opcodes.IFGT:
        case Opcodes.IFLE:
        case Opcodes.IF_ICMPEQ:
        case Opcodes.IF_ICMPNE:
        case Opcodes.IF_ICMPLT:
        case Opcodes.IF_ICMPGE:
        case Opcodes.IF_ICMPGT:
        case Opcodes.IF_ICMPLE:
        case Opcodes.IF_ACMPEQ:
        case Opcodes.IF_ACMPNE:
        case Opcodes.IFNULL:
        case Opcodes.IFNONNULL:
            return true;
        }
    }
    return false;
}

From source file:de.kandid.model.Emitter.java

License:Apache License

/**
 * Assembles a class that implements the given interface by generating the byte code.
 * @param interfaze the interface to implement
 * @return the class//from   w  w w .j  a v a2s  .  co m
 */
private static Class<? extends Emitter<?>> makeClass(Class<?> interfaze) {
    String nameClass = _nameEmitter + '$' + interfaze.getName().replace('.', '$');
    String nameInterface = Type.getInternalName(interfaze);
    // ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_4, ACC_PUBLIC + ACC_SUPER, nameClass, null, _nameEmitter, new String[] { name(interfaze) });

    // Generate default construcotor
    MethodVisitor cv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    cv.visitVarInsn(ALOAD, 0);
    cv.visitMethodInsn(INVOKESPECIAL, _nameEmitter, "<init>", "()V");
    cv.visitInsn(RETURN);
    cv.visitMaxs(1, 1);

    // Generate methods
    Method[] methods = interfaze.getMethods();
    for (int i = 0; i < methods.length; ++i) {
        final Method m = methods[i];
        if (m.getReturnType() != void.class)
            throw new IllegalArgumentException("Method " + m.toGenericString() + " must not return a value");
        final String descMethod = Type.getMethodDescriptor(m);
        final MethodVisitor mw = cw.visitMethod(ACC_PUBLIC + ACC_SYNCHRONIZED, m.getName(), descMethod, null,
                null);
        final Type[] argTypes = Type.getArgumentTypes(m);

        // for (int i = 0; i < _end; i += 2)
        //    ((Listener) _listeners[i]).send(...);

        int localStart = 1; // give one for "this"
        for (Type at : argTypes)
            localStart += at.getSize();
        Label entry = new Label();
        Label exit = new Label();
        mw.visitLabel(entry);

        // _isFiring = true;
        mw.visitVarInsn(ALOAD, 0);
        mw.visitInsn(Opcodes.ICONST_1);
        mw.visitFieldInsn(Opcodes.PUTFIELD, nameClass, "_isFiring", Type.BOOLEAN_TYPE.getDescriptor());

        // setup local variables: i, _listeners, _end
        mw.visitLocalVariable("i", Type.INT_TYPE.getDescriptor(), null, entry, exit, localStart);
        mw.visitInsn(Opcodes.ICONST_0);
        mw.visitIntInsn(Opcodes.ISTORE, localStart);

        mw.visitLocalVariable("listeners", _descObjectArray, null, entry, exit, localStart + 1);
        mw.visitVarInsn(ALOAD, 0);
        mw.visitFieldInsn(GETFIELD, nameClass, "_listeners", _descObjectArray);
        mw.visitIntInsn(Opcodes.ASTORE, localStart + 1);

        mw.visitLocalVariable("end", Type.INT_TYPE.getDescriptor(), null, entry, exit, localStart + 2);
        mw.visitVarInsn(ALOAD, 0);
        mw.visitFieldInsn(GETFIELD, nameClass, "_end", Type.INT_TYPE.getDescriptor());
        mw.visitIntInsn(Opcodes.ISTORE, localStart + 2);

        final Label condition = new Label();
        mw.visitJumpInsn(GOTO, condition);

        final Label loop = new Label();
        mw.visitLabel(loop);

        //((Listener) _listeners[i]).doSomething()
        mw.visitIntInsn(Opcodes.ALOAD, localStart + 1);
        mw.visitIntInsn(Opcodes.ILOAD, localStart);
        mw.visitInsn(Opcodes.AALOAD);
        mw.visitTypeInsn(CHECKCAST, nameInterface);
        int offs = 1; // give one for "this"
        for (Type at : argTypes) {
            mw.visitVarInsn(at.getOpcode(ILOAD), offs);
            offs += at.getSize();
        }
        mw.visitMethodInsn(INVOKEINTERFACE, nameInterface, m.getName(), descMethod);

        // i += 2
        mw.visitIincInsn(localStart, 2);

        // if (i < end) goto loop
        mw.visitLabel(condition);
        mw.visitIntInsn(Opcodes.ILOAD, localStart);
        mw.visitIntInsn(Opcodes.ILOAD, localStart + 2);
        mw.visitJumpInsn(Opcodes.IF_ICMPLT, loop);

        // _isFiring = false;
        mw.visitVarInsn(ALOAD, 0);
        mw.visitInsn(Opcodes.ICONST_0);
        mw.visitFieldInsn(Opcodes.PUTFIELD, nameClass, "_isFiring", Type.BOOLEAN_TYPE.getDescriptor());

        mw.visitLabel(exit);
        mw.visitInsn(RETURN);
        mw.visitMaxs(localStart + 2, localStart + 3);
        mw.visitEnd();
    }
    cw.visitEnd();
    return _loader.loadClass(cw, nameClass.replace('/', '.'));
}

From source file:de.scoopgmbh.copper.instrument.BuildStackInfoAdapter.java

License:Apache License

@Override
public void visitJumpInsn(int arg0, Label arg1) {
    savePreviousFrame();//from ww  w.j a  va  2  s  .c  o m
    switch (arg0) {
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPNE:
        currentFrame.popStack();
    case Opcodes.IFEQ:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
    case Opcodes.IFLT:
    case Opcodes.IFNE:
    case Opcodes.IFNONNULL:
    case Opcodes.IFNULL:
        currentFrame.popStack();
    case Opcodes.GOTO:
        forwardFrames.put(arg1, new StackInfo(currentFrame));
        break;
    case Opcodes.JSR:
        currentFrame.pushStack(retAddressType);
        forwardFrames.put(arg1, new StackInfo(currentFrame));
        break;
    default:
        logger.debug("Unhandled: ");
    }
    if (logger.isDebugEnabled())
        logger.debug("jumpInsn " + getOpCode(arg0) + " " + arg1);
    delegate.visitJumpInsn(arg0, arg1);
}

From source file:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInliner.java

License:Open Source License

private boolean evalTwoOpValue(final Number op1, final Number op2, final int opcode) {
    switch (opcode) {
    case Opcodes.IF_ICMPEQ:
        return op1.intValue() == op2.intValue();
    case Opcodes.IF_ICMPNE:
        return op1.intValue() != op2.intValue();
    case Opcodes.IF_ICMPLT:
        return op1.intValue() < op2.intValue();
    case Opcodes.IF_ICMPGE:
        return op1.intValue() >= op2.intValue();
    case Opcodes.IF_ICMPGT:
        return op1.intValue() > op2.intValue();
    case Opcodes.IF_ICMPLE:
        return op1.intValue() <= op2.intValue();
    case Opcodes.IF_ACMPEQ:
        return op1 == op2;
    case Opcodes.IF_ACMPNE:
        return op1 != op2;
    default:/*from ww  w .j a v  a 2  s  . co m*/
        return false;
    }
}

From source file:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInlinerTest.java

License:Open Source License

/**
 * Tests that constantIfInliner is working correctly.
 * //from   www.  j  a va2s.c o  m
 * Input is
 * 
 * <pre>
 * if(2>=1)
 * ...
 * </pre>
 * 
 * @throws JBOPClassException
 *           the jBOP class exception
 */

@Test
public void testConstantIfInlinerIF_ICMPLT() throws JBOPClassException {
    // INIT
    final LabelNode label = new LabelNode();
    builder.addInsn(new InsnNode(Opcodes.ICONST_2)).//
            addInsn(new InsnNode(Opcodes.ICONST_1)).//
            addInsn(new JumpInsnNode(Opcodes.IF_ICMPLT, label)).//
            addInsn(new InsnNode(Opcodes.NOP)).//
            addInsn(label).//
            addInsn(new InsnNode(Opcodes.RETURN));

    // RUN
    assertEquals(6, method.instructions.size());
    final InsnList optimized = constantIfInliner.optimize(method.instructions, method);

    // ASSERT
    assertEquals(3, optimized.size());
    assertEquals(Opcodes.NOP, optimized.get(0).getOpcode());
}