Package org.objectweb.asm.tree

Examples of org.objectweb.asm.tree.AbstractInsnNode


  public void transform(MethodNode mn) {
    InsnList insns = mn.instructions;
    Iterator i = insns.iterator();
    while (i.hasNext()) {
      AbstractInsnNode i1 = (AbstractInsnNode) i.next();
      if (isALOAD0(i1)) {
        AbstractInsnNode i2 = getNext(i1);
        if (i2 != null && isALOAD0(i2)) {
          AbstractInsnNode i3 = getNext(i2);
          if (i3 != null && i3.getOpcode() == GETFIELD) {
            AbstractInsnNode i4 = getNext(i3);
            if (i4 != null && i4.getOpcode() == PUTFIELD) {
              if (sameField(i3, i4)) {
                while (i.next() != i4) {
                }
                insns.remove(i1);
                insns.remove(i2);
View Full Code Here


        Object o = m.instructions.get(insn);
       
        if (o instanceof Label) {
          merge(insn + 1, f, subroutine);
        } else {
          AbstractInsnNode insnNode = (AbstractInsnNode)o;
          int insnOpcode = insnNode.getOpcode();
         
          current.init(f).execute(insnNode, interpreter);
          subroutine = subroutine == null ? null : subroutine.copy();
         
          if (insnNode instanceof JumpInsnNode) {
View Full Code Here

            }
            locals.addLast(local);
        }

        // now visit the instructions intercepting labels
        AbstractInsnNode insn = getFirst();
        while (insn != null) {
            insn.accept(mv);
            if (insn.getType() == AbstractInsnNode.LABEL) {
                LabelNode labelNode = (LabelNode) insn;
                Label label = labelNode.getLabel();
                List<LocalVariableNode> localStart = localStarts.get(label);
                List<LocalVariableNode> localEnd = localEnds.get(label);
                if (localStart != null) {
                    for (LocalVariableNode local : localStart) {
                        lsmv.visitLocalScopeStart(local.name, local.desc, local.signature, local.index, label.getOffset());
                    }
                }
                if (localEnd != null) {
                    for (LocalVariableNode local : localEnd) {
                        lsmv.visitLocalScopeEnd(local.name, local.desc, local.signature, local.index, label.getOffset());
                    }
                }
            }
            insn = insn.getNext();
        }
    }
View Full Code Here

   
    ByteBufferHelper bufferHelper = new ByteBufferHelper(meta);
   
    boolean shouldDoSetter = true;
    for (int i = 0; instructions.size() > i; i++) {
      AbstractInsnNode node = instructions.get(i);
      switch(node.getType()) {
        case AbstractInsnNode.FIELD_INSN:
          FieldInsnNode f = (FieldInsnNode)node;
          if (shouldDoSetter && isSettingFieldWithPrimitive(f)) {
            if (LOG) System.out.println(">> SETTING FIELD index=" + i);
            i = on(instructions, f)
View Full Code Here

  public boolean transform(MethodNode mn) {
    InsnList instructions = mn.instructions;
    boolean changed = false;
   
    for (int i = 0; instructions.size() > i; i++) {
      AbstractInsnNode node = instructions.get(i);
      if (AbstractInsnNode.FIELD_INSN != node.getType())
        continue;
     
      FieldInsnNode fn = (FieldInsnNode)node;
      if (className.equals(fn.owner))
        continue;
View Full Code Here

  public int transform() {
    ArrayList<Integer> offsets = new ArrayList<Integer>(insertions.keySet());
    Collections.sort(offsets, new ReversedComparator());
    for (int offset : offsets) {
      int refIndex = instructions.indexOf(reference);
      AbstractInsnNode ref = instructions.get(refIndex - offset);
      for (AbstractInsnNode n :  insertions.get(offset)) {
        instructions.insertBefore(ref, n);
      }
    }
   
View Full Code Here

          continue;
        }
        labels.add(catchNode.handler.getLabel());
       
        LabelNode labelNode = catchNode.handler;
        AbstractInsnNode lineNumberNode = labelNode.getNext() instanceof LineNumberNode ? labelNode.getNext() : labelNode;
        FrameNode frameNode = (FrameNode) lineNumberNode.getNext();
        VarInsnNode varInsnNode = (VarInsnNode) frameNode.getNext();
        AbstractInsnNode insertPoint = varInsnNode;
       
        if (catchNode.type == null) {
          // this is probably a finally block;
          if (insertPoint.getNext() != null && insertPoint.getNext() instanceof LabelNode) {
            insertPoint = insertPoint.getNext();
          }
        }
       
        LabelNode labelNode4ifeg = new LabelNode();
        InsnList newCode = new InsnList();
View Full Code Here

        ListIterator li = ins.iterator();

        // Look for the ALOAD 0 (i.e., push this on the stack)
        while (li.hasNext())
        {
            AbstractInsnNode node = (AbstractInsnNode) li.next();

            if (node.getOpcode() == ALOAD)
            {
                VarInsnNode varNode = (VarInsnNode) node;

                assert varNode.var == 0;

                // Remove the ALOAD
                li.remove();
                break;
            }
        }

        // Look for the call to the super-class, an INVOKESPECIAL
        while (li.hasNext())
        {
            AbstractInsnNode node = (AbstractInsnNode) li.next();

            if (node.getOpcode() == INVOKESPECIAL)
            {
                MethodInsnNode mnode = (MethodInsnNode) node;

                assert mnode.owner.equals(classNode.superName);
                assert mnode.name.equals(CONSTRUCTOR_NAME);
View Full Code Here

        ListIterator it = insns.iterator();

        while (it.hasNext())
        {
            AbstractInsnNode node = (AbstractInsnNode) it.next();

            int opcode = node.getOpcode();

            if (opcode != GETFIELD && opcode != PUTFIELD)
                continue;

            // Make sure we're talking about access to a field of this class, not some other
View Full Code Here

        LabelNode mStart = null;// (LabelNode) mn.instructions.getFirst();
        LabelNode mEnd = null; // (LabelNode) mn.instructions.getLast();

        for (ListIterator<AbstractInsnNode> i = mn.instructions.iterator(); i
                .hasNext();) {
            AbstractInsnNode node = i.next();
            if (node instanceof LabelNode) {
                if (mStart == null) {
                    mStart = (LabelNode) node;
                } else {
                    mEnd = (LabelNode) node;
                }
            } else {
                if (mStart == null) {
                    throw new RuntimeException(
                            "Expected instructions of " + cn.name + " : " + mn.name + " " + mn.desc + " to start with a label, got "
                                    + node.getClass());
                }
            }
        }

        Label mStartl = mStart.getLabel();
        if (mEnd == null) {
            mEnd = new LabelNode(new Label());
            mn.instructions.add(mEnd);
        }

        List<LocalVariableNode> paramsAndThis = new ArrayList<LocalVariableNode>();       
        for (Object o : mn.localVariables) {
            LocalVariableNode lvn = (LocalVariableNode) o;
            if (lvn.start.getLabel().equals(mStartl)) {
                paramsAndThis.add(lvn);
            }
        }
        int purrSecretIndex = 0;
        for (LocalVariableNode lvn : paramsAndThis) {
            purrSecretIndex += Type.getType(lvn.desc).getSize();
        }
        Set<String> lvNames = new HashSet<String>();
        for (Object o : mn.localVariables) {
            LocalVariableNode lvn = (LocalVariableNode) o;
            if (lvn.index >= purrSecretIndex) {
                lvn.index = lvn.index + 1;
            }
            lvNames.add(lvn.name);
        }
        String purrSecretUniqueName = makeUnique("_purrSecret", lvNames);

        mn.localVariables.add(paramsAndThis.size(), new LocalVariableNode(
                purrSecretUniqueName, OBJECT_DESC, null, mStart, mEnd,
                purrSecretIndex));
        mn.maxLocals += 1;

        for (Iterator<?> i = mn.instructions.iterator(); i.hasNext();) {
            Object current = i.next();
            if (current instanceof VarInsnNode) {
                VarInsnNode vin = (VarInsnNode) current;
                if (vin.var >= purrSecretIndex) {
                    vin.var = vin.var + 1;
                }
            }
            if (current instanceof IincInsnNode) {
                IincInsnNode iin = (IincInsnNode) current;
                iin.var = iin.var + 1;
                log("Incremented iinc var to " + iin.var);
            }
        }

        InsnList pre = new InsnList();
        // pre.add(vStart);
        if (isStatic) {
            pre.add(new LdcInsnNode(cn.name));
        } else {
            pre.add(new VarInsnNode(ALOAD, 0)); // "this" is index 0 locvar.
        }

        pre.add(new MethodInsnNode(INVOKESTATIC, classDesc, BEFORE,
                ONE_OBJECT_PARAM + OBJECT_DESC));
        pre.add(new VarInsnNode(ASTORE, purrSecretIndex));
        pre.add(fStart);
        mn.instructions.insert(mStart, pre);

        List<AbstractInsnNode> terminalNodes = new ArrayList<AbstractInsnNode>();
        for (int i = 0; i < mn.instructions.size(); i++) {
            AbstractInsnNode insn = mn.instructions.get(i);
            int opcode = insn.getOpcode();
            if (isReturnOpcode(opcode)) {
                terminalNodes.add(insn);
            }
        }
View Full Code Here

TOP

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

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.