8165896: Use "open" flag from JVM_DefineModule to export all module packages
authorrprotacio
Mon, 24 Apr 2017 12:08:28 -0400
changeset 46404 ae62ba99a1a7
parent 46403 f2b91b928476
child 46406 42db25fd251f
8165896: Use "open" flag from JVM_DefineModule to export all module packages Summary: Implemented VM side of open modules, which export all their packages unqualifiedly. Automatic modules and unnamed modules are treated internally as open modules. Reviewed-by: alanb, hseigel, lfoltan
hotspot/src/share/vm/classfile/classLoader.cpp
hotspot/src/share/vm/classfile/moduleEntry.cpp
hotspot/src/share/vm/classfile/moduleEntry.hpp
hotspot/src/share/vm/classfile/modules.cpp
hotspot/src/share/vm/classfile/modules.hpp
hotspot/src/share/vm/classfile/packageEntry.cpp
hotspot/src/share/vm/classfile/packageEntry.hpp
hotspot/src/share/vm/prims/jvm.cpp
hotspot/src/share/vm/prims/whitebox.cpp
hotspot/src/share/vm/runtime/reflection.cpp
hotspot/test/runtime/modules/AccessCheckAllUnnamed.java
hotspot/test/runtime/modules/AccessCheckExp.java
hotspot/test/runtime/modules/AccessCheckJavaBase.java
hotspot/test/runtime/modules/AccessCheckOpen.java
hotspot/test/runtime/modules/AccessCheckRead.java
hotspot/test/runtime/modules/AccessCheckSuper.java
hotspot/test/runtime/modules/AccessCheckUnnamed.java
hotspot/test/runtime/modules/AccessCheckWorks.java
hotspot/test/runtime/modules/CCE_module_msg.java
hotspot/test/runtime/modules/ExportTwice.java
hotspot/test/runtime/modules/JVMAddModuleExportToAllUnnamed.java
hotspot/test/runtime/modules/JVMAddModuleExports.java
hotspot/test/runtime/modules/JVMAddModuleExportsToAll.java
hotspot/test/runtime/modules/JVMAddModulePackage.java
hotspot/test/runtime/modules/JVMAddReadsModule.java
hotspot/test/runtime/modules/JVMDefineModule.java
hotspot/test/runtime/modules/LoadUnloadModuleStress.java
hotspot/test/runtime/modules/ModuleHelper.java
--- a/hotspot/src/share/vm/classfile/classLoader.cpp	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/src/share/vm/classfile/classLoader.cpp	Mon Apr 24 12:08:28 2017 -0400
@@ -1720,7 +1720,8 @@
 
   {
     MutexLocker ml(Module_lock, THREAD);
-    ModuleEntry* jb_module = null_cld_modules->locked_create_entry_or_null(Handle(), vmSymbols::java_base(), NULL, NULL, null_cld);
+    ModuleEntry* jb_module = null_cld_modules->locked_create_entry_or_null(Handle(),
+                               false, vmSymbols::java_base(), NULL, NULL, null_cld);
     if (jb_module == NULL) {
       vm_exit_during_initialization("Unable to create ModuleEntry for " JAVA_BASE_NAME);
     }
--- a/hotspot/src/share/vm/classfile/moduleEntry.cpp	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/src/share/vm/classfile/moduleEntry.cpp	Mon Apr 24 12:08:28 2017 -0400
@@ -172,6 +172,12 @@
   }
 }
 
+// Set whether the module is open, i.e. all its packages are unqualifiedly exported
+void ModuleEntry::set_is_open(bool is_open) {
+  assert_lock_strong(Module_lock);
+  _is_open = is_open;
+}
+
 // Returns true if the module has a non-empty reads list. As such, the unnamed
 // module will return false.
 bool ModuleEntry::has_reads_list() const {
@@ -271,6 +277,7 @@
   }
 
   entry->set_loader_data(cld);
+  entry->_is_open = true;
 
   TRACE_INIT_ID(entry);
 
@@ -324,7 +331,8 @@
   free_buckets();
 }
 
