8202578: Revisit location for class unload events
authorhseigel
Tue, 28 Aug 2018 10:10:11 -0400
changeset 51543 5303c6c05db6
parent 51542 04b857edadec
child 51544 384c9c753f47
8202578: Revisit location for class unload events Summary: Use notify_unload_class() to post JFR class unload events instead of doing a separate traversal of the class loader data graph Reviewed-by: lfoltan, coleenp, mgronlun, egahlin
src/hotspot/share/classfile/classLoaderData.cpp
src/hotspot/share/classfile/systemDictionary.cpp
src/hotspot/share/oops/instanceKlass.cpp
--- a/src/hotspot/share/classfile/classLoaderData.cpp	Tue Aug 28 09:06:23 2018 +0200
+++ b/src/hotspot/share/classfile/classLoaderData.cpp	Tue Aug 28 10:10:11 2018 -0400
@@ -76,11 +76,6 @@
 #include "utilities/growableArray.hpp"
 #include "utilities/macros.hpp"
 #include "utilities/ostream.hpp"
-#include "utilities/ticks.hpp"
-#if INCLUDE_JFR
-#include "jfr/jfr.hpp"
-#include "jfr/jfrEvents.hpp"
-#endif
 
 volatile size_t ClassLoaderDataGraph::_num_array_classes = 0;
 volatile size_t ClassLoaderDataGraph::_num_instance_classes = 0;
@@ -1316,29 +1311,6 @@
 }
 #endif // PRODUCT
 
-#if INCLUDE_JFR
-static Ticks class_unload_time;
-static void post_class_unload_event(Klass* const k) {
-  assert(k != NULL, "invariant");
-  EventClassUnload event(UNTIMED);
-  event.set_endtime(class_unload_time);
-  event.set_unloadedClass(k);
-  event.set_definingClassLoader(k->class_loader_data());
-  event.commit();
-}
-
-static void post_class_unload_events() {
-  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
-  if (Jfr::is_enabled()) {
-    if (EventClassUnload::is_enabled()) {
-      class_unload_time = Ticks::now();
-      ClassLoaderDataGraph::classes_unloading_do(&post_class_unload_event);
-    }
-    Jfr::on_unloading_classes();
-  }
-}
-#endif // INCLUDE_JFR
-
 // Move class loader data from main list to the unloaded list for unloading
 // and deallocation later.
 bool ClassLoaderDataGraph::do_unloading(bool do_cleaning) {
@@ -1382,10 +1354,6 @@
     _unloading = dead;
   }
 
-  if (seen_dead_loader) {
-    JFR_ONLY(post_class_unload_events();)
-  }
-
   log_debug(class, loader, data)("do_unloading: loaders processed %u, loaders removed %u", loaders_processed, loaders_removed);
 
   return seen_dead_loader;
--- a/src/hotspot/share/classfile/systemDictionary.cpp	Tue Aug 28 09:06:23 2018 +0200
+++ b/src/hotspot/share/classfile/systemDictionary.cpp	Tue Aug 28 10:10:11 2018 -0400
@@ -89,6 +89,9 @@
 #if INCLUDE_JVMCI
 #include "jvmci/jvmciRuntime.hpp"
 #endif
+#if INCLUDE_JFR
+#include "jfr/jfr.hpp"
+#endif
 
 PlaceholderTable*      SystemDictionary::_placeholders        = NULL;
 Dictionary*            SystemDictionary::_shared_dictionary   = NULL;
@@ -1856,6 +1859,7 @@
     // First, mark for unload all ClassLoaderData referencing a dead class loader.
     unloading_occurred = ClassLoaderDataGraph::do_unloading(do_cleaning);
     if (unloading_occurred) {
+      JFR_ONLY(Jfr::on_unloading_classes();)
       ClassLoaderDataGraph::clean_module_and_package_info();
     }
   }
--- a/src/hotspot/share/oops/instanceKlass.cpp	Tue Aug 28 09:06:23 2018 +0200
+++ b/src/hotspot/share/oops/instanceKlass.cpp	Tue Aug 28 10:10:11 2018 -0400
@@ -80,6 +80,10 @@
 #ifdef COMPILER1
 #include "c1/c1_Compiler.hpp"
 #endif
+#if INCLUDE_JFR
+#include "jfr/jfrEvents.hpp"
+#endif
+
 
 #ifdef DTRACE_ENABLED
 
@@ -2423,6 +2427,14 @@
 
   // notify ClassLoadingService of class unload
   ClassLoadingService::notify_class_unloaded(ik);
+
+#if INCLUDE_JFR
+  assert(ik != NULL, "invariant");
+  EventClassUnload event;
+  event.set_unloadedClass(ik);
+  event.set_definingClassLoader(ik->class_loader_data());
+  event.commit();
+#endif
 }
 
 void InstanceKlass::release_C_heap_structures(InstanceKlass* ik) {