Example usage for org.objectweb.asm.tree InsnList insert

List of usage examples for org.objectweb.asm.tree InsnList insert

Introduction

In this page you can find the example usage for org.objectweb.asm.tree InsnList insert.

Prototype

public void insert(final AbstractInsnNode previousInsn, final InsnList insnList) 

Source Link

Document

Inserts the given instructions after the specified instruction.

Usage

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

License:Open Source License

private void insertLongComparison(AbstractInsnNode position, InsnList list) {
    MethodInsnNode get = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class),
            "longSub", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.LONG_TYPE, Type.LONG_TYPE }));
    list.insert(position, get);
    list.remove(position);//from w  w  w .j ava 2  s. co  m
}

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

License:Open Source License

private void insertFloatComparison(AbstractInsnNode position, InsnList list) {
    MethodInsnNode get = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class),
            "floatSub",
            Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.FLOAT_TYPE, Type.FLOAT_TYPE }));
    list.insert(position, get);
    list.remove(position);// w  w w. jav  a  2s .c  o m
}

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

License:Open Source License

private void insertDoubleComparison(AbstractInsnNode position, InsnList list) {
    MethodInsnNode get = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class),
            "doubleSub",
            Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.DOUBLE_TYPE, Type.DOUBLE_TYPE }));
    list.insert(position, get);
    list.remove(position);/*from   w ww.  ja v a 2s.  c  om*/
}

From source file:org.evosuite.instrumentation.testability.BooleanTestabilityTransformation.java

License:Open Source License

/**
 * Insert a call that takes a boolean from the stack, and returns the
 * appropriate distance//from   w w  w  .  ja  v  a 2 s.c  o  m
 * 
 * @param position
 * @param list
 */
public void insertGet(AbstractInsnNode position, InsnList list) {
    logger.info("Inserting get call");
    // Here, branchId is the first control dependency
    //list.insertBefore(position,
    //                  new LdcInsnNode(getControlDependentBranchID(currentMethodNode,
    //                                                              position)));
    insertControlDependencyPlaceholder(currentMethodNode, position);

    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.insert(position, get);
}

From source file:org.evosuite.instrumentation.testability.ComparisonTransformation.java

License:Open Source License

private void insertLongComparison(AbstractInsnNode position, InsnList list) {
    MethodInsnNode get = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class),
            "longSub", Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.LONG_TYPE, Type.LONG_TYPE }),
            false);/*from ww  w .ja v a  2s.c  o  m*/
    list.insert(position, get);
    list.remove(position);
}

From source file:org.evosuite.instrumentation.testability.ComparisonTransformation.java

License:Open Source License

private void insertFloatComparisonG(AbstractInsnNode position, InsnList list) {
    MethodInsnNode get = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class),
            "floatSubG",
            Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.FLOAT_TYPE, Type.FLOAT_TYPE }), false);
    list.insert(position, get);
    list.remove(position);/*from  w ww. j  av a 2 s .  co  m*/
}

From source file:org.evosuite.instrumentation.testability.ComparisonTransformation.java

License:Open Source License

private void insertFloatComparisonL(AbstractInsnNode position, InsnList list) {
    MethodInsnNode get = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class),
            "floatSubL",
            Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.FLOAT_TYPE, Type.FLOAT_TYPE }), false);
    list.insert(position, get);
    list.remove(position);/*w w  w .ja v a2  s .  co m*/
}

From source file:org.evosuite.instrumentation.testability.ComparisonTransformation.java

License:Open Source License

private void insertDoubleComparisonG(AbstractInsnNode position, InsnList list) {
    MethodInsnNode get = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class),
            "doubleSubG",
            Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.DOUBLE_TYPE, Type.DOUBLE_TYPE }), false);
    list.insert(position, get);
    list.remove(position);//from ww w.j  ava2s.c o  m
}

From source file:org.evosuite.instrumentation.testability.ComparisonTransformation.java

License:Open Source License

private void insertDoubleComparisonL(AbstractInsnNode position, InsnList list) {
    MethodInsnNode get = new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(BooleanHelper.class),
            "doubleSubL",
            Type.getMethodDescriptor(Type.INT_TYPE, new Type[] { Type.DOUBLE_TYPE, Type.DOUBLE_TYPE }), false);
    list.insert(position, get);
    list.remove(position);//from  w w w.j av a 2  s.c  om
}

From source file:org.evosuite.testcarver.instrument.Instrumenter.java

License:Open Source License

private void instrumentGETXXXFieldAccesses(final ClassNode cn, final String internalClassName,
        final MethodNode methodNode) {
    final InsnList instructions = methodNode.instructions;

    AbstractInsnNode ins = null;// ww  w .  j a v  a2s .  co  m
    FieldInsnNode fieldIns = null;

    for (int i = 0; i < instructions.size(); i++) {
        ins = instructions.get(i);
        if (ins instanceof FieldInsnNode) {
            fieldIns = (FieldInsnNode) ins;

            /*
             * Is field referencing outermost instance? if yes, ignore it
             * http://tns-www.lcs.mit.edu/manuals/java-1.1.1/guide/innerclasses/spec/innerclasses.doc10.html
             */
            if (fieldIns.name.endsWith("$0")) {
                continue;
            }

            final int opcode = ins.getOpcode();
            if (opcode == Opcodes.GETFIELD || opcode == Opcodes.GETSTATIC) {
                final InsnList il = new InsnList();

                if (opcode == Opcodes.GETFIELD) {
                    Type fieldType = Type.getType(fieldIns.desc);
                    if (fieldType.getSize() == 1) {
                        instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP));
                        il.add(new InsnNode(Opcodes.SWAP));
                    } else if (fieldType.getSize() == 2) {
                        instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP));
                        // v
                        // GETFIELD
                        // v, w
                        il.add(new InsnNode(Opcodes.DUP2_X1));
                        // w, v, w
                        il.add(new InsnNode(Opcodes.POP2));
                        // w, v
                        // -> Call
                        // w
                    }
                } else
                    il.add(new InsnNode(Opcodes.ACONST_NULL));

                il.add(new LdcInsnNode(this.captureId));
                il.add(new LdcInsnNode(fieldIns.owner));
                il.add(new LdcInsnNode(fieldIns.name));
                il.add(new LdcInsnNode(fieldIns.desc));

                il.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
                        PackageInfo.getNameWithSlash(org.evosuite.testcarver.capture.FieldRegistry.class),
                        "notifyReadAccess",
                        "(Ljava/lang/Object;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"));

                i += il.size();

                instructions.insert(fieldIns, il);
                this.captureId++;
            }
        }
    }
}