changeset 52148:fb7489f63fd9 jep-334

changes to the DynamicConstantDesc api
author vromero
date Wed, 22 Aug 2018 11:03:23 -0700
parents f4dadd3974aa
children 63c69ded8b60 f4be0ebbaaac
files src/java.base/share/classes/java/lang/Enum.java src/java.base/share/classes/java/lang/constant/ConstantDescs.java src/java.base/share/classes/java/lang/constant/ConstantUtils.java src/java.base/share/classes/java/lang/constant/DirectMethodHandleDescImpl.java src/java.base/share/classes/java/lang/constant/DynamicConstantDesc.java src/java.base/share/classes/java/lang/constant/MethodTypeDescImpl.java src/java.base/share/classes/java/lang/constant/PrimitiveClassDescImpl.java src/java.base/share/classes/java/lang/constant/ReferenceClassDescImpl.java test/jdk/java/lang/constant/CondyRefTest.java test/jdk/java/lang/constant/MethodHandleRefTest.java test/jdk/java/lang/constant/TestHelpers.java
diffstat 11 files changed, 158 insertions(+), 176 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/Enum.java	Wed Aug 22 06:56:15 2018 -0700
+++ b/src/java.base/share/classes/java/lang/Enum.java	Wed Aug 22 11:03:23 2018 -0700
@@ -40,6 +40,7 @@
 
 import static java.lang.constant.ConstantDescs.BSM_ENUMDESC;
 import static java.lang.constant.ConstantDescs.CR_EnumDesc;
+import static java.lang.constant.ConstantDescs.DEFAULT_NAME;
 import static java.lang.constant.ConstantUtils.validateMemberName;
 import static java.util.Objects.requireNonNull;
 
@@ -323,8 +324,7 @@
 
         @Override
         public Optional<? extends ConstantDesc<ConstantDesc<E>>> describeConstable() {
-            return Optional.of(DynamicConstantDesc.<ConstantDesc<E>>of(BSM_ENUMDESC, CR_EnumDesc)
-                                                  .withArgs(constantType().descriptorString(), constantName()));
+            return Optional.of(DynamicConstantDesc.of(BSM_ENUMDESC, constantType().descriptorString(), constantName()));
         }
 
         /**
--- a/src/java.base/share/classes/java/lang/constant/ConstantDescs.java	Wed Aug 22 06:56:15 2018 -0700
+++ b/src/java.base/share/classes/java/lang/constant/ConstantDescs.java	Wed Aug 22 11:03:23 2018 -0700
@@ -247,8 +247,8 @@
 
     /** Nominal descriptor representing the constant {@code null} */
     public static final ConstantDesc<?> NULL
-            = DynamicConstantDesc.of(ConstantDescs.BSM_NULL_CONSTANT,
-                                     ConstantDescs.CR_Object);
+            = DynamicConstantDesc.ofNamed(ConstantDescs.BSM_NULL_CONSTANT,
+                                          DEFAULT_NAME, ConstantDescs.CR_Object);
 
     // Used by XxxDesc classes, but need to be here to avoid bootstrap cycles
     static final DirectMethodHandleDesc MHR_METHODTYPEDESC_FACTORY
