Classfile API proposal to integrate basic print functionality directly to ClassModel and MethodModel
Adam Sotona
adam.sotona at oracle.com
Fri Jul 22 20:50:43 UTC 2022
We can drop many features and it still looks OK, except for expanded vs compact lists and maps. Compact map can be represented as array, however I’m not aware of anything similar for Map. Or we can use explicit delimiter class Compact, where everything inside is treated as compact form. Or we can avoid compact maps and use Maps and Lists for expanded form and arrays for compact lists.
I am not sure what you mean by “compact lists and maps”? Can you give an example so I see what you are aiming at?
Expanded is everything spread across multiple lines.
Expanded lists in the example below are top level list of classes and lists of fields and methods.
Expanded maps are: content of class, constant pool, content of field, content of method, code and stack map frames
Compact means all in one line. Compact lists are everything in [ ] and compact maps everything in { }.
If you traverse the tree from root you can never return from compact to expanded, so an indicator (list or map attribute or another form of delimiter) should indicate where to start render compacted form of lists and maps.
The same applies for XML and JSON if we would like to have them human-readable.
- class name: 'Foo'
version: '61.0'
flags: [PUBLIC]
superclass: 'Boo'
interfaces: ['Phee', 'Phoo']
attributes: [SourceFile]
constant pool:
1: [CONSTANT_Utf8, 'Foo']
2: [CONSTANT_Class, {name index: 1, name: 'Foo'}]
3: [CONSTANT_Utf8, 'Boo']
4: [CONSTANT_Class, {name index: 3, name: 'Boo'}]
5: [CONSTANT_Utf8, 'f']
6: [CONSTANT_Utf8, 'Ljava/lang/String;']
7: [CONSTANT_Utf8, 'm']
8: [CONSTANT_Utf8, '(ZLjava/lang/Throwable;)Ljava/lang/Void;']
9: [CONSTANT_Utf8, 'Phee']
10: [CONSTANT_Class, {name index: 9, name: 'Phee'}]
11: [CONSTANT_Utf8, 'Phoo']
12: [CONSTANT_Class, {name index: 11, name: 'Phoo'}]
13: [CONSTANT_Utf8, 'Code']
14: [CONSTANT_Utf8, 'StackMapTable']
15: [CONSTANT_Utf8, 'SourceFile']
16: [CONSTANT_Utf8, 'Foo.java']
source: 'Foo.java'
fields:
- field name: 'f'
flags: [PRIVATE]
descriptor: 'Ljava/lang/String;'
attributes: []
methods:
- method name: 'm'
flags: [PROTECTED]
descriptor: '(ZLjava/lang/Throwable;)Ljava/lang/Void;'
attributes: [Code]
code:
max stack: 1
max locals: 3
attributes: [StackMapTable]
stack map frames:
6: {locals: ['Foo', 'int', 'java/lang/Throwable'], stack: []}
#stack map frame locals: ['Foo', 'int', 'java/lang/Throwable'], stack: []
0: [ILOAD_1, {slot: 1}]
1: [IFEQ, {target: 6}]
4: [ALOAD_2, {slot: 2}]
5: [ATHROW]
#stack map frame locals: ['Foo', 'int', 'java/lang/Throwable'], stack: []
6: [RETURN]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20220722/507c2f1f/attachment-0001.htm>
More information about the classfile-api-dev
mailing list