< prev index next >

src/hotspot/share/classfile/classLoaderData.cpp

Print this page




 593   int size;
 594   bool resizable = false;
 595   if (_the_null_class_loader_data == NULL) {
 596     size = _boot_loader_dictionary_size;
 597     resizable = true;
 598   } else if (class_loader()->is_a(SystemDictionary::reflect_DelegatingClassLoader_klass())) {
 599     size = 1;  // there's only one class in relection class loader and no initiated classes
 600   } else if (is_system_class_loader_data()) {
 601     size = _boot_loader_dictionary_size;
 602     resizable = true;
 603   } else {
 604     size = _default_loader_dictionary_size;
 605     resizable = true;
 606   }
 607   if (!DynamicallyResizeSystemDictionaries || DumpSharedSpaces || UseSharedSpaces) {
 608     resizable = false;
 609   }
 610   return new Dictionary(this, size, resizable);
 611 }
 612 















 613 // Unloading support
 614 oop ClassLoaderData::keep_alive_object() const {
 615   assert_locked_or_safepoint(_metaspace_lock);
 616   assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
 617   return is_anonymous() ? _klasses->java_mirror() : class_loader();
 618 }
 619 
 620 bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const {
 621   bool alive = keep_alive() // null class loader and incomplete anonymous klasses.
 622       || is_alive_closure->do_object_b(keep_alive_object());
 623 
 624   return alive;
 625 }
 626 
 627 class ReleaseKlassClosure: public KlassClosure {
 628 private:
 629   size_t  _instance_class_released;
 630   size_t  _array_class_released;
 631 public:
 632   ReleaseKlassClosure() : _instance_class_released(0), _array_class_released(0) { }


1031     CLDClosure* closure = cld->keep_alive() ? strong : weak;
1032     if (closure != NULL) {
1033       closure->do_cld(cld);
1034     }
1035   }
1036 }
1037 
1038 void ClassLoaderDataGraph::keep_alive_cld_do(CLDClosure* cl) {
1039   roots_cld_do(cl, NULL);
1040 }
1041 
1042 void ClassLoaderDataGraph::always_strong_cld_do(CLDClosure* cl) {
1043   if (ClassUnloading) {
1044     keep_alive_cld_do(cl);
1045   } else {
1046     cld_do(cl);
1047   }
1048 }
1049 
1050 void ClassLoaderDataGraph::classes_do(KlassClosure* klass_closure) {

1051   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {

1052     cld->classes_do(klass_closure);
1053   }
1054 }
1055 
1056 void ClassLoaderDataGraph::classes_do(void f(Klass* const)) {

1057   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {

1058     cld->classes_do(f);
1059   }
1060 }
1061 
1062 void ClassLoaderDataGraph::methods_do(void f(Method*)) {

1063   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {

1064     cld->methods_do(f);
1065   }
1066 }
1067 
1068 void ClassLoaderDataGraph::modules_do(void f(ModuleEntry*)) {
1069   assert_locked_or_safepoint(Module_lock);

1070   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {

1071     cld->modules_do(f);
1072   }
1073 }
1074 
1075 void ClassLoaderDataGraph::modules_unloading_do(void f(ModuleEntry*)) {
1076   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1077   // Only walk the head until any clds not purged from prior unloading
1078   // (CMS doesn't purge right away).
1079   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1080     assert(cld->is_unloading(), "invariant");
1081     cld->modules_do(f);
1082   }
1083 }
1084 
1085 void ClassLoaderDataGraph::packages_do(void f(PackageEntry*)) {
1086   assert_locked_or_safepoint(Module_lock);

1087   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {

1088     cld->packages_do(f);
1089   }
1090 }
1091 
1092 void ClassLoaderDataGraph::packages_unloading_do(void f(PackageEntry*)) {
1093   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1094   // Only walk the head until any clds not purged from prior unloading
1095   // (CMS doesn't purge right away).
1096   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1097     assert(cld->is_unloading(), "invariant");
1098     cld->packages_do(f);
1099   }
1100 }
1101 
1102 void ClassLoaderDataGraph::loaded_classes_do(KlassClosure* klass_closure) {

1103   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {

1104     cld->loaded_classes_do(klass_closure);
1105   }
1106 }
1107 
1108 void ClassLoaderDataGraph::classes_unloading_do(void f(Klass* const)) {
1109   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1110   // Only walk the head until any clds not purged from prior unloading
1111   // (CMS doesn't purge right away).
1112   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1113     assert(cld->is_unloading(), "invariant");
1114     cld->classes_do(f);
1115   }
1116 }
1117 
1118 #define FOR_ALL_DICTIONARY(X) for (ClassLoaderData* X = _head; X != NULL; X = X->next()) \
1119                                 if (X->dictionary() != NULL)
1120 
1121 // Walk classes in the loaded class dictionaries in various forms.
1122 // Only walks the classes defined in this class loader.
1123 void ClassLoaderDataGraph::dictionary_classes_do(void f(InstanceKlass*)) {

1124   FOR_ALL_DICTIONARY(cld) {

1125     cld->dictionary()->classes_do(f);
1126   }
1127 }
1128 
1129 // Only walks the classes defined in this class loader.
1130 void ClassLoaderDataGraph::dictionary_classes_do(void f(InstanceKlass*, TRAPS), TRAPS) {

1131   FOR_ALL_DICTIONARY(cld) {

1132     cld->dictionary()->classes_do(f, CHECK);
1133   }
1134 }
1135 
1136 // Walks all entries in the dictionary including entries initiated by this class loader.
1137 void ClassLoaderDataGraph::dictionary_all_entries_do(void f(InstanceKlass*, ClassLoaderData*)) {

1138   FOR_ALL_DICTIONARY(cld) {

1139     cld->dictionary()->all_entries_do(f);
1140   }
1141 }
1142 
1143 void ClassLoaderDataGraph::verify_dictionary() {
1144   FOR_ALL_DICTIONARY(cld) {
1145     cld->dictionary()->verify();
1146   }
1147 }
1148 
1149 void ClassLoaderDataGraph::print_dictionary(outputStream* st) {
1150   FOR_ALL_DICTIONARY(cld) {
1151     st->print("Dictionary for ");
1152     cld->print_value_on(st);
1153     st->cr();
1154     cld->dictionary()->print_on(st);
1155     st->cr();
1156   }
1157 }
1158 




 593   int size;
 594   bool resizable = false;
 595   if (_the_null_class_loader_data == NULL) {
 596     size = _boot_loader_dictionary_size;
 597     resizable = true;
 598   } else if (class_loader()->is_a(SystemDictionary::reflect_DelegatingClassLoader_klass())) {
 599     size = 1;  // there's only one class in relection class loader and no initiated classes
 600   } else if (is_system_class_loader_data()) {
 601     size = _boot_loader_dictionary_size;
 602     resizable = true;
 603   } else {
 604     size = _default_loader_dictionary_size;
 605     resizable = true;
 606   }
 607   if (!DynamicallyResizeSystemDictionaries || DumpSharedSpaces || UseSharedSpaces) {
 608     resizable = false;
 609   }
 610   return new Dictionary(this, size, resizable);
 611 }
 612 
 613 // Tell the GC to keep this klass alive while iterating ClassLoaderDataGraph
 614 oop ClassLoaderData::ensure_loader_alive() {
 615   // A klass that was previously considered dead can be looked up in the
 616   // CLD/SD, and its _java_mirror or _class_loader can be stored in a root
 617   // or a reachable object making it alive again. The SATB part of G1 needs
 618   // to get notified about this potential resurrection, otherwise the marking
 619   // might not find the object.
 620   if (!keep_alive()) {
 621     oop* o = is_anonymous() ? _klasses->java_mirror_handle().ptr_raw() : &_class_loader;
 622     return RootAccess<ON_PHANTOM_OOP_REF>::oop_load(o);
 623   } else {
 624     return NULL;
 625   }
 626 }
 627 
 628 // Unloading support
 629 oop ClassLoaderData::keep_alive_object() const {
 630   assert_locked_or_safepoint(_metaspace_lock);
 631   assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
 632   return is_anonymous() ? _klasses->java_mirror() : class_loader();
 633 }
 634 
 635 bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const {
 636   bool alive = keep_alive() // null class loader and incomplete anonymous klasses.
 637       || is_alive_closure->do_object_b(keep_alive_object());
 638 
 639   return alive;
 640 }
 641 
 642 class ReleaseKlassClosure: public KlassClosure {
 643 private:
 644   size_t  _instance_class_released;
 645   size_t  _array_class_released;
 646 public:
 647   ReleaseKlassClosure() : _instance_class_released(0), _array_class_released(0) { }


1046     CLDClosure* closure = cld->keep_alive() ? strong : weak;
1047     if (closure != NULL) {
1048       closure->do_cld(cld);
1049     }
1050   }
1051 }
1052 
1053 void ClassLoaderDataGraph::keep_alive_cld_do(CLDClosure* cl) {
1054   roots_cld_do(cl, NULL);
1055 }
1056 
1057 void ClassLoaderDataGraph::always_strong_cld_do(CLDClosure* cl) {
1058   if (ClassUnloading) {
1059     keep_alive_cld_do(cl);
1060   } else {
1061     cld_do(cl);
1062   }
1063 }
1064 
1065 void ClassLoaderDataGraph::classes_do(KlassClosure* klass_closure) {
1066   Thread* thread = Thread::current();
1067   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1068     Handle holder(thread, cld->ensure_loader_alive());
1069     cld->classes_do(klass_closure);
1070   }
1071 }
1072 
1073 void ClassLoaderDataGraph::classes_do(void f(Klass* const)) {
1074   Thread* thread = Thread::current();
1075   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1076     Handle holder(thread, cld->ensure_loader_alive());
1077     cld->classes_do(f);
1078   }
1079 }
1080 
1081 void ClassLoaderDataGraph::methods_do(void f(Method*)) {
1082   Thread* thread = Thread::current();
1083   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1084     Handle holder(thread, cld->ensure_loader_alive());
1085     cld->methods_do(f);
1086   }
1087 }
1088 
1089 void ClassLoaderDataGraph::modules_do(void f(ModuleEntry*)) {
1090   assert_locked_or_safepoint(Module_lock);
1091   Thread* thread = Thread::current();
1092   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1093     Handle holder(thread, cld->ensure_loader_alive());
1094     cld->modules_do(f);
1095   }
1096 }
1097 
1098 void ClassLoaderDataGraph::modules_unloading_do(void f(ModuleEntry*)) {
1099   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1100   // Only walk the head until any clds not purged from prior unloading
1101   // (CMS doesn't purge right away).
1102   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1103     assert(cld->is_unloading(), "invariant");
1104     cld->modules_do(f);
1105   }
1106 }
1107 
1108 void ClassLoaderDataGraph::packages_do(void f(PackageEntry*)) {
1109   assert_locked_or_safepoint(Module_lock);
1110   Thread* thread = Thread::current();
1111   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1112     Handle holder(thread, cld->ensure_loader_alive());
1113     cld->packages_do(f);
1114   }
1115 }
1116 
1117 void ClassLoaderDataGraph::packages_unloading_do(void f(PackageEntry*)) {
1118   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1119   // Only walk the head until any clds not purged from prior unloading
1120   // (CMS doesn't purge right away).
1121   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1122     assert(cld->is_unloading(), "invariant");
1123     cld->packages_do(f);
1124   }
1125 }
1126 
1127 void ClassLoaderDataGraph::loaded_classes_do(KlassClosure* klass_closure) {
1128   Thread* thread = Thread::current();
1129   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1130     Handle holder(thread, cld->ensure_loader_alive());
1131     cld->loaded_classes_do(klass_closure);
1132   }
1133 }
1134 
1135 void ClassLoaderDataGraph::classes_unloading_do(void f(Klass* const)) {
1136   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1137   // Only walk the head until any clds not purged from prior unloading
1138   // (CMS doesn't purge right away).
1139   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1140     assert(cld->is_unloading(), "invariant");
1141     cld->classes_do(f);
1142   }
1143 }
1144 
1145 #define FOR_ALL_DICTIONARY(X) for (ClassLoaderData* X = _head; X != NULL; X = X->next()) \
1146                                 if (X->dictionary() != NULL)
1147 
1148 // Walk classes in the loaded class dictionaries in various forms.
1149 // Only walks the classes defined in this class loader.
1150 void ClassLoaderDataGraph::dictionary_classes_do(void f(InstanceKlass*)) {
1151   Thread* thread = Thread::current();
1152   FOR_ALL_DICTIONARY(cld) {
1153     Handle holder(thread, cld->ensure_loader_alive());
1154     cld->dictionary()->classes_do(f);
1155   }
1156 }
1157 
1158 // Only walks the classes defined in this class loader.
1159 void ClassLoaderDataGraph::dictionary_classes_do(void f(InstanceKlass*, TRAPS), TRAPS) {
1160   Thread* thread = Thread::current();
1161   FOR_ALL_DICTIONARY(cld) {
1162     Handle holder(thread, cld->ensure_loader_alive());
1163     cld->dictionary()->classes_do(f, CHECK);
1164   }
1165 }
1166 
1167 // Walks all entries in the dictionary including entries initiated by this class loader.
1168 void ClassLoaderDataGraph::dictionary_all_entries_do(void f(InstanceKlass*, ClassLoaderData*)) {
1169   Thread* thread = Thread::current();
1170   FOR_ALL_DICTIONARY(cld) {
1171     Handle holder(thread, cld->ensure_loader_alive());
1172     cld->dictionary()->all_entries_do(f);
1173   }
1174 }
1175 
1176 void ClassLoaderDataGraph::verify_dictionary() {
1177   FOR_ALL_DICTIONARY(cld) {
1178     cld->dictionary()->verify();
1179   }
1180 }
1181 
1182 void ClassLoaderDataGraph::print_dictionary(outputStream* st) {
1183   FOR_ALL_DICTIONARY(cld) {
1184     st->print("Dictionary for ");
1185     cld->print_value_on(st);
1186     st->cr();
1187     cld->dictionary()->print_on(st);
1188     st->cr();
1189   }
1190 }
1191 


< prev index next >