coleenp@4037: /* katleman@4376: * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. coleenp@4037: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. coleenp@4037: * coleenp@4037: * This code is free software; you can redistribute it and/or modify it coleenp@4037: * under the terms of the GNU General Public License version 2 only, as coleenp@4037: * published by the Free Software Foundation. coleenp@4037: * coleenp@4037: * This code is distributed in the hope that it will be useful, but WITHOUT coleenp@4037: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or coleenp@4037: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License coleenp@4037: * version 2 for more details (a copy is included in the LICENSE file that coleenp@4037: * accompanied this code). coleenp@4037: * coleenp@4037: * You should have received a copy of the GNU General Public License version coleenp@4037: * 2 along with this work; if not, write to the Free Software Foundation, coleenp@4037: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. coleenp@4037: * coleenp@4037: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA coleenp@4037: * or visit www.oracle.com if you need additional information or have any coleenp@4037: * questions. coleenp@4037: * coleenp@4037: */ coleenp@4037: coleenp@4037: #include "precompiled.hpp" coleenp@4037: #include "memory/metaspaceCounters.hpp" coleenp@4037: #include "memory/resourceArea.hpp" ehelin@4680: #include "utilities/exceptions.hpp" coleenp@4037: coleenp@4037: MetaspaceCounters* MetaspaceCounters::_metaspace_counters = NULL; coleenp@4037: jmasa@5015: size_t MetaspaceCounters::calc_total_capacity() { jmasa@5015: // The total capacity is the sum of jmasa@5015: // 1) capacity of Metachunks in use by all Metaspaces jmasa@5015: // 2) unused space at the end of each Metachunk jmasa@5015: // 3) space in the freelist jmasa@5015: size_t total_capacity = MetaspaceAux::allocated_capacity_bytes() jmasa@5015: + MetaspaceAux::free_bytes() + MetaspaceAux::free_chunks_total_in_bytes(); jmasa@5015: return total_capacity; jmasa@5015: } jmasa@5015: ehelin@4680: MetaspaceCounters::MetaspaceCounters() : ehelin@4680: _capacity(NULL), ehelin@4680: _used(NULL), ehelin@4680: _max_capacity(NULL) { coleenp@4037: if (UsePerfData) { coleenp@4037: size_t min_capacity = MetaspaceAux::min_chunk_size(); coleenp@4037: size_t max_capacity = MetaspaceAux::reserved_in_bytes(); jmasa@5015: size_t curr_capacity = calc_total_capacity(); jmasa@5015: size_t used = MetaspaceAux::allocated_used_bytes(); coleenp@4037: coleenp@4037: initialize(min_capacity, max_capacity, curr_capacity, used); coleenp@4037: } coleenp@4037: } coleenp@4037: ehelin@4680: static PerfVariable* create_ms_variable(const char *ns, ehelin@4680: const char *name, ehelin@4680: size_t value, ehelin@4680: TRAPS) { ehelin@4680: const char *path = PerfDataManager::counter_name(ns, name); ehelin@4680: PerfVariable *result = ehelin@4680: PerfDataManager::create_variable(SUN_GC, path, PerfData::U_Bytes, value, ehelin@4680: CHECK_NULL); ehelin@4680: return result; ehelin@4680: } ehelin@4680: ehelin@4680: static void create_ms_constant(const char *ns, ehelin@4680: const char *name, ehelin@4680: size_t value, ehelin@4680: TRAPS) { ehelin@4680: const char *path = PerfDataManager::counter_name(ns, name); ehelin@4680: PerfDataManager::create_constant(SUN_GC, path, PerfData::U_Bytes, value, CHECK); ehelin@4680: } ehelin@4680: coleenp@4037: void MetaspaceCounters::initialize(size_t min_capacity, coleenp@4037: size_t max_capacity, coleenp@4037: size_t curr_capacity, coleenp@4037: size_t used) { coleenp@4037: coleenp@4037: if (UsePerfData) { coleenp@4037: EXCEPTION_MARK; coleenp@4037: ResourceMark rm; coleenp@4037: ehelin@4680: const char *ms = "metaspace"; coleenp@4037: ehelin@4680: create_ms_constant(ms, "minCapacity", min_capacity, CHECK); ehelin@4680: _max_capacity = create_ms_variable(ms, "maxCapacity", max_capacity, CHECK); ehelin@4680: _capacity = create_ms_variable(ms, "capacity", curr_capacity, CHECK); ehelin@4680: _used = create_ms_variable(ms, "used", used, CHECK); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: void MetaspaceCounters::update_capacity() { coleenp@4037: assert(UsePerfData, "Should not be called unless being used"); jmasa@5015: size_t total_capacity = calc_total_capacity(); jmasa@5015: _capacity->set_value(total_capacity); coleenp@4037: } coleenp@4037: coleenp@4037: void MetaspaceCounters::update_used() { coleenp@4037: assert(UsePerfData, "Should not be called unless being used"); jmasa@5015: size_t used_in_bytes = MetaspaceAux::allocated_used_bytes(); coleenp@4037: _used->set_value(used_in_bytes); coleenp@4037: } coleenp@4037: coleenp@4037: void MetaspaceCounters::update_max_capacity() { coleenp@4037: assert(UsePerfData, "Should not be called unless being used"); ehelin@4680: assert(_max_capacity != NULL, "Should be initialized"); coleenp@4037: size_t reserved_in_bytes = MetaspaceAux::reserved_in_bytes(); coleenp@4037: _max_capacity->set_value(reserved_in_bytes); coleenp@4037: } coleenp@4037: coleenp@4037: void MetaspaceCounters::update_all() { coleenp@4037: if (UsePerfData) { coleenp@4037: update_used(); coleenp@4037: update_capacity(); coleenp@4037: update_max_capacity(); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: void MetaspaceCounters::initialize_performance_counters() { coleenp@4037: if (UsePerfData) { ehelin@4680: assert(_metaspace_counters == NULL, "Should only be initialized once"); coleenp@4037: _metaspace_counters = new MetaspaceCounters(); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: void MetaspaceCounters::update_performance_counters() { coleenp@4037: if (UsePerfData) { ehelin@4680: assert(_metaspace_counters != NULL, "Should be initialized"); coleenp@4037: _metaspace_counters->update_all(); coleenp@4037: } coleenp@4037: } coleenp@4037: