changeset 50744:0c64fc0636bf condy-folding

manual merge with jep branch
author vromero
date Fri, 25 May 2018 06:40:21 -0700
parents 6c94272f961d 1c2029a5ebe4
children 2df2582d6ad0
files src/java.base/share/classes/java/lang/Enum.java src/java.base/share/classes/java/lang/invoke/VarHandle.java src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template src/java.base/share/classes/java/lang/invoke/constant/ConstantDesc.java src/java.base/share/classes/java/lang/invoke/constant/ConstantDescs.java src/java.base/share/classes/java/lang/invoke/constant/ConstantUtils.java src/java.base/share/classes/java/lang/invoke/constant/DynamicConstantDesc.java src/java.base/share/classes/java/lang/invoke/constant/EnumDesc.java src/java.base/share/classes/java/lang/invoke/constant/VarHandleDesc.java src/java.base/share/classes/java/lang/invoke/constant/package-info.java test/jdk/java/lang/invoke/constant/ClassRefTest.java test/jdk/java/lang/invoke/constant/CondyRefTest.java
diffstat 12 files changed, 291 insertions(+), 337 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/Enum.java	Thu May 24 11:47:55 2018 -0700
+++ b/src/java.base/share/classes/java/lang/Enum.java	Fri May 25 06:40:21 2018 -0700
@@ -30,11 +30,19 @@
 import java.io.InvalidObjectException;
 import java.io.ObjectInputStream;
 import java.io.ObjectStreamException;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.constant.ClassDesc;
 import java.lang.invoke.constant.Constable;
 import java.lang.invoke.constant.ConstantDesc;
-import java.lang.invoke.constant.EnumDesc;
+import java.lang.invoke.constant.ConstantDescs;
+import java.lang.invoke.constant.DynamicConstantDesc;
 import java.util.Optional;
 
+import static java.lang.invoke.constant.ConstantDescs.BSM_ENUMDESC;
+import static java.lang.invoke.constant.ConstantDescs.CR_EnumDesc;
+import static java.lang.invoke.constant.ConstantUtils.validateMemberName;
+import static java.util.Objects.requireNonNull;
+
 /**
  * This is the common base class of all Java language enumeration types.
  *
@@ -268,4 +276,74 @@
     private void readObjectNoData() throws ObjectStreamException {
         throw new InvalidObjectException("can't deserialize enum");
     }
+
+    /**
+     * A <a href="package-summary.html#nominal">nominal descriptor</a> for an
+     * {@code enum} constant.
+     *
+     * @param <E> the type of the enum constant
+     */
+    public static final class EnumDesc<E extends Enum<E>>
+            extends DynamicConstantDesc<E> {
+
+        /**
+         * Construct a nominal descriptor for the specified {@code enum} class and name.
+         *
+         * @param constantType a {@link ClassDesc} describing the {@code enum} class
+         * @param constantName the name of the enum constant, as per JVMS 4.2.2
+         * @throws NullPointerException if any argument is null
+         */
+        private EnumDesc(ClassDesc constantType, String constantName) {
+            super(ConstantDescs.BSM_ENUM_CONSTANT, requireNonNull(constantName), requireNonNull(constantType));
+        }
+
+        /**
+         * Return a nominal descriptor for the specified {@code enum} class and name
+         *
+         * @param <E> the type of the enum constant
+         * @param enumClass a {@link ClassDesc} describing the {@code enum} class
+         * @param constantName the name of the enum constant, as per JVMS 4.2.2
+         * @return the nominal descriptor
+         * @throws NullPointerException if any argument is null
+         */
+        public static<E extends Enum<E>> EnumDesc<E> of(ClassDesc enumClass,
+                                                        String constantName) {
+            return new EnumDesc<>(enumClass, validateMemberName(constantName));
+        }
+
+        @Override
+        @SuppressWarnings("unchecked")
+        public E resolveConstantDesc(MethodHandles.Lookup lookup)
+                throws ReflectiveOperationException {
+            return Enum.valueOf((Class<E>) constantType().resolveConstantDesc(lookup), constantName());
+        }
+
+        @Override
+        public Optional<? extends ConstantDesc<? super ConstantDesc<E>>> describeConstable() {
+            return Optional.of(DynamicConstantDesc.of(BSM_ENUMDESC, CR_EnumDesc)
+                                                  .withArgs(constantType().descriptorString(), constantName()));
+        }
+
+        /**
+         * Constant bootstrap method for representing an {@linkplain EnumDesc} in
+         * the constant pool of a classfile.
+         *
+         * @param lookup ignored
+         * @param name ignored
+         * @param clazz ignored
+         * @param classDescriptor A field type descriptor for the enum class, as
+         *                        per JVMS 4.3.2
+         * @param constantName The name of the {@code enum} constant
+         * @return the {@linkplain EnumDesc}
+         */
+        public static EnumDesc<?> constantBootstrap(MethodHandles.Lookup lookup, String name, Class<ClassDesc> clazz,
+                                                    String classDescriptor, String constantName) {
+            return EnumDesc.of(ClassDesc.ofDescriptor(classDescriptor), constantName);
+        }
+
+        @Override
+        public String toString() {
+            return String.format("EnumDesc[%s.%s]", constantType().displayName(), constantName());
+        }
+    }
 }
