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 31 HSpaceCounters::HSpaceCounters(const char* name_space, 32 const char* name, 33 int ordinal, 34 size_t max_size, 35 size_t initial_capacity) { 36 37 if (UsePerfData) { 38 EXCEPTION_MARK; 39 ResourceMark rm; 40 41 const char* cns = 42 PerfDataManager::name_space(name_space, "space", ordinal); 43 44 _name_space = NEW_C_HEAP_ARRAY(char, strlen(cns)+1, mtGC); 45 strcpy(_name_space, cns); 46 47 const char* cname = PerfDataManager::counter_name(_name_space, "name"); 48 PerfDataManager::create_string_constant(SUN_GC, cname, name, CHECK); 49 50 cname = PerfDataManager::counter_name(_name_space, "maxCapacity"); 51 PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes, 52 (jlong)max_size, CHECK); 53 54 cname = PerfDataManager::counter_name(_name_space, "capacity"); 55 _capacity = PerfDataManager::create_variable(SUN_GC, cname, 56 PerfData::U_Bytes, 57 initial_capacity, CHECK); 58 59 cname = PerfDataManager::counter_name(_name_space, "used"); 60 _used = PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes, 61 (jlong) 0, CHECK); 62 63 cname = PerfDataManager::counter_name(_name_space, "initCapacity"); 64 PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes, 65 initial_capacity, CHECK); 66 } 67 } 68 69 HSpaceCounters::~HSpaceCounters() { 70 FREE_C_HEAP_ARRAY(char, _name_space); 71 } 72 73 void HSpaceCounters::update_capacity(size_t v) { 74 _capacity->set_value(v); 75 } 76 77 void HSpaceCounters::update_used(size_t v) { 78 _used->set_value(v); 79 } 80 81 void HSpaceCounters::update_all(size_t capacity, size_t used) { 82 update_capacity(capacity); 83 update_used(used); 84 } 85 86 debug_only( 87 // for security reasons, we do not allow arbitrary reads from 88 // the counters as they may live in shared memory. 89 jlong HSpaceCounters::used() { 90 return _used->get_value(); 91 } 92 jlong HSpaceCounters::capacity() { 93 return _used->get_value(); 94 } 95 )