Package org.objectweb.asm.tree

Examples of org.objectweb.asm.tree.InsnList


    }
  }

  @Override
  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))
View Full Code Here


            insertPoint = insertPoint.getNext();
          }
        }
       
        LabelNode labelNode4ifeg = new LabelNode();
        InsnList newCode = new InsnList();
        newCode.add(new VarInsnNode(Opcodes.ALOAD, varInsnNode.var));
        newCode.add(new TypeInsnNode(Opcodes.INSTANCEOF, INTERRUPT_EXCEPTION_NAME));
        newCode.add(new JumpInsnNode(Opcodes.IFEQ, labelNode4ifeg));
        newCode.add(new VarInsnNode(Opcodes.ALOAD, varInsnNode.var));
        newCode.add(new TypeInsnNode(Opcodes.CHECKCAST, INTERRUPT_EXCEPTION_NAME));
        newCode.add(new InsnNode(Opcodes.ATHROW));
        newCode.add(labelNode4ifeg);
        m.instructions.insert(insertPoint, newCode);
      }
    }
  }
View Full Code Here

        classNode.methods.add(newConstructor);
    }

    private void stripOutSuperConstructorCall(MethodNode cons)
    {
        InsnList ins = cons.instructions;

        ListIterator li = ins.iterator();

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

        }
    }

    private void interceptFieldAccess(MethodNode methodNode)
    {
        InsnList insns = methodNode.instructions;

        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
            // visible field of another class.

            FieldInsnNode fnode = (FieldInsnNode) node;

            if (!fnode.owner.equals(classNode.name))
                continue;

            Map<String, String> fieldToMethod = opcode == GETFIELD ? fieldToReadMethod : fieldToWriteMethod;

            String methodName = fieldToMethod.get(fnode.name);

            if (methodName == null)
                continue;

            String methodDescription = opcode == GETFIELD ? "()" + fnode.desc : "(" + fnode.desc + ")V";

            // Replace the field access node with the appropriate method invocation.

            insns.insertBefore(fnode, new MethodInsnNode(INVOKEVIRTUAL, fnode.owner, methodName, methodDescription));

            it.remove();
        }
    }
View Full Code Here

                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);
            }
        }

        LabelNode okReturnLabel = new LabelNode( new Label() );
//        LabelNode throwReturnLabel = new LabelNode( new Label() );
        Integer returnOpcode = null;
        for (AbstractInsnNode ain : terminalNodes) {
//            mn.instructions.insertBefore(ain,
//                    preExitInsns(cn, mn, purrSecretIndex));
//            if (  ain.getOpcode() == ATHROW ) {
//                mn.instructions.insert( ain, new JumpInsnNode( GOTO, throwReturnLabel ));
//            }
//           else {
                mn.instructions.insert( ain, new JumpInsnNode( GOTO, okReturnLabel ));
                if ( returnOpcode == null ) {
                    returnOpcode = ain.getOpcode();                   
                }
                else {
                    if ( returnOpcode.intValue() != ain.getOpcode() ) {
                        throw new RuntimeException( "Multiple return types: " + returnOpcode + " and " + ain.getOpcode() );
                    }
//               }
            }
            mn.instructions.remove( ain );
        }

        InsnList coda = new InsnList();
        coda.add( okReturnLabel );
        coda.add( preExitInsns( cn, mn, purrSecretIndex ));
        coda.add( new InsnNode( returnOpcode ));
        coda.add(fEnd);
//        coda.add( throwReturnLabel );
        coda.add(preExitInsns(cn, mn, purrSecretIndex));
        coda.add(new InsnNode(ATHROW));
        mn.instructions.insertBefore(mEnd, coda);

        for (Object o : mn.tryCatchBlocks) {
            TryCatchBlockNode tcbn = (TryCatchBlockNode) o;
            if (tcbn.start == mStart) {
View Full Code Here

        return name;
    }
       

    InsnList preExitInsns(ClassNode cn, MethodNode mn, int varIndex ) {
        InsnList post = new InsnList();
        if ( (mn.access & ACC_STATIC) != 0 ) {
            post.add( new LdcInsnNode( cn.name ));
        }
        else {
            post.add( new VarInsnNode( ALOAD, 0 ));
        }
        post.add( new VarInsnNode( ALOAD, varIndex ));
        post.add( new MethodInsnNode( INVOKESTATIC, classDesc, "after", TWO_OBJECT_PARAM +"V"));
        return post;
    }
View Full Code Here

        }
    }

    // sort the group instructions according to their method index
    private void sort(InstructionGroup group) {
        final InsnList instructions = method.instructions;
        Collections.sort(group.getNodes(), new Comparator<InstructionGraphNode>() {
            public int compare(InstructionGraphNode a, InstructionGraphNode b) {
                return Integer.valueOf(instructions.indexOf(a.getInstruction()))
                        .compareTo(instructions.indexOf(b.getInstruction()));
            }
        });
    }
View Full Code Here

        }
    }

    // sort the group instructions according to their method index
    private void sort(InstructionGroup group) {
        final InsnList instructions = method.instructions;
        Collections.sort(group.getNodes(), new Comparator<InstructionGraphNode>() {
            public int compare(InstructionGraphNode a, InstructionGraphNode b) {
                return Integer.valueOf(instructions.indexOf(a.getInstruction()))
                        .compareTo(instructions.indexOf(b.getInstruction()));
            }
        });
    }
View Full Code Here

    public boolean appliesTo(@NotNull ParserClassNode classNode, @NotNull RuleMethod method) {
        return method.containsPotentialSuperCalls();
    }

    public void process(@NotNull ParserClassNode classNode, @NotNull RuleMethod method) throws Exception {
        InsnList instructions = method.instructions;
        AbstractInsnNode insn = instructions.getFirst();
        while (insn.getOpcode() != ARETURN) {
            if (insn.getOpcode() == INVOKESPECIAL) {
                process(classNode, method, (MethodInsnNode) insn);
            }
            insn = insn.getNext();
View Full Code Here

    public boolean appliesTo(@NotNull ParserClassNode classNode, @NotNull RuleMethod method) {
        return method.containsPotentialSuperCalls();
    }

    public void process(@NotNull ParserClassNode classNode, @NotNull RuleMethod method) throws Exception {
        InsnList instructions = method.instructions;
        AbstractInsnNode insn = instructions.getFirst();
        while (insn.getOpcode() != ARETURN) {
            if (insn.getOpcode() == INVOKESPECIAL) {
                process(classNode, method, (MethodInsnNode) insn);
            }
            insn = insn.getNext();
View Full Code Here

TOP

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

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.