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 #ifndef SHARE_CDS_DUMPALLOCSTATS_HPP 26 #define SHARE_CDS_DUMPALLOCSTATS_HPP 27 28 #include "classfile/compactHashtable.hpp" 29 #include "memory/allocation.hpp" 30 31 // This is for dumping detailed statistics for the allocations 32 // in the shared spaces. 33 class DumpAllocStats : public StackObj { 34 public: 35 36 // Here's poor man's enum inheritance 37 #define SHAREDSPACE_OBJ_TYPES_DO(f) \ 38 METASPACE_OBJ_TYPES_DO(f) \ 39 f(SymbolHashentry) \ 40 f(SymbolBucket) \ 41 f(StringHashentry) \ 42 f(StringBucket) \ 43 f(ModulesNatives) \ 44 f(CppVTables) \ 45 f(Other) 46 47 enum Type { 48 // Types are MetaspaceObj::ClassType, MetaspaceObj::SymbolType, etc 49 SHAREDSPACE_OBJ_TYPES_DO(METASPACE_OBJ_TYPE_DECLARE) 50 _number_of_types 51 }; 52 53 static const char* type_name(Type type) { 54 switch(type) { 55 SHAREDSPACE_OBJ_TYPES_DO(METASPACE_OBJ_TYPE_NAME_CASE) 56 default: 57 ShouldNotReachHere(); 58 return nullptr; 59 } 60 } 61 62 CompactHashtableStats _symbol_stats; 63 CompactHashtableStats _string_stats; 64 65 int _counts[2][_number_of_types]; 66 int _bytes [2][_number_of_types]; 67 68 int _num_field_cp_entries; 69 int _num_field_cp_entries_archived; 70 int _num_field_cp_entries_reverted; 71 int _num_klass_cp_entries; 72 int _num_klass_cp_entries_archived; 73 int _num_klass_cp_entries_reverted; 74 75 public: 76 enum { RO = 0, RW = 1 }; 77 78 DumpAllocStats() { 79 memset(_counts, 0, sizeof(_counts)); 80 memset(_bytes, 0, sizeof(_bytes)); 81 _num_field_cp_entries = 0; 82 _num_field_cp_entries_archived = 0; 83 _num_field_cp_entries_reverted = 0; 84 _num_klass_cp_entries = 0; 85 _num_klass_cp_entries_archived = 0; 86 _num_klass_cp_entries_reverted = 0; 87 }; 88 89 CompactHashtableStats* symbol_stats() { return &_symbol_stats; } 90 CompactHashtableStats* string_stats() { return &_string_stats; } 91 92 void record(MetaspaceObj::Type type, int byte_size, bool read_only) { 93 assert(int(type) >= 0 && type < MetaspaceObj::_number_of_types, "sanity"); 94 int which = (read_only) ? RO : RW; 95 _counts[which][type] ++; 96 _bytes [which][type] += byte_size; 97 } 98 99 void record_modules(int byte_size, bool read_only) { 100 int which = (read_only) ? RO : RW; 101 _bytes [which][ModulesNativesType] += byte_size; 102 } 103 104 void record_other_type(int byte_size, bool read_only) { 105 int which = (read_only) ? RO : RW; 106 _bytes [which][OtherType] += byte_size; 107 } 108 109 void record_cpp_vtables(int byte_size) { 110 _bytes[RW][CppVTablesType] += byte_size; 111 } 112 113 void record_field_cp_entry(bool archived, bool reverted) { 114 _num_field_cp_entries ++; 115 _num_field_cp_entries_archived += archived ? 1 : 0; 116 _num_field_cp_entries_reverted += reverted ? 1 : 0; 117 } 118 119 void record_klass_cp_entry(bool archived, bool reverted) { 120 _num_klass_cp_entries ++; 121 _num_klass_cp_entries_archived += archived ? 1 : 0; 122 _num_klass_cp_entries_reverted += reverted ? 1 : 0; 123 } 124 125 void print_stats(int ro_all, int rw_all); 126 }; 127 128 #endif // SHARE_CDS_DUMPALLOCSTATS_HPP