RFR: 8295537: Enhance TRACE_METHOD_LINKAGE to show the target MethodHandle [v4]

Mandy Chung mchung at openjdk.org
Thu Oct 27 16:24:26 UTC 2022


On Thu, 27 Oct 2022 05:24:33 GMT, Ioi Lam <iklam at openjdk.org> wrote:

>> Improve the handling of the `java.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE` property to print out the full graph of MethodHandles that are used at a CallSite. This helps us understand how invokedynamic call sites are resolved. For example:
>> 
>> 
>> public class StrConcat {
>>     static String hello = "Hello";
>>     static String world = "World";
>>     public static void main(String args[]) {
>>         System.out.println(hello + world);
>>         System.out.println(hello + "World");
>>     }
>> }
>> 
>> $ java -Djava.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE=true -cp . StrConcat
>> linkCallSite StrConcat.main(StrConcat.java:5) java.lang.invoke.StringConcatFactory.makeConcatWithConstants(Lookup,String,MethodType,String,Object[])CallSite/invokeStatic makeConcatWithConstants(String,String)String/BSA1=
>> linkMethod java.lang.invoke.MethodHandle.invokeExact(Lookup,String,MethodType,String,Object[])CallSite/5
>> linkMethod => java.lang.invoke.Invokers$Holder.invokeExact_MT(Object,Object,Object,Object,Object,Object,Object)Object/invokeStatic + (Lookup,String,MethodType,String,Object[])CallSite
>> linkCallSite target class => java.lang.invoke.BoundMethodHandle$Species_L
>> linkCallSite target => (String,String)String : BMH.reinvoke000_LLL_L=Lambda(a0:L/SpeciesData[L => Species_L],a1:L,a2:L)=>{
>>     t3:L=Species_L.argL0(a0:L);
>>     t4:L=MethodHandle.invokeBasic(t3:L,a1:L,a2:L);t4:L}
>> & BMH=[
>>   0: MethodHandle = {(Object,Object)String : DMH.invokeStatic000_LLL_L=Lambda(a0:L,a1:L,a2:L)=>{
>>         t3:L=DirectMethodHandle.internalMemberName(a0:L);
>>         t4:L=MethodHandle.linkToStatic(a1:L,a2:L,t3:L);t4:L}
>>     & DMH.MN=java.lang.StringConcatHelper.simpleConcat(Object,Object)String/invokeStatic
>>   }
>> ]
>> linkCallSite linkage => java.lang.invoke.Invokers$Holder.linkToTargetMethod(Object,Object,Object)Object/invokeStatic + MethodHandle(String,String)String
>> HelloWorld
>> linkCallSite StrConcat.main(StrConcat.java:6) java.lang.invoke.StringConcatFactory.makeConcatWithConstants(Lookup,String,MethodType,String,Object[])CallSite/invokeStatic makeConcatWithConstants(String)String/BSA1=World
>> linkCallSite target class => java.lang.invoke.BoundMethodHandle$Species_LL
>> linkCallSite target => (String)String : invoke000_LL_L=Lambda(a0:L/SpeciesData[LL => BoundMethodHandle$Species_LL],a1:L)=>{
>>     t2:L=BoundMethodHandle$Species_LL.argL1(a0:L);
>>     t3:L=BoundMethodHandle$Species_LL.argL0(a0:L);
>>     t4:L=MethodHandle.invokeBasic(t3:L,a1:L,t2:L);t4:L}
>> & BMH=[
>>   0: MethodHandle = {(Object,Object)String : DMH.invokeStatic000_LLL_L=Lambda(a0:L,a1:L,a2:L)=>{
>>         t3:L=DirectMethodHandle.internalMemberName(a0:L);
>>         t4:L=MethodHandle.linkToStatic(a1:L,a2:L,t3:L);t4:L}
>>     & DMH.MN=java.lang.StringConcatHelper.simpleConcat(Object,Object)String/invokeStatic
>>   }
>>   1: ( World )
>> ]
>> linkCallSite linkage => java.lang.invoke.Invokers$Holder.linkToTargetMethod(Object,Object)Object/invokeStatic + MethodHandle(String)String
>> HelloWorld
>> 
>> 
>> More complex examples are in the JBS bug report
>> - https://bugs.openjdk.org/secure/attachment/101202/eclipse-ide-log.txt
>> - https://bugs.openjdk.org/secure/attachment/101203/lambda-expression.txt
>> - https://bugs.openjdk.org/secure/attachment/101205/pattern-matching-switch.txt
>> - https://bugs.openjdk.org/secure/attachment/101204/str-concat.txt
>
> Ioi Lam has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains six additional commits since the last revision:
> 
>  - Merge branch 'master' into 8295537-trace-jli-dynamic-call-sites
>  - Use Thread::getStackTrace() to find the caller's line number, etc
>  - @JornVernee comments
>  - also print the BSM
>  - cleaned up code; added comments; avoid using indy inside TRACE_CALLSITE; avoid interleaving output
>  - 8295537: Debug tracing for resolved dynamic call sites

Marked as reviewed by mchung (Reviewer).

-------------

PR: https://git.openjdk.org/jdk/pull/10842


More information about the core-libs-dev mailing list