465 } else if (m->is_klass()) { |
465 } else if (m->is_klass()) { |
466 MetadataFactory::free_metadata(this, (InstanceKlass*)m); |
466 MetadataFactory::free_metadata(this, (InstanceKlass*)m); |
467 } else { |
467 } else { |
468 ShouldNotReachHere(); |
468 ShouldNotReachHere(); |
469 } |
469 } |
|
470 } else { |
|
471 // Metadata is alive. |
|
472 // If scratch_class is on stack then it shouldn't be on this list! |
|
473 assert(!m->is_klass() || !((InstanceKlass*)m)->is_scratch_class(), |
|
474 "scratch classes on this list should be dead"); |
|
475 // Also should assert that other metadata on the list was found in handles. |
470 } |
476 } |
471 } |
477 } |
472 } |
478 } |
473 |
479 |
474 // These anonymous class loaders are to contain classes used for JSR292 |
480 // These anonymous class loaders are to contain classes used for JSR292 |
735 #endif // PRODUCT |
741 #endif // PRODUCT |
736 |
742 |
737 |
743 |
738 // Move class loader data from main list to the unloaded list for unloading |
744 // Move class loader data from main list to the unloaded list for unloading |
739 // and deallocation later. |
745 // and deallocation later. |
740 bool ClassLoaderDataGraph::do_unloading(BoolObjectClosure* is_alive_closure, bool clean_alive) { |
746 bool ClassLoaderDataGraph::do_unloading(BoolObjectClosure* is_alive_closure, |
|
747 bool clean_previous_versions) { |
|
748 |
741 ClassLoaderData* data = _head; |
749 ClassLoaderData* data = _head; |
742 ClassLoaderData* prev = NULL; |
750 ClassLoaderData* prev = NULL; |
743 bool seen_dead_loader = false; |
751 bool seen_dead_loader = false; |
744 |
752 |
|
753 // Mark metadata seen on the stack only so we can delete unneeded entries. |
|
754 // Only walk all metadata, including the expensive code cache walk, for Full GC |
|
755 // and only if class redefinition and if there's previous versions of |
|
756 // Klasses to delete. |
|
757 bool walk_all_metadata = clean_previous_versions && |
|
758 JvmtiExport::has_redefined_a_class() && |
|
759 InstanceKlass::has_previous_versions(); |
|
760 MetadataOnStackMark md_on_stack(walk_all_metadata); |
|
761 |
745 // Save previous _unloading pointer for CMS which may add to unloading list before |
762 // Save previous _unloading pointer for CMS which may add to unloading list before |
746 // purging and we don't want to rewalk the previously unloaded class loader data. |
763 // purging and we don't want to rewalk the previously unloaded class loader data. |
747 _saved_unloading = _unloading; |
764 _saved_unloading = _unloading; |
748 |
765 |
749 data = _head; |
766 data = _head; |
750 while (data != NULL) { |
767 while (data != NULL) { |
751 if (data->is_alive(is_alive_closure)) { |
768 if (data->is_alive(is_alive_closure)) { |
|
769 // clean metaspace |
|
770 if (walk_all_metadata) { |
|
771 data->classes_do(InstanceKlass::purge_previous_versions); |
|
772 } |
|
773 data->free_deallocate_list(); |
752 prev = data; |
774 prev = data; |
753 data = data->next(); |
775 data = data->next(); |
754 continue; |
776 continue; |
755 } |
777 } |
756 seen_dead_loader = true; |
778 seen_dead_loader = true; |
768 } |
790 } |
769 dead->set_next(_unloading); |
791 dead->set_next(_unloading); |
770 _unloading = dead; |
792 _unloading = dead; |
771 } |
793 } |
772 |
794 |
773 if (clean_alive) { |
|
774 // Clean previous versions and the deallocate list. |
|
775 ClassLoaderDataGraph::clean_metaspaces(); |
|
776 } |
|
777 |
|
778 if (seen_dead_loader) { |
795 if (seen_dead_loader) { |
779 post_class_unload_events(); |
796 post_class_unload_events(); |
780 } |
797 } |
781 |
798 |
782 return seen_dead_loader; |
799 return seen_dead_loader; |
783 } |
|
784 |
|
785 void ClassLoaderDataGraph::clean_metaspaces() { |
|
786 // mark metadata seen on the stack and code cache so we can delete unneeded entries. |
|
787 bool has_redefined_a_class = JvmtiExport::has_redefined_a_class(); |
|
788 MetadataOnStackMark md_on_stack(has_redefined_a_class); |
|
789 |
|
790 if (has_redefined_a_class) { |
|
791 for (ClassLoaderData* data = _head; data != NULL; data = data->next()) { |
|
792 data->classes_do(InstanceKlass::purge_previous_versions); |
|
793 } |
|
794 } |
|
795 |
|
796 // Should purge the previous version before deallocating. |
|
797 free_deallocate_lists(); |
|
798 } |
800 } |
799 |
801 |
800 void ClassLoaderDataGraph::purge() { |
802 void ClassLoaderDataGraph::purge() { |
801 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!"); |
803 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!"); |
802 ClassLoaderData* list = _unloading; |
804 ClassLoaderData* list = _unloading; |
827 Tracing::on_unloading_classes(); |
829 Tracing::on_unloading_classes(); |
828 } |
830 } |
829 #endif |
831 #endif |
830 } |
832 } |
831 |
833 |
832 void ClassLoaderDataGraph::free_deallocate_lists() { |
|
833 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) { |
|
834 cld->free_deallocate_list(); |
|
835 } |
|
836 } |
|
837 |
|
838 // CDS support |
834 // CDS support |
839 |
835 |
840 // Global metaspaces for writing information to the shared archive. When |
836 // Global metaspaces for writing information to the shared archive. When |
841 // application CDS is supported, we may need one per metaspace, so this |
837 // application CDS is supported, we may need one per metaspace, so this |
842 // sort of looks like it. |
838 // sort of looks like it. |