changeset 834:fdcdffd5b5b1 jdk8u20-b10

Merge
author asaha
date Thu, 10 Apr 2014 15:28:48 -0700
parents b1a025fe733d b5c37cb0b2a0
children ef90d0fc9533
files .hgtags src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java
diffstat 9 files changed, 91 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Wed Apr 09 08:48:04 2014 -0700
+++ b/.hgtags	Thu Apr 10 15:28:48 2014 -0700
@@ -241,6 +241,23 @@
 fdfbb745caf0e54775a44e66e39d3025785e0528 jdk8-b127
 73cbad0c5d28b8f6e12f634aceeb2b3b4ad09553 jdk8-b128
 9cc3fd32fbabdd8b06771d11a319c9802e118612 jdk8-b129
+f87eba70e9ee96255137c389db7cb4e2480e53e7 jdk8-b130
+cca9748cfec7025ac0ddcdede9e5724fa676ad13 jdk8-b131
+5dbdae28a6f3dae3913b118c128bcb1f803317ac jdk8-b132
+13ca8f1a9eba716295fb7d9c2ddad81390931919 jdk8u5-b01
+7e7cb9977a3d1244384ffa454a4890764a07b042 jdk8u5-b02
+2abeb654b57f306f73f3f73bdfa05f93bce2a1f3 jdk8u5-b03
+7c650ceee4902249f32bdc066926b77291007859 jdk8u5-b04
+d88b60cdc8f3cfceb8ef19b095769015b441e37f jdk8u11-b00
+d88b60cdc8f3cfceb8ef19b095769015b441e37f jdk8u5-b05
+d6dfad8b7fb524780ebf4f6b62284cf5679f9ba8 jdk8u5-b06
+96ad962a6a88874830e99e0cd11aece89a1bd1f4 jdk8u5-b07
+f0b7b8b5e29a3a4e481fbeb9b346552c9819675e jdk8u5-b08
+6ca65190effb3bf8119bb4e93f1692487337ec72 jdk8u5-b09
+8bc83045abc547edb7cfb7d688d84164f0b11cea jdk8u5-b10
+bc23b19e08eb1575663044902b6442ceaafa924f jdk8u5-b11
+18b007062905dac9304605955a4b84eaf2a08553 jdk8u5-b12
+e4fb85d69d6b33c9561b932ec5515f44c53c1017 jdk8u5-b13
 43a1183d2ab0ee3dbffd8bc47606e88dbe0c6116 jdk8u20-b02
 9d69311869d513deecfebe767cc5f01502c9c01e jdk8u20-b03
 e70dd55986e085185d976f2a78843a7d7eb87afd jdk8u20-b04
--- a/THIRD_PARTY_README	Wed Apr 09 08:48:04 2014 -0700
+++ b/THIRD_PARTY_README	Thu Apr 10 15:28:48 2014 -0700
@@ -1399,13 +1399,13 @@
 
 -------------------------------------------------------------------------------
 
-%% This notice is provided with respect to Little CMS 2.4, which may be 
+%% This notice is provided with respect to Little CMS 2.5, which may be 
 included with JRE 8, JDK 8, and OpenJDK 8.
 
 --- begin of LICENSE ---
 
 Little CMS