--- a/src/java.base/share/classes/java/lang/invoke/VarHandle.java	Thu May 24 11:47:55 2018 -0700
+++ b/src/java.base/share/classes/java/lang/invoke/VarHandle.java	Fri May 25 06:40:21 2018 -0700
@@ -30,16 +30,23 @@
 import jdk.internal.vm.annotation.ForceInline;
 import jdk.internal.vm.annotation.Stable;
 
+import java.lang.invoke.constant.ClassDesc;
 import java.lang.invoke.constant.Constable;
-import java.lang.invoke.constant.VarHandleDesc;
+import java.lang.invoke.constant.ConstantDesc;
+import java.lang.invoke.constant.ConstantDescs;
+import java.lang.invoke.constant.ConstantMethodHandleDesc;
+import java.lang.invoke.constant.ConstantUtils;
+import java.lang.invoke.constant.DynamicConstantDesc;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.function.BiFunction;
 import java.util.function.Function;
 
 import static java.lang.invoke.MethodHandleStatics.UNSAFE;
+import static java.lang.invoke.constant.ConstantDescs.CR_VarHandleDesc;
 
 /**
  * A VarHandle is a dynamically strongly typed reference to a variable, or to a
@@ -2118,4 +2125,172 @@
     public static void storeStoreFence() {
         UNSAFE.storeStoreFence();
     }
+
+    /**
+     * A <a href="package-summary.html#nominal">nominal descriptor</a> for a
+     * {@link VarHandle} constant.
+     */
+    public static final class VarHandleDesc extends DynamicConstantDesc<VarHandle>
+            implements Constable<ConstantDesc<VarHandle>> {
+
+        /**
+         * Kinds of variable handle descs
+         */
+        private enum Kind {
+            FIELD(ConstantDescs.BSM_VARHANDLE_FIELD, ConstantDescs.MHR_VARHANDLEDESC_OFFIELD),
+            STATIC_FIELD(ConstantDescs.BSM_VARHANDLE_STATIC_FIELD, ConstantDescs.MHR_VARHANDLEDESC_OFSTATIC),
+            ARRAY(ConstantDescs.BSM_VARHANDLE_ARRAY, ConstantDescs.MHR_VARHANDLEDESC_OFARRAY);
+
+            final ConstantMethodHandleDesc bootstrapMethod;
+            final ConstantMethodHandleDesc descFactory;
+
+            Kind(ConstantMethodHandleDesc bootstrapMethod,
+                 ConstantMethodHandleDesc descFactory) {
+                this.bootstrapMethod = bootstrapMethod;
+                this.descFactory = descFactory;
+            }
+
+            List<ConstantDesc<?>> toBSMArgs(ClassDesc declaringClass, String name, ClassDesc varType) {
+                switch (this) {
+                    case FIELD:
+                    case STATIC_FIELD:
+                        return List.of(declaringClass, name, varType);
+                    case ARRAY:
+                        return List.of(declaringClass);
+                    default:
+                        throw new InternalError("Cannot reach here");
+                }
+            }
+        }
+
+        private final Kind kind;
+        private final ClassDesc declaringClass;
+        private final ClassDesc varType;
+
+        /**
+         * Construct a {@linkplain VarHandleDesc} given a kind, name, and declaring
+         * class.
+         *
+         * @param kind the kind of of the var handle
+         * @param name the name of the field, , as per JVMS 4.2.2, for field var
+         *             handles; otherwise ignored
+         * @param declaringClass a {@link ClassDesc} describing the declaring class,
+         *                       for field var handles
+         * @param varType a {@link ClassDesc} describing the type of the variable
+         * @throws NullPointerException if any required argument is null
+         */
+        private VarHandleDesc(Kind kind, String name, ClassDesc declaringClass, ClassDesc varType) {
+            super(kind.bootstrapMethod, name,
+                  ConstantDescs.CR_VarHandle,
+                  kind.toBSMArgs(declaringClass, name, varType).toArray(ConstantUtils.EMPTY_CONSTANTDESC));
+            this.kind = kind;
+            this.declaringClass = declaringClass;
+            this.varType = varType;
+        }
+
+        /**
+         * Returns a {@linkplain VarHandleDesc} corresponding to a {@link VarHandle}
+         * for an instance field.
+         *
+         * @param name the name of the field, as per JVMS 4.2.2
+         * @param declaringClass a {@link ClassDesc} describing the declaring class,
+         *                       for field var handles
+         * @param fieldType a {@link ClassDesc} describing the type of the field
+         * @return the {@linkplain VarHandleDesc}
+         * @throws NullPointerException if any of the arguments are null
+         */
+        public static VarHandleDesc ofField(ClassDesc declaringClass, String name, ClassDesc fieldType) {
+            Objects.requireNonNull(declaringClass);
+            Objects.requireNonNull(name);
+            Objects.requireNonNull(fieldType);
+            return new VarHandleDesc(Kind.FIELD, name, declaringClass, fieldType);
+        }
+
+        /**
+         * Returns a {@linkplain VarHandleDesc} corresponding to a {@link VarHandle}
+         * for a static field.
+         *
+         * @param name the name of the field, as per JVMS 4.2.2
+         * @param declaringClass a {@link ClassDesc} describing the declaring class,
+         *                       for field var handles
+         * @param fieldType a {@link ClassDesc} describing the type of the field
+         * @return the {@linkplain VarHandleDesc}
+         * @throws NullPointerException if any of the arguments are null
+         */
+        public static VarHandleDesc ofStaticField(ClassDesc declaringClass, String name, ClassDesc fieldType) {
+            Objects.requireNonNull(declaringClass);
+            Objects.requireNonNull(name);
+            Objects.requireNonNull(fieldType);
+            return new VarHandleDesc(Kind.STATIC_FIELD, name, declaringClass, fieldType);
+        }
+
+        /**
+         * Returns a {@linkplain VarHandleDesc} corresponding to a {@link VarHandle}
+         * for for an array type.
+         *
+         * @param arrayClass a {@link ClassDesc} describing the type of the array
+         * @return the {@linkplain VarHandleDesc}
+         * @throws NullPointerException if any of the arguments are null
+         */
+        public static VarHandleDesc ofArray(ClassDesc arrayClass) {
+            Objects.requireNonNull(arrayClass);
+            if (!arrayClass.isArray())
+                throw new IllegalArgumentException("Array class argument not an array: " + arrayClass);
+            return new VarHandleDesc(Kind.ARRAY, ConstantDescs.DEFAULT_NAME, arrayClass, arrayClass.componentType());
+        }
+
+        /**
+         * Returns a {@link ClassDesc} describing the type of the variable described
+         * by this descriptor.
+         *
+         * @return the variable type
+         */
+        public ClassDesc varType() {
+            return varType;
+        }
+
+        @Override
+        public VarHandle resolveConstantDesc(MethodHandles.Lookup lookup)
+                throws ReflectiveOperationException {
+            switch (kind) {
+                case FIELD:
+                    return lookup.findVarHandle(declaringClass.resolveConstantDesc(lookup),
+                                                constantName(),
+                                                varType.resolveConstantDesc(lookup));
+                case STATIC_FIELD:
+                    return lookup.findStaticVarHandle(declaringClass.resolveConstantDesc(lookup),
+                                                      constantName(),
+                                                      varType.resolveConstantDesc(lookup));
+                case ARRAY:
+                    return MethodHandles.arrayElementVarHandle(declaringClass.resolveConstantDesc(lookup));
+                default:
+                    throw new InternalError("Cannot reach here");
+            }
+        }
+
+        @Override
+        public Optional<? extends ConstantDesc<? super ConstantDesc<VarHandle>>> describeConstable() {
+            Constable<?>[] args =
+                    (kind == Kind.ARRAY)
+                    ? new Constable<?>[] { declaringClass }
+                    : new Constable<?>[] { declaringClass, constantName(), varType };
+            return ConstantUtils.symbolizeHelper(kind.descFactory, CR_VarHandleDesc, args);
+        }
+
+        @Override
+        public String toString() {
+            switch (kind) {
+                case FIELD:
+                case STATIC_FIELD:
+                    return String.format("VarHandleDesc[%s%s.%s:%s]",
+                                         (kind == Kind.STATIC_FIELD) ? "static " : "",
+                                         declaringClass.displayName(), constantName(), varType.displayName());
+                case ARRAY:
+                    return String.format("VarHandleDesc[%s[]]", declaringClass.displayName());
+                default:
+                    throw new InternalError("Cannot reach here");
+            }
+        }
+    }
+
 }