-ModuleEntry* ModuleEntryTable::new_entry(unsigned int hash, Handle module_handle, Symbol* name,
+ModuleEntry* ModuleEntryTable::new_entry(unsigned int hash, Handle module_handle,
+                                         bool is_open, Symbol* name,
                                          Symbol* version, Symbol* location,
                                          ClassLoaderData* loader_data) {
   assert(Module_lock->owned_by_self(), "should have the Module_lock");
@@ -351,6 +359,7 @@
   entry->set_loader_data(loader_data);
   entry->set_version(version);
   entry->set_location(location);
+  entry->set_is_open(is_open);
 
   if (ClassLoader::is_in_patch_mod_entries(name)) {
     entry->set_is_patched();
@@ -371,6 +380,7 @@
 }
 
 ModuleEntry* ModuleEntryTable::locked_create_entry_or_null(Handle module_handle,
+                                                           bool is_open,
                                                            Symbol* module_name,
                                                            Symbol* module_version,
                                                            Symbol* module_location,
@@ -381,7 +391,7 @@
   if (lookup_only(module_name) != NULL) {
     return NULL;
   } else {
-    ModuleEntry* entry = new_entry(compute_hash(module_name), module_handle, module_name,
+    ModuleEntry* entry = new_entry(compute_hash(module_name), module_handle, is_open, module_name,
                                    module_version, module_location, loader_data);
     add_entry(index_for(module_name), entry);
     return entry;
--- a/hotspot/src/share/vm/classfile/moduleEntry.hpp	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/src/share/vm/classfile/moduleEntry.hpp	Mon Apr 24 12:08:28 2017 -0400
@@ -65,6 +65,7 @@
   bool _can_read_all_unnamed;
   bool _has_default_read_edges;        // JVMTI redefine/retransform support
   bool _must_walk_reads;               // walk module's reads list at GC safepoints to purge out dead modules
+  bool _is_open;                       // whether the packages in the module are all unqualifiedly exported
   bool _is_patched;                    // whether the module is patched via --patch-module
   TRACE_DEFINE_TRACE_ID_FIELD;
   enum {MODULE_READS_SIZE = 101};      // Initial size of list of modules that the module can read.
@@ -81,6 +82,7 @@
     _has_default_read_edges = false;
     _must_walk_reads = false;
     _is_patched = false;
+    _is_open = false;
   }
 
   Symbol*          name() const                        { return literal(); }
@@ -112,6 +114,9 @@
   void             add_read(ModuleEntry* m);
   void             set_read_walk_required(ClassLoaderData* m_loader_data);
 
+  bool             is_open() const                     { return _is_open; }
+  void             set_is_open(bool is_open);
+
   bool             is_named() const                    { return (name() != NULL); }
 
   bool can_read_all_unnamed() const {
@@ -198,8 +203,8 @@
 private:
   static ModuleEntry* _javabase_module;
 
-  ModuleEntry* new_entry(unsigned int hash, Handle module_handle, Symbol* name, Symbol* version,
-                         Symbol* location, ClassLoaderData* loader_data);
+  ModuleEntry* new_entry(unsigned int hash, Handle module_handle, bool is_open,
+                         Symbol* name, Symbol* version, Symbol* location, ClassLoaderData* loader_data);
   void add_entry(int index, ModuleEntry* new_entry);
 
   int entry_size() const { return BasicHashtable<mtModule>::entry_size(); }
@@ -222,6 +227,7 @@
   // Create module in loader's module entry table, if already exists then
   // return null.  Assume Module_lock has been locked by caller.
   ModuleEntry* locked_create_entry_or_null(Handle module_handle,
+                                           bool is_open,
                                            Symbol* module_name,
                                            Symbol* module_version,
                                            Symbol* module_location,
--- a/hotspot/src/share/vm/classfile/modules.cpp	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/src/share/vm/classfile/modules.cpp	Mon Apr 24 12:08:28 2017 -0400
@@ -238,9 +238,11 @@
                      pkg_list->length());
 
   // packages defined to java.base
-  for (int x = 0; x < pkg_list->length(); x++) {
-    log_trace(modules)("define_javabase_module(): creation of package %s for module " JAVA_BASE_NAME,
-                       (pkg_list->at(x))->as_C_string());
+  if (log_is_enabled(Trace, modules)) {
+    for (int x = 0; x < pkg_list->length(); x++) {
+      log_trace(modules)("define_javabase_module(): creation of package %s for module " JAVA_BASE_NAME,
+                         (pkg_list->at(x))->as_C_string());
+    }
   }
 }
 
@@ -258,7 +260,7 @@
   }
 }
 
-void Modules::define_module(jobject module, jstring version,
+void Modules::define_module(jobject module, jboolean is_open, jstring version,
                             jstring location, const char* const* packages,
                             jsize num_packages, TRAPS) {
   ResourceMark rm(THREAD);
@@ -291,6 +293,7 @@
 
   // Special handling of java.base definition
   if (strcmp(module_name, JAVA_BASE_NAME) == 0) {
+    assert(is_open == JNI_FALSE, "java.base module cannot be open");
     define_javabase_module(module, version, location, packages, num_packages, CHECK);
     return;
   }
@@ -394,7 +397,8 @@
     // Add the module and its packages.
     if (!dupl_modules && existing_pkg == NULL) {
       // Create the entry for this module in the class loader's module entry table.
-      ModuleEntry* module_entry = module_table->locked_create_entry_or_null(module_handle, module_symbol,
+      ModuleEntry* module_entry = module_table->locked_create_entry_or_null(module_handle,
+                                    (is_open == JNI_TRUE), module_symbol,
                                     version_symbol, location_symbol, loader_data);
 
       if (module_entry == NULL) {
@@ -502,8 +506,8 @@
               "from_module cannot be found");
   }
 
-  // All packages in unnamed are exported by default.
-  if (!from_module_entry->is_named()) return;
+  // All packages in unnamed and open modules are exported by default.
+  if (!from_module_entry->is_named() || from_module_entry->is_open()) return;
 
   ModuleEntry* to_module_entry;
   if (to_module == NULL) {
--- a/hotspot/src/share/vm/classfile/modules.hpp	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/src/share/vm/classfile/modules.hpp	Mon Apr 24 12:08:28 2017 -0400
@@ -50,7 +50,7 @@
   // * num_packages is negative
   // * num_packages is non-zero when packages is null
   //  NullPointerExceptions are thrown if module is null.
-  static void define_module(jobject module, jstring version,
+  static void define_module(jobject module, jboolean is_open, jstring version,
                             jstring location, const char* const* packages,
                             jsize num_packages, TRAPS);
 
--- a/hotspot/src/share/vm/classfile/packageEntry.cpp	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/src/share/vm/classfile/packageEntry.cpp	Mon Apr 24 12:08:28 2017 -0400
@@ -101,7 +101,6 @@
     // NULL indicates the package is being unqualifiedly exported.  Clean up
     // the qualified list at the next safepoint.
     set_unqual_exported();
-
   } else {
     // Add the exported module
     add_qexport(m);
@@ -111,6 +110,11 @@
 // Set the package as exported to all unnamed modules unless the package is
 // already unqualifiedly exported.
 void PackageEntry::set_is_exported_allUnnamed() {
+  if (module()->is_open()) {
+    // No-op for open modules since all packages are unqualifiedly exported
+    return;
+  }
+
   MutexLocker m1(Module_lock);
   if (!is_unqual_exported()) {
    _export_flags = PKG_EXP_ALLUNNAMED;
@@ -208,11 +212,6 @@
   // Initialize fields specific to a PackageEntry
   entry->init();
   entry->name()->increment_refcount();
-  if (!module->is_named()) {
-    // Set the exported state to true because all packages
-    // within the unnamed module are unqualifiedly exported
-    entry->set_unqual_exported();
-  }
   entry->set_module(module);
   return entry;
 }
--- a/hotspot/src/share/vm/classfile/packageEntry.hpp	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/src/share/vm/classfile/packageEntry.hpp	Mon Apr 24 12:08:28 2017 -0400
@@ -128,7 +128,9 @@
   // package's export state
   bool is_exported() const { // qualifiedly or unqualifiedly exported
     assert_locked_or_safepoint(Module_lock);
-    return ((_export_flags & PKG_EXP_UNQUALIFIED_OR_ALL_UNAMED) != 0) || has_qual_exports_list();
+    return module()->is_open() ||
+            ((_export_flags & PKG_EXP_UNQUALIFIED_OR_ALL_UNAMED) != 0) ||
+            has_qual_exports_list();
   }
   // Returns true if the package has any explicit qualified exports or is exported to all unnamed
   bool is_qual_exported() const {
@@ -145,16 +147,20 @@
   }
   bool is_exported_allUnnamed() const {
     assert_locked_or_safepoint(Module_lock);
-    return (_export_flags == PKG_EXP_ALLUNNAMED);
+    return (module()->is_open() || _export_flags == PKG_EXP_ALLUNNAMED);
   }
   bool is_unqual_exported() const {
     assert_locked_or_safepoint(Module_lock);
-    return (_export_flags == PKG_EXP_UNQUALIFIED);
+    return (module()->is_open() || _export_flags == PKG_EXP_UNQUALIFIED);
   }
 
   // Explicitly set _export_flags to PKG_EXP_UNQUALIFIED and clear
   // PKG_EXP_ALLUNNAMED, if it was set.
   void set_unqual_exported() {
+    if (module()->is_open()) {
+        // No-op for open modules since all packages are unqualifiedly exported
+        return;
+    }
     assert(Module_lock->owned_by_self(), "should have the Module_lock");
     _export_flags = PKG_EXP_UNQUALIFIED;
   }
--- a/hotspot/src/share/vm/prims/jvm.cpp	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/src/share/vm/prims/jvm.cpp	Mon Apr 24 12:08:28 2017 -0400
@@ -1009,7 +1009,7 @@
 JVM_ENTRY(void, JVM_DefineModule(JNIEnv *env, jobject module, jboolean is_open, jstring version,
                                  jstring location, const char* const* packages, jsize num_packages))
   JVMWrapper("JVM_DefineModule");
-  Modules::define_module(module, version, location, packages, num_packages, CHECK);
+  Modules::define_module(module, is_open, version, location, packages, num_packages, CHECK);
 JVM_END
 
 JVM_ENTRY(void, JVM_SetBootLoaderUnnamedModule(JNIEnv *env, jobject module))
--- a/hotspot/src/share/vm/prims/whitebox.cpp	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/src/share/vm/prims/whitebox.cpp	Mon Apr 24 12:08:28 2017 -0400
@@ -1467,8 +1467,8 @@
   MetadataFactory::free_array(cld, (Array<u1>*)(uintptr_t)addr);
 WB_END
 
-WB_ENTRY(void, WB_DefineModule(JNIEnv* env, jobject o, jobject module, jstring version, jstring location,
-                                jobjectArray packages))
+WB_ENTRY(void, WB_DefineModule(JNIEnv* env, jobject o, jobject module, jboolean is_open,
+                                jstring version, jstring location, jobjectArray packages))
   ResourceMark rm(THREAD);
 
   objArrayOop packages_oop = objArrayOop(JNIHandles::resolve(packages));
@@ -1487,7 +1487,7 @@
       pkgs[x] = java_lang_String::as_utf8_string(pkg_str);
     }
   }
-  Modules::define_module(module, version, location, (const char* const*)pkgs, num_packages, CHECK);
+  Modules::define_module(module, is_open, version, location, (const char* const*)pkgs, num_packages, CHECK);
 WB_END
 
 WB_ENTRY(void, WB_AddModuleExports(JNIEnv* env, jobject o, jobject from_module, jstring package, jobject to_module))
@@ -1959,7 +1959,7 @@
   {CC"getCodeBlob",        CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob        },
   {CC"getThreadStackSize", CC"()J",                   (void*)&WB_GetThreadStackSize },
   {CC"getThreadRemainingStackSize", CC"()J",          (void*)&WB_GetThreadRemainingStackSize },
-  {CC"DefineModule",       CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
+  {CC"DefineModule",       CC"(Ljava/lang/Object;ZLjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
                                                       (void*)&WB_DefineModule },
   {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
                                                       (void*)&WB_AddModuleExports },
--- a/hotspot/src/share/vm/runtime/reflection.cpp	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/src/share/vm/runtime/reflection.cpp	Mon Apr 24 12:08:28 2017 -0400
@@ -464,8 +464,9 @@
  Caller S in package     If MS is loose: YES      If same classloader/package (PS == PT): YES
  PS, runtime module MS   If MS can read T's       If same runtime module: (MS == MT): YES
                          unnamed module: YES
-                                                  Else if (MS can read MT (Establish readability) &&
-                                                    MT exports PT to MS or to all modules): YES
+                                                  Else if (MS can read MT (establish readability) &&
+                                                    ((MT exports PT to MS or to all modules) ||
+                                                     (MT is open))): YES
 
  ------------------------------------------------------------------------------------------------
  Caller S in unnamed         YES                  Readability exists because unnamed module
@@ -511,7 +512,7 @@
       return ACCESS_OK;
     }
 
-    // Acceptable access to a type in an unamed module.  Note that since
+    // Acceptable access to a type in an unnamed module. Note that since
     // unnamed modules can read all unnamed modules, this also handles the
     // case where module_from is also unnamed but in a different class loader.
     if (!module_to->is_named() &&
@@ -524,6 +525,11 @@
       return MODULE_NOT_READABLE;
     }
 
+    // Access is allowed if module_to is open, i.e. all its packages are unqualifiedly exported
+    if (module_to->is_open()) {
+      return ACCESS_OK;
+    }
+
     PackageEntry* package_to = new_class->package();
     assert(package_to != NULL, "can not obtain new_class' package");
 
--- a/hotspot/test/runtime/modules/AccessCheckAllUnnamed.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/AccessCheckAllUnnamed.java	Mon Apr 24 12:08:28 2017 -0400
@@ -56,13 +56,13 @@
         // Define a module for p3.
         m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p3" });
         assertNotNull(m1x, "Module should not be null");
-        ModuleHelper.DefineModule(m1x, "9.0", "m1x/there", new String[] { "p3" });
+        ModuleHelper.DefineModule(m1x, false, "9.0", "m1x/there", new String[] { "p3" });
         ModuleHelper.AddReadsModule(m1x, jlM);
 
         // Define a module for p2.
         m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
         assertNotNull(m2x, "Module should not be null");
-        ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+        ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "p2" });
         ModuleHelper.AddReadsModule(m2x, jlM);
 
         try {
--- a/hotspot/test/runtime/modules/AccessCheckExp.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/AccessCheckExp.java	Mon Apr 24 12:08:28 2017 -0400
@@ -55,13 +55,13 @@
         // Define a module for p1.
         m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
         assertNotNull(m1x, "Module should not be null");
-        ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
+        ModuleHelper.DefineModule(m1x, false, "9.0", "m1x/here", new String[] { "p1" });
         ModuleHelper.AddReadsModule(m1x, jlObject_jlM);
 
         // Define a module for p2.
         m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
         assertNotNull(m2x, "Module should not be null");
-        ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+        ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "p2" });
         ModuleHelper.AddReadsModule(m2x, jlObject_jlM);
 
         // Make package p1 in m1x visible to everyone.
@@ -74,7 +74,7 @@
         Class p1_c1_class = Class.forName("p1.c1");
         try {
             p1_c1_class.newInstance();
-            throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported");
+            throw new RuntimeException("Failed to get IAE (p2 in m2x is not exported)");
         } catch (IllegalAccessError f) {
             System.out.println(f.getMessage());
             if (!f.getMessage().contains("does not export")) {
--- a/hotspot/test/runtime/modules/AccessCheckJavaBase.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/AccessCheckJavaBase.java	Mon Apr 24 12:08:28 2017 -0400
@@ -46,7 +46,7 @@
         // Define a module for p2.
         Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
         assertNotNull(m2x, "Module should not be null");
-        ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+        ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "p2" });
 
         // p2.c2 can read its superclass java.lang.Object defined within java.base
         try {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/modules/AccessCheckOpen.java	Mon Apr 24 12:08:28 2017 -0400
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @modules java.base/jdk.internal.misc
+ * @library /test/lib ..
+ * @compile p2/c2.java
+ * @compile p1/c1.java
+ * @build sun.hotspot.WhiteBox
+ * @compile/module=java.base java/lang/ModuleHelper.java
+ * @run main ClassFileInstaller sun.hotspot.WhiteBox
+ *                              sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI AccessCheckOpen
+ */
+
+import java.lang.Module;
+import static jdk.test.lib.Asserts.*;
+
+public class AccessCheckOpen {
+
+    // Test that if module1 can read module2 and module2 is open, then
+    // p1.c1 can read p2.c2
+    public static void main(String args[]) throws Throwable {
+        Object m1, m2;
+
+        // Get the java.lang.Module object for module java.base
+        Class jlObject = Class.forName("java.lang.Object");
+        Object jlObject_jlM = jlObject.getModule();
+        assertNotNull(jlObject_jlM, "jlModule object of java.lang.Object should not be null");
+
+        // Get the class loader for AccessCheckOpen, which is also used to
+        // load classes p1.c1 and p2.c2
+        ClassLoader this_cldr = AccessCheckOpen.class.getClassLoader();
+
+        // Define a module for p1
+        m1 = ModuleHelper.ModuleObject("module1", this_cldr, new String[] { "p1" });
+        assertNotNull(m1, "Module should not be null");
+        ModuleHelper.DefineModule(m1, false, "9.0", "m1/here", new String[] { "p1" });
+        ModuleHelper.AddReadsModule(m1, jlObject_jlM);
+
+        // Define a module for p2
+        m2 = ModuleHelper.ModuleObject("module2", this_cldr, new String[] { "p2" });
+        assertNotNull(m2, "Module should not be null");
+        ModuleHelper.DefineModule(m2, true, "9.0", "m2/there", new String[] { "p2" });
+        ModuleHelper.AddReadsModule(m2, jlObject_jlM);
+
+        // Make package p1 in m1 visible to everyone so this test can run it
+        ModuleHelper.AddModuleExportsToAll(m1, "p1");
+
+        // Let m1 read m2
+        ModuleHelper.AddReadsModule(m1, m2);
+
+        // p1.c1's ctor calls a method in p2.c2, and m2 is open.
+        // So should not get IllegalAccessError
+        Class p1_c1_class = Class.forName("p1.c1");
+        p1_c1_class.newInstance();
+    }
+}
+
--- a/hotspot/test/runtime/modules/AccessCheckRead.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/AccessCheckRead.java	Mon Apr 24 12:08:28 2017 -0400
@@ -55,13 +55,13 @@
         // Define a module for p1.
         m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
         assertNotNull(m1x, "Module should not be null");
-        ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
+        ModuleHelper.DefineModule(m1x, false, "9.0", "m1x/here", new String[] { "p1" });
         ModuleHelper.AddReadsModule(m1x, jlObject_jlM);
 
         // Define a module for p2.
         m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
         assertNotNull(m2x, "Module should not be null");
-        ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+        ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "p2" });
         ModuleHelper.AddReadsModule(m2x, jlObject_jlM);
 
         // Make package p1 in m1x visible to everyone.
--- a/hotspot/test/runtime/modules/AccessCheckSuper.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/AccessCheckSuper.java	Mon Apr 24 12:08:28 2017 -0400
@@ -49,12 +49,12 @@
         // Define a module for p2.
         Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
         assertNotNull(m2x, "Module should not be null");
-        ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+        ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "p2" });
 
         // Define a module for p3.
         Object m3x = ModuleHelper.ModuleObject("module_three", this_cldr, new String[] { "p3" });
         assertNotNull(m3x, "Module should not be null");
-        ModuleHelper.DefineModule(m3x, "9.0", "m3x/there", new String[] { "p3" });
+        ModuleHelper.DefineModule(m3x, false, "9.0", "m3x/there", new String[] { "p3" });
 
         // Since a readability edge has not been established between module_two
         // and module_three, p3.c3 cannot read its superclass p2.c2.
--- a/hotspot/test/runtime/modules/AccessCheckUnnamed.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/AccessCheckUnnamed.java	Mon Apr 24 12:08:28 2017 -0400
@@ -55,7 +55,7 @@
         // Define a module for p2.
         m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
         assertNotNull(m2x, "Module should not be null");
-        ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+        ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "p2" });
         ModuleHelper.AddReadsModule(m2x, jlObject_jlM);
 
         // p1.c1's ctor tries to call a method in p2.c2.  This should fail because