--- a/src/java.base/share/classes/java/lang/constant/ConstantUtils.java	Wed Aug 22 06:56:15 2018 -0700
+++ b/src/java.base/share/classes/java/lang/constant/ConstantUtils.java	Wed Aug 22 11:03:23 2018 -0700
@@ -108,8 +108,8 @@
      * @return the nominal descriptor for the dynamic constant
      */
     public static<T> Optional<DynamicConstantDesc<T>> symbolizeHelper(MethodHandleDesc bootstrap,
-                                                               ClassDesc type,
-                                                               Constable<?>... args) {
+                                                                      ClassDesc type,
+                                                                      Constable<?>... args) {
         requireNonNull(bootstrap);
         requireNonNull(type);
         requireNonNull(args);
@@ -118,8 +118,9 @@
             quotedArgs[0] = bootstrap;
             for (int i=0; i<args.length; i++)
                 quotedArgs[i+1] = args[i].describeConstable().orElseThrow();
-            return Optional.of(DynamicConstantDesc.of(ConstantDescs.BSM_INVOKE, ConstantDescs.DEFAULT_NAME,
-                                                      type, quotedArgs));
+            return Optional.of(DynamicConstantDesc.ofNamed(ConstantDescs.BSM_INVOKE,
+                                                           ConstantDescs.DEFAULT_NAME,
+                                                           type, quotedArgs));
         }
         catch (NoSuchElementException e) {
             return Optional.empty();
--- a/src/java.base/share/classes/java/lang/constant/DirectMethodHandleDescImpl.java	Wed Aug 22 06:56:15 2018 -0700
+++ b/src/java.base/share/classes/java/lang/constant/DirectMethodHandleDescImpl.java	Wed Aug 22 11:03:23 2018 -0700
@@ -32,6 +32,7 @@
 
 import static java.lang.constant.ConstantDescs.BSM_METHODHANDLEDESC;
 import static java.lang.constant.ConstantDescs.CR_DirectMethodHandleDesc;
+import static java.lang.constant.ConstantDescs.DEFAULT_NAME;
 import static java.lang.constant.ConstantUtils.validateClassOrInterface;
 import static java.lang.constant.ConstantUtils.validateMemberName;
 import static java.lang.constant.DirectMethodHandleDesc.Kind.CONSTRUCTOR;
@@ -161,8 +162,11 @@
 
     @Override
     public Optional<? extends ConstantDesc<ConstantDesc<MethodHandle>>> describeConstable() {
-        return Optional.of(DynamicConstantDesc.<ConstantDesc<MethodHandle>>of(BSM_METHODHANDLEDESC, CR_DirectMethodHandleDesc)
-                                              .withArgs(kind.toString(), owner.descriptorString(), name, type.descriptorString()));
+        return Optional.of(DynamicConstantDesc.of(BSM_METHODHANDLEDESC,
+                                                  kind.toString(),
+                                                  owner.descriptorString(),
+                                                  name,
+                                                  type.descriptorString()));
     }
 
     @Override
--- a/src/java.base/share/classes/java/lang/constant/DynamicConstantDesc.java	Wed Aug 22 06:56:15 2018 -0700
+++ b/src/java.base/share/classes/java/lang/constant/DynamicConstantDesc.java	Wed Aug 22 11:03:23 2018 -0700
@@ -41,6 +41,8 @@
 import static java.lang.constant.ConstantDescs.CR_Class;
 import static java.lang.constant.ConstantDescs.CR_DynamicConstantDesc;
 import static java.lang.constant.ConstantDescs.CR_VarHandle;
+import static java.lang.constant.ConstantDescs.DEFAULT_NAME;
+import static java.lang.constant.ConstantUtils.EMPTY_CONSTANTDESC;
 import static java.lang.constant.ConstantUtils.validateMemberName;
 import static java.util.Objects.requireNonNull;
 import static java.util.stream.Collectors.joining;
@@ -105,21 +107,6 @@
     }
 
     /**
-     * Return a nominal descriptor for a dynamic constant whose bootstrap, invocation
-     * name, and invocation type are the same as this one, but with the specified
-     * bootstrap arguments.
-     *
-     * @param bootstrapArgs {@link ConstantDesc}s describing the static arguments
-     *                      to the bootstrap, that would appear in the
-     *                      {@code BootstrapMethods} attribute
-     * @return the nominal descriptor
-     * @throws NullPointerException if any argument is null
-     */
-    public DynamicConstantDesc<T> withArgs(ConstantDesc<?>... bootstrapArgs) {
-        return DynamicConstantDesc.of(bootstrapMethod, constantName, constantType, bootstrapArgs);
-    }
-
-    /**
      * Return a nominal descriptor for a dynamic constant, transforming it into
      * a more specific type if the constant bootstrap is a well-known one and a
      * more specific nominal descriptor type (e.g., ClassDesc) is available.
@@ -131,7 +118,7 @@
      *
      * <p>Bytecode-reading APIs that process the constant pool and wish to expose
      * entries as {@link ConstantDesc} to their callers should generally use this
-     * method in preference to {@link #of(DirectMethodHandleDesc, String, ClassDesc, ConstantDesc[])}
+     * method in preference to {@link #ofNamed(DirectMethodHandleDesc, String, ClassDesc, ConstantDesc...)}
      * because this may result in a more specific type that can be provided to
      * callers.
      *
@@ -157,7 +144,7 @@
                                                  String constantName,
                                                  ClassDesc constantType,
                                                  ConstantDesc<?>[] bootstrapArgs) {
-        return DynamicConstantDesc.<T>of(bootstrapMethod, constantName, constantType, bootstrapArgs)
+        return DynamicConstantDesc.<T>ofNamed(bootstrapMethod, constantName, constantType, bootstrapArgs)
                 .tryCanonicalize();
     }
 
@@ -182,26 +169,25 @@
      * format
      * @jvms 4.2.2 Unqualified Names
      */
