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/metaspace/printMetaspaceInfoKlassClosure.hpp" |
|
29 #include "memory/metaspaceShared.hpp" |
29 #include "memory/resourceArea.hpp" |
30 #include "memory/resourceArea.hpp" |
30 #include "runtime/safepoint.hpp" |
31 #include "runtime/safepoint.hpp" |
31 #include "utilities/globalDefinitions.hpp" |
32 #include "utilities/globalDefinitions.hpp" |
32 #include "utilities/ostream.hpp" |
33 #include "utilities/ostream.hpp" |
33 |
34 |
37 PrintCLDMetaspaceInfoClosure::PrintCLDMetaspaceInfoClosure(outputStream* out, size_t scale, bool do_print, |
38 PrintCLDMetaspaceInfoClosure::PrintCLDMetaspaceInfoClosure(outputStream* out, size_t scale, bool do_print, |
38 bool do_print_classes, bool break_down_by_chunktype) |
39 bool do_print_classes, bool break_down_by_chunktype) |
39 : _out(out), _scale(scale), _do_print(do_print), _do_print_classes(do_print_classes) |
40 : _out(out), _scale(scale), _do_print(do_print), _do_print_classes(do_print_classes) |
40 , _break_down_by_chunktype(break_down_by_chunktype) |
41 , _break_down_by_chunktype(break_down_by_chunktype) |
41 , _num_loaders(0), _num_loaders_without_metaspace(0), _num_loaders_unloading(0) |
42 , _num_loaders(0), _num_loaders_without_metaspace(0), _num_loaders_unloading(0) |
|
43 , _num_classes(0), _num_classes_shared(0) |
42 { |
44 { |
43 memset(_num_loaders_by_spacetype, 0, sizeof(_num_loaders_by_spacetype)); |
45 memset(_num_loaders_by_spacetype, 0, sizeof(_num_loaders_by_spacetype)); |
|
46 memset(_num_classes_by_spacetype, 0, sizeof(_num_classes_by_spacetype)); |
|
47 memset(_num_classes_shared_by_spacetype, 0, sizeof(_num_classes_shared_by_spacetype)); |
44 } |
48 } |
45 |
49 |
46 static const char* classes_plural(uintx num) { |
50 // A closure just to count classes |
47 return num == 1 ? "" : "es"; |
51 class CountKlassClosure : public KlassClosure { |
48 } |
52 public: |
|
53 |
|
54 uintx _num_classes; |
|
55 uintx _num_classes_shared; |
|
56 |
|
57 CountKlassClosure() : _num_classes(0), _num_classes_shared(0) {} |
|
58 void do_klass(Klass* k) { |
|
59 _num_classes ++; |
|
60 if (k->is_shared()) { |
|
61 _num_classes_shared ++; |
|
62 } |
|
63 } |
|
64 |
|
65 }; // end: PrintKlassInfoClosure |
49 |
66 |
50 void PrintCLDMetaspaceInfoClosure::do_cld(ClassLoaderData* cld) { |
67 void PrintCLDMetaspaceInfoClosure::do_cld(ClassLoaderData* cld) { |
51 |
68 |
52 assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint"); |
69 assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint"); |
53 |
70 |
70 _stats_total.add(this_cld_stat); |
87 _stats_total.add(this_cld_stat); |
71 _num_loaders ++; |
88 _num_loaders ++; |
72 _stats_by_spacetype[msp->space_type()].add(this_cld_stat); |
89 _stats_by_spacetype[msp->space_type()].add(this_cld_stat); |
73 _num_loaders_by_spacetype[msp->space_type()] ++; |
90 _num_loaders_by_spacetype[msp->space_type()] ++; |
74 |
91 |
75 // Optionally, print. |
92 // Count classes loaded by this CLD. |
|
93 CountKlassClosure ckc; |
|
94 cld->classes_do(&ckc); |
|
95 // accumulate. |
|
96 _num_classes += ckc._num_classes; |
|
97 _num_classes_by_spacetype[msp->space_type()] += ckc._num_classes; |
|
98 _num_classes_shared += ckc._num_classes_shared; |
|
99 _num_classes_shared_by_spacetype[msp->space_type()] += ckc._num_classes_shared; |
|
100 |
|
101 // Optionally, print |
76 if (_do_print) { |
102 if (_do_print) { |
77 |
103 |
78 _out->print(UINTX_FORMAT_W(4) ": ", _num_loaders); |
104 _out->print(UINTX_FORMAT_W(4) ": ", _num_loaders); |
79 |
105 |
80 // Print "CLD for [<loader name>,] instance of <loader class name>" |
106 // Print "CLD for [<loader name>,] instance of <loader class name>" |
111 if (class_name != NULL) { |
137 if (class_name != NULL) { |
112 _out->print(" instance of %s", class_name); |
138 _out->print(" instance of %s", class_name); |
113 } |
139 } |
114 |
140 |
115 if (_do_print_classes) { |
141 if (_do_print_classes) { |
|
142 // Print a detailed description of all loaded classes. |
116 streamIndentor sti(_out, 6); |
143 streamIndentor sti(_out, 6); |
117 _out->cr_indent(); |
144 _out->cr_indent(); |
118 _out->print("Loaded classes: "); |
145 _out->print("Loaded classes"); |
|
146 if (ckc._num_classes_shared > 0) { |
|
147 _out->print("('s' = shared)"); |
|
148 } |
|
149 _out->print(":"); |
119 PrintMetaspaceInfoKlassClosure pkic(_out, true); |
150 PrintMetaspaceInfoKlassClosure pkic(_out, true); |
120 cld->classes_do(&pkic); |
151 cld->classes_do(&pkic); |
121 _out->cr_indent(); |
152 _out->cr_indent(); |
122 _out->print("-total-: "); |
153 _out->print("-total-: "); |
123 _out->print(UINTX_FORMAT " class%s", pkic._num_classes, classes_plural(pkic._num_classes)); |
154 print_number_of_classes(_out, ckc._num_classes, ckc._num_classes_shared); |
124 if (pkic._num_instance_classes > 0 || pkic._num_array_classes > 0) { |
155 } else { |
125 _out->print(" ("); |
156 // Just print a summary about how many classes have been loaded. |
126 if (pkic._num_instance_classes > 0) { |
157 _out->print(", "); |
127 _out->print(UINTX_FORMAT " instance class%s", pkic._num_instance_classes, |
158 print_number_of_classes(_out, ckc._num_classes, ckc._num_classes_shared); |
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 } |
159 } |
140 |
|
141 _out->cr(); |
|
142 |
|
143 |
|
144 _out->cr(); |
|
145 |
160 |
146 // Print statistics |
161 // Print statistics |
147 this_cld_stat.print_on(_out, _scale, _break_down_by_chunktype); |
162 this_cld_stat.print_on(_out, _scale, _break_down_by_chunktype); |
148 _out->cr(); |
163 _out->cr(); |
149 |
164 |