hotspot/src/share/vm/classfile/classLoaderData.cpp
changeset 22900 e699fc9dc806
parent 22201 9c2ccfa3a5fe
child 22905 4b1549d69106
equal deleted inserted replaced
22899:e2a6bf7f343a 22900:e699fc9dc806
    71 
    71 
    72 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
    72 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
    73 
    73 
    74 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
    74 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
    75   _class_loader(h_class_loader()),
    75   _class_loader(h_class_loader()),
    76   _is_anonymous(is_anonymous), _keep_alive(is_anonymous), // initially
    76   _is_anonymous(is_anonymous),
       
    77   // An anonymous class loader data doesn't have anything to keep
       
    78   // it from being unloaded during parsing of the anonymous class.
       
    79   // The null-class-loader should always be kept alive.
       
    80   _keep_alive(is_anonymous || h_class_loader.is_null()),
    77   _metaspace(NULL), _unloading(false), _klasses(NULL),
    81   _metaspace(NULL), _unloading(false), _klasses(NULL),
    78   _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL),
    82   _claimed(0), _jmethod_ids(NULL), _handles(NULL), _deallocate_list(NULL),
    79   _next(NULL), _dependencies(dependencies),
    83   _next(NULL), _dependencies(dependencies),
    80   _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) {
    84   _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) {
    81     // empty
    85     // empty
   315     }
   319     }
   316     tty->print_cr("]");
   320     tty->print_cr("]");
   317   }
   321   }
   318 }
   322 }
   319 
   323 
       
   324 oop ClassLoaderData::keep_alive_object() const {
       
   325   assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
       
   326   return is_anonymous() ? _klasses->java_mirror() : class_loader();
       
   327 }
       
   328 
   320 bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const {
   329 bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const {
   321   bool alive =
   330   bool alive = keep_alive() // null class loader and incomplete anonymous klasses.
   322     is_anonymous() ?
   331       || is_alive_closure->do_object_b(keep_alive_object());
   323        is_alive_closure->do_object_b(_klasses->java_mirror()) :
   332 
   324        class_loader() == NULL || is_alive_closure->do_object_b(class_loader());
       
   325   assert(!alive || claimed(), "must be claimed");
   333   assert(!alive || claimed(), "must be claimed");
   326   return alive;
   334   return alive;
   327 }
   335 }
   328 
   336 
   329 
   337 
   589   }
   597   }
   590 }
   598 }
   591 
   599 
   592 void ClassLoaderDataGraph::always_strong_oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) {
   600 void ClassLoaderDataGraph::always_strong_oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) {
   593   if (ClassUnloading) {
   601   if (ClassUnloading) {
   594     ClassLoaderData::the_null_class_loader_data()->oops_do(f, klass_closure, must_claim);
       
   595     // keep any special CLDs alive.
       
   596     ClassLoaderDataGraph::keep_alive_oops_do(f, klass_closure, must_claim);
   602     ClassLoaderDataGraph::keep_alive_oops_do(f, klass_closure, must_claim);
   597   } else {
   603   } else {
   598     ClassLoaderDataGraph::oops_do(f, klass_closure, must_claim);
   604     ClassLoaderDataGraph::oops_do(f, klass_closure, must_claim);
   599   }
   605   }
   600 }
   606 }
   696   // mark metadata seen on the stack and code cache so we can delete
   702   // mark metadata seen on the stack and code cache so we can delete
   697   // unneeded entries.
   703   // unneeded entries.
   698   bool has_redefined_a_class = JvmtiExport::has_redefined_a_class();
   704   bool has_redefined_a_class = JvmtiExport::has_redefined_a_class();
   699   MetadataOnStackMark md_on_stack;
   705   MetadataOnStackMark md_on_stack;
   700   while (data != NULL) {
   706   while (data != NULL) {
   701     if (data->keep_alive() || data->is_alive(is_alive_closure)) {
   707     if (data->is_alive(is_alive_closure)) {
   702       if (has_redefined_a_class) {
   708       if (has_redefined_a_class) {
   703         data->classes_do(InstanceKlass::purge_previous_versions);
   709         data->classes_do(InstanceKlass::purge_previous_versions);
   704       }
   710       }
   705       data->free_deallocate_list();
   711       data->free_deallocate_list();
   706       prev = data;
   712       prev = data;