@@ -281,6 +281,12 @@ static MemberName linkCallSiteImpl(Class<?> caller,
281
281
type ,
282
282
staticArguments ,
283
283
caller );
284
+ if (TRACE_METHOD_LINKAGE ) {
285
+ MethodHandle target = callSite .getTarget ();
286
+ System .out .println ("linkCallSite target class => " + target .getClass ().getName ());
287
+ System .out .println ("linkCallSite target => " + target .debugString (0 ));
288
+ }
289
+
284
290
if (callSite instanceof ConstantCallSite ) {
285
291
appendixResult [0 ] = callSite .dynamicInvoker ();
286
292
return Invokers .linkToTargetMethod (type );
@@ -298,13 +304,13 @@ static MemberName linkCallSiteTracing(Class<?> caller,
298
304
Object bsmReference = bootstrapMethod .internalMemberName ();
299
305
if (bsmReference == null ) bsmReference = bootstrapMethod ;
300
306
String staticArglist = staticArglistForTrace (staticArguments );
301
- System .out .println ("linkCallSite " +caller . getName ( )+" " +
307
+ System .out .println ("linkCallSite " +getCallerInfo ( caller )+" " +
302
308
bsmReference +" " +
303
309
name +type +"/" +staticArglist );
304
310
try {
305
311
MemberName res = linkCallSiteImpl (caller , bootstrapMethod , name , type ,
306
312
staticArguments , appendixResult );
307
- System .out .println ("linkCallSite => " +res +" + " +appendixResult [0 ]);
313
+ System .out .println ("linkCallSite linkage => " +res +" + " +appendixResult [0 ]);
308
314
return res ;
309
315
} catch (Throwable ex ) {
310
316
ex .printStackTrace (); // print now in case exception is swallowed
@@ -313,6 +319,20 @@ static MemberName linkCallSiteTracing(Class<?> caller,
313
319
}
314
320
}
315
321
322
+ /**
323
+ * Return a human-readable description of the caller. Something like
324
+ * "java.base/java.security.Security.<clinit>(Security.java:82)"
325
+ */
326
+ private static String getCallerInfo (Class <?> caller ) {
327
+ for (StackTraceElement e : Thread .currentThread ().getStackTrace ()) {
328
+ if (e .getClassName ().equals (caller .getName ())) {
329
+ return e .toString ();
330
+ }
331
+ }
332
+ // fallback if the caller is somehow missing from the stack.
333
+ return caller .getName ();
334
+ }
335
+
316
336
// this implements the upcall from the JVM, MethodHandleNatives.linkDynamicConstant:
317
337
static Object linkDynamicConstant (Object callerObj ,
318
338
Object bootstrapMethodObj ,
0 commit comments