< prev index next >

src/hotspot/share/classfile/classLoaderDataGraph.cpp

Print this page




 163   // TODO: have redefinition clean old methods out of the code cache.  They still exist in some places.
 164   bool walk_all_metadata = InstanceKlass::has_previous_versions_and_reset();
 165 
 166   MetadataOnStackMark md_on_stack(walk_all_metadata, /*redefinition_walk*/false);
 167   clean_deallocate_lists(walk_all_metadata);
 168 }
 169 
 170 // GC root of class loader data created.
 171 ClassLoaderData* ClassLoaderDataGraph::_head = NULL;
 172 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL;
 173 ClassLoaderData* ClassLoaderDataGraph::_saved_unloading = NULL;
 174 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL;
 175 
 176 bool ClassLoaderDataGraph::_should_purge = false;
 177 bool ClassLoaderDataGraph::_should_clean_deallocate_lists = false;
 178 bool ClassLoaderDataGraph::_safepoint_cleanup_needed = false;
 179 bool ClassLoaderDataGraph::_metaspace_oom = false;
 180 
 181 // Add a new class loader data node to the list.  Assign the newly created
 182 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field
 183 ClassLoaderData* ClassLoaderDataGraph::add_to_graph(Handle loader, bool is_unsafe_anonymous) {
 184 
 185   assert_lock_strong(ClassLoaderDataGraph_lock);
 186 
 187   ClassLoaderData* cld;
 188 
 189   // First check if another thread beat us to creating the CLD and installing
 190   // it into the loader while we were waiting for the lock.
 191   if (!is_unsafe_anonymous && loader.not_null()) {
 192     cld = java_lang_ClassLoader::loader_data_acquire(loader());
 193     if (cld != NULL) {
 194       return cld;
 195     }
 196   }
 197 
 198   // We mustn't GC until we've installed the ClassLoaderData in the Graph since the CLD
 199   // contains oops in _handles that must be walked.  GC doesn't walk CLD from the
 200   // loader oop in all collections, particularly young collections.
 201   NoSafepointVerifier no_safepoints;
 202 
 203   cld = new ClassLoaderData(loader, is_unsafe_anonymous);
 204 
 205   // First install the new CLD to the Graph.
 206   cld->set_next(_head);
 207   _head = cld;
 208 
 209   // Next associate with the class_loader.
 210   if (!is_unsafe_anonymous) {
 211     // Use OrderAccess, since readers need to get the loader_data only after
 212     // it's added to the Graph
 213     java_lang_ClassLoader::release_set_loader_data(loader(), cld);
 214   }
 215 
 216   // Lastly log, if requested
 217   LogTarget(Trace, class, loader, data) lt;
 218   if (lt.is_enabled()) {
 219     ResourceMark rm;
 220     LogStream ls(lt);
 221     ls.print("create ");
 222     cld->print_value_on(&ls);
 223     ls.cr();
 224   }
 225   return cld;
 226 }
 227 
 228 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_unsafe_anonymous) {
 229   MutexLocker ml(ClassLoaderDataGraph_lock);
 230   ClassLoaderData* loader_data = add_to_graph(loader, is_unsafe_anonymous);
 231   return loader_data;
 232 }
 233 
 234 void ClassLoaderDataGraph::cld_unloading_do(CLDClosure* cl) {
 235   assert_locked_or_safepoint_weak(ClassLoaderDataGraph_lock);
 236   // Only walk the head until any clds not purged from prior unloading
 237   // (CMS doesn't purge right away).
 238   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
 239     assert(cld->is_unloading(), "invariant");
 240     cl->do_cld(cld);
 241   }
 242 }
 243 
 244 // These are functions called by the GC, which require all of the CLDs, including the
 245 // unloading ones.
 246 void ClassLoaderDataGraph::cld_do(CLDClosure* cl) {
 247   assert_locked_or_safepoint_weak(ClassLoaderDataGraph_lock);
 248   for (ClassLoaderData* cld = _head;  cld != NULL; cld = cld->_next) {
 249     cl->do_cld(cld);
 250   }




 163   // TODO: have redefinition clean old methods out of the code cache.  They still exist in some places.
 164   bool walk_all_metadata = InstanceKlass::has_previous_versions_and_reset();
 165 
 166   MetadataOnStackMark md_on_stack(walk_all_metadata, /*redefinition_walk*/false);
 167   clean_deallocate_lists(walk_all_metadata);
 168 }
 169 
 170 // GC root of class loader data created.
 171 ClassLoaderData* ClassLoaderDataGraph::_head = NULL;
 172 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL;
 173 ClassLoaderData* ClassLoaderDataGraph::_saved_unloading = NULL;
 174 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL;
 175 
 176 bool ClassLoaderDataGraph::_should_purge = false;
 177 bool ClassLoaderDataGraph::_should_clean_deallocate_lists = false;
 178 bool ClassLoaderDataGraph::_safepoint_cleanup_needed = false;
 179 bool ClassLoaderDataGraph::_metaspace_oom = false;
 180 
 181 // Add a new class loader data node to the list.  Assign the newly created
 182 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field
 183 ClassLoaderData* ClassLoaderDataGraph::add_to_graph(Handle loader, bool is_shortlived) {
 184 
 185   assert_lock_strong(ClassLoaderDataGraph_lock);
 186 
 187   ClassLoaderData* cld;
 188 
 189   // First check if another thread beat us to creating the CLD and installing
 190   // it into the loader while we were waiting for the lock.
 191   if (!is_shortlived && loader.not_null()) {
 192     cld = java_lang_ClassLoader::loader_data_acquire(loader());
 193     if (cld != NULL) {
 194       return cld;
 195     }
 196   }
 197 
 198   // We mustn't GC until we've installed the ClassLoaderData in the Graph since the CLD
 199   // contains oops in _handles that must be walked.  GC doesn't walk CLD from the
 200   // loader oop in all collections, particularly young collections.
 201   NoSafepointVerifier no_safepoints;
 202 
 203   cld = new ClassLoaderData(loader, is_shortlived);
 204 
 205   // First install the new CLD to the Graph.
 206   cld->set_next(_head);
 207   _head = cld;
 208 
 209   // Next associate with the class_loader.
 210   if (!is_shortlived) {
 211     // Use OrderAccess, since readers need to get the loader_data only after
 212     // it's added to the Graph
 213     java_lang_ClassLoader::release_set_loader_data(loader(), cld);
 214   }
 215 
 216   // Lastly log, if requested
 217   LogTarget(Trace, class, loader, data) lt;
 218   if (lt.is_enabled()) {
 219     ResourceMark rm;
 220     LogStream ls(lt);
 221     ls.print("create ");
 222     cld->print_value_on(&ls);
 223     ls.cr();
 224   }
 225   return cld;
 226 }
 227 
 228 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_shortlived) {
 229   MutexLocker ml(ClassLoaderDataGraph_lock);
 230   ClassLoaderData* loader_data = add_to_graph(loader, is_shortlived);
 231   return loader_data;
 232 }
 233 
 234 void ClassLoaderDataGraph::cld_unloading_do(CLDClosure* cl) {
 235   assert_locked_or_safepoint_weak(ClassLoaderDataGraph_lock);
 236   // Only walk the head until any clds not purged from prior unloading
 237   // (CMS doesn't purge right away).
 238   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
 239     assert(cld->is_unloading(), "invariant");
 240     cl->do_cld(cld);
 241   }
 242 }
 243 
 244 // These are functions called by the GC, which require all of the CLDs, including the
 245 // unloading ones.
 246 void ClassLoaderDataGraph::cld_do(CLDClosure* cl) {
 247   assert_locked_or_safepoint_weak(ClassLoaderDataGraph_lock);
 248   for (ClassLoaderData* cld = _head;  cld != NULL; cld = cld->_next) {
 249     cl->do_cld(cld);
 250   }


< prev index next >