< prev index next >

src/hotspot/share/classfile/classLoaderData.cpp

Print this page




  59 #include "logging/log.hpp"
  60 #include "logging/logStream.hpp"
  61 #include "memory/allocation.inline.hpp"
  62 #include "memory/metadataFactory.hpp"
  63 #include "memory/metaspaceShared.hpp"
  64 #include "memory/resourceArea.hpp"
  65 #include "memory/universe.hpp"
  66 #include "oops/access.inline.hpp"
  67 #include "oops/oop.inline.hpp"
  68 #include "oops/oopHandle.inline.hpp"
  69 #include "oops/weakHandle.inline.hpp"
  70 #include "runtime/atomic.hpp"
  71 #include "runtime/handles.inline.hpp"
  72 #include "runtime/mutex.hpp"
  73 #include "runtime/orderAccess.hpp"
  74 #include "runtime/safepoint.hpp"
  75 #include "runtime/safepointVerifiers.hpp"
  76 #include "utilities/growableArray.hpp"
  77 #include "utilities/macros.hpp"
  78 #include "utilities/ostream.hpp"
  79 #include "utilities/ticks.hpp"
  80 #if INCLUDE_JFR
  81 #include "jfr/jfr.hpp"
  82 #include "jfr/jfrEvents.hpp"
  83 #endif
  84 
  85 volatile size_t ClassLoaderDataGraph::_num_array_classes = 0;
  86 volatile size_t ClassLoaderDataGraph::_num_instance_classes = 0;
  87 
  88 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
  89 
  90 void ClassLoaderData::init_null_class_loader_data() {
  91   assert(_the_null_class_loader_data == NULL, "cannot initialize twice");
  92   assert(ClassLoaderDataGraph::_head == NULL, "cannot initialize twice");
  93 
  94   _the_null_class_loader_data = new ClassLoaderData(Handle(), false);
  95   ClassLoaderDataGraph::_head = _the_null_class_loader_data;
  96   assert(_the_null_class_loader_data->is_the_null_class_loader_data(), "Must be");
  97 
  98   LogTarget(Trace, class, loader, data) lt;
  99   if (lt.is_enabled()) {
 100     ResourceMark rm;
 101     LogStream ls(lt);
 102     ls.print("create ");
 103     _the_null_class_loader_data->print_value_on(&ls);


1308     }
1309 
1310     curr = curr->_next;
1311   }
1312 
1313   return array;
1314 }
1315 
1316 #ifndef PRODUCT
1317 bool ClassLoaderDataGraph::contains_loader_data(ClassLoaderData* loader_data) {
1318   for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
1319     if (loader_data == data) {
1320       return true;
1321     }
1322   }
1323 
1324   return false;
1325 }
1326 #endif // PRODUCT
1327 
1328 #if INCLUDE_JFR
1329 static Ticks class_unload_time;
1330 static void post_class_unload_event(Klass* const k) {
1331   assert(k != NULL, "invariant");
1332   EventClassUnload event(UNTIMED);
1333   event.set_endtime(class_unload_time);
1334   event.set_unloadedClass(k);
1335   event.set_definingClassLoader(k->class_loader_data());
1336   event.commit();
1337 }
1338 
1339 static void post_class_unload_events() {
1340   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1341   if (Jfr::is_enabled()) {
1342     if (EventClassUnload::is_enabled()) {
1343       class_unload_time = Ticks::now();
1344       ClassLoaderDataGraph::classes_unloading_do(&post_class_unload_event);
1345     }
1346     Jfr::on_unloading_classes();
1347   }
1348 }
1349 #endif // INCLUDE_JFR
1350 
1351 // Move class loader data from main list to the unloaded list for unloading
1352 // and deallocation later.
1353 bool ClassLoaderDataGraph::do_unloading(bool do_cleaning) {
1354 
1355   // Indicate whether safepoint cleanup is needed.
1356   _safepoint_cleanup_needed |= do_cleaning;
1357 
1358   ClassLoaderData* data = _head;
1359   ClassLoaderData* prev = NULL;
1360   bool seen_dead_loader = false;
1361   uint loaders_processed = 0;
1362   uint loaders_removed = 0;
1363 
1364   // Save previous _unloading pointer for CMS which may add to unloading list before
1365   // purging and we don't want to rewalk the previously unloaded class loader data.
1366   _saved_unloading = _unloading;
1367 
1368   data = _head;
1369   while (data != NULL) {
1370     if (data->is_alive()) {


1372       data = data->next();
1373       loaders_processed++;
1374       continue;
1375     }
1376     seen_dead_loader = true;
1377     loaders_removed++;
1378     ClassLoaderData* dead = data;
1379     dead->unload();
1380     data = data->next();
1381     // Remove from loader list.
1382     // This class loader data will no longer be found
1383     // in the ClassLoaderDataGraph.
1384     if (prev != NULL) {
1385       prev->set_next(data);
1386     } else {
1387       assert(dead == _head, "sanity check");
1388       _head = data;
1389     }
1390     dead->set_next(_unloading);
1391     _unloading = dead;
1392   }
1393 
1394   if (seen_dead_loader) {
1395     JFR_ONLY(post_class_unload_events();)
1396   }
1397 
1398   log_debug(class, loader, data)("do_unloading: loaders processed %u, loaders removed %u", loaders_processed, loaders_removed);
1399 
1400   return seen_dead_loader;
1401 }
1402 
1403 // There's at least one dead class loader.  Purge refererences of healthy module
1404 // reads lists and package export lists to modules belonging to dead loaders.
1405 void ClassLoaderDataGraph::clean_module_and_package_info() {
1406   ClassLoaderData* data = _head;
1407   while (data != NULL) {
1408     // Remove entries in the dictionary of live class loader that have
1409     // initiated loading classes in a dead class loader.
1410     if (data->dictionary() != NULL) {
1411       data->dictionary()->do_unloading();
1412     }
1413     // Walk a ModuleEntry's reads, and a PackageEntry's exports
1414     // lists to determine if there are modules on those lists that are now
1415     // dead and should be removed.  A module's life cycle is equivalent




  59 #include "logging/log.hpp"
  60 #include "logging/logStream.hpp"
  61 #include "memory/allocation.inline.hpp"
  62 #include "memory/metadataFactory.hpp"
  63 #include "memory/metaspaceShared.hpp"
  64 #include "memory/resourceArea.hpp"
  65 #include "memory/universe.hpp"
  66 #include "oops/access.inline.hpp"
  67 #include "oops/oop.inline.hpp"
  68 #include "oops/oopHandle.inline.hpp"
  69 #include "oops/weakHandle.inline.hpp"
  70 #include "runtime/atomic.hpp"
  71 #include "runtime/handles.inline.hpp"
  72 #include "runtime/mutex.hpp"
  73 #include "runtime/orderAccess.hpp"
  74 #include "runtime/safepoint.hpp"
  75 #include "runtime/safepointVerifiers.hpp"
  76 #include "utilities/growableArray.hpp"
  77 #include "utilities/macros.hpp"
  78 #include "utilities/ostream.hpp"





  79 
  80 volatile size_t ClassLoaderDataGraph::_num_array_classes = 0;
  81 volatile size_t ClassLoaderDataGraph::_num_instance_classes = 0;
  82 
  83 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
  84 
  85 void ClassLoaderData::init_null_class_loader_data() {
  86   assert(_the_null_class_loader_data == NULL, "cannot initialize twice");
  87   assert(ClassLoaderDataGraph::_head == NULL, "cannot initialize twice");
  88 
  89   _the_null_class_loader_data = new ClassLoaderData(Handle(), false);
  90   ClassLoaderDataGraph::_head = _the_null_class_loader_data;
  91   assert(_the_null_class_loader_data->is_the_null_class_loader_data(), "Must be");
  92 
  93   LogTarget(Trace, class, loader, data) lt;
  94   if (lt.is_enabled()) {
  95     ResourceMark rm;
  96     LogStream ls(lt);
  97     ls.print("create ");
  98     _the_null_class_loader_data->print_value_on(&ls);


1303     }
1304 
1305     curr = curr->_next;
1306   }
1307 
1308   return array;
1309 }
1310 
1311 #ifndef PRODUCT
1312 bool ClassLoaderDataGraph::contains_loader_data(ClassLoaderData* loader_data) {
1313   for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
1314     if (loader_data == data) {
1315       return true;
1316     }
1317   }
1318 
1319   return false;
1320 }
1321 #endif // PRODUCT
1322 























