Search in sources :

Example 11 with LdcInsnNode

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

the class DefUseInstrumentation method getInstrumentation.

/**
 * Creates the instrumentation needed to track defs and uses
 */
private InsnList getInstrumentation(BytecodeInstruction v, boolean staticContext, String className, String methodName, MethodNode mn) {
    InsnList instrumentation = new InsnList();
    if (!v.isDefUse()) {
        logger.warn("unexpected DefUseInstrumentation call for a non-DU-instruction");
        return instrumentation;
    }
    if (DefUsePool.isKnownAsFieldMethodCall(v)) {
        return getMethodInstrumentation(v, staticContext, instrumentation, mn);
    }
    if (DefUsePool.isKnownAsUse(v)) {
        // The actual object that is defined is on the stack _after_ the load instruction
        addObjectInstrumentation(v, instrumentation, mn);
        addCallingObjectInstrumentation(staticContext, instrumentation);
        instrumentation.add(new LdcInsnNode(DefUsePool.getUseCounter()));
        instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ExecutionTracer.class), "passedUse", "(Ljava/lang/Object;Ljava/lang/Object;I)V"));
    }
    if (DefUsePool.isKnownAsDefinition(v)) {
        // The actual object that is defined is on the stack _before_ the store instruction
        addObjectInstrumentation(v, instrumentation, mn);
        addCallingObjectInstrumentation(staticContext, instrumentation);
        instrumentation.add(new LdcInsnNode(DefUsePool.getDefCounter()));
        instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(org.evosuite.testcase.execution.ExecutionTracer.class), "passedDefinition", "(Ljava/lang/Object;Ljava/lang/Object;I)V"));
    }
    return instrumentation;
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) InsnList(org.objectweb.asm.tree.InsnList)

Example 12 with LdcInsnNode

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

the class Instrumenter method addCaptureEnableStatement.

private void addCaptureEnableStatement(final String className, final MethodNode mn, final InsnList il, final int returnValueVar) {
    il.add(new LdcInsnNode(this.captureId));
    if (TransformerUtil.isStatic(mn.access)) {
        // static method
        il.add(new LdcInsnNode(className));
        il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(CaptureUtil.class), "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"));
    } else {
        // non-static method
        il.add(new VarInsnNode(Opcodes.ALOAD, 0));
    }
    final Type returnType = Type.getReturnType(mn.desc);
    if (returnType.equals(Type.VOID_TYPE)) {
        // load return value for VOID methods
        il.add(new FieldInsnNode(Opcodes.GETSTATIC, PackageInfo.getNameWithSlash(CaptureLog.class), "RETURN_TYPE_VOID", Type.getDescriptor(Object.class)));
    } else {
        // load return value as object
        il.add(new VarInsnNode(Opcodes.ALOAD, returnValueVar));
    }
    il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(org.evosuite.testcarver.capture.Capturer.class), "enable", "(ILjava/lang/Object;Ljava/lang/Object;)V"));
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) Type(org.objectweb.asm.Type) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 13 with LdcInsnNode

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

the class InstanceOfTransformer method transformTypeInsnNode.

/* (non-Javadoc)
	 * @see org.evosuite.instrumentation.MethodNodeTransformer#transformTypeInsnNode(org.objectweb.asm.tree.MethodNode, org.objectweb.asm.tree.TypeInsnNode)
	 */
@Override
protected AbstractInsnNode transformTypeInsnNode(MethodNode mn, TypeInsnNode typeNode) {
    if (typeNode.getOpcode() == Opcodes.INSTANCEOF) {
        TransformationStatistics.transformInstanceOf();
        // Depending on the class version we need a String or a Class
        // TODO: This needs to be class version of the class that's loaded, not cn!
        // ClassReader reader;
        int version = 48;
        /*
			String name = typeNode.desc.replace('/', '.');
			try {
				reader = new ClassReader(name);
				ClassNode parent = new ClassNode();
				reader.accept(parent, ClassReader.SKIP_CODE);
				version = parent.version;
			} catch (IOException e) {
				TestabilityTransformation.logger.info("Error reading class " + name);
			}
			*/
        if (version >= 49) {
            if (!typeNode.desc.startsWith("[")) {
                LdcInsnNode lin = new LdcInsnNode(Type.getType("L" + typeNode.desc + ";"));
                mn.instructions.insertBefore(typeNode, lin);
            } else {
                LdcInsnNode lin = new LdcInsnNode(Type.getType(typeNode.desc + ";"));
                mn.instructions.insertBefore(typeNode, lin);
            }
        } else {
            LdcInsnNode lin = new LdcInsnNode(typeNode.desc.replace('/', '.'));
            mn.instructions.insertBefore(typeNode, lin);
            MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(Class.class), "forName", Type.getMethodDescriptor(Type.getType(Class.class), new Type[] { Type.getType(String.class) }));
            mn.instructions.insertBefore(typeNode, n);
        }
        MethodInsnNode n = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class), "instanceOf", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.getType(Object.class), Type.getType(Class.class) }));
        mn.instructions.insertBefore(typeNode, n);
        mn.instructions.remove(typeNode);
        return n;
    }
    return typeNode;
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) Type(org.objectweb.asm.Type) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) BooleanHelper(org.evosuite.instrumentation.testability.BooleanHelper)

Example 14 with LdcInsnNode

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

the class ReplaceComparisonOperator method getInfectionDistance.

/**
 * <p>getInfectionDistance</p>
 *
 * @param opcodeOrig a int.
 * @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;
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) InsnList(org.objectweb.asm.tree.InsnList)

Example 15 with LdcInsnNode

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

the class ReplaceVariable method copy.

/**
 * <p>
 * copy
 * </p>
 *
 * @param orig
 *            a {@link org.objectweb.asm.tree.InsnList} object.
 * @return a {@link org.objectweb.asm.tree.InsnList} object.
 */
public static InsnList copy(InsnList orig) {
    Iterator<?> it = orig.iterator();
    InsnList copy = new InsnList();
    while (it.hasNext()) {
        AbstractInsnNode node = (AbstractInsnNode) it.next();
        if (node instanceof VarInsnNode) {
            VarInsnNode vn = (VarInsnNode) node;
            copy.add(new VarInsnNode(vn.getOpcode(), vn.var));
        } else if (node instanceof FieldInsnNode) {
            FieldInsnNode fn = (FieldInsnNode) node;
            copy.add(new FieldInsnNode(fn.getOpcode(), fn.owner, fn.name, fn.desc));
        } else if (node instanceof InsnNode) {
            if (node.getOpcode() != Opcodes.POP)
                copy.add(new InsnNode(node.getOpcode()));
        } else if (node instanceof LdcInsnNode) {
            copy.add(new LdcInsnNode(((LdcInsnNode) node).cst));
        } else {
            throw new RuntimeException("Unexpected node type: " + node.getClass());
        }
    }
    return copy;
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) IincInsnNode(org.objectweb.asm.tree.IincInsnNode) 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) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) InsnList(org.objectweb.asm.tree.InsnList) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) 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