< prev index next >

src/hotspot/share/oops/klass.cpp

Print this page




 393     } else if (log) {
 394       if (log_is_enabled(Trace, class, unload)) {
 395         ResourceMark rm;
 396         log_trace(class, unload)("unlinking class (sibling): %s", chain->external_name());
 397       }
 398     }
 399   }
 400   return NULL;
 401 }
 402 
 403 void Klass::set_subklass(Klass* s) {
 404   assert(s != this, "sanity check");
 405   Atomic::release_store(&_subklass, s);
 406 }
 407 
 408 void Klass::set_next_sibling(Klass* s) {
 409   assert(s != this, "sanity check");
 410   // Does not need release semantics. If used by cleanup, it will link to
 411   // already safely published data, and if used by inserts, will be published
 412   // safely using cmpxchg.
 413   Atomic::store(s, &_next_sibling);
 414 }
 415 
 416 void Klass::append_to_sibling_list() {
 417   assert_locked_or_safepoint(Compile_lock);
 418   debug_only(verify();)
 419   // add ourselves to superklass' subklass list
 420   InstanceKlass* super = superklass();
 421   if (super == NULL) return;        // special case: class Object
 422   assert((!super->is_interface()    // interfaces cannot be supers
 423           && (super->superklass() == NULL || !is_interface())),
 424          "an interface can only be a subklass of Object");
 425 
 426   // Make sure there is no stale subklass head
 427   super->clean_subklass();
 428 
 429   for (;;) {
 430     Klass* prev_first_subklass = Atomic::load_acquire(&_super->_subklass);
 431     if (prev_first_subklass != NULL) {
 432       // set our sibling to be the superklass' previous first subklass
 433       assert(prev_first_subklass->is_loader_alive(), "May not attach not alive klasses");
 434       set_next_sibling(prev_first_subklass);
 435     }
 436     // Note that the prev_first_subklass is always alive, meaning no sibling_next links
 437     // are ever created to not alive klasses. This is an important invariant of the lock-free
 438     // cleaning protocol, that allows us to safely unlink dead klasses from the sibling list.
 439     if (Atomic::cmpxchg(this, &super->_subklass, prev_first_subklass) == prev_first_subklass) {
 440       return;
 441     }
 442   }
 443   debug_only(verify();)
 444 }
 445 
 446 void Klass::clean_subklass() {
 447   for (;;) {
 448     // Need load_acquire, due to contending with concurrent inserts
 449     Klass* subklass = Atomic::load_acquire(&_subklass);
 450     if (subklass == NULL || subklass->is_loader_alive()) {
 451       return;
 452     }
 453     // Try to fix _subklass until it points at something not dead.
 454     Atomic::cmpxchg(subklass->next_sibling(), &_subklass, subklass);
 455   }
 456 }
 457 
 458 void Klass::clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses) {
 459   if (!ClassUnloading || !unloading_occurred) {
 460     return;
 461   }
 462 
 463   Klass* root = SystemDictionary::Object_klass();
 464   Stack<Klass*, mtGC> stack;
 465 
 466   stack.push(root);
 467   while (!stack.is_empty()) {
 468     Klass* current = stack.pop();
 469 
 470     assert(current->is_loader_alive(), "just checking, this should be live");
 471 
 472     // Find and set the first alive subklass
 473     Klass* sub = current->subklass(true);
 474     current->clean_subklass();


 693   return name()->as_klass_external_name();
 694 }
 695 
 696 const char* Klass::signature_name() const {
 697   if (name() == NULL)  return "<unknown>";
 698   return name()->as_C_string();
 699 }
 700 
 701 const char* Klass::external_kind() const {
 702   if (is_interface()) return "interface";
 703   if (is_abstract()) return "abstract class";
 704   return "class";
 705 }
 706 
 707 // Unless overridden, modifier_flags is 0.
 708 jint Klass::compute_modifier_flags(TRAPS) const {
 709   return 0;
 710 }
 711 
 712 int Klass::atomic_incr_biased_lock_revocation_count() {
 713   return (int) Atomic::add(1, &_biased_lock_revocation_count);
 714 }
 715 
 716 // Unless overridden, jvmti_class_status has no flags set.
 717 jint Klass::jvmti_class_status() const {
 718   return 0;
 719 }
 720 
 721 
 722 // Printing
 723 
 724 void Klass::print_on(outputStream* st) const {
 725   ResourceMark rm;
 726   // print title
 727   st->print("%s", internal_name());
 728   print_address_on(st);
 729   st->cr();
 730 }
 731 
 732 #define BULLET  " - "
 733 




 393     } else if (log) {
 394       if (log_is_enabled(Trace, class, unload)) {
 395         ResourceMark rm;
 396         log_trace(class, unload)("unlinking class (sibling): %s", chain->external_name());
 397       }
 398     }
 399   }
 400   return NULL;
 401 }
 402 
 403 void Klass::set_subklass(Klass* s) {
 404   assert(s != this, "sanity check");
 405   Atomic::release_store(&_subklass, s);
 406 }
 407 
 408 void Klass::set_next_sibling(Klass* s) {
 409   assert(s != this, "sanity check");
 410   // Does not need release semantics. If used by cleanup, it will link to
 411   // already safely published data, and if used by inserts, will be published
 412   // safely using cmpxchg.
 413   Atomic::store(&_next_sibling, s);
 414 }
 415 
 416 void Klass::append_to_sibling_list() {
 417   assert_locked_or_safepoint(Compile_lock);
 418   debug_only(verify();)
 419   // add ourselves to superklass' subklass list
 420   InstanceKlass* super = superklass();
 421   if (super == NULL) return;        // special case: class Object
 422   assert((!super->is_interface()    // interfaces cannot be supers
 423           && (super->superklass() == NULL || !is_interface())),
 424          "an interface can only be a subklass of Object");
 425 
 426   // Make sure there is no stale subklass head
 427   super->clean_subklass();
 428 
 429   for (;;) {
 430     Klass* prev_first_subklass = Atomic::load_acquire(&_super->_subklass);
 431     if (prev_first_subklass != NULL) {
 432       // set our sibling to be the superklass' previous first subklass
 433       assert(prev_first_subklass->is_loader_alive(), "May not attach not alive klasses");
 434       set_next_sibling(prev_first_subklass);
 435     }
 436     // Note that the prev_first_subklass is always alive, meaning no sibling_next links
 437     // are ever created to not alive klasses. This is an important invariant of the lock-free
 438     // cleaning protocol, that allows us to safely unlink dead klasses from the sibling list.
 439     if (Atomic::cmpxchg(&super->_subklass, prev_first_subklass, this) == prev_first_subklass) {
 440       return;
 441     }
 442   }
 443   debug_only(verify();)
 444 }
 445 
 446 void Klass::clean_subklass() {
 447   for (;;) {
 448     // Need load_acquire, due to contending with concurrent inserts
 449     Klass* subklass = Atomic::load_acquire(&_subklass);
 450     if (subklass == NULL || subklass->is_loader_alive()) {
 451       return;
 452     }
 453     // Try to fix _subklass until it points at something not dead.
 454     Atomic::cmpxchg(&_subklass, subklass, subklass->next_sibling());
 455   }
 456 }
 457 
 458 void Klass::clean_weak_klass_links(bool unloading_occurred, bool clean_alive_klasses) {
 459   if (!ClassUnloading || !unloading_occurred) {
 460     return;
 461   }
 462 
 463   Klass* root = SystemDictionary::Object_klass();
 464   Stack<Klass*, mtGC> stack;
 465 
 466   stack.push(root);
 467   while (!stack.is_empty()) {
 468     Klass* current = stack.pop();
 469 
 470     assert(current->is_loader_alive(), "just checking, this should be live");
 471 
 472     // Find and set the first alive subklass
 473     Klass* sub = current->subklass(true);
 474     current->clean_subklass();


 693   return name()->as_klass_external_name();
 694 }
 695 
 696 const char* Klass::signature_name() const {
 697   if (name() == NULL)  return "<unknown>";
 698   return name()->as_C_string();
 699 }
 700 
 701 const char* Klass::external_kind() const {
 702   if (is_interface()) return "interface";
 703   if (is_abstract()) return "abstract class";
 704   return "class";
 705 }
 706 
 707 // Unless overridden, modifier_flags is 0.
 708 jint Klass::compute_modifier_flags(TRAPS) const {
 709   return 0;
 710 }
 711 
 712 int Klass::atomic_incr_biased_lock_revocation_count() {
 713   return (int) Atomic::add(&_biased_lock_revocation_count, 1);
 714 }
 715 
 716 // Unless overridden, jvmti_class_status has no flags set.
 717 jint Klass::jvmti_class_status() const {
 718   return 0;
 719 }
 720 
 721 
 722 // Printing
 723 
 724 void Klass::print_on(outputStream* st) const {
 725   ResourceMark rm;
 726   // print title
 727   st->print("%s", internal_name());
 728   print_address_on(st);
 729   st->cr();
 730 }
 731 
 732 #define BULLET  " - "
 733 


< prev index next >