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:org.evosuite.TestSuiteGeneratorHelper.java
License:Open Source License
static void getBytecodeStatistics() { if (Properties.TRACK_BOOLEAN_BRANCHES) { int gradientBranchCount = ExecutionTraceImpl.gradientBranches.size() * 2; ClientServices.track(RuntimeVariable.Gradient_Branches, gradientBranchCount); }// ww w .j ava 2 s . c om if (Properties.TRACK_COVERED_GRADIENT_BRANCHES) { int coveredGradientBranchCount = ExecutionTraceImpl.gradientBranchesCoveredTrue.size() + ExecutionTraceImpl.gradientBranchesCoveredFalse.size(); ClientServices.track(RuntimeVariable.Gradient_Branches_Covered, coveredGradientBranchCount); } if (Properties.BRANCH_COMPARISON_TYPES) { int cmp_intzero = 0, cmp_intint = 0, cmp_refref = 0, cmp_refnull = 0; int bc_lcmp = 0, bc_fcmpl = 0, bc_fcmpg = 0, bc_dcmpl = 0, bc_dcmpg = 0; for (Branch b : BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()) .getAllBranches()) { int branchOpCode = b.getInstruction().getASMNode().getOpcode(); int previousOpcode = -2; if (b.getInstruction().getASMNode().getPrevious() != null) { previousOpcode = b.getInstruction().getASMNode().getPrevious().getOpcode(); } switch (previousOpcode) { case Opcodes.LCMP: bc_lcmp++; break; case Opcodes.FCMPL: bc_fcmpl++; break; case Opcodes.FCMPG: bc_fcmpg++; break; case Opcodes.DCMPL: bc_dcmpl++; break; case Opcodes.DCMPG: bc_dcmpg++; break; } switch (branchOpCode) { // copmpare int with zero case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: cmp_intzero++; break; // copmpare int with int case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: cmp_intint++; break; // copmpare reference with reference case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: cmp_refref++; break; // compare reference with null case Opcodes.IFNULL: case Opcodes.IFNONNULL: cmp_refnull++; break; } } ClientServices.track(RuntimeVariable.Cmp_IntZero, cmp_intzero); ClientServices.track(RuntimeVariable.Cmp_IntInt, cmp_intint); ClientServices.track(RuntimeVariable.Cmp_RefRef, cmp_refref); ClientServices.track(RuntimeVariable.Cmp_RefNull, cmp_refnull); ClientServices.track(RuntimeVariable.BC_lcmp, bc_lcmp); ClientServices.track(RuntimeVariable.BC_fcmpl, bc_fcmpl); ClientServices.track(RuntimeVariable.BC_fcmpg, bc_fcmpg); ClientServices.track(RuntimeVariable.BC_dcmpl, bc_dcmpl); ClientServices.track(RuntimeVariable.BC_dcmpg, bc_dcmpg); RuntimeVariable[] bytecodeVarsCovered = new RuntimeVariable[] { RuntimeVariable.Covered_lcmp, RuntimeVariable.Covered_fcmpl, RuntimeVariable.Covered_fcmpg, RuntimeVariable.Covered_dcmpl, RuntimeVariable.Covered_dcmpg, RuntimeVariable.Covered_IntInt, RuntimeVariable.Covered_IntInt, RuntimeVariable.Covered_IntZero, RuntimeVariable.Covered_RefRef, RuntimeVariable.Covered_RefNull }; for (RuntimeVariable bcvar : bytecodeVarsCovered) { ClientServices.track(bcvar, getBytecodeCount(bcvar, ExecutionTraceImpl.bytecodeInstructionCoveredFalse) + getBytecodeCount(bcvar, ExecutionTraceImpl.bytecodeInstructionCoveredTrue)); } RuntimeVariable[] bytecodeVarsReached = new RuntimeVariable[] { RuntimeVariable.Reached_lcmp, RuntimeVariable.Reached_fcmpl, RuntimeVariable.Reached_fcmpg, RuntimeVariable.Reached_dcmpl, RuntimeVariable.Reached_dcmpg, RuntimeVariable.Reached_IntInt, RuntimeVariable.Reached_IntInt, RuntimeVariable.Reached_IntZero, RuntimeVariable.Reached_RefRef, RuntimeVariable.Reached_RefNull }; for (RuntimeVariable bcvar : bytecodeVarsReached) { ClientServices.track(bcvar, getBytecodeCount(bcvar, ExecutionTraceImpl.bytecodeInstructionReached) * 2); } } }
From source file:org.formulacompiler.compiler.internal.bytecode.ExpressionCompilerForStrings_Base.java
License:Open Source License
@Override protected int compileComparison(int _ifOpcode, int _comparisonOpcode) throws CompilerException { switch (_ifOpcode) { /*//from www . j ava 2 s . c o m * This may seem counter-intuitive here, but the contract is to return 0 for equality. * Boolean true, however, is 1. So we invert the test for EQ and NE. */ case Opcodes.IFEQ: mv().visitMethodInsn(Opcodes.INVOKEVIRTUAL, SNAME, "equalsIgnoreCase", S2Z); return Opcodes.IFNE; case Opcodes.IFNE: mv().visitMethodInsn(Opcodes.INVOKEVIRTUAL, SNAME, "equalsIgnoreCase", S2Z); return Opcodes.IFEQ; default: mv().visitMethodInsn(Opcodes.INVOKEVIRTUAL, SNAME, "compareToIgnoreCase", S2I); return _ifOpcode; } }
From source file:org.formulacompiler.compiler.internal.bytecode.HelperCompilerForFoldDatabase.java
License:Open Source License
private void compileSkipFoldIfNoMatch(final Label _noMatch) { mv().ifZCmp(Opcodes.IFEQ, _noMatch); }
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
private void handleBooleanOperator(Expression node, Operator op, Type type) throws ASTVisitorException { List<JumpInsnNode> trueList = new ArrayList<JumpInsnNode>(); System.out.println("***** handle boolean " + op); if (type.equals(TypeUtils.STRING_TYPE)) { mn.instructions.add(new InsnNode(Opcodes.SWAP)); JumpInsnNode jmp = null;//from ww w . j av a2 s .com mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false)); switch (op) { case EQUAL: jmp = new JumpInsnNode(Opcodes.IFNE, null); break; case NOT_EQUAL: jmp = new JumpInsnNode(Opcodes.IFEQ, null); break; default: ASTUtils.error(node, "Operator not supported on strings"); break; } mn.instructions.add(jmp); trueList.add(jmp); } else if (type.equals(Type.DOUBLE_TYPE)) { // FIXME: add DCMPG instruction // FIXME: add a JumpInsnNode with null label based on the operation // IFEQ, IFNE, IFGT, IFGE, IFLT, IFLE // FIXME: add the jmp instruction into trueList mn.instructions.add(new InsnNode(Opcodes.DCMPG)); JumpInsnNode jmp = null; switch (op) { case EQUAL: jmp = new JumpInsnNode(Opcodes.IFEQ, null); mn.instructions.add(jmp); break; case NOT_EQUAL: jmp = new JumpInsnNode(Opcodes.IFNE, null); mn.instructions.add(jmp); break; case GREATER: jmp = new JumpInsnNode(Opcodes.IFGT, null); mn.instructions.add(jmp); break; case GREATER_EQUAL: jmp = new JumpInsnNode(Opcodes.IFGE, null); mn.instructions.add(jmp); break; case LESS: jmp = new JumpInsnNode(Opcodes.IFLT, null); mn.instructions.add(jmp); break; case LESS_EQUAL: jmp = new JumpInsnNode(Opcodes.IFLE, null); mn.instructions.add(jmp); break; } trueList.add(jmp); } else { System.out.println("here"); JumpInsnNode jmp = null; switch (op) { case EQUAL: jmp = new JumpInsnNode(Opcodes.IF_ICMPEQ, null); mn.instructions.add(jmp); break; case NOT_EQUAL: jmp = new JumpInsnNode(Opcodes.IF_ICMPNE, null); mn.instructions.add(jmp); break; case GREATER: System.out.println("----- greater"); jmp = new JumpInsnNode(Opcodes.IF_ICMPGT, null); mn.instructions.add(jmp); break; case GREATER_EQUAL: jmp = new JumpInsnNode(Opcodes.IF_ICMPGE, null); mn.instructions.add(jmp); break; case LESS: jmp = new JumpInsnNode(Opcodes.IF_ICMPLT, null); mn.instructions.add(jmp); break; case LESS_EQUAL: jmp = new JumpInsnNode(Opcodes.IF_ICMPLE, null); mn.instructions.add(jmp); break; default: ASTUtils.error(node, "Operator not supported"); break; } trueList.add(jmp); } ASTUtils.setTrueList(node, trueList); List<JumpInsnNode> falseList = new ArrayList<JumpInsnNode>(); JumpInsnNode jmp = new JumpInsnNode(Opcodes.GOTO, null); mn.instructions.add(jmp); falseList.add(jmp); ASTUtils.setFalseList(node, falseList); }
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
private void handleNumberOperator(ASTNode node, Operator op, Type type) throws ASTVisitorException { if (op.equals(Operator.PLUS)) { // FIXME: IADD or DADD, etc. // use type.getOpcode(Opcodes.IADD) to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IADD))); } else if (op.equals(Operator.MINUS)) { // FIXME: ISUB or DSUB, etc. // use type.getOpcode() to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.ISUB))); } else if (op.equals(Operator.MULTIPLY)) { // FIXME: IMUL or DMUL, etc. // use type.getOpcode() to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IMUL))); } else if (op.equals(Operator.DIVISION)) { // FIXME: IDIV or DDIV, etc. // use type.getOpcode() to avoid if-then mn.instructions.add(new InsnNode(type.getOpcode(Opcodes.IDIV))); } else if (op.isRelational()) { if (type.equals(Type.DOUBLE_TYPE)) { mn.instructions.add(new InsnNode(Opcodes.DCMPG)); JumpInsnNode jmp = null;/*from w ww . j ava2 s. c om*/ switch (op) { case EQUAL: jmp = new JumpInsnNode(Opcodes.IFEQ, null); mn.instructions.add(jmp); break; case NOT_EQUAL: jmp = new JumpInsnNode(Opcodes.IFNE, null); mn.instructions.add(jmp); break; case GREATER: jmp = new JumpInsnNode(Opcodes.IFGT, null); mn.instructions.add(jmp); break; case GREATER_EQUAL: jmp = new JumpInsnNode(Opcodes.IFGE, null); mn.instructions.add(jmp); break; case LESS: jmp = new JumpInsnNode(Opcodes.IFLT, null); mn.instructions.add(jmp); break; case LESS_EQUAL: jmp = new JumpInsnNode(Opcodes.IFLE, null); mn.instructions.add(jmp); break; default: ASTUtils.error(node, "Operator not supported"); break; } mn.instructions.add(new InsnNode(Opcodes.ICONST_0)); LabelNode endLabelNode = new LabelNode(); mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode)); LabelNode trueLabelNode = new LabelNode(); jmp.label = trueLabelNode; mn.instructions.add(trueLabelNode); mn.instructions.add(new InsnNode(Opcodes.ICONST_1)); mn.instructions.add(endLabelNode); } else if (type.equals(Type.INT_TYPE)) { LabelNode trueLabelNode = new LabelNode(); switch (op) { case EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPEQ, trueLabelNode)); break; case NOT_EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPNE, trueLabelNode)); break; case GREATER: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPGT, trueLabelNode)); break; case GREATER_EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPGE, trueLabelNode)); break; case LESS: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPLT, trueLabelNode)); break; case LESS_EQUAL: mn.instructions.add(new JumpInsnNode(Opcodes.IF_ICMPLE, trueLabelNode)); break; default: break; } mn.instructions.add(new InsnNode(Opcodes.ICONST_0)); LabelNode endLabelNode = new LabelNode(); mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode)); mn.instructions.add(trueLabelNode); mn.instructions.add(new InsnNode(Opcodes.ICONST_1)); mn.instructions.add(endLabelNode); } else { ASTUtils.error(node, "Cannot compare such types."); } } else { ASTUtils.error(node, "Operator not recognized."); } }
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
/** * Assumes top of stack contains two strings *//* w w w. jav a 2 s . c o m*/ private void handleStringOperator(ASTNode node, Operator op) throws ASTVisitorException { if (op.equals(Operator.PLUS)) { mn.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/lang/StringBuilder")); mn.instructions.add(new InsnNode(Opcodes.DUP)); mn.instructions.add( new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false)); mn.instructions.add(new InsnNode(Opcodes.SWAP)); mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false)); mn.instructions.add(new InsnNode(Opcodes.SWAP)); mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false)); mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false)); } else if (op.isRelational()) { LabelNode trueLabelNode = new LabelNode(); switch (op) { case EQUAL: mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false)); mn.instructions.add(new JumpInsnNode(Opcodes.IFNE, trueLabelNode)); break; case NOT_EQUAL: mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false)); mn.instructions.add(new JumpInsnNode(Opcodes.IFEQ, trueLabelNode)); break; default: ASTUtils.error(node, "Operator not supported on strings"); break; } mn.instructions.add(new InsnNode(Opcodes.ICONST_0)); LabelNode endLabelNode = new LabelNode(); mn.instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabelNode)); mn.instructions.add(trueLabelNode); mn.instructions.add(new InsnNode(Opcodes.ICONST_1)); mn.instructions.add(endLabelNode); } else { ASTUtils.error(node, "Operator not recognized"); } }
From source file:org.jacoco.core.internal.analysis.AC_MethodAnalyzerTest.java
License:Open Source License
private void createIfBranch() { final Label l0 = new Label(); method.visitLabel(l0);//from w ww . j av a 2s.co m method.visitLineNumber(1001, l0); method.visitVarInsn(Opcodes.ILOAD, 1); Label l1 = new Label(); method.visitJumpInsn(Opcodes.IFEQ, l1); final Label l2 = new Label(); method.visitLabel(l2); method.visitLineNumber(1002, l2); method.visitLdcInsn("a"); method.visitInsn(Opcodes.ARETURN); method.visitLabel(l1); method.visitLineNumber(1003, l1); method.visitLdcInsn("b"); method.visitInsn(Opcodes.ARETURN); }
From source file:org.jacoco.core.internal.analysis.AC_MethodAnalyzerTest.java
License:Open Source License
private void createIfBranchMerge() { final Label l0 = new Label(); method.visitLabel(l0);/*from ww w .jav a 2s . co m*/ method.visitLineNumber(1001, l0); method.visitVarInsn(Opcodes.ILOAD, 1); Label l1 = new Label(); method.visitJumpInsn(Opcodes.IFEQ, l1); final Label l2 = new Label(); method.visitLabel(l2); method.visitLineNumber(1002, l2); method.visitInsn(Opcodes.NOP); method.visitLabel(l1); method.visitLineNumber(1003, l1); method.visitInsn(Opcodes.RETURN); }
From source file:org.jacoco.core.internal.analysis.filter.FinallyFilterTest.java
License:Open Source License
/** * <pre>// w w w . jav a 2s . com * try { * ... * if (...) { * ... * return; * } else { * ... * return; * } * } finally { * ... * } * </pre> */ @Test public void should_analyze_control_flow() { final Label start1 = new Label(); final Label end1 = new Label(); final Label start2 = new Label(); final Label end2 = new Label(); final Label finallyStart = new Label(); m.visitTryCatchBlock(start1, end1, finallyStart, null); m.visitTryCatchBlock(start2, end2, finallyStart, null); m.visitLabel(start1); // jump to another region associated with same handler: m.visitJumpInsn(Opcodes.IFEQ, start2); m.visitInsn(Opcodes.NOP); m.visitLabel(end1); m.visitInsn(Opcodes.NOP); // finally block shouldMergeLast(); m.visitInsn(Opcodes.RETURN); m.visitLabel(start2); m.visitInsn(Opcodes.NOP); m.visitLabel(end2); m.visitInsn(Opcodes.NOP); // finally block shouldMergeLast(); m.visitInsn(Opcodes.RETURN); m.visitLabel(finallyStart); m.visitVarInsn(Opcodes.ASTORE, 1); shouldIgnoreLast(); m.visitInsn(Opcodes.NOP); // finally block shouldMergeLast(); m.visitVarInsn(Opcodes.ALOAD, 1); shouldIgnoreLast(); m.visitInsn(Opcodes.ATHROW); shouldIgnoreLast(); execute(); }
From source file:org.jacoco.core.internal.analysis.filter.KotlinCoroutineFilterTest.java
License:Open Source License
/** * <pre>/* www .j a v a2 s. com*/ * runBlocking { * val x = 42 * nop(x) * suspendingFunction() * nop(x) * } * </pre> */ @Test public void should_filter_suspending_lambdas() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "invokeSuspend", "(Ljava/lang/Object;)Ljava/lang/Object;", null, null); context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); m.visitLabel(new Label()); final Range range1 = new Range(); range1.fromInclusive = m.instructions.getLast(); m.visitMethodInsn(Opcodes.INVOKESTATIC, "kotlin/coroutines/intrinsics/IntrinsicsKt", "getCOROUTINE_SUSPENDED", "()Ljava/lang/Object;", false); m.visitVarInsn(Opcodes.ASTORE, 4); m.visitVarInsn(Opcodes.ALOAD, 0); // line of "runBlocking" m.visitFieldInsn(Opcodes.GETFIELD, "Target", "label", "I"); final Label dflt = new Label(); final Label state0 = new Label(); final Label state1 = new Label(); m.visitTableSwitchInsn(0, 1, dflt, state0, state1); m.visitLabel(state0); { m.visitVarInsn(Opcodes.ALOAD, 1); m.visitInsn(Opcodes.DUP); m.visitTypeInsn(Opcodes.INSTANCEOF, "kotlin/Result$Failure"); Label label = new Label(); m.visitJumpInsn(Opcodes.IFEQ, label); m.visitTypeInsn(Opcodes.CHECKCAST, "kotlin/Result$Failure"); m.visitFieldInsn(Opcodes.GETFIELD, "kotlin/Result$Failure", "exception", "Ljava/lang/Throwable"); m.visitInsn(Opcodes.ATHROW); m.visitInsn(Opcodes.POP); range1.toInclusive = m.instructions.getLast(); m.visitLabel(label); } // line before "suspendingFunction" m.visitInsn(Opcodes.NOP); // line of "suspendingFunction" m.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "", "suspendingFunction", "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", false); m.visitInsn(Opcodes.DUP); final Range range2 = new Range(); range2.fromInclusive = m.instructions.getLast(); m.visitVarInsn(Opcodes.ALOAD, 4); final Label continuationLabelAfterLoadedResult = new Label(); m.visitJumpInsn(Opcodes.IF_ACMPNE, continuationLabelAfterLoadedResult); // line of "runBlocking" m.visitVarInsn(Opcodes.ALOAD, 4); m.visitInsn(Opcodes.ARETURN); m.visitLabel(state1); m.visitVarInsn(Opcodes.ALOAD, 0); m.visitFieldInsn(Opcodes.GETFIELD, "Target", "I$0", "I"); m.visitVarInsn(Opcodes.ISTORE, 3); { m.visitVarInsn(Opcodes.ALOAD, 1); m.visitInsn(Opcodes.DUP); m.visitTypeInsn(Opcodes.INSTANCEOF, "kotlin/Result$Failure"); final Label label = new Label(); m.visitJumpInsn(Opcodes.IFEQ, label); m.visitTypeInsn(Opcodes.CHECKCAST, "kotlin/Result$Failure"); m.visitFieldInsn(Opcodes.GETFIELD, "kotlin/Result$Failure", "exception", "Ljava/lang/Throwable"); m.visitInsn(Opcodes.ATHROW); m.visitInsn(Opcodes.POP); m.visitLabel(label); } m.visitVarInsn(Opcodes.ALOAD, 1); range2.toInclusive = m.instructions.getLast(); m.visitLabel(continuationLabelAfterLoadedResult); // line after "suspendingFunction" m.visitInsn(Opcodes.NOP); m.visitInsn(Opcodes.ARETURN); m.visitLabel(dflt); final Range range0 = new Range(); range0.fromInclusive = m.instructions.getLast(); m.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalStateException"); m.visitInsn(Opcodes.DUP); m.visitLdcInsn("call to 'resume' before 'invoke' with coroutine"); m.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalStateException", "<init>", "(Ljava/lang/String;)V", false); m.visitInsn(Opcodes.ATHROW); range0.toInclusive = m.instructions.getLast(); filter.filter(m, context, output); assertIgnored(range0, range1, range2); }