-    public static<T> DynamicConstantDesc<T> of(DirectMethodHandleDesc bootstrapMethod,
-                                               String constantName,
-                                               ClassDesc constantType,
-                                               ConstantDesc<?>[] bootstrapArgs) {
-        return new DynamicConstantDesc<>(bootstrapMethod, constantName, constantType, bootstrapArgs) {};
+
+    public static<T> DynamicConstantDesc<T> ofNamed(DirectMethodHandleDesc bootstrapMethod,
+                                                    String constantName,
+                                                    ClassDesc constantType,
+                                                    ConstantDesc<?>... bootstrapArgs) {
+        return new AnonymousDynamicConstantDesc<>(bootstrapMethod, constantName, constantType, bootstrapArgs);
     }
 
     /**
-     * Return a nominal descriptor for a dynamic constant whose bootstrap has
-     * no static arguments.
+     * Return a nominal descriptor for a dynamic constant whose name parameter
+     * is {@link ConstantDescs#DEFAULT_NAME}, and whose type parameter is always
+     * the same as the bootstrap method return type.
      *
      * @param <T> the type of the dynamic constant
      * @param bootstrapMethod a {@link DirectMethodHandleDescImpl} describing the
      *                        bootstrap method for the constant
-     * @param constantName The name that would appear in the {@code NameAndType}
-     *                     operand of the {@code LDC} for this constant, as per
-     *                     JVMS 4.2.2
-     * @param constantType a {@link DirectMethodHandleDescImpl} describing the type
-     *                     that would appear in the {@code NameAndType} operand
-     *                     of the {@code LDC} for this constant
+     * @param bootstrapArgs {@link ConstantDesc}s describing the static arguments
+     *                      to the bootstrap, that would appear in the
+     *                      {@code BootstrapMethods} attribute
      * @return the nominal descriptor
      * @throws NullPointerException if any argument is null
      * @throws IllegalArgumentException if the {@code name} has the incorrect
@@ -209,50 +195,8 @@
      * @jvms 4.2.2 Unqualified Names
      */
     public static<T> DynamicConstantDesc<T> of(DirectMethodHandleDesc bootstrapMethod,
-                                               String constantName,
-                                               ClassDesc constantType) {
-        return DynamicConstantDesc.of(bootstrapMethod, constantName, constantType, ConstantUtils.EMPTY_CONSTANTDESC);
-    }
-
-    /**
-     * Return a nominal descriptor for a dynamic constant whose bootstrap has
-     * no static arguments, and for which the name parameter
-     * is {@link ConstantDescs#DEFAULT_NAME}.
-     *
-     * @param <T> the type of the dynamic constant
-     * @param bootstrapMethod a {@link DirectMethodHandleDescImpl} describing the
-     *                        bootstrap method for the constant
-     * @param constantType a {@link DirectMethodHandleDescImpl} describing the type
-     *                     that would appear in the {@code NameAndType} operand
-     *                     of the {@code LDC} for this constant
-     * @return the nominal descriptor
-     * @throws NullPointerException if any argument is null
-     */
-    public static<T> DynamicConstantDesc<T> of(DirectMethodHandleDesc bootstrapMethod,
-                                               ClassDesc constantType) {
-        return of(bootstrapMethod, ConstantDescs.DEFAULT_NAME, constantType);
-    }
-
-    /**
-     * Return a nominal descriptor for a dynamic constant whose bootstrap has
-     * no static arguments, and whose type parameter is always the same as the
-     * bootstrap method return type.
-     *
-     * @param <T> the type of the dynamic constant
-     * @param bootstrapMethod a {@link DirectMethodHandleDescImpl} describing the
-     *                        bootstrap method for the constant
-     * @param constantName The name that would appear in the {@code NameAndType}
-     *                     operand of the {@code LDC} for this constant, as per
-     *                     JVMS 4.2.2
-     * @return the nominal descriptor
-     * @throws NullPointerException if any argument is null
-     * @throws IllegalArgumentException if the {@code name} has the incorrect
-     * format
-     * @jvms 4.2.2 Unqualified Names
-     */
-    public static<T> DynamicConstantDesc<T> of(DirectMethodHandleDesc bootstrapMethod,
-                                               String constantName) {
-        return of(bootstrapMethod, constantName, bootstrapMethod.methodType().returnType());
+                                               ConstantDesc<?>... bootstrapArgs) {
+        return ofNamed(bootstrapMethod, DEFAULT_NAME, bootstrapMethod.methodType().returnType(), bootstrapArgs);
     }
 
     /**
@@ -269,7 +213,7 @@
      * format
      */
     public static<T> DynamicConstantDesc<T> of(DirectMethodHandleDesc bootstrapMethod) {
-        return of(bootstrapMethod, ConstantDescs.DEFAULT_NAME);
+        return of(bootstrapMethod, EMPTY_CONSTANTDESC);
     }
 
     /**
@@ -346,16 +290,15 @@
 
     @Override
     public Optional<? extends ConstantDesc<ConstantDesc<T>>> describeConstable() {
-        ConstantDesc<?>[] args =new ConstantDesc<?>[bootstrapArgs.length +5];
-        args[0] =bootstrapMethod.owner().descriptorString();
-        args[1] =bootstrapMethod.methodName();
-        args[2] =bootstrapMethod.methodType().descriptorString();
-        args[3] =constantName;
-        args[4] =constantType.descriptorString();
+        ConstantDesc<?>[] args =new ConstantDesc<?>[bootstrapArgs.length+5];
+        args[0] = bootstrapMethod.owner().descriptorString();
+        args[1] = bootstrapMethod.methodName();
+        args[2] = bootstrapMethod.methodType().descriptorString();
+        args[3] = constantName;
+        args[4] = constantType.descriptorString();
         for (int i=0; i<bootstrapArgs.length; i++)
             args[i+5] = (ConstantDesc<?>) ((Constable)bootstrapArgs[i]).describeConstable().orElseThrow();
-        return Optional.of(DynamicConstantDesc.of(BSM_DYNAMICCONSTANTDESC, ConstantDescs.DEFAULT_NAME,
-                                                  CR_DynamicConstantDesc, args));
+        return Optional.of(DynamicConstantDesc.of(BSM_DYNAMICCONSTANTDESC, args));
     }
 
     /**
@@ -385,10 +328,10 @@
                                                            String bsmOwner, String bsmName, String bsmDesc,
                                                            String constantName, String constantType,
                                                            ConstantDesc<?>... args) {
-        return DynamicConstantDesc.of(MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC,
-                                                          ClassDesc.ofDescriptor(bsmOwner), bsmName,
-                                                          MethodTypeDesc.ofDescriptor(bsmDesc)),
-                                      constantName, ClassDesc.ofDescriptor(constantType), args);
+        return DynamicConstantDesc.ofNamed(MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC,
+                                                               ClassDesc.ofDescriptor(bsmOwner), bsmName,
+                                                               MethodTypeDesc.ofDescriptor(bsmDesc)),
+                                           constantName, ClassDesc.ofDescriptor(constantType), args);
 
     }
 
@@ -482,4 +425,10 @@
                              Stream.of(bootstrapArgs).map(Object::toString).collect(joining(",")),
                              constantType.displayName());
     }
+
+    private static class AnonymousDynamicConstantDesc<T> extends DynamicConstantDesc<T> {
+        AnonymousDynamicConstantDesc(DirectMethodHandleDesc bootstrapMethod, String constantName, ClassDesc constantType, ConstantDesc<?>... bootstrapArgs) {
+            super(bootstrapMethod, constantName, constantType, bootstrapArgs);
+        }
+    }
 }
--- a/src/java.base/share/classes/java/lang/constant/MethodTypeDescImpl.java	Wed Aug 22 06:56:15 2018 -0700
+++ b/src/java.base/share/classes/java/lang/constant/MethodTypeDescImpl.java	Wed Aug 22 11:03:23 2018 -0700
@@ -143,8 +143,7 @@
 
     @Override
     public Optional<? extends ConstantDesc<ConstantDesc<MethodType>>> describeConstable() {
-        return Optional.of(DynamicConstantDesc.of(BSM_METHODTYPEDESC, DEFAULT_NAME, CR_MethodTypeDesc,
-                                                  new ConstantDesc<?>[] { descriptorString() }));
+        return Optional.of(DynamicConstantDesc.of(BSM_METHODTYPEDESC, descriptorString()));
     }
 
     @Override
--- a/src/java.base/share/classes/java/lang/constant/PrimitiveClassDescImpl.java	Wed Aug 22 06:56:15 2018 -0700
+++ b/src/java.base/share/classes/java/lang/constant/PrimitiveClassDescImpl.java	Wed Aug 22 11:03:23 2018 -0700
@@ -73,8 +73,7 @@
 
     @Override
     public Optional<? extends ConstantDesc<ConstantDesc<Class<?>>>> describeConstable() {
-        return Optional.of(DynamicConstantDesc.of(BSM_CLASSDESC, DEFAULT_NAME, CR_ClassDesc,
-                                                  new ConstantDesc<?>[] { descriptor }));
+        return Optional.of(DynamicConstantDesc.of(BSM_CLASSDESC, descriptor));
     }
 
     @Override
--- a/src/java.base/share/classes/java/lang/constant/ReferenceClassDescImpl.java	Wed Aug 22 06:56:15 2018 -0700
+++ b/src/java.base/share/classes/java/lang/constant/ReferenceClassDescImpl.java	Wed Aug 22 11:03:23 2018 -0700
@@ -86,8 +86,7 @@
 
     @Override
     public Optional<? extends ConstantDesc<ConstantDesc<Class<?>>>> describeConstable() {
-        return Optional.of(DynamicConstantDesc.of(BSM_CLASSDESC, DEFAULT_NAME, CR_ClassDesc,
-                                                  new ConstantDesc<?>[] {descriptor }));
+        return Optional.of(DynamicConstantDesc.of(BSM_CLASSDESC, descriptor));
     }
 
     @Override
--- a/test/jdk/java/lang/constant/CondyRefTest.java	Wed Aug 22 06:56:15 2018 -0700
+++ b/test/jdk/java/lang/constant/CondyRefTest.java	Wed Aug 22 11:03:23 2018 -0700
@@ -61,7 +61,7 @@
     private final static ClassDesc CR_ConstantBootstraps = ClassDesc.of("java.lang.invoke.ConstantBootstraps");
 
     private static<T> void testDCR(DynamicConstantDesc<T> r, T c) throws ReflectiveOperationException {
-        assertEquals(r, DynamicConstantDesc.of(r.bootstrapMethod(), r.constantName(), r.constantType(), r.bootstrapArgs()));
+        assertEquals(r, DynamicConstantDesc.ofNamed(r.bootstrapMethod(), r.constantName(), r.constantType(), r.bootstrapArgs()));
         assertEquals(r.resolveConstantDesc(LOOKUP), c);
     }
 
@@ -80,7 +80,7 @@
 
     public void testNullConstant() throws ReflectiveOperationException {
         DynamicConstantDesc<?> r = (DynamicConstantDesc<?>) ConstantDescs.NULL;
-        assertEquals(r, DynamicConstantDesc.of(r.bootstrapMethod(), r.constantName(), r.constantType(), r.bootstrapArgs()));
+        assertEquals(r, DynamicConstantDesc.ofNamed(r.bootstrapMethod(), r.constantName(), r.constantType(), r.bootstrapArgs()));
         assertNull(r.resolveConstantDesc(LOOKUP));
     }
 
@@ -91,7 +91,7 @@
     public void testDynamicConstant() throws ReflectiveOperationException {
         DirectMethodHandleDesc bsmRef = ConstantDescs.ofConstantBootstrap(ClassDesc.of("CondyRefTest"), "concatBSM",
                                                                             CR_String, CR_String, CR_String);
-        DynamicConstantDesc<String> r = DynamicConstantDesc.<String>of(bsmRef).withArgs("foo", "bar");
+        DynamicConstantDesc<String> r = DynamicConstantDesc.of(bsmRef, "foo", "bar");
         testDCR(r, "foobar");
     }
 
@@ -104,10 +104,10 @@
                                            format.resolveConstantDesc(LOOKUP), "%s%s", "moo", "cow");
         assertEquals(s, "moocow");
 
-        DynamicConstantDesc<String> ref = DynamicConstantDesc.<String>of(invoker).withArgs(format, "%s%s", "moo", "cow");
+        DynamicConstantDesc<String> ref = DynamicConstantDesc.of(invoker, format, "%s%s", "moo", "cow");
         testDCR(ref, "moocow");
 
-        DynamicConstantDesc<String> ref2 = DynamicConstantDesc.<String>of(invoker).withArgs(format, "%s%s", ref, "cow");
+        DynamicConstantDesc<String> ref2 = DynamicConstantDesc.of(invoker, format, "%s%s", ref, "cow");
         testDCR(ref2, "moocowcow");
     }
 
@@ -186,7 +186,7 @@
     }
 
     public void testLifting() {
-        DynamicConstantDesc<Object> unliftedNull = DynamicConstantDesc.of(ConstantDescs.BSM_NULL_CONSTANT, "_", CR_Object, EMPTY_ARGS);
+        DynamicConstantDesc<Object> unliftedNull = DynamicConstantDesc.ofNamed(ConstantDescs.BSM_NULL_CONSTANT, "_", CR_Object, EMPTY_ARGS);
         assertEquals(ConstantDescs.NULL, unliftedNull);
         assertNotSame(ConstantDescs.NULL, unliftedNull);
         assertSame(ConstantDescs.NULL, DynamicConstantDesc.ofCanonical(ConstantDescs.BSM_NULL_CONSTANT, "_", CR_Object, EMPTY_ARGS));
@@ -194,23 +194,23 @@
         assertSame(ConstantDescs.NULL, DynamicConstantDesc.ofCanonical(ConstantDescs.BSM_NULL_CONSTANT, "wahoo", CR_Object, EMPTY_ARGS));
 
         assertLifted(CR_int,
-                     DynamicConstantDesc.of(ConstantDescs.BSM_PRIMITIVE_CLASS, "I", ConstantDescs.CR_Class, EMPTY_ARGS),
+                     DynamicConstantDesc.ofNamed(ConstantDescs.BSM_PRIMITIVE_CLASS, "I", ConstantDescs.CR_Class, EMPTY_ARGS),
                      DynamicConstantDesc.ofCanonical(ConstantDescs.BSM_PRIMITIVE_CLASS, "I", ConstantDescs.CR_Class, EMPTY_ARGS));
 
         ClassDesc enumClass = ClassDesc.of("CondyRefTest").inner("MyEnum");
         assertLifted(EnumDesc.of(enumClass, "A"),
-                     DynamicConstantDesc.of(ConstantDescs.BSM_ENUM_CONSTANT, "A", enumClass, EMPTY_ARGS),
+                     DynamicConstantDesc.ofNamed(ConstantDescs.BSM_ENUM_CONSTANT, "A", enumClass, EMPTY_ARGS),
                      DynamicConstantDesc.<MyEnum>ofCanonical(ConstantDescs.BSM_ENUM_CONSTANT, "A", enumClass, EMPTY_ARGS));
 
         ClassDesc testClass = ClassDesc.of("CondyRefTest").inner("MyClass");
         assertLifted(VarHandleDesc.ofStaticField(testClass, "sf", CR_int),
-                     DynamicConstantDesc.of(ConstantDescs.BSM_VARHANDLE_STATIC_FIELD, "sf", CR_VarHandle, new ConstantDesc<?>[] {testClass, "sf", CR_int }),
+                     DynamicConstantDesc.ofNamed(ConstantDescs.BSM_VARHANDLE_STATIC_FIELD, "sf", CR_VarHandle, new ConstantDesc<?>[] {testClass, "sf", CR_int }),
                      DynamicConstantDesc.ofCanonical(ConstantDescs.BSM_VARHANDLE_STATIC_FIELD, "sf", CR_VarHandle, new ConstantDesc<?>[] {testClass, "sf", CR_int }));
         assertLifted(VarHandleDesc.ofField(testClass, "f", CR_int),
-                     DynamicConstantDesc.of(ConstantDescs.BSM_VARHANDLE_FIELD, "f", CR_VarHandle, new ConstantDesc<?>[] {testClass, "f", CR_int }),
+                     DynamicConstantDesc.ofNamed(ConstantDescs.BSM_VARHANDLE_FIELD, "f", CR_VarHandle, new ConstantDesc<?>[] {testClass, "f", CR_int }),
                      DynamicConstantDesc.ofCanonical(ConstantDescs.BSM_VARHANDLE_FIELD, "f", CR_VarHandle, new ConstantDesc<?>[] {testClass, "f", CR_int }));
         assertLifted(VarHandleDesc.ofArray(CR_int.arrayType()),
-                     DynamicConstantDesc.of(ConstantDescs.BSM_VARHANDLE_ARRAY, "_", CR_VarHandle, new ConstantDesc<?>[] {CR_int.arrayType() }),
+                     DynamicConstantDesc.ofNamed(ConstantDescs.BSM_VARHANDLE_ARRAY, "_", CR_VarHandle, new ConstantDesc<?>[] {CR_int.arrayType() }),
                      DynamicConstantDesc.ofCanonical(ConstantDescs.BSM_VARHANDLE_ARRAY, "_", CR_VarHandle, new ConstantDesc<?>[] {CR_int.arrayType() }));
     }
 
--- a/test/jdk/java/lang/constant/MethodHandleRefTest.java	Wed Aug 22 06:56:15 2018 -0700
+++ b/test/jdk/java/lang/constant/MethodHandleRefTest.java	Wed Aug 22 11:03:23 2018 -0700
@@ -65,10 +65,10 @@
  */
 @Test
 public class MethodHandleRefTest extends SymbolicRefTest {
-    private static ClassDesc thisClass = ClassDesc.of("MethodHandleRefTest");
-    private static ClassDesc testClass = thisClass.inner("TestClass");
-    private static ClassDesc testInterface = thisClass.inner("TestInterface");
-    private static ClassDesc testSuperclass = thisClass.inner("TestSuperclass");
+    private static ClassDesc helperHolderClass = ClassDesc.of("TestHelpers");
+    private static ClassDesc testClass = helperHolderClass.inner("TestClass");
+    private static ClassDesc testInterface = helperHolderClass.inner("TestInterface");
+    private static ClassDesc testSuperclass = helperHolderClass.inner("TestSuperclass");
 
 
     private static void assertMHEquals(MethodHandle a, MethodHandle b) {
@@ -175,49 +175,47 @@
         for (MethodHandleDesc r : List.of(ctorRef, staticMethodRef, staticIMethodRef, instanceMethodRef, instanceIMethodRef))
             testMethodHandleRef(r);
 
-        TestClass instance = (TestClass) ctorRef.resolveConstantDesc(LOOKUP).invokeExact();
-        TestClass instance2 = (TestClass) ctorRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact();
-        TestInterface instanceI = instance;
+        TestHelpers.TestClass instance = (TestHelpers.TestClass) ctorRef.resolveConstantDesc(LOOKUP).invokeExact();
+        TestHelpers.TestClass instance2 = (TestHelpers.TestClass) ctorRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact();
+        TestHelpers.TestInterface instanceI = instance;
 
         assertNotSame(instance, instance2);
 
         assertEquals(5, (int) staticMethodRef.resolveConstantDesc(LOOKUP).invokeExact(5));
-        assertEquals(5, (int) staticMethodRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact(5));
+        assertEquals(5, (int) staticMethodRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(5));
         assertEquals(0, (int) staticIMethodRef.resolveConstantDesc(LOOKUP).invokeExact(5));
-        assertEquals(0, (int) staticIMethodRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact(5));
+        assertEquals(0, (int) staticIMethodRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(5));
 
         assertEquals(5, (int) instanceMethodRef.resolveConstantDesc(LOOKUP).invokeExact(instance, 5));
-        assertEquals(5, (int) instanceMethodRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact(instance, 5));
+        assertEquals(5, (int) instanceMethodRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance, 5));
         assertEquals(5, (int) instanceIMethodRef.resolveConstantDesc(LOOKUP).invokeExact(instanceI, 5));
-        assertEquals(5, (int) instanceIMethodRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact(instanceI, 5));
+        assertEquals(5, (int) instanceIMethodRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instanceI, 5));
 
         try { superMethodRef.resolveConstantDesc(LOOKUP); fail(); }
         catch (IllegalAccessException e) { /* expected */ }
-        assertEquals(-1, (int) superMethodRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact(instance, 5));
+        assertEquals(-1, (int) superMethodRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance, 5));
 
         try { superIMethodRef.resolveConstantDesc(LOOKUP); fail(); }
         catch (IllegalAccessException e) { /* expected */ }
