src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Cdiff src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java

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

Print this page
rev 10755 : 8058892: FILL_ARRAYS and ARRAYS are eagely initialized in MethodHandleImpl
Reviewed-by: ?

*** 592,601 **** --- 592,604 ---- * Factored in an inner class to delay initialization until first usage. */ static class Lazy { private static final Class<?> MHI = MethodHandleImpl.class; + private static final MethodHandle[] ARRAYS = makeArrays(); + private static final MethodHandle[] FILL_ARRAYS = makeFillArrays(); + static final NamedFunction NF_checkSpreadArgument; static final NamedFunction NF_guardWithCatch; static final NamedFunction NF_throwException; static final MethodHandle MH_castReference;
*** 1266,1276 **** mhs.add(mh); } assert(mhs.size() == 11); // current number of methods return mhs.toArray(new MethodHandle[MAX_ARITY+1]); } - private static final MethodHandle[] ARRAYS = makeArrays(); // filling versions of the above: // using Integer len instead of int len and no varargs to avoid bootstrapping problems private static Object[] fillNewArray(Integer len, Object[] /*not ...*/ args) { Object[] a = new Object[len]; --- 1269,1278 ----
*** 1313,1334 **** { fillWithArguments(a, pos, a0, a1, a2, a3, a4, a5, a6, a7, a8); return a; } private static Object[] fillArray(Integer pos, Object[] a, Object a0, Object a1, Object a2, Object a3, Object a4, Object a5, Object a6, Object a7, Object a8, Object a9) { fillWithArguments(a, pos, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); return a; } private static MethodHandle[] makeFillArrays() { ArrayList<MethodHandle> mhs = new ArrayList<>(); mhs.add(null); // there is no empty fill; at least a0 is required for (;;) { MethodHandle mh = findCollector("fillArray", mhs.size(), Object[].class, Integer.class, Object[].class); if (mh == null) break; mhs.add(mh); } ! assert(mhs.size() == 11); // current number of methods return mhs.toArray(new MethodHandle[0]); } - private static final MethodHandle[] FILL_ARRAYS = makeFillArrays(); private static Object copyAsPrimitiveArray(Wrapper w, Object... boxes) { Object a = w.makeArray(boxes.length); w.copyArrayUnboxing(boxes, 0, a, 0, boxes.length); return a; --- 1315,1338 ---- { fillWithArguments(a, pos, a0, a1, a2, a3, a4, a5, a6, a7, a8); return a; } private static Object[] fillArray(Integer pos, Object[] a, Object a0, Object a1, Object a2, Object a3, Object a4, Object a5, Object a6, Object a7, Object a8, Object a9) { fillWithArguments(a, pos, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); return a; } + + private static final int FILL_ARRAYS_COUNT = 11; // current number of fillArray methods + private static MethodHandle[] makeFillArrays() { ArrayList<MethodHandle> mhs = new ArrayList<>(); mhs.add(null); // there is no empty fill; at least a0 is required for (;;) { MethodHandle mh = findCollector("fillArray", mhs.size(), Object[].class, Integer.class, Object[].class); if (mh == null) break; mhs.add(mh); } ! assert(mhs.size() == FILL_ARRAYS_COUNT); return mhs.toArray(new MethodHandle[0]); } private static Object copyAsPrimitiveArray(Wrapper w, Object... boxes) { Object a = w.makeArray(boxes.length); w.copyArrayUnboxing(boxes, 0, a, 0, boxes.length); return a;
*** 1336,1354 **** /** Return a method handle that takes the indicated number of Object * arguments and returns an Object array of them, as if for varargs. */ static MethodHandle varargsArray(int nargs) { ! MethodHandle mh = ARRAYS[nargs]; if (mh != null) return mh; mh = findCollector("array", nargs, Object[].class); if (mh != null) mh = makeIntrinsic(mh, Intrinsic.NEW_ARRAY); ! if (mh != null) return ARRAYS[nargs] = mh; mh = buildVarargsArray(Lazy.MH_fillNewArray, Lazy.MH_arrayIdentity, nargs); assert(assertCorrectArity(mh, nargs)); mh = makeIntrinsic(mh, Intrinsic.NEW_ARRAY); ! return ARRAYS[nargs] = mh; } private static boolean assertCorrectArity(MethodHandle mh, int arity) { assert(mh.type().parameterCount() == arity) : "arity != "+arity+": "+mh; return true; --- 1340,1358 ---- /** Return a method handle that takes the indicated number of Object * arguments and returns an Object array of them, as if for varargs. */ static MethodHandle varargsArray(int nargs) { ! MethodHandle mh = Lazy.ARRAYS[nargs]; if (mh != null) return mh; mh = findCollector("array", nargs, Object[].class); if (mh != null) mh = makeIntrinsic(mh, Intrinsic.NEW_ARRAY); ! if (mh != null) return Lazy.ARRAYS[nargs] = mh; mh = buildVarargsArray(Lazy.MH_fillNewArray, Lazy.MH_arrayIdentity, nargs); assert(assertCorrectArity(mh, nargs)); mh = makeIntrinsic(mh, Intrinsic.NEW_ARRAY); ! return Lazy.ARRAYS[nargs] = mh; } private static boolean assertCorrectArity(MethodHandle mh, int arity) { assert(mh.type().parameterCount() == arity) : "arity != "+arity+": "+mh; return true;
*** 1380,1390 **** else mh = MethodHandles.collectArguments(mh, 0, leftCollector); return mh; } ! private static final int LEFT_ARGS = (FILL_ARRAYS.length - 1); private static final MethodHandle[] FILL_ARRAY_TO_RIGHT = new MethodHandle[MAX_ARITY+1]; /** fill_array_to_right(N).invoke(a, argL..arg[N-1]) * fills a[L]..a[N-1] with corresponding arguments, * and then returns a. The value L is a global constant (LEFT_ARGS). */ --- 1384,1394 ---- else mh = MethodHandles.collectArguments(mh, 0, leftCollector); return mh; } ! private static final int LEFT_ARGS = FILL_ARRAYS_COUNT - 1; private static final MethodHandle[] FILL_ARRAY_TO_RIGHT = new MethodHandle[MAX_ARITY+1]; /** fill_array_to_right(N).invoke(a, argL..arg[N-1]) * fills a[L]..a[N-1] with corresponding arguments, * and then returns a. The value L is a global constant (LEFT_ARGS). */
*** 1411,1421 **** } } if (midLen < LEFT_ARGS) rightLen = nargs - (midLen = LEFT_ARGS); assert(rightLen > 0); MethodHandle midFill = fillToRight(midLen); // recursive fill ! MethodHandle rightFill = FILL_ARRAYS[rightLen].bindTo(midLen); // [midLen..nargs-1] assert(midFill.type().parameterCount() == 1 + midLen - LEFT_ARGS); assert(rightFill.type().parameterCount() == 1 + rightLen); // Combine the two fills: // right(mid(a, x10..x19), x20..x23) --- 1415,1425 ---- } } if (midLen < LEFT_ARGS) rightLen = nargs - (midLen = LEFT_ARGS); assert(rightLen > 0); MethodHandle midFill = fillToRight(midLen); // recursive fill ! MethodHandle rightFill = Lazy.FILL_ARRAYS[rightLen].bindTo(midLen); // [midLen..nargs-1] assert(midFill.type().parameterCount() == 1 + midLen - LEFT_ARGS); assert(rightFill.type().parameterCount() == 1 + rightLen); // Combine the two fills: // right(mid(a, x10..x19), x20..x23)
src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File