Examples of LabelNode


Examples of org.objectweb.asm.tree.LabelNode

      return al;
    }
 
    LabelNode getLabel(int intValue) {
      if (!_labels.containsKey(intValue)) {
        _labels.put(intValue, new LabelNode());
      }
      return _labels.get(intValue);
    }
View Full Code Here

Examples of org.objectweb.asm.tree.LabelNode

        writer.write("\n\t\t\t\tinteger(" + n.getOpcode() + ", " + n.operand + ")");
      } else if (ai instanceof JumpInsnNode) {
        JumpInsnNode n = ((JumpInsnNode)ai);
        writer.write("\n\t\t\t\tjump(" + n.getOpcode() + ", " + getLabelIndex(n.label) + ")");
      } else if (ai instanceof LabelNode) {
        LabelNode n = ((LabelNode)ai);
        writer.write("\n\t\t\t\tlabel(" + getLabelIndex(n) + ")");
      } else if (ai instanceof LineNumberNode) {
        LineNumberNode n = ((LineNumberNode)ai);
        writer.write("\n\t\t\t\tlineNumber(" + n.line + ", " + getLabelIndex(n.start) + ")");
      } else if (ai instanceof VarInsnNode) {
        VarInsnNode n = ((VarInsnNode)ai);
        writer.write("\n\t\t\t\tlocalVariable(" + n.getOpcode() + ", " + n.var + ")");
      } else if (ai instanceof LdcInsnNode) {
        LdcInsnNode n = ((LdcInsnNode)ai);
        if (n.cst instanceof String) {
          writer.write("\n\t\t\t\tloadConstantString(\"" + escape((String)n.cst) + "\")");
        } else if (n.cst instanceof Integer) {
          writer.write("\n\t\t\t\tloadConstantInteger(" + n.cst + ")");
        } else if (n.cst instanceof Long) {
          writer.write("\n\t\t\t\tloadConstantLong(" + n.cst + ")");
        } else if (n.cst instanceof Float) {
          writer.write("\n\t\t\t\tloadConstantFloat(" + n.cst + ")");
        } else if (n.cst instanceof Double) {
          writer.write("\n\t\t\t\tloadConstantDouble(" + n.cst + ")");
        }
      } else if (ai instanceof LookupSwitchInsnNode) {
        LookupSwitchInsnNode n = ((LookupSwitchInsnNode)ai);
        writer.write("\n\t\t\t\tlookupSwitch(" + getLabelIndex(n.dflt) + ", [");
        boolean firstKey = true;
        for (Integer k : (List<Integer>)n.keys) {
          if (firstKey) { firstKey = false; } else { writer.write(", "); }
          writer.write(k);
        }
        writer.write("], [");
        boolean firstCase = true;
        for (LabelNode l : (List<LabelNode>)n.labels) {
          if (firstCase) { firstCase = false; } else { writer.write(", "); }
          writer.write("" + getLabelIndex(l));
        }
        writer.write("])");
      } else if (ai instanceof MethodInsnNode) {
        MethodInsnNode n = ((MethodInsnNode)ai);
        writer.write("\n\t\t\t\tmethod(" + n.getOpcode() + ", \"" + escape(n.owner) + "\", \"" + escape(n.name) + "\", \"" + escape(n.desc) + "\")");
      } else if (ai instanceof MultiANewArrayInsnNode) {
        MultiANewArrayInsnNode n = ((MultiANewArrayInsnNode)ai);
        writer.write("\n\t\t\t\tmultiANewArray(\"" + escape(n.desc) + "\", " + n.dims + ")");
      } else if (ai instanceof TableSwitchInsnNode) {
        TableSwitchInsnNode n = ((TableSwitchInsnNode)ai);
        writer.write("\n\t\t\t\ttableSwitch(" + n.min + ", " + n.max + ", " + getLabelIndex(n.dflt) + ", [");
        boolean firstCase = true;
        for (LabelNode l : (List<LabelNode>)n.labels) {
          if (firstCase) { firstCase = false; } else { writer.write(", "); }
          writer.write("" + getLabelIndex(l));
        }
        writer.write("])");
      } else if (ai instanceof TypeInsnNode) {
        TypeInsnNode n = ((TypeInsnNode)ai);
        writer.write("\n\t\t\t\t\\type(" + n.getOpcode() + ", \"" + escape(n.desc) + "\")");
      } else {
        if (!(ai instanceof FrameNode)) {
          throw new RuntimeException("Error: Unsupported instruction encountered (" + ai.getClass() + ").");
        }
        first = true;
View Full Code Here

Examples of org.objectweb.asm.tree.LabelNode

        // 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());
View Full Code Here

Examples of org.objectweb.asm.tree.LabelNode

          logger.info("skipping node");
          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();
        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));
