aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/bytecode/StackMapTable.java
blob: 6318104f44020c8b49b463eb7bcf001aed56bad0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
 * Javassist, a Java-bytecode translator toolkit.
 * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License.  Alternatively, the contents of this file may be used under
 * the terms of the GNU Lesser General Public License Version 2.1 or later.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 */

package javassist.bytecode;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Map;

/**
 * <code>stack_map</code> attribute.
 *
 * <p>This is an entry in the attributes table of a Code attribute.
 * It was introduced by J2SE 6 for the process of verification by
 * typechecking.
 */
public class StackMapTable extends AttributeInfo {
    /**
     * The name of this attribute <code>"StackMapTable"</code>.
     */
    public static final String tag = "StackMapTable";

    private StackMapFrame[] entries;    // may be null

    /**
     * Constructs a <code>stack_map</code> attribute.
     */
    public StackMapTable(ConstPool cp) {
        this(cp, (byte[])null);
    }

    private StackMapTable(ConstPool cp, byte[] newInfo) {
        super(cp, tag, newInfo);
        entries = null;
    }

    StackMapTable(ConstPool cp, int name_id, DataInputStream in)
        throws IOException
    {
        super(cp, name_id, in);
        entries = null;
    }

    /**
     * Makes a copy.
     */
    public AttributeInfo copy(ConstPool newCp, Map classnames) {
        toByteArray(false);
        int s = info.length;
        byte[] newInfo = new byte[s];
        System.arraycopy(info, 0, newInfo, 0, s);
        return new StackMapTable(newCp, newInfo);
    }

    void write(DataOutputStream out) throws IOException {
        toByteArray(true);
        super.write(out);
    }

    private void parseMap() {
        byte[] data = info;
        int n = ByteArray.readU16bit(data, 0);
        entries = new StackMapFrame[n];
    }

    private void toByteArray(boolean clear) {
        if (entries != null)
            ; // unparse 
    }

    /**
     * <code>union stack_map_frame</code>
     */
    public static class StackMapFrame {} 

    /*
     * verification_type_info is represented by a pair of
     * 2 int variables (tag and cpool_index/offset). 
     */

    /**
     * <code>Top_variable_info.tag</code>.
     */
    public static final int TOP = 0;

    /**
     * <code>Float_variable_info.tag</code>.
     */
    public static final int INTEGER = 1;

    /**
     * <code>Integer_variable_info.tag</code>.
     */
    public static final int FLOAT = 2;

    /**
     * <code>Double_variable_info.tag</code>.
     */
    public static final int DOUBLE = 3;

    /**
     * <code>Long_variable_info.tag</code>.
     */
    public static final int LONG = 4;

    /**
     * <code>Null_variable_info.tag</code>.
     */
    public static final int NULL = 5;

    /**
     * <code>UninitializedThis_variable_info.tag</code>.
     */
    public static final int THIS = 6;

    /**
     * <code>Object_variable_info.tag</code>.
     */
    public static final int OBJECT = 7;

    /**
     * <code>Uninitialized_variable_info.tag</code>.
     */
    public static final int UNINIT = 8;

    /**
     * <code>same_frame</code>.
     * The frame has exactly the same locals as the previous
     * stack map frame.
     */
    public static class SameFrame extends StackMapFrame {
        /**
         * The maximum value of <code>SAME</code>.
         */
        public static final int FRAME_TYPE_MAX = 63;

        /**
         * <code>u1 frame_type</code>.
         */
        public int frameType;
    }

    /**
     * <code>same_locals_1_stack_item_frame</code> or 
     * <code>same_locals_1_stack_item_frame_extended</code>. 
     */
    public static class SameLocals extends StackMapFrame {
        /**
         * The minimum value of <code>SAME_LOCALS_1_STACK_ITEM</code>.
         */
        public static final int FRAME_TYPE = 64;

        /**
         * The maximum value of <code>SAME_LOCALS_1_STACK_ITEM</code>.
         */
        public static final int FRAME_TYPE_MAX = 127;

        /**
         * <code>SAME_LOCALS_1_STACK_ITEM_EXTENDED</code>.
         */
        public static final int FRAME_TYPE_EXTENDED = 247;

        /*
         * <code>frame_type</code> is computed by offsetDelta.
         */

        /**
         * <code>u2 offset_delta</code>.
         */
        public int offsetDelta;

        /**
         * <code>stack[0].tag</code>.
         */
        public int typeTag;

        /**
         * <code>stack[0].cpool_index</code> or <code>stack[0].offset</code>.
         */
        public int typeValue;
    }

    /**
     * <code>chop_frame</code>.
     */
    public static class ChopFrame extends StackMapFrame {
        /**
         * The minimum value of <code>CHOP</code>.
         */
        public static final int FRAME_TYPE = 248;

        /**
         * The maximum value of <code>CHOP</code>.
         */
        public static final int FRAME_TYPE_MAX = 250;

        /**
         * <code>u1 frame_type</code>.
         */
        public int frameType;

        /**
         * <code>u2 offset_delta</code>.
         */
        public int offsetDelta;
    }

    /**
     * <code>same_frame_extended</code>.
     */
    public static class SameFrameExtended extends StackMapFrame {
        /**
         * <code>SAME_FRAME_EXTENDED</code>.
         */
        public static final int FRAME_TYPE = 251;

        /**
         * <code>u2 offset_delta</code>.
         */
        public int offsetDelta;
    }

    /**
     * <code>append_frame</code>.
     */
    public static class AppendFrame extends StackMapFrame {
        /**
         * The minimum value of <code>APPEND</code>.
         */
        public static final int FRAME_TYPE = 252;

        /**
         * The maximum value of <code>APPEND</code>.
         */
        public static final int FRAME_TYPE_MAX = 254;

        /**
         * <code>u1 frame_type</code>.
         */
        public int frameType;

        /**
         * <code>u2 offset_delta</code>.
         */
        public int offsetDelta;

        /**
         * <code>locals[?].tag</code>.
         */
        public int[] typeTags;

        /**
         * <code>locals[?].cpool_index</code> or <code>locals[?].offset</code>.
         */
        public int[] typeValues;
    }

    /**
     * <code>ful_frame</code>.
     */
    public static class FullFrame extends StackMapFrame {
        /**
         * <code>FULL_FRAME</code>.
         */
        public static final int FRAME_TYPE = 255;

        /**
         * <code>u2 offset_delta</code>.
         */
        public int offsetDelta;

        /**
         * <code>u2 number_of_locals</code>.
         */
        public int numOfLocals;

        /**
         * <code>locals[?].tag</code>.
         */
        public int[] typeTags;

        /**
         * <code>locals[?].cpool_index</code> or <code>locals[?].offset</code>.
         */
        public int[] typeValues;

        /**
         * <code>u2 number_of_stack_items</code>.
         */
        public int numOfStackItems;

        /**
         * <code>stack[?].tag</code>.
         */
        public int[] stackTypeTags;

        /**
         * <code>stack[?].cpool_index</code> or <code>locals[?].offset</code>.
         */
        public int[] stackTypeValues;
    }
}