--- old/src/share/classes/java/lang/invoke/MethodType.java 2013-09-26 18:36:11.824421724 +0400 +++ new/src/share/classes/java/lang/invoke/MethodType.java 2013-09-26 18:36:11.680421716 +0400 @@ -32,6 +32,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentHashMap; import sun.invoke.util.BytecodeDescriptor; @@ -97,14 +98,24 @@ private MethodTypeForm form; // erased form, plus cached data about primitives private MethodType wrapAlt; // alternative wrapped/unwrapped version private Invokers invokers; // cache of handy higher-order adapters + private String methodDescriptor; /** * Check the given parameters for validity and store them into the final fields. */ - private MethodType(Class rtype, Class[] ptypes) { + private MethodType(Class rtype, Class[] ptypes, boolean trusted) { checkRtype(rtype); checkPtypes(ptypes); this.rtype = rtype; + // defensively copy the array passed in by the user + this.ptypes = trusted ? ptypes : Arrays.copyOf(ptypes, ptypes.length); + } + + /** + * Don't check the given parameters for validity - creates MethodType for usage as searching key only. + */ + private MethodType(Class rtype, Class[] ptypes) { + this.rtype = rtype; this.ptypes = ptypes; } @@ -145,10 +156,10 @@ /*non-public*/ static final int MAX_MH_INVOKER_ARITY = MAX_MH_ARITY-1; // deduct one more for invoker private static void checkRtype(Class rtype) { - rtype.equals(rtype); // null check + Objects.requireNonNull(rtype); // null check } private static int checkPtype(Class ptype) { - ptype.getClass(); //NPE + Objects.requireNonNull(ptype); // null check if (ptype == void.class) throw newIllegalArgumentException("parameter type cannot be void"); if (ptype == double.class || ptype == long.class) return 1; @@ -283,20 +294,16 @@ */ /*trusted*/ static MethodType makeImpl(Class rtype, Class[] ptypes, boolean trusted) { + MethodType mt = internTable.get(new MethodType(rtype, ptypes)); + if (mt != null) + return mt; if (ptypes.length == 0) { ptypes = NO_PTYPES; trusted = true; } - MethodType mt1 = new MethodType(rtype, ptypes); - MethodType mt0 = internTable.get(mt1); - if (mt0 != null) - return mt0; - if (!trusted) - // defensively copy the array passed in by the user - mt1 = new MethodType(rtype, ptypes.clone()); + mt = new MethodType(rtype, ptypes, trusted); // promote the object to the Real Thing, and reprobe - MethodTypeForm form = MethodTypeForm.findForm(mt1); - mt1.form = form; - return internTable.add(mt1); + mt.form = MethodTypeForm.findForm(mt); + return internTable.add(mt); } private static final MethodType[] objectOnlyTypes = new MethodType[20]; @@ -918,7 +925,12 @@ * @return the bytecode type descriptor representation */ public String toMethodDescriptorString() { - return BytecodeDescriptor.unparse(this); + String desc = methodDescriptor; + if (desc == null) { + desc = BytecodeDescriptor.unparse(this); + methodDescriptor = desc; + } + return desc; } /*non-public*/ static String toFieldDescriptorString(Class cls) {