8066683: nashorn test failures after modular image changes
authorsundar
Thu, 04 Dec 2014 20:40:48 +0530
changeset 27825 cbb30ab946ee
parent 27824 ab74da77b5a2
child 27826 605a589e33ca
8066683: nashorn test failures after modular image changes Reviewed-by: attila, jlaskey
nashorn/make/build.xml
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AstDeserializer.java
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java
nashorn/test/script/basic/JDK-8066232.js
--- a/nashorn/make/build.xml	Wed Dec 03 17:55:36 2014 +0000
+++ b/nashorn/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/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AstDeserializer.java	Wed Dec 03 17:55:36 2014 +0000
+++ b/nashorn/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/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/BrowserJSObjectLinker.java	Wed Dec 03 17:55:36 2014 +0000
+++ b/nashorn/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/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java	Wed Dec 03 17:55:36 2014 +0000
+++ b/nashorn/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/nashorn/test/script/basic/JDK-8066232.js	Wed Dec 03 17:55:36 2014 +0000
+++ b/nashorn/test/script/basic/JDK-8066232.js	Thu Dec 04 20:40:48 2014 +0530
@@ -34,3 +34,5 @@
     } catch(e if 1) {
     }
 })()
+
+print("SUCCESS");