JASM format for Dynamic constants
Jonathan Gibbons
jonathan.gibbons at oracle.com
Tue Aug 20 18:59:35 UTC 2024
Paging Leonid...
-- Jon
On 8/19/24 4:08 PM, Dan Smith wrote:
> 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.
>
More information about the code-tools-dev
mailing list