src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java

Print this page
rev 17771 : 8184777: species logic for BoundMethodHandle doesn't scale, needs refactor

@@ -378,15 +378,15 @@
         return new LambdaFormBuffer(lambdaForm);
     }
 
     /// Editing methods for method handles.  These need to have fast paths.
 
-    private BoundMethodHandle.SpeciesData oldSpeciesData() {
-        return BoundMethodHandle.speciesData(lambdaForm);
+    private BoundMethodHandle.BMHSpecies oldSpeciesData() {
+        return BoundMethodHandle.formSpeciesData(lambdaForm);
     }
-    private BoundMethodHandle.SpeciesData newSpeciesData(BasicType type) {
-        return oldSpeciesData().extendWith(type);
+    private BoundMethodHandle.BMHSpecies newSpeciesData(BasicType type) {
+        return oldSpeciesData().extendWith((byte) type.ordinal());
     }
 
     BoundMethodHandle bindArgumentL(BoundMethodHandle mh, int pos, Object value) {
         assert(mh.speciesData() == oldSpeciesData());
         BasicType bt = L_TYPE;

@@ -444,12 +444,12 @@
             return form;
         }
         LambdaFormBuffer buf = buffer();
         buf.startEdit();
 
-        BoundMethodHandle.SpeciesData oldData = oldSpeciesData();
-        BoundMethodHandle.SpeciesData newData = newSpeciesData(lambdaForm.parameterType(pos));
+        BoundMethodHandle.BMHSpecies oldData = oldSpeciesData();
+        BoundMethodHandle.BMHSpecies newData = newSpeciesData(lambdaForm.parameterType(pos));
         Name oldBaseAddress = lambdaForm.parameter(0);  // BMH holding the values
         Name newBaseAddress;
         NamedFunction getter = newData.getterFunction(oldData.fieldCount());
 
         if (pos != 0) {

@@ -459,11 +459,11 @@
             newBaseAddress = oldBaseAddress.withConstraint(newData);
             buf.renameParameter(0, newBaseAddress);
             buf.replaceParameterByNewExpression(pos, new Name(getter, newBaseAddress));
         } else {
             // cannot bind the MH arg itself, unless oldData is empty
-            assert(oldData == BoundMethodHandle.SpeciesData.EMPTY);
+            assert(oldData == BoundMethodHandle.SPECIALIZER.topSpecies());
             newBaseAddress = new Name(L_TYPE).withConstraint(newData);
             buf.replaceParameterByNewExpression(0, new Name(getter, newBaseAddress));
             buf.insertParameter(0, newBaseAddress);
         }
 

@@ -651,12 +651,12 @@
         assert(pos + resultArity + (keepArguments ? combinerArity : 0) <= lambdaForm.arity);
         assert(pos > 0);  // cannot filter the MH arg itself
         assert(combinerType == combinerType.basicType());
         assert(combinerType.returnType() != void.class || dropResult);
 
-        BoundMethodHandle.SpeciesData oldData = oldSpeciesData();
-        BoundMethodHandle.SpeciesData newData = newSpeciesData(L_TYPE);
+        BoundMethodHandle.BMHSpecies oldData = oldSpeciesData();
+        BoundMethodHandle.BMHSpecies newData = newSpeciesData(L_TYPE);
 
         // The newly created LF will run with a different BMH.
         // Switch over any pre-existing BMH field references to the new BMH class.
         Name oldBaseAddress = lambdaForm.parameter(0);  // BMH holding the values
         buf.replaceFunctions(oldData.getterFunctions(), newData.getterFunctions(), oldBaseAddress);

@@ -714,12 +714,12 @@
         assert(pos <= lambdaForm.arity);
         assert(pos > 0);  // cannot filter the MH arg itself
         assert(combinerType == combinerType.basicType());
         assert(combinerType.returnType() != void.class || dropResult);
 
-        BoundMethodHandle.SpeciesData oldData = oldSpeciesData();
-        BoundMethodHandle.SpeciesData newData = newSpeciesData(L_TYPE);
+        BoundMethodHandle.BMHSpecies oldData = oldSpeciesData();
+        BoundMethodHandle.BMHSpecies newData = newSpeciesData(L_TYPE);
 
         // The newly created LF will run with a different BMH.
         // Switch over any pre-existing BMH field references to the new BMH class.
         Name oldBaseAddress = lambdaForm.parameter(0);  // BMH holding the values
         buf.replaceFunctions(oldData.getterFunctions(), newData.getterFunctions(), oldBaseAddress);

@@ -784,12 +784,12 @@
             if (newType == V_TYPE)
                 callFilter = null;
             else
                 callFilter = new Name(constantZero(newType));
         } else {
-            BoundMethodHandle.SpeciesData oldData = oldSpeciesData();
-            BoundMethodHandle.SpeciesData newData = newSpeciesData(L_TYPE);
+            BoundMethodHandle.BMHSpecies oldData = oldSpeciesData();
+            BoundMethodHandle.BMHSpecies newData = newSpeciesData(L_TYPE);
 
             // The newly created LF will run with a different BMH.
             // Switch over any pre-existing BMH field references to the new BMH class.
             Name oldBaseAddress = lambdaForm.parameter(0);  // BMH holding the values
             buf.replaceFunctions(oldData.getterFunctions(), newData.getterFunctions(), oldBaseAddress);