changeset 52900:533a0c8e1567 jep-334

changes after review comments
author vromero
date Thu, 18 Oct 2018 12:24:26 -0700
parents 7485ade5ea80
children e4624753b153
files src/java.base/share/classes/java/lang/constant/ConstantDescs.java src/java.base/share/classes/java/lang/constant/DirectMethodHandleDesc.java src/java.base/share/classes/java/lang/invoke/VarHandle.java
diffstat 3 files changed, 27 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/constant/ConstantDescs.java	Tue Oct 16 13:27:28 2018 -0700
+++ b/src/java.base/share/classes/java/lang/constant/ConstantDescs.java	Thu Oct 18 12:24:26 2018 -0700
@@ -248,37 +248,9 @@
             = DynamicConstantDesc.ofNamed(ConstantDescs.BSM_NULL_CONSTANT,
                                           DEFAULT_NAME, ConstantDescs.CD_Object);
 
-    static final DirectMethodHandleDesc MHD_CLASSDESC_FACTORY
-            = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CD_ClassDesc, "ofDescriptor",
-            CD_ClassDesc, CD_String);
-
     static final DirectMethodHandleDesc MHD_METHODHANDLE_ASTYPE
             = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.VIRTUAL, CD_MethodHandle, "asType",
             CD_MethodHandle, CD_MethodType);
