Search in sources :

Example 21 with MethodInsnNode

use of org.objectweb.asm.tree.MethodInsnNode in project quasar by puniverse.

the class InstrumentMethod method dumpCodeBlock.

private void dumpCodeBlock(MethodVisitor mv, int idx, int skip) {
    int start = codeBlocks[idx].endInstruction;
    int end = codeBlocks[idx + 1].endInstruction;
    for (int i = start + skip; i < end; i++) {
        AbstractInsnNode ins = mn.instructions.get(i);
        switch(ins.getOpcode()) {
            case Opcodes.RETURN:
            case Opcodes.ARETURN:
            case Opcodes.IRETURN:
            case Opcodes.LRETURN:
            case Opcodes.FRETURN:
            case Opcodes.DRETURN:
                emitPopMethod(mv);
                break;
            case Opcodes.MONITORENTER:
            case Opcodes.MONITOREXIT:
                if (!db.isAllowMonitors()) {
                    if (!className.equals("clojure/lang/LazySeq"))
                        throw new UnableToInstrumentException("synchronization", className, mn.name, mn.desc);
                } else if (!warnedAboutMonitors) {
                    warnedAboutMonitors = true;
                    db.log(LogLevel.WARNING, "Method %s#%s%s contains synchronization", className, mn.name, mn.desc);
                }
                break;
            case Opcodes.INVOKESPECIAL:
                MethodInsnNode min = (MethodInsnNode) ins;
                if ("<init>".equals(min.name)) {
                    int argSize = TypeAnalyzer.getNumArguments(min.desc);
                    Frame frame = frames[i];
                    int stackIndex = frame.getStackSize() - argSize - 1;
                    Value thisValue = frame.getStack(stackIndex);
                    if (stackIndex >= 1 && isNewValue(thisValue, true) && isNewValue(frame.getStack(stackIndex - 1), false)) {
                        if (isOmitted((NewValue) thisValue))
                            // explanation in emitNewAndDup
                            emitNewAndDup(mv, frame, stackIndex, min);
                    } else {
                        db.log(LogLevel.WARNING, "Expected to find a NewValue on stack index %d: %s", stackIndex, frame);
                    }
                }
                break;
        }
        ins.accept(mv);
    }
}
Also used : Frame(org.objectweb.asm.tree.analysis.Frame) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) BasicValue(org.objectweb.asm.tree.analysis.BasicValue) Value(org.objectweb.asm.tree.analysis.Value) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 22 with MethodInsnNode

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

the class TypeDiffComputer method computeAnyMethodDifferences.

/**
	 * Determine if there any differences between the methods supplied. A MethodDelta object is built to record any
	 * differences and stored against the type delta.
	 *
	 * @param oMethod 'old' method
	 * @param nMethod 'new' method
	 * @param td the type delta where changes are currently being accumulated
	 */
private static void computeAnyMethodDifferences(MethodNode oMethod, MethodNode nMethod, TypeDelta td) {
    MethodDelta md = new MethodDelta(oMethod.name, oMethod.desc);
    if (oMethod.access != nMethod.access) {
        md.setAccessChanged(oMethod.access, nMethod.access);
    }
    // TODO annotations
    InsnList oInstructions = oMethod.instructions;
    InsnList nInstructions = nMethod.instructions;
    if (oInstructions.size() != nInstructions.size()) {
        md.setInstructionsChanged(oInstructions.toArray(), nInstructions.toArray());
    } else {
        // TODO Just interested in constructors right now - should add others
        if (oMethod.name.charAt(0) == '<') {
            String oInvokeSpecialDescriptor = null;
            String nInvokeSpecialDescriptor = null;
            int oUninitCount = 0;
            int nUninitCount = 0;
            boolean codeChange = false;
            for (int i = 0, max = oInstructions.size(); i < max; i++) {
                AbstractInsnNode oInstruction = oInstructions.get(i);
                AbstractInsnNode nInstruction = nInstructions.get(i);
                if (!codeChange) {
                    if (!sameInstruction(oInstruction, nInstruction)) {
                        codeChange = true;
                    }
                }
                if (oInstruction.getType() == AbstractInsnNode.TYPE_INSN) {
                    if (oInstruction.getOpcode() == Opcodes.NEW) {
                        oUninitCount++;
                    }
                }
                if (nInstruction.getType() == AbstractInsnNode.TYPE_INSN) {
                    if (nInstruction.getOpcode() == Opcodes.NEW) {
                        nUninitCount++;
                    }
                }
                if (oInstruction.getType() == AbstractInsnNode.METHOD_INSN) {
                    MethodInsnNode mi = (MethodInsnNode) oInstruction;
                    if (mi.getOpcode() == INVOKESPECIAL && mi.name.equals("<init>")) {
                        if (oUninitCount == 0) {
                            // this is the one!
                            oInvokeSpecialDescriptor = mi.desc;
                        } else {
                            oUninitCount--;
                        }
                    }
                }
                if (nInstruction.getType() == AbstractInsnNode.METHOD_INSN) {
                    MethodInsnNode mi = (MethodInsnNode) nInstruction;
                    if (mi.getOpcode() == INVOKESPECIAL && mi.name.equals("<init>")) {
                        if (nUninitCount == 0) {
                            // this is the one!
                            nInvokeSpecialDescriptor = mi.desc;
                        } else {
                            nUninitCount--;
                        }
                    }
                }
            }
            // Has the invokespecial changed?
            if (oInvokeSpecialDescriptor == null) {
                if (nInvokeSpecialDescriptor != null) {
                    md.setInvokespecialChanged(oInvokeSpecialDescriptor, nInvokeSpecialDescriptor);
                }
            } else {
                if (!oInvokeSpecialDescriptor.equals(nInvokeSpecialDescriptor)) {
                    md.setInvokespecialChanged(oInvokeSpecialDescriptor, nInvokeSpecialDescriptor);
                }
            }
            if (codeChange) {
                md.setCodeChanged(oInstructions.toArray(), nInstructions.toArray());
            }
        }
    }
    if (md.hasAnyChanges()) {
        // it needs recording
        td.addChangedMethod(md);
    }
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) InsnList(org.objectweb.asm.tree.InsnList) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 23 with MethodInsnNode