--- a/hotspot/test/runtime/modules/AccessCheckWorks.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/AccessCheckWorks.java	Mon Apr 24 12:08:28 2017 -0400
@@ -56,13 +56,13 @@
         // Define a module for p1.
         m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
         assertNotNull(m1x, "Module should not be null");
-        ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
+        ModuleHelper.DefineModule(m1x, false, "9.0", "m1x/here", new String[] { "p1" });
         ModuleHelper.AddReadsModule(m1x, jlObject_jlM);
 
         // Define a module for p2.
         m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
         assertNotNull(m2x, "Module should not be null");
-        ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+        ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "p2" });
         ModuleHelper.AddReadsModule(m2x, jlObject_jlM);
 
         // Make package p1 in m1x visible to everyone.
--- a/hotspot/test/runtime/modules/CCE_module_msg.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/CCE_module_msg.java	Mon Apr 24 12:08:28 2017 -0400
@@ -84,7 +84,7 @@
         // Define a module for p2.
         Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
         assertNotNull(m2x, "Module should not be null");
-        ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+        ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "p2" });
         ModuleHelper.AddReadsModule(m2x, jlObject_jlM);
 
         try {
--- a/hotspot/test/runtime/modules/ExportTwice.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/ExportTwice.java	Mon Apr 24 12:08:28 2017 -0400
@@ -57,19 +57,19 @@
         // Define a module for p1.
         m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
         assertNotNull(m1x, "Module should not be null");
-        ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
+        ModuleHelper.DefineModule(m1x, false, "9.0", "m1x/here", new String[] { "p1" });
         ModuleHelper.AddReadsModule(m1x, jlObject_jlM);
 
         // Define a module for p2.
         m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
         assertNotNull(m2x, "Module should not be null");
-        ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+        ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "p2" });
         ModuleHelper.AddReadsModule(m2x, jlObject_jlM);
 
         // Define a module for p3.
         m3x = ModuleHelper.ModuleObject("module_three", this_cldr, new String[] { "p3" });
         assertNotNull(m3x, "Module should not be null");
