List of usage examples for org.objectweb.asm Opcodes IF_ICMPEQ
int IF_ICMPEQ
To view the source code for org.objectweb.asm Opcodes IF_ICMPEQ.
Click Source Link
From source file:org.evosuite.regression.bytecode.RegressionClassDiff.java
License:Open Source License
private static String getBranchFamily(int opcode) { // The default family is the opcode itself // Admittedly we could've use ints/enums for performance, but strings should be interned anyway String family = "" + opcode; switch (opcode) { // copmpare int with zero case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: family = "int_zero"; break;//from w w w.java 2 s.c om // 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: family = "int_int"; break; // copmpare reference with reference case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: family = "ref_ref"; break; // compare reference with null case Opcodes.IFNULL: case Opcodes.IFNONNULL: family = "ref_null"; break; } return family; }
From source file:org.evosuite.regression.RegressionClassDiff.java
License:Open Source License
public static String getBranchFamily(int opcode) { // The default family is the opcode itself // Admittedly we could've use ints/enums for performance, but strings should be interned anyway String family = "" + opcode; switch (opcode) { // copmpare int with zero case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: family = "int_zero"; break;//from ww w . j a v a 2 s . co m // 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: family = "int_int"; break; // copmpare reference with reference case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: family = "ref_ref"; break; // compare reference with null case Opcodes.IFNULL: case Opcodes.IFNONNULL: family = "ref_null"; break; } return family; }
From source file:org.evosuite.testcase.execution.ExecutionTraceImpl.java
License:Open Source License
/** * {@inheritDoc}//from w ww.ja va 2 s. c om * * Add branch to currently active method call */ @Override public void branchPassed(int branch, int bytecode_id, double true_distance, double false_distance) { assert (true_distance >= 0.0); assert (false_distance >= 0.0); updateTopStackMethodCall(branch, bytecode_id, true_distance, false_distance); // TODO: property should really be called TRACK_GRADIENT_BRANCHES! if (Properties.TRACK_BOOLEAN_BRANCHES) { if ((true_distance != 0 && true_distance != 1) || (false_distance != 0 && false_distance != 1)) gradientBranches.add(branch); } if (traceCoverage) { if (!coveredPredicates.containsKey(branch)) coveredPredicates.put(branch, 1); else coveredPredicates.put(branch, coveredPredicates.get(branch) + 1); if (true_distance == 0.0) { if (!coveredTrue.containsKey(branch)) coveredTrue.put(branch, 1); else coveredTrue.put(branch, coveredTrue.get(branch) + 1); } if (false_distance == 0.0) { if (!coveredFalse.containsKey(branch)) coveredFalse.put(branch, 1); else coveredFalse.put(branch, coveredFalse.get(branch) + 1); } } if (Properties.TRACK_COVERED_GRADIENT_BRANCHES) { if (gradientBranches.contains(branch)) { if ((coveredTrue.containsKey(branch))) gradientBranchesCoveredTrue.add(branch); if ((coveredFalse.containsKey(branch))) gradientBranchesCoveredFalse.add(branch); } } if (Properties.BRANCH_COMPARISON_TYPES) { int opcode = BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()) .getBranch(branch).getInstruction().getASMNode().getOpcode(); int previousOpcode = -2; if (BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranch(branch) .getInstruction().getASMNode().getPrevious() != null) previousOpcode = BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()) .getBranch(branch).getInstruction().getASMNode().getPrevious().getOpcode(); boolean cTrue = coveredTrue.containsKey(branch); boolean cFalse = coveredFalse.containsKey(branch); switch (previousOpcode) { case Opcodes.LCMP: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_lcmp, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_lcmp, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_lcmp, branch); break; case Opcodes.FCMPL: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_fcmpl, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_fcmpl, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_fcmpl, branch); break; case Opcodes.FCMPG: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_fcmpg, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_fcmpg, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_fcmpg, branch); break; case Opcodes.DCMPL: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_dcmpl, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_dcmpl, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_dcmpl, branch); break; case Opcodes.DCMPG: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_dcmpg, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_dcmpg, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_dcmpg, branch); break; } switch (opcode) { // copmpare int with zero case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_IntZero, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_IntZero, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_IntZero, branch); 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: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_IntInt, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_IntInt, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_IntInt, branch); break; // copmpare reference with reference case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_RefRef, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_RefRef, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_RefRef, branch); break; // compare reference with null case Opcodes.IFNULL: case Opcodes.IFNONNULL: trackBranchOpcode(bytecodeInstructionReached, RuntimeVariable.Reached_RefNull, branch); if (cTrue) trackBranchOpcode(bytecodeInstructionCoveredTrue, RuntimeVariable.Covered_RefNull, branch); if (cFalse) trackBranchOpcode(bytecodeInstructionCoveredFalse, RuntimeVariable.Covered_RefNull, branch); break; } } if (!trueDistances.containsKey(branch)) trueDistances.put(branch, true_distance); else trueDistances.put(branch, Math.min(trueDistances.get(branch), true_distance)); if (!falseDistances.containsKey(branch)) falseDistances.put(branch, false_distance); else falseDistances.put(branch, Math.min(falseDistances.get(branch), false_distance)); if (!trueDistancesSum.containsKey(branch)) trueDistancesSum.put(branch, true_distance); else trueDistancesSum.put(branch, trueDistancesSum.get(branch) + true_distance); if (!falseDistancesSum.containsKey(branch)) falseDistancesSum.put(branch, false_distance); else falseDistancesSum.put(branch, falseDistancesSum.get(branch) + false_distance); if (!disableContext && (Properties.INSTRUMENT_CONTEXT || Properties.INSTRUMENT_METHOD_CALLS || ArrayUtil.contains(Properties.CRITERION, Criterion.IBRANCH) || ArrayUtil.contains(Properties.CRITERION, Criterion.CBRANCH))) { updateBranchContextMaps(branch, true_distance, false_distance); } // This requires a lot of memory and should not really be used if (Properties.BRANCH_EVAL) { branchesTrace.add(new BranchEval(branch, true_distance, false_distance)); } }
From source file:org.evosuite.testcase.execution.ExecutionTracer.java
License:Open Source License
/** * Called by the instrumented code each time a new branch is taken * // w ww . ja v a 2 s. c o m * @param val1 * a int. * @param val2 * a int. * @param opcode * a int. * @param branch * a int. * @param bytecode_id * a int. */ public static void passedBranch(int val1, int val2, int opcode, int branch, int bytecode_id) { ExecutionTracer tracer = getExecutionTracer(); if (tracer.disabled) return; if (isThreadNeqCurrentThread()) return; checkTimeout(); ConstantPoolManager.getInstance().addDynamicConstant(val1); ConstantPoolManager.getInstance().addDynamicConstant(val2); /* logger.trace("Called passedBranch2 with opcode " + AbstractVisitor.OPCODES[opcode] + ", val1=" + val1 + ", val2=" + val2 + " in branch " + branch); */ double distance_true = 0; double distance_false = 0; switch (opcode) { // Problem is that the JVM is a stack machine // x < 5 gets compiled to a val2 > val1, // because operators are on the stack in reverse order case Opcodes.IF_ICMPEQ: // The greater the difference, the further away distance_true = Math.abs((double) val1 - (double) val2); // Anything but 0 is good distance_false = distance_true == 0 ? 1.0 : 0.0; break; case Opcodes.IF_ICMPNE: // The greater abs is, the further away from 0 distance_false = Math.abs((double) val1 - (double) val2); // Anything but 0 leads to NE distance_true = distance_false == 0 ? 1.0 : 0.0; break; case Opcodes.IF_ICMPLT: // val1 >= val2? distance_true = val1 >= val2 ? (double) val1 - (double) val2 + 1.0 : 0.0; distance_false = val1 < val2 ? (double) val2 - (double) val1 + 1.0 : 0.0; break; case Opcodes.IF_ICMPGE: // val1 < val2? distance_true = val1 < val2 ? (double) val2 - (double) val1 + 1.0 : 0.0; distance_false = val1 >= val2 ? (double) val1 - (double) val2 + 1.0 : 0.0; break; case Opcodes.IF_ICMPGT: // val1 <= val2? distance_true = val1 <= val2 ? (double) val2 - (double) val1 + 1.0 : 0.0; distance_false = val1 > val2 ? (double) val1 - (double) val2 + 1.0 : 0.0; break; case Opcodes.IF_ICMPLE: // val1 > val2? distance_true = val1 > val2 ? (double) val1 - (double) val2 + 1.0 : 0.0; distance_false = val1 <= val2 ? (double) val2 - (double) val1 + 1.0 : 0.0; break; default: logger.error("Unknown opcode: " + opcode); } // logger.trace("2 Branch distance true: " + distance_true); // logger.trace("2 Branch distance false: " + distance_false); // Add current branch to control trace tracer.trace.branchPassed(branch, bytecode_id, distance_true, distance_false); // tracer.trace.branchPassed(branch, distance_true, distance_false); }
From source file:org.evosuite.testcase.ExecutionTracer.java
License:Open Source License
/** * Called by the instrumented code each time a new branch is taken * // w w w . jav a 2 s . c o m * @param val1 * a int. * @param val2 * a int. * @param opcode * a int. * @param branch * a int. * @param bytecode_id * a int. */ public static void passedBranch(int val1, int val2, int opcode, int branch, int bytecode_id) { ExecutionTracer tracer = getExecutionTracer(); if (tracer.disabled) return; if (isThreadNeqCurrentThread()) return; checkTimeout(); if (Properties.DYNAMIC_SEEDING) { ConstantPoolManager.getInstance().addDynamicConstant(val1); ConstantPoolManager.getInstance().addDynamicConstant(val2); } ; /* logger.trace("Called passedBranch2 with opcode " + AbstractVisitor.OPCODES[opcode] + ", val1=" + val1 + ", val2=" + val2 + " in branch " + branch); */ double distance_true = 0; double distance_false = 0; switch (opcode) { // Problem is that the JVM is a stack machine // x < 5 gets compiled to a val2 > val1, // because operators are on the stack in reverse order case Opcodes.IF_ICMPEQ: // The greater the difference, the further away distance_true = Math.abs((double) val1 - (double) val2); // Anything but 0 is good distance_false = distance_true == 0 ? 1.0 : 0.0; break; case Opcodes.IF_ICMPNE: // The greater abs is, the further away from 0 distance_false = Math.abs((double) val1 - (double) val2); // Anything but 0 leads to NE distance_true = distance_false == 0 ? 1.0 : 0.0; break; case Opcodes.IF_ICMPLT: // val1 >= val2? distance_true = val1 >= val2 ? (double) val1 - (double) val2 + 1.0 : 0.0; distance_false = val1 < val2 ? (double) val2 - (double) val1 + 1.0 : 0.0; break; case Opcodes.IF_ICMPGE: // val1 < val2? distance_true = val1 < val2 ? (double) val2 - (double) val1 + 1.0 : 0.0; distance_false = val1 >= val2 ? (double) val1 - (double) val2 + 1.0 : 0.0; break; case Opcodes.IF_ICMPGT: // val1 <= val2? distance_true = val1 <= val2 ? (double) val2 - (double) val1 + 1.0 : 0.0; distance_false = val1 > val2 ? (double) val1 - (double) val2 + 1.0 : 0.0; break; case Opcodes.IF_ICMPLE: // val1 > val2? distance_true = val1 > val2 ? (double) val1 - (double) val2 + 1.0 : 0.0; distance_false = val1 <= val2 ? (double) val2 - (double) val1 + 1.0 : 0.0; break; default: logger.error("Unknown opcode: {}", opcode); } // logger.trace("2 Branch distance true: " + distance_true); // logger.trace("2 Branch distance false: " + distance_false); // Add current branch to control trace tracer.trace.branchPassed(branch, bytecode_id, distance_true, distance_false); // tracer.trace.branchPassed(branch, distance_true, distance_false); }
From source file:org.evosuite.TestSuiteGenerator.java
License:Open Source License
private void getBytecodeStatistics() { if (Properties.TRACK_BOOLEAN_BRANCHES) { int gradientBranchCount = ExecutionTraceImpl.gradientBranches.size() * 2; ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Gradient_Branches, gradientBranchCount);// w w w. j a v a 2 s . c o m } if (Properties.TRACK_COVERED_GRADIENT_BRANCHES) { int coveredGradientBranchCount = ExecutionTraceImpl.gradientBranchesCoveredTrue.size() + ExecutionTraceImpl.gradientBranchesCoveredFalse.size(); ClientServices.getInstance().getClientNode() .trackOutputVariable(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.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Cmp_IntZero, cmp_intzero); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Cmp_IntInt, cmp_intint); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Cmp_RefRef, cmp_refref); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.Cmp_RefNull, cmp_refnull); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.BC_lcmp, bc_lcmp); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.BC_fcmpl, bc_fcmpl); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.BC_fcmpg, bc_fcmpg); ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.BC_dcmpl, bc_dcmpl); ClientServices.getInstance().getClientNode().trackOutputVariable(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.getInstance().getClientNode().trackOutputVariable(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.getInstance().getClientNode().trackOutputVariable(bcvar, getBytecodeCount(bcvar, ExecutionTraceImpl.bytecodeInstructionReached) * 2); } } }
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 ava2 s .c o m*/ 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.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 w w w. j a va 2 s . co m*/ 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 www.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.instr.FrameTracker.java
License:Open Source License
@Override public void visitJumpInsn(final int opcode, final Label label) { switch (opcode) { case Opcodes.GOTO: break;//from w ww .j a va2 s. c o m case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: case Opcodes.IFNULL: case Opcodes.IFNONNULL: pop(1); 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: case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: pop(2); break; default: throw new IllegalArgumentException(); } mv.visitJumpInsn(opcode, label); }