< prev index next >

src/hotspot/share/classfile/classLoaderData.cpp

Print this page




1060   }
1061   return false;
1062 }
1063 
1064 
1065 // GC root of class loader data created.
1066 ClassLoaderData* ClassLoaderDataGraph::_head = NULL;
1067 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL;
1068 ClassLoaderData* ClassLoaderDataGraph::_saved_unloading = NULL;
1069 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL;
1070 
1071 bool ClassLoaderDataGraph::_should_purge = false;
1072 bool ClassLoaderDataGraph::_should_clean_deallocate_lists = false;
1073 bool ClassLoaderDataGraph::_safepoint_cleanup_needed = false;
1074 bool ClassLoaderDataGraph::_metaspace_oom = false;
1075 
1076 // Add a new class loader data node to the list.  Assign the newly created
1077 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field
1078 ClassLoaderData* ClassLoaderDataGraph::add_to_graph(Handle loader, bool is_unsafe_anonymous) {
1079 

1080 
1081   ClassLoaderData* cld;
1082   {
1083     NoSafepointVerifier no_safepoints; // we mustn't GC until we've installed the
1084                                        // ClassLoaderData in the loader since the CLD
1085                                        // contains oops in _handles that must be walked.
1086                                        // GC will find the CLD through the loader after this.
1087 
1088     cld = new ClassLoaderData(loader, is_unsafe_anonymous);
1089 
1090     if (!is_unsafe_anonymous) {
1091       // First, Atomically set it
1092       ClassLoaderData* old = java_lang_ClassLoader::cmpxchg_loader_data(cld, loader(), NULL);
1093       if (old != NULL) {
1094         delete cld;
1095         // Returns the data.
1096         return old;
1097       }
1098     }
1099   }
1100 
1101   MutexLocker ml(ClassLoaderDataGraph_lock);



1102 
1103   // We won the race, and therefore the task of adding the data to the list of
1104   // class loader data

1105   cld->set_next(_head);
1106   _head = cld;









1107   LogTarget(Trace, class, loader, data) lt;
1108   if (lt.is_enabled()) {
1109     ResourceMark rm;
1110     LogStream ls(lt);
1111     ls.print("create ");
1112     cld->print_value_on(&ls);
1113     ls.cr();
1114   }
1115   return cld;
1116 }
1117 
1118 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_unsafe_anonymous) {

1119   ClassLoaderData* loader_data = add_to_graph(loader, is_unsafe_anonymous);
1120   // Initialize _name and _name_and_id after the loader data is added to the
1121   // CLDG because adding the Symbol for _name and _name_and_id might safepoint.
1122   if (loader.not_null()) {
1123     loader_data->initialize_name(loader);
1124   }
1125   return loader_data;
1126 }
1127 
1128 void ClassLoaderDataGraph::cld_do(CLDClosure* cl) {
1129   assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
1130   for (ClassLoaderData* cld = _head;  cld != NULL; cld = cld->_next) {
1131     cl->do_cld(cld);
1132   }
1133 }
1134 
1135 void ClassLoaderDataGraph::cld_unloading_do(CLDClosure* cl) {
1136   assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
1137   // Only walk the head until any clds not purged from prior unloading
1138   // (CMS doesn't purge right away).
1139   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1140     assert(cld->is_unloading(), "invariant");
1141     cl->do_cld(cld);




1060   }
1061   return false;
1062 }
1063 
1064 
1065 // GC root of class loader data created.
1066 ClassLoaderData* ClassLoaderDataGraph::_head = NULL;
1067 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL;
1068 ClassLoaderData* ClassLoaderDataGraph::_saved_unloading = NULL;
1069 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL;
1070 
1071 bool ClassLoaderDataGraph::_should_purge = false;
1072 bool ClassLoaderDataGraph::_should_clean_deallocate_lists = false;
1073 bool ClassLoaderDataGraph::_safepoint_cleanup_needed = false;
1074 bool ClassLoaderDataGraph::_metaspace_oom = false;
1075 
1076 // Add a new class loader data node to the list.  Assign the newly created
1077 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field
1078 ClassLoaderData* ClassLoaderDataGraph::add_to_graph(Handle loader, bool is_unsafe_anonymous) {
1079 
1080   assert_lock_strong(ClassLoaderDataGraph_lock);
1081 
1082   ClassLoaderData* cld;





1083 
1084   // First check if another thread beat us to creating the CLD and installing
1085   // it into the loader while we were waiting for the lock.
1086   if (!is_unsafe_anonymous && loader.not_null()) {
1087     cld = java_lang_ClassLoader::loader_data_acquire(loader());
1088     if (cld != NULL) {
1089       return cld;




1090     }
1091   }
1092 
1093   // We mustn't GC until we've installed the ClassLoaderData in the Graph since the CLD
1094   // contains oops in _handles that must be walked.  GC doesn't walk CLD from the
1095   // loader oop in all collections, particularly young collections.
1096   NoSafepointVerifier no_safepoints;
1097 
1098   cld = new ClassLoaderData(loader, is_unsafe_anonymous);
1099 
1100   // First install the new CLD to the Graph.
1101   cld->set_next(_head);
1102   _head = cld;
1103 
1104   // Next associate with the class_loader.
1105   if (!is_unsafe_anonymous) {
1106     // Use OrderAccess, since readers need to get the loader_data only after
1107     // it's added to the Graph
1108     java_lang_ClassLoader::release_set_loader_data(loader(), cld);
1109   }
1110 
1111   // Lastly log, if requested
1112   LogTarget(Trace, class, loader, data) lt;
1113   if (lt.is_enabled()) {
1114     ResourceMark rm;
1115     LogStream ls(lt);
1116     ls.print("create ");
1117     cld->print_value_on(&ls);
1118     ls.cr();
1119   }
1120   return cld;
1121 }
1122 
1123 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_unsafe_anonymous) {
1124   MutexLocker ml(ClassLoaderDataGraph_lock);
1125   ClassLoaderData* loader_data = add_to_graph(loader, is_unsafe_anonymous);
1126   // Initialize _name and _name_and_id after the loader data is added to the
1127   // CLDG.
1128   if (loader.not_null()) {
1129     loader_data->initialize_name(loader);
1130   }
1131   return loader_data;
1132 }
1133 
1134 void ClassLoaderDataGraph::cld_do(CLDClosure* cl) {
1135   assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
1136   for (ClassLoaderData* cld = _head;  cld != NULL; cld = cld->_next) {
1137     cl->do_cld(cld);
1138   }
1139 }
1140 
1141 void ClassLoaderDataGraph::cld_unloading_do(CLDClosure* cl) {
1142   assert_locked_or_safepoint(ClassLoaderDataGraph_lock);
1143   // Only walk the head until any clds not purged from prior unloading
1144   // (CMS doesn't purge right away).
1145   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1146     assert(cld->is_unloading(), "invariant");
1147     cl->do_cld(cld);


< prev index next >