On Tue, 25 Oct 2022 13:16:19 GMT, Jorn Vernee <jver...@openjdk.org> wrote:

>> Ioi Lam has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   @JornVernee comments
>
> src/java.base/share/classes/java/lang/invoke/CallSite.java line 179:
> 
>> 177:         target.type();  // null check
>> 178:         this.target = target;
>> 179:         if (MethodHandleStatics.TRACE_CALLSITE) {
> 
> This doesn't seem like the right place to put this. Anyone can indirectly 
> extend CallSite, by extending e.g. MutableCallSite, but this code seems to 
> assume that the call is going through `MethodHandleNatives.linkCallSite`? I 
> suggest putting any tracing around that area. Both the target method handle, 
> and the BSM are available at that point in the code as well.
> 
> I also note that there's already a `TRACE_METHOD_LINKAGE` flag as well, which 
> does some tracing of call site linking. Maybe that option could be enhanced 
> instead of adding a new one?

Thanks for the suggestion! I removed the new property and just piggyback on 
`TRACE_METHOD_LINKAGE`. I also moved the tracing code into 
`MethodHandleNatives.linkCallSiteXXX`, and improved the existing code a bit to 
print out the line number of the call site.

Here's what it looks like now:


$ java -Djava.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE=true -cp . StrConcat
[...]
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 : 
invoke001_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

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

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

Reply via email to