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" coleenp@4037: coleenp@4037: #define METASPACE_NAME "perm" coleenp@4037: coleenp@4037: MetaspaceCounters* MetaspaceCounters::_metaspace_counters = NULL; coleenp@4037: coleenp@4037: MetaspaceCounters::MetaspaceCounters() { coleenp@4037: if (UsePerfData) { coleenp@4037: size_t min_capacity = MetaspaceAux::min_chunk_size(); coleenp@4037: size_t max_capacity = MetaspaceAux::reserved_in_bytes(); coleenp@4037: size_t curr_capacity = MetaspaceAux::capacity_in_bytes(); jmasa@4046: size_t used = MetaspaceAux::used_in_bytes(); coleenp@4037: coleenp@4037: initialize(min_capacity, max_capacity, curr_capacity, used); coleenp@4037: } coleenp@4037: } coleenp@4037: 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: coleenp@4037: // Create a name that will be recognized by jstat tools as coleenp@4037: // the perm gen. Change this to a Metaspace name when the coleenp@4037: // tools are fixed. coleenp@4037: // name to recognize "sun.gc.generation.2.*" coleenp@4037: coleenp@4037: const char* name = METASPACE_NAME; coleenp@4037: const int ordinal = 2; coleenp@4037: const int spaces = 1; coleenp@4037: coleenp@4037: const char* cns = PerfDataManager::name_space("generation", ordinal); coleenp@4037: coleenp@4037: _name_space = NEW_C_HEAP_ARRAY(char, strlen(cns)+1, mtClass); coleenp@4037: strcpy(_name_space, cns); coleenp@4037: coleenp@4037: const char* cname = PerfDataManager::counter_name(_name_space, "name"); coleenp@4037: PerfDataManager::create_string_constant(SUN_GC, cname, name, CHECK); coleenp@4037: coleenp@4037: // End of perm gen like name creation coleenp@4037: coleenp@4037: cname = PerfDataManager::counter_name(_name_space, "spaces"); coleenp@4037: PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None, coleenp@4037: spaces, CHECK); coleenp@4037: coleenp@4037: cname = PerfDataManager::counter_name(_name_space, "minCapacity"); coleenp@4037: PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes, coleenp@4037: min_capacity, CHECK); coleenp@4037: coleenp@4037: cname = PerfDataManager::counter_name(_name_space, "maxCapacity"); coleenp@4037: PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes, coleenp@4037: max_capacity, CHECK); coleenp@4037: coleenp@4037: cname = PerfDataManager::counter_name(_name_space, "capacity"); coleenp@4037: _current_size = coleenp@4037: PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes, coleenp@4037: curr_capacity, CHECK); coleenp@4037: coleenp@4037: // SpaceCounter like counters coleenp@4037: // name to recognize "sun.gc.generation.2.space.0.*" coleenp@4037: { coleenp@4037: const int space_ordinal = 0; coleenp@4037: const char* cns = PerfDataManager::name_space(_name_space, "space", coleenp@4037: space_ordinal); coleenp@4037: coleenp@4037: char* space_name_space = NEW_C_HEAP_ARRAY(char, strlen(cns)+1, mtClass); coleenp@4037: strcpy(space_name_space, cns); coleenp@4037: coleenp@4037: const char* cname = PerfDataManager::counter_name(space_name_space, "name"); coleenp@4037: PerfDataManager::create_string_constant(SUN_GC, cname, name, CHECK); coleenp@4037: coleenp@4037: cname = PerfDataManager::counter_name(space_name_space, "maxCapacity"); coleenp@4037: _max_capacity = PerfDataManager::create_variable(SUN_GC, cname, coleenp@4037: PerfData::U_Bytes, coleenp@4037: (jlong)max_capacity, CHECK); coleenp@4037: coleenp@4037: cname = PerfDataManager::counter_name(space_name_space, "capacity"); coleenp@4037: _capacity = PerfDataManager::create_variable(SUN_GC, cname, coleenp@4037: PerfData::U_Bytes, coleenp@4037: curr_capacity, CHECK); coleenp@4037: coleenp@4037: cname = PerfDataManager::counter_name(space_name_space, "used"); coleenp@4037: _used = PerfDataManager::create_variable(SUN_GC, coleenp@4037: cname, coleenp@4037: PerfData::U_Bytes, coleenp@4037: used, coleenp@4037: CHECK); coleenp@4037: coleenp@4037: cname = PerfDataManager::counter_name(space_name_space, "initCapacity"); coleenp@4037: PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes, coleenp@4037: min_capacity, CHECK); coleenp@4037: } coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: void MetaspaceCounters::update_capacity() { coleenp@4037: assert(UsePerfData, "Should not be called unless being used"); coleenp@4037: size_t capacity_in_bytes = MetaspaceAux::capacity_in_bytes(); coleenp@4037: _capacity->set_value(capacity_in_bytes); coleenp@4037: } coleenp@4037: coleenp@4037: void MetaspaceCounters::update_used() { coleenp@4037: assert(UsePerfData, "Should not be called unless being used"); jmasa@4046: size_t used_in_bytes = MetaspaceAux::used_in_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"); 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: _current_size->set_value(MetaspaceAux::reserved_in_bytes()); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: void MetaspaceCounters::initialize_performance_counters() { coleenp@4037: if (UsePerfData) { coleenp@4037: _metaspace_counters = new MetaspaceCounters(); coleenp@4037: } coleenp@4037: } coleenp@4037: coleenp@4037: void MetaspaceCounters::update_performance_counters() { coleenp@4037: if (UsePerfData) { coleenp@4037: _metaspace_counters->update_all(); coleenp@4037: } coleenp@4037: } coleenp@4037: