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