changeset 1506:e5ed16b0ae71

8142422: Smaller Dynalink API adjustments Reviewed-by: hannesw, sundar
author attila
date Wed, 11 Nov 2015 14:54:09 +0100
parents fe703753f53f
children 549f06563f1c
files src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/CompositeOperation.java src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/NamedOperation.java src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AbstractJavaLinker.java src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/BeanLinker.java src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/BeansLinker.java src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/StaticClass.java src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/StaticClassLinker.java src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/CompositeGuardingDynamicLinker.java src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/CompositeTypeBasedGuardingDynamicLinker.java src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/TypeUtilities.java
diffstat 11 files changed, 58 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/CompositeOperation.java	Wed Nov 11 11:32:15 2015 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/CompositeOperation.java	Wed Nov 11 14:54:09 2015 +0100
@@ -139,7 +139,7 @@
  * {@code SET_ELEMENT}; other standard operations should not be combined. The
  * constructor will allow any combination of operations, though.
  */
-public class CompositeOperation implements Operation {
+public final class CompositeOperation implements Operation {
     private final Operation[] operations;
 
     /**
@@ -228,10 +228,10 @@
      */
     @Override
     public boolean equals(final Object obj) {
-        if (obj == null || obj.getClass() != CompositeOperation.class) {
-            return false;
+        if (obj instanceof CompositeOperation) {
+            return Arrays.equals(operations, ((CompositeOperation)obj).operations);
         }
-        return Arrays.equals(operations, ((CompositeOperation)obj).operations);
+        return false;
     }
 
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java	Wed Nov 11 11:32:15 2015 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinkerFactory.java	Wed Nov 11 14:54:09 2015 +0100
@@ -137,7 +137,7 @@
      * Default value for {@link #setUnstableRelinkThreshold(int) unstable relink
      * threshold}.
      */
-    public static final int DEFAULT_UNSTABLE_RELINK_THRESHOLD = 8;
+    private static final int DEFAULT_UNSTABLE_RELINK_THRESHOLD = 8;
 
     private boolean classLoaderExplicitlySet = false;
     private ClassLoader classLoader;
@@ -272,7 +272,7 @@
     /**
      * Sets the unstable relink threshold; the number of times a call site is
      * relinked after which it will be considered unstable, and subsequent link
-     * requests for it will indicate this.
+     * requests for it will indicate this. Defaults to 8 when not set explicitly.
      * @param unstableRelinkThreshold the new threshold. Must not be less than
      * zero. The value of zero means that call sites will never be considered
      * unstable.
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/NamedOperation.java	Wed Nov 11 11:32:15 2015 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/NamedOperation.java	Wed Nov 11 14:54:09 2015 +0100
@@ -98,7 +98,7 @@
  * the documentation for all {@link StandardOperation} members describes how
  * they are affected by being incorporated into a named operation.
  */
-public class NamedOperation implements Operation {
+public final class NamedOperation implements Operation {
     private final Operation baseOperation;
     private final Object name;
 
@@ -145,13 +145,11 @@
      */
     @Override
     public boolean equals(final Object obj) {
-        if (obj == null) {
-            return false;
-        } else if(obj.getClass() != NamedOperation.class) {
-            return false;
+        if (obj instanceof NamedOperation) {
+            final NamedOperation other = (NamedOperation)obj;
+            return baseOperation.equals(other.baseOperation) && name.equals(other.name);
         }
-        final NamedOperation other = (NamedOperation)obj;
-        return baseOperation.equals(other.baseOperation) && name.equals(other.name);
+        return false;
     }
 
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AbstractJavaLinker.java	Wed Nov 11 11:32:15 2015 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/AbstractJavaLinker.java	Wed Nov 11 14:54:09 2015 +0100
@@ -93,11 +93,11 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import jdk.internal.dynalink.CallSiteDescriptor;
 import jdk.internal.dynalink.CompositeOperation;
 import jdk.internal.dynalink.NamedOperation;
@@ -200,20 +200,20 @@
 
     abstract FacetIntrospector createFacetIntrospector();
 
-    Collection<String> getReadablePropertyNames() {
+    Set<String> getReadablePropertyNames() {
         return getUnmodifiableKeys(propertyGetters);
     }
 
-    Collection<String> getWritablePropertyNames() {
+    Set<String> getWritablePropertyNames() {
         return getUnmodifiableKeys(propertySetters);
     }
 
-    Collection<String> getMethodNames() {
+    Set<String> getMethodNames() {
         return getUnmodifiableKeys(methods);
     }
 
-    private static Collection<String> getUnmodifiableKeys(final Map<String, ?> m) {
-        return Collections.unmodifiableCollection(m.keySet());
+    private static Set<String> getUnmodifiableKeys(final Map<String, ?> m) {
+        return Collections.unmodifiableSet(m.keySet());
     }
 
     /**
@@ -416,9 +416,7 @@
         return new GuardedInvocationComponent(invocation, getClassGuard(type), clazz, ValidationType.EXACT_CLASS);
     }
 
-    SingleDynamicMethod getConstructorMethod(final String signature) {
-        return null;
-    }
+    abstract SingleDynamicMethod getConstructorMethod(final String signature);
 
     private MethodHandle getAssignableGuard(final MethodType type) {
         return Guards.asType(assignableGuard, type);
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/BeanLinker.java	Wed Nov 11 11:32:15 2015 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/BeanLinker.java	Wed Nov 11 14:54:09 2015 +0100
@@ -152,6 +152,11 @@
         return null;
     }
 
+    @Override
+    SingleDynamicMethod getConstructorMethod(final String signature) {
+        return null;
+    }
+
     private static final MethodHandle GET_LIST_ELEMENT = Lookup.PUBLIC.findVirtual(List.class, "get",
             MethodType.methodType(Object.class, int.class));
 
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/BeansLinker.java	Wed Nov 11 11:32:15 2015 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/BeansLinker.java	Wed Nov 11 14:54:09 2015 +0100
@@ -84,8 +84,8 @@
 package jdk.internal.dynalink.beans;
 
 import java.lang.invoke.MethodHandles.Lookup;
-import java.util.Collection;
 import java.util.Collections;
+import java.util.Set;
 import jdk.internal.dynalink.DynamicLinkerFactory;
 import jdk.internal.dynalink.StandardOperation;
 import jdk.internal.dynalink.linker.GuardedInvocation;
@@ -229,11 +229,11 @@
     }
 
     /**
-     * Returns a collection of names of all readable instance properties of a class.
+     * Returns a set of names of all readable instance properties of a class.
      * @param clazz the class
-     * @return a collection of names of all readable instance properties of a class.
+     * @return a set of names of all readable instance properties of a class.
      */
-    public static Collection<String> getReadableInstancePropertyNames(final Class<?> clazz) {
+    public static Set<String> getReadableInstancePropertyNames(final Class<?> clazz) {
         final TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
         if(linker instanceof BeanLinker) {
             return ((BeanLinker)linker).getReadablePropertyNames();
@@ -242,11 +242,11 @@
     }
 
     /**
-     * Returns a collection of names of all writable instance properties of a class.
+     * Returns a set of names of all writable instance properties of a class.
      * @param clazz the class
-     * @return a collection of names of all writable instance properties of a class.
+     * @return a set of names of all writable instance properties of a class.
      */
-    public static Collection<String> getWritableInstancePropertyNames(final Class<?> clazz) {
+    public static Set<String> getWritableInstancePropertyNames(final Class<?> clazz) {
         final TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
         if(linker instanceof BeanLinker) {
             return ((BeanLinker)linker).getWritablePropertyNames();
@@ -255,11 +255,11 @@
     }
 
     /**
-     * Returns a collection of names of all instance methods of a class.
+     * Returns a set of names of all instance methods of a class.
      * @param clazz the class
-     * @return a collection of names of all instance methods of a class.
+     * @return a set of names of all instance methods of a class.
      */
-    public static Collection<String> getInstanceMethodNames(final Class<?> clazz) {
+    public static Set<String> getInstanceMethodNames(final Class<?> clazz) {
         final TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
         if(linker instanceof BeanLinker) {
             return ((BeanLinker)linker).getMethodNames();
@@ -268,29 +268,29 @@
     }
 
     /**
-     * Returns a collection of names of all readable static properties of a class.
+     * Returns a set of names of all readable static properties of a class.
      * @param clazz the class
-     * @return a collection of names of all readable static properties of a class.
+     * @return a set of names of all readable static properties of a class.
      */
-    public static Collection<String> getReadableStaticPropertyNames(final Class<?> clazz) {
+    public static Set<String> getReadableStaticPropertyNames(final Class<?> clazz) {
         return StaticClassLinker.getReadableStaticPropertyNames(clazz);
     }
 
     /**
-     * Returns a collection of names of all writable static properties of a class.
+     * Returns a set of names of all writable static properties of a class.
      * @param clazz the class
-     * @return a collection of names of all writable static properties of a class.
+     * @return a set of names of all writable static properties of a class.
      */
-    public static Collection<String> getWritableStaticPropertyNames(final Class<?> clazz) {
+    public static Set<String> getWritableStaticPropertyNames(final Class<?> clazz) {
         return StaticClassLinker.getWritableStaticPropertyNames(clazz);
     }
 
     /**
-     * Returns a collection of names of all static methods of a class.
+     * Returns a set of names of all static methods of a class.
      * @param clazz the class
-     * @return a collection of names of all static methods of a class.
+     * @return a set of names of all static methods of a class.
      */
-    public static Collection<String> getStaticMethodNames(final Class<?> clazz) {
+    public static Set<String> getStaticMethodNames(final Class<?> clazz) {
         return StaticClassLinker.getStaticMethodNames(clazz);
     }
 
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/StaticClass.java	Wed Nov 11 11:32:15 2015 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/StaticClass.java	Wed Nov 11 14:54:09 2015 +0100
@@ -136,6 +136,10 @@
 
     private static final long serialVersionUID = 1L;
 
+    /**
+     * The runtime {@code Class} object whose static members this
+     * {@code StaticClass} represents.
+     */
     private final Class<?> clazz;
 
     /*private*/ StaticClass(final Class<?> clazz) {
@@ -164,6 +168,11 @@
         return "StaticClass[" + clazz.getName() + "]";
     }
 
+    /**
+     * Returns {@link #forClass(Class)} for the underlying {@code clazz} field
+     * ensuring that deserialization doesn't create non-canonical instances.
+     * @return {@link #forClass(Class)} for the underlying {@code clazz} field.
+     */
     private Object readResolve() {
         return forClass(clazz);
     }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/StaticClassLinker.java	Wed Nov 11 11:32:15 2015 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/beans/StaticClassLinker.java	Wed Nov 11 14:54:09 2015 +0100
@@ -88,7 +88,7 @@
 import java.lang.invoke.MethodType;
 import java.lang.reflect.Array;
 import java.util.Arrays;
-import java.util.Collection;
+import java.util.Set;
 import jdk.internal.dynalink.CallSiteDescriptor;
 import jdk.internal.dynalink.NamedOperation;
 import jdk.internal.dynalink.StandardOperation;
@@ -171,15 +171,15 @@
         return linkers.get(clazz).getConstructorMethod(signature);
     }
 
-    static Collection<String> getReadableStaticPropertyNames(final Class<?> clazz) {
+    static Set<String> getReadableStaticPropertyNames(final Class<?> clazz) {
         return linkers.get(clazz).getReadablePropertyNames();
     }
 
-    static Collection<String> getWritableStaticPropertyNames(final Class<?> clazz) {
+    static Set<String> getWritableStaticPropertyNames(final Class<?> clazz) {
         return linkers.get(clazz).getWritablePropertyNames();
     }
 
-    static Collection<String> getStaticMethodNames(final Class<?> clazz) {
+    static Set<String> getStaticMethodNames(final Class<?> clazz) {
         return linkers.get(clazz).getMethodNames();
     }
 
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/CompositeGuardingDynamicLinker.java	Wed Nov 11 11:32:15 2015 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/CompositeGuardingDynamicLinker.java	Wed Nov 11 14:54:09 2015 +0100
@@ -83,7 +83,6 @@
 
 package jdk.internal.dynalink.linker.support;
 
-import java.io.Serializable;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Objects;
@@ -97,9 +96,7 @@
  * other guarding dynamic linkers in its
  * {@link #getGuardedInvocation(LinkRequest, LinkerServices)}.
  */
-public class CompositeGuardingDynamicLinker implements GuardingDynamicLinker, Serializable {
-
-    private static final long serialVersionUID = 1L;
+public class CompositeGuardingDynamicLinker implements GuardingDynamicLinker {
 
     private final GuardingDynamicLinker[] linkers;
 
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/CompositeTypeBasedGuardingDynamicLinker.java	Wed Nov 11 11:32:15 2015 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/CompositeTypeBasedGuardingDynamicLinker.java	Wed Nov 11 14:54:09 2015 +0100
@@ -83,7 +83,6 @@
 
 package jdk.internal.dynalink.linker.support;
 
-import java.io.Serializable;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
@@ -102,9 +101,7 @@
  * type is encountered, the linking is delegated to those linkers only, speeding
  * up dispatch.
  */
-public class CompositeTypeBasedGuardingDynamicLinker implements TypeBasedGuardingDynamicLinker, Serializable {
-    private static final long serialVersionUID = 1L;
-
+public class CompositeTypeBasedGuardingDynamicLinker implements TypeBasedGuardingDynamicLinker {
     // Using a separate static class instance so there's no strong reference from the class value back to the composite
     // linker.
     private static class ClassToLinker extends ClassValue<List<TypeBasedGuardingDynamicLinker>> {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/TypeUtilities.java	Wed Nov 11 11:32:15 2015 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/TypeUtilities.java	Wed Nov 11 14:54:09 2015 +0100
@@ -94,7 +94,7 @@
 /**
  * Various static utility methods for working with Java types.
  */
-public class TypeUtilities {
+public final class TypeUtilities {
     static final Class<Object> OBJECT_CLASS = Object.class;
 
     private TypeUtilities() {