[External] : Re: asmtools `ldc Dynamic` syntax

Leonid Kuskov leonid.kuskov at oracle.com
Fri Apr 23 04:29:41 UTC 2021


Agreed, processing of the reference_kind items is incorrect, excepting REF_invokeStatic, REF_invokeSpecial. (https://bugs.openjdk.java.net/browse/CODETOOLS-7902892)
I've fixed this and the fix will be applied in the coming days. I need time to test it.
The format will be the same for all Dynamic instructions:
LDC(2_W) Dynamic  reference_kind:{Method|InterfaceMethod}  {ClassName|InterfaceName}.MethodName....
Since asmtools is written for testing purposes it doesn't control assertions like as follows:  
"If the value is 8 (REF_newInvokeSpecial), the name of the method represented by a CONSTANT_Methodref_info structure must be <init>."
It's valid to write ldc Dynamic REF_invokeVirtual:InterfaceMethod ClassName:"<clinit>"


On 4/22/21, 4:14 AM, "Maxim Degtyarev" <mdegtyarev at gmail.com> wrote:

    > 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://urldefense.com/v3/__https://gist.github.com/Maccimo/9763417764aa53576c39b73d14a8fc85__;!!GqivPVa7Brio!MRmThSYowTE7Lm_SK_0zpruGdkigwFBH3hpCzEWqVAuEByXZnd8D-8K-WSjU1Yy68uc$ 

    Assembled with asmtools built from master branch of
    https://urldefense.com/v3/__https://github.com/openjdk/asmtools__;!!GqivPVa7Brio!MRmThSYowTE7Lm_SK_0zpruGdkigwFBH3hpCzEWqVAuEByXZnd8D-8K-WSjUI4LCXOU$ 

    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://urldefense.com/v3/__https://github.com/Maccimo/HugeEnumGeneratorArticle/blob/master/5_Samples/bin/ConDyHugeEnum.class__;!!GqivPVa7Brio!MRmThSYowTE7Lm_SK_0zpruGdkigwFBH3hpCzEWqVAuEByXZnd8D-8K-WSjUqB8d0tg$ 

    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