src/hotspot/share/classfile/classLoaderData.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File webrev Sdiff src/hotspot/share/classfile

src/hotspot/share/classfile/classLoaderData.cpp

Print this page




 587   // Lock-free access requires load_acquire.
 588   ModuleEntryTable* modules = OrderAccess::load_acquire(&_modules);
 589   if (modules == NULL) {
 590     MutexLocker m1(Module_lock);
 591     // Check if _modules got allocated while we were waiting for this lock.
 592     if ((modules = _modules) == NULL) {
 593       modules = new ModuleEntryTable(ModuleEntryTable::_moduletable_entry_size);
 594 
 595       {
 596         MutexLockerEx m1(metaspace_lock(), Mutex::_no_safepoint_check_flag);
 597         // Ensure _modules is stable, since it is examined without a lock
 598         OrderAccess::release_store(&_modules, modules);
 599       }
 600     }
 601   }
 602   return modules;
 603 }
 604 
 605 const int _boot_loader_dictionary_size    = 1009;
 606 const int _default_loader_dictionary_size = 107;
 607 const int _prime_array_size         = 8;                       // array of primes for system dictionary size
 608 const int _average_depth_goal       = 3;                       // goal for lookup length
 609 const int _primelist[_prime_array_size] = {107, 1009, 2017, 4049, 5051, 10103, 20201, 40423};
 610 
 611 // Calculate a "good" dictionary size based
 612 // on predicted or current loaded classes count.
 613 static int calculate_dictionary_size(int classcount) {
 614   int newsize = _primelist[0];
 615   if (classcount > 0 && !DumpSharedSpaces) {
 616     int index = 0;
 617     int desiredsize = classcount/_average_depth_goal;
 618     for (newsize = _primelist[index]; index < _prime_array_size -1;
 619          newsize = _primelist[++index]) {
 620       if (desiredsize <=  newsize) {
 621         break;
 622       }
 623     }
 624   }
 625   return newsize;
 626 }
 627 
 628 Dictionary* ClassLoaderData::create_dictionary() {
 629   assert(!is_anonymous(), "anonymous class loader data do not have a dictionary");
 630   int size;

 631   if (_the_null_class_loader_data == NULL) {
 632     size = _boot_loader_dictionary_size;

 633   } else if (class_loader()->is_a(SystemDictionary::reflect_DelegatingClassLoader_klass())) {
 634     size = 1;  // there's only one class in relection class loader and no initiated classes
 635   } else if (is_system_class_loader_data()) {
 636     size = calculate_dictionary_size(PredictedLoadedClassCount);

 637   } else {
 638     size = _default_loader_dictionary_size;




 639   }
 640   return new Dictionary(this, size);
 641 }
 642 
 643 // Unloading support
 644 oop ClassLoaderData::keep_alive_object() const {
 645   assert_locked_or_safepoint(_metaspace_lock);
 646   assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
 647   return is_anonymous() ? _klasses->java_mirror() : class_loader();
 648 }
 649 
 650 bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const {
 651   bool alive = keep_alive() // null class loader and incomplete anonymous klasses.
 652       || is_alive_closure->do_object_b(keep_alive_object());
 653 
 654   return alive;
 655 }
 656 
 657 ClassLoaderData::~ClassLoaderData() {
 658   // Release C heap structures for all the classes.
 659   classes_do(InstanceKlass::release_C_heap_structures);
 660 


1308 }
1309 
1310 void ClassLoaderDataGraph::purge() {
1311   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1312   ClassLoaderData* list = _unloading;
1313   _unloading = NULL;
1314   ClassLoaderData* next = list;
1315   bool classes_unloaded = false;
1316   while (next != NULL) {
1317     ClassLoaderData* purge_me = next;
1318     next = purge_me->next();
1319     delete purge_me;
1320     classes_unloaded = true;
1321   }
1322   if (classes_unloaded) {
1323     Metaspace::purge();
1324     set_metaspace_oom(false);
1325   }
1326 }
1327 













