JASM format for Dynamic constants
Leonid Kuskov
leonid.kuskov at oracle.com
Tue Aug 20 21:10:58 UTC 2024
Thanks, Dan, for pointing this out.
The page appears to be quite outdated. I'll need some time to synchronize the syntax with the current implementation, which has undergone slight changes.
For example, the current output (not yet integrated) is shown in the attachment.
From: code-tools-dev <code-tools-dev-retn at openjdk.org> on behalf of Dan Smith <daniel.smith at oracle.com>
Date: Monday, August 19, 2024 at 4:08 PM
To: code-tools-dev at openjdk.org <code-tools-dev at openjdk.org>
Subject: JASM format for Dynamic constants
The JASM syntax is specified on this page:
https://wiki.openjdk.org/pages/viewpage.action?pageId=21430416
It is stale, and makes no mention of Dynamic constants. I'm not sure if there are other new features that should be covered as well.
Based on some trial and error, I believe the text should be updated as follows:
"The Constant Pool and Constant Elements"
1) Add "Dynamic" to the list of TAGs
2) Clean up the use of CONSTANT_FIELD, which is kind of a mess.
- I'd suggest a CONSTANT_METHOD production which looks exactly the same but narratively is described as having a method descriptor. Otherwise, maybe name the thing CONSTANT_REFERENCE.
- There's a missing InterfaceMethodref row from the TAGGED_CONSTANT_VALUE table
- The second argument to a MethodHandle is *not* a CONSTANT_FIELD—it's a "CONSTANT_CELL(Field | Method | InterfaceMethod)" (specifically, it can be tagged or untagged, and it can be a #n reference to the constant pool)
- Similarly for the second argument to a InvokeDynamic
3) Add a row to TAGGED_CONSTANT_VALUE, as follows:
Dynamic INVOKESUBTAG : CONSTANT_CELL(Field | Method | InterfaceMethod) : NAME_AND_TYPE [ INVOKEDYNAMIC_STATIC_ARGS ]
I'd suggest some narrative text here to clarify that: for InvokeDynamic and Dynamic, there will typically be two NAME_AND_TYPE pairs in succession. The first is to refer to the bootstrap method. The second provides the name and type arguments passed to the bootstrap method. For an InvokeDynamic, the 2nd NAME_AND_TYPE would use a method descriptor; for a Dynamic, the 2nd NAME_AND_TYPE would be a field descriptor.
4) Add Dynamic to places that mention InvokeDynamic:
"When the JASM parser encounters an InvokeDynamic **or Dynamic** constant"
"INVOKESUBTAGs for MethodHandle**,** ~~and (const)~~ InvokeDynamic**, and Dynamic** are defined as follows"
"Static arguments for an InvokeDynamic **or Dynamic** constant are defined as follows:"
5) Update INVOKEDYNAMIC_STATIC_ARGUMENTS to include optional braces ("{ ... }").
6) Add "Dynamic" to the list of INVOKEDYNAMIC_STATIC_ARG variants.
INVOKEDYNAMIC_STATIC_ARG should be expressed in terms of CONSTANT_CELL, rather than trying to redefine it. I might write this as "CONSTANT_CELL(int | long | float | double | class | String | MethodHandle | MethodType | Dynamic)"; or it could be listed as "CONSTANT_CELL(int)", "CONSTANT_CELL(long)", ..., each variant on its own row.
7) Consider revising some of the discussion/examples from "InvokeDynamic Instructions" to illustrate both InvokeDynamic and Dynamic, and shift it from the "Instructions" section of the document to "The Constant Pool and Constant Elements". Update the grammar discussed there to align with the changes described above.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/code-tools-dev/attachments/20240820/fcc98d92/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LambdaConversion.class.g.t.jasm
Type: application/octet-stream
Size: 13918 bytes
Desc: LambdaConversion.class.g.t.jasm
URL: <https://mail.openjdk.org/pipermail/code-tools-dev/attachments/20240820/fcc98d92/LambdaConversion.class.g.t-0001.jasm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestInlined.class.jasm
Type: application/octet-stream
Size: 3477 bytes
Desc: TestInlined.class.jasm
URL: <https://mail.openjdk.org/pipermail/code-tools-dev/attachments/20240820/fcc98d92/TestInlined.class-0001.jasm>
More information about the code-tools-dev
mailing list