Java Code Examples for org.objectweb.asm.tree.MethodInsnNode#getOpcode()

The following examples show how to use org.objectweb.asm.tree.MethodInsnNode#getOpcode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ASMMethodVariables.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
AbstractInsnNode findInitConstructorInstruction() {
    int nested = 0;
    for (AbstractInsnNode insnNode = this.methodNode.instructions.getFirst(); insnNode != null; insnNode = insnNode.getNext()) {
        if (insnNode instanceof TypeInsnNode) {
            if (insnNode.getOpcode() == Opcodes.NEW) {
                // new object().
                nested++;
            }
        } else if (insnNode instanceof MethodInsnNode) {
            final MethodInsnNode methodInsnNode = (MethodInsnNode) insnNode;
            if (methodInsnNode.getOpcode() == Opcodes.INVOKESPECIAL && methodInsnNode.name.equals("<init>")) {
                if (--nested < 0) {
                    // find this() or super().
                    return insnNode.getNext();
                }
            }
        }
    }

    return null;
}
 
Example 2
Source File: Transformer.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Convert code from using Class.X methods to our remapped versions
 */
public static byte[] transform(byte[] code) {
    ClassReader reader = new ClassReader(code); // Turn from bytes into visitor
    ClassNode node = new ClassNode();
    reader.accept(node, 0); // Visit using ClassNode

    for (MethodNode method : node.methods) { // Taken from SpecialSource
        ListIterator<AbstractInsnNode> insnIterator = method.instructions.iterator();
        while (insnIterator.hasNext()) {
            AbstractInsnNode insn = insnIterator.next();
            if (!(insn instanceof MethodInsnNode)) {
                continue;
            }
            MethodInsnNode mi = (MethodInsnNode) insn;
            switch (mi.getOpcode()) {
                case Opcodes.INVOKEVIRTUAL:
                    remapVirtual(mi);
                    break;
                case Opcodes.INVOKESTATIC:
                    remapForName(mi);
                    break;
            }
        }
    }

    ClassWriter writer = new ClassWriter(0);
    node.accept(writer);
    return writer.toByteArray();
}
 
Example 3
Source File: DefaultMethodClassFixer.java    From bazel with Apache License 2.0 5 votes vote down vote up
private boolean isClinitAlreadyDesugared(
    ImmutableList<String> companionsToAccessToTriggerInterfaceClinit) {
  InsnList instructions = clInitMethodNode.instructions;
  if (instructions.size() <= companionsToAccessToTriggerInterfaceClinit.size()) {
    // The <clinit> must end with RETURN, so if the instruction count is less than or equal to
    // the companion class count, this <clinit> has not been desugared.
    return false;
  }
  Iterator<AbstractInsnNode> iterator = instructions.iterator();
  for (String companion : companionsToAccessToTriggerInterfaceClinit) {
    if (!iterator.hasNext()) {
      return false;
    }
    AbstractInsnNode insn = iterator.next();
    if (!(insn instanceof MethodInsnNode)) {
      return false;
    }
    MethodInsnNode methodInsnNode = (MethodInsnNode) insn;
    if (methodInsnNode.getOpcode() != Opcodes.INVOKESTATIC
        || !methodInsnNode.owner.equals(companion)
        || !methodInsnNode.name.equals(
            InterfaceDesugaring.COMPANION_METHOD_TO_TRIGGER_INTERFACE_CLINIT_NAME)) {
      return false;
    }
    checkState(
        methodInsnNode.desc.equals(
            InterfaceDesugaring.COMPANION_METHOD_TO_TRIGGER_INTERFACE_CLINIT_DESC),
        "Inconsistent method desc: %s vs %s",
        methodInsnNode.desc,
        InterfaceDesugaring.COMPANION_METHOD_TO_TRIGGER_INTERFACE_CLINIT_DESC);
  }
  return true;
}
 
Example 4
Source File: FlowAnalyzer.java    From Concurnas with MIT License 4 votes vote down vote up
private static int getNumArgs(MethodInsnNode m) {
    int ret = TypeDesc.getNumArgumentTypes(m.desc);
    if (m.getOpcode() != INVOKESTATIC) ret++; 
    return ret;
}
 