-        assertEquals(0, (int) superIMethodRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact(instance, 5));
+        assertEquals(0, (int) superIMethodRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance, 5));
 
         try { privateMethodRef.resolveConstantDesc(LOOKUP); fail(); }
         catch (IllegalAccessException e) { /* expected */ }
-        assertEquals(5, (int) privateMethodRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact(instance, 5));
+        assertEquals(5, (int) privateMethodRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance, 5));
 
         try { privateIMethodRef.resolveConstantDesc(LOOKUP); fail(); }
         catch (IllegalAccessException e) { /* expected */ }
-        try { privateIMethodRef.resolveConstantDesc(TestClass.LOOKUP); fail(); }
-        catch (IllegalAccessException e) { /* expected */ }
-        assertEquals(0, (int) privateIMethodRef.resolveConstantDesc(TestInterface.LOOKUP).invokeExact(instanceI, 5));
+        assertEquals(0, (int) privateIMethodRef.resolveConstantDesc(TestHelpers.TestInterface.LOOKUP).invokeExact(instanceI, 5));
+        assertEquals(0, (int) privateIMethodRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invoke(instanceI, 5));
 
         try { privateStaticMethodRef.resolveConstantDesc(LOOKUP); fail(); }
         catch (IllegalAccessException e) { /* expected */ }
