9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoaderData.inline.hpp"
27 #include "classfile/classLoaderDataGraph.hpp"
28 #include "classfile/classLoaderStats.hpp"
29 #include "oops/objArrayKlass.hpp"
30 #include "oops/oop.inline.hpp"
31 #include "utilities/globalDefinitions.hpp"
32
33
34 class ClassStatsClosure : public KlassClosure {
35 public:
36 int _num_classes;
37
38 ClassStatsClosure() :
39 _num_classes(0) {
40 }
41
42 virtual void do_klass(Klass* k) {
43 _num_classes++;
44 }
45 };
46
47 void ClassLoaderStatsClosure::do_cld(ClassLoaderData* cld) {
48 oop cl = cld->class_loader();
63
64 if (cl != NULL) {
65 cls->_parent = java_lang_ClassLoader::parent(cl);
66 addEmptyParents(cls->_parent);
67 }
68
69 ClassStatsClosure csc;
70 cld->classes_do(&csc);
71 bool is_hidden = false;
72 if(cld->has_class_mirror_holder()) {
73 // If cld has a class holder then it must be either hidden or unsafe anonymous.
74 // Either way, count it as a hidden class.
75 cls->_hidden_classes_count += csc._num_classes;
76 } else {
77 cls->_classes_count = csc._num_classes;
78 }
79 _total_classes += csc._num_classes;
80
81 ClassLoaderMetaspace* ms = cld->metaspace_or_null();
82 if (ms != NULL) {
83 if(cld->has_class_mirror_holder()) {
84 cls->_hidden_chunk_sz += ms->allocated_chunks_bytes();
85 cls->_hidden_block_sz += ms->allocated_blocks_bytes();
86 } else {
87 cls->_chunk_sz = ms->allocated_chunks_bytes();
88 cls->_block_sz = ms->allocated_blocks_bytes();
89 }
90 _total_chunk_sz += ms->allocated_chunks_bytes();
91 _total_block_sz += ms->allocated_blocks_bytes();
92 }
93 }
94
95
96 // Handles the difference in pointer width on 32 and 64 bit platforms
97 #ifdef _LP64
98 #define SPACE "%8s"
99 #else
100 #define SPACE "%s"
101 #endif
102
103
104 bool ClassLoaderStatsClosure::do_entry(oop const& key, ClassLoaderStats const& cls) {
105 Klass* class_loader_klass = (cls._class_loader == NULL ? NULL : cls._class_loader->klass());
106 Klass* parent_klass = (cls._parent == NULL ? NULL : cls._parent->klass());
107
108 _out->print(INTPTR_FORMAT " " INTPTR_FORMAT " " INTPTR_FORMAT " " UINTX_FORMAT_W(6) " " SIZE_FORMAT_W(8) " " SIZE_FORMAT_W(8) " ",
109 p2i(class_loader_klass), p2i(parent_klass), p2i(cls._cld),
110 cls._classes_count,
111 cls._chunk_sz, cls._block_sz);
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoaderData.inline.hpp"
27 #include "classfile/classLoaderDataGraph.hpp"
28 #include "classfile/classLoaderStats.hpp"
29 #include "memory/metaspace.hpp"
30 #include "oops/objArrayKlass.hpp"
31 #include "oops/oop.inline.hpp"
32 #include "utilities/globalDefinitions.hpp"
33
34
35 class ClassStatsClosure : public KlassClosure {
36 public:
37 int _num_classes;
38
39 ClassStatsClosure() :
40 _num_classes(0) {
41 }
42
43 virtual void do_klass(Klass* k) {
44 _num_classes++;
45 }
46 };
47
48 void ClassLoaderStatsClosure::do_cld(ClassLoaderData* cld) {
49 oop cl = cld->class_loader();
64
65 if (cl != NULL) {
66 cls->_parent = java_lang_ClassLoader::parent(cl);
67 addEmptyParents(cls->_parent);
68 }
69
70 ClassStatsClosure csc;
71 cld->classes_do(&csc);
72 bool is_hidden = false;
73 if(cld->has_class_mirror_holder()) {
74 // If cld has a class holder then it must be either hidden or unsafe anonymous.
75 // Either way, count it as a hidden class.
76 cls->_hidden_classes_count += csc._num_classes;
77 } else {
78 cls->_classes_count = csc._num_classes;
79 }
80 _total_classes += csc._num_classes;
81
82 ClassLoaderMetaspace* ms = cld->metaspace_or_null();
83 if (ms != NULL) {
84 size_t used_bytes, capacity_bytes;
85 ms->calculate_jfr_stats(&used_bytes, &capacity_bytes);
86 if(cld->has_class_mirror_holder()) {
87 cls->_hidden_chunk_sz += capacity_bytes;
88 cls->_hidden_block_sz += used_bytes;
89 } else {
90 cls->_chunk_sz = capacity_bytes;
91 cls->_block_sz = used_bytes;
92 }
93 _total_chunk_sz += capacity_bytes;
94 _total_block_sz += used_bytes;
95 }
96 }
97
98
99 // Handles the difference in pointer width on 32 and 64 bit platforms
100 #ifdef _LP64
101 #define SPACE "%8s"
102 #else
103 #define SPACE "%s"
104 #endif
105
106
107 bool ClassLoaderStatsClosure::do_entry(oop const& key, ClassLoaderStats const& cls) {
108 Klass* class_loader_klass = (cls._class_loader == NULL ? NULL : cls._class_loader->klass());
109 Klass* parent_klass = (cls._parent == NULL ? NULL : cls._parent->klass());
110
111 _out->print(INTPTR_FORMAT " " INTPTR_FORMAT " " INTPTR_FORMAT " " UINTX_FORMAT_W(6) " " SIZE_FORMAT_W(8) " " SIZE_FORMAT_W(8) " ",
112 p2i(class_loader_klass), p2i(parent_klass), p2i(cls._cld),
113 cls._classes_count,
114 cls._chunk_sz, cls._block_sz);
|