-Copyright (c) 1998-2010 Marti Maria Saguer
+Copyright (c) 1998-2011 Marti Maria Saguer
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
--- a/src/jdk/internal/dynalink/beans/AccessibleMembersLookup.java	Wed Apr 09 08:48:04 2014 -0700
+++ b/src/jdk/internal/dynalink/beans/AccessibleMembersLookup.java	Thu Apr 10 15:28:48 2014 -0700
@@ -211,7 +211,8 @@
         if(!CheckRestrictedPackage.isRestrictedClass(clazz)) {
             searchSuperTypes = false;
             for(Method method: clazz.getMethods()) {
-                if(instance != Modifier.isStatic(method.getModifiers())) {
+                final boolean isStatic = Modifier.isStatic(method.getModifiers());
+                if(instance != isStatic) {
                     final MethodSignature sig = new MethodSignature(method);
                     if(!methods.containsKey(sig)) {
                         final Class<?> declaringClass = method.getDeclaringClass();
@@ -228,7 +229,10 @@
                             //generate the said synthetic delegators.
                             searchSuperTypes = true;
                         } else {
-                            methods.put(sig, method);
+                            // don't allow inherited static
+                            if (!isStatic || clazz == declaringClass) {
+                                methods.put(sig, method);
+                            }
                         }
                     }
                 }
@@ -245,7 +249,8 @@
             searchSuperTypes = true;
         }
 
-        if(searchSuperTypes) {
+        // don't need to search super types for static methods
+        if(instance && searchSuperTypes) {
             // If we reach here, the class is either not public, or it is in a restricted package. Alternatively, it is
             // public, but some of its methods claim that their declaring class is non-public. We'll try superclasses
             // and implemented interfaces then looking for public ones.
--- a/src/jdk/internal/dynalink/beans/FacetIntrospector.java	Wed Apr 09 08:48:04 2014 -0700
+++ b/src/jdk/internal/dynalink/beans/FacetIntrospector.java	Thu Apr 10 15:28:48 2014 -0700
@@ -136,7 +136,13 @@
         final Field[] fields = clazz.getFields();
         final Collection<Field> cfields = new ArrayList<>(fields.length);
         for(Field field: fields) {
-            if(instance != Modifier.isStatic(field.getModifiers()) && isAccessible(field)) {
+            final boolean isStatic = Modifier.isStatic(field.getModifiers());
+            if(isStatic && clazz != field.getDeclaringClass()) {
+                // ignore inherited static fields
+                continue;
+            }
+
+            if(instance != isStatic && isAccessible(field)) {
                 cfields.add(field);
             }
         }
--- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Wed Apr 09 08:48:04 2014 -0700
+++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java	Thu Apr 10 15:28:48 2014 -0700
@@ -64,7 +64,6 @@
 import jdk.internal.org.objectweb.asm.Opcodes;
 import jdk.internal.org.objectweb.asm.Type;
 import jdk.internal.org.objectweb.asm.commons.InstructionAdapter;
-import jdk.nashorn.internal.objects.Global;
 import jdk.nashorn.internal.runtime.Context;
 import jdk.nashorn.internal.runtime.ScriptFunction;
 import jdk.nashorn.internal.runtime.ScriptObject;
@@ -132,23 +131,17 @@
  * implemented securely.
  */
 final class JavaAdapterBytecodeGenerator {
-    static final Type CONTEXT_TYPE       = Type.getType(Context.class);
     static final Type OBJECT_TYPE        = Type.getType(Object.class);
-    static final Type SCRIPT_OBJECT_TYPE = Type.getType(ScriptObject.class);
-    static final Type GLOBAL_TYPE        = Type.getType(Global.class);
 
-    static final String CONTEXT_TYPE_NAME = CONTEXT_TYPE.getInternalName();
     static final String OBJECT_TYPE_NAME  = OBJECT_TYPE.getInternalName();
 
     static final String INIT = "<init>";
 
     static final String GLOBAL_FIELD_NAME = "global";
 
-    static final String SCRIPT_OBJECT_TYPE_DESCRIPTOR = SCRIPT_OBJECT_TYPE.getDescriptor();
-    static final String GLOBAL_TYPE_DESCRIPTOR = GLOBAL_TYPE.getDescriptor();
+    static final String GLOBAL_TYPE_DESCRIPTOR = OBJECT_TYPE.getDescriptor();
 
-
-    static final String SET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE, GLOBAL_TYPE);
+    static final String SET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE, OBJECT_TYPE);
     static final String VOID_NOARG_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE);
 
     private static final Type SCRIPT_FUNCTION_TYPE = Type.getType(ScriptFunction.class);
@@ -159,7 +152,7 @@
             OBJECT_TYPE, STRING_TYPE, METHOD_TYPE_TYPE);
     private static final String GET_HANDLE_FUNCTION_DESCRIPTOR = Type.getMethodDescriptor(METHOD_HANDLE_TYPE,
             SCRIPT_FUNCTION_TYPE, METHOD_TYPE_TYPE);
-    private static final String GET_CLASS_INITIALIZER_DESCRIPTOR = Type.getMethodDescriptor(SCRIPT_OBJECT_TYPE);
+    private static final String GET_CLASS_INITIALIZER_DESCRIPTOR = Type.getMethodDescriptor(OBJECT_TYPE);
     private static final Type RUNTIME_EXCEPTION_TYPE = Type.getType(RuntimeException.class);
     private static final Type THROWABLE_TYPE = Type.getType(Throwable.class);
     private static final Type UNSUPPORTED_OPERATION_TYPE = Type.getType(UnsupportedOperationException.class);
@@ -171,7 +164,7 @@
     private static final String UNSUPPORTED_OPERATION_TYPE_NAME = UNSUPPORTED_OPERATION_TYPE.getInternalName();
 
     private static final String METHOD_HANDLE_TYPE_DESCRIPTOR = METHOD_HANDLE_TYPE.getDescriptor();
-    private static final String GET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(GLOBAL_TYPE);
+    private static final String GET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(OBJECT_TYPE);
     private static final String GET_CLASS_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.getType(Class.class));
 
     // Package used when the adapter can't be defined in the adaptee's package (either because it's sealed, or because
