src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java
Print this page
rev 10923 : 8062180: MethodHandleImpl.makeArrays throws and swallows java.lang.NoSuchFieldError in normal flow
Reviewed-by: duke
*** 1386,1405 ****
{ return makeArray(a0, a1, a2, a3, a4, a5, a6, a7, a8); }
private static Object[] array(Object a0, Object a1, Object a2, Object a3,
Object a4, Object a5, Object a6, Object a7,
Object a8, Object a9)
{ return makeArray(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); }
private static MethodHandle[] makeArrays() {
! ArrayList<MethodHandle> mhs = new ArrayList<>();
! for (;;) {
! MethodHandle mh = findCollector("array", mhs.size(), Object[].class);
if (mh == null) break;
mh = makeIntrinsic(mh, Intrinsic.NEW_ARRAY);
! mhs.add(mh);
}
! assert(mhs.size() == 11); // current number of methods
! return mhs.toArray(new MethodHandle[MAX_ARITY+1]);
}
// 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) {
--- 1386,1408 ----
{ return makeArray(a0, a1, a2, a3, a4, a5, a6, a7, a8); }
private static Object[] array(Object a0, Object a1, Object a2, Object a3,
Object a4, Object a5, Object a6, Object a7,
Object a8, Object a9)
{ return makeArray(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); }
+
+ private static final int ARRAYS_COUNT = 11;
+
private static MethodHandle[] makeArrays() {
! MethodHandle[] mhs = new MethodHandle[MAX_ARITY + 1];
! for (int i = 0; i < ARRAYS_COUNT; i++) {
! MethodHandle mh = findCollector("array", i, Object[].class);
if (mh == null) break;
mh = makeIntrinsic(mh, Intrinsic.NEW_ARRAY);
! mhs[i] = mh;
}
! assert(mhs[ARRAYS_COUNT - 1] != null); // current number of methods
! return mhs;
}
// 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) {
*** 1447,1465 ****
{ 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);
--- 1450,1468 ----
{ 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() {
! MethodHandle[] mhs = new MethodHandle[FILL_ARRAYS_COUNT];
! mhs[0] = null; // there is no empty fill; at least a0 is required
! for (int i = 1; i < FILL_ARRAYS_COUNT; i++) {
! MethodHandle mh = findCollector("fillArray", i, Object[].class, Integer.class, Object[].class);
if (mh == null) break;
! mhs[i] = mh;
}
! assert(mhs[FILL_ARRAYS_COUNT - 1] != null);
! return mhs;
}
private static Object copyAsPrimitiveArray(Wrapper w, Object... boxes) {
Object a = w.makeArray(boxes.length);
w.copyArrayUnboxing(boxes, 0, a, 0, boxes.length);
*** 1470,1482 ****
* 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;
}
--- 1473,1482 ----