576 // Returns true if this class loader data is for the system class loader.
577 bool ClassLoaderData::is_system_class_loader_data() const {
578 return SystemDictionary::is_system_class_loader(class_loader());
579 }
580
581 // Returns true if this class loader data is for the platform class loader.
582 bool ClassLoaderData::is_platform_class_loader_data() const {
583 return SystemDictionary::is_platform_class_loader(class_loader());
584 }
585
586 // Returns true if this class loader data is one of the 3 builtin
587 // (boot, application/system or platform) class loaders. Note, the
588 // builtin loaders are not freed by a GC.
589 bool ClassLoaderData::is_builtin_class_loader_data() const {
590 return (is_the_null_class_loader_data() ||
591 SystemDictionary::is_system_class_loader(class_loader()) ||
592 SystemDictionary::is_platform_class_loader(class_loader()));
593 }
594
595 Metaspace* ClassLoaderData::metaspace_non_null() {
596 assert(!DumpSharedSpaces, "wrong metaspace!");
597 // If the metaspace has not been allocated, create a new one. Might want
598 // to create smaller arena for Reflection class loaders also.
599 // The reason for the delayed allocation is because some class loaders are
600 // simply for delegating with no metadata of their own.
601 // Lock-free access requires load_ptr_acquire.
602 Metaspace* metaspace = load_ptr_acquire(&_metaspace);
603 if (metaspace == NULL) {
604 MutexLockerEx ml(_metaspace_lock, Mutex::_no_safepoint_check_flag);
605 // Check if _metaspace got allocated while we were waiting for this lock.
606 if ((metaspace = _metaspace) == NULL) {
607 if (this == the_null_class_loader_data()) {
608 assert (class_loader() == NULL, "Must be");
609 metaspace = new Metaspace(_metaspace_lock, Metaspace::BootMetaspaceType);
610 } else if (is_anonymous()) {
611 if (class_loader() != NULL) {
612 log_trace(class, loader, data)("is_anonymous: %s", class_loader()->klass()->internal_name());
613 }
614 metaspace = new Metaspace(_metaspace_lock, Metaspace::AnonymousMetaspaceType);
615 } else if (class_loader()->is_a(SystemDictionary::reflect_DelegatingClassLoader_klass())) {
616 if (class_loader() != NULL) {
1107 classes_unloaded = true;
1108 }
1109 if (classes_unloaded) {
1110 Metaspace::purge();
1111 set_metaspace_oom(false);
1112 }
1113 }
1114
1115 void ClassLoaderDataGraph::post_class_unload_events() {
1116 #if INCLUDE_TRACE
1117 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1118 if (Tracing::enabled()) {
1119 if (Tracing::is_event_enabled(TraceClassUnloadEvent)) {
1120 assert(_unloading != NULL, "need class loader data unload list!");
1121 _class_unload_time = Ticks::now();
1122 classes_unloading_do(&class_unload_event);
1123 }
1124 Tracing::on_unloading_classes();
1125 }
1126 #endif
1127 }
1128
1129 // CDS support
1130
1131 // Global metaspaces for writing information to the shared archive. When
1132 // application CDS is supported, we may need one per metaspace, so this
1133 // sort of looks like it.
1134 Metaspace* ClassLoaderData::_ro_metaspace = NULL;
1135 Metaspace* ClassLoaderData::_rw_metaspace = NULL;
1136 static bool _shared_metaspaces_initialized = false;
1137
1138 // Initialize shared metaspaces (change to call from somewhere not lazily)
1139 void ClassLoaderData::initialize_shared_metaspaces() {
1140 assert(DumpSharedSpaces, "only use this for dumping shared spaces");
1141 assert(this == ClassLoaderData::the_null_class_loader_data(),
1142 "only supported for null loader data for now");
1143 assert (!_shared_metaspaces_initialized, "only initialize once");
1144 MutexLockerEx ml(metaspace_lock(), Mutex::_no_safepoint_check_flag);
1145 _ro_metaspace = new Metaspace(_metaspace_lock, Metaspace::ROMetaspaceType);
1146 _rw_metaspace = new Metaspace(_metaspace_lock, Metaspace::ReadWriteMetaspaceType);
1147 _shared_metaspaces_initialized = true;
1148 }
1149
1150 Metaspace* ClassLoaderData::ro_metaspace() {
1151 assert(_ro_metaspace != NULL, "should already be initialized");
1152 return _ro_metaspace;
1153 }
1154
1155 Metaspace* ClassLoaderData::rw_metaspace() {
1156 assert(_rw_metaspace != NULL, "should already be initialized");
1157 return _rw_metaspace;
1158 }
1159
1160 ClassLoaderDataGraphKlassIteratorAtomic::ClassLoaderDataGraphKlassIteratorAtomic()
1161 : _next_klass(NULL) {
1162 ClassLoaderData* cld = ClassLoaderDataGraph::_head;
1163 Klass* klass = NULL;
1164
1165 // Find the first klass in the CLDG.
1166 while (cld != NULL) {
1167 assert_locked_or_safepoint(cld->metaspace_lock());
1168 klass = cld->_klasses;
1169 if (klass != NULL) {
1170 _next_klass = klass;
1171 return;
1172 }
1173 cld = cld->next();
1174 }
1175 }
1176
1177 Klass* ClassLoaderDataGraphKlassIteratorAtomic::next_klass_in_cldg(Klass* klass) {
|
576 // Returns true if this class loader data is for the system class loader.
577 bool ClassLoaderData::is_system_class_loader_data() const {
578 return SystemDictionary::is_system_class_loader(class_loader());
579 }
580
581 // Returns true if this class loader data is for the platform class loader.
582 bool ClassLoaderData::is_platform_class_loader_data() const {
583 return SystemDictionary::is_platform_class_loader(class_loader());
584 }
585
586 // Returns true if this class loader data is one of the 3 builtin
587 // (boot, application/system or platform) class loaders. Note, the
588 // builtin loaders are not freed by a GC.
589 bool ClassLoaderData::is_builtin_class_loader_data() const {
590 return (is_the_null_class_loader_data() ||
591 SystemDictionary::is_system_class_loader(class_loader()) ||
592 SystemDictionary::is_platform_class_loader(class_loader()));
593 }
594
595 Metaspace* ClassLoaderData::metaspace_non_null() {
596 // If the metaspace has not been allocated, create a new one. Might want
597 // to create smaller arena for Reflection class loaders also.
598 // The reason for the delayed allocation is because some class loaders are
599 // simply for delegating with no metadata of their own.
600 // Lock-free access requires load_ptr_acquire.
601 Metaspace* metaspace = load_ptr_acquire(&_metaspace);
602 if (metaspace == NULL) {
603 MutexLockerEx ml(_metaspace_lock, Mutex::_no_safepoint_check_flag);
604 // Check if _metaspace got allocated while we were waiting for this lock.
605 if ((metaspace = _metaspace) == NULL) {
606 if (this == the_null_class_loader_data()) {
607 assert (class_loader() == NULL, "Must be");
608 metaspace = new Metaspace(_metaspace_lock, Metaspace::BootMetaspaceType);
609 } else if (is_anonymous()) {
610 if (class_loader() != NULL) {
611 log_trace(class, loader, data)("is_anonymous: %s", class_loader()->klass()->internal_name());
612 }
613 metaspace = new Metaspace(_metaspace_lock, Metaspace::AnonymousMetaspaceType);
614 } else if (class_loader()->is_a(SystemDictionary::reflect_DelegatingClassLoader_klass())) {
615 if (class_loader() != NULL) {
1106 classes_unloaded = true;
1107 }
1108 if (classes_unloaded) {
1109 Metaspace::purge();
1110 set_metaspace_oom(false);
1111 }
1112 }
1113
1114 void ClassLoaderDataGraph::post_class_unload_events() {
1115 #if INCLUDE_TRACE
1116 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1117 if (Tracing::enabled()) {
1118 if (Tracing::is_event_enabled(TraceClassUnloadEvent)) {
1119 assert(_unloading != NULL, "need class loader data unload list!");
1120 _class_unload_time = Ticks::now();
1121 classes_unloading_do(&class_unload_event);
1122 }
1123 Tracing::on_unloading_classes();
1124 }
1125 #endif
1126 }
1127
1128 ClassLoaderDataGraphKlassIteratorAtomic::ClassLoaderDataGraphKlassIteratorAtomic()
1129 : _next_klass(NULL) {
1130 ClassLoaderData* cld = ClassLoaderDataGraph::_head;
1131 Klass* klass = NULL;
1132
1133 // Find the first klass in the CLDG.
1134 while (cld != NULL) {
1135 assert_locked_or_safepoint(cld->metaspace_lock());
1136 klass = cld->_klasses;
1137 if (klass != NULL) {
1138 _next_klass = klass;
1139 return;
1140 }
1141 cld = cld->next();
1142 }
1143 }
1144
1145 Klass* ClassLoaderDataGraphKlassIteratorAtomic::next_klass_in_cldg(Klass* klass) {
|