List of usage examples for org.objectweb.asm Opcodes IFEQ
int IFEQ
To view the source code for org.objectweb.asm Opcodes IFEQ.
Click Source Link
From source file:com.mebigfatguy.junitflood.jvm.OperandStack.java
License:Apache License
public void performJumpInsn(int opcode, Label label) { switch (opcode) { case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: case Opcodes.IFNULL: case Opcodes.IFNONNULL: pop();// ww w .j a v a 2s.c o m break; 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: pop2(); break; case Opcodes.GOTO: //nop break; case Opcodes.JSR: //nop -- a fudge break; } }
From source file:com.mogujie.instantrun.IntSwitch.java
License:Apache License
private void visitx(GeneratorAdapter mv, List<String> strings) { if (strings.size() == 1) { visitCase(strings.get(0));/*from w w w. ja va 2 s.c o m*/ return; } for (String string : strings) { Label label = new Label(); visitString(); mv.visitLdcInsn(string); mv.invokeVirtual(STRING_TYPE, Method.getMethod("boolean equals(Object)")); mv.visitJumpInsn(Opcodes.IFEQ, label); visitCase(string); mv.visitLabel(label); } visitDefault(); }
From source file:com.nginious.http.xsp.expr.EqualsOperator.java
License:Apache License
/** * Compiles bytecode for evaluating this equals operator producing * a double as result. The specified method visitor is used for generating * bytecode./*ww w.ja v a 2 s .com*/ * * @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(false); visitor.visitJumpInsn(Opcodes.GOTO, falseLabel); visitor.visitLabel(trueLabel); visitor.visitLdcInsn(true); visitor.visitLabel(falseLabel); }
From source file:com.nginious.http.xsp.expr.ExpressionCompiler.java
License:Apache License
/** * Creates a compiled expression from the specified tree value node expression. The class bytecode for the * compiled expression is generated at runtime. * // w ww. j av a 2 s . c o m * @param uncompiled the uncompiled tree value node expression * @return the compiled expression * @throws ExpressionException if unable to compile expression */ public Expression compile(TreeExpression uncompiled) throws ExpressionException { ClassWriter writer = new ClassWriter(0); // Create class String className = classBaseName + classNameCounter.getAndIncrement(); String classIdentifier = className.replace('.', '/'); writer.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, classIdentifier, "L" + classIdentifier + ";", "com/nginious/http/xsp/expr/Expression", null); // Create constructor MethodVisitor visitor = writer.visitMethod(Opcodes.ACC_PROTECTED, "<init>", "()V", null, null); visitor.visitCode(); visitor.visitVarInsn(Opcodes.ALOAD, 0); visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/nginious/http/xsp/expr/Expression", "<init>", "()V"); visitor.visitInsn(Opcodes.RETURN); visitor.visitMaxs(1, 1); visitor.visitEnd(); // protected abstract boolean evaluateBoolean(); visitor = writer.visitMethod(Opcodes.ACC_PROTECTED, "evaluateBoolean", "()Z", null, null); if (uncompiled.getType() == Type.BOOLEAN) { uncompiled.compile(visitor); } else if (uncompiled.getType() == Type.DOUBLE) { visitor.visitVarInsn(Opcodes.ALOAD, 0); // this visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classIdentifier, "evaluateDouble", "()D"); Label endLabel = new Label(); Label falseLabel = new Label(); visitor.visitLdcInsn(0.0d); visitor.visitInsn(Opcodes.DCMPL); visitor.visitJumpInsn(Opcodes.IFEQ, falseLabel); visitor.visitLdcInsn(true); visitor.visitJumpInsn(Opcodes.GOTO, endLabel); visitor.visitLabel(falseLabel); visitor.visitLdcInsn(false); visitor.visitLabel(endLabel); } else if (uncompiled.getType() == Type.INT) { visitor.visitVarInsn(Opcodes.ALOAD, 0); // this visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classIdentifier, "evaluateInt", "()I"); Label endLabel = new Label(); Label falseLabel = new Label(); visitor.visitLdcInsn(0); visitor.visitJumpInsn(Opcodes.IFNE, falseLabel); visitor.visitLdcInsn(true); visitor.visitJumpInsn(Opcodes.GOTO, endLabel); visitor.visitLabel(falseLabel); visitor.visitLdcInsn(false); visitor.visitLabel(endLabel); } else if (uncompiled.getType() == Type.STRING) { visitor.visitVarInsn(Opcodes.ALOAD, 0); // this visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classIdentifier, "evaluateString", "()Ljava/lang/String;"); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "parseBoolean", "(Ljava/lang/String;)Z"); } visitor.visitInsn(Opcodes.IRETURN); visitor.visitMaxs(5, 5); visitor.visitEnd(); // protected abstract int evaluateInt(); visitor = writer.visitMethod(Opcodes.ACC_PROTECTED, "evaluateInt", "()I", null, null); if (uncompiled.getType() == Type.BOOLEAN) { visitor.visitVarInsn(Opcodes.ALOAD, 0); // this visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classIdentifier, "evaluateBoolean", "()Z"); Label endLabel = new Label(); Label falseLabel = new Label(); visitor.visitJumpInsn(Opcodes.IFEQ, falseLabel); visitor.visitLdcInsn(1); visitor.visitJumpInsn(Opcodes.GOTO, endLabel); visitor.visitLabel(falseLabel); visitor.visitLdcInsn(0); visitor.visitLabel(endLabel); } else if (uncompiled.getType() == Type.DOUBLE) { visitor.visitVarInsn(Opcodes.ALOAD, 0); // this visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classIdentifier, "evaluateDouble", "()D"); visitor.visitInsn(Opcodes.D2I); } else if (uncompiled.getType() == Type.INT) { uncompiled.compile(visitor); } else if (uncompiled.getType() == Type.STRING) { visitor.visitVarInsn(Opcodes.ALOAD, 0); // this visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classIdentifier, "evaluateString", "()Ljava/lang/String;"); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "parseInt", "(Ljava/lang/String;)I"); } visitor.visitInsn(Opcodes.IRETURN); visitor.visitMaxs(5, 5); visitor.visitEnd(); // protected abstract double evaluateDouble(); visitor = writer.visitMethod(Opcodes.ACC_PROTECTED, "evaluateDouble", "()D", null, null); if (uncompiled.getType() == Type.BOOLEAN) { visitor.visitVarInsn(Opcodes.ALOAD, 0); // this visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classIdentifier, "evaluateBoolean", "()Z"); Label endLabel = new Label(); Label falseLabel = new Label(); visitor.visitJumpInsn(Opcodes.IFEQ, falseLabel); visitor.visitLdcInsn(1.0d); visitor.visitJumpInsn(Opcodes.GOTO, endLabel); visitor.visitLabel(falseLabel); visitor.visitLdcInsn(0.0d); visitor.visitLabel(endLabel); } else if (uncompiled.getType() == Type.DOUBLE) { uncompiled.compile(visitor); } else if (uncompiled.getType() == Type.INT) { visitor.visitVarInsn(Opcodes.ALOAD, 0); // this visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classIdentifier, "evaluateInt", "()I"); visitor.visitInsn(Opcodes.I2D); } else if (uncompiled.getType() == Type.STRING) { visitor.visitVarInsn(Opcodes.ALOAD, 0); // this visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classIdentifier, "evaluateString", "()Ljava/lang/String;"); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "parseDouble", "(Ljava/lang/String;)D"); } visitor.visitInsn(Opcodes.DRETURN); visitor.visitMaxs(5, 5); visitor.visitEnd(); // protected abstract String evaluateString(); visitor = writer.visitMethod(Opcodes.ACC_PROTECTED, "evaluateString", "()Ljava/lang/String;", null, null); if (uncompiled.getType() == Type.BOOLEAN) { visitor.visitVarInsn(Opcodes.ALOAD, 0); // this visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classIdentifier, "evaluateBoolean", "()Z"); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "toString", "(Z)Ljava/lang/String;"); } else if (uncompiled.getType() == Type.DOUBLE) { visitor.visitVarInsn(Opcodes.ALOAD, 0); // this visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classIdentifier, "evaluateDouble", "()D"); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "toString", "(D)Ljava/lang/String;"); } else if (uncompiled.getType() == Type.INT) { visitor.visitVarInsn(Opcodes.ALOAD, 0); // this visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classIdentifier, "evaluateInt", "()I"); visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "toString", "(I)Ljava/lang/String;"); } else if (uncompiled.getType() == Type.STRING) { uncompiled.compile(visitor); } visitor.visitInsn(Opcodes.ARETURN); visitor.visitMaxs(6, 6); visitor.visitEnd(); // public abstract Type getType(); visitor = writer.visitMethod(Opcodes.ACC_PUBLIC, "getType", "()Lcom/nginious/http/xsp/expr/Type;", null, null); if (uncompiled.getType() == Type.BOOLEAN) { visitor.visitFieldInsn(Opcodes.GETSTATIC, "com/nginious/http/xsp/expr/Type", "BOOLEAN", "Lcom/nginious/http/xsp/expr/Type;"); visitor.visitInsn(Opcodes.ARETURN); } else if (uncompiled.getType() == Type.DOUBLE) { visitor.visitFieldInsn(Opcodes.GETSTATIC, "com/nginious/http/xsp/expr/Type", "DOUBLE", "Lcom/nginious/http/xsp/expr/Type;"); visitor.visitInsn(Opcodes.ARETURN); } else if (uncompiled.getType() == Type.INT) { visitor.visitFieldInsn(Opcodes.GETSTATIC, "com/nginious/http/xsp/expr/Type", "INT", "Lcom/nginious/http/xsp/expr/Type;"); visitor.visitInsn(Opcodes.ARETURN); } else if (uncompiled.getType() == Type.STRING) { visitor.visitFieldInsn(Opcodes.GETSTATIC, "com/nginious/http/xsp/expr/Type", "STRING", "Lcom/nginious/http/xsp/expr/Type;"); visitor.visitInsn(Opcodes.ARETURN); } visitor.visitMaxs(1, 1); visitor.visitEnd(); try { writer.visitEnd(); byte[] clazzBytes = writer.toByteArray(); Class<?> clazz = loadClass(className, clazzBytes); return (Expression) clazz.newInstance(); } catch (Exception e) { throw new ExpressionException("Can't instantiate compiled expression", e); } }
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 . jav a 2 s . co 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.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 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.nginious.http.xsp.IfTagPart.java
License:Apache License
/** * Creates bytecode for this if tag part using the specified class writer and method visitor. A separate * method is created within the class to evaluate the expression in the test attribute. * /*from ww w.ja va2 s. co m*/ * @param intClassName the binary class name of the class being created * @param writer the class writer * @param visitor the method visitor * @throws XspException if unable to create bytecode */ void compile(String intClassName, ClassWriter writer, MethodVisitor visitor) throws XspException { if (this.part == null) { throw new XspException( "Attribute test is missing for tag " + getName() + " at " + getLocationDescriptor()); } this.methodName = "ifTest" + methodNameCounter.getAndIncrement(); visitor.visitVarInsn(Opcodes.ALOAD, 0); visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, intClassName, this.methodName, "()Z"); Label falseLabel = new Label(); visitor.visitJumpInsn(Opcodes.IFEQ, falseLabel); for (XspPart part : this.contentParts) { part.compile(intClassName, writer, visitor); } visitor.visitLabel(falseLabel); }
From source file:com.retroduction.carma.transformer.asm.ror.IFEQ_2_IFNE_Transition.java
License:Open Source License
public IFEQ_2_IFNE_Transition() { super(); this.sourceInstruction = Opcodes.IFEQ; this.targetInstruction = Opcodes.IFNE; }
From source file:com.retroduction.carma.transformer.asm.ror.IFNE_2_IFEQ_Transition.java
License:Open Source License
public IFNE_2_IFEQ_Transition() { super(); this.sourceInstruction = Opcodes.IFNE; this.targetInstruction = Opcodes.IFEQ; }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void getRawBaseCase(MethodVisitor mv, String className, Relation<String, Integer> hashCodeRelation, EnvironmentClass environmentClass, int code, Label returnNull) {//from w w w .j ava 2 s.c o m PredicateSet<String> strings = hashCodeRelation.matchSecond(code); for (String testString : strings) { mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitLdcInsn(testString); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z"); Label afterReturn = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, afterReturn); mv.visitVarInsn(Opcodes.ALOAD, 0); String idString = testString + environmentClass.namespace(); mv.visitFieldInsn(Opcodes.GETFIELD, className, Naming.mangleIdentifier(idString), environmentClass.descriptor()); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(afterReturn); } mv.visitJumpInsn(Opcodes.GOTO, returnNull); }