src/share/classes/jdk/internal/org/objectweb/asm/tree/FrameNode.java

Print this page




  57  * THE POSSIBILITY OF SUCH DAMAGE.
  58  */
  59 package jdk.internal.org.objectweb.asm.tree;
  60 
  61 import java.util.ArrayList;
  62 import java.util.Arrays;
  63 import java.util.List;
  64 import java.util.Map;
  65 
  66 import jdk.internal.org.objectweb.asm.MethodVisitor;
  67 import jdk.internal.org.objectweb.asm.Opcodes;
  68 
  69 /**
  70  * A node that represents a stack map frame. These nodes are pseudo instruction
  71  * nodes in order to be inserted in an instruction list. In fact these nodes
  72  * must(*) be inserted <i>just before</i> any instruction node <b>i</b> that
  73  * follows an unconditionnal branch instruction such as GOTO or THROW, that is
  74  * the target of a jump instruction, or that starts an exception handler block.
  75  * The stack map frame types must describe the values of the local variables and
  76  * of the operand stack elements <i>just before</i> <b>i</b> is executed. <br>
  77  * <br> (*) this is mandatory only for classes whose version is greater than or
  78  * equal to {@link Opcodes#V1_6 V1_6}.

  79  *
  80  * @author Eric Bruneton
  81  */
  82 public class FrameNode extends AbstractInsnNode {
  83 
  84     /**
  85      * The type of this frame. Must be {@link Opcodes#F_NEW} for expanded
  86      * frames, or {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND},
  87      * {@link Opcodes#F_CHOP}, {@link Opcodes#F_SAME} or
  88      * {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for compressed frames.
  89      */
  90     public int type;
  91 
  92     /**
  93      * The types of the local variables of this stack map frame. Elements of
  94      * this list can be Integer, String or LabelNode objects (for primitive,
  95      * reference and uninitialized types respectively - see
  96      * {@link MethodVisitor}).
  97      */
  98     public List<Object> local;
  99 
 100     /**
 101      * The types of the operand stack elements of this stack map frame. Elements
 102      * of this list can be Integer, String or LabelNode objects (for primitive,
 103      * reference and uninitialized types respectively - see
 104      * {@link MethodVisitor}).
 105      */
 106     public List<Object> stack;
 107 
 108     private FrameNode() {
 109         super(-1);
 110     }
 111 
 112     /**
 113      * Constructs a new {@link FrameNode}.
 114      *
 115      * @param type the type of this frame. Must be {@link Opcodes#F_NEW} for

 116      *        expanded frames, or {@link Opcodes#F_FULL},
 117      *        {@link Opcodes#F_APPEND}, {@link Opcodes#F_CHOP},
 118      *        {@link Opcodes#F_SAME} or {@link Opcodes#F_APPEND},
 119      *        {@link Opcodes#F_SAME1} for compressed frames.
 120      * @param nLocal number of local variables of this stack map frame.
 121      * @param local the types of the local variables of this stack map frame.
 122      *        Elements of this list can be Integer, String or LabelNode objects
 123      *        (for primitive, reference and uninitialized types respectively -
 124      *        see {@link MethodVisitor}).
 125      * @param nStack number of operand stack elements of this stack map frame.
 126      * @param stack the types of the operand stack elements of this stack map
 127      *        frame. Elements of this list can be Integer, String or LabelNode
 128      *        objects (for primitive, reference and uninitialized types
 129      *        respectively - see {@link MethodVisitor}).







 130      */
 131     public FrameNode(
 132         final int type,
 133         final int nLocal,
 134         final Object[] local,
 135         final int nStack,
 136         final Object[] stack)
 137     {
 138         super(-1);
 139         this.type = type;
 140         switch (type) {
 141             case Opcodes.F_NEW:
 142             case Opcodes.F_FULL:
 143                 this.local = asList(nLocal, local);
 144                 this.stack = asList(nStack, stack);
 145                 break;
 146             case Opcodes.F_APPEND:
 147                 this.local = asList(nLocal, local);
 148                 break;
 149             case Opcodes.F_CHOP:
 150                 this.local = Arrays.asList(new Object[nLocal]);
 151                 break;
 152             case Opcodes.F_SAME:
 153                 break;
 154             case Opcodes.F_SAME1:
 155                 this.stack = asList(1, stack);
 156                 break;
 157         }
 158     }
 159 
 160     @Override
 161     public int getType() {
 162         return FRAME;
 163     }
 164 
 165     /**
 166      * Makes the given visitor visit this stack map frame.
 167      *
 168      * @param mv a method visitor.

 169      */
 170     @Override
 171     public void accept(final MethodVisitor mv) {
 172         switch (type) {
 173             case Opcodes.F_NEW:
 174             case Opcodes.F_FULL:
 175                 mv.visitFrame(type,
 176                         local.size(),
 177                         asArray(local),
 178                         stack.size(),
 179                         asArray(stack));
 180                 break;
 181             case Opcodes.F_APPEND:
 182                 mv.visitFrame(type, local.size(), asArray(local), 0, null);
 183                 break;
 184             case Opcodes.F_CHOP:
 185                 mv.visitFrame(type, local.size(), null, 0, null);
 186                 break;
 187             case Opcodes.F_SAME:
 188                 mv.visitFrame(type, 0, null, 0, null);
 189                 break;
 190             case Opcodes.F_SAME1:
 191                 mv.visitFrame(type, 0, null, 1, asArray(stack));
 192                 break;
 193         }
 194     }
 195 
 196     @Override
 197     public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
 198         FrameNode clone = new FrameNode();




  57  * THE POSSIBILITY OF SUCH DAMAGE.
  58  */
  59 package jdk.internal.org.objectweb.asm.tree;
  60 
  61 import java.util.ArrayList;
  62 import java.util.Arrays;
  63 import java.util.List;
  64 import java.util.Map;
  65 
  66 import jdk.internal.org.objectweb.asm.MethodVisitor;
  67 import jdk.internal.org.objectweb.asm.Opcodes;
  68 
  69 /**
  70  * A node that represents a stack map frame. These nodes are pseudo instruction
  71  * nodes in order to be inserted in an instruction list. In fact these nodes
  72  * must(*) be inserted <i>just before</i> any instruction node <b>i</b> that
  73  * follows an unconditionnal branch instruction such as GOTO or THROW, that is
  74  * the target of a jump instruction, or that starts an exception handler block.
  75  * The stack map frame types must describe the values of the local variables and
  76  * of the operand stack elements <i>just before</i> <b>i</b> is executed. <br>
  77  * <br>
  78  * (*) this is mandatory only for classes whose version is greater than or equal
  79  * to {@link Opcodes#V1_6 V1_6}.
  80  *
  81  * @author Eric Bruneton
  82  */
  83 public class FrameNode extends AbstractInsnNode {
  84 
  85     /**
  86      * The type of this frame. Must be {@link Opcodes#F_NEW} for expanded
  87      * frames, or {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND},
  88      * {@link Opcodes#F_CHOP}, {@link Opcodes#F_SAME} or
  89      * {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for compressed frames.
  90      */
  91     public int type;
  92 
  93     /**
  94      * The types of the local variables of this stack map frame. Elements of
  95      * this list can be Integer, String or LabelNode objects (for primitive,
  96      * reference and uninitialized types respectively - see
  97      * {@link MethodVisitor}).
  98      */
  99     public List<Object> local;
 100 
 101     /**
 102      * The types of the operand stack elements of this stack map frame. Elements
 103      * of this list can be Integer, String or LabelNode objects (for primitive,
 104      * reference and uninitialized types respectively - see
 105      * {@link MethodVisitor}).
 106      */
 107     public List<Object> stack;
 108 
 109     private FrameNode() {
 110         super(-1);
 111     }
 112 
 113     /**
 114      * Constructs a new {@link FrameNode}.
 115      *
 116      * @param type
 117      *            the type of this frame. Must be {@link Opcodes#F_NEW} for
 118      *            expanded frames, or {@link Opcodes#F_FULL},
 119      *            {@link Opcodes#F_APPEND}, {@link Opcodes#F_CHOP},
 120      *            {@link Opcodes#F_SAME} or {@link Opcodes#F_APPEND},
 121      *            {@link Opcodes#F_SAME1} for compressed frames.
 122      * @param nLocal
 123      *            number of local variables of this stack map frame.
 124      * @param local
 125      *            the types of the local variables of this stack map frame.
 126      *            Elements of this list can be Integer, String or LabelNode



 127      *            objects (for primitive, reference and uninitialized types
 128      *            respectively - see {@link MethodVisitor}).
 129      * @param nStack
 130      *            number of operand stack elements of this stack map frame.
 131      * @param stack
 132      *            the types of the operand stack elements of this stack map
 133      *            frame. Elements of this list can be Integer, String or
 134      *            LabelNode objects (for primitive, reference and uninitialized
 135      *            types respectively - see {@link MethodVisitor}).
 136      */
 137     public FrameNode(final int type, final int nLocal, final Object[] local,
 138             final int nStack, final Object[] stack) {





 139         super(-1);
 140         this.type = type;
 141         switch (type) {
 142         case Opcodes.F_NEW:
 143         case Opcodes.F_FULL:
 144             this.local = asList(nLocal, local);
 145             this.stack = asList(nStack, stack);
 146             break;
 147         case Opcodes.F_APPEND:
 148             this.local = asList(nLocal, local);
 149             break;
 150         case Opcodes.F_CHOP:
 151             this.local = Arrays.asList(new Object[nLocal]);
 152             break;
 153         case Opcodes.F_SAME:
 154             break;
 155         case Opcodes.F_SAME1:
 156             this.stack = asList(1, stack);
 157             break;
 158         }
 159     }
 160 
 161     @Override
 162     public int getType() {
 163         return FRAME;
 164     }
 165 
 166     /**
 167      * Makes the given visitor visit this stack map frame.
 168      *
 169      * @param mv
 170      *            a method visitor.
 171      */
 172     @Override
 173     public void accept(final MethodVisitor mv) {
 174         switch (type) {
 175         case Opcodes.F_NEW:
 176         case Opcodes.F_FULL:
 177             mv.visitFrame(type, local.size(), asArray(local), stack.size(),



 178                     asArray(stack));
 179             break;
 180         case Opcodes.F_APPEND:
 181             mv.visitFrame(type, local.size(), asArray(local), 0, null);
 182             break;
 183         case Opcodes.F_CHOP:
 184             mv.visitFrame(type, local.size(), null, 0, null);
 185             break;
 186         case Opcodes.F_SAME:
 187             mv.visitFrame(type, 0, null, 0, null);
 188             break;
 189         case Opcodes.F_SAME1:
 190             mv.visitFrame(type, 0, null, 1, asArray(stack));
 191             break;
 192         }
 193     }
 194 
 195     @Override
 196     public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
 197         FrameNode clone = new FrameNode();