Package org.objectweb.asm.tree

Examples of org.objectweb.asm.tree.AbstractInsnNode


     *            part of this subroutine or any previously computed subroutine.
     */
    private void markSubroutineWalkDFS(final BitSet sub, int index,
            final BitSet anyvisited) {
        while (true) {
            AbstractInsnNode node = instructions.get(index);

            // don't visit a node twice
            if (sub.get(index)) {
                return;
            }
            sub.set(index);

            // check for those nodes already visited by another subroutine
            if (anyvisited.get(index)) {
                dualCitizens.set(index);
                if (LOGGING) {
                    log("Instruction #" + index + " is dual citizen.");
                }
            }
            anyvisited.set(index);

            if (node.getType() == AbstractInsnNode.JUMP_INSN
                    && node.getOpcode() != JSR) {
                // we do not follow recursively called subroutines here; but any
                // other sort of branch we do follow
                JumpInsnNode jnode = (JumpInsnNode) node;
                int destidx = instructions.indexOf(jnode.label);
                markSubroutineWalkDFS(sub, destidx, anyvisited);
            }
            if (node.getType() == AbstractInsnNode.TABLESWITCH_INSN) {
                TableSwitchInsnNode tsnode = (TableSwitchInsnNode) node;
                int destidx = instructions.indexOf(tsnode.dflt);
                markSubroutineWalkDFS(sub, destidx, anyvisited);
                for (int i = tsnode.labels.size() - 1; i >= 0; --i) {
                    LabelNode l = tsnode.labels.get(i);
                    destidx = instructions.indexOf(l);
                    markSubroutineWalkDFS(sub, destidx, anyvisited);
                }
            }
            if (node.getType() == AbstractInsnNode.LOOKUPSWITCH_INSN) {
                LookupSwitchInsnNode lsnode = (LookupSwitchInsnNode) node;
                int destidx = instructions.indexOf(lsnode.dflt);
                markSubroutineWalkDFS(sub, destidx, anyvisited);
                for (int i = lsnode.labels.size() - 1; i >= 0; --i) {
                    LabelNode l = lsnode.labels.get(i);
View Full Code Here


        }

        // Emit the relevant instructions for this instantiation, translating
        // labels and jump targets as we go:
        for (int i = 0, c = instructions.size(); i < c; i++) {
            AbstractInsnNode insn = instructions.get(i);
            Instantiation owner = instant.findOwner(i);

            // Always remap labels:
            if (insn.getType() == AbstractInsnNode.LABEL) {
                // Translate labels into their renamed equivalents.
                // Avoid adding the same label more than once. Note
                // that because we own this instruction the gotoTable
                // and the rangeTable will always agree.
                LabelNode ilbl = (LabelNode) insn;
                LabelNode remap = instant.rangeLabel(ilbl);
                if (LOGGING) {
                    // TODO use of default toString().
                    log("Translating lbl #" + i + ':' + ilbl + " to " + remap);
                }
                if (remap != duplbl) {
                    newInstructions.add(remap);
                    duplbl = remap;
                }
                continue;
            }

            // We don't want to emit instructions that were already
            // emitted by a subroutine higher on the stack. Note that
            // it is still possible for a given instruction to be
            // emitted twice because it may belong to two subroutines
            // that do not invoke each other.
            if (owner != instant) {
                continue;
            }

            if (LOGGING) {
                log("Emitting inst #" + i);
            }

            if (insn.getOpcode() == RET) {
                // Translate RET instruction(s) to a jump to the return label
                // for the appropriate instantiation. The problem is that the
                // subroutine may "fall through" to the ret of a parent
                // subroutine; therefore, to find the appropriate ret label we
                // find the lowest subroutine on the stack that claims to own
                // this instruction. See the class javadoc comment for an
                // explanation on why this technique is safe (note: it is only
                // safe if the input is verifiable).
                LabelNode retlabel = null;
                for (Instantiation p = instant; p != null; p = p.previous) {
                    if (p.subroutine.get(i)) {
                        retlabel = p.returnLabel;
                    }
                }
                if (retlabel == null) {
                    // This is only possible if the mainSubroutine owns a RET
                    // instruction, which should never happen for verifiable
                    // code.
                    throw new RuntimeException("Instruction #" + i
                            + " is a RET not owned by any subroutine");
                }
                newInstructions.add(new JumpInsnNode(GOTO, retlabel));
            } else if (insn.getOpcode() == JSR) {
                LabelNode lbl = ((JumpInsnNode) insn).label;
                BitSet sub = subroutineHeads.get(lbl);
                Instantiation newinst = new Instantiation(instant, sub);
                LabelNode startlbl = newinst.gotoLabel(lbl);

                if (LOGGING) {
                    log(" Creating instantiation of subr " + sub);
                }

                // Rather than JSRing, we will jump to the inline version and
                // push NULL for what was once the return value. This hack
                // allows us to avoid doing any sort of data flow analysis to
                // figure out which instructions manipulate the old return value
                // pointer which is now known to be unneeded.
                newInstructions.add(new InsnNode(ACONST_NULL));
                newInstructions.add(new JumpInsnNode(GOTO, startlbl));
                newInstructions.add(newinst.returnLabel);

                // Insert this new instantiation into the queue to be emitted
                // later.
                worklist.add(newinst);
            } else {
                newInstructions.add(insn.clone(instant));
            }
        }

        // Emit try/catch blocks that are relevant to this method.
        for (Iterator<TryCatchBlockNode> it = tryCatchBlocks.iterator(); it
View Full Code Here

            // this is fairly common as we are often ignoring large chunks of
            // instructions, so what were previously distinct labels become
            // duplicates.
            LabelNode duplbl = null;
            for (int i = 0, c = instructions.size(); i < c; i++) {
                AbstractInsnNode insn = instructions.get(i);

                if (insn.getType() == AbstractInsnNode.LABEL) {
                    LabelNode ilbl = (LabelNode) insn;

                    if (duplbl == null) {
                        // if we already have a label pointing at this spot,
                        // don't recreate it.
View Full Code Here

    else
      labelNames.clear();

    buildingLabelMap = true;
    {
      AbstractInsnNode insn = subsection.first;
      while (true)
      {
        if (insn.getType() == 8)
          visitLabel(((LabelNode) insn).getLabel());
        if (insn == subsection.last)
          break;
        insn = insn.getNext();
      }
    }

    text.clear();
    buildingLabelMap = false;

    {
      AbstractInsnNode insn = subsection.first;
      while (true)
      {
        _visitInsn(insn);
        if (insn == subsection.last)
          break;
        insn = insn.getNext();
      }
    }
  }
View Full Code Here

    replacement.accept(original);
  }

  public static void removeBlock(InsnList insns, InsnListSection block)
  {
    AbstractInsnNode insn = block.first;
    while (true)
    {
      AbstractInsnNode next = insn.getNext();
      insns.remove(insn);
      if (insn == block.last)
        break;
      insn = next;
    }
View Full Code Here

  private static InsnListSection insnListMatchesL(InsnList haystack, InsnList needle, int start, HashSet<LabelNode> controlFlowLabels)
  {
    int h = start, n = 0;
    for (; h < haystack.size() && n < needle.size(); h++)
    {
      AbstractInsnNode insn = haystack.get(h);
      if (insn.getType() == 15)
        continue;
      if (insn.getType() == 8 && !controlFlowLabels.contains(insn))
        continue;

      if (!insnEqual(haystack.get(h), needle.get(n)))
        return null;
      n++;
View Full Code Here

            toNull.and(unsafeIn);
            if (!nullThis && isInstanceMethod) {
                toNull.clear(0);
            }
           
            AbstractInsnNode next = insn.getNext();
            if (toNull.cardinality() > 0) {
                // Construct the nulling instructions.
                InsnList nullingInsns = new InsnList();
                for (int i = 0; i < toNull.length(); i++) {
                    if (toNull.get(i)) {
                        AbstractInsnNode pushNull = new InsnNode(Opcodes.ACONST_NULL);
                        AbstractInsnNode store = new VarInsnNode(Opcodes.ASTORE, i);
                        nullingInsns.add(pushNull);
                        nullingInsns.add(store);
                    }
                }
               
View Full Code Here

                    // Tell the node which index it has.
                    if (nodes[i] != null) nodes[i].setIndex(i);
                }
               
                // Initialize the 'def', 'use', and 'alloc' sets for each node.
                AbstractInsnNode insn = instructions.getFirst();
                for (int i = 0; i < nodes.length; i++) {
                    if (nodes[i] != null) nodes[i].initInfoSets(insn);
                   
                    insn = insn.getNext();
                }
                assert insn == null;
               
                // Iterate liveness analysis until sets are unchanged.
                // To reduce the number of iterations, we use depth-first
                // search to reverse topologically sort the nodes.
                Node[] updateOrder = getReversePseudoTopologicalOrder(nodes);
                dirty = true;
                while (dirty) {
                    dirty = false;
                    for (int i = 0; i < updateOrder.length; i++) {
                        updateOrder[i].updateLiveness();
                    }
                }

                // Replace dead non-nulling assignments with pops.
                // Note that this does not affect liveness information.
                insn = instructions.getFirst();
                for (int i = 0; i < nodes.length; i++) {
                    AbstractInsnNode next = insn.getNext();
                    if (nodes[i] != null) nodes[i].removeDeadAssignments(instructions, insn);
                    insn = next;
                }
                assert insn == null;
               
View Full Code Here

  
   // Returns false on encountering something that can't be analyzed properly
   static boolean breakIntoPaths(List<CodePath> paths, List<PathInstruction> previousInstructions, int index, CFG cfg, MethodNode m)
   {
      // Get the next instruction and check if we can handle it
      AbstractInsnNode instruction = m.instructions.get(index);
     
      // TODO: various control-flow instructions that we don't currently handle
      if (instruction instanceof LookupSwitchInsnNode) return false;
      if (instruction instanceof TableSwitchInsnNode) return false;
      if (instruction.getOpcode() == Opcodes.JSR) return false;
      if (instruction.getOpcode() == Opcodes.RET) return false;
     
      // Handle conditional branches specially
      if (instruction instanceof JumpInsnNode && instruction.getOpcode() != Opcodes.GOTO)
      {
         int nextIndex = index+1;
         int branchIndex = index+1;
         for (int next: cfg.succsOf(index))
            if (next != nextIndex)
View Full Code Here

    public void replaceLabels(Map<LabelNode, LabelNode> labelMap, Set<LabelNode> usedLabels) {
        for (AbstractInsnNode insn : list)
            switch (insn.getType()) {
                case LABEL:
                    AbstractInsnNode insn2 = insn.clone(labelMap);
                    if (insn2 == insn)//identity mapping
                        continue;
                    if (usedLabels.contains(insn2))
                        throw new IllegalStateException("LabelNode cannot be a part of two InsnLists");
                    list.replace(insn, insn2);
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.