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 |
67 #include "utilities/ticks.hpp" |
68 #include "trace/tracing.hpp" |
68 #if INCLUDE_JFR |
|
69 #include "jfr/jfr.hpp" |
|
70 #include "jfr/jfrEvents.hpp" |
69 #endif |
71 #endif |
70 |
72 |
71 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL; |
73 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL; |
72 |
74 |
73 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) : |
75 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) : |
79 _keep_alive(is_anonymous || h_class_loader.is_null()), |
81 _keep_alive(is_anonymous || h_class_loader.is_null()), |
80 _metaspace(NULL), _unloading(false), _klasses(NULL), |
82 _metaspace(NULL), _unloading(false), _klasses(NULL), |
81 _claimed(0), _jmethod_ids(NULL), _handles(), _deallocate_list(NULL), |
83 _claimed(0), _jmethod_ids(NULL), _handles(), _deallocate_list(NULL), |
82 _next(NULL), _dependencies(dependencies), |
84 _next(NULL), _dependencies(dependencies), |
83 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) { |
85 _metaspace_lock(new Mutex(Monitor::leaf+1, "Metaspace allocation lock", true)) { |
84 // empty |
86 |
|
87 JFR_ONLY(INIT_ID(this);) |
85 } |
88 } |
86 |
89 |
87 void ClassLoaderData::init_dependencies(TRAPS) { |
90 void ClassLoaderData::init_dependencies(TRAPS) { |
88 assert(!Universe::is_fully_initialized(), "should only be called when initializing"); |
91 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"); |
92 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()) { |
647 for (ClassLoaderData* cld = _head; cl != NULL && cld != NULL; cld = cld->next()) { |
645 cl->do_cld(cld); |
648 cl->do_cld(cld); |
646 } |
649 } |
647 } |
650 } |
648 |
651 |
|
652 void ClassLoaderDataGraph::cld_unloading_do(CLDClosure* cl) { |
|
653 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!"); |
|
654 // Only walk the head until any clds not purged from prior unloading |
|
655 // (CMS doesn't purge right away). |
|
656 for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) { |
|
657 assert(cld->is_unloading(), "invariant"); |
|
658 cl->do_cld(cld); |
|
659 } |
|
660 } |
|
661 |
649 void ClassLoaderDataGraph::roots_cld_do(CLDClosure* strong, CLDClosure* weak) { |
662 void ClassLoaderDataGraph::roots_cld_do(CLDClosure* strong, CLDClosure* weak) { |
650 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->_next) { |
663 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->_next) { |
651 CLDClosure* closure = cld->keep_alive() ? strong : weak; |
664 CLDClosure* closure = cld->keep_alive() ? strong : weak; |
652 if (closure != NULL) { |
665 if (closure != NULL) { |
653 closure->do_cld(cld); |
666 closure->do_cld(cld); |
738 |
751 |
739 return false; |
752 return false; |
740 } |
753 } |
741 #endif // PRODUCT |
754 #endif // PRODUCT |
742 |
755 |
|
756 #if INCLUDE_JFR |
|
757 static Ticks class_unload_time; |
|
758 static void post_class_unload_event(Klass* const k) { |
|
759 assert(k != NULL, "invariant"); |
|
760 EventClassUnload event(UNTIMED); |
|
761 event.set_endtime(class_unload_time); |
|
762 event.set_unloadedClass(k); |
|
763 event.set_definingClassLoader(k->class_loader_data()); |
|
764 event.commit(); |
|
765 } |
|
766 |
|
767 static void post_class_unload_events() { |
|
768 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!"); |
|
769 if (Jfr::is_enabled()) { |
|
770 if (EventClassUnload::is_enabled()) { |
|
771 class_unload_time = Ticks::now(); |
|
772 ClassLoaderDataGraph::classes_unloading_do(&post_class_unload_event); |
|
773 } |
|
774 Jfr::on_unloading_classes(); |
|
775 } |
|
776 } |
|
777 #endif // INCLUDE_JFR |
743 |
778 |
744 // Move class loader data from main list to the unloaded list for unloading |
779 // Move class loader data from main list to the unloaded list for unloading |
745 // and deallocation later. |
780 // and deallocation later. |
746 bool ClassLoaderDataGraph::do_unloading(BoolObjectClosure* is_alive_closure, bool clean_alive) { |
781 bool ClassLoaderDataGraph::do_unloading(BoolObjectClosure* is_alive_closure, bool clean_alive) { |
747 ClassLoaderData* data = _head; |
782 ClassLoaderData* data = _head; |
779 // Clean previous versions and the deallocate list. |
814 // Clean previous versions and the deallocate list. |
780 ClassLoaderDataGraph::clean_metaspaces(); |
815 ClassLoaderDataGraph::clean_metaspaces(); |
781 } |
816 } |
782 |
817 |
783 if (seen_dead_loader) { |
818 if (seen_dead_loader) { |
784 post_class_unload_events(); |
819 JFR_ONLY(post_class_unload_events();) |
785 } |
820 } |
786 |
821 |
787 return seen_dead_loader; |
822 return seen_dead_loader; |
788 } |
823 } |
789 |
824 |
816 ClassLoaderData* purge_me = next; |
851 ClassLoaderData* purge_me = next; |
817 next = purge_me->next(); |
852 next = purge_me->next(); |
818 delete purge_me; |
853 delete purge_me; |
819 } |
854 } |
820 Metaspace::purge(); |
855 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 } |
856 } |
836 |
857 |
837 void ClassLoaderDataGraph::free_deallocate_lists() { |
858 void ClassLoaderDataGraph::free_deallocate_lists() { |
838 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) { |
859 for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) { |
839 // We need to keep this data until InstanceKlass::purge_previous_version has been |
860 // We need to keep this data until InstanceKlass::purge_previous_version has been |
967 } else { |
988 } else { |
968 out->print("class loader " INTPTR_FORMAT, p2i(this)); |
989 out->print("class loader " INTPTR_FORMAT, p2i(this)); |
969 class_loader()->print_value_on(out); |
990 class_loader()->print_value_on(out); |
970 } |
991 } |
971 } |
992 } |
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 |
|