use of org.objectweb.asm.tree.MethodInsnNode in project pinpoint by naver.

the class ASMMethodNodeAdapter method addDelegator.

public void addDelegator(final String superClassInternalName) {
    if (superClassInternalName == null) {
        throw new IllegalArgumentException("super class internal name must not be null.");
    }
    final InsnList instructions = this.methodNode.instructions;
    if (isStatic()) {
        this.methodVariables.initLocalVariables(instructions);
        // load parameters
        this.methodVariables.loadArgs(instructions);
        // invoke static
        instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, superClassInternalName, this.methodNode.name, this.methodNode.desc, false));
    } else {
        this.methodVariables.initLocalVariables(instructions);
        // load this
        this.methodVariables.loadVar(instructions, 0);
        // load parameters
        this.methodVariables.loadArgs(instructions);
        // invoke special
        instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, superClassInternalName, this.methodNode.name, this.methodNode.desc, false));
    }
    // return
    this.methodVariables.returnValue(instructions);
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) InsnList(org.objectweb.asm.tree.InsnList)

Example 24 with MethodInsnNode

use of org.objectweb.asm.tree.MethodInsnNode in project pinpoint by naver.

the class ASMMethodNodeAdapter method remapMethodInsnNode.

public void remapMethodInsnNode(final ASMMethodInsnNodeRemapper remapper) {
    AbstractInsnNode insnNode = this.methodNode.instructions.getFirst();
    while (insnNode != null) {
        if (insnNode instanceof MethodInsnNode) {
            final MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode;
            remapper.mapping(methodInsnNode);
        }
        insnNode = insnNode.getNext();
    }
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Example 25 with MethodInsnNode

use of org.objectweb.asm.tree.MethodInsnNode in project drill by apache.

the class ReplacingInterpreter method naryOperation.

@Override
public BasicValue naryOperation(final AbstractInsnNode insn, final List<? extends BasicValue> values) throws AnalyzerException {
    if (insn instanceof MethodInsnNode) {
        boolean skipOne = insn.getOpcode() != Opcodes.INVOKESTATIC;
        // Note if the argument is a holder, and is used as a function argument
        for (BasicValue value : values) {
            // if non-static method, skip over the receiver
            if (skipOne) {
                skipOne = false;
                continue;
            }
            if (value instanceof ReplacingBasicValue) {
                final ReplacingBasicValue argument = (ReplacingBasicValue) value;
                argument.setFunctionArgument();
            }
        }
    }
    return super.naryOperation(insn, values);
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) BasicValue(org.objectweb.asm.tree.analysis.BasicValue)

Aggregations

MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)26 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)12 MethodNode (org.objectweb.asm.tree.MethodNode)5 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)4 ArrayList (java.util.ArrayList)3 Type (org.objectweb.asm.Type)3 InsnList (org.objectweb.asm.tree.InsnList)3 InvokeDynamicInsnNode (org.objectweb.asm.tree.InvokeDynamicInsnNode)3 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)3 BasicValue (org.objectweb.asm.tree.analysis.BasicValue)3 List (java.util.List)2 AnnotationNode (org.objectweb.asm.tree.AnnotationNode)2 ClassNode (org.objectweb.asm.tree.ClassNode)2 FieldNode (org.objectweb.asm.tree.FieldNode)2 InsnNode (org.objectweb.asm.tree.InsnNode)2 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)2 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)2 Frame (org.objectweb.asm.tree.analysis.Frame)2 SuspendableType (co.paralleluniverse.fibers.instrument.MethodDatabase.SuspendableType)1 com.mxgraph.swing.mxGraphComponent (com.mxgraph.swing.mxGraphComponent)1