jdk
1/*
2* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*
5* This code is free software; you can redistribute it and/or modify it
6* under the terms of the GNU General Public License version 2 only, as
7* published by the Free Software Foundation.
8*
9* This code is distributed in the hope that it will be useful, but WITHOUT
10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12* version 2 for more details (a copy is included in the LICENSE file that
13* accompanied this code).
14*
15* You should have received a copy of the GNU General Public License version
16* 2 along with this work; if not, write to the Free Software Foundation,
17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18*
19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20* or visit www.oracle.com if you need additional information or have any
21* questions.
22*
23*/
24
25#include "precompiled.hpp"26#include "gc/shared/hSpaceCounters.hpp"27#include "memory/allocation.inline.hpp"28#include "memory/resourceArea.hpp"29#include "runtime/perfData.hpp"30
31HSpaceCounters::HSpaceCounters(const char* name_space,32const char* name,33int ordinal,34size_t max_size,35size_t initial_capacity) {36
37if (UsePerfData) {38EXCEPTION_MARK;39ResourceMark rm;40
41const char* cns =42PerfDataManager::name_space(name_space, "space", ordinal);43
44_name_space = NEW_C_HEAP_ARRAY(char, strlen(cns)+1, mtGC);45strcpy(_name_space, cns);46
47const char* cname = PerfDataManager::counter_name(_name_space, "name");48PerfDataManager::create_string_constant(SUN_GC, cname, name, CHECK);49
50cname = PerfDataManager::counter_name(_name_space, "maxCapacity");51PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes,52(jlong)max_size, CHECK);53
54cname = PerfDataManager::counter_name(_name_space, "capacity");55_capacity = PerfDataManager::create_variable(SUN_GC, cname,56PerfData::U_Bytes,57initial_capacity, CHECK);58
59cname = PerfDataManager::counter_name(_name_space, "used");60_used = PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes,61(jlong) 0, CHECK);62
63cname = PerfDataManager::counter_name(_name_space, "initCapacity");64PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes,65initial_capacity, CHECK);66}67}
68
69HSpaceCounters::~HSpaceCounters() {70FREE_C_HEAP_ARRAY(char, _name_space);71}
72
73void HSpaceCounters::update_capacity(size_t v) {74_capacity->set_value(v);75}
76
77void HSpaceCounters::update_used(size_t v) {78_used->set_value(v);79}
80
81void HSpaceCounters::update_all(size_t capacity, size_t used) {82update_capacity(capacity);83update_used(used);84}
85
86debug_only(87// for security reasons, we do not allow arbitrary reads from88// the counters as they may live in shared memory.89jlong HSpaceCounters::used() {90return _used->get_value();91}92jlong HSpaceCounters::capacity() {93return _used->get_value();94}95)
96