23 */ |
23 */ |
24 #include "precompiled.hpp" |
24 #include "precompiled.hpp" |
25 #include "classfile/classLoaderData.inline.hpp" |
25 #include "classfile/classLoaderData.inline.hpp" |
26 #include "classfile/javaClasses.hpp" |
26 #include "classfile/javaClasses.hpp" |
27 #include "memory/metaspace/printCLDMetaspaceInfoClosure.hpp" |
27 #include "memory/metaspace/printCLDMetaspaceInfoClosure.hpp" |
|
28 #include "memory/metaspace/printMetaspaceInfoKlassClosure.hpp" |
28 #include "memory/resourceArea.hpp" |
29 #include "memory/resourceArea.hpp" |
29 #include "runtime/safepoint.hpp" |
30 #include "runtime/safepoint.hpp" |
30 #include "utilities/globalDefinitions.hpp" |
31 #include "utilities/globalDefinitions.hpp" |
31 #include "utilities/ostream.hpp" |
32 #include "utilities/ostream.hpp" |
32 |
33 |
33 |
34 |
34 namespace metaspace { |
35 namespace metaspace { |
35 |
36 |
36 PrintCLDMetaspaceInfoClosure::PrintCLDMetaspaceInfoClosure(outputStream* out, size_t scale, bool do_print, bool break_down_by_chunktype) |
37 PrintCLDMetaspaceInfoClosure::PrintCLDMetaspaceInfoClosure(outputStream* out, size_t scale, bool do_print, |
37 : _out(out), _scale(scale), _do_print(do_print), _break_down_by_chunktype(break_down_by_chunktype) |
38 bool do_print_classes, bool break_down_by_chunktype) |
38 , _num_loaders(0) |
39 : _out(out), _scale(scale), _do_print(do_print), _do_print_classes(do_print_classes) |
|
40 , _break_down_by_chunktype(break_down_by_chunktype) |
|
41 , _num_loaders(0), _num_loaders_unloading(0), _num_loaders_without_metaspace(0) |
39 { |
42 { |
40 memset(_num_loaders_by_spacetype, 0, sizeof(_num_loaders_by_spacetype)); |
43 memset(_num_loaders_by_spacetype, 0, sizeof(_num_loaders_by_spacetype)); |
|
44 } |
|
45 |
|
46 static const char* classes_plural(uintx num) { |
|
47 return num == 1 ? "" : "es"; |
41 } |
48 } |
42 |
49 |
43 void PrintCLDMetaspaceInfoClosure::do_cld(ClassLoaderData* cld) { |
50 void PrintCLDMetaspaceInfoClosure::do_cld(ClassLoaderData* cld) { |
44 |
51 |
45 assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint"); |
52 assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint"); |
46 |
53 |
|
54 if (cld->is_unloading()) { |
|
55 _num_loaders_unloading ++; |
|
56 return; |
|
57 } |
|
58 |
47 ClassLoaderMetaspace* msp = cld->metaspace_or_null(); |
59 ClassLoaderMetaspace* msp = cld->metaspace_or_null(); |
48 if (msp == NULL) { |
60 if (msp == NULL) { |
|
61 _num_loaders_without_metaspace ++; |
49 return; |
62 return; |
50 } |
63 } |
51 |
64 |
52 // Collect statistics for this class loader metaspace |
65 // Collect statistics for this class loader metaspace |
53 ClassLoaderMetaspaceStatistics this_cld_stat; |
66 ClassLoaderMetaspaceStatistics this_cld_stat; |
97 } |
110 } |
98 if (class_name != NULL) { |
111 if (class_name != NULL) { |
99 _out->print(" instance of %s", class_name); |
112 _out->print(" instance of %s", class_name); |
100 } |
113 } |
101 |
114 |
|
115 if (_do_print_classes) { |
|
116 streamIndentor sti(_out, 6); |
|
117 _out->cr_indent(); |
|
118 _out->print("Loaded classes: "); |
|
119 PrintMetaspaceInfoKlassClosure pkic(_out, true); |
|
120 cld->classes_do(&pkic); |
|
121 _out->cr_indent(); |
|
122 _out->print("-total-: "); |
|
123 _out->print(UINTX_FORMAT " class%s", pkic._num_classes, classes_plural(pkic._num_classes)); |
|
124 if (pkic._num_instance_classes > 0 || pkic._num_array_classes > 0) { |
|
125 _out->print(" ("); |
|
126 if (pkic._num_instance_classes > 0) { |
|
127 _out->print(UINTX_FORMAT " instance class%s", pkic._num_instance_classes, |
|
128 classes_plural(pkic._num_instance_classes)); |
|
129 } |
|
130 if (pkic._num_array_classes > 0) { |
|
131 if (pkic._num_instance_classes > 0) { |
|
132 _out->print(", "); |
|
133 } |
|
134 _out->print(UINTX_FORMAT " array class%s", pkic._num_array_classes, |
|
135 classes_plural(pkic._num_array_classes)); |
|
136 } |
|
137 _out->print(")."); |
|
138 } |
|
139 } |
|
140 |
|
141 _out->cr(); |
|
142 |
|
143 |
102 _out->cr(); |
144 _out->cr(); |
103 |
145 |
104 // Print statistics |
146 // Print statistics |
105 this_cld_stat.print_on(_out, _scale, _break_down_by_chunktype); |
147 this_cld_stat.print_on(_out, _scale, _break_down_by_chunktype); |
106 _out->cr(); |
148 _out->cr(); |