JDK-8272614 : Unused parameters in MethodHandleNatives linking methods
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 18
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2021-08-18
  • Updated: 2021-10-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 18
18Unresolved
Related Reports
Relates :  
Description
The constant dynamic changes in JDK-8186209 updated MethodHandleNatives.linkCallSite to take an int parameter `indexInCP` that is passed up from the VM, but it is not actually used:

From: http://hg.openjdk.java.net/jdk/jdk/rev/c4d9d1b08e2e

@@ -228,6 +234,7 @@
      * The JVM is linking an invokedynamic instruction.  Create a reified call site for it.
      */
     static MemberName linkCallSite(Object callerObj,
+                                   int indexInCP,
                                    Object bootstrapMethodObj,
                                    Object nameObj, Object typeObj,
                                    Object staticArguments,

@@ -268,9 +275,7 @@
                                           Object[] appendixResult) {
         Object bsmReference = bootstrapMethod.internalMemberName();
         if (bsmReference == null)  bsmReference = bootstrapMethod;
-        Object staticArglist = (staticArguments instanceof Object[] ?
-                                java.util.Arrays.asList((Object[]) staticArguments) :
-                                staticArguments);
+        String staticArglist = staticArglistForTrace(staticArguments);
         System.out.println("linkCallSite "+caller.getName()+" "+
                            bsmReference+" "+
                            name+type+"/"+staticArglist);

@@ -280,11 +285,89 @@
             System.out.println("linkCallSite => "+res+" + "+appendixResult[0]);
             return res;
         } catch (Throwable ex) {
+            ex.printStackTrace(); // print now in case exception is swallowed
             System.out.println("linkCallSite => throw "+ex);
             throw ex;
         }
     }
 
+    // this implements the upcall from the JVM, MethodHandleNatives.linkDynamicConstant:
+    static Object linkDynamicConstant(Object callerObj,
+                                      int indexInCP,
+                                      Object bootstrapMethodObj,
+                                      Object nameObj, Object typeObj,
+                                      Object staticArguments) {
+        MethodHandle bootstrapMethod = (MethodHandle)bootstrapMethodObj;
+        Class<?> caller = (Class<?>)callerObj;
+        String name = nameObj.toString().intern();
+        Class<?> type = (Class<?>)typeObj;
+        if (!TRACE_METHOD_LINKAGE)
+            return linkDynamicConstantImpl(caller, bootstrapMethod, name, type, staticArguments);
+        return linkDynamicConstantTracing(caller, bootstrapMethod, name, type, staticArguments);
+    }

The new indexInCP parameter is not used; nor is it used in the newly added linkDynamicConstant method.