--- a/src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template	Thu May 24 11:47:55 2018 -0700
+++ b/src/java.base/share/classes/java/lang/invoke/X-VarHandle.java.template	Fri May 25 06:40:21 2018 -0700
@@ -27,7 +27,7 @@
 import jdk.internal.util.Preconditions;
 import jdk.internal.vm.annotation.ForceInline;
 
-import java.lang.invoke.constant.VarHandleDesc;
+import java.lang.invoke.VarHandle.VarHandleDesc;
 import java.util.Objects;
 import java.util.Optional;
 
--- a/src/java.base/share/classes/java/lang/invoke/constant/ConstantDesc.java	Thu May 24 11:47:55 2018 -0700
+++ b/src/java.base/share/classes/java/lang/invoke/constant/ConstantDesc.java	Fri May 25 06:40:21 2018 -0700
@@ -25,9 +25,11 @@
 package java.lang.invoke.constant;
 
 import java.lang.invoke.Intrinsics;
+import java.lang.Enum.EnumDesc;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
+import java.lang.invoke.VarHandle.VarHandleDesc;
 
 /**
  * A <a href="package-summary.html#nominal">nominal descriptor</a> for a loadable
--- a/src/java.base/share/classes/java/lang/invoke/constant/ConstantDescs.java	Thu May 24 11:47:55 2018 -0700
+++ b/src/java.base/share/classes/java/lang/invoke/constant/ConstantDescs.java	Fri May 25 06:40:21 2018 -0700
@@ -26,6 +26,7 @@
 
 import jdk.internal.lang.annotation.Foldable;
 
+import java.lang.Enum.EnumDesc;
 import java.lang.invoke.CallSite;
 import java.lang.invoke.ConstantBootstraps;
 import java.lang.invoke.MethodHandle;
@@ -33,6 +34,7 @@
 import java.lang.invoke.MethodHandles.Lookup;
 import java.lang.invoke.MethodType;
 import java.lang.invoke.VarHandle;
+import java.lang.invoke.VarHandle.VarHandleDesc;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -174,7 +176,7 @@
 
     /** {@link ClassDesc} representing {@link EnumDesc} */
     @Foldable
