src/share/vm/classfile/classLoaderData.cpp

Print this page
rev 6621 : 8047812: Ensure ClassLoaderDataGraph::classes_unloading_do only
delivers klasses from CLDs with non-reclaimed class loader oops
Reviewed-by:


 532   }
 533 
 534   for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
 535     guarantee(k->class_loader_data() == this, "Must be the same");
 536     k->verify();
 537     assert(k != k->next_link(), "no loops!");
 538   }
 539 }
 540 
 541 bool ClassLoaderData::contains_klass(Klass* klass) {
 542   for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
 543     if (k == klass) return true;
 544   }
 545   return false;
 546 }
 547 
 548 
 549 // GC root of class loader data created.
 550 ClassLoaderData* ClassLoaderDataGraph::_head = NULL;
 551 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL;

 552 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL;
 553 
 554 bool ClassLoaderDataGraph::_should_purge = false;
 555 
 556 // Add a new class loader data node to the list.  Assign the newly created
 557 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field
 558 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous, TRAPS) {
 559   // We need to allocate all the oops for the ClassLoaderData before allocating the
 560   // actual ClassLoaderData object.
 561   ClassLoaderData::Dependencies dependencies(CHECK_NULL);
 562 
 563   No_Safepoint_Verifier no_safepoints; // we mustn't GC until we've installed the
 564                                        // ClassLoaderData in the graph since the CLD
 565                                        // contains unhandled oops
 566 
 567   ClassLoaderData* cld = new ClassLoaderData(loader, is_anonymous, dependencies);
 568 
 569 
 570   if (!is_anonymous) {
 571     ClassLoaderData** cld_addr = java_lang_ClassLoader::loader_data_addr(loader());


 639 void ClassLoaderDataGraph::classes_do(void f(Klass* const)) {
 640   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
 641     cld->classes_do(f);
 642   }
 643 }
 644 
 645 void ClassLoaderDataGraph::methods_do(void f(Method*)) {
 646   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
 647     cld->methods_do(f);
 648   }
 649 }
 650 
 651 void ClassLoaderDataGraph::loaded_classes_do(KlassClosure* klass_closure) {
 652   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
 653     cld->loaded_classes_do(klass_closure);
 654   }
 655 }
 656 
 657 void ClassLoaderDataGraph::classes_unloading_do(void f(Klass* const)) {
 658   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
 659   for (ClassLoaderData* cld = _unloading; cld != NULL; cld = cld->next()) {


 660     cld->classes_do(f);
 661   }
 662 }
 663 
 664 GrowableArray<ClassLoaderData*>* ClassLoaderDataGraph::new_clds() {
 665   assert(_head == NULL || _saved_head != NULL, "remember_new_clds(true) not called?");
 666 
 667   GrowableArray<ClassLoaderData*>* array = new GrowableArray<ClassLoaderData*>();
 668 
 669   // The CLDs in [_head, _saved_head] were all added during last call to remember_new_clds(true);
 670   ClassLoaderData* curr = _head;
 671   while (curr != _saved_head) {
 672     if (!curr->claimed()) {
 673       array->push(curr);
 674 
 675       if (TraceClassLoaderData) {
 676         tty->print("[ClassLoaderData] found new CLD: ");
 677         curr->print_value_on(tty);
 678         tty->cr();
 679       }


 687 
 688 #ifndef PRODUCT
 689 bool ClassLoaderDataGraph::contains_loader_data(ClassLoaderData* loader_data) {
 690   for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
 691     if (loader_data == data) {
 692       return true;
 693     }
 694   }
 695 
 696   return false;
 697 }
 698 #endif // PRODUCT
 699 
 700 
 701 // Move class loader data from main list to the unloaded list for unloading
 702 // and deallocation later.
 703 bool ClassLoaderDataGraph::do_unloading(BoolObjectClosure* is_alive_closure) {
 704   ClassLoaderData* data = _head;
 705   ClassLoaderData* prev = NULL;
 706   bool seen_dead_loader = false;





 707   // mark metadata seen on the stack and code cache so we can delete
 708   // unneeded entries.
 709   bool has_redefined_a_class = JvmtiExport::has_redefined_a_class();
 710   MetadataOnStackMark md_on_stack;
 711   while (data != NULL) {
 712     if (data->is_alive(is_alive_closure)) {
 713       if (has_redefined_a_class) {
 714         data->classes_do(InstanceKlass::purge_previous_versions);
 715       }
 716       data->free_deallocate_list();
 717       prev = data;
 718       data = data->next();
 719       continue;
 720     }
 721     seen_dead_loader = true;
 722     ClassLoaderData* dead = data;
 723     dead->unload();
 724     data = data->next();
 725     // Remove from loader list.
 726     // This class loader data will no longer be found




 532   }
 533 
 534   for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
 535     guarantee(k->class_loader_data() == this, "Must be the same");
 536     k->verify();
 537     assert(k != k->next_link(), "no loops!");
 538   }
 539 }
 540 
 541 bool ClassLoaderData::contains_klass(Klass* klass) {
 542   for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
 543     if (k == klass) return true;
 544   }
 545   return false;
 546 }
 547 
 548 
 549 // GC root of class loader data created.
 550 ClassLoaderData* ClassLoaderDataGraph::_head = NULL;
 551 ClassLoaderData* ClassLoaderDataGraph::_unloading = NULL;
 552 ClassLoaderData* ClassLoaderDataGraph::_saved_unloading = NULL;
 553 ClassLoaderData* ClassLoaderDataGraph::_saved_head = NULL;
 554 
 555 bool ClassLoaderDataGraph::_should_purge = false;
 556 
 557 // Add a new class loader data node to the list.  Assign the newly created
 558 // ClassLoaderData into the java/lang/ClassLoader object as a hidden field
 559 ClassLoaderData* ClassLoaderDataGraph::add(Handle loader, bool is_anonymous, TRAPS) {
 560   // We need to allocate all the oops for the ClassLoaderData before allocating the
 561   // actual ClassLoaderData object.
 562   ClassLoaderData::Dependencies dependencies(CHECK_NULL);
 563 
 564   No_Safepoint_Verifier no_safepoints; // we mustn't GC until we've installed the
 565                                        // ClassLoaderData in the graph since the CLD
 566                                        // contains unhandled oops
 567 
 568   ClassLoaderData* cld = new ClassLoaderData(loader, is_anonymous, dependencies);
 569 
 570 
 571   if (!is_anonymous) {
 572     ClassLoaderData** cld_addr = java_lang_ClassLoader::loader_data_addr(loader());


 640 void ClassLoaderDataGraph::classes_do(void f(Klass* const)) {
 641   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
 642     cld->classes_do(f);
 643   }
 644 }
 645 
 646 void ClassLoaderDataGraph::methods_do(void f(Method*)) {
 647   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
 648     cld->methods_do(f);
 649   }
 650 }
 651 
 652 void ClassLoaderDataGraph::loaded_classes_do(KlassClosure* klass_closure) {
 653   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
 654     cld->loaded_classes_do(klass_closure);
 655   }
 656 }
 657 
 658 void ClassLoaderDataGraph::classes_unloading_do(void f(Klass* const)) {
 659   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
 660   // Only walk the head until any clds not purged from prior unloading
 661   // (CMS doesn't purge right away).
 662   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
 663     cld->classes_do(f);
 664   }
 665 }
 666 
 667 GrowableArray<ClassLoaderData*>* ClassLoaderDataGraph::new_clds() {
 668   assert(_head == NULL || _saved_head != NULL, "remember_new_clds(true) not called?");
 669 
 670   GrowableArray<ClassLoaderData*>* array = new GrowableArray<ClassLoaderData*>();
 671 
 672   // The CLDs in [_head, _saved_head] were all added during last call to remember_new_clds(true);
 673   ClassLoaderData* curr = _head;
 674   while (curr != _saved_head) {
 675     if (!curr->claimed()) {
 676       array->push(curr);
 677 
 678       if (TraceClassLoaderData) {
 679         tty->print("[ClassLoaderData] found new CLD: ");
 680         curr->print_value_on(tty);
 681         tty->cr();
 682       }


 690 
 691 #ifndef PRODUCT
 692 bool ClassLoaderDataGraph::contains_loader_data(ClassLoaderData* loader_data) {
 693   for (ClassLoaderData* data = _head; data != NULL; data = data->next()) {
 694     if (loader_data == data) {
 695       return true;
 696     }
 697   }
 698 
 699   return false;
 700 }
 701 #endif // PRODUCT
 702 
 703 
 704 // Move class loader data from main list to the unloaded list for unloading
 705 // and deallocation later.
 706 bool ClassLoaderDataGraph::do_unloading(BoolObjectClosure* is_alive_closure) {
 707   ClassLoaderData* data = _head;
 708   ClassLoaderData* prev = NULL;
 709   bool seen_dead_loader = false;
 710 
 711   // Save previous _unloading pointer for CMS which may add to unloading list before
 712   // purging and we don't want to rewalk the previously unloaded class loader data.
 713   _saved_unloading = _unloading;
 714 
 715   // mark metadata seen on the stack and code cache so we can delete
 716   // unneeded entries.
 717   bool has_redefined_a_class = JvmtiExport::has_redefined_a_class();
 718   MetadataOnStackMark md_on_stack;
 719   while (data != NULL) {
 720     if (data->is_alive(is_alive_closure)) {
 721       if (has_redefined_a_class) {
 722         data->classes_do(InstanceKlass::purge_previous_versions);
 723       }
 724       data->free_deallocate_list();
 725       prev = data;
 726       data = data->next();
 727       continue;
 728     }
 729     seen_dead_loader = true;
 730     ClassLoaderData* dead = data;
 731     dead->unload();
 732     data = data->next();
 733     // Remove from loader list.
 734     // This class loader data will no longer be found