changeset 1125:687430164864

8066683: nashorn test failures after modular image changes Reviewed-by: attila, jlaskey
author sundar
date Thu, 04 Dec 2014 20:40:48 +0530
parents a64d69fb8eb3
children 1c7fd53d4205
files make/build.xml src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AstDeserializer.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java test/script/basic/JDK-8066232.js
diffstat 5 files changed, 30 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/make/build.xml	Wed Dec 03 17:55:36 2014 +0000
+++ b/make/build.xml	Thu Dec 04 20:40:48 2014 +0530
@@ -36,9 +36,9 @@
          <pathelement location="${dist.dir}"/>
     </path>
     <path id="nashorn.boot.prefix.path">
-      <pathelement location="${dist.dir}"/>
+      <pathelement location="${dist.jar}"/>
     </path>
-    <property name="boot.class.path" value="-Xbootclasspath/a:=&quot;${toString:nashorn.boot.prefix.path}&quot;"/>
+    <property name="boot.class.path" value="-Xbootclasspath/p:&quot;${toString:nashorn.boot.prefix.path}&quot;"/>
     <condition property="svn.executable" value="/usr/local/bin/svn" else="svn">
       <available file="/usr/local/bin/svn"/>
     </condition>
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AstDeserializer.java	Wed Dec 03 17:55:36 2014 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AstDeserializer.java	Thu Dec 04 20:40:48 2014 +0530
@@ -27,6 +27,8 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.zip.InflaterInputStream;
 import jdk.nashorn.internal.ir.FunctionNode;
 
@@ -36,12 +38,18 @@
  */
 final class AstDeserializer {
     static FunctionNode deserialize(final byte[] serializedAst) {
-        try {
-            return (FunctionNode)new ObjectInputStream(new InflaterInputStream(new ByteArrayInputStream(
-                    serializedAst))).readObject();
-        } catch (final ClassNotFoundException | IOException e) {
-            // This is internal, can't happen
-            throw new AssertionError("Unexpected exception deserializing function", e);
-        }
+        // FIXME: do we need this doPrivileged block at all?
+        return AccessController.doPrivileged(new PrivilegedAction<FunctionNode>() {
+            @Override
+            public FunctionNode run() {
+                try {
+                    return (FunctionNode)new ObjectInputStream(new InflaterInputStream(
+                        new ByteArrayInputStream(serializedAst))).readObject();
+                } catch (final ClassNotFoundException | IOException e) {
+                    // This is internal, can't happen
+                    throw new AssertionError("Unexpected exception deserializing function", e);
+                }
+            }
+        });
     }
 }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java	Wed Dec 03 17:55:36 2014 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java	Thu Dec 04 20:40:48 2014 +0530
@@ -45,7 +45,15 @@
  * A Dynalink linker to handle web browser built-in JS (DOM etc.) objects.
  */
 final class BrowserJSObjectLinker implements TypeBasedGuardingDynamicLinker {
-    private static final ClassLoader myLoader = BrowserJSObjectLinker.class.getClassLoader();
+    private static ClassLoader extLoader;
+    static {
+        extLoader = BrowserJSObjectLinker.class.getClassLoader();
+        // in case nashorn is loaded as bootstrap!
+        if (extLoader == null) {
+            extLoader = ClassLoader.getSystemClassLoader().getParent();
+        }
+    }
+
     private static final String JSOBJECT_CLASS = "netscape.javascript.JSObject";
     // not final because this is lazily initialized
     // when we hit a subclass for the first time.
@@ -69,7 +77,7 @@
         // check if this class is a subclass of JSObject
         Class<?> clazz = type;
         while (clazz != null) {
-            if (clazz.getClassLoader() == myLoader &&
+            if (clazz.getClassLoader() == extLoader &&
                 clazz.getName().equals(JSOBJECT_CLASS)) {
                 jsObjectClass = clazz;
                 return true;
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java	Wed Dec 03 17:55:36 2014 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java	Thu Dec 04 20:40:48 2014 +0530
@@ -104,7 +104,7 @@
                     // SecurityException for nashorn's classes!. For adapter's to work, we
                     // should be able to refer to the few classes it needs in its implementation.
                     if(VISIBLE_INTERNAL_CLASS_NAMES.contains(name)) {
-                        return myLoader.loadClass(name);
+                        return myLoader != null? myLoader.loadClass(name) : Class.forName(name, false, myLoader);
                     }
                     throw se;
                 }
--- a/test/script/basic/JDK-8066232.js	Wed Dec 03 17:55:36 2014 +0000
+++ b/test/script/basic/JDK-8066232.js	Thu Dec 04 20:40:48 2014 +0530
@@ -34,3 +34,5 @@
     } catch(e if 1) {
     }
 })()
+
+print("SUCCESS");