Path: blob/master/src/hotspot/share/cds/dumpAllocStats.hpp
41144 views
/*1* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_CDS_DUMPALLOCSTATS_HPP25#define SHARE_CDS_DUMPALLOCSTATS_HPP2627#include "classfile/compactHashtable.hpp"28#include "memory/allocation.hpp"2930// This is for dumping detailed statistics for the allocations31// in the shared spaces.32class DumpAllocStats : public ResourceObj {33public:3435// Here's poor man's enum inheritance36#define SHAREDSPACE_OBJ_TYPES_DO(f) \37METASPACE_OBJ_TYPES_DO(f) \38f(SymbolHashentry) \39f(SymbolBucket) \40f(StringHashentry) \41f(StringBucket) \42f(ModulesNatives) \43f(CppVTables) \44f(Other)4546enum Type {47// Types are MetaspaceObj::ClassType, MetaspaceObj::SymbolType, etc48SHAREDSPACE_OBJ_TYPES_DO(METASPACE_OBJ_TYPE_DECLARE)49_number_of_types50};5152static const char* type_name(Type type) {53switch(type) {54SHAREDSPACE_OBJ_TYPES_DO(METASPACE_OBJ_TYPE_NAME_CASE)55default:56ShouldNotReachHere();57return NULL;58}59}6061CompactHashtableStats _symbol_stats;62CompactHashtableStats _string_stats;6364int _counts[2][_number_of_types];65int _bytes [2][_number_of_types];6667public:68enum { RO = 0, RW = 1 };6970DumpAllocStats() {71memset(_counts, 0, sizeof(_counts));72memset(_bytes, 0, sizeof(_bytes));73};7475CompactHashtableStats* symbol_stats() { return &_symbol_stats; }76CompactHashtableStats* string_stats() { return &_string_stats; }7778void record(MetaspaceObj::Type type, int byte_size, bool read_only) {79assert(int(type) >= 0 && type < MetaspaceObj::_number_of_types, "sanity");80int which = (read_only) ? RO : RW;81_counts[which][type] ++;82_bytes [which][type] += byte_size;83}8485void record_modules(int byte_size, bool read_only) {86int which = (read_only) ? RO : RW;87_bytes [which][ModulesNativesType] += byte_size;88}8990void record_other_type(int byte_size, bool read_only) {91int which = (read_only) ? RO : RW;92_bytes [which][OtherType] += byte_size;93}9495void record_cpp_vtables(int byte_size) {96_bytes[RW][CppVTablesType] += byte_size;97}9899void print_stats(int ro_all, int rw_all);100};101102#endif // SHARE_CDS_DUMPALLOCSTATS_HPP103104105