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,392 **** 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.SpeciesData newSpeciesData(BasicType type) { ! return oldSpeciesData().extendWith(type); } BoundMethodHandle bindArgumentL(BoundMethodHandle mh, int pos, Object value) { assert(mh.speciesData() == oldSpeciesData()); BasicType bt = L_TYPE; --- 378,392 ---- return new LambdaFormBuffer(lambdaForm); } /// Editing methods for method handles. These need to have fast paths. ! private BoundMethodHandle.BMHSpecies oldSpeciesData() { ! return BoundMethodHandle.formSpeciesData(lambdaForm); } ! 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,455 **** return form; } LambdaFormBuffer buf = buffer(); buf.startEdit(); ! BoundMethodHandle.SpeciesData oldData = oldSpeciesData(); ! BoundMethodHandle.SpeciesData 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) { --- 444,455 ---- return form; } LambdaFormBuffer buf = buffer(); buf.startEdit(); ! 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,469 **** 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); newBaseAddress = new Name(L_TYPE).withConstraint(newData); buf.replaceParameterByNewExpression(0, new Name(getter, newBaseAddress)); buf.insertParameter(0, newBaseAddress); } --- 459,469 ---- 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.SPECIALIZER.topSpecies()); newBaseAddress = new Name(L_TYPE).withConstraint(newData); buf.replaceParameterByNewExpression(0, new Name(getter, newBaseAddress)); buf.insertParameter(0, newBaseAddress); }
*** 651,662 **** 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); // 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); --- 651,662 ---- 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.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,725 **** 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); // 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,725 ---- assert(pos <= lambdaForm.arity); assert(pos > 0); // cannot filter the MH arg itself assert(combinerType == combinerType.basicType()); assert(combinerType.returnType() != void.class || dropResult); ! 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,795 **** if (newType == V_TYPE) callFilter = null; else callFilter = new Name(constantZero(newType)); } else { ! BoundMethodHandle.SpeciesData oldData = oldSpeciesData(); ! BoundMethodHandle.SpeciesData 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,795 ---- if (newType == V_TYPE) callFilter = null; else callFilter = new Name(constantZero(newType)); } else { ! 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);