changeset 1586:7aed4ca0e885

8140235: Clean up dynamic module creation in jake/nashorn Reviewed-by: attila, lagergren, alanb
author sundar
date Wed, 21 Oct 2015 19:47:00 +0530
parents dd1ef00eb2b0
children e7a3b9f01ae4
files src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/NashornLoader.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptLoader.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/StructureLoader.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java
diffstat 4 files changed, 45 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/NashornLoader.java	Fri Oct 16 13:41:24 2015 +0100
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/NashornLoader.java	Wed Oct 21 19:47:00 2015 +0530
@@ -94,14 +94,11 @@
     }
 
     protected static void addModuleExports(final Module from, final String pkg, final Module to) {
-        // FIXME try..catch to faciliate test run
-        try {
-            if (to == null) {
-                Modules.addExportsToAll(from, pkg);
-            } else {
-                Modules.addExports(from, pkg, to);
-            }
-        } catch (IllegalArgumentException iae) {}
+        if (to == null) {
+            Modules.addExportsToAll(from, pkg);
+        } else {
+            Modules.addExports(from, pkg, to);
+        }
     }
 
     protected static void checkPackageAccess(final String name) {
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptLoader.java	Fri Oct 16 13:41:24 2015 +0100
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptLoader.java	Wed Oct 21 19:47:00 2015 +0530
@@ -50,16 +50,22 @@
     ScriptLoader(final ClassLoader parent, final Context context) {
         super(parent);
         this.context = context;
-        scriptModule = defineModule("nashorn.scripts", this);
-        addModuleExports(nashornModule, OBJECTS_PKG, scriptModule);
-        addModuleExports(nashornModule, RUNTIME_PKG, scriptModule);
-        addModuleExports(nashornModule, RUNTIME_ARRAYS_PKG, scriptModule);
-        addModuleExports(nashornModule, RUNTIME_LINKER_PKG, scriptModule);
-        addModuleExports(nashornModule, SCRIPTS_PKG, scriptModule);
+
+        // new scripts module, it's specific exports and read-edges
+        scriptModule = defineModule("jdk.scripting.nashorn.scripts", this);
         addModuleExports(scriptModule, SCRIPTS_PKG, nashornModule);
         addReadsModule(scriptModule, nashornModule);
-        addReadsModule(nashornModule, scriptModule);
         addReadsModule(scriptModule, Object.class.getModule());
+
+        // specific exports from nashorn to new scripts module
+        nashornModule.addExports(OBJECTS_PKG, scriptModule);
+        nashornModule.addExports(RUNTIME_PKG, scriptModule);
+        nashornModule.addExports(RUNTIME_ARRAYS_PKG, scriptModule);
+        nashornModule.addExports(RUNTIME_LINKER_PKG, scriptModule);
+        nashornModule.addExports(SCRIPTS_PKG, scriptModule);
+
+        // nashorn needs to read scripts module methods,fields
+        nashornModule.addReads(scriptModule);
     }
 
     @Override
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/StructureLoader.java	Fri Oct 16 13:41:24 2015 +0100
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/StructureLoader.java	Wed Oct 21 19:47:00 2015 +0530
@@ -48,13 +48,19 @@
      */
     StructureLoader(final ClassLoader parent) {
         super(parent);
-        structuresModule = defineModule("nashorn.structures", this);
-        addModuleExports(nashornModule, SCRIPTS_PKG, structuresModule);
-        addModuleExports(nashornModule, RUNTIME_PKG, structuresModule);
+
+        // new structures module, it's exports, read edges
+        structuresModule = defineModule("jdk.scripting.nashorn.structures", this);
         addModuleExports(structuresModule, SCRIPTS_PKG, nashornModule);
         addReadsModule(structuresModule, nashornModule);
-        addReadsModule(nashornModule, structuresModule);
         addReadsModule(structuresModule, Object.class.getModule());
+
+        // specific exports from nashorn to the structures module
+        nashornModule.addExports(SCRIPTS_PKG, structuresModule);
+        nashornModule.addExports(RUNTIME_PKG, structuresModule);
+
+        // nashorn has to read fields from classes of the new module
+        nashornModule.addReads(structuresModule);
     }
 
     /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java	Fri Oct 16 13:41:24 2015 +0100
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java	Wed Oct 21 19:47:00 2015 +0530
@@ -94,15 +94,11 @@
     }
 
     private static void addExports(final Module from, final String pkg, final Module to) {
-        // FIXME: jtreg tests need to add @module which results in blanket export
-        // and this specific export fails because of such blanket export!
-        try {
-            if (to == null) {
-                Modules.addExportsToAll(from, pkg);
-            } else {
-                Modules.addExports(from, pkg, to);
-            }
-        } catch (final IllegalArgumentException ignore) {}
+        if (to == null) {
+            Modules.addExportsToAll(from, pkg);
+        } else {
+            Modules.addExports(from, pkg, to);
+        }
     }
 
     // Note that the adapter class is created in the protection domain of the class/interface being
@@ -115,18 +111,25 @@
     private ClassLoader createClassLoader(final ClassLoader parentLoader, final ProtectionDomain protectionDomain) {
         return new SecureClassLoader(parentLoader) {
             private final ClassLoader myLoader = getClass().getClassLoader();
-            private final Module adapterModule = Modules.defineModule(this, "nashorn.javaadapters", adapterPkgs);
+
+            // new adapter module
+            private final Module adapterModule = Modules.defineModule(this, "jdk.scripting.nashorn.javaadapters", adapterPkgs);
 
             {
+                // new adapter module exports and read-edges
+                addExports(adapterModule, JavaAdapterBytecodeGenerator.ADAPTER_PACKAGE, null);
                 Modules.addReads(adapterModule, nashornModule);
                 Modules.addReads(adapterModule, Object.class.getModule());
-                Modules.addReads(nashornModule, adapterModule);
-                addExports(nashornModule, "jdk.nashorn.internal.runtime", adapterModule);
-                addExports(nashornModule, "jdk.nashorn.internal.runtime.linker", adapterModule);
-                addExports(adapterModule, JavaAdapterBytecodeGenerator.ADAPTER_PACKAGE, null);
                 for (Module mod : accessedModules) {
                     Modules.addReads(adapterModule, mod);
                 }
+
+                // specific exports from nashorn to the new adapter module
+                nashornModule.addExports("jdk.nashorn.internal.runtime", adapterModule);
+                nashornModule.addExports("jdk.nashorn.internal.runtime.linker", adapterModule);
+
+                // nashorn should be be able to read methods of classes loaded in adapter module
+                nashornModule.addReads(adapterModule);
             }
 
             @Override