1 /* 2 * Copyright (c) 2020, 2024, 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 "precompiled.hpp" 26 #include "cds/dumpAllocStats.hpp" 27 #include "logging/log.hpp" 28 #include "logging/logMessage.hpp" 29 30 void DumpAllocStats::print_stats(int ro_all, int rw_all) { 31 // symbols 32 _counts[RO][SymbolHashentryType] = _symbol_stats.hashentry_count; 33 _bytes [RO][SymbolHashentryType] = _symbol_stats.hashentry_bytes; 34 35 _counts[RO][SymbolBucketType] = _symbol_stats.bucket_count; 36 _bytes [RO][SymbolBucketType] = _symbol_stats.bucket_bytes; 37 38 // strings 39 _counts[RO][StringHashentryType] = _string_stats.hashentry_count; 40 _bytes [RO][StringHashentryType] = _string_stats.hashentry_bytes; 41 42 _counts[RO][StringBucketType] = _string_stats.bucket_count; 43 _bytes [RO][StringBucketType] = _string_stats.bucket_bytes; 44 45 int all_ro_count = 0; 46 int all_ro_bytes = 0; 47 int all_rw_count = 0; 48 int all_rw_bytes = 0; 49 50 // To make fmt_stats be a syntactic constant (for format warnings), use #define. 51 #define fmt_stats "%-20s: %8d %10d %5.1f | %8d %10d %5.1f | %8d %10d %5.1f" 52 const char *sep = "--------------------+---------------------------+---------------------------+--------------------------"; 53 const char *hdr = " ro_cnt ro_bytes % | rw_cnt rw_bytes % | all_cnt all_bytes %"; 54 55 LogMessage(cds) msg; 56 57 msg.debug("Detailed metadata info (excluding heap region):"); 58 msg.debug("%s", hdr); 59 msg.debug("%s", sep); 60 for (int type = 0; type < int(_number_of_types); type ++) { 61 const char *name = type_name((Type)type); 62 int ro_count = _counts[RO][type]; 63 int ro_bytes = _bytes [RO][type]; 64 int rw_count = _counts[RW][type]; 65 int rw_bytes = _bytes [RW][type]; 66 int count = ro_count + rw_count; 67 int bytes = ro_bytes + rw_bytes; 68 69 double ro_perc = percent_of(ro_bytes, ro_all); 70 double rw_perc = percent_of(rw_bytes, rw_all); 71 double perc = percent_of(bytes, ro_all + rw_all); 72 73 msg.debug(fmt_stats, name, 74 ro_count, ro_bytes, ro_perc, 75 rw_count, rw_bytes, rw_perc, 76 count, bytes, perc); 77 78 all_ro_count += ro_count; 79 all_ro_bytes += ro_bytes; 80 all_rw_count += rw_count; 81 all_rw_bytes += rw_bytes; 82 } 83 84 int all_count = all_ro_count + all_rw_count; 85 int all_bytes = all_ro_bytes + all_rw_bytes; 86 87 double all_ro_perc = percent_of(all_ro_bytes, ro_all); 88 double all_rw_perc = percent_of(all_rw_bytes, rw_all); 89 double all_perc = percent_of(all_bytes, ro_all + rw_all); 90 91 msg.debug("%s", sep); 92 msg.debug(fmt_stats, "Total", 93 all_ro_count, all_ro_bytes, all_ro_perc, 94 all_rw_count, all_rw_bytes, all_rw_perc, 95 all_count, all_bytes, all_perc); 96 97 msg.flush(); 98 99 assert(all_ro_bytes == ro_all && all_rw_bytes == rw_all, 100 "everything should have been counted (used/counted: ro %d/%d, rw %d/%d", 101 ro_all, all_ro_bytes, rw_all, all_rw_bytes); 102 103 #undef fmt_stats 104 105 msg.info("Class CP entries = %6d, archived = %6d (%5.1f%%), reverted = %6d", 106 _num_klass_cp_entries, _num_klass_cp_entries_archived, 107 percent_of(_num_klass_cp_entries_archived, _num_klass_cp_entries), 108 _num_klass_cp_entries_reverted); 109 msg.info("Field CP entries = %6d, archived = %6d (%5.1f%%), reverted = %6d", 110 _num_field_cp_entries, _num_field_cp_entries_archived, 111 percent_of(_num_field_cp_entries_archived, _num_field_cp_entries), 112 _num_field_cp_entries_reverted); 113 }