@@ -528,11 +521,11 @@
     }
 
     private static void invokeGetGlobal(final InstructionAdapter mv) {
-        mv.invokestatic(CONTEXT_TYPE_NAME, "getGlobal", GET_GLOBAL_METHOD_DESCRIPTOR, false);
+        mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "getGlobal", GET_GLOBAL_METHOD_DESCRIPTOR, false);
     }
 
     private static void invokeSetGlobal(final InstructionAdapter mv) {
-        mv.invokestatic(CONTEXT_TYPE_NAME, "setGlobal", SET_GLOBAL_METHOD_DESCRIPTOR, false);
+        mv.invokestatic(SERVICES_CLASS_TYPE_NAME, "setGlobal", SET_GLOBAL_METHOD_DESCRIPTOR, false);
     }
 
     /**
@@ -649,7 +642,7 @@
             mv.athrow();
         } else {
             // If the super method is not abstract, delegate to it.
-            emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc);
+            emitSuperCall(mv, name, methodDesc);
         }
 
         mv.visitLabel(handleDefined);
@@ -678,7 +671,7 @@
         // stack: [creatingGlobal, creatingGlobal, handle]
 
         // Emit code for switching to the creating global
-        // Global currentGlobal = Context.getGlobal();
+        // ScriptObject currentGlobal = Context.getGlobal();
         invokeGetGlobal(mv);
         mv.dup();
 
@@ -821,12 +814,12 @@
                 SUPER_PREFIX + name, methodDesc, null, getExceptionNames(method.getExceptionTypes())));
         mv.visitCode();
 
-        emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc);
+        emitSuperCall(mv, name, methodDesc);
 
         endMethod(mv);
     }
 
-    private void emitSuperCall(final InstructionAdapter mv, final Class owner, final String name, final String methodDesc) {
+    private void emitSuperCall(final InstructionAdapter mv, final String name, final String methodDesc) {
         mv.visitVarInsn(ALOAD, 0);
         int nextParam = 1;
         final Type methodType = Type.getMethodType(methodDesc);
@@ -834,13 +827,7 @@
             mv.load(nextParam, t);
             nextParam += t.getSize();
         }
-
-        // default method - non-abstract, interface method
-        if (Modifier.isInterface(owner.getModifiers())) {
-            mv.invokespecial(Type.getInternalName(owner), name, methodDesc, false);
-        } else {
-            mv.invokespecial(superClassName, name, methodDesc, false);
-        }
+        mv.invokespecial(superClassName, name, methodDesc, false);
         mv.areturn(methodType.getReturnType());
     }
 
--- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java	Wed Apr 09 08:48:04 2014 -0700
+++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java	Thu Apr 10 15:28:48 2014 -0700
@@ -31,6 +31,8 @@
 import java.security.ProtectionDomain;
 import java.security.SecureClassLoader;
 import jdk.internal.dynalink.beans.StaticClass;
+import jdk.nashorn.internal.runtime.Context;
+import jdk.nashorn.internal.runtime.ScriptFunction;
 
 /**
  * This class encapsulates the bytecode of the adapter class and can be used to load it into the JVM as an actual Class.
@@ -85,13 +87,14 @@
             @Override
             public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
                 try {
+                    Context.checkPackageAccess(name);
                     return super.loadClass(name, resolve);
                 } catch (final SecurityException se) {
                     // we may be implementing an interface or extending a class that was
                     // loaded by a loader that prevents package.access. If so, it'd throw
                     // SecurityException for nashorn's classes!. For adapter's to work, we
-                    // should be able to refer to nashorn classes.
-                    if (name.startsWith("jdk.nashorn.internal.")) {
+                    // should be able to refer to the few classes it needs in its implementation.
+                    if(ScriptFunction.class.getName().equals(name) || JavaAdapterServices.class.getName().equals(name)) {
                         return myLoader.loadClass(name);
                     }
                     throw se;
--- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Wed Apr 09 08:48:04 2014 -0700
+++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java	Thu Apr 10 15:28:48 2014 -0700
@@ -247,7 +247,7 @@
     }
 
     private static class AdapterInfo {
-        private static final ClassAndLoader SCRIPT_OBJECT_LOADER = new ClassAndLoader(ScriptObject.class, true);
+        private static final ClassAndLoader SCRIPT_OBJECT_LOADER = new ClassAndLoader(ScriptFunction.class, true);
 
         private final ClassLoader commonLoader;
         // TODO: soft reference the JavaAdapterClassLoader objects. They can be recreated when needed.
--- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterServices.java	Wed Apr 09 08:48:04 2014 -0700
+++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterServices.java	Thu Apr 10 15:28:48 2014 -0700
@@ -116,8 +116,8 @@
      * static initializers.
      * @return the thread-local JS object used to define methods for the class being initialized.
      */