-        ModuleHelper.DefineModule(m3x, "9.0", "m3x/there", new String[] { "p3" });
+        ModuleHelper.DefineModule(m3x, false, "9.0", "m3x/there", new String[] { "p3" });
         ModuleHelper.AddReadsModule(m3x, jlObject_jlM);
 
         // Make package p1 in m1x visible to everyone.
--- a/hotspot/test/runtime/modules/JVMAddModuleExportToAllUnnamed.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/JVMAddModuleExportToAllUnnamed.java	Mon Apr 24 12:08:28 2017 -0400
@@ -55,7 +55,7 @@
         // Define a module for p1.
         m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p1" });
         assertNotNull(m1x, "Module should not be null");
-        ModuleHelper.DefineModule(m1x, "9.0", "m1x/here", new String[] { "p1" });
+        ModuleHelper.DefineModule(m1x, false, "9.0", "m1x/here", new String[] { "p1" });
         ModuleHelper.AddReadsModule(m1x, jlObject_jlM);
 
         // Make package p1 in m1x visible to everyone.
--- a/hotspot/test/runtime/modules/JVMAddModuleExports.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/JVMAddModuleExports.java	Mon Apr 24 12:08:28 2017 -0400
@@ -43,10 +43,10 @@
 
         from_module = ModuleHelper.ModuleObject("from_module", from_cl, new String[] { "mypackage", "this/package" });
         assertNotNull(from_module, "Module should not be null");
