asmtools `ldc Dynamic` syntax

Maxim Degtyarev mdegtyarev at gmail.com
Thu Apr 22 11:13:15 UTC 2021


> If the value of the reference_kind item is 6 (REF_invokeStatic) or 7 (REF_invokeSpecial),

The question is about other part:

If the value is 8 (REF_newInvokeSpecial), the name of the method represented
by a CONSTANT_Methodref_info structure must be <init>.

Either assembler or disassembler doing wrong:

- Disassembler produce output with the "Method " prefix for
constructor reference:

  ldc    Dynamic
      REF_newInvokeSpecial
      :Method LdcConDyTwice."<init>"
...

- Assembler in turn accept only syntax WITHOUT "Method " prefix:

  ldc Dynamic
      REF_newInvokeSpecial
      :LdcConDyTwice."<init>"
...

The question is: Which syntax is correct for REF_newInvokeSpecial?

> > (it's even didn't assemble back).
> I could not reproduce this. Please send your example.

Here is an example:
https://gist.github.com/Maccimo/9763417764aa53576c39b73d14a8fc85

Assembled with asmtools built from master branch of
https://github.com/openjdk/asmtools

BTW, https://wiki.openjdk.java.net/display/CodeTools/asmtools page
contains broken links for downloads and there are no "Releases" on
GitHub for asmtools.



In case you need a bit less synthetic example here is ENUM class
example implemented via ConDy:

https://github.com/Maccimo/HugeEnumGeneratorArticle/blob/master/5_Samples/bin/ConDyHugeEnum.class

Everything required to generate such enums can be found in the same repository.

> > 2nd issue is the defect, although it doesn't affect a code the bytecode footprint grows.

Not only bytecode footprint. Different Dynamic CP entries will
reference different instances of objects.

El jue, 22 abr 2021 a las 8:01, Leonid Kuskov
(<leonid.kuskov at oracle.com>) escribió:
>
> Hello,
>
> Your first question is about the JVMS 4.4.8. The CONSTANT_MethodHandle_info Structure
> CONSTANT_MethodHandle_info {
>     u1 tag;
>     u1 reference_kind;
>     u2 reference_index;
> }
> The format of the ldc instruction is: ldc Dynamic reference_kind:reference_index {ClassName|InterfaceName}.MethodName ....
> According to the assertion:
>
> If the value of the reference_kind item is 6 (REF_invokeStatic) or 7 (REF_invokeSpecial), then if the class file version number is less than 52.0, the constant_pool entry at that index must be a CONSTANT_Methodref_info structure representing a class's method for which a method handle is to be created; if the class file version number is 52.0 or above, the constant_pool entry at that index must be either a CONSTANT_Methodref_info structure or a CONSTANT_InterfaceMethodref_info structure (§4.4.2) representing a class's or interface's method for which a method handle is to be created.
>
> i.e. we might have the following pairs:
>
> ldc Dynamic  REF_invokeSpecial:Method ...... if reference_index is an index of a CONSTANT_Methodref_info structure in CP or
> ldc Dynamic  REF_invokeSpecial: InterfaceMethod... if reference_index points to CONSTANT_InterfaceMethodref_info
>
> 2nd issue is the defect, although it doesn't affect a code the bytecode footprint grows.
> I will take care of the problem: https://bugs.openjdk.java.net/browse/JDK-8129547
>
> > (it's even didn't assemble back).
> I could not reproduce this. Please send your example.
>
>
>
> On 4/21/21, 3:54 PM, "code-tools-dev on behalf of Maxim Degtyarev" <code-tools-dev-retn at openjdk.java.net on behalf of mdegtyarev at gmail.com> wrote:
>
>     Hello,
>
>     I have 2 questions regarding `ldc Dynamic` syntax:
>
>     1) Consider the following example:
>
>               ldc Dynamic
>                   REF_newInvokeSpecial
>                   :LdcConDyTwice."<init>"
>                   :"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)V"
>                 :LdcConDyTwice
>                 :"LLdcConDyTwice;";
>
>     Being assembled with `asmtools jasm` and then disassembled with
>     `asmtools jdis` above instruction turns to:
>
>             ldc    Dynamic
>                 REF_newInvokeSpecial
>                 :Method LdcConDyTwice."<init>"
>                 :"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;)V"
>                 :LdcConDyTwice
>                 :"LLdcConDyTwice;";
>
>     I assume "Method" in front of the constructor reference is a
>     disassembler bug (it's even didn't assemble back).
>     Could anyone confirm my assumption?
>
>     2) Is there a way to reference the same Dynamic constant more than
>     once with the current jasm syntax?
>     Right now two syntactically equal ldc Dynamic instructions create two
>     different entries in BootstrapMethods attribute.
>


More information about the code-tools-dev mailing list