List of usage examples for org.objectweb.asm Opcodes IAND
int IAND
To view the source code for org.objectweb.asm Opcodes IAND.
Click Source Link
From source file:org.evosuite.instrumentation.mutation.ReplaceBitwiseOperator.java
License:Open Source License
private String getOp(int opcode) { switch (opcode) { case Opcodes.IAND: case Opcodes.LAND: return "&"; case Opcodes.IOR: case Opcodes.LOR: return "|"; case Opcodes.IXOR: case Opcodes.LXOR: return "^"; case Opcodes.ISHR: return ">> I"; case Opcodes.LSHR: return ">> L"; case Opcodes.ISHL: return "<< I"; case Opcodes.LSHL: return "<< L"; case Opcodes.IUSHR: return ">>> I"; case Opcodes.LUSHR: return ">>> L"; }// www . j a v a 2 s . c o m throw new RuntimeException("Unknown opcode: " + opcode); }
From source file:org.evosuite.instrumentation.mutation.ReplaceBitwiseOperator.java
License:Open Source License
/** * <p>calculate</p>/*from w w w. jav a2 s.co m*/ * * @param x a int. * @param y a int. * @param opcode a int. * @return a int. */ public static int calculate(int x, int y, int opcode) { switch (opcode) { case Opcodes.IAND: return x & y; case Opcodes.IOR: return x | y; case Opcodes.IXOR: return x ^ y; case Opcodes.ISHL: return x << y; case Opcodes.ISHR: return x >> y; case Opcodes.IUSHR: return x >>> y; } throw new RuntimeException("Unknown integer opcode: " + opcode); }
From source file:org.evosuite.instrumentation.mutation.TestReplaceBitwiseOperator.java
License:Open Source License
@Test public void testGetInfectionDistanceInt() { assertEquals(ReplaceBitwiseOperator.getInfectionDistanceInt(1, 0, Opcodes.IAND, Opcodes.IOR), 0.0, 0.0); assertEquals(ReplaceBitwiseOperator.getInfectionDistanceInt(0, 0, Opcodes.IAND, Opcodes.IOR), 1.0, 0.0); assertEquals(ReplaceBitwiseOperator.getInfectionDistanceInt(1, 1, Opcodes.IAND, Opcodes.IOR), 1.0, 0.0); assertEquals(ReplaceBitwiseOperator.getInfectionDistanceInt(1, 2, Opcodes.IAND, Opcodes.IOR), 0.0, 0.0); }
From source file:org.evosuite.instrumentation.testability.transformer.BitwiseOperatorTransformer.java
License:Open Source License
@Override protected AbstractInsnNode transformInsnNode(MethodNode mn, InsnNode insnNode) { if (insnNode.getOpcode() == Opcodes.IOR || insnNode.getOpcode() == Opcodes.IAND || insnNode.getOpcode() == Opcodes.IXOR) { if (this.booleanTestabilityTransformation.isBooleanOnStack(mn, insnNode, 0) && this.booleanTestabilityTransformation.isBooleanOnStack(mn, insnNode, 1)) { if (insnNode.getOpcode() == Opcodes.IOR) { MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "IOR", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE })); mn.instructions.insertBefore(insnNode, push); mn.instructions.remove(insnNode); TransformationStatistics.transformedBitwise(); return push; } else if (insnNode.getOpcode() == Opcodes.IAND) { MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "IAND", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE })); mn.instructions.insertBefore(insnNode, push); mn.instructions.remove(insnNode); TransformationStatistics.transformedBitwise(); return push; } else if (insnNode.getOpcode() == Opcodes.IXOR) { MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "IXOR", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE })); mn.instructions.insertBefore(insnNode, push); mn.instructions.remove(insnNode); TransformationStatistics.transformedBitwise(); return push; }/*from w ww. ja v a 2 s . com*/ } } return insnNode; }
From source file:org.jacoco.core.internal.analysis.filter.KotlinCoroutineFilterTest.java
License:Open Source License
/** * <pre>/*from ww w . java 2 s. co m*/ * suspend fun example() { * suspendingFunction() * nop() * } * </pre> */ @Test public void should_filter_suspending_functions() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_STATIC, "example", "(Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", null, null); context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); final int continuationArgumentIndex = 0; final int continuationIndex = 2; m.visitVarInsn(Opcodes.ALOAD, continuationArgumentIndex); final Range range1 = new Range(); range1.fromInclusive = m.instructions.getLast(); m.visitTypeInsn(Opcodes.INSTANCEOF, "ExampleKt$example$1"); final Label createStateInstance = new Label(); m.visitJumpInsn(Opcodes.IFEQ, createStateInstance); m.visitVarInsn(Opcodes.ALOAD, continuationArgumentIndex); m.visitTypeInsn(Opcodes.CHECKCAST, "ExampleKt$example$1"); m.visitVarInsn(Opcodes.ASTORE, continuationIndex); m.visitVarInsn(Opcodes.ALOAD, continuationIndex); m.visitFieldInsn(Opcodes.GETFIELD, "ExampleKt$example$1", "label", "I"); m.visitLdcInsn(Integer.valueOf(Integer.MIN_VALUE)); m.visitInsn(Opcodes.IAND); m.visitJumpInsn(Opcodes.IFEQ, createStateInstance); m.visitVarInsn(Opcodes.ALOAD, continuationIndex); m.visitInsn(Opcodes.DUP); m.visitFieldInsn(Opcodes.GETFIELD, "ExampleKt$example$1", "label", "I"); m.visitLdcInsn(Integer.valueOf(Integer.MIN_VALUE)); m.visitInsn(Opcodes.ISUB); m.visitFieldInsn(Opcodes.PUTFIELD, "ExampleKt$example$1", "label", "I"); final Label afterCoroutineStateCreated = new Label(); m.visitJumpInsn(Opcodes.GOTO, afterCoroutineStateCreated); m.visitLabel(createStateInstance); m.visitTypeInsn(Opcodes.NEW, "ExampleKt$example$1"); m.visitInsn(Opcodes.DUP); m.visitVarInsn(Opcodes.ALOAD, continuationArgumentIndex); m.visitMethodInsn(Opcodes.INVOKESPECIAL, "ExampleKt$example$1", "<init>", "(Lkotlin/coroutines/Continuation;)V", false); m.visitVarInsn(Opcodes.ASTORE, continuationIndex); m.visitLabel(afterCoroutineStateCreated); m.visitVarInsn(Opcodes.ALOAD, continuationIndex); m.visitFieldInsn(Opcodes.GETFIELD, "ExampleKt$example$1", "result", "Ljava/lang/Object;"); m.visitVarInsn(Opcodes.ASTORE, 1); m.visitMethodInsn(Opcodes.INVOKESTATIC, "kotlin/coroutines/intrinsics/IntrinsicsKt", "getCOROUTINE_SUSPENDED", "()Ljava/lang/Object;", false); // line of "fun" m.visitVarInsn(Opcodes.ASTORE, 3); m.visitVarInsn(Opcodes.ALOAD, continuationIndex); m.visitFieldInsn(Opcodes.GETFIELD, "ExampleKt$example$1", "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 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, 3); final Label continuationLabelAfterLoadedResult = new Label(); m.visitJumpInsn(Opcodes.IF_ACMPNE, continuationLabelAfterLoadedResult); // line of "fun" m.visitVarInsn(Opcodes.ALOAD, 3); m.visitInsn(Opcodes.ARETURN); m.visitLabel(state1); { 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); }
From source file:org.jacoco.core.internal.analysis.filter.KotlinDefaultArgumentsFilterTest.java
License:Open Source License
private static MethodNode createMethod(final int access, final String name, final String descriptor) { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, access, name, descriptor, null, null); m.visitVarInsn(Opcodes.ILOAD, 2);//w w w . j a v a 2 s. co m m.visitInsn(Opcodes.ICONST_1); m.visitInsn(Opcodes.IAND); final Label label = new Label(); m.visitJumpInsn(Opcodes.IFEQ, label); // default argument m.visitLdcInsn(Integer.valueOf(42)); m.visitVarInsn(Opcodes.ISTORE, 1); m.visitLabel(label); m.visitVarInsn(Opcodes.ALOAD, 0); m.visitVarInsn(Opcodes.ILOAD, 1); m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Target", "origin", "(I)V", false); m.visitInsn(Opcodes.RETURN); return m; }
From source file:org.jacoco.core.internal.analysis.filter.KotlinDefaultArgumentsFilterTest.java
License:Open Source License
/** * <pre>//w ww .ja v a 2s. c om * open class Open { * open fun foo(a: Int = 42) { * } * } * </pre> */ @Test public void should_filter_open_functions() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "foo$default", "(LOpen;IILjava/lang/Object;)V", null, null); context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); { m.visitVarInsn(Opcodes.ALOAD, 3); final Label label = new Label(); m.visitJumpInsn(Opcodes.IFNULL, label); m.visitTypeInsn(Opcodes.NEW, "java/lang/UnsupportedOperationException"); m.visitInsn(Opcodes.DUP); m.visitLdcInsn("Super calls with default arguments not supported in this target, function: foo"); m.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>", "(Ljava/lang/String;)V", false); m.visitInsn(Opcodes.ATHROW); m.visitLabel(label); } { m.visitVarInsn(Opcodes.ILOAD, 2); m.visitInsn(Opcodes.ICONST_1); m.visitInsn(Opcodes.IAND); final Label label = new Label(); m.visitJumpInsn(Opcodes.IFEQ, label); // default argument m.visitLdcInsn(Integer.valueOf(42)); m.visitVarInsn(Opcodes.ISTORE, 1); m.visitLabel(label); m.visitVarInsn(Opcodes.ALOAD, 0); m.visitVarInsn(Opcodes.ILOAD, 1); m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Open", "foo", "(I)V", false); m.visitInsn(Opcodes.RETURN); } filter.filter(m, context, output); assertIgnored(new Range(m.instructions.getFirst(), m.instructions.get(6)), new Range(m.instructions.get(11), m.instructions.get(11))); }
From source file:org.jacoco.core.internal.analysis.filter.KotlinDefaultArgumentsFilterTest.java
License:Open Source License
/** * <pre>/*from ww w . j a va 2 s . c o m*/ * class C(a: Int = 42) * </pre> */ @Test public void should_filter_constructors() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "<init>", "(IILkotlin/jvm/internal/DefaultConstructorMarker;)V", null, null); context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); m.visitVarInsn(Opcodes.ILOAD, 2); m.visitInsn(Opcodes.ICONST_1); m.visitInsn(Opcodes.IAND); Label label = new Label(); m.visitJumpInsn(Opcodes.IFEQ, label); // default argument m.visitLdcInsn(Integer.valueOf(42)); m.visitVarInsn(Opcodes.ISTORE, 1); m.visitLabel(label); m.visitVarInsn(Opcodes.ALOAD, 0); m.visitVarInsn(Opcodes.ILOAD, 1); m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Owner", "<init>", "(I)V", false); m.visitInsn(Opcodes.RETURN); filter.filter(m, context, output); assertIgnored(new Range(m.instructions.get(3), m.instructions.get(3))); }
From source file:org.jacoco.core.internal.analysis.filter.KotlinDefaultArgumentsFilterTest.java
License:Open Source License
/** * <pre>/* w w w . java 2 s. c o m*/ * data class C(val x: Long = 42) * </pre> */ @Test public void should_filter_methods_with_parameters_that_consume_two_slots() { final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, Opcodes.ACC_SYNTHETIC, "<init>", "(JILkotlin/jvm/internal/DefaultConstructorMarker;)V", null, null); context.classAnnotations.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC); m.visitVarInsn(Opcodes.ILOAD, 3); m.visitInsn(Opcodes.ICONST_1); m.visitInsn(Opcodes.IAND); final Label label = new Label(); m.visitJumpInsn(Opcodes.IFEQ, label); // default argument m.visitLdcInsn(Integer.valueOf(42)); m.visitVarInsn(Opcodes.ISTORE, 1); m.visitLabel(label); m.visitVarInsn(Opcodes.ALOAD, 0); m.visitVarInsn(Opcodes.ILOAD, 1); m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Owner", "<init>", "(J)V", false); m.visitInsn(Opcodes.RETURN); filter.filter(m, context, output); assertIgnored(new Range(m.instructions.get(3), m.instructions.get(3))); }
From source file:org.jacoco.core.internal.instr.FrameTracker.java
License:Open Source License
@Override public void visitInsn(final int opcode) { final Object t1, t2, t3, t4; switch (opcode) { case Opcodes.NOP: case Opcodes.RETURN: break;/*from ww w . j a v a 2s . c o m*/ case Opcodes.ARETURN: case Opcodes.ATHROW: case Opcodes.FRETURN: case Opcodes.IRETURN: case Opcodes.MONITORENTER: case Opcodes.MONITOREXIT: case Opcodes.POP: pop(1); break; case Opcodes.DRETURN: case Opcodes.LRETURN: case Opcodes.POP2: pop(2); break; case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.FASTORE: case Opcodes.IASTORE: case Opcodes.SASTORE: pop(3); break; case Opcodes.LASTORE: case Opcodes.DASTORE: pop(4); break; case Opcodes.ICONST_M1: case Opcodes.ICONST_0: case Opcodes.ICONST_1: case Opcodes.ICONST_2: case Opcodes.ICONST_3: case Opcodes.ICONST_4: case Opcodes.ICONST_5: push(Opcodes.INTEGER); break; case Opcodes.ARRAYLENGTH: case Opcodes.F2I: case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: case Opcodes.INEG: pop(1); push(Opcodes.INTEGER); break; case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.D2I: case Opcodes.FCMPG: case Opcodes.FCMPL: case Opcodes.IADD: case Opcodes.IALOAD: case Opcodes.IAND: case Opcodes.IDIV: case Opcodes.IMUL: case Opcodes.IOR: case Opcodes.IREM: case Opcodes.ISHL: case Opcodes.ISHR: case Opcodes.ISUB: case Opcodes.IUSHR: case Opcodes.IXOR: case Opcodes.L2I: case Opcodes.SALOAD: pop(2); push(Opcodes.INTEGER); break; case Opcodes.DCMPG: case Opcodes.DCMPL: case Opcodes.LCMP: pop(4); push(Opcodes.INTEGER); break; case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: push(Opcodes.FLOAT); break; case Opcodes.FNEG: case Opcodes.I2F: pop(1); push(Opcodes.FLOAT); break; case Opcodes.D2F: case Opcodes.FADD: case Opcodes.FALOAD: case Opcodes.FDIV: case Opcodes.FMUL: case Opcodes.FREM: case Opcodes.FSUB: case Opcodes.L2F: pop(2); push(Opcodes.FLOAT); break; case Opcodes.LCONST_0: case Opcodes.LCONST_1: push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.F2L: case Opcodes.I2L: pop(1); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.D2L: case Opcodes.LALOAD: case Opcodes.LNEG: pop(2); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.LSHL: case Opcodes.LSHR: case Opcodes.LUSHR: pop(3); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.LADD: case Opcodes.LAND: case Opcodes.LDIV: case Opcodes.LMUL: case Opcodes.LOR: case Opcodes.LREM: case Opcodes.LSUB: case Opcodes.LXOR: pop(4); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.DCONST_0: case Opcodes.DCONST_1: push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.F2D: case Opcodes.I2D: pop(1); push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.DALOAD: case Opcodes.DNEG: case Opcodes.L2D: pop(2); push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.DADD: case Opcodes.DDIV: case Opcodes.DMUL: case Opcodes.DREM: case Opcodes.DSUB: pop(4); push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.ACONST_NULL: push(Opcodes.NULL); break; case Opcodes.AALOAD: pop(1); t1 = pop(); push(Type.getType(((String) t1).substring(1))); break; case Opcodes.DUP: t1 = pop(); push(t1); push(t1); break; case Opcodes.DUP_X1: t1 = pop(); t2 = pop(); push(t1); push(t2); push(t1); break; case Opcodes.DUP_X2: t1 = pop(); t2 = pop(); t3 = pop(); push(t1); push(t3); push(t2); push(t1); break; case Opcodes.DUP2: t1 = pop(); t2 = pop(); push(t2); push(t1); push(t2); push(t1); break; case Opcodes.DUP2_X1: t1 = pop(); t2 = pop(); t3 = pop(); push(t2); push(t1); push(t3); push(t2); push(t1); break; case Opcodes.DUP2_X2: t1 = pop(); t2 = pop(); t3 = pop(); t4 = pop(); push(t2); push(t1); push(t4); push(t3); push(t2); push(t1); break; case Opcodes.SWAP: t1 = pop(); t2 = pop(); push(t1); push(t2); break; default: throw new IllegalArgumentException(); } mv.visitInsn(opcode); }