62 #include "runtime/safepoint.hpp" |
62 #include "runtime/safepoint.hpp" |
63 #include "runtime/synchronizer.hpp" |
63 #include "runtime/synchronizer.hpp" |
64 #include "utilities/growableArray.hpp" |
64 #include "utilities/growableArray.hpp" |
65 #include "utilities/macros.hpp" |
65 #include "utilities/macros.hpp" |
66 #include "utilities/ostream.hpp" |
66 #include "utilities/ostream.hpp" |
67 #if INCLUDE_TRACE |
|
68 #include "trace/tracing.hpp" |
|
69 #endif |
|
70 |
67 |
71 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL; |
68 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL; |
72 |
69 |
73 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) : |
70 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) : |
74 _class_loader(h_class_loader()), |
71 _class_loader(h_class_loader()), |
79 _keep_alive(is_anonymous || h_class_loader.is_null()), |
76 _keep_alive(is_anonymous || h_class_loader.is_null()), |
80 _metaspace(NULL), _unloading(false), _klasses(NULL), |
77 _metaspace(NULL), _unloading(false), _klasses(NULL), |
81 _claimed(0), _jmethod_ids(NULL), _handles(), _deallocate_list(NULL), |
78 _claimed(0), _jmethod_ids(NULL), _handles(), _deallocate_list(NULL), |
82 _next(NULL), _dependencies(dependencies), |
79 _next(NULL), _dependencies(dependencies), |
83 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) { |
80 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) { |
84 // empty |
81 |
|
82 JFR_ONLY(INIT_ID(this);) |
85 } |
83 } |
86 |
84 |
87 void ClassLoaderData::init_dependencies(TRAPS) { |
85 void ClassLoaderData::init_dependencies(TRAPS) { |
88 assert(!Universe::is_fully_initialized(), "should only be called when initializing"); |
86 assert(!Universe::is_fully_initialized(), "should only be called when initializing"); |
89 assert(is_the_null_class_loader_data(), "should only call this for the null class loader"); |
87 assert(is_the_null_class_loader_data(), "should only call this for the null class loader"); |
644 for (ClassLoaderData* cld = _head; cl != NULL && cld != NULL; cld = cld->next()) { |
642 for (ClassLoaderData* cld = _head; cl != NULL && cld != NULL; cld = cld->next()) { |
645 cl->do_cld(cld); |
643 cl->do_cld(cld); |
646 } |
644 } |
647 } |
645 } |
648 |
646 |
|
647 void ClassLoaderDataGraph::cld_unloading_do(CLDClosure* cl) { |
|
648 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!"); |
|
649 // Only walk the head until any clds not purged from prior unloading |
|
650 // (CMS doesn't purge right away). |
|
651 for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) { |
|
652 assert(cld->is_unloading(), "invariant"); |
|
653 cl->do_cld(cld); |
|
654 } |
|
655 } |
|
656 |
649 void ClassLoaderDataGraph::roots_cld_do(CLDClosure* strong, CLDClosure* weak) { |
657 void ClassLoaderDataGraph::roots_cld_do(CLDClosure* strong, CLDClosure* weak) { |
650 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->_next) { |
658 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->_next) { |
651 CLDClosure* closure = cld->keep_alive() ? strong : weak; |
659 CLDClosure* closure = cld->keep_alive() ? strong : weak; |
652 if (closure != NULL) { |
660 if (closure != NULL) { |
653 closure->do_cld(cld); |
661 closure->do_cld(cld); |
737 } |
745 } |
738 |
746 |
739 return false; |
747 return false; |
740 } |
748 } |
741 #endif // PRODUCT |
749 #endif // PRODUCT |
742 |
|
743 |
750 |
744 // Move class loader data from main list to the unloaded list for unloading |
751 // Move class loader data from main list to the unloaded list for unloading |
745 // and deallocation later. |
752 // and deallocation later. |
746 bool ClassLoaderDataGraph::do_unloading(BoolObjectClosure* is_alive_closure, bool clean_alive) { |
753 bool ClassLoaderDataGraph::do_unloading(BoolObjectClosure* is_alive_closure, bool clean_alive) { |
747 ClassLoaderData* data = _head; |
754 ClassLoaderData* data = _head; |
778 if (clean_alive) { |
785 if (clean_alive) { |
779 // Clean previous versions and the deallocate list. |
786 // Clean previous versions and the deallocate list. |
780 ClassLoaderDataGraph::clean_metaspaces(); |
787 ClassLoaderDataGraph::clean_metaspaces(); |
781 } |
788 } |
782 |
789 |
783 if (seen_dead_loader) { |
|
784 post_class_unload_events(); |
|
785 } |
|
786 |
|
787 return seen_dead_loader; |
790 return seen_dead_loader; |
788 } |
791 } |
789 |
792 |
790 void ClassLoaderDataGraph::clean_metaspaces() { |
793 void ClassLoaderDataGraph::clean_metaspaces() { |
791 // mark metadata seen on the stack and code cache so we can delete unneeded entries. |
794 // mark metadata seen on the stack and code cache so we can delete unneeded entries. |
816 ClassLoaderData* purge_me = next; |
819 ClassLoaderData* purge_me = next; |
817 next = purge_me->next(); |
820 next = purge_me->next(); |
818 delete purge_me; |
821 delete purge_me; |
819 } |
822 } |
820 Metaspace::purge(); |
823 Metaspace::purge(); |
821 } |
|
822 |
|
823 void ClassLoaderDataGraph::post_class_unload_events(void) { |
|
824 #if INCLUDE_TRACE |
|
825 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!"); |
|
826 if (Tracing::enabled()) { |
|
827 if (Tracing::is_event_enabled(TraceClassUnloadEvent)) { |
|
828 assert(_unloading != NULL, "need class loader data unload list!"); |
|
829 _class_unload_time = Ticks::now(); |
|
830 classes_unloading_do(&class_unload_event); |
|
831 } |
|
832 Tracing::on_unloading_classes(); |
|
833 } |
|
834 #endif |
|
835 } |
824 } |
836 |
825 |
837 void ClassLoaderDataGraph::free_deallocate_lists() { |
826 void ClassLoaderDataGraph::free_deallocate_lists() { |
838 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) { |
827 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) { |
839 // We need to keep this data until InstanceKlass::purge_previous_version has been |
828 // We need to keep this data until InstanceKlass::purge_previous_version has been |
967 } else { |
956 } else { |
968 out->print("class loader " INTPTR_FORMAT, p2i(this)); |
957 out->print("class loader " INTPTR_FORMAT, p2i(this)); |
969 class_loader()->print_value_on(out); |
958 class_loader()->print_value_on(out); |
970 } |
959 } |
971 } |
960 } |
972 |
|
973 #if INCLUDE_TRACE |
|
974 |
|
975 Ticks ClassLoaderDataGraph::_class_unload_time; |
|
976 |
|
977 void ClassLoaderDataGraph::class_unload_event(Klass* const k) { |
|
978 |
|
979 // post class unload event |
|
980 EventClassUnload event(UNTIMED); |
|
981 event.set_endtime(_class_unload_time); |
|
982 event.set_unloadedClass(k); |
|
983 oop defining_class_loader = k->class_loader(); |
|
984 event.set_definingClassLoader(defining_class_loader != NULL ? |
|
985 defining_class_loader->klass() : (Klass*)NULL); |
|
986 event.commit(); |
|
987 } |
|
988 |
|
989 #endif // INCLUDE_TRACE |
|