Search in sources :

Example 46 with LdcInsnNode

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

the class Instrumenter method instrumentPUTXXXFieldAccesses.

private void instrumentPUTXXXFieldAccesses(final ClassNode cn, final String internalClassName, final MethodNode methodNode) {
    final InsnList instructions = methodNode.instructions;
    AbstractInsnNode ins = null;
    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.PUTFIELD || opcode == Opcodes.PUTSTATIC) {
                // construction of
                // Capturer.capture(final Object receiver, final String methodName, final Object[] methodParams)
                // call
                final InsnList il = new InsnList();
                if (opcode == Opcodes.PUTFIELD) {
                    Type fieldType = Type.getType(fieldIns.desc);
                    if (fieldType.getSize() == 1) {
                        instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP2));
                        il.add(new InsnNode(Opcodes.POP));
                    } else if (fieldType.getSize() == 2) {
                        InsnList uglyList = new InsnList();
                        // v, w
                        uglyList.add(new InsnNode(Opcodes.DUP2_X1));
                        // w, v, w
                        uglyList.add(new InsnNode(Opcodes.POP2));
                        // w, v
                        uglyList.add(new InsnNode(Opcodes.DUP));
                        // w, v, v
                        uglyList.add(new InsnNode(Opcodes.DUP2_X2));
                        // v, v, w, v, v
                        uglyList.add(new InsnNode(Opcodes.POP2));
                        // v, v, w
                        instructions.insertBefore(fieldIns, uglyList);
                    // PUTFIELD
                    // v
                    }
                } 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(FieldRegistry.class), "notifyModification", "(Ljava/lang/Object;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"));
                // PUTFIELDRegistry.notifyModification also adds corresponding GETFIELD capture instructions
                this.captureId++;
                i += il.size();
                instructions.insert(fieldIns, il);
                this.captureId++;
            }
        }
    }
}
Also used : FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) IntInsnNode(org.objectweb.asm.tree.IntInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) 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) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) InsnList(org.objectweb.asm.tree.InsnList) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 47 with LdcInsnNode

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

the class LCSAJsInstrumentation method addInstrumentation.

@SuppressWarnings("unchecked")
private void addInstrumentation(ClassLoader classLoader, MethodNode mn, String className, String methodName) {
    RawControlFlowGraph graph = GraphPool.getInstance(classLoader).getRawCFG(className, methodName);
    Iterator<AbstractInsnNode> j = mn.instructions.iterator();
    while (j.hasNext()) {
        AbstractInsnNode in = j.next();
        for (BytecodeInstruction v : graph.vertexSet()) {
            // If this is in the CFG and it's a branch...
            if (in.equals(v.getASMNode())) {
                if (v.isForcedBranch()) {
                    LCSAJPool.addLCSAJBranch(BranchPool.getInstance(classLoader).getBranchForInstruction(v));
                    int branchId = BranchPool.getInstance(classLoader).getActualBranchIdForNormalBranchInstruction(v);
                    InsnList instrumentation = new InsnList();
                    instrumentation.add(new LdcInsnNode(v.getASMNode().getOpcode()));
                    instrumentation.add(new LdcInsnNode(branchId));
                    instrumentation.add(new LdcInsnNode(v.getInstructionId()));
                    instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/evosuite/testcase/ExecutionTracer", "passedUnconditionalBranch", "(III)V"));
                    if (v.isLabel())
                        mn.instructions.insert(v.getASMNode(), instrumentation);
                    else
                        mn.instructions.insertBefore(v.getASMNode(), instrumentation);
                }
            }
        }
    }
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) BytecodeInstruction(org.evosuite.graphs.cfg.BytecodeInstruction) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnList(org.objectweb.asm.tree.InsnList) RawControlFlowGraph(org.evosuite.graphs.cfg.RawControlFlowGraph)

Example 48 with LdcInsnNode

use of org.objectweb.asm.tree.LdcInsnNode in project cassandra by apache.

the class MonitorMethodTransformer method invokePreMonitorEnter.

void invokePreMonitorEnter() {
    pushRef();
    instructions.add(new LdcInsnNode(monitorDelayChance.get()));
    instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "org/apache/cassandra/simulator/systems/InterceptorOfSystemMethods$Global", "preMonitorEnter", "(Ljava/lang/Object;F)Ljava/lang/Object;", false));
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode)

Example 49 with LdcInsnNode

use of org.objectweb.asm.tree.LdcInsnNode in project spring-loaded by spring-projects.

the class TypeDiffComputer method sameLdcInsnNode.

private static boolean sameLdcInsnNode(AbstractInsnNode o, AbstractInsnNode n) {
    LdcInsnNode oi = (LdcInsnNode) o;
    if (!(n instanceof LdcInsnNode)) {
        return false;
    }
    LdcInsnNode ni = (LdcInsnNode) n;
    Object ocst = oi.cst;
    if (ocst instanceof Integer) {
        if (!(ni.cst instanceof Integer)) {
            return false;
        }
        return ((Integer) ocst).equals(ni.cst);
    }
    if (ocst instanceof Float) {
        if (!(ni.cst instanceof Float)) {
            return false;
        }
        return ((Float) ocst).equals(ni.cst);
    }
    if (ocst instanceof Long) {
        if (!(ni.cst instanceof Long)) {
            return false;
        }
        return ((Long) ocst).equals(ni.cst);
    }
    if (ocst instanceof Double) {
        if (!(ni.cst instanceof Double)) {
            return false;
        }
        return ((Double) ocst).equals(ni.cst);
    }
    if (ocst instanceof String) {
        if (!(ni.cst instanceof String)) {
            return false;
        }
        return ((String) ocst).equals(ni.cst);
    }
    // must be Type
    return ((Type) ocst).equals(ni.cst);
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) Type(org.objectweb.asm.Type)

Example 50 with LdcInsnNode

use of org.objectweb.asm.tree.LdcInsnNode in project parseq by linkedin.

the class Util method getDescriptionForTypeInsnNode.

/* package private */
static String getDescriptionForTypeInsnNode(TypeInsnNode typeInsnNode) {
    AbstractInsnNode nextInsn = typeInsnNode.getNext();
    StringJoiner argsDesc = new StringJoiner(",", "(", ")");
    while (nextInsn != null) {
        if (nextInsn instanceof LdcInsnNode) {
            argsDesc.add("_");
        } else if (nextInsn.getOpcode() == Opcodes.DUP) {
        // ignore
        } else {
            break;
        }
        nextInsn = nextInsn.getNext();
    }
    if (typeInsnNode.getOpcode() == Opcodes.NEW) {
        return "new " + Util.extractSimpleName(typeInsnNode.desc, "/") + argsDesc.toString();
    }
    return "";
}
Also used : LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) StringJoiner(java.util.StringJoiner)

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