< prev index next >

src/hotspot/share/classfile/classLoaderData.cpp

Print this page




 579   int size;
 580   bool resizable = false;
 581   if (_the_null_class_loader_data == NULL) {
 582     size = _boot_loader_dictionary_size;
 583     resizable = true;
 584   } else if (class_loader()->is_a(SystemDictionary::reflect_DelegatingClassLoader_klass())) {
 585     size = 1;  // there's only one class in relection class loader and no initiated classes
 586   } else if (is_system_class_loader_data()) {
 587     size = _boot_loader_dictionary_size;
 588     resizable = true;
 589   } else {
 590     size = _default_loader_dictionary_size;
 591     resizable = true;
 592   }
 593   if (!DynamicallyResizeSystemDictionaries || DumpSharedSpaces || UseSharedSpaces) {
 594     resizable = false;
 595   }
 596   return new Dictionary(this, size, resizable);
 597 }
 598 













 599 // Unloading support
 600 oop ClassLoaderData::keep_alive_object() const {
 601   assert_locked_or_safepoint(_metaspace_lock);
 602   assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
 603   return is_anonymous() ? _klasses->java_mirror() : class_loader();
 604 }
 605 
 606 bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const {
 607   bool alive = keep_alive() // null class loader and incomplete anonymous klasses.
 608       || is_alive_closure->do_object_b(keep_alive_object());
 609 
 610   return alive;
 611 }
 612 
 613 class ReleaseKlassClosure: public KlassClosure {
 614 private:
 615   size_t  _instance_class_released;
 616   size_t  _array_class_released;
 617 public:
 618   ReleaseKlassClosure() : _instance_class_released(0), _array_class_released(0) { }


1018     if (closure != NULL) {
1019       closure->do_cld(cld);
1020     }
1021   }
1022 }
1023 
1024 void ClassLoaderDataGraph::keep_alive_cld_do(CLDClosure* cl) {
1025   roots_cld_do(cl, NULL);
1026 }
1027 
1028 void ClassLoaderDataGraph::always_strong_cld_do(CLDClosure* cl) {
1029   if (ClassUnloading) {
1030     keep_alive_cld_do(cl);
1031   } else {
1032     cld_do(cl);
1033   }
1034 }
1035 
1036 void ClassLoaderDataGraph::classes_do(KlassClosure* klass_closure) {
1037   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {

1038     cld->classes_do(klass_closure);
1039   }
1040 }
1041 
1042 void ClassLoaderDataGraph::classes_do(void f(Klass* const)) {
1043   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {

1044     cld->classes_do(f);
1045   }
1046 }
1047 
1048 void ClassLoaderDataGraph::methods_do(void f(Method*)) {
1049   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {

1050     cld->methods_do(f);
1051   }
1052 }
1053 
1054 void ClassLoaderDataGraph::modules_do(void f(ModuleEntry*)) {
1055   assert_locked_or_safepoint(Module_lock);
1056   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {

1057     cld->modules_do(f);
1058   }
1059 }
1060 
1061 void ClassLoaderDataGraph::modules_unloading_do(void f(ModuleEntry*)) {
1062   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1063   // Only walk the head until any clds not purged from prior unloading
1064   // (CMS doesn't purge right away).
1065   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1066     assert(cld->is_unloading(), "invariant");
1067     cld->modules_do(f);
1068   }
1069 }
1070 
1071 void ClassLoaderDataGraph::packages_do(void f(PackageEntry*)) {
1072   assert_locked_or_safepoint(Module_lock);
1073   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {

1074     cld->packages_do(f);
1075   }
1076 }
1077 
1078 void ClassLoaderDataGraph::packages_unloading_do(void f(PackageEntry*)) {
1079   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1080   // Only walk the head until any clds not purged from prior unloading
1081   // (CMS doesn't purge right away).
1082   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1083     assert(cld->is_unloading(), "invariant");
1084     cld->packages_do(f);
1085   }
1086 }
1087 
1088 void ClassLoaderDataGraph::loaded_classes_do(KlassClosure* klass_closure) {
1089   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {

1090     cld->loaded_classes_do(klass_closure);
1091   }
1092 }
1093 
1094 void ClassLoaderDataGraph::classes_unloading_do(void f(Klass* const)) {
1095   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1096   // Only walk the head until any clds not purged from prior unloading
1097   // (CMS doesn't purge right away).
1098   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1099     assert(cld->is_unloading(), "invariant");
1100     cld->classes_do(f);
1101   }
1102 }
1103 
1104 #define FOR_ALL_DICTIONARY(X) for (ClassLoaderData* X = _head; X != NULL; X = X->next()) \
1105                                 if (X->dictionary() != NULL)
1106 
1107 // Walk classes in the loaded class dictionaries in various forms.
1108 // Only walks the classes defined in this class loader.
1109 void ClassLoaderDataGraph::dictionary_classes_do(void f(InstanceKlass*)) {
1110   FOR_ALL_DICTIONARY(cld) {

1111     cld->dictionary()->classes_do(f);
1112   }
1113 }
1114 
1115 // Only walks the classes defined in this class loader.
1116 void ClassLoaderDataGraph::dictionary_classes_do(void f(InstanceKlass*, TRAPS), TRAPS) {
1117   FOR_ALL_DICTIONARY(cld) {

1118     cld->dictionary()->classes_do(f, CHECK);
1119   }
1120 }
1121 
1122 // Walks all entries in the dictionary including entries initiated by this class loader.
1123 void ClassLoaderDataGraph::dictionary_all_entries_do(void f(InstanceKlass*, ClassLoaderData*)) {
1124   FOR_ALL_DICTIONARY(cld) {

1125     cld->dictionary()->all_entries_do(f);
1126   }
1127 }
1128 
1129 void ClassLoaderDataGraph::verify_dictionary() {
1130   FOR_ALL_DICTIONARY(cld) {

1131     cld->dictionary()->verify();
1132   }
1133 }
1134 
1135 void ClassLoaderDataGraph::print_dictionary(outputStream* st) {
1136   FOR_ALL_DICTIONARY(cld) {
1137     st->print("Dictionary for ");
1138     cld->print_value_on(st);
1139     st->cr();
1140     cld->dictionary()->print_on(st);
1141     st->cr();
1142   }
1143 }
1144 
1145 void ClassLoaderDataGraph::print_dictionary_statistics(outputStream* st) {
1146   FOR_ALL_DICTIONARY(cld) {
1147     ResourceMark rm;
1148     stringStream tempst;
1149     tempst.print("System Dictionary for %s", cld->loader_name());
1150     cld->dictionary()->print_table_statistics(st, tempst.as_string());




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


1031     if (closure != NULL) {
1032       closure->do_cld(cld);
1033     }
1034   }
1035 }
1036 
1037 void ClassLoaderDataGraph::keep_alive_cld_do(CLDClosure* cl) {
1038   roots_cld_do(cl, NULL);
1039 }
1040 
1041 void ClassLoaderDataGraph::always_strong_cld_do(CLDClosure* cl) {
1042   if (ClassUnloading) {
1043     keep_alive_cld_do(cl);
1044   } else {
1045     cld_do(cl);
1046   }
1047 }
1048 
1049 void ClassLoaderDataGraph::classes_do(KlassClosure* klass_closure) {
1050   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1051     cld->ensure_loader_alive();
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->ensure_loader_alive();
1059     cld->classes_do(f);
1060   }
1061 }
1062 
1063 void ClassLoaderDataGraph::methods_do(void f(Method*)) {
1064   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1065     cld->ensure_loader_alive();
1066     cld->methods_do(f);
1067   }
1068 }
1069 
1070 void ClassLoaderDataGraph::modules_do(void f(ModuleEntry*)) {
1071   assert_locked_or_safepoint(Module_lock);
1072   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1073     cld->ensure_loader_alive();
1074     cld->modules_do(f);
1075   }
1076 }
1077 
1078 void ClassLoaderDataGraph::modules_unloading_do(void f(ModuleEntry*)) {
1079   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1080   // Only walk the head until any clds not purged from prior unloading
1081   // (CMS doesn't purge right away).
1082   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1083     assert(cld->is_unloading(), "invariant");
1084     cld->modules_do(f);
1085   }
1086 }
1087 
1088 void ClassLoaderDataGraph::packages_do(void f(PackageEntry*)) {
1089   assert_locked_or_safepoint(Module_lock);
1090   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1091     cld->ensure_loader_alive();
1092     cld->packages_do(f);
1093   }
1094 }
1095 
1096 void ClassLoaderDataGraph::packages_unloading_do(void f(PackageEntry*)) {
1097   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1098   // Only walk the head until any clds not purged from prior unloading
1099   // (CMS doesn't purge right away).
1100   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1101     assert(cld->is_unloading(), "invariant");
1102     cld->packages_do(f);
1103   }
1104 }
1105 
1106 void ClassLoaderDataGraph::loaded_classes_do(KlassClosure* klass_closure) {
1107   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
1108     cld->ensure_loader_alive();
1109     cld->loaded_classes_do(klass_closure);
1110   }
1111 }
1112 
1113 void ClassLoaderDataGraph::classes_unloading_do(void f(Klass* const)) {
1114   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
1115   // Only walk the head until any clds not purged from prior unloading
1116   // (CMS doesn't purge right away).
1117   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
1118     assert(cld->is_unloading(), "invariant");
1119     cld->classes_do(f);
1120   }
1121 }
1122 
1123 #define FOR_ALL_DICTIONARY(X) for (ClassLoaderData* X = _head; X != NULL; X = X->next()) \
1124                                 if (X->dictionary() != NULL)
1125 
1126 // Walk classes in the loaded class dictionaries in various forms.
1127 // Only walks the classes defined in this class loader.
1128 void ClassLoaderDataGraph::dictionary_classes_do(void f(InstanceKlass*)) {
1129   FOR_ALL_DICTIONARY(cld) {
1130     cld->ensure_loader_alive();
1131     cld->dictionary()->classes_do(f);
1132   }
1133 }
1134 
1135 // Only walks the classes defined in this class loader.
1136 void ClassLoaderDataGraph::dictionary_classes_do(void f(InstanceKlass*, TRAPS), TRAPS) {
1137   FOR_ALL_DICTIONARY(cld) {
1138     cld->ensure_loader_alive();
1139     cld->dictionary()->classes_do(f, CHECK);
1140   }
1141 }
1142 
1143 // Walks all entries in the dictionary including entries initiated by this class loader.
1144 void ClassLoaderDataGraph::dictionary_all_entries_do(void f(InstanceKlass*, ClassLoaderData*)) {
1145   FOR_ALL_DICTIONARY(cld) {
1146     cld->ensure_loader_alive();
1147     cld->dictionary()->all_entries_do(f);
1148   }
1149 }
1150 
1151 void ClassLoaderDataGraph::verify_dictionary() {
1152   FOR_ALL_DICTIONARY(cld) {
1153     cld->ensure_loader_alive();
1154     cld->dictionary()->verify();
1155   }
1156 }
1157 
1158 void ClassLoaderDataGraph::print_dictionary(outputStream* st) {
1159   FOR_ALL_DICTIONARY(cld) {
1160     st->print("Dictionary for ");
1161     cld->print_value_on(st);
1162     st->cr();
1163     cld->dictionary()->print_on(st);
1164     st->cr();
1165   }
1166 }
1167 
1168 void ClassLoaderDataGraph::print_dictionary_statistics(outputStream* st) {
1169   FOR_ALL_DICTIONARY(cld) {
1170     ResourceMark rm;
1171     stringStream tempst;
1172     tempst.print("System Dictionary for %s", cld->loader_name());
1173     cld->dictionary()->print_table_statistics(st, tempst.as_string());


< prev index next >