-    public static ScriptObject getClassOverrides() {
-        final ScriptObject overrides = classOverrides.get();
+    public static Object getClassOverrides() {
+        final Object overrides = classOverrides.get();
         assert overrides != null;
         return overrides;
     }
@@ -134,6 +134,22 @@
         NO_PERMISSIONS_INVOKER.invokeExact(method, arg);
     }
 
+    /**
+     * Set the current global scope
+     * @param global the global scope
+     */
+    public static void setGlobal(final Object global) {
+        Context.setGlobal((ScriptObject)global);
+    }
+
+    /**
+     * Get the current global scope
+     * @return the current global scope
+     */
+    public static Object getGlobal() {
+        return Context.getGlobal();
+    }
+
     static void setClassOverrides(ScriptObject overrides) {
         classOverrides.set(overrides);
     }
--- a/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java	Wed Apr 09 08:48:04 2014 -0700
+++ b/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java	Thu Apr 10 15:28:48 2014 -0700
@@ -39,16 +39,38 @@
  * Check java reflection permission for java reflective and java.lang.invoke access from scripts
  */
 final class ReflectionCheckLinker implements TypeBasedGuardingDynamicLinker{
+    private static final Class<?> STATEMENT_CLASS  = getBeanClass("Statement");
+    private static final Class<?> XMLENCODER_CLASS = getBeanClass("XMLEncoder");
+    private static final Class<?> XMLDECODER_CLASS = getBeanClass("XMLDecoder");
+
+    private static Class<?> getBeanClass(final String name) {
+        try {
+            return Class.forName("java.beans." + name);
+        } catch (final ClassNotFoundException cnfe) {
+            // Possible to miss this class in other profiles.
+            return null;
+        }
+    }
+
     @Override
     public boolean canLinkType(final Class<?> type) {
         return isReflectionClass(type);
     }
 
     private static boolean isReflectionClass(final Class<?> type) {
+        // Class or ClassLoader subclasses
         if (type == Class.class || ClassLoader.class.isAssignableFrom(type)) {
             return true;
         }
 
+        // check for bean reflection
+        if ((STATEMENT_CLASS != null && STATEMENT_CLASS.isAssignableFrom(type)) ||
+            (XMLENCODER_CLASS != null && XMLENCODER_CLASS.isAssignableFrom(type)) ||
+            (XMLDECODER_CLASS != null && XMLDECODER_CLASS.isAssignableFrom(type))) {
+            return true;
+        }
+
+        // package name check
         final String name = type.getName();
         return name.startsWith("java.lang.reflect.") || name.startsWith("java.lang.invoke.");
     }