-        assertEquals(5, (int) privateStaticMethodRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact(5));
+        assertEquals(5, (int) privateStaticMethodRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(5));
 
         try { privateStaticIMethodRef.resolveConstantDesc(LOOKUP); fail(); }
         catch (IllegalAccessException e) { /* expected */ }
-        try { privateStaticIMethodRef.resolveConstantDesc(TestClass.LOOKUP); fail(); }
-        catch (IllegalAccessException e) { /* expected */ }
-        assertEquals(0, (int) privateStaticIMethodRef.resolveConstantDesc(TestInterface.LOOKUP).invokeExact(5));
+        assertEquals(0, (int) privateStaticIMethodRef.resolveConstantDesc(TestHelpers.TestInterface.LOOKUP).invokeExact(5));
+        assertEquals(0, (int) privateStaticIMethodRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(5));
 
         MethodHandleDesc staticSetterRef = MethodHandleDesc.ofField(STATIC_SETTER, testClass, "sf", CR_int);
         MethodHandleDesc staticGetterRef = MethodHandleDesc.ofField(STATIC_GETTER, testClass, "sf", CR_int);
@@ -228,22 +226,22 @@
         for (MethodHandleDesc r : List.of(staticSetterRef, staticGetterRef, staticGetterIRef, setterRef, getterRef))
             testMethodHandleRef(r);
 
