Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/memory/metaspace/printCLDMetaspaceInfoClosure.cpp
40957 views
1
/*
2
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2018, 2020 SAP SE. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*
24
*/
25
26
#include "precompiled.hpp"
27
#include "classfile/classLoaderData.inline.hpp"
28
#include "classfile/javaClasses.hpp"
29
#include "memory/classLoaderMetaspace.hpp"
30
#include "memory/metaspace/metaspaceCommon.hpp"
31
#include "memory/metaspace/printCLDMetaspaceInfoClosure.hpp"
32
#include "memory/metaspace/printMetaspaceInfoKlassClosure.hpp"
33
#include "memory/resourceArea.hpp"
34
#include "runtime/safepoint.hpp"
35
#include "utilities/globalDefinitions.hpp"
36
#include "utilities/ostream.hpp"
37
38
namespace metaspace {
39
40
PrintCLDMetaspaceInfoClosure::PrintCLDMetaspaceInfoClosure(outputStream* out, size_t scale, bool do_print,
41
bool do_print_classes, bool break_down_by_chunktype) :
42
_out(out),
43
_scale(scale),
44
_do_print(do_print),
45
_do_print_classes(do_print_classes),
46
_break_down_by_chunktype(break_down_by_chunktype),
47
_num_loaders(0),
48
_num_loaders_without_metaspace(0),
49
_num_loaders_unloading(0),
50
_num_classes(0), _num_classes_shared(0)
51
{
52
memset(_num_loaders_by_spacetype, 0, sizeof(_num_loaders_by_spacetype));
53
memset(_num_classes_by_spacetype, 0, sizeof(_num_classes_by_spacetype));
54
memset(_num_classes_shared_by_spacetype, 0, sizeof(_num_classes_shared_by_spacetype));
55
}
56
57
// A closure just to count classes
58
class CountKlassClosure : public KlassClosure {
59
public:
60
61
uintx _num_classes;
62
uintx _num_classes_shared;
63
64
CountKlassClosure() : _num_classes(0), _num_classes_shared(0) {}
65
void do_klass(Klass* k) {
66
_num_classes++;
67
if (k->is_shared()) {
68
_num_classes_shared++;
69
}
70
}
71
72
}; // end: PrintKlassInfoClosure
73
74
void PrintCLDMetaspaceInfoClosure::do_cld(ClassLoaderData* cld) {
75
assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
76
77
if (cld->is_unloading()) {
78
_num_loaders_unloading++;
79
return;
80
}
81
82
ClassLoaderMetaspace* msp = cld->metaspace_or_null();
83
if (msp == NULL) {
84
_num_loaders_without_metaspace++;
85
return;
86
}
87
88
// Collect statistics for this class loader metaspace
89
ClmsStats this_cld_stat;
90
msp->add_to_statistics(&this_cld_stat);
91
92
// And add it to the running totals
93
_stats_total.add(this_cld_stat);
94
_num_loaders++;
95
_stats_by_spacetype[msp->space_type()].add(this_cld_stat);
96
_num_loaders_by_spacetype[msp->space_type()] ++;
97
98
// Count classes loaded by this CLD.
99
CountKlassClosure ckc;
100
cld->classes_do(&ckc);
101
// accumulate.
102
_num_classes += ckc._num_classes;
103
_num_classes_by_spacetype[msp->space_type()] += ckc._num_classes;
104
_num_classes_shared += ckc._num_classes_shared;
105
_num_classes_shared_by_spacetype[msp->space_type()] += ckc._num_classes_shared;
106
107
// Optionally, print
108
if (_do_print) {
109
_out->print(UINTX_FORMAT_W(4) ": ", _num_loaders);
110
111
// Print "CLD for [<loader name>,] instance of <loader class name>"
112
// or "CLD for <hidden>, loaded by [<loader name>,] instance of <loader class name>"
113
ResourceMark rm;
114
const char* name = NULL;
115
const char* class_name = NULL;
116
117
// Note: this should also work if unloading:
118
Klass* k = cld->class_loader_klass();
119
if (k != NULL) {
120
class_name = k->external_name();
121
Symbol* s = cld->name();
122
if (s != NULL) {
123
name = s->as_C_string();
124
}
125
} else {
126
name = "<bootstrap>";
127
}
128
129
// Print
130
_out->print("CLD " PTR_FORMAT, p2i(cld));
131
if (cld->is_unloading()) {
132
_out->print(" (unloading)");
133
}
134
_out->print(":");
135
if (cld->has_class_mirror_holder()) {
136
_out->print(" <hidden class>, loaded by");
137
}
138
if (name != NULL) {
139
_out->print(" \"%s\"", name);
140
}
141
if (class_name != NULL) {
142
_out->print(" instance of %s", class_name);
143
}
144
145
if (_do_print_classes) {
146
// Print a detailed description of all loaded classes.
147
streamIndentor sti(_out, 6);
148
_out->cr_indent();
149
_out->print("Loaded classes");
150
if (ckc._num_classes_shared > 0) {
151
_out->print("('s' = shared)");
152
}
153
_out->print(":");
154
PrintMetaspaceInfoKlassClosure pkic(_out, true);
155
cld->classes_do(&pkic);
156
_out->cr_indent();
157
_out->print("-total-: ");
158
print_number_of_classes(_out, ckc._num_classes, ckc._num_classes_shared);
159
} else {
160
// Just print a summary about how many classes have been loaded.
161
_out->print(", ");
162
print_number_of_classes(_out, ckc._num_classes, ckc._num_classes_shared);
163
}
164
165
// Print statistics
166
this_cld_stat.print_on(_out, _scale, _break_down_by_chunktype);
167
_out->cr();
168
}
169
}
170
171
} // namespace metaspace
172
173
174