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

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

Print this page
rev 10271 : 8037209: Improvements and cleanups to bytecode assembly for lambda forms
Reviewed-by: vlivanov, psandoz
Contributed-by: john.r.rose@oracle.com
rev 10272 : 8038261: JSR292: cache and reuse typed array accessors
Reviewed-by: vlivanov, psandoz
Contributed-by: john.r.rose@oracle.com
rev 10273 : 8049555: Move varargsArray from sun.invoke.util package to java.lang.invoke
Reviewed-by: ?
rev 10274 : 8050052: Small cleanups in java.lang.invoke code
Reviewed-by: ?

*** 532,542 **** static final NamedFunction NF_selectAlternative; static final NamedFunction NF_throwException; static final MethodHandle MH_castReference; static final MethodHandle MH_copyAsPrimitiveArray; - static final MethodHandle MH_copyAsReferenceArray; static final MethodHandle MH_fillNewTypedArray; static final MethodHandle MH_fillNewArray; static final MethodHandle MH_arrayIdentity; static { --- 532,541 ----
*** 555,566 **** MH_castReference = IMPL_LOOKUP.findStatic(MHI, "castReference", MethodType.methodType(Object.class, Class.class, Object.class)); MH_copyAsPrimitiveArray = IMPL_LOOKUP.findStatic(MHI, "copyAsPrimitiveArray", MethodType.methodType(Object.class, Wrapper.class, Object[].class)); - MH_copyAsReferenceArray = IMPL_LOOKUP.findStatic(MHI, "copyAsReferenceArray", - MethodType.methodType(Object[].class, Class.class, Object[].class)); MH_arrayIdentity = IMPL_LOOKUP.findStatic(MHI, "identity", MethodType.methodType(Object[].class, Object[].class)); MH_fillNewArray = IMPL_LOOKUP.findStatic(MHI, "fillNewArray", MethodType.methodType(Object[].class, Integer.class, Object[].class)); MH_fillNewTypedArray = IMPL_LOOKUP.findStatic(MHI, "fillNewTypedArray", --- 554,563 ----
*** 756,766 **** BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLLLL(); BoundMethodHandle mh; try { mh = (BoundMethodHandle) ! data.constructor[0].invokeBasic(type, form, (Object) target, (Object) exType, (Object) catcher, (Object) collectArgs, (Object) unboxResult); } catch (Throwable ex) { throw uncaughtException(ex); } assert(mh.type() == type); --- 753,763 ---- BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLLLL(); BoundMethodHandle mh; try { mh = (BoundMethodHandle) ! data.constructor().invokeBasic(type, form, (Object) target, (Object) exType, (Object) catcher, (Object) collectArgs, (Object) unboxResult); } catch (Throwable ex) { throw uncaughtException(ex); } assert(mh.type() == type);
*** 1093,1102 **** --- 1090,1100 ---- fillWithArguments(a, 0, args); return a; } private static Object[] fillNewTypedArray(Object[] example, Integer len, Object[] /*not ...*/ args) { Object[] a = Arrays.copyOf(example, len); + assert(a.getClass() != Object[].class); fillWithArguments(a, 0, args); return a; } private static void fillWithArguments(Object[] a, int pos, Object... args) { System.arraycopy(args, 0, a, pos, args.length);
*** 1141,1153 **** assert(mhs.size() == 11); // current number of methods return mhs.toArray(new MethodHandle[0]); } private static final MethodHandle[] FILL_ARRAYS = makeFillArrays(); - private static Object[] copyAsReferenceArray(Class<? extends Object[]> arrayType, Object... a) { - return Arrays.copyOf(a, a.length, arrayType); - } private static Object copyAsPrimitiveArray(Wrapper w, Object... boxes) { Object a = w.makeArray(boxes.length); w.copyArrayUnboxing(boxes, 0, a, 0, boxes.length); return a; } --- 1139,1148 ----
*** 1263,1293 **** if (elemType == null) throw new IllegalArgumentException("not an array: "+arrayType); // FIXME: Need more special casing and caching here. if (nargs >= MAX_JVM_ARITY/2 - 1) { int slots = nargs; final int MAX_ARRAY_SLOTS = MAX_JVM_ARITY - 1; // 1 for receiver MH ! if (arrayType == double[].class || arrayType == long[].class) ! slots *= 2; if (slots > MAX_ARRAY_SLOTS) throw new IllegalArgumentException("too many arguments: "+arrayType.getSimpleName()+", length "+nargs); } if (elemType == Object.class) return varargsArray(nargs); // other cases: primitive arrays, subtypes of Object[] MethodHandle cache[] = TYPED_COLLECTORS.get(elemType); MethodHandle mh = nargs < cache.length ? cache[nargs] : null; if (mh != null) return mh; ! if (elemType.isPrimitive()) { MethodHandle builder = Lazy.MH_fillNewArray; MethodHandle producer = buildArrayProducer(arrayType); mh = buildVarargsArray(builder, producer, nargs); } else { ! @SuppressWarnings("unchecked") ! Class<? extends Object[]> objArrayType = (Class<? extends Object[]>) arrayType; Object[] example = Arrays.copyOf(NO_ARGS_ARRAY, 0, objArrayType); MethodHandle builder = Lazy.MH_fillNewTypedArray.bindTo(example); ! MethodHandle producer = Lazy.MH_arrayIdentity; mh = buildVarargsArray(builder, producer, nargs); } mh = mh.asType(MethodType.methodType(arrayType, Collections.<Class<?>>nCopies(nargs, elemType))); assert(assertCorrectArity(mh, nargs)); if (nargs < cache.length) --- 1258,1290 ---- if (elemType == null) throw new IllegalArgumentException("not an array: "+arrayType); // FIXME: Need more special casing and caching here. if (nargs >= MAX_JVM_ARITY/2 - 1) { int slots = nargs; final int MAX_ARRAY_SLOTS = MAX_JVM_ARITY - 1; // 1 for receiver MH ! if (slots <= MAX_ARRAY_SLOTS && elemType.isPrimitive()) ! slots *= Wrapper.forPrimitiveType(elemType).stackSlots(); if (slots > MAX_ARRAY_SLOTS) throw new IllegalArgumentException("too many arguments: "+arrayType.getSimpleName()+", length "+nargs); } if (elemType == Object.class) return varargsArray(nargs); // other cases: primitive arrays, subtypes of Object[] MethodHandle cache[] = TYPED_COLLECTORS.get(elemType); MethodHandle mh = nargs < cache.length ? cache[nargs] : null; if (mh != null) return mh; ! if (nargs == 0) { ! Object example = java.lang.reflect.Array.newInstance(arrayType.getComponentType(), 0); ! mh = MethodHandles.constant(arrayType, example); ! } else if (elemType.isPrimitive()) { MethodHandle builder = Lazy.MH_fillNewArray; MethodHandle producer = buildArrayProducer(arrayType); mh = buildVarargsArray(builder, producer, nargs); } else { ! Class<? extends Object[]> objArrayType = arrayType.asSubclass(Object[].class); Object[] example = Arrays.copyOf(NO_ARGS_ARRAY, 0, objArrayType); MethodHandle builder = Lazy.MH_fillNewTypedArray.bindTo(example); ! MethodHandle producer = Lazy.MH_arrayIdentity; // must be weakly typed mh = buildVarargsArray(builder, producer, nargs); } mh = mh.asType(MethodType.methodType(arrayType, Collections.<Class<?>>nCopies(nargs, elemType))); assert(assertCorrectArity(mh, nargs)); if (nargs < cache.length)
*** 1295,1305 **** return mh; } private static MethodHandle buildArrayProducer(Class<?> arrayType) { Class<?> elemType = arrayType.getComponentType(); ! if (elemType.isPrimitive()) return Lazy.MH_copyAsPrimitiveArray.bindTo(Wrapper.forPrimitiveType(elemType)); - else - return Lazy.MH_copyAsReferenceArray.bindTo(arrayType); } } --- 1292,1300 ---- return mh; } private static MethodHandle buildArrayProducer(Class<?> arrayType) { Class<?> elemType = arrayType.getComponentType(); ! assert(elemType.isPrimitive()); return Lazy.MH_copyAsPrimitiveArray.bindTo(Wrapper.forPrimitiveType(elemType)); } }
src/share/classes/java/lang/invoke/MethodHandleImpl.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File