List of usage examples for org.objectweb.asm Opcodes ISUB
int ISUB
To view the source code for org.objectweb.asm Opcodes ISUB.
Click Source Link
From source file:org.jacoco.core.internal.analysis.filter.KotlinCoroutineFilterTest.java
License:Open Source License
/** * <pre>/* w ww.ja v a 2 s. c om*/ * 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.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 av a 2 s . co 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); }
From source file:org.jboss.byteman.rule.expression.ArithmeticExpression.java
License:Open Source License
public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException { // make sure we are at the right source line compileContext.notifySourceLine(line); int currentStack = compileContext.getStackCount(); int expectedStack = 0; Expression operand0 = getOperand(0); Expression operand1 = getOperand(1); Type type0 = operand0.getType(); Type type1 = operand1.getType(); // compile lhs -- it adds 1 or 2 to the stack height operand0.compile(mv, compileContext); // do any required type conversion compileTypeConversion(type0, type, mv, compileContext); // compile rhs -- it adds 1 or 2 to the stack height operand1.compile(mv, compileContext); // do any required type conversion compileTypeConversion(type1, type, mv, compileContext); try {//from w ww . jav a 2s .co m // n.b. be careful with characters here if (type == type.B || type == type.S || type == type.C || type == type.I) { // TODO we should probably only respect the byte, short and char types for + and - // TODO also need to decide how to handle divide by zero expectedStack = 1; switch (oper) { case MUL: mv.visitInsn(Opcodes.IMUL); break; case DIV: mv.visitInsn(Opcodes.IDIV); break; case PLUS: mv.visitInsn(Opcodes.IADD); break; case MINUS: mv.visitInsn(Opcodes.ISUB); break; case MOD: mv.visitInsn(Opcodes.IREM); break; default: // should never happen throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper); } // now coerce back to appropriate type if (type == type.B) { mv.visitInsn(Opcodes.I2B); } else if (type == type.S) { mv.visitInsn(Opcodes.I2S); } else if (type == type.C) { mv.visitInsn(Opcodes.I2C); } // else if (type == type.I) { do nothing } // ok, we popped two bytes but added one compileContext.addStackCount(-1); } else if (type == type.J) { expectedStack = 2; switch (oper) { case MUL: mv.visitInsn(Opcodes.LMUL); break; case DIV: mv.visitInsn(Opcodes.LDIV); break; case PLUS: mv.visitInsn(Opcodes.LADD); break; case MINUS: mv.visitInsn(Opcodes.LSUB); break; case MOD: mv.visitInsn(Opcodes.LREM); break; default: // should never happen throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper); } // ok, we popped four bytes but added two compileContext.addStackCount(-2); } else if (type == type.F) { expectedStack = 1; switch (oper) { case MUL: mv.visitInsn(Opcodes.FMUL); break; case DIV: mv.visitInsn(Opcodes.FDIV); break; case PLUS: mv.visitInsn(Opcodes.FADD); break; case MINUS: mv.visitInsn(Opcodes.FSUB); break; case MOD: mv.visitInsn(Opcodes.FREM); break; default: // should never happen throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper); } // ok, we popped two bytes but added one compileContext.addStackCount(-1); } else if (type == type.D) { expectedStack = 2; switch (oper) { case MUL: mv.visitInsn(Opcodes.DMUL); break; case DIV: mv.visitInsn(Opcodes.DDIV); break; case PLUS: mv.visitInsn(Opcodes.DADD); break; case MINUS: mv.visitInsn(Opcodes.DSUB); break; case MOD: mv.visitInsn(Opcodes.DREM); break; default: // should never happen throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper); } // ok, we popped four bytes but added two compileContext.addStackCount(-2); } else { throw new CompileException( "ArithmeticExpression.compile : unexpected result type " + type.getName()); } } catch (CompileException e) { throw e; } catch (Exception e) { throw new CompileException("ArithmeticExpression.compile : unexpected exception for operation " + token + getPos() + " in rule " + rule.getName(), e); } // check stack heights if (compileContext.getStackCount() != currentStack + expectedStack) { throw new CompileException("ArithmeticExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + (currentStack + expectedStack)); } }
From source file:org.lambdamatic.analyzer.ast.LambdaExpressionReader.java
License:Open Source License
/** * Reads the current {@link InsnNode} instruction and returns a {@link Statement} or {@code null} * if the instruction is not a full statement (in that case, the instruction is stored in the * given Expression {@link Stack}).//from www . j a va 2 s . co m * * @param insnNode the instruction to read * @param expressionStack the expression stack to put on or pop from. * @param localVariables the local variables * @return a {@link List} of {@link Statement} or empty list if no {@link Statement} was created * after reading the current instruction. * @see <a href="https://en.wikipedia.org/wiki/Java_bytecode_instruction_listings">Java bytcode * instruction listings on Wikipedia</a> */ private List<Statement> readInstruction(final InsnCursor insnCursor, final Stack<Expression> expressionStack, final List<CapturedArgument> capturedArguments, final LocalVariables localVariables) { final List<Statement> statements = new ArrayList<>(); final AbstractInsnNode insnNode = insnCursor.getCurrent(); switch (insnNode.getOpcode()) { // return a reference from a method case Opcodes.ARETURN: // return an integer from a method case Opcodes.IRETURN: statements.add(new ReturnStatement(expressionStack.pop())); break; // return void from method case Opcodes.RETURN: // wrap all pending expressions into ExpressionStatements while (!expressionStack.isEmpty()) { final Expression pendingExpression = expressionStack.pop(); statements.add(new ExpressionStatement(pendingExpression)); } break; // push a null reference onto the stack case Opcodes.ACONST_NULL: expressionStack.add(new NullLiteral()); break; // load the int value 0 onto the stack case Opcodes.ICONST_0: // applies for byte, short, int and boolean expressionStack.add(new NumberLiteral(0)); break; // load the int value 1 onto the stack case Opcodes.ICONST_1: // applies for byte, short, int and boolean expressionStack.add(new NumberLiteral(1)); break; // load the int value 2 onto the stack case Opcodes.ICONST_2: expressionStack.add(new NumberLiteral(2)); break; // load the int value 3 onto the stack case Opcodes.ICONST_3: expressionStack.add(new NumberLiteral(3)); break; // load the int value 4 onto the stack case Opcodes.ICONST_4: expressionStack.add(new NumberLiteral(4)); break; // load the int value 5 onto the stack case Opcodes.ICONST_5: expressionStack.add(new NumberLiteral(5)); break; // push the long 0 onto the stack case Opcodes.LCONST_0: expressionStack.add(new NumberLiteral(0L)); break; // push the long 1 onto the stack case Opcodes.LCONST_1: expressionStack.add(new NumberLiteral(1L)); break; // push the 0.0f onto the stack case Opcodes.FCONST_0: expressionStack.add(new NumberLiteral(0f)); break; // push the 1.0f onto the stack case Opcodes.FCONST_1: expressionStack.add(new NumberLiteral(1f)); break; // push the 2.0f onto the stack case Opcodes.FCONST_2: expressionStack.add(new NumberLiteral(2f)); break; // push the constant 0.0 onto the stack case Opcodes.DCONST_0: expressionStack.add(new NumberLiteral(0d)); break; // push the constant 1.0 onto the stack case Opcodes.DCONST_1: expressionStack.add(new NumberLiteral(1d)); break; // compare two longs values case Opcodes.LCMP: // compare two doubles case Opcodes.DCMPL: // compare two doubles case Opcodes.DCMPG: // compare two floats case Opcodes.FCMPL: // compare two floats case Opcodes.FCMPG: statements.addAll( readJumpInstruction(insnCursor.next(), expressionStack, capturedArguments, localVariables)); break; // add 2 ints case Opcodes.IADD: expressionStack.add(readOperation(Operator.ADD, expressionStack)); break; // int subtract case Opcodes.ISUB: expressionStack.add(readOperation(Operator.SUBTRACT, expressionStack)); break; // multiply 2 integers case Opcodes.IMUL: expressionStack.add(readOperation(Operator.MULTIPLY, expressionStack)); break; // divide 2 integers case Opcodes.IDIV: expressionStack.add(readOperation(Operator.DIVIDE, expressionStack)); break; // negate int case Opcodes.INEG: expressionStack.add(inverseInteger(expressionStack)); break; // discard the top value on the stack case Opcodes.POP: statements.add(new ExpressionStatement(expressionStack.pop())); break; // duplicate the value on top of the stack case Opcodes.DUP: expressionStack.push(expressionStack.peek()); break; // insert a copy of the top value into the stack two values from the top. case Opcodes.DUP_X1: expressionStack.add(expressionStack.size() - 2, expressionStack.peek()); break; // store into a reference in an array case Opcodes.AASTORE: readArrayStoreInstruction(insnNode, expressionStack); break; // converts Float to Double -> ignored. case Opcodes.F2D: break; default: throw new AnalyzeException( "Bytecode instruction with OpCode '" + insnNode.getOpcode() + "' is not supported."); } return statements; }
From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java
License:Open Source License
private static final int getBinaryIntOpCode(String op) { switch (op.charAt(0)) { case '-': return Opcodes.ISUB; case '+': return Opcodes.IADD; case '%': return Opcodes.IREM; case '*': return Opcodes.IMUL; case '/': return Opcodes.IDIV; case '&': return Opcodes.IAND; case '|': return Opcodes.IOR; case '^': return Opcodes.IXOR; case '<': return Opcodes.ISHL; case '>': return op.equals(">>>") ? Opcodes.IUSHR : Opcodes.ISHR; default://from ww w.ja v a 2 s. com throw new IllegalArgumentException("Invalid operand " + op); } }
From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.AODMutator1.java
License:Apache License
@Override public void visitInsn(int opcode) { switch (opcode) { case Opcodes.IADD: case Opcodes.ISUB: case Opcodes.IMUL: case Opcodes.IDIV: case Opcodes.IREM: case Opcodes.FADD: case Opcodes.FSUB: case Opcodes.FMUL: case Opcodes.FDIV: case Opcodes.FREM: if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) { mv.visitInsn(Opcodes.POP);//from w w w .jav a 2 s . co m } else { mv.visitInsn(opcode); } break; case Opcodes.LADD: case Opcodes.LSUB: case Opcodes.LMUL: case Opcodes.LDIV: case Opcodes.LREM: case Opcodes.DADD: case Opcodes.DSUB: case Opcodes.DMUL: case Opcodes.DDIV: case Opcodes.DREM: if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) { mv.visitInsn(Opcodes.POP2); } else { mv.visitInsn(opcode); } break; default: mv.visitInsn(opcode); break; } }
From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.AODMutator2.java
License:Apache License
@Override public void visitInsn(int opcode) { switch (opcode) { case Opcodes.IADD: case Opcodes.ISUB: case Opcodes.IMUL: case Opcodes.IDIV: case Opcodes.IREM: if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) { int storage = this.newLocal(Type.INT_TYPE); mv.visitVarInsn(Opcodes.ISTORE, storage); mv.visitInsn(Opcodes.POP);//from www . j av a 2 s.c om mv.visitVarInsn(Opcodes.ILOAD, storage); /* * Alternative : mv.visitInsn(Opcodes.SWAP); * mv.visitInsn(Opcodes.POP); * mv.visitVarInsn(Opcodes.ILOAD,storage); */ } else { mv.visitInsn(opcode); } break; case Opcodes.FADD: case Opcodes.FSUB: case Opcodes.FMUL: case Opcodes.FDIV: case Opcodes.FREM: if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) { int storage = this.newLocal(Type.FLOAT_TYPE); mv.visitVarInsn(Opcodes.FSTORE, storage); mv.visitInsn(Opcodes.POP); mv.visitVarInsn(Opcodes.FLOAD, storage); } else { mv.visitInsn(opcode); } break; case Opcodes.LADD: case Opcodes.LSUB: case Opcodes.LMUL: case Opcodes.LDIV: case Opcodes.LREM: if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) { int storage = this.newLocal(Type.LONG_TYPE); mv.visitVarInsn(Opcodes.LSTORE, storage); mv.visitInsn(Opcodes.POP2); mv.visitVarInsn(Opcodes.LLOAD, storage); } else { mv.visitInsn(opcode); } break; case Opcodes.DADD: case Opcodes.DSUB: case Opcodes.DMUL: case Opcodes.DDIV: case Opcodes.DREM: if (this.shouldMutate(OpcodeToType.typeOfOpcode(opcode))) { int storage = this.newLocal(Type.DOUBLE_TYPE); mv.visitVarInsn(Opcodes.DSTORE, storage); mv.visitInsn(Opcodes.POP2); mv.visitVarInsn(Opcodes.DLOAD, storage); } else { mv.visitInsn(opcode); } break; default: mv.visitInsn(opcode); break; } }
From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator2.java
License:Apache License
@Override public void visitInsn(final int opcode) { // I F L D + BS switch (opcode) { case Opcodes.IALOAD: if (this.shouldMutate("Decremented (a--) integer array field")) { // stack = [array] [index] , wanted to perform an IALOAD mv.visitInsn(Opcodes.DUP2); // stack = [array] [index] [array] [index] mv.visitInsn(opcode); // stack = [array] [index] [array(index)] mv.visitInsn(Opcodes.DUP_X2); // stack = [array(index)] [array] [index] [array(index)] mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); // stack = [array(index)] [array] [index] [array(index)-1] mv.visitInsn(Opcodes.IASTORE); } else {//from w ww . j a va 2 s . c o m mv.visitInsn(opcode); } break; case Opcodes.FALOAD: if (this.shouldMutate("Decremented (a--) float array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.FCONST_1); mv.visitInsn(Opcodes.FSUB); mv.visitInsn(Opcodes.FASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.LALOAD: if (this.shouldMutate("Decremented (a--) long array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.LCONST_1); mv.visitInsn(Opcodes.LSUB); mv.visitInsn(Opcodes.LASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.DALOAD: if (this.shouldMutate("Decremented (a--) double array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.DCONST_1); mv.visitInsn(Opcodes.DSUB); mv.visitInsn(Opcodes.DASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.BALOAD: if (this.shouldMutate("Decremented (a--) byte array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.I2B); mv.visitInsn(Opcodes.BASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.SALOAD: if (this.shouldMutate("Decremented (a--) short array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.I2S); mv.visitInsn(Opcodes.SASTORE); } else { mv.visitInsn(opcode); } break; default: mv.visitInsn(opcode); break; } }
From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator2.java
License:Apache License
@Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { // GETFIELD I,F,L,D + B,S if ((opcode == Opcodes.GETFIELD)) { if (desc.equals("I")) { if (this.shouldMutate("Decremented (a--) integer field " + name)) { // stack = [this] mv.visitInsn(Opcodes.DUP); // stack = [this] [this] mv.visitFieldInsn(opcode, owner, name, desc); // stack = [this] [this.field] mv.visitInsn(Opcodes.DUP_X1); // stack = [this.field] [this] [this.field] mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc); return; }/*from w w w . j ava2 s . c o m*/ } if (desc.equals("F")) { if (this.shouldMutate("Decremented (a--) float field " + name)) { mv.visitInsn(Opcodes.DUP); mv.visitFieldInsn(opcode, owner, name, desc); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.FCONST_1); mv.visitInsn(Opcodes.FSUB); mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc); return; } } if (desc.equals("J")) { if (this.shouldMutate("Decremented (a--) long field " + name)) { mv.visitInsn(Opcodes.DUP); mv.visitFieldInsn(opcode, owner, name, desc); mv.visitInsn(Opcodes.DUP2_X1); mv.visitInsn(Opcodes.LCONST_1); mv.visitInsn(Opcodes.LSUB); mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc); return; } } if (desc.equals("D")) { if (this.shouldMutate("Decremented (a--) double field " + name)) { mv.visitInsn(Opcodes.DUP); mv.visitFieldInsn(opcode, owner, name, desc); mv.visitInsn(Opcodes.DUP2_X1); mv.visitInsn(Opcodes.DCONST_1); mv.visitInsn(Opcodes.DSUB); mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc); return; } } if (desc.equals("B")) { if (this.shouldMutate("Decremented (a--) byte field " + name)) { mv.visitInsn(Opcodes.DUP); mv.visitFieldInsn(opcode, owner, name, desc); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.I2B); mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc); return; } } if (desc.equals("S")) { if (this.shouldMutate("Decremented (a--) short field " + name)) { mv.visitInsn(Opcodes.DUP); mv.visitFieldInsn(opcode, owner, name, desc); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.I2S); mv.visitFieldInsn(Opcodes.PUTFIELD, owner, name, desc); return; } } } // GETSTATIC I,F,L,D + B,S if (opcode == Opcodes.GETSTATIC) { if (desc.equals("I")) { if (this.shouldMutate("Decremented (a--) static integer field " + name)) { mv.visitFieldInsn(opcode, owner, name, desc); // stack = [this.sfield] mv.visitInsn(Opcodes.DUP); // stack = [this.sfield] [this.sfield] mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); // stack = [this.sfield] [this.sfield -1] mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc); return; } } if (desc.equals("F")) { if (this.shouldMutate("Decremented (a--) static float field " + name)) { mv.visitFieldInsn(opcode, owner, name, desc); mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.FCONST_1); mv.visitInsn(Opcodes.FSUB); mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc); return; } } if (desc.equals("J")) { if (this.shouldMutate("Decremented (a--) static long field " + name)) { mv.visitFieldInsn(opcode, owner, name, desc); mv.visitInsn(Opcodes.DUP2); mv.visitInsn(Opcodes.LCONST_1); mv.visitInsn(Opcodes.LSUB); mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc); return; } } if (desc.equals("D")) { if (this.shouldMutate("Decremented (a--) static double field " + name)) { mv.visitFieldInsn(opcode, owner, name, desc); mv.visitInsn(Opcodes.DUP2); mv.visitInsn(Opcodes.DCONST_1); mv.visitInsn(Opcodes.DSUB); mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc); return; } } if (desc.equals("B")) { if (this.shouldMutate("Decremented (a--) static byte field " + name)) { mv.visitFieldInsn(opcode, owner, name, desc); mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.I2B); mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc); return; } } if (desc.equals("S")) { if (this.shouldMutate("Decremented (a--) static short field " + name)) { mv.visitFieldInsn(opcode, owner, name, desc); mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.I2S); mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc); return; } } } mv.visitFieldInsn(opcode, owner, name, desc); }
From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator4.java
License:Apache License
@Override public void visitInsn(final int opcode) { // I F L D + BS switch (opcode) { case Opcodes.IALOAD: if (this.shouldMutate("Decremented (--a) integer array field")) { // stack = [array] [index] mv.visitInsn(Opcodes.DUP2);// w w w.ja v a 2s . com // stack = [array] [index] [array] [index] mv.visitInsn(opcode); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); // stack = [array] [index] [array(index)-1] mv.visitInsn(Opcodes.DUP_X2); // stack = [array(index)-1] [array] [index] [array(index)-1] mv.visitInsn(Opcodes.IASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.FALOAD: if (this.shouldMutate("Decremented (--a) float array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.FCONST_1); mv.visitInsn(Opcodes.FSUB); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.FASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.LALOAD: if (this.shouldMutate("Decremented (--a) long array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.LCONST_1); mv.visitInsn(Opcodes.LSUB); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.LASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.DALOAD: if (this.shouldMutate("Decremented (--a) double array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DCONST_1); mv.visitInsn(Opcodes.DSUB); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.DASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.BALOAD: if (this.shouldMutate("Decremented (--a) byte array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.I2B); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.BASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.SALOAD: if (this.shouldMutate("Decremented (--a) short array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.I2S); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.SASTORE); } else { mv.visitInsn(opcode); } break; default: mv.visitInsn(opcode); break; } }