Path: blob/master/src/hotspot/share/memory/metaspaceCounters.cpp
40949 views
/*1* Copyright (c) 2012, 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#include "precompiled.hpp"25#include "memory/metaspace.hpp"26#include "memory/metaspaceCounters.hpp"27#include "memory/metaspaceStats.hpp"28#include "memory/metaspaceUtils.hpp"29#include "memory/resourceArea.hpp"30#include "runtime/globals.hpp"31#include "runtime/perfData.hpp"32#include "utilities/exceptions.hpp"3334class MetaspacePerfCounters {35friend class VMStructs;36PerfVariable* _capacity;37PerfVariable* _used;38PerfVariable* _max_capacity;3940PerfVariable* create_variable(const char *ns, const char *name, size_t value, TRAPS) {41const char *path = PerfDataManager::counter_name(ns, name);42return PerfDataManager::create_variable(SUN_GC, path, PerfData::U_Bytes, value, THREAD);43}4445void create_constant(const char *ns, const char *name, size_t value, TRAPS) {46const char *path = PerfDataManager::counter_name(ns, name);47PerfDataManager::create_constant(SUN_GC, path, PerfData::U_Bytes, value, THREAD);48}4950public:51MetaspacePerfCounters() : _capacity(NULL), _used(NULL), _max_capacity(NULL) {}5253void initialize(const char* ns) {54assert(_capacity == NULL, "Only initialize once");55EXCEPTION_MARK;56ResourceMark rm;5758create_constant(ns, "minCapacity", 0, THREAD); // min_capacity makes little sense in the context of metaspace59_capacity = create_variable(ns, "capacity", 0, THREAD);60_max_capacity = create_variable(ns, "maxCapacity", 0, THREAD);61_used = create_variable(ns, "used", 0, THREAD);62}6364void update(const MetaspaceStats& stats) {65_capacity->set_value(stats.committed());66_max_capacity->set_value(stats.reserved());67_used->set_value(stats.used());68}69};7071static MetaspacePerfCounters g_meta_space_perf_counters; // class + nonclass72static MetaspacePerfCounters g_class_space_perf_counters;7374void MetaspaceCounters::initialize_performance_counters() {75if (UsePerfData) {76g_meta_space_perf_counters.initialize("metaspace");77g_class_space_perf_counters.initialize("compressedclassspace");78update_performance_counters();79}80}8182void MetaspaceCounters::update_performance_counters() {83if (UsePerfData) {84g_meta_space_perf_counters.update(MetaspaceUtils::get_combined_statistics());85g_class_space_perf_counters.update(MetaspaceUtils::get_statistics(Metaspace::ClassType));86}87}888990