-        staticSetterRef.resolveConstantDesc(LOOKUP).invokeExact(6); assertEquals(TestClass.sf, 6);
+        staticSetterRef.resolveConstantDesc(LOOKUP).invokeExact(6); assertEquals(TestHelpers.TestClass.sf, 6);
         assertEquals(6, (int) staticGetterRef.resolveConstantDesc(LOOKUP).invokeExact());
-        assertEquals(6, (int) staticGetterRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact());
-        staticSetterRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact(7); assertEquals(TestClass.sf, 7);
+        assertEquals(6, (int) staticGetterRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact());
+        staticSetterRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(7); assertEquals(TestHelpers.TestClass.sf, 7);
         assertEquals(7, (int) staticGetterRef.resolveConstantDesc(LOOKUP).invokeExact());
-        assertEquals(7, (int) staticGetterRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact());
+        assertEquals(7, (int) staticGetterRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact());
 
         assertEquals(3, (int) staticGetterIRef.resolveConstantDesc(LOOKUP).invokeExact());
-        assertEquals(3, (int) staticGetterIRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact());
+        assertEquals(3, (int) staticGetterIRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact());
 
         setterRef.resolveConstantDesc(LOOKUP).invokeExact(instance, 6); assertEquals(instance.f, 6);
         assertEquals(6, (int) getterRef.resolveConstantDesc(LOOKUP).invokeExact(instance));
