From mdegtyarev at gmail.com Wed Apr 21 22:53:45 2021 From: mdegtyarev at gmail.com (Maxim Degtyarev) Date: Thu, 22 Apr 2021 01:53:45 +0300 Subject: asmtools `ldc Dynamic` syntax Message-ID: Hello, I have 2 questions regarding `ldc Dynamic` syntax: 1) Consider the following example: ldc Dynamic REF_newInvokeSpecial :LdcConDyTwice."" :"(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."" :"(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. From leonid.kuskov at oracle.com Thu Apr 22 05:01:11 2021 From: leonid.kuskov at oracle.com (Leonid Kuskov) Date: Thu, 22 Apr 2021 05:01:11 +0000 Subject: asmtools `ldc Dynamic` syntax In-Reply-To: References: Message-ID: <8C01E265-A548-425C-8D0E-649EBEC9AB44@oracle.com> 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" wrote: Hello, I have 2 questions regarding `ldc Dynamic` syntax: 1) Consider the following example: ldc Dynamic REF_newInvokeSpecial :LdcConDyTwice."" :"(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."" :"(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. From leonid.kuskov at oracle.com Thu Apr 22 05:07:05 2021 From: leonid.kuskov at oracle.com (Leonid Kuskov) Date: Thu, 22 Apr 2021 05:07:05 +0000 Subject: asmtools `ldc Dynamic` syntax In-Reply-To: <8C01E265-A548-425C-8D0E-649EBEC9AB44@oracle.com> References: <8C01E265-A548-425C-8D0E-649EBEC9AB44@oracle.com> Message-ID: Correction: The issue for tracking purposes is https://bugs.openjdk.java.net/browse/CODETOOLS-7902888 ?On 4/21/21, 10:01 PM, "code-tools-dev on behalf of Leonid Kuskov" wrote: 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" wrote: Hello, I have 2 questions regarding `ldc Dynamic` syntax: 1) Consider the following example: ldc Dynamic REF_newInvokeSpecial :LdcConDyTwice."" :"(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."" :"(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. From mdegtyarev at gmail.com Thu Apr 22 11:13:15 2021 From: mdegtyarev at gmail.com (Maxim Degtyarev) Date: Thu, 22 Apr 2021 14:13:15 +0300 Subject: asmtools `ldc Dynamic` syntax In-Reply-To: <8C01E265-A548-425C-8D0E-649EBEC9AB44@oracle.com> References: <8C01E265-A548-425C-8D0E-649EBEC9AB44@oracle.com> Message-ID: > 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 . Either assembler or disassembler doing wrong: - Disassembler produce output with the "Method " prefix for constructor reference: ldc Dynamic REF_newInvokeSpecial :Method LdcConDyTwice."" ... - Assembler in turn accept only syntax WITHOUT "Method " prefix: ldc Dynamic REF_newInvokeSpecial :LdcConDyTwice."" ... 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 () 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" wrote: > > Hello, > > I have 2 questions regarding `ldc Dynamic` syntax: > > 1) Consider the following example: > > ldc Dynamic > REF_newInvokeSpecial > :LdcConDyTwice."" > :"(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."" > :"(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. > From leonid.kuskov at oracle.com Fri Apr 23 04:29:41 2021 From: leonid.kuskov at oracle.com (Leonid Kuskov) Date: Fri, 23 Apr 2021 04:29:41 +0000 Subject: [External] : Re: asmtools `ldc Dynamic` syntax In-Reply-To: References: <8C01E265-A548-425C-8D0E-649EBEC9AB44@oracle.com> Message-ID: 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 ." It's valid to write ldc Dynamic REF_invokeVirtual:InterfaceMethod ClassName:"" On 4/22/21, 4:14 AM, "Maxim Degtyarev" 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 . Either assembler or disassembler doing wrong: - Disassembler produce output with the "Method " prefix for constructor reference: ldc Dynamic REF_newInvokeSpecial :Method LdcConDyTwice."" ... - Assembler in turn accept only syntax WITHOUT "Method " prefix: ldc Dynamic REF_newInvokeSpecial :LdcConDyTwice."" ... 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 () 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" wrote: > > Hello, > > I have 2 questions regarding `ldc Dynamic` syntax: > > 1) Consider the following example: > > ldc Dynamic > REF_newInvokeSpecial > :LdcConDyTwice."" > :"(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."" > :"(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. > From mdegtyarev at gmail.com Fri Apr 30 09:27:14 2021 From: mdegtyarev at gmail.com (Maxim Degtyarev) Date: Fri, 30 Apr 2021 12:27:14 +0300 Subject: [External] : Re: asmtools `ldc Dynamic` syntax In-Reply-To: References: <8C01E265-A548-425C-8D0E-649EBEC9AB44@oracle.com> Message-ID: Hello, It looks like the latest patch fix `ldc Dynamic` but broke `ldc MethodHandle`. Here is the example: https://gist.github.com/Maccimo/a71b16e0c0282e8159866decf8b8cd21 Provided *.jasm file is successfully assembled with asmtools built from the `pull/15` branch but failed to be assembled with asmtools built from `pull/17` branch. The error message is as follows: TestLdcMethodHandle.jasm (17:42) Error: Wrong tag: Either Method or InterfaceMethod expected. ldc MethodHandle REF_invokeStatic:Method TestLdcMethodHandle.main:"([Ljava/lang/String;)V"; ^ 1 error El vie, 23 abr 2021 a las 7:29, Leonid Kuskov () escribi?: > > 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 ." > It's valid to write ldc Dynamic REF_invokeVirtual:InterfaceMethod ClassName:"" > > > On 4/22/21, 4:14 AM, "Maxim Degtyarev" 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 . > > Either assembler or disassembler doing wrong: > > - Disassembler produce output with the "Method " prefix for > constructor reference: > > ldc Dynamic > REF_newInvokeSpecial > :Method LdcConDyTwice."" > ... > > - Assembler in turn accept only syntax WITHOUT "Method " prefix: > > ldc Dynamic > REF_newInvokeSpecial > :LdcConDyTwice."" > ... > > 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 > () 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" wrote: > > > > Hello, > > > > I have 2 questions regarding `ldc Dynamic` syntax: > > > > 1) Consider the following example: > > > > ldc Dynamic > > REF_newInvokeSpecial > > :LdcConDyTwice."" > > :"(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."" > > :"(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. > > > > From leonid.kuskov at oracle.com Fri Apr 30 17:26:30 2021 From: leonid.kuskov at oracle.com (Leonid Kuskov) Date: Fri, 30 Apr 2021 17:26:30 +0000 Subject: [External] : Re: asmtools `ldc Dynamic` syntax In-Reply-To: References: <8C01E265-A548-425C-8D0E-649EBEC9AB44@oracle.com> Message-ID: <5582321B-0B0F-4DE4-AA3F-71CFE031E2D8@oracle.com> Hello, Thanks for catching that. The fix https://bugs.openjdk.java.net/browse/CODETOOLS-7902913 is in progress. ?On 4/30/21, 2:27 AM, "Maxim Degtyarev" wrote: Hello, It looks like the latest patch fix `ldc Dynamic` but broke `ldc MethodHandle`. Here is the example: https://urldefense.com/v3/__https://gist.github.com/Maccimo/a71b16e0c0282e8159866decf8b8cd21__;!!GqivPVa7Brio!MFgqgFI3jTZuX26VqUdUwkvd3OJmzsfAxnVKaptUElF62TARkazDBMvYgZTBOGIGuFs$ Provided *.jasm file is successfully assembled with asmtools built from the `pull/15` branch but failed to be assembled with asmtools built from `pull/17` branch. The error message is as follows: TestLdcMethodHandle.jasm (17:42) Error: Wrong tag: Either Method or InterfaceMethod expected. ldc MethodHandle REF_invokeStatic:Method TestLdcMethodHandle.main:"([Ljava/lang/String;)V"; ^ 1 error El vie, 23 abr 2021 a las 7:29, Leonid Kuskov () escribi?: > > 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 ." > It's valid to write ldc Dynamic REF_invokeVirtual:InterfaceMethod ClassName:"" > > > On 4/22/21, 4:14 AM, "Maxim Degtyarev" 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 . > > Either assembler or disassembler doing wrong: > > - Disassembler produce output with the "Method " prefix for > constructor reference: > > ldc Dynamic > REF_newInvokeSpecial > :Method LdcConDyTwice."" > ... > > - Assembler in turn accept only syntax WITHOUT "Method " prefix: > > ldc Dynamic > REF_newInvokeSpecial > :LdcConDyTwice."" > ... > > 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 > () 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" wrote: > > > > Hello, > > > > I have 2 questions regarding `ldc Dynamic` syntax: > > > > 1) Consider the following example: > > > > ldc Dynamic > > REF_newInvokeSpecial > > :LdcConDyTwice."" > > :"(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."" > > :"(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. > > > >