Search in sources :

Example 6 with LdcInsnNode

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

the class BooleanTestabilityTransformation method insertGetBefore.

/**
 * Insert a call that takes a boolean from the stack, and returns the
 * appropriate distance
 *
 * @param position
 * @param list
 */
public void insertGetBefore(AbstractInsnNode position, InsnList list) {
    logger.info("Inserting get call before");
    // Here, branchId is the first control dependency
    // list.insertBefore(position,
    // new LdcInsnNode(getControlDependentBranchID(currentMethodNode,
    // position)));
    // insertControlDependencyPlaceholder(currentMethodNode, position);
    // branch
    // approx
    // value
    Label label = new Label();
    LabelNode labelNode = new LabelNode(label);
    // BooleanTestabilityPlaceholderTransformer.addControlDependencyPlaceholder(label,
    // insnNode);
    currentMethodNode.instructions.insertBefore(position, labelNode);
    // instructions.insertBefore(insnNode, new LdcInsnNode(0));
    // mn.instructions.insertBefore(insnNode, new LdcInsnNode(0));
    currentMethodNode.instructions.insertBefore(position, new LdcInsnNode(getControlDependentBranchID(currentMethodNode, position)));
    currentMethodNode.instructions.insertBefore(position, new InsnNode(Opcodes.SWAP));
    currentMethodNode.instructions.insertBefore(position, new LdcInsnNode(getApproximationLevel(currentMethodNode, position)));
    currentMethodNode.instructions.insertBefore(position, new InsnNode(Opcodes.SWAP));
    MethodInsnNode get = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "getDistance", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE, Type.INT_TYPE }), false);
    list.insertBefore(position, get);
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) 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) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) Type(org.objectweb.asm.Type) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) Label(org.objectweb.asm.Label)

Example 7 with LdcInsnNode

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

the class BooleanTestabilityTransformation method insertPush2.

/**
 * Insert a call to the distance function for binary comparison
 *
 * @param opcode
 * @param position
 * @param list
 */
public void insertPush2(int opcode, JumpInsnNode position, InsnList list) {
    list.insertBefore(position, new InsnNode(Opcodes.DUP2));
    // list.insertBefore(position, new InsnNode(Opcodes.ISUB));
    MethodInsnNode sub = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "intSub", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.INT_TYPE, Type.INT_TYPE }), false);
    list.insertBefore(position, sub);
    insertBranchIdPlaceholder(currentMethodNode, position);
    // list.insertBefore(position,
    // new LdcInsnNode(getBranchID(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 8 with LdcInsnNode

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

the class BooleanTestabilityTransformation method insertBranchIdPlaceholder.

private void insertBranchIdPlaceholder(MethodNode mn, JumpInsnNode jumpNode, int branchId) {
    Label label = new Label();
    LabelNode labelNode = new LabelNode(label);
    // BooleanTestabilityPlaceholderTransformer.addBranchPlaceholder(label, jumpNode);
    mn.instructions.insertBefore(jumpNode, labelNode);
    // mn.instructions.insertBefore(jumpNode, new LdcInsnNode(0));
    mn.instructions.insertBefore(jumpNode, new LdcInsnNode(branchId));
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) Label(org.objectweb.asm.Label)

Example 9 with LdcInsnNode

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

the class BranchInstrumentation method getInstrumentation.

/**
 * <p>
 * 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;
}
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) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) InsnList(org.objectweb.asm.tree.InsnList)

Example 10 with LdcInsnNode

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

the class DefUseInstrumentation method getMethodInstrumentation.

private InsnList getMethodInstrumentation(BytecodeInstruction call, boolean staticContext, InsnList instrumentation, MethodNode mn) {
    String descriptor = call.getMethodCallDescriptor();
    Type[] args = Type.getArgumentTypes(descriptor);
    int loc = getNextLocalNum(mn);
    Map<Integer, Integer> to = new HashMap<Integer, Integer>();
    for (int i = args.length - 1; i >= 0; i--) {
        Type type = args[i];
        instrumentation.add(new VarInsnNode(type.getOpcode(Opcodes.ISTORE), loc));
        to.put(i, loc);
        loc++;
    }
    // instrumentation.add(new InsnNode(Opcodes.DUP));//callee
    addObjectInstrumentation(call, instrumentation, mn);
    addCallingObjectInstrumentation(staticContext, instrumentation);
    // field method calls get special treatment:
    // during instrumentation it is not clear whether a field method
    // call constitutes a definition or a use. So the instrumentation
    // will call a special function of the ExecutionTracer which will
    // redirect the call to either passedUse() or passedDefinition()
    // using the information available during runtime (the CCFGs)
    instrumentation.add(new LdcInsnNode(DefUsePool.getDefUseCounter()));
    instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ExecutionTracer.class), "passedFieldMethodCall", "(Ljava/lang/Object;Ljava/lang/Object;I)V"));
    for (int i = 0; i < args.length; i++) {
        Type type = args[i];
        instrumentation.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), to.get(i)));
    }
    return instrumentation;
}
Also used : Type(org.objectweb.asm.Type) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) HashMap(java.util.HashMap) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

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