src/share/vm/prims/jvmtiExport.cpp

Print this page

        

@@ -572,16 +572,20 @@
       Klass* klass = (_h_class_being_redefined == NULL) ? NULL : (*_h_class_being_redefined)();
       if (_load_kind != jvmti_class_load_kind_load && klass != NULL) {
         ModuleEntry* module_entry = InstanceKlass::cast(klass)->module();
         assert(module_entry != NULL, "module_entry should always be set");
         if (module_entry->is_named() &&
-            module_entry->jlrM_module() != NULL) {
+            module_entry->jlrM_module() != NULL &&
+            !module_entry->has_default_read_edges()) {
+          if (!module_entry->set_has_default_read_edges()) {
+            // We won a potential race.
           // Add read edges to the unnamed modules of the bootstrap and app class loaders
           Handle class_module(_thread, JNIHandles::resolve(module_entry->jlrM_module())); // Obtain j.l.r.Module
           JvmtiExport::add_default_read_edges(class_module, _thread);
         }
       }
+      }
       // Clear class_being_redefined flag here. The action
       // from agent handler could generate a new class file load
       // hook event and if it is not cleared the new event generated
       // from regular class file load could have this stale redefined
       // class handle info.