--- old/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java 2014-10-17 13:54:29.388912404 -0400 +++ new/src/java.base/share/classes/java/lang/invoke/DirectMethodHandle.java 2014-10-17 13:54:29.220906462 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -109,10 +109,10 @@ return make(member.getDeclaringClass(), member); } static DirectMethodHandle make(Method method) { - return make(method.getDeclaringClass(), new MemberName(method)); + return make(method.getDeclaringClass(), MemberName.make(method)); } static DirectMethodHandle make(Field field) { - return make(field.getDeclaringClass(), new MemberName(field)); + return make(field.getDeclaringClass(), MemberName.make(field)); } private static DirectMethodHandle makeAllocator(MemberName ctor) { assert(ctor.isConstructor() && ctor.getName().equals("")); --- old/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java 2014-10-17 13:54:29.388912404 -0400 +++ new/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java 2014-10-17 13:54:29.220906462 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -286,14 +286,11 @@ private static MemberName resolveInvokerMember(Class invokerClass, String name, MethodType type) { MemberName member = new MemberName(invokerClass, name, type, REF_invokeStatic); - //System.out.println("resolveInvokerMember => "+member); - //for (Method m : invokerClass.getDeclaredMethods()) System.out.println(" "+m); try { member = MEMBERNAME_FACTORY.resolveOrFail(REF_invokeStatic, member, HOST_CLASS, ReflectiveOperationException.class); } catch (ReflectiveOperationException e) { throw newInternalError(e); } - //System.out.println("resolveInvokerMember => "+member); return member; } --- old/src/java.base/share/classes/java/lang/invoke/LambdaForm.java 2014-10-17 13:54:29.388912404 -0400 +++ new/src/java.base/share/classes/java/lang/invoke/LambdaForm.java 2014-10-17 13:54:29.220906462 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1017,10 +1017,10 @@ // This is OK, since all such LFs are prepared with special primitive vmentry points. // And even without the resolvedHandle, the name can still be compiled and optimized. NamedFunction(Method method) { - this(new MemberName(method)); + this(MemberName.make(method)); } NamedFunction(Field field) { - this(new MemberName(field)); + this(MemberName.make(field)); } NamedFunction(MemberName member) { this.member = member; --- old/src/java.base/share/classes/java/lang/Class.java 2014-10-17 13:54:29.388912404 -0400 +++ new/src/java.base/share/classes/java/lang/Class.java 2014-10-17 13:54:29.216906321 -0400 @@ -67,8 +67,10 @@ import sun.reflect.generics.repository.ConstructorRepository; import sun.reflect.generics.scope.ClassScope; import sun.security.util.SecurityConstants; + import java.lang.annotation.Annotation; import java.lang.reflect.Proxy; + import sun.reflect.annotation.*; import sun.reflect.misc.ReflectUtil; @@ -2462,6 +2464,122 @@ } /** + * ClassData + */ + private static class ClassData { + /** + * This needs to be a simple data structure because we need to access and update its elements from the JVM. + */ + private Comparable[] elementData; + private int size; + + /** + * Interns a member name in the member name table. + * + * @param memberName member name to be interned + * @return + */ + @SuppressWarnings({"unchecked","rawtypes"}) + public > E intern(E memberName) { + if (elementData == null) { + synchronized (this) { + if (elementData == null) { + elementData = new Comparable[1]; + } + } + } + synchronized (elementData) { +// for (int i = 0; i < size; i++) { +// Object element = elementData[i]; +// if (memberName.equals(element)) { +// return (E) element; +// } +// } +// add(memberName); + + final int index = Arrays.binarySearch(elementData, 0, size, memberName); + if (index >= 0) { + return (E) elementData[index]; + } + // Not found, add and sort. + add(memberName); + Arrays.parallelSort((E[]) elementData, 0, size); + } + return memberName; + } + + /* + * The following methods are taken from java.util.ArrayList to grow our inlined array. + */ + + /** + * Appends the specified element to the end of this list. + * + * @param e element to be appended to this list + * @return {@code true} (as specified by {@link Collection#add}) + */ + private void add(Object e) { + ensureCapacityInternal(size + 1); // Increments modCount!! + elementData[size++] = (Comparable) e; + } + + /** + * Default initial capacity. + */ + private static final int DEFAULT_CAPACITY = 10; + + private void ensureCapacityInternal(int minCapacity) { + if (elementData == null) { + minCapacity = Math.max(DEFAULT_CAPACITY, minCapacity); + } + ensureExplicitCapacity(minCapacity); + } + + private void ensureExplicitCapacity(int minCapacity) { + // overflow-conscious code + if (minCapacity - elementData.length > 0) + grow(minCapacity); + } + + /** + * Increases the capacity to ensure that it can hold at least the + * number of elements specified by the minimum capacity argument. + * + * @param minCapacity the desired minimum capacity + */ + private void grow(int minCapacity) { + // overflow-conscious code + int oldCapacity = elementData.length; + int newCapacity = oldCapacity + (oldCapacity >> 1); + if (newCapacity - minCapacity < 0) + newCapacity = minCapacity; + // minCapacity is usually close to size, so this is a win: + elementData = Arrays.copyOf(elementData, newCapacity); + } + } + + private volatile transient ClassData classData; + + /** + * Lazily create {@link ClassData}. + */ + private ClassData classData() { + if (this.classData != null) { + return this.classData; + } + synchronized (this) { + if (this.classData == null) { + this.classData = new ClassData(); + } + } + return this.classData; + } + + public > E internMemberName(E memberName) { + return classData().intern(memberName); + } + + /** * Reflection support. */ --- old/src/java.base/share/classes/java/lang/invoke/MemberName.java 2014-10-17 13:54:29.388912404 -0400 +++ new/src/java.base/share/classes/java/lang/invoke/MemberName.java 2014-10-17 13:54:29.220906462 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -38,8 +38,10 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; + import static java.lang.invoke.MethodHandleNatives.Constants.*; import static java.lang.invoke.MethodHandleStatics.*; + import java.util.Objects; /** @@ -69,7 +71,8 @@ * and those seven fields omit much of the information in Method. * @author jrose */ -/*non-public*/ final class MemberName implements Member, Cloneable { +@SuppressWarnings("rawtypes") //Comparable in next line +/*non-public*/ final class MemberName implements Member, Comparable, Cloneable { private Class clazz; // class in which the method is defined private String name; // may be null if not yet materialized private Object type; // may be null if not yet materialized @@ -78,6 +81,204 @@ //@Injected int vmindex; private Object resolution; // if null, this guy is resolved + // bare-bones constructor; the JVM will fill it in + MemberName() { } + + /** Create a name for the given class. The resulting name will be in a resolved state. */ + public MemberName(Class type) { + init(type.getDeclaringClass(), type.getSimpleName(), type, + flagsMods(IS_TYPE, type.getModifiers(), REF_NONE)); + initResolved(true); + } + + // Construction from symbolic parts, for queries: + /** Create a field or type name from the given components: + * Declaring class, name, type, reference kind. + * The declaring class may be supplied as null if this is to be a bare name and type. + * The resulting name will in an unresolved state. + */ + public MemberName(Class defClass, String name, Class type, byte refKind) { + init(defClass, name, type, flagsMods(IS_FIELD, 0, refKind)); + initResolved(false); + } + + /** Create a field or type name from the given components: Declaring class, name, type. + * The declaring class may be supplied as null if this is to be a bare name and type. + * The modifier flags default to zero. + * The resulting name will in an unresolved state. + */ + public MemberName(Class defClass, String name, Class type, Void unused) { + this(defClass, name, type, REF_NONE); + initResolved(false); + } + + /** Create a method or constructor name from the given components: Declaring class, name, type, modifiers. + * It will be a constructor if and only if the name is {@code "<init>"}. + * The declaring class may be supplied as null if this is to be a bare name and type. + * The last argument is optional, a boolean which requests REF_invokeSpecial. + * The resulting name will in an unresolved state. + */ + public MemberName(Class defClass, String name, MethodType type, byte refKind) { + int initFlags = (name != null && name.equals(CONSTRUCTOR_NAME) ? IS_CONSTRUCTOR : IS_METHOD); + init(defClass, name, type, flagsMods(initFlags, 0, refKind)); + initResolved(false); + } + + /** Create a method, constructor, or field name from the given components: + * Reference kind, declaring class, name, type. + */ + public MemberName(byte refKind, Class defClass, String name, Object type) { + int kindFlags; + if (MethodHandleNatives.refKindIsField(refKind)) { + kindFlags = IS_FIELD; + if (!(type instanceof Class)) + throw newIllegalArgumentException("not a field type"); + } else if (MethodHandleNatives.refKindIsMethod(refKind)) { + kindFlags = IS_METHOD; + if (!(type instanceof MethodType)) + throw newIllegalArgumentException("not a method type"); + } else if (refKind == REF_newInvokeSpecial) { + kindFlags = IS_CONSTRUCTOR; + if (!(type instanceof MethodType) || + !CONSTRUCTOR_NAME.equals(name)) + throw newIllegalArgumentException("not a constructor type or name"); + } else { + throw newIllegalArgumentException("bad reference kind "+refKind); + } + init(defClass, name, type, flagsMods(kindFlags, 0, refKind)); + initResolved(false); + } + + /** Create a name for the given reflected method. The resulting name will be in a resolved state. */ + public static MemberName make(Method m) { + return make(m, false); + } + + @SuppressWarnings("LeakingThisInConstructor") + private MemberName(Method m, boolean wantSpecial) { + m.getClass(); // NPE check + // fill in vmtarget, vmindex while we have m in hand: + MethodHandleNatives.init(this, m); + if (clazz == null) { // MHN.init failed + if (m.getDeclaringClass() == MethodHandle.class && + isMethodHandleInvokeName(m.getName())) { + // The JVM did not reify this signature-polymorphic instance. + // Need a special case here. + // See comments on MethodHandleNatives.linkMethod. + MethodType type = MethodType.methodType(m.getReturnType(), m.getParameterTypes()); + int flags = flagsMods(IS_METHOD, m.getModifiers(), REF_invokeVirtual); + init(MethodHandle.class, m.getName(), type, flags); + if (isMethodHandleInvoke()) { + return; + } + } + throw new LinkageError(m.toString()); + } + assert(isResolved() && this.clazz != null); + this.name = m.getName(); + if (this.type == null) { + this.type = new Object[] { m.getReturnType(), m.getParameterTypes() }; + } + if (wantSpecial) { + if (isAbstract()) { + throw new AbstractMethodError(this.toString()); + } + if (getReferenceKind() == REF_invokeVirtual) { + changeReferenceKind(REF_invokeSpecial, REF_invokeVirtual); + } else if (getReferenceKind() == REF_invokeInterface) { + // invokeSpecial on a default method + changeReferenceKind(REF_invokeSpecial, REF_invokeInterface); + } + } + } + + public static MemberName make(Method m, boolean wantSpecial) { + MemberName tmp = new MemberName(m, wantSpecial); + // Unreflected member names are resolved so intern them here. + return tmp.intern(); + } + + /** + * Create a name for the given reflected constructor. The resulting name + * will be in a resolved state. + */ + @SuppressWarnings("LeakingThisInConstructor") + private MemberName(Constructor ctor) { + ctor.getClass(); // NPE check + // fill in vmtarget, vmindex while we have ctor in hand: + MethodHandleNatives.init(this, ctor); + assert(isResolved() && this.clazz != null); + this.name = CONSTRUCTOR_NAME; + if (this.type == null) { + this.type = new Object[] { void.class, ctor.getParameterTypes() }; + } + } + + static public MemberName make(Constructor ctor) { + MemberName tmp = new MemberName(ctor); + // Unreflected member names are resolved so intern them here. + return tmp.intern(); + } + + + /** Create a name for the given reflected field. The resulting name will be in a resolved state. + */ + public static MemberName make(Field field) { + return make(field, false); + } + + @SuppressWarnings("LeakingThisInConstructor") + private MemberName(Field field, boolean makeSetter) { + field.getClass(); // NPE check + // fill in vmtarget, vmindex while we have field in hand: + MethodHandleNatives.init(this, field); + assert(isResolved() && this.clazz != null); + this.name = field.getName(); + this.type = field.getType(); + byte refKind = this.getReferenceKind(); + assert(refKind == (isStatic() ? REF_getStatic : REF_getField)); + if (makeSetter) { + assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField)); + changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind); + } + } + + static public MemberName make(Field field, boolean makeSetter) { + MemberName tmp = new MemberName(field, makeSetter); + // Unreflected member names are resolved so intern them here. + return tmp.intern(); + } + + /** Initialize a query. It is not resolved. */ + private void init(Class defClass, String name, Object type, int flags) { + // defining class is allowed to be null (for a naked name/type pair) + //name.toString(); // null check + //type.equals(type); // null check + // fill in fields: + this.clazz = defClass; + this.name = name; + this.type = type; + this.flags = flags; + assert(testAnyFlags(ALL_KINDS)); + assert(this.resolution == null); // nobody should have touched this yet + //assert(referenceKindIsConsistent()); // do this after resolution + } + + private void initResolved(boolean isResolved) { + assert(this.resolution == null); // not initialized yet! + if (!isResolved) + this.resolution = this; + assert(isResolved() == isResolved); + } + + /** + * Helper method to intern this member name in the declaring class' member name table. + */ + @SuppressWarnings("unchecked") + private MemberName intern() { + return clazz.internMemberName(this); + } + /** Return the declaring class of this member. * In the case of a bare name and type, the declaring class will be null. */ @@ -479,21 +680,6 @@ lookupClass, ALL_ACCESS|MethodHandles.Lookup.PACKAGE); } - /** Initialize a query. It is not resolved. */ - private void init(Class defClass, String name, Object type, int flags) { - // defining class is allowed to be null (for a naked name/type pair) - //name.toString(); // null check - //type.equals(type); // null check - // fill in fields: - this.clazz = defClass; - this.name = name; - this.type = type; - this.flags = flags; - assert(testAnyFlags(ALL_KINDS)); - assert(this.resolution == null); // nobody should have touched this yet - //assert(referenceKindIsConsistent()); // do this after resolution - } - /** * Calls down to the VM to fill in the fields. This method is * synchronized to avoid racing calls. @@ -515,43 +701,6 @@ assert((refKind & ~MN_REFERENCE_KIND_MASK) == 0); return flags | mods | (refKind << MN_REFERENCE_KIND_SHIFT); } - /** Create a name for the given reflected method. The resulting name will be in a resolved state. */ - public MemberName(Method m) { - this(m, false); - } - @SuppressWarnings("LeakingThisInConstructor") - public MemberName(Method m, boolean wantSpecial) { - m.getClass(); // NPE check - // fill in vmtarget, vmindex while we have m in hand: - MethodHandleNatives.init(this, m); - if (clazz == null) { // MHN.init failed - if (m.getDeclaringClass() == MethodHandle.class && - isMethodHandleInvokeName(m.getName())) { - // The JVM did not reify this signature-polymorphic instance. - // Need a special case here. - // See comments on MethodHandleNatives.linkMethod. - MethodType type = MethodType.methodType(m.getReturnType(), m.getParameterTypes()); - int flags = flagsMods(IS_METHOD, m.getModifiers(), REF_invokeVirtual); - init(MethodHandle.class, m.getName(), type, flags); - if (isMethodHandleInvoke()) - return; - } - throw new LinkageError(m.toString()); - } - assert(isResolved() && this.clazz != null); - this.name = m.getName(); - if (this.type == null) - this.type = new Object[] { m.getReturnType(), m.getParameterTypes() }; - if (wantSpecial) { - if (isAbstract()) - throw new AbstractMethodError(this.toString()); - if (getReferenceKind() == REF_invokeVirtual) - changeReferenceKind(REF_invokeSpecial, REF_invokeVirtual); - else if (getReferenceKind() == REF_invokeInterface) - // invokeSpecial on a default method - changeReferenceKind(REF_invokeSpecial, REF_invokeInterface); - } - } public MemberName asSpecial() { switch (getReferenceKind()) { case REF_invokeSpecial: return this; @@ -597,37 +746,6 @@ assert(this.referenceKindIsConsistentWith(result.getReferenceKind())); return result; } - /** Create a name for the given reflected constructor. The resulting name will be in a resolved state. */ - @SuppressWarnings("LeakingThisInConstructor") - public MemberName(Constructor ctor) { - ctor.getClass(); // NPE check - // fill in vmtarget, vmindex while we have ctor in hand: - MethodHandleNatives.init(this, ctor); - assert(isResolved() && this.clazz != null); - this.name = CONSTRUCTOR_NAME; - if (this.type == null) - this.type = new Object[] { void.class, ctor.getParameterTypes() }; - } - /** Create a name for the given reflected field. The resulting name will be in a resolved state. - */ - public MemberName(Field fld) { - this(fld, false); - } - @SuppressWarnings("LeakingThisInConstructor") - public MemberName(Field fld, boolean makeSetter) { - fld.getClass(); // NPE check - // fill in vmtarget, vmindex while we have fld in hand: - MethodHandleNatives.init(this, fld); - assert(isResolved() && this.clazz != null); - this.name = fld.getName(); - this.type = fld.getType(); - assert((REF_putStatic - REF_getStatic) == (REF_putField - REF_getField)); - byte refKind = this.getReferenceKind(); - assert(refKind == (isStatic() ? REF_getStatic : REF_getField)); - if (makeSetter) { - changeReferenceKind((byte)(refKind + (REF_putStatic - REF_getStatic)), refKind); - } - } public boolean isGetter() { return MethodHandleNatives.refKindIsGetter(getReferenceKind()); } @@ -641,13 +759,6 @@ byte setterRefKind = (byte)(refKind + (REF_putField - REF_getField)); return clone().changeReferenceKind(setterRefKind, refKind); } - /** Create a name for the given class. The resulting name will be in a resolved state. */ - public MemberName(Class type) { - init(type.getDeclaringClass(), type.getSimpleName(), type, - flagsMods(IS_TYPE, type.getModifiers(), REF_NONE)); - initResolved(true); - } - /** * Create a name for a signature-polymorphic invoker. * This is a placeholder for a signature-polymorphic instance @@ -664,9 +775,6 @@ return mem; } - // bare-bones constructor; the JVM will fill it in - MemberName() { } - // locally useful cloner @Override protected MemberName clone() { try { @@ -715,51 +823,39 @@ && Objects.equals(this.getType(), that.getType()); } - // Construction from symbolic parts, for queries: - /** Create a field or type name from the given components: - * Declaring class, name, type, reference kind. - * The declaring class may be supplied as null if this is to be a bare name and type. - * The resulting name will in an unresolved state. - */ - public MemberName(Class defClass, String name, Class type, byte refKind) { - init(defClass, name, type, flagsMods(IS_FIELD, 0, refKind)); - initResolved(false); - } - /** Create a method or constructor name from the given components: - * Declaring class, name, type, reference kind. - * It will be a constructor if and only if the name is {@code "<init>"}. - * The declaring class may be supplied as null if this is to be a bare name and type. - * The last argument is optional, a boolean which requests REF_invokeSpecial. - * The resulting name will in an unresolved state. - */ - public MemberName(Class defClass, String name, MethodType type, byte refKind) { - int initFlags = (name != null && name.equals(CONSTRUCTOR_NAME) ? IS_CONSTRUCTOR : IS_METHOD); - init(defClass, name, type, flagsMods(initFlags, 0, refKind)); - initResolved(false); - } - /** Create a method, constructor, or field name from the given components: - * Reference kind, declaring class, name, type. - */ - public MemberName(byte refKind, Class defClass, String name, Object type) { - int kindFlags; - if (MethodHandleNatives.refKindIsField(refKind)) { - kindFlags = IS_FIELD; - if (!(type instanceof Class)) - throw newIllegalArgumentException("not a field type"); - } else if (MethodHandleNatives.refKindIsMethod(refKind)) { - kindFlags = IS_METHOD; - if (!(type instanceof MethodType)) - throw newIllegalArgumentException("not a method type"); - } else if (refKind == REF_newInvokeSpecial) { - kindFlags = IS_CONSTRUCTOR; - if (!(type instanceof MethodType) || - !CONSTRUCTOR_NAME.equals(name)) - throw newIllegalArgumentException("not a constructor type or name"); - } else { - throw newIllegalArgumentException("bad reference kind "+refKind); + @Override + public int compareTo(Object o) { + MemberName that = (MemberName) o; + + /* First try an equals. This make the ordering checks easier because we + * don't have to be precise and can use hash codes. + */ + if (equals(that)) { + return 0; } - init(defClass, name, type, flagsMods(kindFlags, 0, refKind)); - initResolved(false); + + final int clazzDiff = this.clazz.hashCode() - that.clazz.hashCode(); + if (clazzDiff != 0) { + return clazzDiff; + } + + final int kindDiff = this.getReferenceKind() - that.getReferenceKind(); + if (kindDiff != 0) { + return kindDiff; + } + + final int nameDiff = this.name.hashCode() - that.name.hashCode(); + if (nameDiff != 0) { + return nameDiff; + } + + final int typeDiff = this.getType().hashCode() - that.getType().hashCode(); + if (typeDiff != 0) { + return typeDiff; + } + + // In the unlikely case all values above are equal we just return 1. + return 1; } /** Query whether this member name is resolved to a non-static, non-final method. */ @@ -776,13 +872,6 @@ return resolution == null; } - private void initResolved(boolean isResolved) { - assert(this.resolution == null); // not initialized yet! - if (!isResolved) - this.resolution = this; - assert(isResolved() == isResolved); - } - void checkForTypeAlias() { if (isInvocable()) { MethodType type; @@ -962,6 +1051,7 @@ m = MethodHandleNatives.resolve(m, lookupClass); m.checkForTypeAlias(); m.resolution = null; + m.intern(); } catch (LinkageError ex) { // JVM reports that the "bytecode behavior" would get an error assert(!m.isResolved()); @@ -1069,9 +1159,4 @@ return buf; } } - -// static { -// System.out.println("Hello world! My methods are:"); -// System.out.println(Factory.INSTANCE.getMethods(MemberName.class, true, null)); -// } } --- old/src/java.base/share/classes/java/lang/invoke/InfoFromMemberName.java 2014-10-17 13:54:29.388912404 -0400 +++ new/src/java.base/share/classes/java/lang/invoke/InfoFromMemberName.java 2014-10-17 13:54:29.220906462 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -133,12 +133,12 @@ private static MemberName convertToMemberName(byte refKind, Member mem) throws IllegalAccessException { if (mem instanceof Method) { boolean wantSpecial = (refKind == REF_invokeSpecial); - return new MemberName((Method) mem, wantSpecial); + return MemberName.make((Method) mem, wantSpecial); } else if (mem instanceof Constructor) { - return new MemberName((Constructor) mem); + return MemberName.make((Constructor) mem); } else if (mem instanceof Field) { boolean isSetter = (refKind == REF_putField || refKind == REF_putStatic); - return new MemberName((Field) mem, isSetter); + return MemberName.make((Field) mem, isSetter); } throw new InternalError(mem.getClass().getName()); } --- old/src/java.base/share/classes/java/lang/invoke/MethodHandles.java 2014-10-17 13:54:29.388912404 -0400 +++ new/src/java.base/share/classes/java/lang/invoke/MethodHandles.java 2014-10-17 13:54:29.220906462 -0400 @@ -1178,7 +1178,7 @@ MethodHandle mh = unreflectForMH(m); if (mh != null) return mh; } - MemberName method = new MemberName(m); + MemberName method = MemberName.make(m); byte refKind = method.getReferenceKind(); if (refKind == REF_invokeSpecial) refKind = REF_invokeVirtual; @@ -1189,7 +1189,7 @@ private MethodHandle unreflectForMH(Method m) { // these names require special lookups because they throw UnsupportedOperationException if (MemberName.isMethodHandleInvokeName(m.getName())) - return MethodHandleImpl.fakeMethodHandleInvoke(new MemberName(m)); + return MethodHandleImpl.fakeMethodHandleInvoke(MemberName.make(m)); return null; } @@ -1225,7 +1225,7 @@ public MethodHandle unreflectSpecial(Method m, Class specialCaller) throws IllegalAccessException { checkSpecialCaller(specialCaller); Lookup specialLookup = this.in(specialCaller); - MemberName method = new MemberName(m, true); + MemberName method = MemberName.make(m, true); assert(method.isMethod()); // ignore m.isAccessible: this is a new kind of access return specialLookup.getDirectMethodNoSecurityManager(REF_invokeSpecial, method.getDeclaringClass(), method, findBoundCallerClass(method)); @@ -1256,7 +1256,7 @@ * @throws NullPointerException if the argument is null */ public MethodHandle unreflectConstructor(Constructor c) throws IllegalAccessException { - MemberName ctor = new MemberName(c); + MemberName ctor = MemberName.make(c); assert(ctor.isConstructor()); Lookup lookup = c.isAccessible() ? IMPL_LOOKUP : this; return lookup.getDirectConstructorNoSecurityManager(ctor.getDeclaringClass(), ctor); @@ -1284,7 +1284,7 @@ return unreflectField(f, false); } private MethodHandle unreflectField(Field f, boolean isSetter) throws IllegalAccessException { - MemberName field = new MemberName(f, isSetter); + MemberName field = MemberName.make(f, isSetter); assert(isSetter ? MethodHandleNatives.refKindIsSetter(field.getReferenceKind()) : MethodHandleNatives.refKindIsGetter(field.getReferenceKind()));