List of usage examples for org.objectweb.asm Opcodes IF_ICMPNE
int IF_ICMPNE
To view the source code for org.objectweb.asm Opcodes IF_ICMPNE.
Click Source Link
From source file:name.martingeisse.minimal.compiler.Compiler.java
License:Open Source License
private MBinaryIntegerOperator mapOperator(final int jvmOpcode) { switch (jvmOpcode) { case Opcodes.IFEQ: case Opcodes.IF_ICMPEQ: return MBinaryIntegerOperator.EQUAL; case Opcodes.IFNE: case Opcodes.IF_ICMPNE: return MBinaryIntegerOperator.NOT_EQUAL; case Opcodes.IFLT: case Opcodes.IF_ICMPLT: return MBinaryIntegerOperator.LESS_THAN; case Opcodes.IFLE: case Opcodes.IF_ICMPLE: return MBinaryIntegerOperator.LESS_THAN_OR_EQUAL; case Opcodes.IFGT: case Opcodes.IF_ICMPGT: return MBinaryIntegerOperator.GREATER_THAN; case Opcodes.IFGE: case Opcodes.IF_ICMPGE: return MBinaryIntegerOperator.GREATER_THAN_OR_EQUAL; default:/*from w w w . j a v a 2 s .c om*/ throw new IllegalArgumentException("cannot map comparison operator for JVM opcode: " + jvmOpcode); } }
From source file:net.sourceforge.cobertura.instrument.pass3.AbstractCodeProvider.java
License:GNU General Public License
public void generateCodeThatIncrementsCoberturaCounterIfVariableEqualsAndCleanVariable( MethodVisitor nextMethodVisitor, Integer neededJumpCounterIdVariableValue, Integer counterIdToIncrement, int lastJumpIdVariableIndex, String className) { nextMethodVisitor.visitLdcInsn((int) neededJumpCounterIdVariableValue); nextMethodVisitor.visitVarInsn(Opcodes.ILOAD, lastJumpIdVariableIndex); Label afterJump = new Label(); nextMethodVisitor.visitJumpInsn(Opcodes.IF_ICMPNE, afterJump); generateCodeThatIncrementsCoberturaCounter(nextMethodVisitor, counterIdToIncrement, className); generateCodeThatZeroJumpCounterIdVariable(nextMethodVisitor, lastJumpIdVariableIndex); nextMethodVisitor.visitLabel(afterJump); }
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public void visitJumpInsn(final int opcode, final Label label) { T t = null;//from www. ja va 2 s .c o m Object oValue = null; final int targetPc = getPc(label); switch (opcode) { /******** * GOTO * ********/ case Opcodes.GOTO: { final GOTO op = new GOTO(this.ops.size(), opcode, this.line); add(op); op.setTargetPc(targetPc); if (targetPc < 0) { getUnresolved(label).add(op); } break; } /******** * JCMP * ********/ case Opcodes.IF_ACMPEQ: t = T.REF; oValue = CmpType.T_EQ; // fall through case Opcodes.IF_ACMPNE: if (t == null) { t = T.REF; oValue = CmpType.T_NE; } // fall through case Opcodes.IF_ICMPEQ: if (t == null) { t = T.AINT; // boolean too oValue = CmpType.T_EQ; } // fall through case Opcodes.IF_ICMPGE: if (t == null) { t = T.INT; oValue = CmpType.T_GE; } // fall through case Opcodes.IF_ICMPGT: if (t == null) { t = T.INT; oValue = CmpType.T_GT; } // fall through case Opcodes.IF_ICMPLE: if (t == null) { t = T.INT; oValue = CmpType.T_LE; } // fall through case Opcodes.IF_ICMPLT: if (t == null) { t = T.INT; oValue = CmpType.T_LT; } // fall through case Opcodes.IF_ICMPNE: if (t == null) { t = T.AINT; // boolean too oValue = CmpType.T_NE; } { assert oValue instanceof CmpType; final JCMP op = new JCMP(this.ops.size(), opcode, this.line, t, (CmpType) oValue); add(op); op.setTargetPc(targetPc); if (targetPc < 0) { getUnresolved(label).add(op); } } break; /******** * JCND * ********/ case Opcodes.IFNULL: t = T.REF; oValue = CmpType.T_EQ; // fall through case Opcodes.IFNONNULL: if (t == null) { t = T.REF; oValue = CmpType.T_NE; } // fall through case Opcodes.IFEQ: if (t == null) { t = T.AINT; // boolean too oValue = CmpType.T_EQ; } // fall through case Opcodes.IFGE: if (t == null) { t = T.INT; oValue = CmpType.T_GE; } // fall through case Opcodes.IFGT: if (t == null) { t = T.INT; oValue = CmpType.T_GT; } // fall through case Opcodes.IFLE: if (t == null) { t = T.INT; oValue = CmpType.T_LE; } // fall through case Opcodes.IFLT: if (t == null) { t = T.INT; oValue = CmpType.T_LT; } // fall through case Opcodes.IFNE: if (t == null) { t = T.AINT; // boolean too oValue = CmpType.T_NE; } { assert oValue instanceof CmpType; final JCND op = new JCND(this.ops.size(), opcode, this.line, t, (CmpType) oValue); add(op); op.setTargetPc(targetPc); if (targetPc < 0) { getUnresolved(label).add(op); } } break; /******* * JSR * *******/ case Opcodes.JSR: { final JSR op = new JSR(this.ops.size(), opcode, this.line); add(op); op.setTargetPc(targetPc); if (targetPc < 0) { getUnresolved(label).add(op); } break; } default: log.warn(getM() + ": Unknown jump insn opcode '" + opcode + "'!"); } }
From source file:org.evosuite.graphs.cfg.BytecodeInstructionPool.java
License:Open Source License
/** * Determine how many bytes the current instruction occupies together with * its operands// w ww . j a va2 s. co m * * @return */ private int getBytecodeIncrement(AbstractInsnNode instructionNode) { int opcode = instructionNode.getOpcode(); switch (opcode) { case Opcodes.ALOAD: // index case Opcodes.ASTORE: // index case Opcodes.DLOAD: case Opcodes.DSTORE: case Opcodes.FLOAD: case Opcodes.FSTORE: case Opcodes.ILOAD: case Opcodes.ISTORE: case Opcodes.LLOAD: case Opcodes.LSTORE: VarInsnNode varNode = (VarInsnNode) instructionNode; if (varNode.var > 3) return 1; else return 0; case Opcodes.BIPUSH: // byte case Opcodes.NEWARRAY: case Opcodes.RET: return 1; case Opcodes.LDC: LdcInsnNode ldcNode = (LdcInsnNode) instructionNode; if (ldcNode.cst instanceof Double || ldcNode.cst instanceof Long) return 2; // LDC2_W else return 1; case 19: //LDC_W case 20: //LDC2_W return 2; case Opcodes.ANEWARRAY: // indexbyte1, indexbyte2 case Opcodes.CHECKCAST: // indexbyte1, indexbyte2 case Opcodes.GETFIELD: case Opcodes.GETSTATIC: case Opcodes.GOTO: case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: case Opcodes.IF_ICMPLT: case Opcodes.IFLE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFNE: case Opcodes.IFEQ: case Opcodes.IFNONNULL: case Opcodes.IFNULL: case Opcodes.IINC: case Opcodes.INSTANCEOF: case Opcodes.INVOKESPECIAL: case Opcodes.INVOKESTATIC: case Opcodes.INVOKEVIRTUAL: case Opcodes.JSR: case Opcodes.NEW: case Opcodes.PUTFIELD: case Opcodes.PUTSTATIC: case Opcodes.SIPUSH: // case Opcodes.LDC_W // case Opcodes.LDC2_W return 2; case Opcodes.MULTIANEWARRAY: return 3; case Opcodes.INVOKEDYNAMIC: case Opcodes.INVOKEINTERFACE: return 4; case Opcodes.LOOKUPSWITCH: case Opcodes.TABLESWITCH: // TODO: Could be more return 4; // case Opcodes.GOTO_W // case Opcodes.JSR_W } return 0; }
From source file:org.evosuite.instrumentation.coverage.BranchInstrumentation.java
License:Open Source License
/** * <p>//from w w w. ja v a 2 s.c om * getInstrumentation * </p> * * @param instruction * a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object. * @return a {@link org.objectweb.asm.tree.InsnList} object. */ protected InsnList getInstrumentation(BytecodeInstruction instruction) { if (instruction == null) throw new IllegalArgumentException("null given"); if (!instruction.isActualBranch()) throw new IllegalArgumentException("branch instruction expected"); if (!BranchPool.getInstance(classLoader).isKnownAsNormalBranchInstruction(instruction)) throw new IllegalArgumentException( "expect given instruction to be known by the BranchPool as a normal branch instruction"); int opcode = instruction.getASMNode().getOpcode(); int instructionId = instruction.getInstructionId(); int branchId = BranchPool.getInstance(classLoader).getActualBranchIdForNormalBranchInstruction(instruction); if (branchId < 0) throw new IllegalStateException("expect BranchPool to know branchId for all branch instructions"); InsnList instrumentation = new InsnList(); switch (opcode) { case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: instrumentation.add(new InsnNode(Opcodes.DUP)); instrumentation.add(new LdcInsnNode(opcode)); // instrumentation.add(new LdcInsnNode(id)); instrumentation.add(new LdcInsnNode(branchId)); instrumentation.add(new LdcInsnNode(instructionId)); instrumentation.add( new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIII)V", false)); logger.debug("Adding passedBranch val=?, opcode=" + opcode + ", branch=" + branchId + ", bytecode_id=" + instructionId); 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: instrumentation.add(new InsnNode(Opcodes.DUP2)); instrumentation.add(new LdcInsnNode(opcode)); // instrumentation.add(new LdcInsnNode(id)); instrumentation.add(new LdcInsnNode(branchId)); instrumentation.add(new LdcInsnNode(instructionId)); instrumentation.add( new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIIII)V", false)); break; case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: instrumentation.add(new InsnNode(Opcodes.DUP2)); instrumentation.add(new LdcInsnNode(opcode)); // instrumentation.add(new LdcInsnNode(id)); instrumentation.add(new LdcInsnNode(branchId)); instrumentation.add(new LdcInsnNode(instructionId)); instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(Ljava/lang/Object;Ljava/lang/Object;III)V", false)); break; case Opcodes.IFNULL: case Opcodes.IFNONNULL: instrumentation.add(new InsnNode(Opcodes.DUP)); instrumentation.add(new LdcInsnNode(opcode)); // instrumentation.add(new LdcInsnNode(id)); instrumentation.add(new LdcInsnNode(branchId)); instrumentation.add(new LdcInsnNode(instructionId)); instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(Ljava/lang/Object;III)V", false)); break; } return instrumentation; }
From source file:org.evosuite.instrumentation.coverage.MutationInstrumentation.java
License:Open Source License
/** * <p>/*from w w w.jav a2 s . co m*/ * addInstrumentation * </p> * * @param mn * a {@link org.objectweb.asm.tree.MethodNode} object. * @param original * a {@link org.objectweb.asm.tree.AbstractInsnNode} object. * @param mutations * a {@link java.util.List} object. */ protected void addInstrumentation(MethodNode mn, AbstractInsnNode original, List<Mutation> mutations) { InsnList instructions = new InsnList(); // call mutationTouched(mutationObject.getId()); // TODO: All mutations in the id are touched, not just one! for (Mutation mutation : mutations) { instructions.add(mutation.getInfectionDistance()); instructions.add(new LdcInsnNode(mutation.getId())); MethodInsnNode touched = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(ExecutionTracer.class), "passedMutation", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.DOUBLE_TYPE, Type.INT_TYPE }), false); instructions.add(touched); } LabelNode endLabel = new LabelNode(); for (Mutation mutation : mutations) { LabelNode nextLabel = new LabelNode(); LdcInsnNode mutationId = new LdcInsnNode(mutation.getId()); instructions.add(mutationId); FieldInsnNode activeId = new FieldInsnNode(Opcodes.GETSTATIC, Type.getInternalName(MutationObserver.class), "activeMutation", "I"); instructions.add(activeId); instructions.add(new JumpInsnNode(Opcodes.IF_ICMPNE, nextLabel)); instructions.add(mutation.getMutation()); instructions.add(new JumpInsnNode(Opcodes.GOTO, endLabel)); instructions.add(nextLabel); } mn.instructions.insertBefore(original, instructions); mn.instructions.insert(original, endLabel); }
From source file:org.evosuite.instrumentation.mutation.ReplaceComparisonOperator.java
License:Open Source License
private String getOp(int opcode) { switch (opcode) { case Opcodes.IFEQ: case Opcodes.IF_ACMPEQ: case Opcodes.IF_ICMPEQ: return "=="; case Opcodes.IFNE: case Opcodes.IF_ACMPNE: case Opcodes.IF_ICMPNE: return "!="; case Opcodes.IFLT: case Opcodes.IF_ICMPLT: return "<"; case Opcodes.IFLE: case Opcodes.IF_ICMPLE: return "<="; case Opcodes.IFGT: case Opcodes.IF_ICMPGT: return ">"; case Opcodes.IFGE: case Opcodes.IF_ICMPGE: return ">="; case Opcodes.IFNULL: return "= null"; case Opcodes.IFNONNULL: return "!= null"; }//from w w w . j ava 2s .com throw new RuntimeException("Unknown opcode: " + opcode); }
From source file:org.evosuite.instrumentation.mutation.ReplaceComparisonOperator.java
License:Open Source License
/** * <p>getInfectionDistance</p> * * @param opcodeOrig a int.// w ww . j a v a2 s .c om * @param opcodeNew a int. * @return a {@link org.objectweb.asm.tree.InsnList} object. */ public InsnList getInfectionDistance(int opcodeOrig, int opcodeNew) { InsnList distance = new InsnList(); switch (opcodeOrig) { case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: distance.add(new InsnNode(Opcodes.DUP2)); distance.add(new LdcInsnNode(opcodeOrig)); distance.add(new LdcInsnNode(opcodeNew)); distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceComparisonOperator.class), "getInfectionDistance", "(IIII)D", false)); break; case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: distance.add(new InsnNode(Opcodes.DUP)); distance.add(new LdcInsnNode(opcodeOrig)); distance.add(new LdcInsnNode(opcodeNew)); distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceComparisonOperator.class), "getInfectionDistance", "(III)D", false)); break; default: distance.add(new LdcInsnNode(0.0)); } return distance; }
From source file:org.evosuite.instrumentation.mutation.ReplaceComparisonOperator.java
License:Open Source License
/** * <p>getInfectionDistance</p> * * @param left a int./* w ww . ja v a 2s. co m*/ * @param right a int. * @param opcodeOrig a int. * @param opcodeNew a int. * @return a double. */ public static double getInfectionDistance(int left, int right, int opcodeOrig, int opcodeNew) { long val = (long) left - (long) right; switch (opcodeOrig) { case Opcodes.IF_ICMPLT: switch (opcodeNew) { case Opcodes.IF_ICMPLE: // Only differs for val == 0 return Math.abs(val); case Opcodes.IF_ICMPEQ: // Only differs for val <= 0 return val > 0 ? val : 0.0; case Opcodes.IF_ICMPGT: // Only same for val == 0 return val == 0 ? 1.0 : 0.0; case Opcodes.IF_ICMPGE: // Always differs return 0.0; case Opcodes.IF_ICMPNE: // Only differs for val > 0 return val <= 0 ? Math.abs(val) + 1.0 : 0.0; case TRUE: return val < 0 ? 1.0 : 0.0; case FALSE: return val < 0 ? 0.0 : 1.0; } case Opcodes.IF_ICMPLE: switch (opcodeNew) { case Opcodes.IF_ICMPLT: // Only differs for val == 0 return Math.abs(val); case Opcodes.IF_ICMPEQ: return val >= 0 ? val + 1.0 : 0.0; case Opcodes.IF_ICMPGE: // Only equals for val == 0 return val == 0 ? 1.0 : 0.0; case Opcodes.IF_ICMPGT: // Always differs return 0.0; case Opcodes.IF_ICMPNE: // Only differs if val >= 0 return val < 0 ? Math.abs(val) : 0.0; case TRUE: return val <= 0 ? 1.0 : 0.0; case FALSE: return val <= 0 ? 0.0 : 1.0; } case Opcodes.IF_ICMPGT: switch (opcodeNew) { case Opcodes.IF_ICMPGE: // Only differs for val == 0 return Math.abs(val); case Opcodes.IF_ICMPEQ: // Only differs for val >= 0 return val < 0 ? Math.abs(val) : 0.0; case Opcodes.IF_ICMPLT: // Only same for val == 0 return val == 0 ? 1.0 : 0.0; case Opcodes.IF_ICMPLE: // Always differs return 0.0; case Opcodes.IF_ICMPNE: // Only differs for val < 0 return val >= 0 ? val + 1.0 : 0.0; case TRUE: return val > 0 ? 1.0 : 0.0; case FALSE: return val > 0 ? 0.0 : 1.0; } case Opcodes.IF_ICMPGE: switch (opcodeNew) { case Opcodes.IF_ICMPGT: // Only differs for val == 0 return Math.abs(val); case Opcodes.IF_ICMPEQ: return val <= 0 ? Math.abs(val) + 1.0 : 0.0; case Opcodes.IF_ICMPLE: // Only equals for val == 0 return val == 0 ? 1.0 : 0.0; case Opcodes.IF_ICMPLT: // Always differs return 0.0; case Opcodes.IF_ICMPNE: // Only differs if val > 0 return val > 0 ? val : 0.0; case TRUE: return val >= 0 ? 1.0 : 0.0; case FALSE: return val >= 0 ? 0.0 : 1.0; } case Opcodes.IF_ICMPEQ: switch (opcodeNew) { case Opcodes.IF_ICMPLT: // Only differs if val <= 0 return val > 0 ? val : 0.0; case Opcodes.IF_ICMPGT: // Only differs if val >= 0 return val < 0 ? Math.abs(val) : 0.0; case Opcodes.IF_ICMPNE: // Always differs return 0.0; case Opcodes.IF_ICMPLE: return val >= 0 ? val + 1.0 : 0.0; case Opcodes.IF_ICMPGE: return val <= 0 ? Math.abs(val) + 1.0 : 0.0; case TRUE: return val == 0 ? 1.0 : 0.0; case FALSE: return val == 0 ? 0.0 : 1.0; } case Opcodes.IF_ICMPNE: switch (opcodeNew) { case Opcodes.IF_ICMPEQ: return 0.0; case Opcodes.IF_ICMPLT: // Only differs for val > 0 return val <= 0 ? Math.abs(val) + 1.0 : 0.0; case Opcodes.IF_ICMPLE: // Only differs for val > 0 return val < 0 ? Math.abs(val) : 0.0; case Opcodes.IF_ICMPGT: return val >= 0 ? val + 1.0 : 0.0; case Opcodes.IF_ICMPGE: return val > 0 ? val : 0.0; case TRUE: return val != 0 ? 1.0 : 0.0; case FALSE: return val != 0 ? 0.0 : 1.0; } } throw new RuntimeException("Unknown operator replacement: " + opcodeOrig + " -> " + opcodeNew); }
From source file:org.evosuite.instrumentation.mutation.ReplaceComparisonOperator.java
License:Open Source License
private int getBooleanIntIntReplacement(int opcode) { logger.debug("Getting Boolean int int replacement"); switch (opcode) { case Opcodes.IF_ICMPEQ: return Opcodes.IF_ICMPNE; case Opcodes.IF_ICMPNE: return Opcodes.IF_ICMPEQ; case Opcodes.IF_ICMPGT: return Opcodes.IF_ICMPEQ; case Opcodes.IF_ICMPLE: return Opcodes.IF_ICMPGT; // The rest should not occur except if our interpreter did something wrong case Opcodes.IF_ICMPGE: return Opcodes.IF_ICMPLT; case Opcodes.IF_ICMPLT: return Opcodes.IF_ICMPGE; }/*from ww w .j a v a 2 s . c o m*/ throw new RuntimeException("Illegal opcode received: " + opcode); }