List of usage examples for org.objectweb.asm Opcodes IADD
int IADD
To view the source code for org.objectweb.asm Opcodes IADD.
Click Source Link
From source file:org.evosuite.instrumentation.ErrorConditionChecker.java
License:Open Source License
public static int underflowDistance(int op1, int op2, int opcode) { switch (opcode) { case Opcodes.IADD: int result = underflowDistanceAdd(op1, op2); logger.debug("U: {} + {} = {} -> {}", op1, op2, op1 + op2, result); return result; case Opcodes.ISUB: return underflowDistanceSub(op1, op2); case Opcodes.IMUL: return underflowDistanceMul(op1, op2); }/*from ww w . j av a 2 s . com*/ return Integer.MAX_VALUE; }
From source file:org.evosuite.instrumentation.mutation.InsertUnaryOperator.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w . j a v a 2 s . c om public List<Mutation> apply(MethodNode mn, String className, String methodName, BytecodeInstruction instruction, Frame frame) { // TODO - need to keep InsnList in Mutation, not only Instruction? // Mutation: Insert an INEG _after_ an iload List<Mutation> mutations = new LinkedList<Mutation>(); List<InsnList> mutationCode = new LinkedList<InsnList>(); List<String> descriptions = new LinkedList<String>(); if (instruction.getASMNode() instanceof VarInsnNode) { try { InsnList mutation = new InsnList(); VarInsnNode node = (VarInsnNode) instruction.getASMNode(); // insert mutation into bytecode with conditional mutation.add(new VarInsnNode(node.getOpcode(), node.var)); mutation.add(new InsnNode(getNegation(node.getOpcode()))); mutationCode.add(mutation); if (!mn.localVariables.isEmpty()) descriptions.add("Negation of " + getName(mn, node)); else descriptions.add("Negation"); if (node.getOpcode() == Opcodes.ILOAD) { if (frame.getStack(frame.getStackSize() - 1) != BooleanValueInterpreter.BOOLEAN_VALUE) { mutation = new InsnList(); mutation.add(new IincInsnNode(node.var, 1)); mutation.add(new VarInsnNode(node.getOpcode(), node.var)); if (!mn.localVariables.isEmpty()) descriptions.add("IINC 1 " + getName(mn, node)); else descriptions.add("IINC 1"); mutationCode.add(mutation); mutation = new InsnList(); mutation.add(new IincInsnNode(node.var, -1)); mutation.add(new VarInsnNode(node.getOpcode(), node.var)); if (!mn.localVariables.isEmpty()) descriptions.add("IINC -1 " + getName(mn, node)); else descriptions.add("IINC -1"); mutationCode.add(mutation); } } } catch (VariableNotFoundException e) { logger.info("Could not find variable: " + e); return new ArrayList<Mutation>(); } } else { InsnList mutation = new InsnList(); FieldInsnNode node = (FieldInsnNode) instruction.getASMNode(); Type type = Type.getType(node.desc); mutation.add(new FieldInsnNode(node.getOpcode(), node.owner, node.name, node.desc)); mutation.add(new InsnNode(getNegation(type))); descriptions.add("Negation"); mutationCode.add(mutation); if (type == Type.INT_TYPE) { mutation = new InsnList(); mutation.add(new FieldInsnNode(node.getOpcode(), node.owner, node.name, node.desc)); mutation.add(new InsnNode(Opcodes.ICONST_1)); mutation.add(new InsnNode(Opcodes.IADD)); descriptions.add("+1"); mutationCode.add(mutation); mutation = new InsnList(); mutation.add(new FieldInsnNode(node.getOpcode(), node.owner, node.name, node.desc)); mutation.add(new InsnNode(Opcodes.ICONST_M1)); mutation.add(new InsnNode(Opcodes.IADD)); descriptions.add("-1"); mutationCode.add(mutation); } } int i = 0; for (InsnList mutation : mutationCode) { // insert mutation into pool Mutation mutationObject = MutationPool.addMutation(className, methodName, NAME + " " + descriptions.get(i++), instruction, mutation, Mutation.getDefaultInfectionDistance()); mutations.add(mutationObject); } return mutations; }
From source file:org.evosuite.instrumentation.mutation.ReplaceArithmeticOperator.java
License:Open Source License
/** * <p>calculate</p>/*from ww w . j a va 2 s. c o 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.IADD: return x + y; case Opcodes.ISUB: return x - y; case Opcodes.IMUL: return x * y; case Opcodes.IDIV: return x / y; case Opcodes.IREM: return x % y; } throw new RuntimeException("Unknown integer opcode: " + opcode); }
From source file:org.evosuite.javaagent.ErrorConditionCheckerTest.java
License:Open Source License
@Test public void testIntAddOverflow() { int distance = ErrorConditionChecker.overflowDistance(Integer.MAX_VALUE, 2, Opcodes.IADD); assertTrue(distance <= 0);/*from w w w. j a va 2 s .c om*/ distance = ErrorConditionChecker.overflowDistance(Integer.MAX_VALUE, Integer.MAX_VALUE, Opcodes.IADD); assertTrue(distance <= 0); distance = ErrorConditionChecker.overflowDistance(Integer.MAX_VALUE, 1, Opcodes.IADD); assertTrue(distance <= 0); distance = ErrorConditionChecker.overflowDistance(Integer.MAX_VALUE, 0, Opcodes.IADD); assertEquals(1, distance); distance = ErrorConditionChecker.overflowDistance(0, Integer.MAX_VALUE, Opcodes.IADD); assertEquals(1, distance); distance = ErrorConditionChecker.overflowDistance(Integer.MIN_VALUE, Integer.MAX_VALUE, Opcodes.IADD); assertEquals(Integer.MAX_VALUE, distance); int distance1 = ErrorConditionChecker.overflowDistance(10, 10, Opcodes.IADD); assertTrue("Expected value greater 0 but got " + distance1, distance1 > 0); int distance2 = ErrorConditionChecker.overflowDistance(1000, 1000, Opcodes.IADD); assertTrue("Expected value greater 0 but got " + distance2, distance2 > 0); assertTrue("Invalid ranking: " + distance1 + ", " + distance2, distance1 > distance2); distance1 = ErrorConditionChecker.overflowDistance(100, -100, Opcodes.IADD); assertTrue("Expected value greater 0 but got " + distance1, distance1 > 0); distance2 = ErrorConditionChecker.overflowDistance(-100, 100, Opcodes.IADD); assertTrue("Expected value greater 0 but got " + distance2, distance2 > 0); assertEquals(distance1, distance2); int distance3 = ErrorConditionChecker.overflowDistance(-100, 10, Opcodes.IADD); assertTrue("Expected value greater 0 but got " + distance3, distance3 > 0); assertEquals(distance1, distance2); distance3 = ErrorConditionChecker.overflowDistance(-50, 10, Opcodes.IADD); assertTrue("Expected value greater 0 but got " + distance3, distance3 > 0); assertTrue(distance3 < distance2); }
From source file:org.evosuite.javaagent.ErrorConditionCheckerTest.java
License:Open Source License
@Test public void testIntAddUnderflow() { int distance = ErrorConditionChecker.underflowDistance(Integer.MIN_VALUE, -1, Opcodes.IADD); assertTrue(distance <= 0);/*w ww . jav a 2 s .c o m*/ distance = ErrorConditionChecker.underflowDistance(-1, Integer.MIN_VALUE, Opcodes.IADD); assertTrue(distance <= 0); distance = ErrorConditionChecker.underflowDistance(Integer.MIN_VALUE / 2, Integer.MIN_VALUE / 2, Opcodes.IADD); assertEquals(1, distance); distance = ErrorConditionChecker.underflowDistance((Integer.MIN_VALUE / 2) - 1, (Integer.MIN_VALUE / 2) - 1, Opcodes.IADD); assertTrue(distance <= 0); distance = ErrorConditionChecker.underflowDistance((Integer.MIN_VALUE + 1) / 2, (Integer.MIN_VALUE + 1) / 2, Opcodes.IADD); assertTrue(distance > 0); int distance1 = ErrorConditionChecker.underflowDistance(10, 10, Opcodes.IADD); assertTrue("Expected value greater 0 but got " + distance1, distance1 > 0); int distance2 = ErrorConditionChecker.underflowDistance(1000, 1000, Opcodes.IADD); assertTrue("Expected value greater 0 but got " + distance2, distance2 > 0); assertTrue("Invalid ranking: " + distance1 + ", " + distance2, distance1 < distance2); }
From source file:org.formulacompiler.compiler.internal.bytecode.ExpressionCompilerForNumbers_Base.java
License:Open Source License
@Override protected final void compileCount(ExpressionNodeForCount _node) throws CompilerException { final GeneratorAdapter mv = mv(); mv.push(_node.staticValueCount());/*from w w w . jav a2s .c om*/ final SectionModel[] subs = _node.subSectionModels(); final int[] cnts = _node.subSectionStaticValueCounts(); for (int i = 0; i < subs.length; i++) { final SubSectionCompiler sub = sectionInContext().subSectionCompiler(subs[i]); method().compileObjectInContext(); sectionInContext().compileCallToGetterFor(mv, sub); mv.arrayLength(); if (cnts[i] != 1) { mv.push(cnts[i]); mv.visitInsn(Opcodes.IMUL); } mv.visitInsn(Opcodes.IADD); } compileConversionFromInt(); }
From source file:org.formulacompiler.compiler.internal.bytecode.LinearizerCompiler.java
License:Open Source License
@Override protected void compileBody() throws CompilerException { final GeneratorAdapter mv = mv(); final Label outOfRange = mv.newLabel(); // range check row mv.visitVarInsn(Opcodes.ILOAD, 1); // row mv.push(1);/* ww w . j a v a2 s . com*/ mv.ifICmp(mv.LT, outOfRange); mv.visitVarInsn(Opcodes.ILOAD, 1); // row mv.push(this.rows); mv.ifICmp(mv.GT, outOfRange); // range check col mv.visitVarInsn(Opcodes.ILOAD, 2); // col mv.push(1); mv.ifICmp(mv.LT, outOfRange); mv.visitVarInsn(Opcodes.ILOAD, 2); // col mv.push(this.cols); mv.ifICmp(mv.GT, outOfRange); // (<row> - 1) * <num_cols>) + (<col> - 1); mv.visitVarInsn(Opcodes.ILOAD, 1); // row mv.push(1); mv.visitInsn(Opcodes.ISUB); mv.push(this.cols); mv.visitInsn(Opcodes.IMUL); mv.visitVarInsn(Opcodes.ILOAD, 2); // col mv.push(1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.IADD); mv.visitInsn(Opcodes.IRETURN); mv.visitLabel(outOfRange); mv.throwException(ExpressionCompiler.FORMULA_ERROR_TYPE, "#VALUE/REF! because index is out of range in INDEX"); }
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;/*w ww . j a v a2 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.jacoco.core.internal.flow.MethodProbesAdapterTest.java
License:Open Source License
@Test public void testVisitInsn2() { adapter.visitInsn(Opcodes.IADD); expectedVisitor.visitInsn(Opcodes.IADD); }
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;/*w w w.j a v a2 s . 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); }