-    public static final ClassDesc CR_EnumDesc = ClassDesc.of("java.lang.invoke.constant.EnumDesc");
+    public static final ClassDesc CR_EnumDesc = CR_Enum.inner("EnumDesc");
 
     /** {@link ClassDesc} representing {@link MethodTypeDesc} */
     @Foldable
@@ -194,7 +196,7 @@
 
     /** {@link ClassDesc} representing {@link VarHandleDesc} */
     @Foldable
-    public static final ClassDesc CR_VarHandleDesc = ClassDesc.of("java.lang.invoke.constant.VarHandleDesc");
+    public static final ClassDesc CR_VarHandleDesc = CR_VarHandle.inner("VarHandleDesc");
 
     /** {@link ClassDesc} representing {@link MethodHandleDesc.Kind} */
     @Foldable
@@ -341,37 +343,39 @@
             = MethodHandleDesc.of(MethodHandleDesc.Kind.STATIC, CR_EnumDesc, "of",
                                   CR_EnumDesc, CR_ClassDesc, CR_String);
 
-    static final ConstantMethodHandleDesc MHR_VARHANDLEDESC_OFFIELD
+    /** {@link MethodHandleDesc} representing {@link VarHandleDesc#ofField(Lookup, String, Class, Class, String, Class)} */
+    public static final ConstantMethodHandleDesc MHR_VARHANDLEDESC_OFFIELD
             = MethodHandleDesc.of(MethodHandleDesc.Kind.STATIC, CR_VarHandleDesc, "ofField",
                                   CR_VarHandleDesc, CR_ClassDesc, CR_String, CR_ClassDesc);
-
-    static final ConstantMethodHandleDesc MHR_VARHANDLEDESC_OFSTATIC
+    /** {@link MethodHandleDesc} representing {@link VarHandleDesc#ofStaticField(Lookup, String, Class, Class, String, Class)} */
+    public static final ConstantMethodHandleDesc MHR_VARHANDLEDESC_OFSTATIC
             = MethodHandleDesc.of(MethodHandleDesc.Kind.STATIC, CR_VarHandleDesc, "ofStaticField",
                                   CR_VarHandleDesc, CR_ClassDesc, CR_String, CR_ClassDesc);
 
-    static final ConstantMethodHandleDesc MHR_VARHANDLEDESC_OFARRAY
+    /** {@link MethodHandleDesc} representing {@link VarHandleDesc#ofArray(Lookup, String, Class, Class, Class)} */
+    public static final ConstantMethodHandleDesc MHR_VARHANDLEDESC_OFARRAY
             = MethodHandleDesc.of(MethodHandleDesc.Kind.STATIC, CR_VarHandleDesc, "ofArray",
                                   CR_VarHandleDesc, CR_ClassDesc);
 
     static final ConstantMethodHandleDesc BSM_CLASSDESC
