< prev index next >

src/hotspot/share/classfile/classLoaderDataGraph.cpp

Print this page




  42 #include "runtime/safepoint.hpp"
  43 #include "runtime/safepointVerifiers.hpp"
  44 #include "utilities/growableArray.hpp"
  45 #include "utilities/macros.hpp"
  46 #include "utilities/ostream.hpp"
  47 
  48 volatile size_t ClassLoaderDataGraph::_num_array_classes = 0;
  49 volatile size_t ClassLoaderDataGraph::_num_instance_classes = 0;
  50 
  51 void ClassLoaderDataGraph::clear_claimed_marks() {
  52   // The claimed marks of the CLDs in the ClassLoaderDataGraph are cleared
  53   // outside a safepoint and without locking the ClassLoaderDataGraph_lock.
  54   // This is required to avoid a deadlock between concurrent GC threads and safepointing.
  55   //
  56   // We need to make sure that the CLD contents are fully visible to the
  57   // reader thread. This is accomplished by acquire/release of the _head,
  58   // and is sufficient.
  59   //
  60   // Any ClassLoaderData added after or during walking the list are prepended to
  61   // _head. Their claim mark need not be handled here.
  62   for (ClassLoaderData* cld = OrderAccess::load_acquire(&_head); cld != NULL; cld = cld->next()) {
  63     cld->clear_claim();
  64   }
  65 }
  66 
  67 void ClassLoaderDataGraph::clear_claimed_marks(int claim) {
  68  for (ClassLoaderData* cld = OrderAccess::load_acquire(&_head); cld != NULL; cld = cld->next()) {
  69     cld->clear_claim(claim);
  70   }
  71 }
  72 // Class iterator used by the compiler.  It gets some number of classes at
  73 // a safepoint to decay invocation counters on the methods.
  74 class ClassLoaderDataGraphKlassIteratorStatic {
  75   ClassLoaderData* _current_loader_data;
  76   Klass*           _current_class_entry;
  77  public:
  78 
  79   ClassLoaderDataGraphKlassIteratorStatic() : _current_loader_data(NULL), _current_class_entry(NULL) {}
  80 
  81   InstanceKlass* try_get_next_class() {
  82     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
  83     size_t max_classes = ClassLoaderDataGraph::num_instance_classes();
  84     assert(max_classes > 0, "should not be called with no instance classes");
  85     for (size_t i = 0; i < max_classes; ) {
  86 
  87       if (_current_class_entry != NULL) {
  88         Klass* k = _current_class_entry;


 203   ClassLoaderData* cld;
 204 
 205   // First check if another thread beat us to creating the CLD and installing
 206   // it into the loader while we were waiting for the lock.
 207   if (!is_unsafe_anonymous && loader.not_null()) {
 208     cld = java_lang_ClassLoader::loader_data_acquire(loader());
 209     if (cld != NULL) {
 210       return cld;
 211     }
 212   }
 213 
 214   // We mustn't GC until we've installed the ClassLoaderData in the Graph since the CLD
 215   // contains oops in _handles that must be walked.  GC doesn't walk CLD from the
 216   // loader oop in all collections, particularly young collections.
 217   NoSafepointVerifier no_safepoints;
 218 
 219   cld = new ClassLoaderData(loader, is_unsafe_anonymous);
 220 
 221   // First install the new CLD to the Graph.
 222   cld->set_next(_head);
 223   OrderAccess::release_store(&_head, cld);
 224 
 225   // Next associate with the class_loader.
 226   if (!is_unsafe_anonymous) {
 227     // Use OrderAccess, since readers need to get the loader_data only after
 228     // it's added to the Graph
 229     java_lang_ClassLoader::release_set_loader_data(loader(), cld);
 230   }
 231 
 232   // Lastly log, if requested
 233   LogTarget(Trace, class, loader, data) lt;
 234   if (lt.is_enabled()) {
 235     ResourceMark rm;
 236     LogStream ls(lt);
 237     ls.print("create ");
 238     cld->print_value_on(&ls);
 239     ls.cr();
 240   }
 241   return cld;
 242 }
 243 




  42 #include "runtime/safepoint.hpp"
  43 #include "runtime/safepointVerifiers.hpp"
  44 #include "utilities/growableArray.hpp"
  45 #include "utilities/macros.hpp"
  46 #include "utilities/ostream.hpp"
  47 
  48 volatile size_t ClassLoaderDataGraph::_num_array_classes = 0;
  49 volatile size_t ClassLoaderDataGraph::_num_instance_classes = 0;
  50 
  51 void ClassLoaderDataGraph::clear_claimed_marks() {
  52   // The claimed marks of the CLDs in the ClassLoaderDataGraph are cleared
  53   // outside a safepoint and without locking the ClassLoaderDataGraph_lock.
  54   // This is required to avoid a deadlock between concurrent GC threads and safepointing.
  55   //
  56   // We need to make sure that the CLD contents are fully visible to the
  57   // reader thread. This is accomplished by acquire/release of the _head,
  58   // and is sufficient.
  59   //
  60   // Any ClassLoaderData added after or during walking the list are prepended to
  61   // _head. Their claim mark need not be handled here.
  62   for (ClassLoaderData* cld = Atomic::load_acquire(&_head); cld != NULL; cld = cld->next()) {
  63     cld->clear_claim();
  64   }
  65 }
  66 
  67 void ClassLoaderDataGraph::clear_claimed_marks(int claim) {
  68  for (ClassLoaderData* cld = Atomic::load_acquire(&_head); cld != NULL; cld = cld->next()) {
  69     cld->clear_claim(claim);
  70   }
  71 }
  72 // Class iterator used by the compiler.  It gets some number of classes at
  73 // a safepoint to decay invocation counters on the methods.
  74 class ClassLoaderDataGraphKlassIteratorStatic {
  75   ClassLoaderData* _current_loader_data;
  76   Klass*           _current_class_entry;
  77  public:
  78 
  79   ClassLoaderDataGraphKlassIteratorStatic() : _current_loader_data(NULL), _current_class_entry(NULL) {}
  80 
  81   InstanceKlass* try_get_next_class() {
  82     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
  83     size_t max_classes = ClassLoaderDataGraph::num_instance_classes();
  84     assert(max_classes > 0, "should not be called with no instance classes");
  85     for (size_t i = 0; i < max_classes; ) {
  86 
  87       if (_current_class_entry != NULL) {
  88         Klass* k = _current_class_entry;


 203   ClassLoaderData* cld;
 204 
 205   // First check if another thread beat us to creating the CLD and installing
 206   // it into the loader while we were waiting for the lock.
 207   if (!is_unsafe_anonymous && loader.not_null()) {
 208     cld = java_lang_ClassLoader::loader_data_acquire(loader());
 209     if (cld != NULL) {
 210       return cld;
 211     }
 212   }
 213 
 214   // We mustn't GC until we've installed the ClassLoaderData in the Graph since the CLD
 215   // contains oops in _handles that must be walked.  GC doesn't walk CLD from the
 216   // loader oop in all collections, particularly young collections.
 217   NoSafepointVerifier no_safepoints;
 218 
 219   cld = new ClassLoaderData(loader, is_unsafe_anonymous);
 220 
 221   // First install the new CLD to the Graph.
 222   cld->set_next(_head);
 223   Atomic::release_store(&_head, cld);
 224 
 225   // Next associate with the class_loader.
 226   if (!is_unsafe_anonymous) {
 227     // Use OrderAccess, since readers need to get the loader_data only after
 228     // it's added to the Graph
 229     java_lang_ClassLoader::release_set_loader_data(loader(), cld);
 230   }
 231 
 232   // Lastly log, if requested
 233   LogTarget(Trace, class, loader, data) lt;
 234   if (lt.is_enabled()) {
 235     ResourceMark rm;
 236     LogStream ls(lt);
 237     ls.print("create ");
 238     cld->print_value_on(&ls);
 239     ls.cr();
 240   }
 241   return cld;
 242 }
 243 


< prev index next >