Example 5
Source File: SearchEntry.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
public SearchEntry(ClassNode cn, MethodNode mn, MethodInsnNode min) {
  this(cn, mn, min.owner, min.name, min.desc, min.getOpcode());
}
 
Example 6
Source File: AbstractAsyncMethodTransformer.java    From tascalate-async-await with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void createAccessMethodsForAsyncMethod() {
    List<MethodNode> methods = methodsOf(classNode);
    for (Iterator<?> i = originalAsyncMethod.instructions.iterator(); i.hasNext();) {
        AbstractInsnNode instruction = (AbstractInsnNode) i.next();
        if (instruction instanceof MethodInsnNode) {
            MethodInsnNode methodInstructionNode = (MethodInsnNode) instruction;
            if ((methodInstructionNode.getOpcode() == INVOKEVIRTUAL || 
                 methodInstructionNode.getOpcode() == INVOKESPECIAL || 
                 methodInstructionNode.getOpcode() == INVOKESTATIC
                ) && methodInstructionNode.owner.equals(classNode.name)) {
                
                MethodNode targetMethodNode = getMethod(methodInstructionNode.name, methodInstructionNode.desc,
                        methods);
                if (null != targetMethodNode && (targetMethodNode.access & ACC_PRIVATE) != 0) {
                    log.debug("Found private call " + BytecodeTraceUtil.toString(methodInstructionNode));
                    createAccessMethod(methodInstructionNode,
                            (targetMethodNode.access & ACC_STATIC) != 0, methods);
                }
            }

            if (methodInstructionNode.getOpcode() == INVOKESPECIAL && 
                !"<init>".equals(methodInstructionNode.name)  && 
                !methodInstructionNode.owner.equals(classNode.name)) {
                // INVOKESPECIAL is used for constructors/super-call,
                // private instance methods
                // Here we filtered out only to private super-method calls
                log.debug("Found super-call " + BytecodeTraceUtil.toString(methodInstructionNode));
                createAccessMethod(methodInstructionNode, false, methods);
            }

        }
        if (instruction instanceof FieldInsnNode) {
            FieldInsnNode fieldInstructionNode = (FieldInsnNode) instruction;
            if (fieldInstructionNode.owner.equals(classNode.name)) {
                FieldNode targetFieldNode = 
                    getField(classNode, fieldInstructionNode.name, fieldInstructionNode.desc);
                
                if (null != targetFieldNode && (targetFieldNode.access & ACC_PRIVATE) != 0) {
                    // log.debug("Found " +
                    // BytecodeTraceUtil.toString(fieldInstructionNode));
                    if (fieldInstructionNode.getOpcode() == GETSTATIC || 
                        fieldInstructionNode.getOpcode() == GETFIELD) {
                        
                        createAccessGetter(fieldInstructionNode, (targetFieldNode.access & ACC_STATIC) != 0, methods);
                        
                    } else if (fieldInstructionNode.getOpcode() == PUTSTATIC || 
                               fieldInstructionNode.getOpcode() == PUTFIELD) {
                        
                        createAccessSetter(fieldInstructionNode, (targetFieldNode.access & ACC_STATIC) != 0, methods);
                    }
                }
            }
        }
        if (instruction instanceof InvokeDynamicInsnNode) {
            Object[] result = findOwnerInvokeDynamic(instruction, methods);
            if (null != result) {
                MethodNode method = (MethodNode)result[1];
                createAccessLambda((InvokeDynamicInsnNode)instruction, (Handle)result[0], (method.access & ACC_STATIC) != 0, methods);
            }
        }            
    }
}
 
Example 7
Source File: BytecodeTraceUtil.java    From tascalate-async-await with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static String toString(MethodInsnNode min) {
    // return AbstractVisitor.OPCODES[min.getOpcode()] + " " + min.owner + "
    // " + min.name + " " + min.desc;
    return min.getOpcode() + " " + min.owner + " " + min.name + " " + min.desc;
}