Examples of AbstractInsnNode


Examples of org.objectweb.asm.tree.AbstractInsnNode

          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

Examples of org.objectweb.asm.tree.AbstractInsnNode

        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

Examples of org.objectweb.asm.tree.AbstractInsnNode

        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

Examples of org.objectweb.asm.tree.AbstractInsnNode

        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

Examples of org.objectweb.asm.tree.AbstractInsnNode

    }

    private boolean isObjectArgumentToRuleCreatingMethodCall(InstructionGraphNode node,
                                                             InstructionGraphNode dependent) {
        // is the single dependent a method call ?
        AbstractInsnNode insn = dependent.getInstruction();
        if (insn.getType() != AbstractInsnNode.METHOD_INSN) return false;

        // Does this method call return a Rule ?
        MethodInsnNode mi = (MethodInsnNode) insn;
        if (!RULE.equals(Type.getReturnType(mi.desc))) return false;
View Full Code Here

Examples of org.objectweb.asm.tree.AbstractInsnNode

        return "java/lang/Object".equals(argTypes[argIndex].getInternalName());
    }

    private boolean isStoredIntoObjectArray(InstructionGraphNode dependent) {
        // is the single dependent an AASTORE instruction ?
        AbstractInsnNode insn = dependent.getInstruction();
        if (insn.getOpcode() != AASTORE) return false;

        // Does this instruction store into an array of Object ?
        List<InstructionGraphNode> dependents = getDependents(dependent);
        Preconditions.checkState(dependents.size() == 1); // an AASTORE instruction should have exactly one dependent
        AbstractInsnNode newArrayInsn = dependents.get(0).getInstruction();
        Preconditions.checkState(newArrayInsn.getOpcode() == ANEWARRAY); // which should be a n ANEWARRAY instruction
        return "java/lang/Object".equals(((TypeInsnNode) newArrayInsn).desc);
    }
View Full Code Here

Examples of org.objectweb.asm.tree.AbstractInsnNode

    public void process(@NotNull ParserClassNode classNode, @NotNull RuleMethod method) throws Exception {
        if (method.getNumberOfReturns() == 1) return;
        Preconditions.checkState(method.getNumberOfReturns() > 1);

        AbstractInsnNode current = method.instructions.getLast();

        // find last return
        while (current.getOpcode() != ARETURN) {
            current = current.getPrevious();
        }

        LabelNode lastReturnLabel = new LabelNode();
        method.instructions.insertBefore(current, lastReturnLabel);

        // iterate backwards up to first instructions
        while ((current = current.getPrevious()) != null) {

            // replace returns with gotos
            if (current.getOpcode() == ARETURN) {
                JumpInsnNode gotoInstruction = new JumpInsnNode(GOTO, lastReturnLabel);
                method.instructions.set(current, gotoInstruction);
                current = gotoInstruction;
            }
        }
View Full Code Here

Examples of org.objectweb.asm.tree.AbstractInsnNode

    }

    private boolean isObjectArgumentToRuleCreatingMethodCall(InstructionGraphNode node,
                                                             InstructionGraphNode dependent) {
        // is the single dependent a method call ?
        AbstractInsnNode insn = dependent.getInstruction();
        if (insn.getType() != AbstractInsnNode.METHOD_INSN) return false;

        // Does this method call return a Rule ?
        MethodInsnNode mi = (MethodInsnNode) insn;
        if (!RULE.equals(Type.getReturnType(mi.desc))) return false;
View Full Code Here

Examples of org.objectweb.asm.tree.AbstractInsnNode

        return "java/lang/Object".equals(argTypes[argIndex].getInternalName());
    }

    private boolean isStoredIntoObjectArray(InstructionGraphNode dependent) {
        // is the single dependent an AASTORE instruction ?
        AbstractInsnNode insn = dependent.getInstruction();
        if (insn.getOpcode() != AASTORE) return false;

        // Does this instruction store into an array of Object ?
        List<InstructionGraphNode> dependents = getDependents(dependent);
        Preconditions.checkState(dependents.size() == 1); // an AASTORE instruction should have exactly one dependent
        AbstractInsnNode newArrayInsn = dependents.get(0).getInstruction();
        Preconditions.checkState(newArrayInsn.getOpcode() == ANEWARRAY); // which should be a n ANEWARRAY instruction
        return "java/lang/Object".equals(((TypeInsnNode) newArrayInsn).desc);
    }
View Full Code Here

Examples of org.objectweb.asm.tree.AbstractInsnNode

    public void process(@NotNull ParserClassNode classNode, @NotNull RuleMethod method) throws Exception {
        if (method.getNumberOfReturns() == 1) return;
        Preconditions.checkState(method.getNumberOfReturns() > 1);

        AbstractInsnNode current = method.instructions.getLast();

        // find last return
        while (current.getOpcode() != ARETURN) {
            current = current.getPrevious();
        }

        LabelNode lastReturnLabel = new LabelNode();
        method.instructions.insertBefore(current, lastReturnLabel);

        // iterate backwards up to first instructions
        while ((current = current.getPrevious()) != null) {

            // replace returns with gotos
            if (current.getOpcode() == ARETURN) {
                JumpInsnNode gotoInstruction = new JumpInsnNode(GOTO, lastReturnLabel);
                method.instructions.set(current, gotoInstruction);
                current = gotoInstruction;
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.