-
-    static final DirectMethodHandleDesc MHD_DYNAMICCONSTANTDESC_FACTORY
-            = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CD_DynamicConstantDesc, "of",
-            CD_DynamicConstantDesc, CD_DirectMethodHandleDesc, CD_ConstantDesc.arrayType());
-
-    static final DirectMethodHandleDesc MHD_DYNAMICCONSTANTDESC_NAMED_FACTORY
-            = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CD_DynamicConstantDesc, "ofNamed",
-            CD_DynamicConstantDesc, CD_DirectMethodHandleDesc, CD_String, CD_String, CD_ConstantDesc.arrayType());
-
-    /** {@link MethodHandleDesc} representing {@link VarHandleDesc#ofField(ClassDesc, String, ClassDesc)} */
-    public static final DirectMethodHandleDesc MHD_VARHANDLEDESC_OFFIELD
-            = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CD_VarHandleDesc, "ofField",
-            CD_VarHandleDesc, CD_ClassDesc, CD_String, CD_ClassDesc);
-
-    /** {@link MethodHandleDesc} representing {@link VarHandleDesc#ofStaticField(ClassDesc, String, ClassDesc)} */
-    public static final DirectMethodHandleDesc MHD_VARHANDLEDESC_OFSTATIC
-            = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CD_VarHandleDesc, "ofStaticField",
-            CD_VarHandleDesc, CD_ClassDesc, CD_String, CD_ClassDesc);
-
-    /** {@link MethodHandleDesc} representing {@link VarHandleDesc#ofArray(ClassDesc)} */
-    public static final DirectMethodHandleDesc MHD_VARHANDLEDESC_OFARRAY
-            = MethodHandleDesc.of(DirectMethodHandleDesc.Kind.STATIC, CD_VarHandleDesc, "ofArray",
-            CD_VarHandleDesc, CD_ClassDesc);
-
     /**
      * Return a {@link MethodHandleDesc} corresponding to a bootstrap method for
      * an {@code invokedynamic} callsite, which is a static method whose leading
--- a/src/java.base/share/classes/java/lang/constant/DirectMethodHandleDesc.java	Tue Oct 16 13:27:28 2018 -0700
+++ b/src/java.base/share/classes/java/lang/constant/DirectMethodHandleDesc.java	Thu Oct 18 12:24:26 2018 -0700
@@ -108,18 +108,24 @@
         }
 
         /**
-         * Find the enumeration member with the given {@code refKind} and
-         * {@code isInterface} fields. If {@code isInterface} is true and there
-         * is no such enumeration member, return the member, if any, with the
-         * same {@code refKind} and a false {@code isInterface} field. If
-         * {@code isInterface} is true but there is no such enumeration member,
-         * then the result of {@code valueOf(refKind, false)} is returned.  As
-         * a special case, if {@code refKind} is {@code REF_invokeVirtual} (5) and
-         * {@code isInterface} is true, then the result of
-         * {@code valueOf(REF_invokeInterface, false)} is returned, and if
-         * {@code isInterface} is false and {@code refKind} is {@code REF_invokeInterface},
-         * {@code INTERFACE_VIRTUAL} is returned.
-         *
+         * Find the enumeration member with the given the {@code refKind} and
+         * {@code isInterface} arguments.
+         * For most values of {@code refKind} there is an exact match regardless of the value of {@code isInterface}.
+         * These are:
+         * <UL>
+         *     <LI>{@code REF_invokeVirtual} which matches to {@code VIRTUAL}
+         *     <LI>{@code REF_invokeInterface} which matches to {@code INTERFACE_VIRTUAL}
+         *     <LI>{@code REF_newInvokeSpecial} which matches to {@code CONSTRUCTOR}
+         *     <LI>{@code REF_getField} which matches to {@code GETTER}
+         *     <LI>{@code REF_putField} which matches to {@code SETTER}
+         *     <LI>{@code REF_getStatic} which matches to {@code STATIC_GETTER}
+         *     <LI>{@code REF_putStatic} which matches to {@code STATIC_SETTER}
+         * </UL>
+         * As for the rest, the returned kind will depend on the value (false or true accordingly) of {@code isInterface}:
+         * <UL>
+         *     <LI>{@code REF_invokeStatic} which matches to {@code STATIC} or {@code INTERFACE_STATIC}
+         *     <LI>{@code REF_invokeSpecial} which matches to {@code SPECIAL} or {@code INTERFACE_SPECIAL}
+         * </UL>
          * @param refKind refKind of desired member
          * @param isInterface whether desired member is for interface methods
          * @return the matching enumeration member
@@ -129,16 +135,14 @@
             int i = tableIndex(refKind, isInterface);
             if (i >= 0 && i < TABLE.length) {
                 Kind kind = TABLE[i];
+                if (kind == null) {
+                    throw new IllegalArgumentException(String.format("refKind=%d", refKind));
+                }
                 if (kind.refKind == refKind && kind.isInterface == isInterface) {
                     return kind;
                 }
             }
-            if (isInterface)
-                return valueOf(refKind);
-            else if (refKind == REF_invokeInterface)
-                return INTERFACE_VIRTUAL;
-            else
-                throw new IllegalArgumentException(String.format("refKind=%d", refKind));
+            throw new IllegalArgumentException(String.format("refKind=%d", refKind));
         }
 
         private static int tableIndex(int refKind, boolean isInterface) {
@@ -152,7 +156,7 @@
             // Pack the static table.
             int max = 0;
             for (Kind k : values())
-                max = Math.max(max, tableIndex(k.refKind, k.isInterface));
+                max = Math.max(max, tableIndex(k.refKind, true));
 
             TABLE = new Kind[max+1];
             for (Kind kind : values()) {
--- a/src/java.base/share/classes/java/lang/invoke/VarHandle.java	Tue Oct 16 13:27:28 2018 -0700
+++ b/src/java.base/share/classes/java/lang/invoke/VarHandle.java	Thu Oct 18 12:24:26 2018 -0700
@@ -2134,17 +2134,14 @@
          * Kinds of variable handle descs
          */
         private enum Kind {
-            FIELD(ConstantDescs.BSM_VARHANDLE_FIELD, ConstantDescs.MHD_VARHANDLEDESC_OFFIELD),
-            STATIC_FIELD(ConstantDescs.BSM_VARHANDLE_STATIC_FIELD, ConstantDescs.MHD_VARHANDLEDESC_OFSTATIC),
-            ARRAY(ConstantDescs.BSM_VARHANDLE_ARRAY, ConstantDescs.MHD_VARHANDLEDESC_OFARRAY);
+            FIELD(ConstantDescs.BSM_VARHANDLE_FIELD),
+            STATIC_FIELD(ConstantDescs.BSM_VARHANDLE_STATIC_FIELD),
+            ARRAY(ConstantDescs.BSM_VARHANDLE_ARRAY);
 
             final DirectMethodHandleDesc bootstrapMethod;
-            final DirectMethodHandleDesc descFactory;
 
-            Kind(DirectMethodHandleDesc bootstrapMethod,
-                 DirectMethodHandleDesc descFactory) {
+            Kind(DirectMethodHandleDesc bootstrapMethod) {
                 this.bootstrapMethod = bootstrapMethod;
-                this.descFactory = descFactory;
             }
 
             ConstantDesc<?>[] toBSMArgs(ClassDesc declaringClass, String name, ClassDesc varType) {