-
Notifications
You must be signed in to change notification settings - Fork 200
/
java_class.ksy
494 lines (492 loc) · 15.7 KB
/
java_class.ksy
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
meta:
id: java_class
file-extension: class
xref:
justsolve: Java
pronom: x-fmt/415
wikidata: Q2193155
license: CC0-1.0
endian: be
doc-ref:
- https://docs.oracle.com/javase/specs/jvms/se19/html/jvms-4.html
- https://docs.oracle.com/javase/specs/jls/se6/jls3.pdf
- https://github.com/openjdk/jdk/blob/jdk-21%2B14/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/ClassConstants.java
- https://github.com/openjdk/jdk/blob/jdk-21%2B14/src/java.base/share/native/include/classfile_constants.h.template
- https://github.com/openjdk/jdk/blob/jdk-21%2B14/src/hotspot/share/classfile/classFileParser.cpp
seq:
- id: magic
contents: [0xca, 0xfe, 0xba, 0xbe]
- id: version_minor
type: u2
- id: version_major
type: u2
valid:
# https://github.com/file/file/blob/905ca555/magic/Magdir/cafebabe#L11-L12
min: 43
- id: constant_pool_count
type: u2
- id: constant_pool
type: 'constant_pool_entry(_index != 0 ? constant_pool[_index - 1].is_two_entries : false)'
repeat: expr
repeat-expr: constant_pool_count - 1
- id: access_flags
type: u2
- id: this_class
type: u2
- id: super_class
type: u2
- id: interfaces_count
type: u2
- id: interfaces
type: u2
repeat: expr
repeat-expr: interfaces_count
- id: fields_count
type: u2
- id: fields
type: field_info
repeat: expr
repeat-expr: fields_count
- id: methods_count
type: u2
- id: methods
type: method_info
repeat: expr
repeat-expr: methods_count
- id: attributes_count
type: u2
- id: attributes
type: attribute_info
repeat: expr
repeat-expr: attributes_count
types:
constant_pool_entry:
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4
params:
- id: is_prev_two_entries
type: bool
seq:
- id: tag
type: u1
enum: tag_enum
if: not is_prev_two_entries
- id: cp_info
type:
switch-on: tag
cases:
tag_enum::class_type: class_cp_info
tag_enum::field_ref: field_ref_cp_info
tag_enum::method_ref: method_ref_cp_info
tag_enum::interface_method_ref: interface_method_ref_cp_info
tag_enum::string: string_cp_info
tag_enum::integer: integer_cp_info
tag_enum::float: float_cp_info
tag_enum::long: long_cp_info
tag_enum::double: double_cp_info
tag_enum::name_and_type: name_and_type_cp_info
tag_enum::utf8: utf8_cp_info
tag_enum::method_handle: method_handle_cp_info
tag_enum::method_type: method_type_cp_info
tag_enum::invoke_dynamic: invoke_dynamic_cp_info
tag_enum::dynamic: dynamic_cp_info
tag_enum::module: module_package_cp_info
tag_enum::package: module_package_cp_info
if: not is_prev_two_entries
instances:
is_two_entries:
value: 'is_prev_two_entries ? false : tag == tag_enum::long or tag == tag_enum::double'
enums:
tag_enum:
1:
id: utf8
-orig-id: CONSTANT_Utf8
3:
id: integer
-orig-id: CONSTANT_Integer
4:
id: float
-orig-id: CONSTANT_Float
5:
id: long
-orig-id: CONSTANT_Long
6:
id: double
-orig-id: CONSTANT_Double
7:
id: class_type
-orig-id: CONSTANT_Class
8:
id: string
-orig-id: CONSTANT_String
9:
id: field_ref
-orig-id: CONSTANT_Fieldref
10:
id: method_ref
-orig-id: CONSTANT_Methodref
11:
id: interface_method_ref
-orig-id: CONSTANT_InterfaceMethodref
12:
id: name_and_type
-orig-id: CONSTANT_NameAndType
15:
id: method_handle
-orig-id: CONSTANT_MethodHandle
16:
id: method_type
-orig-id: CONSTANT_MethodType
17:
id: dynamic
-orig-id: CONSTANT_Dynamic
18:
id: invoke_dynamic
-orig-id: CONSTANT_InvokeDynamic
19:
id: module
-orig-id: CONSTANT_Module
20:
id: package
-orig-id: CONSTANT_Package
version_guard:
doc: |
`class` file format version 45.3 (appeared in the very first publicly
known release of Java SE AND JDK 1.0.2, released 23th January 1996) is so
ancient that it's taken for granted. Earlier formats seem to be
undocumented. Changes of `version_minor` don't change `class` format.
Earlier `version_major`s likely belong to Oak programming language, the
proprietary predecessor of Java.
doc-ref:
- "James Gosling, Bill Joy and Guy Steele. The Java Language Specification. English. Ed. by Lisa Friendly. Addison-Wesley, Aug. 1996, p. 825. ISBN: 0-201-63451-1."
- "Frank Yellin and Tim Lindholm. The Java Virtual Machine Specification. English. Ed. by Lisa Friendly. Addison-Wesley, Sept. 1996, p. 475. ISBN: 0-201-63452-X."
params:
- id: major
type: u2
seq:
- size: 0
valid:
expr: _root.version_major >= major
class_cp_info:
-orig-id: CONSTANT_Class_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.1
seq:
- id: name_index
type: u2
instances:
name_as_info:
value: _root.constant_pool[name_index - 1].cp_info.as<utf8_cp_info>
name_as_str:
value: name_as_info.value
field_ref_cp_info:
-orig-id: CONSTANT_Fieldref_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.2
seq:
- id: class_index
type: u2
- id: name_and_type_index
type: u2
instances:
class_as_info:
value: _root.constant_pool[class_index - 1].cp_info.as<class_cp_info>
name_and_type_as_info:
value: _root.constant_pool[name_and_type_index - 1].cp_info.as<name_and_type_cp_info>
method_ref_cp_info:
-orig-id: CONSTANT_Methodref_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.2
seq:
- id: class_index
type: u2
- id: name_and_type_index
type: u2
instances:
class_as_info:
value: _root.constant_pool[class_index - 1].cp_info.as<class_cp_info>
name_and_type_as_info:
value: _root.constant_pool[name_and_type_index - 1].cp_info.as<name_and_type_cp_info>
interface_method_ref_cp_info:
-orig-id: CONSTANT_InterfaceMethodref_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.2
seq:
- id: class_index
type: u2
- id: name_and_type_index
type: u2
instances:
class_as_info:
value: _root.constant_pool[class_index - 1].cp_info.as<class_cp_info>
name_and_type_as_info:
value: _root.constant_pool[name_and_type_index - 1].cp_info.as<name_and_type_cp_info>
string_cp_info:
-orig-id: CONSTANT_String_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.3
seq:
- id: string_index
type: u2
integer_cp_info:
-orig-id: CONSTANT_Integer_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.4
seq:
- id: value
type: u4
float_cp_info:
-orig-id: CONSTANT_Float_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.5
seq:
- id: value
type: f4
long_cp_info:
-orig-id: CONSTANT_Long_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.5
seq:
- id: value
type: u8
double_cp_info:
-orig-id: CONSTANT_Double_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.6
seq:
- id: value
type: f8
name_and_type_cp_info:
-orig-id: CONSTANT_NameAndType_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.6
seq:
- id: name_index
type: u2
- id: descriptor_index
type: u2
instances:
name_as_info:
value: _root.constant_pool[name_index - 1].cp_info.as<utf8_cp_info>
name_as_str:
value: name_as_info.value
descriptor_as_info:
value: _root.constant_pool[descriptor_index - 1].cp_info.as<utf8_cp_info>
descriptor_as_str:
value: descriptor_as_info.value
utf8_cp_info:
-orig-id: CONSTANT_Utf8_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.7
seq:
- id: str_len
type: u2
- id: value
type: str
size: str_len
encoding: UTF-8
method_handle_cp_info:
-orig-id: CONSTANT_MethodHandle_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.8
seq:
- type: version_guard(51)
- id: reference_kind
type: u1
enum: reference_kind_enum
- id: reference_index
type: u2
enums:
reference_kind_enum:
1: get_field
2: get_static
3: put_field
4: put_static
5: invoke_virtual
6: invoke_static
7: invoke_special
8: new_invoke_special
9: invoke_interface
method_type_cp_info:
-orig-id: CONSTANT_MethodType_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.9
seq:
- type: version_guard(51)
- id: descriptor_index
type: u2
dynamic_cp_info:
-orig-id: CONSTANT_Dynamic_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se19/html/jvms-4.html#jvms-4.4.10
seq:
- type: version_guard(55)
- id: bootstrap_method_attr_index
type: u2
- id: name_and_type_index
type: u2
invoke_dynamic_cp_info:
-orig-id: CONSTANT_InvokeDynamic_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.10
seq:
- type: version_guard(51)
- id: bootstrap_method_attr_index
type: u2
- id: name_and_type_index
type: u2
module_package_cp_info:
-orig-id:
- CONSTANT_Module_info
- CONSTANT_Package_info
doc: |
Project Jigsaw modules introduced in Java 9
doc-ref:
- https://docs.oracle.com/javase/specs/jvms/se19/html/jvms-3.html#jvms-3.16
- https://docs.oracle.com/javase/specs/jvms/se19/html/jvms-4.html#jvms-4.4.11
- https://docs.oracle.com/javase/specs/jvms/se19/html/jvms-4.html#jvms-4.4.12
seq:
- type: version_guard(53)
- id: name_index
type: u2
instances:
name_as_info:
value: _root.constant_pool[name_index - 1].cp_info.as<utf8_cp_info>
name_as_str:
value: name_as_info.value
field_info:
-orig-id: field_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.5
seq:
- id: access_flags
type: u2
- id: name_index
type: u2
- id: descriptor_index
type: u2
- id: attributes_count
type: u2
- id: attributes
type: attribute_info
repeat: expr
repeat-expr: attributes_count
instances:
name_as_str:
value: _root.constant_pool[name_index - 1].cp_info.as<utf8_cp_info>.value
attribute_info:
-orig-id: attribute_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7
seq:
- id: name_index
type: u2
- id: attribute_length
type: u4
- id: info
size: attribute_length
type:
switch-on: name_as_str
cases:
'"Code"': attr_body_code # 4.7.3
'"Exceptions"': attr_body_exceptions # 4.7.5
'"SourceFile"': attr_body_source_file # 4.7.10
'"LineNumberTable"': attr_body_line_number_table # 4.7.12
instances:
name_as_str:
value: _root.constant_pool[name_index - 1].cp_info.as<utf8_cp_info>.value
types:
attr_body_code:
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3
seq:
- id: max_stack
type: u2
- id: max_locals
type: u2
- id: code_length
type: u4
- id: code
size: code_length
- id: exception_table_length
type: u2
- id: exception_table
type: exception_entry
repeat: expr
repeat-expr: exception_table_length
- id: attributes_count
type: u2
- id: attributes
type: attribute_info
repeat: expr
repeat-expr: attributes_count
types:
exception_entry:
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3
seq:
- id: start_pc
type: u2
doc: |
Start of a code region where exception handler is being
active, index in code array (inclusive)
- id: end_pc
type: u2
doc: |
End of a code region where exception handler is being
active, index in code array (exclusive)
- id: handler_pc
type: u2
doc: Start of exception handler code, index in code array
- id: catch_type
type: u2
doc: |
Exception class that this handler catches, index in constant
pool, or 0 (catch all exceptions handler, used to implement
`finally`).
instances:
catch_exception:
value: _root.constant_pool[catch_type - 1]
if: catch_type != 0
attr_body_exceptions:
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.5
seq:
- id: number_of_exceptions
type: u2
- id: exceptions
type: exception_table_entry
repeat: expr
repeat-expr: number_of_exceptions
types:
exception_table_entry:
seq:
- id: index
type: u2
instances:
as_info:
value: _root.constant_pool[index - 1].cp_info.as<class_cp_info>
name_as_str:
value: as_info.name_as_str
attr_body_source_file:
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.10
seq:
- id: sourcefile_index
type: u2
instances:
sourcefile_as_str:
value: _root.constant_pool[sourcefile_index - 1].cp_info.as<utf8_cp_info>.value
attr_body_line_number_table:
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.12
seq:
- id: line_number_table_length
type: u2
- id: line_number_table
type: line_number_table_entry
repeat: expr
repeat-expr: line_number_table_length
types:
line_number_table_entry:
seq:
- id: start_pc
type: u2
- id: line_number
type: u2
method_info:
-orig-id: method_info
doc-ref: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.6
seq:
- id: access_flags
type: u2
- id: name_index
type: u2
- id: descriptor_index
type: u2
- id: attributes_count
type: u2
- id: attributes
type: attribute_info
repeat: expr
repeat-expr: attributes_count
instances:
name_as_str:
value: _root.constant_pool[name_index - 1].cp_info.as<utf8_cp_info>.value