Example usage for org.objectweb.asm Opcodes IFNULL

List of usage examples for org.objectweb.asm Opcodes IFNULL

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes IFNULL.

Prototype

int IFNULL

To view the source code for org.objectweb.asm Opcodes IFNULL.

Click Source Link

Usage

From source file:org.evosuite.instrumentation.BooleanHelper.java

License:Open Source License

/**
 * Replacement function for the Java IFNULL instruction, returning a
 * distance integer/*from   www .ja v  a 2 s .  c o  m*/
 * 
 * @param o
 * @param opcode
 * @param opcode
 *            a int.
 * @return a int.
 */
public static int isNull(Object o, int opcode) {
    if (opcode == Opcodes.IFNULL)
        return o == null ? TRUE : FALSE;
    else
        return o != null ? TRUE : FALSE;
}

From source file:org.evosuite.instrumentation.coverage.BranchInstrumentation.java

License:Open Source License

/**
 * <p>//from  www .jav  a 2s  .  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.error.CastErrorInstrumentation.java

License:Open Source License

@Override
public void visitTypeInsn(int opcode, String type) {

    if (opcode == Opcodes.CHECKCAST) {
        Label origTarget = new Label();
        // Label origTarget = new AnnotatedLabel();
        // origTarget.info = Boolean.FALSE;
        mv.visitInsn(Opcodes.DUP);/*from  w w w. j  a  v  a2s.  c  o  m*/
        mv.tagBranch();
        mv.visitJumpInsn(Opcodes.IFNULL, origTarget);
        mv.visitInsn(Opcodes.DUP);
        mv.visitTypeInsn(Opcodes.INSTANCEOF, type);
        mv.tagBranch();
        mv.visitJumpInsn(Opcodes.IFNE, origTarget);
        mv.visitTypeInsn(Opcodes.NEW, "java/lang/ClassCastException");
        mv.visitInsn(Opcodes.DUP);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/ClassCastException", "<init>", "()V", false);
        mv.visitInsn(Opcodes.ATHROW);
        mv.visitLabel(origTarget);
        mv.tagBranchExit();
    }
}

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";
    }// www. j a v a 2  s .  c o m
    throw new RuntimeException("Unknown opcode: " + opcode);
}

From source file:org.evosuite.instrumentation.testability.transformer.BooleanDistanceTransformer.java

License:Open Source License

@Override
protected AbstractInsnNode transformJumpInsnNode(MethodNode mn, JumpInsnNode jumpNode) {

    switch (jumpNode.getOpcode()) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
        TransformationStatistics.insertPush(jumpNode.getOpcode());
        this.booleanTestabilityTransformation.insertPush(jumpNode.getOpcode(), jumpNode, mn.instructions);
        break;/*w ww  .jav a  2  s  . co  m*/
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
        TransformationStatistics.insertPush(jumpNode.getOpcode());
        this.booleanTestabilityTransformation.insertPush2(jumpNode.getOpcode(), jumpNode, mn.instructions);
        break;
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        TransformationStatistics.insertPush(jumpNode.getOpcode());
        this.booleanTestabilityTransformation.insertPushNull(jumpNode.getOpcode(), jumpNode, mn.instructions);
        break;
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        TransformationStatistics.insertPush(jumpNode.getOpcode());
        this.booleanTestabilityTransformation.insertPushEquals(jumpNode.getOpcode(), jumpNode, mn.instructions);
        break;
    default:
        // GOTO, JSR: Do nothing
    }
    return jumpNode;
}

From source file:org.evosuite.instrumentation.TransformationStatistics.java

License:Open Source License

/**
 * Insertion of pushDistance/* w  w w. ja  v  a2s  .  c  om*/
 *
 * @param opcode a int.
 */
public static void insertPush(int opcode) {
    switch (opcode) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
        insertedPushInt0++;
        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:
        insertedPushInt1++;
        break;
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        insertedPushIntRef++;
        break;
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        insertedPushIntNull++;
        break;
    default:
        // GOTO, JSR: Do nothing
    }
}

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;// ww w.jav a2  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.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;//  w  w  w  .  j  av  a2s  .c  o  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}/*w  ww  . j  a v  a  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  .j  a v  a 2  s.  c  om*/
 * @param val
 *            a {@link java.lang.Object} object.
 * @param opcode
 *            a int.
 * @param branch
 *            a int.
 * @param bytecode_id
 *            a int.
 */
public static void passedBranch(Object val, int opcode, int branch, int bytecode_id) {
    ExecutionTracer tracer = getExecutionTracer();
    if (tracer.disabled)
        return;

    if (isThreadNeqCurrentThread())
        return;

    checkTimeout();

    double distance_true = 0;
    double distance_false = 0;
    switch (opcode) {
    case Opcodes.IFNULL:
        distance_true = val == null ? 0.0 : 1.0;
        break;
    case Opcodes.IFNONNULL:
        distance_true = val == null ? 1.0 : 0.0;
        break;
    default:
        logger.error("Warning: encountered opcode " + opcode);
    }
    distance_false = distance_true == 0 ? 1.0 : 0.0;
    // enable();

    // logger.trace("Branch distance true: " + distance_true);
    // logger.trace("Branch distance false: " + distance_false);

    // Add current branch to control trace
    tracer.trace.branchPassed(branch, bytecode_id, distance_true, distance_false);
}