1 /*
2 * Copyright (c) 2020, 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 "cds/aotClassLinker.hpp"
26 #include "cds/cdsConfig.hpp"
27 #include "cds/dumpAllocStats.hpp"
28 #include "logging/log.hpp"
29 #include "logging/logMessage.hpp"
30
31 void DumpAllocStats::print_stats(int ro_all, int rw_all) {
32 // symbols
33 _counts[RO][SymbolHashentryType] = _symbol_stats.hashentry_count;
34 _bytes [RO][SymbolHashentryType] = _symbol_stats.hashentry_bytes;
35
36 _counts[RO][SymbolBucketType] = _symbol_stats.bucket_count;
37 _bytes [RO][SymbolBucketType] = _symbol_stats.bucket_bytes;
38
39 // strings
40 _counts[RO][StringHashentryType] = _string_stats.hashentry_count;
41 _bytes [RO][StringHashentryType] = _string_stats.hashentry_bytes;
42
43 _counts[RO][StringBucketType] = _string_stats.bucket_count;
44 _bytes [RO][StringBucketType] = _string_stats.bucket_bytes;
45
46 int all_ro_count = 0;
47 int all_ro_bytes = 0;
48 int all_rw_count = 0;
49 int all_rw_bytes = 0;
50
51 // To make fmt_stats be a syntactic constant (for format warnings), use #define.
52 #define fmt_stats "%-20s: %8d %10d %5.1f | %8d %10d %5.1f | %8d %10d %5.1f"
53 const char *sep = "--------------------+---------------------------+---------------------------+--------------------------";
54 const char *hdr = " ro_cnt ro_bytes % | rw_cnt rw_bytes % | all_cnt all_bytes %";
55
56 LogMessage(aot) msg;
57
58 msg.debug("Detailed metadata info (excluding heap region):");
59 msg.debug("%s", hdr);
60 msg.debug("%s", sep);
61 for (int type = 0; type < int(_number_of_types); type ++) {
62 const char *name = type_name((Type)type);
63 int ro_count = _counts[RO][type];
64 int ro_bytes = _bytes [RO][type];
65 int rw_count = _counts[RW][type];
66 int rw_bytes = _bytes [RW][type];
67 int count = ro_count + rw_count;
68 int bytes = ro_bytes + rw_bytes;
69
70 double ro_perc = percent_of(ro_bytes, ro_all);
71 double rw_perc = percent_of(rw_bytes, rw_all);
72 double perc = percent_of(bytes, ro_all + rw_all);
73
74 msg.debug(fmt_stats, name,
75 ro_count, ro_bytes, ro_perc,
76 rw_count, rw_bytes, rw_perc,
77 count, bytes, perc);
78
79 all_ro_count += ro_count;
80 all_ro_bytes += ro_bytes;
81 all_rw_count += rw_count;
82 all_rw_bytes += rw_bytes;
83 }
84
85 int all_count = all_ro_count + all_rw_count;
86 int all_bytes = all_ro_bytes + all_rw_bytes;
87
88 double all_ro_perc = percent_of(all_ro_bytes, ro_all);
89 double all_rw_perc = percent_of(all_rw_bytes, rw_all);
90 double all_perc = percent_of(all_bytes, ro_all + rw_all);
91
92 msg.debug("%s", sep);
93 msg.debug(fmt_stats, "Total",
94 all_ro_count, all_ro_bytes, all_ro_perc,
95 all_rw_count, all_rw_bytes, all_rw_perc,
96 all_count, all_bytes, all_perc);
97
98 msg.flush();
99
100 assert(all_ro_bytes == ro_all && all_rw_bytes == rw_all,
101 "everything should have been counted (used/counted: ro %d/%d, rw %d/%d",
102 ro_all, all_ro_bytes, rw_all, all_rw_bytes);
103
104 #undef fmt_stats
105
106 msg.info("Class CP entries = %6d, archived = %6d (%5.1f%%), reverted = %6d",
107 _num_klass_cp_entries, _num_klass_cp_entries_archived,
108 percent_of(_num_klass_cp_entries_archived, _num_klass_cp_entries),
109 _num_klass_cp_entries_reverted);
110 msg.info("Field CP entries = %6d, archived = %6d (%5.1f%%), reverted = %6d",
111 _num_field_cp_entries, _num_field_cp_entries_archived,
112 percent_of(_num_field_cp_entries_archived, _num_field_cp_entries),
113 _num_field_cp_entries_reverted);
114 msg.info("Method CP entries = %6d, archived = %6d (%5.1f%%), reverted = %6d",
115 _num_method_cp_entries, _num_method_cp_entries_archived,
116 percent_of(_num_method_cp_entries_archived, _num_method_cp_entries),
117 _num_method_cp_entries_reverted);
118 msg.info("Indy CP entries = %6d, archived = %6d (%5.1f%%), reverted = %6d",
119 _num_indy_cp_entries, _num_indy_cp_entries_archived,
120 percent_of(_num_indy_cp_entries_archived, _num_indy_cp_entries),
121 _num_indy_cp_entries_reverted);
122 msg.info("Platform loader initiated classes = %6d", AOTClassLinker::num_platform_initiated_classes());
123 msg.info("App loader initiated classes = %6d", AOTClassLinker::num_app_initiated_classes());
124 msg.info("Dynamic proxy classes = %6d%s", _num_dynamic_proxy_classes,
125 CDSConfig::is_dumping_full_module_graph() ? "" : " (not archiving FMG)");
126 msg.info("MethodCounters = %6d (%8d bytes)", _counts[RW][MethodCountersType],
127 _bytes [RW][MethodCountersType]);
128 msg.info("KlassTrainingData = %6d (%8d bytes)", _counts[RW][KlassTrainingDataType],
129 _bytes [RW][KlassTrainingDataType]);
130 msg.info("MethodTrainingData = %6d (%8d bytes)", _counts[RW][MethodTrainingDataType],
131 _bytes [RW][MethodTrainingDataType]);
132 }
133
134 #ifdef ASSERT
135 void DumpAllocStats::verify(int expected_byte_size, bool read_only) const {
136 int bytes = 0;
137 const int what = (int)(read_only ? RO : RW);
138 for (int type = 0; type < int(_number_of_types); type ++) {
139 bytes += _bytes[what][type];
140 }
141 assert(bytes == expected_byte_size, "counter mismatch (%s: %d vs %d)",
142 (read_only ? "RO" : "RW"), bytes, expected_byte_size);
143 }
144 #endif // ASSERT