8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock
authorhseigel
Wed, 01 Jun 2016 07:44:43 -0400
changeset 38732 bb77e0dcc7e5
parent 38731 2c741a995b07
child 38733 2b65f4db449e
8158060: BasicLayerTest causes fatal error: Thread holding lock at safepoint that vm can block on: Module_lock Summary: Move the exception throw outside of the block containing the lock Reviewed-by: dholmes, kbarrett, lfoltan
hotspot/src/share/vm/classfile/modules.cpp
--- a/hotspot/src/share/vm/classfile/modules.cpp	Tue May 31 15:21:56 2016 -0400
+++ b/hotspot/src/share/vm/classfile/modules.cpp	Wed Jun 01 07:44:43 2016 -0400
@@ -237,35 +237,40 @@
   // Ensure java.base's ModuleEntry has been created
   assert(ModuleEntryTable::javabase_module() != NULL, "No ModuleEntry for java.base");
 
+  bool duplicate_javabase = false;
   {
     MutexLocker m1(Module_lock, THREAD);
 
     if (ModuleEntryTable::javabase_defined()) {
-      THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
-                "Module java.base is already defined");
-    }
+      duplicate_javabase = true;
+    } else {
 
-    // Verify that all java.base packages created during bootstrapping are in
-    // pkg_list.  If any are not in pkg_list, than a non-java.base class was
-    // loaded erroneously pre java.base module definition.
-    package_table->verify_javabase_packages(pkg_list);
+      // Verify that all java.base packages created during bootstrapping are in
+      // pkg_list.  If any are not in pkg_list, than a non-java.base class was
+      // loaded erroneously pre java.base module definition.
+      package_table->verify_javabase_packages(pkg_list);
 
-    // loop through and add any new packages for java.base
-    PackageEntry* pkg;
-    for (int x = 0; x < pkg_list->length(); x++) {
-      // Some of java.base's packages were added early in bootstrapping, ignore duplicates.
-      if (package_table->lookup_only(pkg_list->at(x)) == NULL) {
-        pkg = package_table->locked_create_entry_or_null(pkg_list->at(x), ModuleEntryTable::javabase_module());
-        assert(pkg != NULL, "Unable to create a java.base package entry");
+      // loop through and add any new packages for java.base
+      PackageEntry* pkg;
+      for (int x = 0; x < pkg_list->length(); x++) {
+        // Some of java.base's packages were added early in bootstrapping, ignore duplicates.
+        if (package_table->lookup_only(pkg_list->at(x)) == NULL) {
+          pkg = package_table->locked_create_entry_or_null(pkg_list->at(x), ModuleEntryTable::javabase_module());
+          assert(pkg != NULL, "Unable to create a java.base package entry");
+        }
+        // Unable to have a GrowableArray of TempNewSymbol.  Must decrement the refcount of
+        // the Symbol* that was created above for each package. The refcount was incremented
+        // by SymbolTable::new_symbol and as well by the PackageEntry creation.
+        pkg_list->at(x)->decrement_refcount();
       }
-      // Unable to have a GrowableArray of TempNewSymbol.  Must decrement the refcount of
-      // the Symbol* that was created above for each package. The refcount was incremented
-      // by SymbolTable::new_symbol and as well by the PackageEntry creation.
-      pkg_list->at(x)->decrement_refcount();
+
+      // Finish defining java.base's ModuleEntry
+      ModuleEntryTable::finalize_javabase(module_handle, version_symbol, location_symbol);
     }
-
-    // Finish defining java.base's ModuleEntry
-    ModuleEntryTable::finalize_javabase(module_handle, version_symbol, location_symbol);
+  }
+  if (duplicate_javabase) {
+    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
+              "Module java.base is already defined");
   }
 
   log_debug(modules)("define_javabase_module(): Definition of module: java.base,"