Package org.objectweb.asm.tree

Examples of org.objectweb.asm.tree.MethodInsnNode


      int di = 0;

      for (int i = 0, e = m.instructions.size(); i < e; ++i) {
        AbstractInsnNode n = m.instructions.get(i);
        if (n.getType() == AbstractInsnNode.METHOD_INSN) {
          MethodInsnNode mn = (MethodInsnNode)n;
          if (n.getOpcode() == INVOKEINTERFACE && n.getNext().getOpcode() == INVOKEVIRTUAL) {
            if (names[2].equals(remapper.mapMethodName(mn.owner, mn.name, mn.desc))) {
              if (Csig.equals(remapper.mapMethodDesc(mn.desc)) &&
                  Ssig.equals(remapper.mapMethodDesc(((MethodInsnNode)mn.getNext()).desc))) {
                m.instructions.insertBefore(n, new FieldInsnNode(GETSTATIC, fd, dirs[di++], 'L'+fd+';'));
                m.instructions.insertBefore(n, new MethodInsnNode(INVOKEVIRTUAL, cc, "canPaneConnectTo", Rsig, false));
                m.instructions.remove(n.getNext());
                m.instructions.remove(n);
              }
            }
          }
View Full Code Here


      m.instructions.add(new VarInsnNode(ALOAD, 1));
      m.instructions.add(new VarInsnNode(ILOAD, 2));
      m.instructions.add(new VarInsnNode(ILOAD, 3));
      m.instructions.add(new VarInsnNode(ILOAD, 4));
      m.instructions.add(new VarInsnNode(ALOAD, 5));
      m.instructions.add(new MethodInsnNode(INVOKESTATIC, "cofh/asm/HooksCore", "paneConnectsTo", sig, false));
      m.instructions.add(new InsnNode(IRETURN));

      m.localVariables = null;

      ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
View Full Code Here

        if (names[0].equals(mName) && "()V".equals(m.desc)) {
          updated = true;
          for (int i = 0, e = m.instructions.size(); i < e; ++i) {
            AbstractInsnNode n = m.instructions.get(i);
            if (n.getOpcode() == INVOKEVIRTUAL) {
              MethodInsnNode mn = (MethodInsnNode) n;
              if (mOwner.equals(mn.owner) && names[1].equals(remapper.mapMethodName(mn.owner, mn.name, mn.desc)) && "()V".equals(mn.desc)) {
                m.instructions.set(mn, new MethodInsnNode(INVOKESTATIC, "cofh/asm/HooksCore", "tickTextures",
                    "(Lnet/minecraft/client/renderer/texture/ITickable;)V", false));
                break mc;
              }
            }
          }
View Full Code Here

      }

      for (int i = 0, e = m.instructions.size(); i < e; i++) {
        AbstractInsnNode n = m.instructions.get(i);
        if (n.getOpcode() == INVOKEVIRTUAL) {
          MethodInsnNode mn = (MethodInsnNode) n;
          if (itemstack.equals(mn.owner)) {
            LabelNode jmp = null, jmp2 = null;
            s: for (int j = i; j < e; ++j) {
              n = m.instructions.get(j);
              if (n.getOpcode() == ICONST_1) {
                for (int k = j; k > i; --k) {
                  n = m.instructions.get(k);
                  if (n.getType() == AbstractInsnNode.LABEL) {
                    jmp = (LabelNode) n;
                    break;
                  }
                }
                for (int k = j; k < e; ++k) {
                  n = m.instructions.get(k);
                  if (n.getType() == AbstractInsnNode.LABEL) {
                    jmp2 = (LabelNode) n;
                    break s;
                  }
                }
              }
            }
            if (jmp == null || jmp2 == null) {
              break l;
            }

            // presently on stack: player.getHeldItem()
            m.instructions.insertBefore(mn, new VarInsnNode(ALOAD, 0));
            m.instructions.insertBefore(mn, new FieldInsnNode(GETFIELD, name, names[1], 'L' + itemstack + ';'));
            final String clazz = "cofh/asm/HooksCore";
            final String method = "areItemsEqualHook";
            final String sign = "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z";
            m.instructions.insertBefore(mn, new MethodInsnNode(INVOKESTATIC, clazz, method, sign, false));
            m.instructions.insertBefore(mn, new JumpInsnNode(IFEQ, jmp2));
            m.instructions.insertBefore(mn, new JumpInsnNode(GOTO, jmp));
            break;
          }
        }
View Full Code Here

      m.instructions.add(new VarInsnNode(ALOAD, 1));
      m.instructions.add(new VarInsnNode(ILOAD, 2));
      m.instructions.add(new VarInsnNode(ILOAD, 3));
      m.instructions.add(new VarInsnNode(ILOAD, 4));
      m.instructions.add(new InsnNode(ICONST_0));
      m.instructions.add(new MethodInsnNode(INVOKESTATIC, "cofh/lib/util/helpers/InventoryHelper", "mergeItemStack",
          "(Ljava/util/List;Lnet/minecraft/item/ItemStack;IIZZ)Z", false));
      m.instructions.add(new InsnNode(IRETURN));

      // this fixes a crash in dev and with cauldron
      m.localVariables = null;
View Full Code Here

        m.instructions.insert(n, n = a);
        m.instructions.insert(n, n = new LineNumberNode(-15000, a));
        m.instructions.insert(n, n = new VarInsnNode(ALOAD, 0));
        m.instructions.insert(n, n = new TypeInsnNode(NEW, "cofh/lib/util/LinkedHashList"));
        m.instructions.insert(n, n = new InsnNode(DUP));
        m.instructions.insert(n, n = new MethodInsnNode(INVOKESPECIAL, "cofh/lib/util/LinkedHashList", "<init>", "()V", false));
        m.instructions.insert(n, n = new FieldInsnNode(PUTFIELD, "net/minecraft/world/World", "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;"));
      } else if ("addTileEntity".equals(m.name) && "(Lnet/minecraft/tileentity/TileEntity;)V".equals(remapper.mapMethodDesc(m.desc))) {
        addTileEntity = m;
      } else if (names[4].equals(remapper.mapMethodName(name, m.name, m.desc)) && "(Ljava/util/Collection;)V".equals(m.desc)) {
        addTileEntities = m;
      } else if (names[5].equals(remapper.mapMethodName(name, m.name, m.desc)) && "(IIILnet/minecraft/tileentity/TileEntity;)V".equals(remapper.mapMethodDesc(m.desc))) {
        setTileEntity = m;
      } else if (names[6].equals(remapper.mapMethodName(name, m.name, m.desc)) && "()V".equals(remapper.mapMethodDesc(m.desc))) {
        updateEntities = m;
      }
    }
    cn.fields.add(new FieldNode(ACC_PRIVATE, "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;", null, null));
    if (addTileEntity != null) {

      LabelNode a = new LabelNode(new Label());
      AbstractInsnNode n;
      addTileEntity.instructions.insert(n = a);
      addTileEntity.instructions.insert(n, n = new LineNumberNode(-15001, a));
      addTileEntity.instructions.insert(n, n = new VarInsnNode(ALOAD, 0));
      addTileEntity.instructions.insert(n, n = new FieldInsnNode(GETFIELD, "net/minecraft/world/World", "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;"));
      addTileEntity.instructions.insert(n, n = new VarInsnNode(ALOAD, 1));
      addTileEntity.instructions.insert(n, n = new MethodInsnNode(INVOKEVIRTUAL, "cofh/lib/util/LinkedHashList", "push", "(Ljava/lang/Object;)Z", false));
      addTileEntity.instructions.insert(n, n = new InsnNode(POP));
    }
    if (setTileEntity != null) {

      LabelNode a = new LabelNode(new Label());
      AbstractInsnNode n = setTileEntity.instructions.getLast();
      while (n.getOpcode() != RETURN) n = n.getPrevious();
      n = n.getPrevious();
      setTileEntity.instructions.insert(n = a);
      setTileEntity.instructions.insert(n, n = new LineNumberNode(-15002, a));
      setTileEntity.instructions.insert(n, n = new VarInsnNode(ALOAD, 0));
      setTileEntity.instructions.insert(n, n = new FieldInsnNode(GETFIELD, "net/minecraft/world/World", "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;"));
      setTileEntity.instructions.insert(n, n = new VarInsnNode(ALOAD, 4));
      setTileEntity.instructions.insert(n, n = new MethodInsnNode(INVOKEVIRTUAL, "cofh/lib/util/LinkedHashList", "push", "(Ljava/lang/Object;)Z", false));
      setTileEntity.instructions.insert(n, n = new InsnNode(POP));
    }
    if (addTileEntities != null) {
      LabelNode a = new LabelNode(new Label());
      AbstractInsnNode n = addTileEntities.instructions.getFirst();
      for (;;) {
        while (n.getOpcode() != CHECKCAST) n = n.getNext();
        if (remapper.mapType(((TypeInsnNode)n).desc).equals("net/minecraft/tileentity/TileEntity"))
          break;
      }
      addTileEntities.instructions.insert(n, n = a);
      addTileEntities.instructions.insert(n, n = new LineNumberNode(-15003, a));
      addTileEntities.instructions.insert(n, n = new InsnNode(DUP));
      addTileEntities.instructions.insert(n, n = new VarInsnNode(ALOAD, 0));
      addTileEntities.instructions.insert(n, n = new FieldInsnNode(GETFIELD, "net/minecraft/world/World", "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;"));
      addTileEntities.instructions.insert(n, n = new InsnNode(SWAP));
      addTileEntities.instructions.insert(n, n = new MethodInsnNode(INVOKEVIRTUAL, "cofh/lib/util/LinkedHashList", "push", "(Ljava/lang/Object;)Z", false));
      addTileEntities.instructions.insert(n, n = new InsnNode(POP));
    }
    if (updateEntities != null) {
      AbstractInsnNode n = updateEntities.instructions.getFirst();
      while (n.getOpcode() != INVOKEVIRTUAL ||
          !"onChunkUnload".equals(((MethodInsnNode)n).name) ||
          !"()V".equals(((MethodInsnNode)n).desc)) n = n.getNext();
      while (n.getOpcode() != PUTFIELD) n = n.getNext();
      n = n.getPrevious().getPrevious();
      LabelNode lStart = new LabelNode(new Label());
      LabelNode lCond = new LabelNode(new Label());
      LabelNode lGuard = new LabelNode(new Label());
      LabelNode a = new LabelNode(new Label());
      updateEntities.instructions.insert(n, n = a);
      updateEntities.instructions.insert(n, n = new LineNumberNode(-15004, a));
      updateEntities.instructions.insert(n, n = new JumpInsnNode(GOTO, lCond));
      updateEntities.instructions.insert(n, n = lStart);
      updateEntities.instructions.insert(n, n = new FrameNode(F_SAME, 0, null, 0, null));
      updateEntities.instructions.insert(n, n = new VarInsnNode(ALOAD, 0));
      updateEntities.instructions.insert(n, n = new FieldInsnNode(GETFIELD, "net/minecraft/world/World", "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;"));
      updateEntities.instructions.insert(n, n = new MethodInsnNode(INVOKEVIRTUAL, "cofh/lib/util/LinkedHashList", "shift", "()Ljava/lang/Object;", false));
      updateEntities.instructions.insert(n, n = new TypeInsnNode(CHECKCAST, "net/minecraft/tileentity/TileEntity"));
      updateEntities.instructions.insert(n, n = new InsnNode(DUP));
      updateEntities.instructions.insert(n, n = new JumpInsnNode(IFNULL, lGuard));
      updateEntities.instructions.insert(n, n = new MethodInsnNode(INVOKEVIRTUAL, "net/minecraft/tileentity/TileEntity", "cofh_validate", "()V", false));
      updateEntities.instructions.insert(n, n = new InsnNode(ACONST_NULL));
      updateEntities.instructions.insert(n, n = lGuard);
      updateEntities.instructions.insert(n, n = new InsnNode(POP));
      updateEntities.instructions.insert(n, n = lCond);
      updateEntities.instructions.insert(n, n = new FrameNode(F_SAME, 0, null, 0, null));
      updateEntities.instructions.insert(n, n = new VarInsnNode(ALOAD, 0));
      updateEntities.instructions.insert(n, n = new FieldInsnNode(GETFIELD, "net/minecraft/world/World", "cofh_recentTiles", "Lcofh/lib/util/LinkedHashList;"));
      updateEntities.instructions.insert(n, n = new MethodInsnNode(INVOKEVIRTUAL, "cofh/lib/util/LinkedHashList", "size", "()I", false));
      updateEntities.instructions.insert(n, n = new JumpInsnNode(IFNE, lStart));
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    cn.accept(cw);
View Full Code Here

      if ("<init>".equals(m.name)) {
        InsnList l = m.instructions;
        for (int i = 0, e = l.size(); i < e; i++) {
          AbstractInsnNode n = l.get(i);
          if (n instanceof MethodInsnNode) {
            MethodInsnNode mn = (MethodInsnNode) n;
            if (mn.getOpcode() == INVOKESPECIAL) {
              mn.owner = cn.superName;
              break;
            }
          }
        }
View Full Code Here

            Frame f = frames[i];
            if (f != null) { // reachable ?
                AbstractInsnNode in = mn.instructions.get(i);
                if (in.getType() == AbstractInsnNode.METHOD_INSN || in.getType() == AbstractInsnNode.INVOKE_DYNAMIC_INSN) {
                    Boolean susp = true;
                    MethodInsnNode min = null;
                    if (in.getType() == AbstractInsnNode.METHOD_INSN) {
                        min = (MethodInsnNode) in;
                        int opcode = min.getOpcode();

                        if (isReflectInvocation(min.owner, min.name))
                            db.log(LogLevel.DEBUG, "Reflective method call at instruction %d is assumed suspendable", i);
                        else if (isMethodHandleInvocation(min.owner, min.name))
                            db.log(LogLevel.DEBUG, "MethodHandle invocation at instruction %d is assumed suspendable", i);
View Full Code Here

        // This must be done here, before all other visitTryCatchBlock, because the exception's handler
        // will be matched according to the order of in which visitTryCatchBlock has been called. Earlier calls take precedence.
        Label[][] refInvokeTryCatch = new Label[numCodeBlocks - 1][];
        for (int i = 1; i < numCodeBlocks; i++) {
            FrameInfo fi = codeBlocks[i];
            MethodInsnNode min = (MethodInsnNode) (mn.instructions.get(fi.endInstruction));
            if (isReflectInvocation(min.owner, min.name)) {
                Label[] ls = new Label[3];
                for (int k = 0; k < 3; k++)
                    ls[k] = new Label();
                refInvokeTryCatch[i - 1] = ls;
                mv.visitTryCatchBlock(ls[0], ls[1], ls[2], "java/lang/reflect/InvocationTargetException");
            }
        }

        for (Object o : mn.tryCatchBlocks) {
            TryCatchBlockNode tcb = (TryCatchBlockNode) o;
            if (EXCEPTION_NAME.equals(tcb.type) && !hasAnnotation) // we allow catch of SuspendExecution in method annotated with @Suspendable.
                throw new UnableToInstrumentException("catch for SuspendExecution", className, mn.name, mn.desc);
            if (handleProxyInvocations && UNDECLARED_THROWABLE_NAME.equals(tcb.type)) // we allow catch of SuspendExecution in method annotated with @Suspendable.
                throw new UnableToInstrumentException("catch for UndeclaredThrowableException", className, mn.name, mn.desc);
//          if (INTERRUPTED_EXCEPTION_NAME.equals(tcb.type))
//              throw new UnableToInstrumentException("catch for " + InterruptedException.class.getSimpleName(), className, mn.name, mn.desc);

            tcb.accept(mv);
        }

        if (mn.visibleParameterAnnotations != null)
            dumpParameterAnnotations(mv, mn.visibleParameterAnnotations, true);

        if (mn.invisibleParameterAnnotations != null)
            dumpParameterAnnotations(mv, mn.invisibleParameterAnnotations, false);

        if (mn.visibleAnnotations != null) {
            for (Object o : mn.visibleAnnotations) {
                AnnotationNode an = (AnnotationNode) o;
                an.accept(mv.visitAnnotation(an.desc, true));
            }
        }

        mv.visitTryCatchBlock(lMethodStart, lMethodEnd, lCatchAll, null);

        mv.visitMethodInsn(Opcodes.INVOKESTATIC, STACK_NAME, "getStack", "()L" + STACK_NAME + ";");
        mv.visitInsn(Opcodes.DUP);
        mv.visitVarInsn(Opcodes.ASTORE, lvarStack);

        if (DUAL) {
            mv.visitJumpInsn(Opcodes.IFNULL, lMethodStart);
            mv.visitVarInsn(Opcodes.ALOAD, lvarStack);
        }

        emitStoreResumed(mv, true); // we'll assume we have been resumed

        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "nextMethodEntry", "()I");
        mv.visitTableSwitchInsn(1, numCodeBlocks - 1, lMethodStart, lMethodCalls);

        mv.visitLabel(lMethodStart);

        emitStoreResumed(mv, false); // no, we have not been resumed

        dumpCodeBlock(mv, 0, 0);

        for (int i = 1; i < numCodeBlocks; i++) {
            FrameInfo fi = codeBlocks[i];

            MethodInsnNode min = (MethodInsnNode) (mn.instructions.get(fi.endInstruction));
            if (isYieldMethod(min.owner, min.name)) { // special case - call to yield
                if (min.getOpcode() != Opcodes.INVOKESTATIC)
                    throw new UnableToInstrumentException("invalid call to suspending method.", className, mn.name, mn.desc);

                final int numYieldArgs = TypeAnalyzer.getNumArguments(min.desc);
                final boolean yieldReturnsValue = (Type.getReturnType(min.desc) != Type.VOID_TYPE);

                emitStoreState(mv, i, fi, numYieldArgs); // we preserve the arguments for the call to yield on the operand stack
                emitStoreResumed(mv, false); // we have not been resumed

                min.accept(mv);                              // we call the yield method
                if (yieldReturnsValue)
                    mv.visitInsn(Opcodes.POP);               // we ignore the returned value...
                mv.visitLabel(lMethodCalls[i - 1]);          // we resume AFTER the call

                final Label afterPostRestore = new Label();
                mv.visitVarInsn(Opcodes.ILOAD, lvarResumed);
                mv.visitJumpInsn(Opcodes.IFEQ, afterPostRestore);
                emitPostRestore(mv);
                mv.visitLabel(afterPostRestore);

                emitRestoreState(mv, i, fi, numYieldArgs);
                if (yieldReturnsValue)
                    mv.visitVarInsn(Opcodes.ILOAD, lvarResumed); // ... and replace the returned value with the value of resumed

                dumpCodeBlock(mv, i, 1);    // skip the call
            } else {
                final Label lbl = new Label();
                if (DUAL) {
                    mv.visitVarInsn(Opcodes.ALOAD, lvarStack);
                    mv.visitJumpInsn(Opcodes.IFNULL, lbl);
                }

                // normal case - call to a suspendable method - resume before the call
                emitStoreState(mv, i, fi, 0);
                emitStoreResumed(mv, false); // we have not been resumed
                emitPreemptionPoint(mv, PREEMPTION_CALL);

                mv.visitLabel(lMethodCalls[i - 1]);
                emitRestoreState(mv, i, fi, 0);

                if (DUAL)
                    mv.visitLabel(lbl);

                if (isReflectInvocation(min.owner, min.name)) {
                    // We catch the InvocationTargetException and unwrap it if it wraps a SuspendExecution exception.
                    Label[] ls = refInvokeTryCatch[i - 1];
                    final Label startTry = ls[0];
                    final Label endTry = ls[1];
                    final Label startCatch = ls[2];
                    final Label endCatch = new Label();
                    final Label notSuspendExecution = new Label();

                    // mv.visitTryCatchBlock(startTry, endTry, startCatch, "java/lang/reflect/InvocationTargetException");
                    mv.visitLabel(startTry);   // try {
                    min.accept(mv);            //   method.invoke()
                    mv.visitVarInsn(Opcodes.ASTORE, lvarInvocationReturnValue); // save return value
                    mv.visitLabel(endTry);     // }
                    mv.visitJumpInsn(Opcodes.GOTO, endCatch);
                    mv.visitLabel(startCatch); // catch(InvocationTargetException ex) {
                    mv.visitInsn(Opcodes.DUP);
View Full Code Here

                        db.log(LogLevel.WARNING, "Method %s#%s%s contains synchronisation", 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);
View Full Code Here

TOP

Related Classes of org.objectweb.asm.tree.MethodInsnNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.