src/hotspot/share/classfile/classLoaderData.cpp
changeset 50113 caf115bb98ad
parent 49824 e242740a92b8
child 50219 4ab066d71956
equal deleted inserted replaced
50112:7a2a740815b7 50113:caf115bb98ad
    74 #include "runtime/safepoint.hpp"
    74 #include "runtime/safepoint.hpp"
    75 #include "runtime/safepointVerifiers.hpp"
    75 #include "runtime/safepointVerifiers.hpp"
    76 #include "utilities/growableArray.hpp"
    76 #include "utilities/growableArray.hpp"
    77 #include "utilities/macros.hpp"
    77 #include "utilities/macros.hpp"
    78 #include "utilities/ostream.hpp"
    78 #include "utilities/ostream.hpp"
    79 #if INCLUDE_TRACE
    79 #include "utilities/ticks.hpp"
    80 #include "trace/tracing.hpp"
    80 #if INCLUDE_JFR
       
    81 #include "jfr/jfr.hpp"
       
    82 #include "jfr/jfrEvents.hpp"
    81 #endif
    83 #endif
    82 
    84 
    83 volatile size_t ClassLoaderDataGraph::_num_array_classes = 0;
    85 volatile size_t ClassLoaderDataGraph::_num_array_classes = 0;
    84 volatile size_t ClassLoaderDataGraph::_num_instance_classes = 0;
    86 volatile size_t ClassLoaderDataGraph::_num_instance_classes = 0;
    85 
    87 
   159     _dictionary = create_dictionary();
   161     _dictionary = create_dictionary();
   160   }
   162   }
   161 
   163 
   162   NOT_PRODUCT(_dependency_count = 0); // number of class loader dependencies
   164   NOT_PRODUCT(_dependency_count = 0); // number of class loader dependencies
   163 
   165 
   164   TRACE_INIT_ID(this);
   166   JFR_ONLY(INIT_ID(this);)
   165 }
   167 }
   166 
   168 
   167 ClassLoaderData::ChunkedHandleList::~ChunkedHandleList() {
   169 ClassLoaderData::ChunkedHandleList::~ChunkedHandleList() {
   168   Chunk* c = _head;
   170   Chunk* c = _head;
   169   while (c != NULL) {
   171   while (c != NULL) {
  1274 
  1276 
  1275   return false;
  1277   return false;
  1276 }
  1278 }
  1277 #endif // PRODUCT
  1279 #endif // PRODUCT
  1278 
  1280 
       
  1281 #if INCLUDE_JFR
       
  1282 static Ticks class_unload_time;
       
  1283 static void post_class_unload_event(Klass* const k) {
       
  1284   assert(k != NULL, "invariant");
       
  1285   EventClassUnload event(UNTIMED);
       
  1286   event.set_endtime(class_unload_time);
       
  1287   event.set_unloadedClass(k);
       
  1288   event.set_definingClassLoader(k->class_loader_data());
       
  1289   event.commit();
       
  1290 }
       
  1291 
       
  1292 static void post_class_unload_events() {
       
  1293   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
       
  1294   if (Jfr::is_enabled()) {
       
  1295     if (EventClassUnload::is_enabled()) {
       
  1296       class_unload_time = Ticks::now();
       
  1297       ClassLoaderDataGraph::classes_unloading_do(&post_class_unload_event);
       
  1298     }
       
  1299     Jfr::on_unloading_classes();
       
  1300   }
       
  1301 }
       
  1302 #endif // INCLUDE_JFR
  1279 
  1303 
  1280 // Move class loader data from main list to the unloaded list for unloading
  1304 // Move class loader data from main list to the unloaded list for unloading
  1281 // and deallocation later.
  1305 // and deallocation later.
  1282 bool ClassLoaderDataGraph::do_unloading(bool clean_previous_versions) {
  1306 bool ClassLoaderDataGraph::do_unloading(bool clean_previous_versions) {
  1283 
  1307 
  1351       if (data->modules_defined()) {
  1375       if (data->modules_defined()) {
  1352         data->modules()->purge_all_module_reads();
  1376         data->modules()->purge_all_module_reads();
  1353       }
  1377       }
  1354       data = data->next();
  1378       data = data->next();
  1355     }
  1379     }
  1356 
  1380     JFR_ONLY(post_class_unload_events();)
  1357     post_class_unload_events();
       
  1358   }
  1381   }
  1359 
  1382 
  1360   log_debug(class, loader, data)("do_unloading: loaders processed %u, loaders removed %u", loaders_processed, loaders_removed);
  1383   log_debug(class, loader, data)("do_unloading: loaders processed %u, loaders removed %u", loaders_processed, loaders_removed);
  1361 
  1384 
  1362   return seen_dead_loader;
  1385   return seen_dead_loader;
  1391     }
  1414     }
  1392   }
  1415   }
  1393   return resized;
  1416   return resized;
  1394 }
  1417 }
  1395 
  1418 
  1396 void ClassLoaderDataGraph::post_class_unload_events() {
       
  1397 #if INCLUDE_TRACE
       
  1398   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
       
  1399   if (Tracing::enabled()) {
       
  1400     if (Tracing::is_event_enabled(TraceClassUnloadEvent)) {
       
  1401       assert(_unloading != NULL, "need class loader data unload list!");
       
  1402       _class_unload_time = Ticks::now();
       
  1403       classes_unloading_do(&class_unload_event);
       
  1404     }
       
  1405     Tracing::on_unloading_classes();
       
  1406   }
       
  1407 #endif
       
  1408 }
       
  1409 
       
  1410 ClassLoaderDataGraphKlassIteratorAtomic::ClassLoaderDataGraphKlassIteratorAtomic()
  1419 ClassLoaderDataGraphKlassIteratorAtomic::ClassLoaderDataGraphKlassIteratorAtomic()
  1411     : _next_klass(NULL) {
  1420     : _next_klass(NULL) {
  1412   ClassLoaderData* cld = ClassLoaderDataGraph::_head;
  1421   ClassLoaderData* cld = ClassLoaderDataGraph::_head;
  1413   Klass* klass = NULL;
  1422   Klass* klass = NULL;
  1414 
  1423 
  1488   for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
  1497   for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
  1489     data->print_on(out);
  1498     data->print_on(out);
  1490   }
  1499   }
  1491 }
  1500 }
  1492 #endif // PRODUCT
  1501 #endif // PRODUCT
  1493 
       
  1494 #if INCLUDE_TRACE
       
  1495 
       
  1496 Ticks ClassLoaderDataGraph::_class_unload_time;
       
  1497 
       
  1498 void ClassLoaderDataGraph::class_unload_event(Klass* const k) {
       
  1499   assert(k != NULL, "invariant");
       
  1500 
       
  1501   // post class unload event
       
  1502   EventClassUnload event(UNTIMED);
       
  1503   event.set_endtime(_class_unload_time);
       
  1504   event.set_unloadedClass(k);
       
  1505   event.set_definingClassLoader(k->class_loader_data());
       
  1506   event.commit();
       
  1507 }
       
  1508 
       
  1509 #endif // INCLUDE_TRACE