1328 void ClassLoaderDataGraph::post_class_unload_events() {
1329 #if INCLUDE_TRACE
1330   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1331   if (Tracing::enabled()) {
1332     if (Tracing::is_event_enabled(TraceClassUnloadEvent)) {
1333       assert(_unloading != NULL, "need class loader data unload list!");
1334       _class_unload_time = Ticks::now();
1335       classes_unloading_do(&class_unload_event);
1336     }
1337     Tracing::on_unloading_classes();
1338   }
1339 #endif
1340 }
1341 
1342 ClassLoaderDataGraphKlassIteratorAtomic::ClassLoaderDataGraphKlassIteratorAtomic()
1343     : _next_klass(NULL) {
1344   ClassLoaderData* cld = ClassLoaderDataGraph::_head;
1345   Klass* klass = NULL;
1346 
1347   // Find the first klass in the CLDG.




 587   // Lock-free access requires load_acquire.
 588   ModuleEntryTable* modules = OrderAccess::load_acquire(&_modules);
 589   if (modules == NULL) {
 590     MutexLocker m1(Module_lock);
 591     // Check if _modules got allocated while we were waiting for this lock.
 592     if ((modules = _modules) == NULL) {
 593       modules = new ModuleEntryTable(ModuleEntryTable::_moduletable_entry_size);
 594 
 595       {
 596         MutexLockerEx m1(metaspace_lock(), Mutex::_no_safepoint_check_flag);
 597         // Ensure _modules is stable, since it is examined without a lock
 598         OrderAccess::release_store(&_modules, modules);
 599       }
 600     }
 601   }
 602   return modules;
 603 }
 604 
 605 const int _boot_loader_dictionary_size    = 1009;
 606 const int _default_loader_dictionary_size = 107;




















 607 
 608 Dictionary* ClassLoaderData::create_dictionary() {
 609   assert(!is_anonymous(), "anonymous class loader data do not have a dictionary");
 610   int size;
 611   bool resizable = false;
 612   if (_the_null_class_loader_data == NULL) {
 613     size = _boot_loader_dictionary_size;
 614     resizable = true;
 615   } else if (class_loader()->is_a(SystemDictionary::reflect_DelegatingClassLoader_klass())) {
 616     size = 1;  // there's only one class in relection class loader and no initiated classes
 617   } else if (is_system_class_loader_data()) {
 618     size = _boot_loader_dictionary_size;
 619     resizable = true;
 620   } else {
 621     size = _default_loader_dictionary_size;
 622     resizable = true;
 623   }
 624   if (!DynamicallyResizeSystemDictionaries || DumpSharedSpaces || UseSharedSpaces) {
 625     resizable = false;
 626   }
 627   return new Dictionary(this, size, resizable);
 628 }
 629 
 630 // Unloading support
 631 oop ClassLoaderData::keep_alive_object() const {
 632   assert_locked_or_safepoint(_metaspace_lock);
 633   assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
 634   return is_anonymous() ? _klasses->java_mirror() : class_loader();
 635 }
 636 
 637 bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const {
 638   bool alive = keep_alive() // null class loader and incomplete anonymous klasses.
 639       || is_alive_closure->do_object_b(keep_alive_object());
 640 
 641   return alive;
 642 }
 643 
 644 ClassLoaderData::~ClassLoaderData() {
 645   // Release C heap structures for all the classes.
 646   classes_do(InstanceKlass::release_C_heap_structures);
 647 


1295 }
1296 
1297 void ClassLoaderDataGraph::purge() {
1298   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1299   ClassLoaderData* list = _unloading;
1300   _unloading = NULL;
1301   ClassLoaderData* next = list;
1302   bool classes_unloaded = false;
1303   while (next != NULL) {
1304     ClassLoaderData* purge_me = next;
1305     next = purge_me->next();
1306     delete purge_me;
1307     classes_unloaded = true;
1308   }
1309   if (classes_unloaded) {
1310     Metaspace::purge();
1311     set_metaspace_oom(false);
1312   }
1313 }
1314 
1315 int ClassLoaderDataGraph::resize_if_needed() {
1316   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1317   int resized = 0;
1318   if (Dictionary::does_any_dictionary_needs_resizing()) {
1319     FOR_ALL_DICTIONARY(cld) {
1320       if (cld->dictionary()->resize_if_needed()) {
1321         resized++;
1322       }
1323     }
1324   }
1325   return resized;
1326 }
1327 
1328 void ClassLoaderDataGraph::post_class_unload_events() {
1329 #if INCLUDE_TRACE
1330   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1331   if (Tracing::enabled()) {
1332     if (Tracing::is_event_enabled(TraceClassUnloadEvent)) {
1333       assert(_unloading != NULL, "need class loader data unload list!");
1334       _class_unload_time = Ticks::now();
1335       classes_unloading_do(&class_unload_event);
1336     }
1337     Tracing::on_unloading_classes();
1338   }
1339 #endif
1340 }
1341 
1342 ClassLoaderDataGraphKlassIteratorAtomic::ClassLoaderDataGraphKlassIteratorAtomic()
1343     : _next_klass(NULL) {
1344   ClassLoaderData* cld = ClassLoaderDataGraph::_head;
1345   Klass* klass = NULL;
1346 
1347   // Find the first klass in the CLDG.


src/hotspot/share/classfile/classLoaderData.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File