8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker jdk-11+16
authorredestad
Wed, 30 May 2018 14:46:28 +0200
changeset 50305 02934b0d661b
parent 50304 d5331b94f821
child 50306 ed7605e8675f
8203886: Invoke LambdaMetafactory::altMetafactory exactly from the BootstrapMethodInvoker Reviewed-by: mchung
src/java.base/share/classes/java/lang/invoke/BootstrapMethodInvoker.java
--- a/src/java.base/share/classes/java/lang/invoke/BootstrapMethodInvoker.java	Wed May 30 11:39:26 2018 +0200
+++ b/src/java.base/share/classes/java/lang/invoke/BootstrapMethodInvoker.java	Wed May 30 14:46:28 2018 +0200
@@ -134,6 +134,8 @@
                     String recipe = (String)argv[0];
                     Object[] shiftedArgs = Arrays.copyOfRange(argv, 1, argv.length);
                     result = (CallSite)bootstrapMethod.invokeExact(caller, name, (MethodType)type, recipe, shiftedArgs);
+                } else if (isLambdaMetafactoryAltMetafactoryBSM(bsmType)) {
+                    result = (CallSite)bootstrapMethod.invokeExact(caller, name, (MethodType)type, argv);
                 } else {
                     switch (argv.length) {
                         case 0:
@@ -286,6 +288,9 @@
     private static final MethodType LMF_INDY_MT = MethodType.methodType(CallSite.class,
             Lookup.class, String.class, MethodType.class, MethodType.class, MethodHandle.class, MethodType.class);
 
+    private static final MethodType LMF_ALT_MT = MethodType.methodType(CallSite.class,
+            Lookup.class, String.class, MethodType.class, Object[].class);
+
     private static final MethodType LMF_CONDY_MT = MethodType.methodType(Object.class,
             Lookup.class, String.class, Class.class, MethodType.class, MethodHandle.class, MethodType.class);
 
@@ -319,6 +324,15 @@
         return bsmType == LMF_INDY_MT;
     }
 
+    /**
+     * @return true iff the BSM method type exactly matches
+     *         {@see java.lang.invoke.LambdaMetafactory#altMetafactory(
+     *          MethodHandles.Lookup,String,MethodType,Object[])}
+     */
+    private static boolean isLambdaMetafactoryAltMetafactoryBSM(MethodType bsmType) {
+        return bsmType == LMF_ALT_MT;
+    }
+
     /** The JVM produces java.lang.Integer values to box
      *  CONSTANT_Integer boxes but does not intern them.
      *  Let's intern them.  This is slightly wrong for