1323 // Move class loader data from main list to the unloaded list for unloading
1324 // and deallocation later.
1325 bool ClassLoaderDataGraph::do_unloading(bool do_cleaning) {
1326 
1327   // Indicate whether safepoint cleanup is needed.
1328   _safepoint_cleanup_needed |= do_cleaning;
1329 
1330   ClassLoaderData* data = _head;
1331   ClassLoaderData* prev = NULL;
1332   bool seen_dead_loader = false;
1333   uint loaders_processed = 0;
1334   uint loaders_removed = 0;
1335 
1336   // Save previous _unloading pointer for CMS which may add to unloading list before
1337   // purging and we don't want to rewalk the previously unloaded class loader data.
1338   _saved_unloading = _unloading;
1339 
1340   data = _head;
1341   while (data != NULL) {
1342     if (data->is_alive()) {


1344       data = data->next();
1345       loaders_processed++;
1346       continue;
1347     }
1348     seen_dead_loader = true;
1349     loaders_removed++;
1350     ClassLoaderData* dead = data;
1351     dead->unload();
1352     data = data->next();
1353     // Remove from loader list.
1354     // This class loader data will no longer be found
1355     // in the ClassLoaderDataGraph.
1356     if (prev != NULL) {
1357       prev->set_next(data);
1358     } else {
1359       assert(dead == _head, "sanity check");
1360       _head = data;
1361     }
1362     dead->set_next(_unloading);
1363     _unloading = dead;




1364   }
1365 
1366   log_debug(class, loader, data)("do_unloading: loaders processed %u, loaders removed %u", loaders_processed, loaders_removed);
1367 
1368   return seen_dead_loader;
1369 }
1370 
1371 // There's at least one dead class loader.  Purge refererences of healthy module
1372 // reads lists and package export lists to modules belonging to dead loaders.
1373 void ClassLoaderDataGraph::clean_module_and_package_info() {
1374   ClassLoaderData* data = _head;
1375   while (data != NULL) {
1376     // Remove entries in the dictionary of live class loader that have
1377     // initiated loading classes in a dead class loader.
1378     if (data->dictionary() != NULL) {
1379       data->dictionary()->do_unloading();
1380     }
1381     // Walk a ModuleEntry's reads, and a PackageEntry's exports
1382     // lists to determine if there are modules on those lists that are now
1383     // dead and should be removed.  A module's life cycle is equivalent


< prev index next >