View Full Code Here

Examples of org.objectweb.asm.tree.LabelNode

        boolean isStatic = (mn.access & ACC_STATIC) != 0;
        log("Instrumenting " + mn.name + " " + mn.desc + " "
                + (isStatic ? " static " : ""));
        Label fStartl = new Label();
        Label fEndl = new Label();
        LabelNode fStart = new LabelNode(fStartl);
        LabelNode fEnd = new LabelNode(fEndl);

        // Label vStartl = new Label();
        // Label vEndl = new Label();
        // LabelNode vStart = new LabelNode(vStartl);
        // LabelNode vEnd = new LabelNode(vEndl);

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

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

Examples of org.objectweb.asm.tree.LabelNode

        // 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) {
View Full Code Here

Examples of org.objectweb.asm.tree.LabelNode

        // 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) {
View Full Code Here

Examples of org.objectweb.asm.tree.LabelNode

                        LookupSwitchInsnNode lsi = (LookupSwitchInsnNode) insnNode;
                        int jump = insns.indexOf(lsi.dflt);
                        merge(jump, current, subroutine);
                        newControlFlowEdge(insn, jump);
                        for (int j = 0; j < lsi.labels.size(); ++j) {
                            LabelNode label = (LabelNode) lsi.labels.get(j);
                            jump = insns.indexOf(label);
                            merge(jump, current, subroutine);
                            newControlFlowEdge(insn, jump);
                        }
                    } else if (insnNode instanceof TableSwitchInsnNode) {
                        TableSwitchInsnNode tsi = (TableSwitchInsnNode) insnNode;
                        int jump = insns.indexOf(tsi.dflt);
                        merge(jump, current, subroutine);
                        newControlFlowEdge(insn, jump);
                        for (int j = 0; j < tsi.labels.size(); ++j) {
                            LabelNode label = (LabelNode) tsi.labels.get(j);
                            jump = insns.indexOf(label);
                            merge(jump, current, subroutine);
                            newControlFlowEdge(insn, jump);
                        }
                    } else if (insnOpcode == RET) {
View Full Code Here

Examples of org.objectweb.asm.tree.LabelNode

                }
            } else if (node instanceof TableSwitchInsnNode) {
                TableSwitchInsnNode tsnode = (TableSwitchInsnNode) node;
                findSubroutine(insns.indexOf(tsnode.dflt), sub, calls);
                for (int i = tsnode.labels.size() - 1; i >= 0; --i) {
                    LabelNode l = (LabelNode) tsnode.labels.get(i);
                    findSubroutine(insns.indexOf(l), sub, calls);
                }
            } else if (node instanceof LookupSwitchInsnNode) {
                LookupSwitchInsnNode lsnode = (LookupSwitchInsnNode) node;
                findSubroutine(insns.indexOf(lsnode.dflt), sub, calls);
                for (int i = lsnode.labels.size() - 1; i >= 0; --i) {
                    LabelNode l = (LabelNode) lsnode.labels.get(i);
                    findSubroutine(insns.indexOf(l), sub, calls);
                }
            }

            // calls findSubroutine recursively on exception handler successors
View Full Code Here

Examples of org.objectweb.asm.tree.LabelNode

        new LabelNode(), new LabelNode[0]));
  }

  @Test
  public void testLookupSwitchInsn() {
    testInstructionBetweenFrames(new LookupSwitchInsnNode(new LabelNode(),
        new int[0], new LabelNode[0]));
  }
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.