List of usage examples for org.objectweb.asm Opcodes GOTO
int GOTO
To view the source code for org.objectweb.asm Opcodes GOTO.
Click Source Link
From source file:com.nginious.http.xsp.expr.MoreOperator.java
License:Apache License
/** * Creates bytecode for evaluating the argument values as doubles. The bytecode * is generated using the specified method visitor. * /*from w w w .java 2 s . c o m*/ * @param visitor the method visitor */ private void compileDouble(MethodVisitor visitor) { Label labelFalse = new Label(); Label labelEnd = new Label(); value1.compile(visitor, Type.DOUBLE); value2.compile(visitor, Type.DOUBLE); visitor.visitInsn(Opcodes.DCMPL); visitor.visitJumpInsn(Opcodes.IFLE, labelFalse); // True visitor.visitLdcInsn(true); visitor.visitJumpInsn(Opcodes.GOTO, labelEnd); // False visitor.visitLabel(labelFalse); visitor.visitLdcInsn(false); visitor.visitLabel(labelEnd); }
From source file:com.nginious.http.xsp.expr.NotEqualsOperator.java
License:Apache License
/** * Compiles bytecode for evaluating this not equals operator producing * a string as result. The specified method visitor is used for generating * bytecode.//from ww w. j av a 2 s .co m * * @param visitor the method visitor */ private void compileString(MethodVisitor visitor) { Label trueLabel = new Label(); Label falseLabel = new Label(); Label nullLabel = new Label(); value1.compile(visitor, Type.STRING); visitor.visitVarInsn(Opcodes.ASTORE, 1); value2.compile(visitor, Type.STRING); visitor.visitVarInsn(Opcodes.ASTORE, 2); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel); visitor.visitVarInsn(Opcodes.ALOAD, 2); visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitVarInsn(Opcodes.ALOAD, 2); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z"); visitor.visitJumpInsn(Opcodes.IFNE, falseLabel); visitor.visitLabel(nullLabel); visitor.visitLdcInsn(true); visitor.visitJumpInsn(Opcodes.GOTO, trueLabel); visitor.visitLabel(falseLabel); visitor.visitLdcInsn(false); visitor.visitLabel(trueLabel); }
From source file:com.nginious.http.xsp.expr.NotEqualsOperator.java
License:Apache License
/** * Compiles bytecode for evaluating this not equals operator producing * an integer as result. The specified method visitor is used for generating * bytecode.//www. j a va2 s . c o m * * @param visitor the method visitor */ private void compileInt(MethodVisitor visitor) { Label trueLabel = new Label(); Label falseLabel = new Label(); value1.compile(visitor, Type.INT); value2.compile(visitor, Type.INT); visitor.visitJumpInsn(Opcodes.IF_ICMPEQ, trueLabel); visitor.visitLdcInsn(true); visitor.visitJumpInsn(Opcodes.GOTO, falseLabel); visitor.visitLabel(trueLabel); visitor.visitLdcInsn(false); visitor.visitLabel(falseLabel); }
From source file:com.nginious.http.xsp.expr.NotEqualsOperator.java
License:Apache License
/** * Compiles bytecode for evaluating this not equals operator producing * a double as result. The specified method visitor is used for generating * bytecode.//from w w w . j a va 2 s . c o m * * @param visitor the method visitor */ private void compileDouble(MethodVisitor visitor) { Label trueLabel = new Label(); Label falseLabel = new Label(); value1.compile(visitor, Type.DOUBLE); value2.compile(visitor, Type.DOUBLE); visitor.visitInsn(Opcodes.DCMPL); visitor.visitJumpInsn(Opcodes.IFEQ, trueLabel); visitor.visitLdcInsn(true); visitor.visitJumpInsn(Opcodes.GOTO, falseLabel); visitor.visitLabel(trueLabel); visitor.visitLdcInsn(false); visitor.visitLabel(falseLabel); }
From source file:com.nginious.http.xsp.expr.OrOperator.java
License:Apache License
/** * Creates bytecode for evaluating this or operator. The bytecode is generated using * the specified method visitor. The result of the evaluation produces the specified * type./* w w w .j a v a 2 s .co m*/ * * @param visitor the method visitor * @param type the type */ void compile(MethodVisitor visitor, Type type) { Label labelTrue = new Label(); Label labelEnd = new Label(); // Test first value value1.compile(visitor, type); visitor.visitInsn(Opcodes.ICONST_1); visitor.visitJumpInsn(Opcodes.IF_ICMPEQ, labelTrue); // Test second value value2.compile(visitor, type); visitor.visitInsn(Opcodes.ICONST_1); visitor.visitJumpInsn(Opcodes.IF_ICMPEQ, labelTrue); // False visitor.visitLdcInsn(false); visitor.visitJumpInsn(Opcodes.GOTO, labelEnd); // True visitor.visitLabel(labelTrue); visitor.visitLdcInsn(true); visitor.visitLabel(labelEnd); }
From source file:com.nginious.http.xsp.expr.RightFunction.java
License:Apache License
/** * Creates bytecode for evaluating this right function. The specified method visitor * and type are used for generating bytecode. * //w w w . ja va 2s . co 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); Label nullLabel = new Label(); Label notNullLabel = new Label(); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitVarInsn(Opcodes.ALOAD, 1); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "length", "()I"); value2.compile(visitor, Type.INT); visitor.visitInsn(Opcodes.ISUB); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "substring", "(I)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.expr.SubstrFunction.java
License:Apache License
/** * Creates bytecode for evaluating this substring function. The specified method visitor * and type are used for generating bytecode. * /*w w w . j a v a 2 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. * /*from w w w . j a v a 2s .c om*/ * @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.offbynull.coroutines.instrumenter.asm.InstructionUtils.java
License:Open Source License
/** * Generates instructions for an unconditional jump to a label. * @param labelNode label to jump to//from w ww . j av a 2s .c om * @throws NullPointerException if any argument is {@code null} * @return instructions for an unconditional jump to {@code labelNode} */ public static InsnList jumpTo(LabelNode labelNode) { Validate.notNull(labelNode); InsnList ret = new InsnList(); ret.add(new JumpInsnNode(Opcodes.GOTO, labelNode)); return ret; }
From source file:com.offbynull.coroutines.instrumenter.asm.InstructionUtils.java
License:Open Source License
/** * For each element in an object array, performs an action. * @param counterVar parameter used to keep track of count in loop * @param arrayLenVar parameter used to keep track of array length * @param array object array instruction list -- must leave an array on top of the stack * @param action action to perform on each element -- element will be at top of stack and must be consumed by these instructions * @return instructions instruction list to perform some action if two ints are equal * @throws NullPointerException if any argument is {@code null} *///from w w w . j a va 2 s. c o m public static InsnList forEach(Variable counterVar, Variable arrayLenVar, InsnList array, InsnList action) { Validate.notNull(counterVar); Validate.notNull(arrayLenVar); Validate.notNull(array); Validate.notNull(action); Validate.isTrue(counterVar.getType().equals(Type.INT_TYPE)); Validate.isTrue(arrayLenVar.getType().equals(Type.INT_TYPE)); InsnList ret = new InsnList(); LabelNode doneLabelNode = new LabelNode(); LabelNode loopLabelNode = new LabelNode(); // put zero in to counterVar ret.add(new LdcInsnNode(0)); // int ret.add(new VarInsnNode(Opcodes.ISTORE, counterVar.getIndex())); // // load array we'll be traversing over ret.add(array); // object[] // put array length in to arrayLenVar ret.add(new InsnNode(Opcodes.DUP)); // object[], object[] ret.add(new InsnNode(Opcodes.ARRAYLENGTH)); // object[], int ret.add(new VarInsnNode(Opcodes.ISTORE, arrayLenVar.getIndex())); // object[] // loopLabelNode: test if counterVar == arrayLenVar, if it does then jump to doneLabelNode ret.add(loopLabelNode); ret.add(new VarInsnNode(Opcodes.ILOAD, counterVar.getIndex())); // object[], int ret.add(new VarInsnNode(Opcodes.ILOAD, arrayLenVar.getIndex())); // object[], int, int ret.add(new JumpInsnNode(Opcodes.IF_ICMPEQ, doneLabelNode)); // object[] // load object from object[] ret.add(new InsnNode(Opcodes.DUP)); // object[], object[] ret.add(new VarInsnNode(Opcodes.ILOAD, counterVar.getIndex())); // object[], object[], int ret.add(new InsnNode(Opcodes.AALOAD)); // object[], object // call action ret.add(action); // object[] // increment counter var and goto loopLabelNode ret.add(new IincInsnNode(counterVar.getIndex(), 1)); // object[] ret.add(new JumpInsnNode(Opcodes.GOTO, loopLabelNode)); // object[] // doneLabelNode: pop object[] off of stack ret.add(doneLabelNode); ret.add(new InsnNode(Opcodes.POP)); // return ret; }