> I've added a `java.lang.invoke.MethodHandle.TRACE_CALLSITE` property to show > 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_CALLSITE=true -cp . StrConcat > ======== CallSite: StrConcat.main(StrConcat.java:5) > BSM = > java.base/java.lang.invoke.StringConcatFactory.makeConcatWithConstants(StringConcatFactory.java:354) > target class = java.lang.invoke.BoundMethodHandle$Species_L > target = (String,String)String : BMH.reinvoke=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.invokeStatic=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 > } > ] > HelloWorld > ======== CallSite: StrConcat.main(StrConcat.java:6) > BSM = > java.base/java.lang.invoke.StringConcatFactory.makeConcatWithConstants(StringConcatFactory.java:354) > target class = java.lang.invoke.BoundMethodHandle$Species_LL > target = (String)String : invoke=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.invokeStatic=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 ) > ] > HelloWorld > > > More complex examples are in the JBS bug report > - https://bugs.openjdk.org/secure/attachment/101170/eclipse-ide-log.txt > - https://bugs.openjdk.org/secure/attachment/101168/lambda-expression.txt > - > https://bugs.openjdk.org/secure/attachment/101174/pattern-matching-switch.txt > - https://bugs.openjdk.org/secure/attachment/101169/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 ------------- Changes: - all: https://git.openjdk.org/jdk/pull/10842/files - new: https://git.openjdk.org/jdk/pull/10842/files/c26cbd7c..5d2ac5a2 Webrevs: - full: https://webrevs.openjdk.org/?repo=jdk&pr=10842&range=03 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=10842&range=02-03 Stats: 154080 lines in 1740 files changed: 87176 ins; 33940 del; 32964 mod Patch: https://git.openjdk.org/jdk/pull/10842.diff Fetch: git fetch https://git.openjdk.org/jdk pull/10842/head:pull/10842 PR: https://git.openjdk.org/jdk/pull/10842