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@5531: #include "runtime/globals.hpp" ehelin@5531: #include "runtime/perfData.hpp" ehelin@4680: #include "utilities/exceptions.hpp" coleenp@4037: ehelin@5531: class MetaspacePerfCounters: public CHeapObj { ehelin@5531: friend class VMStructs; ehelin@5531: PerfVariable* _capacity; ehelin@5531: PerfVariable* _used; ehelin@5531: PerfVariable* _max_capacity; coleenp@4037: ehelin@5531: PerfVariable* create_variable(const char *ns, const char *name, size_t value, TRAPS) { ehelin@5531: const char *path = PerfDataManager::counter_name(ns, name); ehelin@5531: return PerfDataManager::create_variable(SUN_GC, path, PerfData::U_Bytes, value, THREAD); ehelin@5531: } ehelin@5531: ehelin@5531: void create_constant(const char *ns, const char *name, size_t value, TRAPS) { ehelin@5531: const char *path = PerfDataManager::counter_name(ns, name); ehelin@5531: PerfDataManager::create_constant(SUN_GC, path, PerfData::U_Bytes, value, THREAD); ehelin@5531: } ehelin@5531: ehelin@5531: public: ehelin@5531: MetaspacePerfCounters(const char* ns, size_t min_capacity, size_t curr_capacity, size_t max_capacity, size_t used) { ehelin@5531: EXCEPTION_MARK; ehelin@5531: ResourceMark rm; ehelin@5531: ehelin@5531: create_constant(ns, "minCapacity", min_capacity, THREAD); ehelin@5531: _capacity = create_variable(ns, "capacity", curr_capacity, THREAD); ehelin@5531: _max_capacity = create_variable(ns, "maxCapacity", max_capacity, THREAD); ehelin@5531: _used = create_variable(ns, "used", used, THREAD); ehelin@5531: } ehelin@5531: ehelin@5531: void update(size_t capacity, size_t max_capacity, size_t used) { ehelin@5531: _capacity->set_value(capacity); ehelin@5531: _max_capacity->set_value(max_capacity); ehelin@5531: _used->set_value(used); ehelin@5531: } ehelin@5531: }; ehelin@5531: ehelin@5531: MetaspacePerfCounters* MetaspaceCounters::_perf_counters = NULL; ehelin@5531: ehelin@5531: size_t MetaspaceCounters::calculate_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@5531: void MetaspaceCounters::initialize_performance_counters() { coleenp@4037: if (UsePerfData) { ehelin@5531: assert(_perf_counters == NULL, "Should only be initialized once"); ehelin@5531: coleenp@4037: size_t min_capacity = MetaspaceAux::min_chunk_size(); ehelin@5531: size_t capacity = calculate_capacity(); coleenp@4037: size_t max_capacity = MetaspaceAux::reserved_in_bytes(); jmasa@5015: size_t used = MetaspaceAux::allocated_used_bytes(); coleenp@4037: ehelin@5531: _perf_counters = new MetaspacePerfCounters("metaspace", min_capacity, capacity, max_capacity, used); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: void MetaspaceCounters::update_performance_counters() { coleenp@4037: if (UsePerfData) { ehelin@5531: assert(_perf_counters != NULL, "Should be initialized"); ehelin@5531: ehelin@5531: size_t capacity = calculate_capacity(); ehelin@5531: size_t max_capacity = MetaspaceAux::reserved_in_bytes(); ehelin@5531: size_t used = MetaspaceAux::allocated_used_bytes(); ehelin@5531: ehelin@5531: _perf_counters->update(capacity, max_capacity, used); coleenp@4037: } coleenp@4037: } coleenp@4037: ehelin@5531: MetaspacePerfCounters* CompressedClassSpaceCounters::_perf_counters = NULL; ehelin@5531: ehelin@5531: size_t CompressedClassSpaceCounters::calculate_capacity() { ehelin@5531: return MetaspaceAux::allocated_capacity_bytes(_class_type) + ehelin@5531: MetaspaceAux::free_bytes(_class_type) + ehelin@5531: MetaspaceAux::free_chunks_total_in_bytes(_class_type); ehelin@5531: } ehelin@5531: ehelin@5531: void CompressedClassSpaceCounters::update_performance_counters() { ehelin@5694: if (UsePerfData && UseCompressedClassPointers) { ehelin@5531: assert(_perf_counters != NULL, "Should be initialized"); ehelin@5531: ehelin@5531: size_t capacity = calculate_capacity(); ehelin@5531: size_t max_capacity = MetaspaceAux::reserved_in_bytes(_class_type); ehelin@5531: size_t used = MetaspaceAux::allocated_used_bytes(_class_type); ehelin@5531: ehelin@5531: _perf_counters->update(capacity, max_capacity, used); ehelin@5531: } ehelin@5531: } ehelin@5531: ehelin@5531: void CompressedClassSpaceCounters::initialize_performance_counters() { ehelin@5531: if (UsePerfData) { ehelin@5531: assert(_perf_counters == NULL, "Should only be initialized once"); ehelin@5531: const char* ns = "compressedclassspace"; ehelin@5531: ehelin@5694: if (UseCompressedClassPointers) { ehelin@5531: size_t min_capacity = MetaspaceAux::min_chunk_size(); ehelin@5531: size_t capacity = calculate_capacity(); ehelin@5531: size_t max_capacity = MetaspaceAux::reserved_in_bytes(_class_type); ehelin@5531: size_t used = MetaspaceAux::allocated_used_bytes(_class_type); ehelin@5531: ehelin@5531: _perf_counters = new MetaspacePerfCounters(ns, min_capacity, capacity, max_capacity, used); ehelin@5531: } else { ehelin@5531: _perf_counters = new MetaspacePerfCounters(ns, 0, 0, 0, 0); ehelin@5531: } ehelin@5531: } ehelin@5531: }