-        ModuleHelper.DefineModule(from_module, "9.0", "from_module/here", new String[] { "mypackage", "this/package" });
+        ModuleHelper.DefineModule(from_module, false, "9.0", "from_module/here", new String[] { "mypackage", "this/package" });
         to_module = ModuleHelper.ModuleObject("to_module", to_cl, new String[] { "yourpackage", "that/package" });
         assertNotNull(to_module, "Module should not be null");
-        ModuleHelper.DefineModule(to_module, "9.0", "to_module/here", new String[] { "yourpackage", "that/package" });
+        ModuleHelper.DefineModule(to_module, false, "9.0", "to_module/here", new String[] { "yourpackage", "that/package" });
 
         // Null from_module argument, expect an NPE
         try {
--- a/hotspot/test/runtime/modules/JVMAddModuleExportsToAll.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/JVMAddModuleExportsToAll.java	Mon Apr 24 12:08:28 2017 -0400
@@ -56,13 +56,13 @@
         // Define a module for p3.
         m1x = ModuleHelper.ModuleObject("module_one", this_cldr, new String[] { "p3" });
         assertNotNull(m1x, "Module should not be null");
-        ModuleHelper.DefineModule(m1x, "9.0", "m1x/there", new String[] { "p3" });
+        ModuleHelper.DefineModule(m1x, false, "9.0", "m1x/there", new String[] { "p3" });
         ModuleHelper.AddReadsModule(m1x, jlObject_jlM);
 
         // Define a module for p2.
         m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
         assertNotNull(m2x, "Module should not be null");
-        ModuleHelper.DefineModule(m2x, "9.0", "m2x/there", new String[] { "p2" });
+        ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "p2" });
         ModuleHelper.AddReadsModule(m2x, jlObject_jlM);
 
         try {
@@ -104,7 +104,7 @@
         // of p2 in m2x to m3x.  This should not affect the unqualified export.
         m3x = ModuleHelper.ModuleObject("module_three", this_cldr, new String[] { "p4" });
         assertNotNull(m3x, "Module m3x should not be null");
-        ModuleHelper.DefineModule(m3x, "9.0", "m3x/there", new String[] { "p4" });
+        ModuleHelper.DefineModule(m3x, false, "9.0", "m3x/there", new String[] { "p4" });
         ModuleHelper.AddModuleExportsToAll(m2x, "p2");
         ModuleHelper.AddModuleExports(m2x, "p2", m3x);
 
--- a/hotspot/test/runtime/modules/JVMAddModulePackage.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/JVMAddModulePackage.java	Mon Apr 24 12:08:28 2017 -0400
@@ -45,13 +45,13 @@
 
         module_one = ModuleHelper.ModuleObject("module_one", cl1, new String[] { "mypackage" });
         assertNotNull(module_one, "Module should not be null");
-        ModuleHelper.DefineModule(module_one, "9.0", "module_one/here", new String[] { "mypackage" });
+        ModuleHelper.DefineModule(module_one, false, "9.0", "module_one/here", new String[] { "mypackage" });
         module_two = ModuleHelper.ModuleObject("module_two", cl1, new String[] { "yourpackage" });
         assertNotNull(module_two, "Module should not be null");
-        ModuleHelper.DefineModule(module_two, "9.0", "module_two/here", new String[] { "yourpackage" });
+        ModuleHelper.DefineModule(module_two, false, "9.0", "module_two/here", new String[] { "yourpackage" });
         module_three = ModuleHelper.ModuleObject("module_three", cl3, new String[] { "package/num3" });
         assertNotNull(module_three, "Module should not be null");
-        ModuleHelper.DefineModule(module_three, "9.0", "module_three/here", new String[] { "package/num3" });
+        ModuleHelper.DefineModule(module_three, false, "9.0", "module_three/here", new String[] { "package/num3" });
 
         // Simple call
         ModuleHelper.AddModulePackage(module_one, "new_package");
--- a/hotspot/test/runtime/modules/JVMAddReadsModule.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/JVMAddReadsModule.java	Mon Apr 24 12:08:28 2017 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -43,11 +43,11 @@
 
         from_module = ModuleHelper.ModuleObject("from_module", from_cl, new String[] { "mypackage" });
         assertNotNull(from_module, "Module should not be null");
-        ModuleHelper.DefineModule(from_module, "9.0", "from_module/here", new String[] { "mypackage" });
+        ModuleHelper.DefineModule(from_module, false, "9.0", "from_module/here", new String[] { "mypackage" });
 
         to_module = ModuleHelper.ModuleObject("to_module", to_cl, new String[] { "yourpackage" });
         assertNotNull(to_module, "Module should not be null");
-        ModuleHelper.DefineModule(to_module, "9.0", "to_module/here", new String[] { "yourpackage" });
+        ModuleHelper.DefineModule(to_module, false, "9.0", "to_module/here", new String[] { "yourpackage" });
 
         // Null from_module argument, expect NPE
         try {
--- a/hotspot/test/runtime/modules/JVMDefineModule.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/JVMDefineModule.java	Mon Apr 24 12:08:28 2017 -0400
@@ -44,13 +44,13 @@
         // NULL classloader argument, expect success
         m = ModuleHelper.ModuleObject("mymodule", null, new String[] { "mypackage" });
         assertNotNull(m, "Module should not be null");
-        ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage" });
+        ModuleHelper.DefineModule(m, false, "9.0", "mymodule/here", new String[] { "mypackage" });
 
 /* Invalid test, won't compile.
         // Invalid classloader argument, expect an IAE
         try {
             m = ModuleHelper.ModuleObject("mymodule_one", new Object(), new String[] { "mypackage1" });
-            ModuleHelper.DefineModule(m,  "9.0", "mymodule/here", new String[] { "mypackage1" });
+            ModuleHelper.DefineModule(m, false, "9.0", "mymodule/here", new String[] { "mypackage1" });
             throw new RuntimeException("Failed to get expected IAE for bad loader");
         } catch(IllegalArgumentException e) {
             // Expected
@@ -60,11 +60,11 @@
         // NULL package argument, should not throw an exception
         m = ModuleHelper.ModuleObject("mymoduleTwo", cl, new String[] { "nullpkg" });
         assertNotNull(m, "Module should not be null");
-        ModuleHelper.DefineModule(m, "9.0", "mymoduleTwo/here", null);
+        ModuleHelper.DefineModule(m, false, "9.0", "mymoduleTwo/here", null);
 
         // Null module argument, expect an NPE
         try {
-            ModuleHelper.DefineModule(null,  "9.0", "mymodule/here", new String[] { "mypackage1" });
+            ModuleHelper.DefineModule(null, false, "9.0", "mymodule/here", new String[] { "mypackage1" });
             throw new RuntimeException("Failed to get expected NPE for null module");
         } catch(NullPointerException e) {
             if (!e.getMessage().contains("Null module object")) {
@@ -75,7 +75,7 @@
 
         // Invalid module argument, expect an IAE
         try {
-            ModuleHelper.DefineModule(new Object(),  "9.0", "mymodule/here", new String[] { "mypackage1" });
+            ModuleHelper.DefineModule(new Object(), false, "9.0", "mymodule/here", new String[] { "mypackage1" });
             throw new RuntimeException("Failed to get expected IAE or NPE for bad module");
         } catch(IllegalArgumentException e) {
             if (!e.getMessage().contains("module is not an instance of type java.lang.Module")) {
@@ -86,7 +86,7 @@
         // NULL module name, expect an IAE or NPE
         try {
             m = ModuleHelper.ModuleObject(null, cl, new String[] { "mypackage2" });
-            ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage2" });
+            ModuleHelper.DefineModule(m, false, "9.0", "mymodule/here", new String[] { "mypackage2" });
             throw new RuntimeException("Failed to get expected NPE for NULL module");
         } catch(IllegalArgumentException e) {
             // Expected
@@ -97,7 +97,7 @@
         // module name is java.base, expect an IAE
         m = ModuleHelper.ModuleObject("java.base", cl, new String[] { "mypackage3" });
         try {
-            ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackage3" });
+            ModuleHelper.DefineModule(m, false, "9.0", "mymodule/here", new String[] { "mypackage3" });
             throw new RuntimeException("Failed to get expected IAE for java.base, not defined with boot class loader");
         } catch(IllegalArgumentException e) {
             if (!e.getMessage().contains("Class loader must be the boot class loader")) {
@@ -108,7 +108,7 @@
         // Empty entry in package list, expect an IAE
         m = ModuleHelper.ModuleObject("module.y", cl, new String[] { "mypackageX", "mypackageY" });
         try {
-            ModuleHelper.DefineModule(m, "9.0", "mymodule/here", new String[] { "mypackageX", "", "mypackageY" });
+            ModuleHelper.DefineModule(m, false, "9.0", "mymodule/here", new String[] { "mypackageX", "", "mypackageY" });
             throw new RuntimeException("Failed to get IAE for empty package");
         } catch(IllegalArgumentException e) {
             if (!e.getMessage().contains("Invalid package name")) {
@@ -119,9 +119,9 @@
         // Duplicate module name, expect an ISE
         m = ModuleHelper.ModuleObject("Module_A", cl, new String[] { "mypackage6" });
         assertNotNull(m, "Module should not be null");
-        ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage6" });
+        ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "mypackage6" });
         try {
-            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage6a" });
+            ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "mypackage6a" });
             throw new RuntimeException("Failed to get ISE for duplicate module");
         } catch(IllegalStateException e) {
             if (!e.getMessage().contains("Module Module_A is already defined")) {
@@ -132,7 +132,7 @@
         // Package is already defined for class loader, expect an ISE
         m = ModuleHelper.ModuleObject("dupl.pkg.module", cl, new String[] { "mypackage6b" });
         try {
-            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage6" });
+            ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "mypackage6" });
             throw new RuntimeException("Failed to get ISE for existing package");
         } catch(IllegalStateException e) {
             if (!e.getMessage().contains("Package mypackage6 for module dupl.pkg.module is already in another module, Module_A, defined to the class loader")) {
@@ -143,7 +143,7 @@
         // Empty module name, expect an IAE
         try {
             m = ModuleHelper.ModuleObject("", cl, new String[] { "mypackage8" });
-            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage8" });
+            ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "mypackage8" });
             throw new RuntimeException("Failed to get expected IAE for empty module name");
         } catch(IllegalArgumentException e) {
             // Expected
@@ -152,7 +152,7 @@
         // Module name with ';', not allowed in java source
         try {
             m = ModuleHelper.ModuleObject("bad;name", cl, new String[] { "mypackage9" });
-            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9" });
+            ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "mypackage9" });
             throw new RuntimeException("Failed to get expected IAE for bad;name");
         } catch(IllegalArgumentException e) {
             // Expected
@@ -161,7 +161,7 @@
         // Module name with leading dot, not allowed in java source
         try {
             m = ModuleHelper.ModuleObject(".leadingdot", cl, new String[] { "mypackage9a" });
-            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9a" });
+            ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "mypackage9a" });
             throw new RuntimeException("Failed to get expected IAE for .leadingdot");
         } catch(IllegalArgumentException e) {
             // Expected
@@ -170,7 +170,7 @@
         // Module name with trailing dot, not allowed in java source
         try {
             m = ModuleHelper.ModuleObject("trailingdot.", cl, new String[] { "mypackage9b" });
-            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9b" });
+            ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "mypackage9b" });
             throw new RuntimeException("Failed to get expected IAE for trailingdot.");
         } catch(IllegalArgumentException e) {
             // Expected
@@ -179,7 +179,7 @@
         // Module name with consecutive dots, not allowed in java source
         try {
             m = ModuleHelper.ModuleObject("trailingdot.", cl, new String[] { "mypackage9b" });
-            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9b" });
+            ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "mypackage9b" });
             throw new RuntimeException("Failed to get expected IAE for trailingdot.");
         } catch(IllegalArgumentException e) {
             // Expected
@@ -188,17 +188,17 @@
         // module name with multiple dots, should be okay
         m = ModuleHelper.ModuleObject("more.than.one.dat", cl, new String[] { "mypackage9d" });
         assertNotNull(m, "Module should not be null");
-        ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9d" });
+        ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "mypackage9d" });
 
         // Zero length package list, should be okay
         m = ModuleHelper.ModuleObject("zero.packages", cl, new String[] { });
         assertNotNull(m, "Module should not be null");
-        ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { });
+        ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { });
 
         // Invalid package name, expect an IAE
         m = ModuleHelper.ModuleObject("moduleFive", cl, new String[] { "your.package" });
         try {
-            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "your.package" });
+            ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "your.package" });
             throw new RuntimeException("Failed to get expected IAE for your.package");
         } catch(IllegalArgumentException e) {
             if (!e.getMessage().contains("Invalid package name")) {
@@ -209,7 +209,7 @@
         // Invalid package name, expect an IAE
         m = ModuleHelper.ModuleObject("moduleSix", cl, new String[] { "foo" }); // Name irrelevant
         try {
-            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { ";your/package" });
+            ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { ";your/package" });
             throw new RuntimeException("Failed to get expected IAE for ;your.package");
         } catch(IllegalArgumentException e) {
             if (!e.getMessage().contains("Invalid package name")) {
@@ -220,7 +220,7 @@
         // Invalid package name, expect an IAE
         m = ModuleHelper.ModuleObject("moduleSeven", cl, new String[] { "foo" }); // Name irrelevant
         try {
-            ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "7[743" });
+            ModuleHelper.DefineModule(m, false, "9.0", "module.name/here", new String[] { "7[743" });
             throw new RuntimeException("Failed to get expected IAE for package 7[743");
         } catch(IllegalArgumentException e) {
             if (!e.getMessage().contains("Invalid package name")) {
@@ -232,7 +232,7 @@
         m = ModuleHelper.ModuleObject("modulejavapkgOne", cl, new String[] { "java/foo" });
         try {
             // module m is defined to an instance of MyClassLoader class loader
-            ModuleHelper.DefineModule(m, "9.0", "modulejavapkgOne", new String[] { "java/foo" });
+            ModuleHelper.DefineModule(m, false, "9.0", "modulejavapkgOne", new String[] { "java/foo" });
             throw new RuntimeException("Failed to get expected IAE for package java/foo");
         } catch(IllegalArgumentException e) {
             if (!e.getMessage().contains("prohibited package name")) {
@@ -243,7 +243,7 @@
         // Package named "javabar" defined to a class loader other than the boot or platform class loader, should be ok
         m = ModuleHelper.ModuleObject("modulejavapkgTwo", cl, new String[] { "javabar" });
         assertNotNull(m, "Module should not be null");
-        ModuleHelper.DefineModule(m, "9.0", "modulejavapkgTwo", new String[] { "javabar" });
+        ModuleHelper.DefineModule(m, false, "9.0", "modulejavapkgTwo", new String[] { "javabar" });
 
         // Package named "java" defined to the boot class loader, should be ok
         //   m's type is a java.lang.Object, module is java.base
@@ -251,7 +251,7 @@
         ClassLoader boot_loader = m.getClass().getClassLoader();
         m = ModuleHelper.ModuleObject("modulejavapkgThree", boot_loader, new String[] { "java/foo" });
         assertNotNull(m, "Module should not be null");
-        ModuleHelper.DefineModule(m, "9.0", "modulejavapkgThree", new String[] { "java/foo" });
+        ModuleHelper.DefineModule(m, false, "9.0", "modulejavapkgThree", new String[] { "java/foo" });
 
         // Package named "java" defined to the platform class loader, should be ok
         //   java.sql module defined to the platform class loader.
@@ -259,27 +259,27 @@
         ClassLoader platform_loader = jst.getClass().getClassLoader();
         m = ModuleHelper.ModuleObject("modulejavapkgFour", platform_loader, new String[] { "java/foo" });
         assertNotNull(m, "Module should not be null");
-        ModuleHelper.DefineModule(m, "9.0", "modulejavapkgFour", new String[] { "java/foo" });
+        ModuleHelper.DefineModule(m, false, "9.0", "modulejavapkgFour", new String[] { "java/foo" });
 
         // module version that is null, should be okay
         m = ModuleHelper.ModuleObject("moduleEight", cl, new String[] { "a_package_8" });
         assertNotNull(m, "Module should not be null");
-        ModuleHelper.DefineModule(m, null, "moduleEight/here", new String[] { "a_package_8" });
+        ModuleHelper.DefineModule(m, false, null, "moduleEight/here", new String[] { "a_package_8" });
 
         // module version that is "", should be okay
         m = ModuleHelper.ModuleObject("moduleNine", cl, new String[] { "a_package_9" });
         assertNotNull(m, "Module should not be null");
-        ModuleHelper.DefineModule(m, "", "moduleNine/here", new String[] { "a_package_9" });
+        ModuleHelper.DefineModule(m, false, "", "moduleNine/here", new String[] { "a_package_9" });
 
         // module location that is null, should be okay
         m = ModuleHelper.ModuleObject("moduleTen", cl, new String[] { "a_package_10" });
         assertNotNull(m, "Module should not be null");
-        ModuleHelper.DefineModule(m, "9.0", null, new String[] { "a_package_10" });
+        ModuleHelper.DefineModule(m, false, "9.0", null, new String[] { "a_package_10" });
 
         // module location that is "", should be okay
         m = ModuleHelper.ModuleObject("moduleEleven", cl, new String[] { "a_package_11" });
         assertNotNull(m, "Module should not be null");
-        ModuleHelper.DefineModule(m, "9.0", "", new String[] { "a_package_11" });
+        ModuleHelper.DefineModule(m, false, "9.0", "", new String[] { "a_package_11" });
     }
 
     static class MyClassLoader extends ClassLoader { }
--- a/hotspot/test/runtime/modules/LoadUnloadModuleStress.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/LoadUnloadModuleStress.java	Mon Apr 24 12:08:28 2017 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -48,7 +48,7 @@
         MyClassLoader cl = new MyClassLoader();
         Object module = ModuleHelper.ModuleObject("mymodule", cl, new String [] {"PackageA"});
         assertNotNull(module);
-        ModuleHelper.DefineModule(module, "9.0", "mymodule", new String[] { "PackageA" });
+        ModuleHelper.DefineModule(module, false, "9.0", "mymodule", new String[] { "PackageA" });
         clweak = new WeakReference<>(cl);
         return module;
     }
--- a/hotspot/test/runtime/modules/ModuleHelper.java	Mon Apr 24 08:47:38 2017 -0400
+++ b/hotspot/test/runtime/modules/ModuleHelper.java	Mon Apr 24 12:08:28 2017 -0400
@@ -31,10 +31,10 @@
 
 public class ModuleHelper {
 
-    public static void DefineModule(Object module, String version, String location,
-                                    String[] pkgs) throws Throwable {
+    public static void DefineModule(Object module, boolean is_open, String version,
+                                    String location, String[] pkgs) throws Throwable {
         WhiteBox wb = WhiteBox.getWhiteBox();
-        wb.DefineModule(module, version, location, pkgs);
+        wb.DefineModule(module, is_open, version, location, pkgs);
     }
 
     public static void AddModuleExports(Object from, String pkg, Object to) throws Throwable {