-        assertEquals(6, (int) getterRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact(instance));
-        setterRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact(instance, 7); assertEquals(instance.f, 7);
+        assertEquals(6, (int) getterRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance));
+        setterRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance, 7); assertEquals(instance.f, 7);
         assertEquals(7, (int) getterRef.resolveConstantDesc(LOOKUP).invokeExact(instance));
-        assertEquals(7, (int) getterRef.resolveConstantDesc(TestClass.LOOKUP).invokeExact(instance));
+        assertEquals(7, (int) getterRef.resolveConstantDesc(TestHelpers.TestClass.LOOKUP).invokeExact(instance));
     }
 
     private void assertBadArgs(Supplier<MethodHandleDesc> supplier, String s) {
@@ -262,10 +260,10 @@
         List<String> badSetterDescs = List.of("()V", "(I)V", "(Ljava/lang/Object;)V", "(Ljava/lang/Object;I)I", "(Ljava/lang/Object;II)V");
         List<String> badStaticSetterDescs = List.of("()V", "(II)V", "()I");
 
-        badGetterDescs.forEach(s -> assertBadArgs(() -> MethodHandleDesc.of(GETTER, thisClass, "x", s), s));
-        badSetterDescs.forEach(s -> assertBadArgs(() -> MethodHandleDesc.of(SETTER, thisClass, "x", s), s));
-        badStaticGetterDescs.forEach(s -> assertBadArgs(() -> MethodHandleDesc.of(STATIC_GETTER, thisClass, "x", s), s));
-        badStaticSetterDescs.forEach(s -> assertBadArgs(() -> MethodHandleDesc.of(STATIC_SETTER, thisClass, "x", s), s));
+        badGetterDescs.forEach(s -> assertBadArgs(() -> MethodHandleDesc.of(GETTER, helperHolderClass, "x", s), s));
+        badSetterDescs.forEach(s -> assertBadArgs(() -> MethodHandleDesc.of(SETTER, helperHolderClass, "x", s), s));
+        badStaticGetterDescs.forEach(s -> assertBadArgs(() -> MethodHandleDesc.of(STATIC_GETTER, helperHolderClass, "x", s), s));
+        badStaticSetterDescs.forEach(s -> assertBadArgs(() -> MethodHandleDesc.of(STATIC_SETTER, helperHolderClass, "x", s), s));
     }
 
     @Test(expectedExceptions = IllegalArgumentException.class)
