8139566: need proper sync for adding default read edges
authorsspitsyn
Sun, 18 Dec 2016 19:21:18 -0800
changeset 42866 97de8ed6c6b3
parent 42864 194398a04b7e
child 42867 5448e1bbe72a
8139566: need proper sync for adding default read edges Summary: use has_default_read_edges() in the ModuleEntry::can_read to fix race issue Reviewed-by: hseigel, lfoltan
hotspot/src/share/vm/classfile/moduleEntry.cpp
--- a/hotspot/src/share/vm/classfile/moduleEntry.cpp	Tue Dec 13 02:04:23 2016 +0100
+++ b/hotspot/src/share/vm/classfile/moduleEntry.cpp	Sun Dec 18 19:21:18 2016 -0800
@@ -108,6 +108,18 @@
   }
 
   MutexLocker m1(Module_lock);
+  // This is a guard against possible race between agent threads that redefine
+  // or retransform classes in this module. Only one of them is adding the
+  // default read edges to the unnamed modules of the boot and app class loaders
+  // with an upcall to jdk.internal.module.Modules.transformedByAgent.
+  // At the same time, another thread can instrument the module classes by
+  // injecting dependencies that require the default read edges for resolution.
+  if (this->has_default_read_edges() && !m->is_named()) {
+    ClassLoaderData* cld = m->loader_data();
+    if (cld->is_the_null_class_loader_data() || cld->is_system_class_loader_data()) {
+      return true; // default read edge
+    }
+  }
   if (!has_reads()) {
     return false;
   } else {