Search in sources :

Example 31 with LdcInsnNode

use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.

the class BooleanTestabilityTransformation method insertPush.

/**
 * Insert a call to the distance function for unary comparison
 *
 * @param opcode
 * @param position
 * @param list
 */
public void insertPush(int opcode, JumpInsnNode position, InsnList list) {
    list.insertBefore(position, new InsnNode(Opcodes.DUP));
    // TODO: We have to put a placeholder here instead of the actual branch ID
    // TODO: And then later add another transformation where we replace this with
    // actual branch IDs
    // list.insertBefore(position,
    // new LdcInsnNode(getBranchID(currentMethodNode, position)));
    insertBranchIdPlaceholder(currentMethodNode, position);
    MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "pushPredicate", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE }), false);
    list.insertBefore(position, push);
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Type(org.objectweb.asm.Type) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode)

Example 32 with LdcInsnNode

use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.

the class BooleanTestabilityTransformation method insertPushEquals.

/**
 * Insert a call to the reference equality check helper function
 *
 * @param opcode
 * @param position
 * @param list
 */
public void insertPushEquals(int opcode, JumpInsnNode position, InsnList list) {
    MethodInsnNode equalCheck = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "isEqual", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.getType(Object.class), Type.getType(Object.class), Type.INT_TYPE }), false);
    list.insertBefore(position, new InsnNode(Opcodes.DUP2));
    list.insertBefore(position, new LdcInsnNode(opcode));
    list.insertBefore(position, equalCheck);
    // list.insertBefore(position,
    // new LdcInsnNode(getBranchID(currentMethodNode, position)));
    insertBranchIdPlaceholder(currentMethodNode, position);
    MethodInsnNode push = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "pushPredicate", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE }), false);
    list.insertBefore(position, push);
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Type(org.objectweb.asm.Type) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode)

Example 33 with LdcInsnNode

use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.

the class BranchInstrumentation method addDefaultCaseNotCoveredCall.

/**
 * <p>
 * addDefaultCaseNotCoveredCall
 * </p>
 *
 * @param v
 *            a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
 * @param instrumentation
 *            a {@link org.objectweb.asm.tree.InsnList} object.
 * @param defaultCaseBranchId
 *            a int.
 */
protected void addDefaultCaseNotCoveredCall(BytecodeInstruction v, InsnList instrumentation, int defaultCaseBranchId) {
    instrumentation.add(new LdcInsnNode(0));
    instrumentation.add(new LdcInsnNode(Opcodes.IFNE));
    instrumentation.add(new LdcInsnNode(defaultCaseBranchId));
    instrumentation.add(new LdcInsnNode(v.getInstructionId()));
    instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIII)V", false));
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode)

Example 34 with LdcInsnNode

use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.

the class BranchInstrumentation method addDefaultCaseCoveredCall.

/**
 * <p>
 * addDefaultCaseCoveredCall
 * </p>
 *
 * @param v
 *            a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
 * @param instrumentation
 *            a {@link org.objectweb.asm.tree.InsnList} object.
 * @param defaultCaseBranchId
 *            a int.
 */
protected void addDefaultCaseCoveredCall(BytecodeInstruction v, InsnList instrumentation, int defaultCaseBranchId) {
    instrumentation.add(new LdcInsnNode(0));
    instrumentation.add(new LdcInsnNode(Opcodes.IFEQ));
    instrumentation.add(new LdcInsnNode(defaultCaseBranchId));
    instrumentation.add(new LdcInsnNode(v.getInstructionId()));
    instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIII)V", false));
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode)

Example 35 with LdcInsnNode

use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.

the class BranchInstrumentation method addInstrumentationForSwitchCases.

/**
 * For each actual case <key>: of a switch this method adds instrumentation
 * for the Branch corresponding to that case to the given instruction list.
 *
 * @param v
 *            a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
 * @param instrumentation
 *            a {@link org.objectweb.asm.tree.InsnList} object.
 * @param className
 *            a {@link java.lang.String} object.
 * @param methodName
 *            a {@link java.lang.String} object.
 */
protected void addInstrumentationForSwitchCases(BytecodeInstruction v, InsnList instrumentation, String className, String methodName) {
    if (!v.isSwitch())
        throw new IllegalArgumentException("switch instruction expected");
    List<Branch> caseBranches = BranchPool.getInstance(classLoader).getCaseBranchesForSwitch(v);
    if (caseBranches == null || caseBranches.isEmpty())
        throw new IllegalStateException("expect BranchPool to know at least one Branch for each switch instruction");
    for (Branch targetCaseBranch : caseBranches) {
        if (targetCaseBranch.isDefaultCase())
            // handled elsewhere
            continue;
        Integer targetCaseValue = targetCaseBranch.getTargetCaseValue();
        Integer targetCaseBranchId = targetCaseBranch.getActualBranchId();
        instrumentation.add(new InsnNode(Opcodes.DUP));
        instrumentation.add(new LdcInsnNode(targetCaseValue));
        instrumentation.add(new LdcInsnNode(Opcodes.IF_ICMPEQ));
        instrumentation.add(new LdcInsnNode(targetCaseBranchId));
        instrumentation.add(new LdcInsnNode(v.getInstructionId()));
        instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIIII)V", false));
    }
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) TableSwitchInsnNode(org.objectweb.asm.tree.TableSwitchInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) LookupSwitchInsnNode(org.objectweb.asm.tree.LookupSwitchInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) Branch(org.evosuite.coverage.branch.Branch) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode)

Aggregations

LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)50 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)32 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)30 InsnList (org.objectweb.asm.tree.InsnList)22 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)18 InsnNode (org.objectweb.asm.tree.InsnNode)18 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)18 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)15 Type (org.objectweb.asm.Type)14 MethodNode (org.objectweb.asm.tree.MethodNode)10 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)9 LabelNode (org.objectweb.asm.tree.LabelNode)8 IntInsnNode (org.objectweb.asm.tree.IntInsnNode)7 Label (org.objectweb.asm.Label)6 ClassNode (org.objectweb.asm.tree.ClassNode)5 FieldNode (org.objectweb.asm.tree.FieldNode)4 Mutation (org.evosuite.coverage.mutation.Mutation)3 IincInsnNode (org.objectweb.asm.tree.IincInsnNode)3 LookupSwitchInsnNode (org.objectweb.asm.tree.LookupSwitchInsnNode)3 TableSwitchInsnNode (org.objectweb.asm.tree.TableSwitchInsnNode)3