< prev index next >

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

Print this page
rev 52204 : 8212726: Replace some use of drop- and foldArguments with filtering argument combinator in StringConcatFactory
Reviewed-by: TBD

*** 83,93 **** FOLD_ARGS = 11, FOLD_ARGS_TO_VOID = 12, PERMUTE_ARGS = 13, LOCAL_TYPES = 14, FOLD_SELECT_ARGS = 15, ! FOLD_SELECT_ARGS_TO_VOID = 16; private static final boolean STRESS_TEST = false; // turn on to disable most packing private static final int PACKED_BYTE_SIZE = (STRESS_TEST ? 2 : 4), PACKED_BYTE_MASK = (1 << PACKED_BYTE_SIZE) - 1, --- 83,94 ---- FOLD_ARGS = 11, FOLD_ARGS_TO_VOID = 12, PERMUTE_ARGS = 13, LOCAL_TYPES = 14, FOLD_SELECT_ARGS = 15, ! FOLD_SELECT_ARGS_TO_VOID = 16, ! FILTER_SELECT_ARGS = 17; private static final boolean STRESS_TEST = false; // turn on to disable most packing private static final int PACKED_BYTE_SIZE = (STRESS_TEST ? 2 : 4), PACKED_BYTE_MASK = (1 << PACKED_BYTE_SIZE) - 1,
*** 728,768 **** buf.renameParameter(0, newBaseAddress); Name getCombiner = new Name(newData.getterFunction(oldData.fieldCount()), newBaseAddress); Object[] combinerArgs = new Object[1 + combinerArity]; combinerArgs[0] = getCombiner; ! Name[] newParams; if (keepArguments) { - newParams = new Name[0]; for (int i = 0; i < combinerArity; i++) { combinerArgs[i + 1] = lambdaForm.parameter(1 + argPositions[i]); assert (basicType(combinerType.parameterType(i)) == lambdaForm.parameterType(1 + argPositions[i])); } } else { ! newParams = new Name[combinerArity]; ! for (int i = 0; i < newParams.length; i++) { ! newParams[i] = lambdaForm.parameter(1 + argPositions[i]); assert (basicType(combinerType.parameterType(i)) == lambdaForm.parameterType(1 + argPositions[i])); } - System.arraycopy(newParams, 0, - combinerArgs, 1, combinerArity); } Name callCombiner = new Name(combinerType, combinerArgs); // insert the two new expressions int exprPos = lambdaForm.arity(); buf.insertExpression(exprPos+0, getCombiner); buf.insertExpression(exprPos+1, callCombiner); // insert new arguments, if needed int argPos = pos + resultArity; // skip result parameter ! for (Name newParam : newParams) { buf.insertParameter(argPos++, newParam); } ! assert(buf.lastIndexOf(callCombiner) == exprPos+1+newParams.length); if (!dropResult) { ! buf.replaceParameterByCopy(pos, exprPos+1+newParams.length); } return buf.endEdit(); } --- 729,772 ---- buf.renameParameter(0, newBaseAddress); Name getCombiner = new Name(newData.getterFunction(oldData.fieldCount()), newBaseAddress); Object[] combinerArgs = new Object[1 + combinerArity]; combinerArgs[0] = getCombiner; ! Name newParam = null; if (keepArguments) { for (int i = 0; i < combinerArity; i++) { combinerArgs[i + 1] = lambdaForm.parameter(1 + argPositions[i]); assert (basicType(combinerType.parameterType(i)) == lambdaForm.parameterType(1 + argPositions[i])); } } else { ! newParam = new Name(pos, BasicType.basicType(combinerType.returnType())); ! for (int i = 0; i < combinerArity; i++) { ! int argPos = 1 + argPositions[i]; ! if (argPos == pos) { ! combinerArgs[i + 1] = newParam; ! } else { ! combinerArgs[i + 1] = lambdaForm.parameter(argPos); ! } assert (basicType(combinerType.parameterType(i)) == lambdaForm.parameterType(1 + argPositions[i])); } } Name callCombiner = new Name(combinerType, combinerArgs); // insert the two new expressions int exprPos = lambdaForm.arity(); buf.insertExpression(exprPos+0, getCombiner); buf.insertExpression(exprPos+1, callCombiner); // insert new arguments, if needed int argPos = pos + resultArity; // skip result parameter ! if (newParam != null) { buf.insertParameter(argPos++, newParam); + exprPos++; } ! assert(buf.lastIndexOf(callCombiner) == exprPos+1); if (!dropResult) { ! buf.replaceParameterByCopy(pos, exprPos+1); } return buf.endEdit(); }
*** 843,852 **** --- 847,870 ---- } form = makeArgumentCombinationForm(foldPos, combinerType, argPositions, true, dropResult); return putInCache(key, form); } + LambdaForm filterArgumentsForm(int filterPos, MethodType combinerType, int ... argPositions) { + byte kind = Transform.FILTER_SELECT_ARGS; + int[] keyArgs = Arrays.copyOf(argPositions, argPositions.length + 1); + keyArgs[argPositions.length] = filterPos; + Transform key = Transform.of(kind, keyArgs); + LambdaForm form = getInCache(key); + if (form != null) { + assert(form.arity == lambdaForm.arity); + return form; + } + form = makeArgumentCombinationForm(filterPos, combinerType, argPositions, false, false); + return putInCache(key, form); + } + LambdaForm permuteArgumentsForm(int skip, int[] reorder) { assert(skip == 1); // skip only the leading MH argument, names[0] int length = lambdaForm.names.length; int outArgs = reorder.length; int inTypes = 0;
< prev index next >