1 /* 2 * Copyright (c) 2020, 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_MEMORY_DUMPALLOCSTATS_HPP 26 #define SHARE_MEMORY_DUMPALLOCSTATS_HPP 27 28 #include "memory/allocation.hpp" 29 30 // This is for dumping detailed statistics for the allocations 31 // in the shared spaces. 32 class DumpAllocStats : public ResourceObj { 33 public: 34 35 // Here's poor man's enum inheritance 36 #define SHAREDSPACE_OBJ_TYPES_DO(f) \ 37 METASPACE_OBJ_TYPES_DO(f) \ 38 f(SymbolHashentry) \ 39 f(SymbolBucket) \ 40 f(StringHashentry) \ 41 f(StringBucket) \ 42 f(ModulesNatives) \ 43 f(Other) 44 45 enum Type { 46 // Types are MetaspaceObj::ClassType, MetaspaceObj::SymbolType, etc 47 SHAREDSPACE_OBJ_TYPES_DO(METASPACE_OBJ_TYPE_DECLARE) 48 _number_of_types 49 }; 50 51 static const char* type_name(Type type) { 52 switch(type) { 53 SHAREDSPACE_OBJ_TYPES_DO(METASPACE_OBJ_TYPE_NAME_CASE) 54 default: 55 ShouldNotReachHere(); 56 return NULL; 57 } 58 } 59 60 public: 61 enum { RO = 0, RW = 1 }; 62 63 int _counts[2][_number_of_types]; 64 int _bytes [2][_number_of_types]; 65 66 DumpAllocStats() { 67 memset(_counts, 0, sizeof(_counts)); 68 memset(_bytes, 0, sizeof(_bytes)); 69 }; 70 71 void record(MetaspaceObj::Type type, int byte_size, bool read_only) { 72 assert(int(type) >= 0 && type < MetaspaceObj::_number_of_types, "sanity"); 73 int which = (read_only) ? RO : RW; 74 _counts[which][type] ++; 75 _bytes [which][type] += byte_size; 76 } 77 78 void record_modules(int byte_size, bool read_only) { 79 int which = (read_only) ? RO : RW; 80 _bytes [which][ModulesNativesType] += byte_size; 81 } 82 83 void record_other_type(int byte_size, bool read_only) { 84 int which = (read_only) ? RO : RW; 85 _bytes [which][OtherType] += byte_size; 86 } 87 void print_stats(int ro_all, int rw_all, int mc_all); 88 }; 89 90 #endif // SHARE_MEMORY_DUMPALLOCSTATS_HPP