hotspot/src/share/vm/classfile/classLoaderData.cpp
changeset 24457 0e20b36df5c4
parent 24424 2658d7834c6e
child 24658 e41df2fc6e87
equal deleted inserted replaced
24456:8c7933fa5a1f 24457:0e20b36df5c4
   547 // GC root of class loader data created.
   547 // GC root of class loader data created.
   548 ClassLoaderData* ClassLoaderDataGraph::_head = NULL;
   548 ClassLoaderData* ClassLoaderDataGraph::_head = NULL;
   549 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL;
   549 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL;
   550 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL;
   550 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL;
   551 
   551 
       
   552 bool ClassLoaderDataGraph::_should_purge = false;
       
   553 
   552 // Add a new class loader data node to the list.  Assign the newly created
   554 // Add a new class loader data node to the list.  Assign the newly created
   553 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field
   555 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field
   554 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous, TRAPS) {
   556 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous, TRAPS) {
   555   // We need to allocate all the oops for the ClassLoaderData before allocating the
   557   // We need to allocate all the oops for the ClassLoaderData before allocating the
   556   // actual ClassLoaderData object.
   558   // actual ClassLoaderData object.
   671 
   673 
   672     curr = curr->_next;
   674     curr = curr->_next;
   673   }
   675   }
   674 
   676 
   675   return array;
   677   return array;
   676 }
       
   677 
       
   678 // For profiling and hsfind() only.  Otherwise, this is unsafe (and slow).  This
       
   679 // is done lock free to avoid lock inversion problems.  It is safe because
       
   680 // new ClassLoaderData are added to the end of the CLDG, and only removed at
       
   681 // safepoint.  The _unloading list can be deallocated concurrently with CMS so
       
   682 // this doesn't look in metaspace for classes that have been unloaded.
       
   683 bool ClassLoaderDataGraph::contains(const void* x) {
       
   684   if (DumpSharedSpaces) {
       
   685     // There are only two metaspaces to worry about.
       
   686     ClassLoaderData* ncld = ClassLoaderData::the_null_class_loader_data();
       
   687     return (ncld->ro_metaspace()->contains(x) || ncld->rw_metaspace()->contains(x));
       
   688   }
       
   689 
       
   690   if (UseSharedSpaces && MetaspaceShared::is_in_shared_space(x)) {
       
   691     return true;
       
   692   }
       
   693 
       
   694   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
       
   695     if (cld->metaspace_or_null() != NULL && cld->metaspace_or_null()->contains(x)) {
       
   696       return true;
       
   697     }
       
   698   }
       
   699 
       
   700   // Do not check unloading list because deallocation can be concurrent.
       
   701   return false;
       
   702 }
   678 }
   703 
   679 
   704 #ifndef PRODUCT
   680 #ifndef PRODUCT
   705 bool ClassLoaderDataGraph::contains_loader_data(ClassLoaderData* loader_data) {
   681 bool ClassLoaderDataGraph::contains_loader_data(ClassLoaderData* loader_data) {
   706   for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
   682   for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
   757 
   733 
   758   return seen_dead_loader;
   734   return seen_dead_loader;
   759 }
   735 }
   760 
   736 
   761 void ClassLoaderDataGraph::purge() {
   737 void ClassLoaderDataGraph::purge() {
       
   738   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
   762   ClassLoaderData* list = _unloading;
   739   ClassLoaderData* list = _unloading;
   763   _unloading = NULL;
   740   _unloading = NULL;
   764   ClassLoaderData* next = list;
   741   ClassLoaderData* next = list;
   765   while (next != NULL) {
   742   while (next != NULL) {
   766     ClassLoaderData* purge_me = next;
   743     ClassLoaderData* purge_me = next;