1 /*
2 * Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
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 "classfile/classLoaderData.inline.hpp"
26 #include "classfile/classLoaderDataGraph.hpp"
27 #include "classfile/classLoaderStats.hpp"
28 #include "memory/classLoaderMetaspace.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 // Class loaders are not kept alive so this closure must only be
49 // used during a safepoint.
50 assert_at_safepoint();
51 oop cl = cld->class_loader_no_keepalive();
52
53 // The hashtable key is the ClassLoader oop since we want to account
54 // for "real" classes and hidden classes together
55 bool added = false;
56 ClassLoaderStats* cls = _stats->put_if_absent(cl, &added);
57 if (added) {
58 cls->_class_loader = cl;
59 _total_loaders++;
60 }
61 assert(cls->_class_loader == cl, "Sanity");
62
63 if (!cld->has_class_mirror_holder()) {
64 cls->_cld = cld;
|
1 /*
2 * Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
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 "classfile/classLoaderData.inline.hpp"
26 #include "classfile/classLoaderDataGraph.hpp"
27 #include "classfile/classLoaderStats.hpp"
28 #include "memory/classLoaderMetaspace.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 // Some klasses should not be reported by ClassStatistics
36 bool exclude_klass(Klass* k) const {
37 // Direct instances of ObjArrayKlass represent the Java types that Java code can see.
38 // RefArrayKlass/FlatArrayKlass describe different implementations of the arrays, filter them out.
39 if (k->is_objArray_klass() && k->kind() != Klass::KlassKind::ObjArrayKlassKind) {
40 return true;
41 }
42 return false;
43 }
44
45 public:
46 int _num_classes;
47
48 ClassStatsClosure() :
49 _num_classes(0) {
50 }
51
52 virtual void do_klass(Klass* k) {
53 if (!exclude_klass(k)) {
54 _num_classes++;
55 }
56 }
57
58 };
59
60 void ClassLoaderStatsClosure::do_cld(ClassLoaderData* cld) {
61 // Class loaders are not kept alive so this closure must only be
62 // used during a safepoint.
63 assert_at_safepoint();
64 oop cl = cld->class_loader_no_keepalive();
65
66 // The hashtable key is the ClassLoader oop since we want to account
67 // for "real" classes and hidden classes together
68 bool added = false;
69 ClassLoaderStats* cls = _stats->put_if_absent(cl, &added);
70 if (added) {
71 cls->_class_loader = cl;
72 _total_loaders++;
73 }
74 assert(cls->_class_loader == cl, "Sanity");
75
76 if (!cld->has_class_mirror_holder()) {
77 cls->_cld = cld;
|