@@ -294,33 +292,4 @@
 
         assertTrue(tested > 0);
     }
-
-    private interface TestInterface {
-        public static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
-
-        public static final int sf = 3;
-
-        static int sm(int  x) { return 0; }
-        default int m(int x) { return 0; }
-        private int pm(int x) { return 0; }
-        private static int psm(int x) { return 0; }
-    }
-
-    private static class TestSuperclass {
-        public int m(int x) { return -1; }
-    }
-
-    private static class TestClass extends TestSuperclass implements TestInterface {
-        public static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
-
-        static int sf;
-        int f;
-
-        public TestClass()  {}
-
-        public static int sm(int x) { return x; }
-        public int m(int x) { return x; }
-        private static int psm(int x) { return x; }
-        private int pm(int x) { return x; }
-    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/lang/constant/TestHelpers.java	Wed Aug 22 11:03:23 2018 -0700
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2012, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.lang.invoke.MethodHandles;
+
+/**
+ * TestHelpers
+ *
+ * @author Brian Goetz
+ */
+class TestHelpers {
+    interface TestInterface {
+        public static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
+
+        public static final int sf = 3;
+
+        static int sm(int  x) { return 0; }
+        default int m(int x) { return 0; }
+        private int pm(int x) { return 0; }
+        private static int psm(int x) { return 0; }
+    }
+
+    static class TestSuperclass {
+        public int m(int x) { return -1; }
+    }
+
+    static class TestClass extends TestSuperclass implements TestInterface {
+        public static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
+
+        static int sf;
+        int f;
+
+        public TestClass()  {}
+
+        public static int sm(int x) { return x; }
+        public int m(int x) { return x; }
+        private static int psm(int x) { return x; }
+        private int pm(int x) { return x; }
+    }
+}