changeset 1487:77d303d8a943

8140273: restore use of CompositeOperation.contains where it is needed Reviewed-by: hannesw, sundar
author attila
date Thu, 22 Oct 2015 10:43:10 +0200
parents b640f10ccd6d
children 62641244c378
files src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/CompositeOperation.java src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornCallSiteDescriptor.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java
diffstat 5 files changed, 62 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/CompositeOperation.java	Wed Oct 21 18:39:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/CompositeOperation.java	Thu Oct 22 10:43:10 2015 +0200
@@ -204,6 +204,23 @@
     }
 
     /**
+     * Returns true if this composite operation contains an operation equal to
+     * the specified operation.
+     * @param operation the operation being searched for. Must not be null.
+     * @return true if the if this composite operation contains an operation
+     * equal to the specified operation.
+     */
+    public boolean contains(final Operation operation) {
+        Objects.requireNonNull(operation);
+        for(final Operation component: operations) {
+            if (component.equals(operation)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
      * Returns true if the other object is also a composite operation and their
      * component operations are equal.
      * @param obj the object to compare to
@@ -257,4 +274,24 @@
                 ? ((CompositeOperation)op).operations.clone()
                 : new Operation[] { op };
     }
+
+    /**
+     * Returns true if the specified potentially composite operation is a
+     * {@link CompositeOperation} and contains an operation equal to the
+     * specified operation. If {@code composite} is not a
+     * {@link CompositeOperation}, then the two operations are compared for
+     * equality.
+     * @param composite the potentially composite operation. Must not be null.
+     * @param operation the operation being searched for. Must not be null.
+     * @return true if the if the passed operation is a
+     * {@link CompositeOperation} and contains a component operation equal to
+     * the specified operation, or if it is not a {@link CompositeOperation} and
+     * is equal to {@code operation}.
+     */
+    public static boolean contains(final Operation composite, final Operation operation) {
+        if (composite instanceof CompositeOperation) {
+            return ((CompositeOperation)composite).contains(operation);
+        }
+        return composite.equals(Objects.requireNonNull(operation));
+    }
 }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java	Wed Oct 21 18:39:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/DynamicLinker.java	Thu Oct 22 10:43:10 2015 +0200
@@ -123,7 +123,13 @@
  *     }
  *
  *     public static CallSite bootstrap(MethodHandles.Lookup lookup, String name, MethodType type) {
- *         return dynamicLinker.link(new SimpleRelinkableCallSite(new CallSiteDescriptor(lookup, name, type)));
+ *         return dynamicLinker.link(
+ *             new SimpleRelinkableCallSite(
+ *                 new CallSiteDescriptor(lookup, parseOperation(name), type)));
+ *     }
+ *
+ *     private static Operation parseOperation(String name) {
+ *         ...
  *     }
  * }
  * </pre>
@@ -151,8 +157,10 @@
  *
  * <li>You also need to provide {@link CallSiteDescriptor}s to your call sites.
  * They are immutable objects that contain all the information about the call
- * site: the class performing the lookups, the name of the method being invoked,
- * and the method signature.</li>
+ * site: the class performing the lookups, the operation being invoked, and the
+ * method signature. You will have to supply your own scheme to encode and
+ * decode operations in the call site name or static parameters, that is why
+ * in the above example the {@code parseOperation} method is left unimplemented.</li>
  *
  * </ul>
  */
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java	Wed Oct 21 18:39:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaSuperAdapterLinker.java	Thu Oct 22 10:43:10 2015 +0200
@@ -77,7 +77,7 @@
 
         final CallSiteDescriptor descriptor = linkRequest.getCallSiteDescriptor();
 
-        if(NashornCallSiteDescriptor.getFirstStandardOperation(descriptor) != StandardOperation.GET_METHOD) {
+        if(!NashornCallSiteDescriptor.contains(descriptor, StandardOperation.GET_METHOD)) {
             // We only handle GET_METHOD
             return null;
         }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornCallSiteDescriptor.java	Wed Oct 21 18:39:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/NashornCallSiteDescriptor.java	Thu Oct 22 10:43:10 2015 +0200
@@ -335,6 +335,18 @@
     }
 
     /**
+     * Returns true if the passed call site descriptor's operation contains (or
+     * is) the specified standard operation.
+     * @param desc the call site descriptor.
+     * @param operation the operation whose presence is tested.
+     * @return Returns true if the call site descriptor's operation contains (or
+     * is) the specified standard operation.
+     */
+    public static boolean contains(final CallSiteDescriptor desc, final StandardOperation operation) {
+        return CompositeOperation.contains(NamedOperation.getBaseOperation(desc.getOperation()), operation);
+    }
+
+    /**
      * Returns the error message to be used when CALL or NEW is used on a non-function.
      *
      * @param obj object on which CALL or NEW is used
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java	Wed Oct 21 18:39:15 2015 -0700
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java	Thu Oct 22 10:43:10 2015 +0200
@@ -129,7 +129,7 @@
             // allow 'static' access on Class objects representing public classes of non-restricted packages
             if ((self instanceof Class) && Modifier.isPublic(((Class<?>)self).getModifiers())) {
                 final CallSiteDescriptor desc = request.getCallSiteDescriptor();
-                if ("static".equals(NashornCallSiteDescriptor.getOperand(desc)) && NashornCallSiteDescriptor.getFirstStandardOperation(desc) == StandardOperation.GET_PROPERTY) {
+                if ("static".equals(NashornCallSiteDescriptor.getOperand(desc)) && NashornCallSiteDescriptor.contains(desc, StandardOperation.GET_PROPERTY)) {
                     if (Context.isAccessibleClass((Class<?>)self) && !isReflectionClass((Class<?>)self)) {
                         // If "GET_PROPERTY:static" passes access checks, allow access.
                         return;