blob: 112f89ce4e64f8d28560ca43a8638b4fcfc5a590 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26/*
27 Java Class Version numbers history
28 1.0 to 1.3.X 45,3
29 1.4 to 1.4.X 46,0
30 1.5 to 1.5.X 49,0
31 1.6 to 1.5.x 50,0 NOTE Assumed for now
32*/
33
34// classfile constants
35#define JAVA_MAGIC 0xCAFEBABE
36#define JAVA_MIN_MAJOR_VERSION 45
37#define JAVA_MIN_MINOR_VERSION 3
38#define JAVA5_MAX_MAJOR_VERSION 49
39#define JAVA5_MAX_MINOR_VERSION 0
40// NOTE: Assume for now
41#define JAVA6_MAX_MAJOR_VERSION 50
42#define JAVA6_MAX_MINOR_VERSION 0
43
44// package file constants
45#define JAVA_PACKAGE_MAGIC 0xCAFED00D
46#define JAVA5_PACKAGE_MAJOR_VERSION 150
47#define JAVA5_PACKAGE_MINOR_VERSION 7
48
49#define JAVA6_PACKAGE_MAJOR_VERSION 160
50#define JAVA6_PACKAGE_MINOR_VERSION 1
51
52
53// magic number for gzip streams (for processing pack200-gzip data)
54#define GZIP_MAGIC 0x1F8B0800
55#define GZIP_MAGIC_MASK 0xFFFFFF00 // last byte is variable "flg" field
56
57enum {
58 CONSTANT_None,
59 CONSTANT_Utf8,
60 CONSTANT_unused2, /* unused, was Unicode */
61 CONSTANT_Integer,
62 CONSTANT_Float,
63 CONSTANT_Long,
64 CONSTANT_Double,
65 CONSTANT_Class,
66 CONSTANT_String,
67 CONSTANT_Fieldref,
68 CONSTANT_Methodref,
69 CONSTANT_InterfaceMethodref,
70 CONSTANT_NameandType,
71
72 CONSTANT_Signature = 13,
73 CONSTANT_All = 14,
74 CONSTANT_Limit = 15,
75 CONSTANT_NONE = 0,
76
77 CONSTANT_Literal = 20, //pseudo-tag for debugging
78 CONSTANT_Member = 21, //pseudo-tag for debugging
79
80 SUBINDEX_BIT = 64, // combined with CONSTANT_xxx for ixTag
81
82 ACC_STATIC = 0x0008,
83 ACC_IC_LONG_FORM = (1<<16), //for ic_flags
84
85 CLASS_ATTR_SourceFile = 17,
86 CLASS_ATTR_EnclosingMethod = 18,
87 CLASS_ATTR_InnerClasses = 23,
88 CLASS_ATTR_ClassFile_version = 24,
89 FIELD_ATTR_ConstantValue = 17,
90 METHOD_ATTR_Code = 17,
91 METHOD_ATTR_Exceptions = 18,
92 METHOD_ATTR_RuntimeVisibleParameterAnnotations = 23,
93 METHOD_ATTR_RuntimeInvisibleParameterAnnotations = 24,
94 METHOD_ATTR_AnnotationDefault = 25,
95 CODE_ATTR_StackMapTable = 0,
96 CODE_ATTR_LineNumberTable = 1,
97 CODE_ATTR_LocalVariableTable = 2,
98 CODE_ATTR_LocalVariableTypeTable = 3,
99 //X_ATTR_Synthetic = 12, // ACC_SYNTHETIC; not predefined
100 X_ATTR_Signature = 19,
101 X_ATTR_Deprecated = 20,
102 X_ATTR_RuntimeVisibleAnnotations = 21,
103 X_ATTR_RuntimeInvisibleAnnotations = 22,
104 X_ATTR_OVERFLOW = 16,
105 X_ATTR_LIMIT_NO_FLAGS_HI = 32,
106 X_ATTR_LIMIT_FLAGS_HI = 63,
107
108#define O_ATTR_DO(F) \
109 F(X_ATTR_OVERFLOW,01) \
110 /*(end)*/
111#define X_ATTR_DO(F) \
112 O_ATTR_DO(F) \
113 F(X_ATTR_Signature,Signature) \
114 F(X_ATTR_Deprecated,Deprecated) \
115 F(X_ATTR_RuntimeVisibleAnnotations,RuntimeVisibleAnnotations) \
116 F(X_ATTR_RuntimeInvisibleAnnotations,RuntimeInvisibleAnnotations) \
117 /*F(X_ATTR_Synthetic,Synthetic)*/ \
118 /*(end)*/
119#define CLASS_ATTR_DO(F) \
120 F(CLASS_ATTR_SourceFile,SourceFile) \
121 F(CLASS_ATTR_InnerClasses,InnerClasses) \
122 F(CLASS_ATTR_EnclosingMethod,EnclosingMethod) \
123 F(CLASS_ATTR_ClassFile_version,02) \
124 /*(end)*/
125#define FIELD_ATTR_DO(F) \
126 F(FIELD_ATTR_ConstantValue,ConstantValue) \
127 /*(end)*/
128#define METHOD_ATTR_DO(F) \
129 F(METHOD_ATTR_Code,Code) \
130 F(METHOD_ATTR_Exceptions,Exceptions) \
131 F(METHOD_ATTR_RuntimeVisibleParameterAnnotations,RuntimeVisibleParameterAnnotations) \
132 F(METHOD_ATTR_RuntimeInvisibleParameterAnnotations,RuntimeInvisibleParameterAnnotations) \
133 F(METHOD_ATTR_AnnotationDefault,AnnotationDefault) \
134 /*(end)*/
135#define CODE_ATTR_DO(F) \
136 F(CODE_ATTR_StackMapTable,StackMapTable) \
137 F(CODE_ATTR_LineNumberTable,LineNumberTable) \
138 F(CODE_ATTR_LocalVariableTable,LocalVariableTable) \
139 F(CODE_ATTR_LocalVariableTypeTable,LocalVariableTypeTable) \
140 /*(end)*/
141#define ALL_ATTR_DO(F) \
142 X_ATTR_DO(F) \
143 CLASS_ATTR_DO(F) \
144 FIELD_ATTR_DO(F) \
145 METHOD_ATTR_DO(F) \
146 CODE_ATTR_DO(F) \
147 /*(end)*/
148
149 // attribute "context types"
150 ATTR_CONTEXT_CLASS = 0,
151 ATTR_CONTEXT_FIELD = 1,
152 ATTR_CONTEXT_METHOD = 2,
153 ATTR_CONTEXT_CODE = 3,
154 ATTR_CONTEXT_LIMIT = 4,
155
156 // constants for parsed layouts (stored in band::le_kind)
157 EK_NONE = 0, // not a layout element
158 EK_INT = 'I', // B H I SH etc., also FH etc.
159 EK_BCI = 'P', // PH etc.
160 EK_BCID = 'Q', // POH etc.
161 EK_BCO = 'O', // OH etc.
162 EK_REPL = 'N', // NH[...] etc.
163 EK_REF = 'R', // RUH, RUNH, KQH, etc.
164 EK_UN = 'T', // TB(...)[...] etc.
165 EK_CASE = 'K', // (...)[...] etc.
166 EK_CALL = '(', // (0), (1), etc.
167 EK_CBLE = '[', // [...][...] etc.
168 NO_BAND_INDEX = -1,
169
170 // File option bits, from LSB in ascending bit position.
171 FO_DEFLATE_HINT = 1<<0,
172 FO_IS_CLASS_STUB = 1<<1,
173
174 // Archive option bits, from LSB in ascending bit position:
175 AO_HAVE_SPECIAL_FORMATS = 1<<0,
176 AO_HAVE_CP_NUMBERS = 1<<1,
177 AO_HAVE_ALL_CODE_FLAGS = 1<<2,
178 AO_3_UNUSED_MBZ = 1<<3,
179 AO_HAVE_FILE_HEADERS = 1<<4,
180 AO_DEFLATE_HINT = 1<<5,
181 AO_HAVE_FILE_MODTIME = 1<<6,
182 AO_HAVE_FILE_OPTIONS = 1<<7,
183 AO_HAVE_FILE_SIZE_HI = 1<<8,
184 AO_HAVE_CLASS_FLAGS_HI = 1<<9,
185 AO_HAVE_FIELD_FLAGS_HI = 1<<10,
186 AO_HAVE_METHOD_FLAGS_HI = 1<<11,
187 AO_HAVE_CODE_FLAGS_HI = 1<<12,
188#define ARCHIVE_BIT_DO(F) \
189 F(AO_HAVE_SPECIAL_FORMATS) \
190 F(AO_HAVE_CP_NUMBERS) \
191 F(AO_HAVE_ALL_CODE_FLAGS) \
192 /*F(AO_3_UNUSED_MBZ)*/ \
193 F(AO_HAVE_FILE_HEADERS) \
194 F(AO_DEFLATE_HINT) \
195 F(AO_HAVE_FILE_MODTIME) \
196 F(AO_HAVE_FILE_OPTIONS) \
197 F(AO_HAVE_FILE_SIZE_HI) \
198 F(AO_HAVE_CLASS_FLAGS_HI) \
199 F(AO_HAVE_FIELD_FLAGS_HI) \
200 F(AO_HAVE_METHOD_FLAGS_HI) \
201 F(AO_HAVE_CODE_FLAGS_HI) \
202 /*(end)*/
203
204 // Constants for decoding attribute definition header bytes.
205 ADH_CONTEXT_MASK = 0x3, // (hdr & ADH_CONTEXT_MASK)
206 ADH_BIT_SHIFT = 0x2, // (hdr >> ADH_BIT_SHIFT)
207 ADH_BIT_IS_LSB = 1, // (hdr >> ADH_BIT_SHIFT) - ADH_BIT_IS_LSB
208#define ADH_BYTE(context, index) \
209 ((((index) + ADH_BIT_IS_LSB)<<ADH_BIT_SHIFT) + (context))
210#define ADH_BYTE_CONTEXT(adhb) \
211 ((adhb) & ADH_CONTEXT_MASK)
212#define ADH_BYTE_INDEX(adhb) \
213 (((adhb) >> ADH_BIT_SHIFT) - ADH_BIT_IS_LSB)
214
215 NO_MODTIME = 0, // null modtime value
216
217 // meta-coding
218 _meta_default = 0,
219 _meta_canon_min = 1,
220 _meta_canon_max = 115,
221 _meta_arb = 116,
222 _meta_run = 117,
223 _meta_pop = 141,
224 _meta_limit = 189,
225 _meta_error = 255,
226
227 _xxx_1_end
228};
229
230// Bytecodes.
231
232enum {
233 bc_nop = 0, // 0x00
234 bc_aconst_null = 1, // 0x01
235 bc_iconst_m1 = 2, // 0x02
236 bc_iconst_0 = 3, // 0x03
237 bc_iconst_1 = 4, // 0x04
238 bc_iconst_2 = 5, // 0x05
239 bc_iconst_3 = 6, // 0x06
240 bc_iconst_4 = 7, // 0x07
241 bc_iconst_5 = 8, // 0x08
242 bc_lconst_0 = 9, // 0x09
243 bc_lconst_1 = 10, // 0x0a
244 bc_fconst_0 = 11, // 0x0b
245 bc_fconst_1 = 12, // 0x0c
246 bc_fconst_2 = 13, // 0x0d
247 bc_dconst_0 = 14, // 0x0e
248 bc_dconst_1 = 15, // 0x0f
249 bc_bipush = 16, // 0x10
250 bc_sipush = 17, // 0x11
251 bc_ldc = 18, // 0x12
252 bc_ldc_w = 19, // 0x13
253 bc_ldc2_w = 20, // 0x14
254 bc_iload = 21, // 0x15
255 bc_lload = 22, // 0x16
256 bc_fload = 23, // 0x17
257 bc_dload = 24, // 0x18
258 bc_aload = 25, // 0x19
259 bc_iload_0 = 26, // 0x1a
260 bc_iload_1 = 27, // 0x1b
261 bc_iload_2 = 28, // 0x1c
262 bc_iload_3 = 29, // 0x1d
263 bc_lload_0 = 30, // 0x1e
264 bc_lload_1 = 31, // 0x1f
265 bc_lload_2 = 32, // 0x20
266 bc_lload_3 = 33, // 0x21
267 bc_fload_0 = 34, // 0x22
268 bc_fload_1 = 35, // 0x23
269 bc_fload_2 = 36, // 0x24
270 bc_fload_3 = 37, // 0x25
271 bc_dload_0 = 38, // 0x26
272 bc_dload_1 = 39, // 0x27
273 bc_dload_2 = 40, // 0x28
274 bc_dload_3 = 41, // 0x29
275 bc_aload_0 = 42, // 0x2a
276 bc_aload_1 = 43, // 0x2b
277 bc_aload_2 = 44, // 0x2c
278 bc_aload_3 = 45, // 0x2d
279 bc_iaload = 46, // 0x2e
280 bc_laload = 47, // 0x2f
281 bc_faload = 48, // 0x30
282 bc_daload = 49, // 0x31
283 bc_aaload = 50, // 0x32
284 bc_baload = 51, // 0x33
285 bc_caload = 52, // 0x34
286 bc_saload = 53, // 0x35
287 bc_istore = 54, // 0x36
288 bc_lstore = 55, // 0x37
289 bc_fstore = 56, // 0x38
290 bc_dstore = 57, // 0x39
291 bc_astore = 58, // 0x3a
292 bc_istore_0 = 59, // 0x3b
293 bc_istore_1 = 60, // 0x3c
294 bc_istore_2 = 61, // 0x3d
295 bc_istore_3 = 62, // 0x3e
296 bc_lstore_0 = 63, // 0x3f
297 bc_lstore_1 = 64, // 0x40
298 bc_lstore_2 = 65, // 0x41
299 bc_lstore_3 = 66, // 0x42
300 bc_fstore_0 = 67, // 0x43
301 bc_fstore_1 = 68, // 0x44
302 bc_fstore_2 = 69, // 0x45
303 bc_fstore_3 = 70, // 0x46
304 bc_dstore_0 = 71, // 0x47
305 bc_dstore_1 = 72, // 0x48
306 bc_dstore_2 = 73, // 0x49
307 bc_dstore_3 = 74, // 0x4a
308 bc_astore_0 = 75, // 0x4b
309 bc_astore_1 = 76, // 0x4c
310 bc_astore_2 = 77, // 0x4d
311 bc_astore_3 = 78, // 0x4e
312 bc_iastore = 79, // 0x4f
313 bc_lastore = 80, // 0x50
314 bc_fastore = 81, // 0x51
315 bc_dastore = 82, // 0x52
316 bc_aastore = 83, // 0x53
317 bc_bastore = 84, // 0x54
318 bc_castore = 85, // 0x55
319 bc_sastore = 86, // 0x56
320 bc_pop = 87, // 0x57
321 bc_pop2 = 88, // 0x58
322 bc_dup = 89, // 0x59
323 bc_dup_x1 = 90, // 0x5a
324 bc_dup_x2 = 91, // 0x5b
325 bc_dup2 = 92, // 0x5c
326 bc_dup2_x1 = 93, // 0x5d
327 bc_dup2_x2 = 94, // 0x5e
328 bc_swap = 95, // 0x5f
329 bc_iadd = 96, // 0x60
330 bc_ladd = 97, // 0x61
331 bc_fadd = 98, // 0x62
332 bc_dadd = 99, // 0x63
333 bc_isub = 100, // 0x64
334 bc_lsub = 101, // 0x65
335 bc_fsub = 102, // 0x66
336 bc_dsub = 103, // 0x67
337 bc_imul = 104, // 0x68
338 bc_lmul = 105, // 0x69
339 bc_fmul = 106, // 0x6a
340 bc_dmul = 107, // 0x6b
341 bc_idiv = 108, // 0x6c
342 bc_ldiv = 109, // 0x6d
343 bc_fdiv = 110, // 0x6e
344 bc_ddiv = 111, // 0x6f
345 bc_irem = 112, // 0x70
346 bc_lrem = 113, // 0x71
347 bc_frem = 114, // 0x72
348 bc_drem = 115, // 0x73
349 bc_ineg = 116, // 0x74
350 bc_lneg = 117, // 0x75
351 bc_fneg = 118, // 0x76
352 bc_dneg = 119, // 0x77
353 bc_ishl = 120, // 0x78
354 bc_lshl = 121, // 0x79
355 bc_ishr = 122, // 0x7a
356 bc_lshr = 123, // 0x7b
357 bc_iushr = 124, // 0x7c
358 bc_lushr = 125, // 0x7d
359 bc_iand = 126, // 0x7e
360 bc_land = 127, // 0x7f
361 bc_ior = 128, // 0x80
362 bc_lor = 129, // 0x81
363 bc_ixor = 130, // 0x82
364 bc_lxor = 131, // 0x83
365 bc_iinc = 132, // 0x84
366 bc_i2l = 133, // 0x85
367 bc_i2f = 134, // 0x86
368 bc_i2d = 135, // 0x87
369 bc_l2i = 136, // 0x88
370 bc_l2f = 137, // 0x89
371 bc_l2d = 138, // 0x8a
372 bc_f2i = 139, // 0x8b
373 bc_f2l = 140, // 0x8c
374 bc_f2d = 141, // 0x8d
375 bc_d2i = 142, // 0x8e
376 bc_d2l = 143, // 0x8f
377 bc_d2f = 144, // 0x90
378 bc_i2b = 145, // 0x91
379 bc_i2c = 146, // 0x92
380 bc_i2s = 147, // 0x93
381 bc_lcmp = 148, // 0x94
382 bc_fcmpl = 149, // 0x95
383 bc_fcmpg = 150, // 0x96
384 bc_dcmpl = 151, // 0x97
385 bc_dcmpg = 152, // 0x98
386 bc_ifeq = 153, // 0x99
387 bc_ifne = 154, // 0x9a
388 bc_iflt = 155, // 0x9b
389 bc_ifge = 156, // 0x9c
390 bc_ifgt = 157, // 0x9d
391 bc_ifle = 158, // 0x9e
392 bc_if_icmpeq = 159, // 0x9f
393 bc_if_icmpne = 160, // 0xa0
394 bc_if_icmplt = 161, // 0xa1
395 bc_if_icmpge = 162, // 0xa2
396 bc_if_icmpgt = 163, // 0xa3
397 bc_if_icmple = 164, // 0xa4
398 bc_if_acmpeq = 165, // 0xa5
399 bc_if_acmpne = 166, // 0xa6
400 bc_goto = 167, // 0xa7
401 bc_jsr = 168, // 0xa8
402 bc_ret = 169, // 0xa9
403 bc_tableswitch = 170, // 0xaa
404 bc_lookupswitch = 171, // 0xab
405 bc_ireturn = 172, // 0xac
406 bc_lreturn = 173, // 0xad
407 bc_freturn = 174, // 0xae
408 bc_dreturn = 175, // 0xaf
409 bc_areturn = 176, // 0xb0
410 bc_return = 177, // 0xb1
411 bc_getstatic = 178, // 0xb2
412 bc_putstatic = 179, // 0xb3
413 bc_getfield = 180, // 0xb4
414 bc_putfield = 181, // 0xb5
415 bc_invokevirtual = 182, // 0xb6
416 bc_invokespecial = 183, // 0xb7
417 bc_invokestatic = 184, // 0xb8
418 bc_invokeinterface = 185, // 0xb9
419 bc_xxxunusedxxx = 186, // 0xba
420 bc_new = 187, // 0xbb
421 bc_newarray = 188, // 0xbc
422 bc_anewarray = 189, // 0xbd
423 bc_arraylength = 190, // 0xbe
424 bc_athrow = 191, // 0xbf
425 bc_checkcast = 192, // 0xc0
426 bc_instanceof = 193, // 0xc1
427 bc_monitorenter = 194, // 0xc2
428 bc_monitorexit = 195, // 0xc3
429 bc_wide = 196, // 0xc4
430 bc_multianewarray = 197, // 0xc5
431 bc_ifnull = 198, // 0xc6
432 bc_ifnonnull = 199, // 0xc7
433 bc_goto_w = 200, // 0xc8
434 bc_jsr_w = 201, // 0xc9
435 bc_bytecode_limit = 202 // 0xca
436};
437
438enum {
439 bc_end_marker = 255,
440 bc_byte_escape = 254,
441 bc_ref_escape = 253,
442
443 _first_linker_op = bc_getstatic,
444 _last_linker_op = bc_invokestatic,
445 _num_linker_ops = (_last_linker_op - _first_linker_op) + 1,
446 _self_linker_op = bc_bytecode_limit,
447 _self_linker_aload_flag = 1*_num_linker_ops,
448 _self_linker_super_flag = 2*_num_linker_ops,
449 _self_linker_limit = _self_linker_op + 4*_num_linker_ops,
450
451 _invokeinit_op = _self_linker_limit,
452 _invokeinit_self_option = 0,
453 _invokeinit_super_option = 1,
454 _invokeinit_new_option = 2,
455 _invokeinit_limit = _invokeinit_op+3,
456
457 _xldc_op = _invokeinit_limit,
458 bc_aldc = bc_ldc,
459 bc_cldc = _xldc_op+0,
460 bc_ildc = _xldc_op+1,
461 bc_fldc = _xldc_op+2,
462 bc_aldc_w = bc_ldc_w,
463 bc_cldc_w = _xldc_op+3,
464 bc_ildc_w = _xldc_op+4,
465 bc_fldc_w = _xldc_op+5,
466 bc_lldc2_w = bc_ldc2_w,
467 bc_dldc2_w = _xldc_op+6,
468 _xldc_limit = _xldc_op+7,
469
470 _xxx_3_end
471};