-            = ConstantDescs.ofConstantBootstrap(ClassDesc.of("java.lang.invoke.constant", "ConstantClassDesc"),
+            = ConstantDescs.ofConstantBootstrap(CR_ConstantClassDesc,
                                                 "constantBootstrap", CR_ClassDesc, CR_String);
 
     static final ConstantMethodHandleDesc BSM_METHODTYPEDESC
-            = ConstantDescs.ofConstantBootstrap(ClassDesc.of("java.lang.invoke.constant", "ConstantMethodTypeDesc"),
+            = ConstantDescs.ofConstantBootstrap(CR_ConstantMethodTypeDesc,
                                                 "constantBootstrap", CR_ConstantMethodTypeDesc, CR_String);
 
     static final ConstantMethodHandleDesc BSM_METHODHANDLEDESC
-            = ConstantDescs.ofConstantBootstrap(ClassDesc.of("java.lang.invoke.constant", "ConstantMethodHandleDesc"),
+            = ConstantDescs.ofConstantBootstrap(CR_ConstantMethodHandleDesc,
                                                 "constantBootstrap", CR_ConstantMethodHandleDesc,
                                                 CR_String, CR_String, CR_String, CR_String);
 
-    static final ConstantMethodHandleDesc BSM_ENUMDESC
-            = ConstantDescs.ofConstantBootstrap(ClassDesc.of("java.lang.invoke.constant", "EnumDesc"),
-                                                "constantBootstrap", CR_EnumDesc, CR_String, CR_String);
+    /** {@link MethodHandleDesc} representing {@link EnumDesc#constantBootstrap(Lookup, String, Class, String, String)} */
+    public static final ConstantMethodHandleDesc BSM_ENUMDESC
+            = ConstantDescs.ofConstantBootstrap(CR_EnumDesc, "constantBootstrap", CR_EnumDesc, CR_String, CR_String);
 
     static final ConstantMethodHandleDesc BSM_DYNAMICCONSTANTDESC
-            = ConstantDescs.ofConstantBootstrap(ClassDesc.of("java.lang.invoke.constant", "DynamicConstantDesc"),
+            = ConstantDescs.ofConstantBootstrap(CR_DynamicConstantDesc,
                                                 "constantBootstrap",
                                                 CR_DynamicConstantDesc,
                                                 CR_String, CR_String, CR_String, CR_String, CR_String, CR_ConstantDesc.arrayType());
--- a/src/java.base/share/classes/java/lang/invoke/constant/ConstantUtils.java	Thu May 24 11:47:55 2018 -0700
+++ b/src/java.base/share/classes/java/lang/invoke/constant/ConstantUtils.java	Fri May 25 06:40:21 2018 -0700
@@ -30,13 +30,12 @@
 import java.util.Optional;
 import java.util.Set;
 
-import sun.invoke.util.Wrapper;
-
 /**
  * Helper methods for the implementation of {@code java.lang.invoke.constant}.
  */
-class ConstantUtils {
-    static final ConstantDesc<?>[] EMPTY_CONSTANTDESC = new ConstantDesc<?>[0];
+public class ConstantUtils {
+    /** an empty constant descriptor */
+    public static final ConstantDesc<?>[] EMPTY_CONSTANTDESC = new ConstantDesc<?>[0];
     static final Constable<?>[] EMPTY_CONSTABLE = new Constable<?>[0];
 
     private static final Set<String> pointyNames = Set.of("<init>", "<clinit>");
@@ -50,7 +49,12 @@
         return name;
     }
 
-    static String validateMemberName(String name) {
+    /**
+     * validates a member name
+     * @param name the name of the member
+     * @return the name passed if valid
+     */
+    public static String validateMemberName(String name) {
         if (name.length() == 0)
             throw new IllegalArgumentException("zero-length member name");
         for (int i=0; i<name.length(); i++) {
@@ -105,7 +109,7 @@
      * @param args nominal descriptors for the bootstrap arguments
      * @return the nominal descriptor for the dynamic constant
      */
-    static<T> Optional<DynamicConstantDesc<T>> symbolizeHelper(MethodHandleDesc bootstrap,
+    public static<T> Optional<DynamicConstantDesc<T>> symbolizeHelper(MethodHandleDesc bootstrap,
                                                                ClassDesc type,
                                                                Constable<?>... args) {
         try {
--- a/src/java.base/share/classes/java/lang/invoke/constant/DynamicConstantDesc.java	Thu May 24 11:47:55 2018 -0700
+++ b/src/java.base/share/classes/java/lang/invoke/constant/DynamicConstantDesc.java	Fri May 25 06:40:21 2018 -0700
@@ -24,9 +24,11 @@
  */
 package java.lang.invoke.constant;
 
+import java.lang.Enum.EnumDesc;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.VarHandle;
+import java.lang.invoke.VarHandle.VarHandleDesc;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
--- a/src/java.base/share/classes/java/lang/invoke/constant/EnumDesc.java	Thu May 24 11:47:55 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,106 +0,0 @@
-/*
- * Copyright (c) 2018, 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.
- */
-package java.lang.invoke.constant;
-
-import jdk.internal.lang.annotation.Foldable;
-
-import java.lang.invoke.MethodHandles;
-import java.util.Optional;
-
-import static java.lang.invoke.constant.ConstantDescs.BSM_ENUMDESC;
-import static java.lang.invoke.constant.ConstantDescs.CR_EnumDesc;
-import static java.lang.invoke.constant.ConstantUtils.validateMemberName;
-import static java.util.Objects.requireNonNull;
-
-/**
- * A <a href="package-summary.html#nominal">nominal descriptor</a> for an
- * {@code enum} constant.
- *
- * @param <E> the type of the enum constant
- */
-public final class EnumDesc<E extends Enum<E>>
-        extends DynamicConstantDesc<E> {
-
-    /**
-     * Construct a nominal descriptor for the specified {@code enum} class and name.
-     *
-     * @param constantType a {@link ClassDesc} describing the {@code enum} class
-     * @param constantName the name of the enum constant, as per JVMS 4.2.2
-     * @throws NullPointerException if any argument is null
-     */
-    private EnumDesc(ClassDesc constantType, String constantName) {
-        super(ConstantDescs.BSM_ENUM_CONSTANT, requireNonNull(constantName), requireNonNull(constantType));
-    }
-
-    /**
-     * Return a nominal descriptor for the specified {@code enum} class and name
-     *
-     * @param <E> the type of the enum constant
-     * @param enumClass a {@link ClassDesc} describing the {@code enum} class
-     * @param constantName the name of the enum constant, as per JVMS 4.2.2
-     * @return the nominal descriptor
-     * @throws NullPointerException if any argument is null
-     */
-    @Foldable
-    public static<E extends Enum<E>> EnumDesc<E> of(ClassDesc enumClass,
-                                                    String constantName) {
-        return new EnumDesc<>(enumClass, validateMemberName(constantName));
-    }
-
-    @Override
-    @SuppressWarnings("unchecked")
-    public E resolveConstantDesc(MethodHandles.Lookup lookup)
-            throws ReflectiveOperationException {
-        return Enum.valueOf((Class<E>) constantType().resolveConstantDesc(lookup), constantName());
-    }
-
-    @Override
-    public Optional<? extends ConstantDesc<? super ConstantDesc<E>>> describeConstable() {
-        return Optional.of(DynamicConstantDesc.of(BSM_ENUMDESC, CR_EnumDesc)
-                                              .withArgs(constantType().descriptorString(), constantName()));
-    }
-
-    /**
-     * Constant bootstrap method for representing an {@linkplain EnumDesc} in
-     * the constant pool of a classfile.
-     *
-     * @param lookup ignored
-     * @param name ignored
-     * @param clazz ignored
-     * @param classDescriptor A field type descriptor for the enum class, as
-     *                        per JVMS 4.3.2
-     * @param constantName The name of the {@code enum} constant
-     * @return the {@linkplain EnumDesc}
-     */
-    public static EnumDesc<?> constantBootstrap(MethodHandles.Lookup lookup, String name, Class<ClassDesc> clazz,
-                                                String classDescriptor, String constantName) {
-        return EnumDesc.of(ClassDesc.ofDescriptor(classDescriptor), constantName);
-    }
-
-    @Override
-    public String toString() {
-        return String.format("EnumDesc[%s.%s]", constantType().displayName(), constantName());
-    }
-}
--- a/src/java.base/share/classes/java/lang/invoke/constant/VarHandleDesc.java	Thu May 24 11:47:55 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,206 +0,0 @@
-/*
- * Copyright (c) 2018, 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.
- */
-package java.lang.invoke.constant;
-
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.VarHandle;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-
-import jdk.internal.lang.annotation.Foldable;
-
-import static java.lang.invoke.constant.ConstantDescs.CR_VarHandleDesc;
-
-/**
- * A <a href="package-summary.html#nominal">nominal descriptor</a> for a
- * {@link VarHandle} constant.
- */
-public final class VarHandleDesc extends DynamicConstantDesc<VarHandle>
-        implements Constable<ConstantDesc<VarHandle>> {
-
-    /**
-     * Kinds of variable handle descs
-     */
-    private enum Kind {
-        FIELD(ConstantDescs.BSM_VARHANDLE_FIELD, ConstantDescs.MHR_VARHANDLEDESC_OFFIELD),
-        STATIC_FIELD(ConstantDescs.BSM_VARHANDLE_STATIC_FIELD, ConstantDescs.MHR_VARHANDLEDESC_OFSTATIC),
-        ARRAY(ConstantDescs.BSM_VARHANDLE_ARRAY, ConstantDescs.MHR_VARHANDLEDESC_OFARRAY);
-
-        final ConstantMethodHandleDesc bootstrapMethod;
-        final ConstantMethodHandleDesc descFactory;
-
-        Kind(ConstantMethodHandleDesc bootstrapMethod,
-             ConstantMethodHandleDesc descFactory) {
-            this.bootstrapMethod = bootstrapMethod;
-            this.descFactory = descFactory;
-        }
-
-        List<ConstantDesc<?>> toBSMArgs(ClassDesc declaringClass, String name, ClassDesc varType) {
-            switch (this) {
-                case FIELD:
-                case STATIC_FIELD:
-                    return List.of(declaringClass, name, varType);
-                case ARRAY:
-                    return List.of(declaringClass);
-                default:
-                    throw new InternalError("Cannot reach here");
-            }
-        }
-    }
-
-    private final Kind kind;
-    private final ClassDesc declaringClass;
-    private final ClassDesc varType;
-
-    /**
-     * Construct a {@linkplain VarHandleDesc} given a kind, name, and declaring
-     * class.
-     *
-     * @param kind the kind of of the var handle
-     * @param name the name of the field, , as per JVMS 4.2.2, for field var
-     *             handles; otherwise ignored
-     * @param declaringClass a {@link ClassDesc} describing the declaring class,
-     *                       for field var handles
-     * @param varType a {@link ClassDesc} describing the type of the variable
-     * @throws NullPointerException if any required argument is null
-     */
-    private VarHandleDesc(Kind kind, String name, ClassDesc declaringClass, ClassDesc varType) {
-        super(kind.bootstrapMethod, name,
-              ConstantDescs.CR_VarHandle,
-              kind.toBSMArgs(declaringClass, name, varType).toArray(ConstantUtils.EMPTY_CONSTANTDESC));
-        this.kind = kind;
-        this.declaringClass = declaringClass;
-        this.varType = varType;
-    }
-
-    /**
-     * Returns a {@linkplain VarHandleDesc} corresponding to a {@link VarHandle}
-     * for an instance field.
-     *
-     * @param name the name of the field, as per JVMS 4.2.2
-     * @param declaringClass a {@link ClassDesc} describing the declaring class,
-     *                       for field var handles
-     * @param fieldType a {@link ClassDesc} describing the type of the field
-     * @return the {@linkplain VarHandleDesc}
-     * @throws NullPointerException if any of the arguments are null
-     */
-    @Foldable
-    public static VarHandleDesc ofField(ClassDesc declaringClass, String name, ClassDesc fieldType) {
-        Objects.requireNonNull(declaringClass);
-        Objects.requireNonNull(name);
-        Objects.requireNonNull(fieldType);
-        return new VarHandleDesc(Kind.FIELD, name, declaringClass, fieldType);
-    }
-
-    /**
-     * Returns a {@linkplain VarHandleDesc} corresponding to a {@link VarHandle}
-     * for a static field.
-     *
-     * @param name the name of the field, as per JVMS 4.2.2
-     * @param declaringClass a {@link ClassDesc} describing the declaring class,
-     *                       for field var handles
-     * @param fieldType a {@link ClassDesc} describing the type of the field
-     * @return the {@linkplain VarHandleDesc}
-     * @throws NullPointerException if any of the arguments are null
-     */
-    @Foldable
-    public static VarHandleDesc ofStaticField(ClassDesc declaringClass, String name, ClassDesc fieldType) {
-        Objects.requireNonNull(declaringClass);
-        Objects.requireNonNull(name);
-        Objects.requireNonNull(fieldType);
-        return new VarHandleDesc(Kind.STATIC_FIELD, name, declaringClass, fieldType);
-    }
-
-    /**
-     * Returns a {@linkplain VarHandleDesc} corresponding to a {@link VarHandle}
-     * for for an array type.
-     *
-     * @param arrayClass a {@link ClassDesc} describing the type of the array
-     * @return the {@linkplain VarHandleDesc}
-     * @throws NullPointerException if any of the arguments are null
-     */
-    @Foldable
-    public static VarHandleDesc ofArray(ClassDesc arrayClass) {
-        Objects.requireNonNull(arrayClass);
-        if (!arrayClass.isArray())
-            throw new IllegalArgumentException("Array class argument not an array: " + arrayClass);
-        return new VarHandleDesc(Kind.ARRAY, ConstantDescs.DEFAULT_NAME, arrayClass, arrayClass.componentType());
-    }
-
-    /**
-     * Returns a {@link ClassDesc} describing the type of the variable described
-     * by this descriptor.
-     *
-     * @return the variable type
-     */
-    @Foldable
-    public ClassDesc varType() {
-        return varType;
-    }
-
-    @Override
-    public VarHandle resolveConstantDesc(MethodHandles.Lookup lookup)
-            throws ReflectiveOperationException {
-        switch (kind) {
-            case FIELD:
-                return lookup.findVarHandle(declaringClass.resolveConstantDesc(lookup),
-                                            constantName(),
-                                            varType.resolveConstantDesc(lookup));
-            case STATIC_FIELD:
-                return lookup.findStaticVarHandle(declaringClass.resolveConstantDesc(lookup),
-                                                  constantName(),
-                                                  varType.resolveConstantDesc(lookup));
-            case ARRAY:
-                return MethodHandles.arrayElementVarHandle(declaringClass.resolveConstantDesc(lookup));
-            default:
-                throw new InternalError("Cannot reach here");
-        }
-    }
-
-    @Override
-    public Optional<? extends ConstantDesc<? super ConstantDesc<VarHandle>>> describeConstable() {
-        Constable<?>[] args =
-                (kind == Kind.ARRAY)
-                ? new Constable<?>[] { declaringClass }
-                : new Constable<?>[] { declaringClass, constantName(), varType };
-        return ConstantUtils.symbolizeHelper(kind.descFactory, CR_VarHandleDesc, args);
-    }
-
-    @Override
-    public String toString() {
-        switch (kind) {
-            case FIELD:
-            case STATIC_FIELD:
-                return String.format("VarHandleDesc[%s%s.%s:%s]",
-                                     (kind == Kind.STATIC_FIELD) ? "static " : "",
-                                     declaringClass.displayName(), constantName(), varType.displayName());
-            case ARRAY:
-                return String.format("VarHandleDesc[%s[]]", declaringClass.displayName());
-            default:
-                throw new InternalError("Cannot reach here");
-        }
-    }
-}
--- a/src/java.base/share/classes/java/lang/invoke/constant/package-info.java	Thu May 24 11:47:55 2018 -0700
+++ b/src/java.base/share/classes/java/lang/invoke/constant/package-info.java	Fri May 25 06:40:21 2018 -0700
@@ -71,7 +71,7 @@
  * {@link java.lang.invoke.constant.DynamicConstantDesc#ofCanonical(ConstantMethodHandleDesc, java.lang.String, ClassDesc, ConstantDesc[])},
  * which will inspect the bootstrap and, for well-known bootstraps, return
  * a more specific subtype of {@link java.lang.invoke.constant.DynamicConstantDesc}, such as
- * {@link java.lang.invoke.constant.EnumDesc}.
+ * {@link java.lang.Enum.EnumDesc}.
  *
  * <p>Another way to obtain the nominal description of a value is to ask the value
  * itself.  A {@link java.lang.invoke.constant.Constable} is a type whose values
--- a/test/jdk/java/lang/invoke/constant/ClassRefTest.java	Thu May 24 11:47:55 2018 -0700
+++ b/test/jdk/java/lang/invoke/constant/ClassRefTest.java	Fri May 25 06:40:21 2018 -0700
@@ -95,6 +95,7 @@
                 }
             }
             catch (Throwable e) {
+                System.out.println(e.getMessage());
                 fail("Error testing field " + f.getName(), e);
             }
         }
--- a/test/jdk/java/lang/invoke/constant/CondyRefTest.java	Thu May 24 11:47:55 2018 -0700
+++ b/test/jdk/java/lang/invoke/constant/CondyRefTest.java	Fri May 25 06:40:21 2018 -0700
@@ -23,16 +23,16 @@
  * questions.
  */
 
+import java.lang.Enum.EnumDesc;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.VarHandle;
+import java.lang.invoke.VarHandle.VarHandleDesc;
 import java.lang.invoke.constant.ClassDesc;
 import java.lang.invoke.constant.ConstantDesc;
 import java.lang.invoke.constant.ConstantDescs;
 import java.lang.invoke.constant.ConstantMethodHandleDesc;
 import java.lang.invoke.constant.DynamicConstantDesc;
-import java.lang.invoke.constant.EnumDesc;
 import java.lang.invoke.constant.MethodHandleDesc;
-import java.lang.invoke.constant.VarHandleDesc;
 
 import org.testng.annotations.Test;