1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/memory/metaspaceCounters.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,133 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "memory/metaspaceCounters.hpp" 1.30 +#include "memory/resourceArea.hpp" 1.31 +#include "runtime/globals.hpp" 1.32 +#include "runtime/perfData.hpp" 1.33 +#include "utilities/exceptions.hpp" 1.34 + 1.35 +class MetaspacePerfCounters: public CHeapObj<mtInternal> { 1.36 + friend class VMStructs; 1.37 + PerfVariable* _capacity; 1.38 + PerfVariable* _used; 1.39 + PerfVariable* _max_capacity; 1.40 + 1.41 + PerfVariable* create_variable(const char *ns, const char *name, size_t value, TRAPS) { 1.42 + const char *path = PerfDataManager::counter_name(ns, name); 1.43 + return PerfDataManager::create_variable(SUN_GC, path, PerfData::U_Bytes, value, THREAD); 1.44 + } 1.45 + 1.46 + void create_constant(const char *ns, const char *name, size_t value, TRAPS) { 1.47 + const char *path = PerfDataManager::counter_name(ns, name); 1.48 + PerfDataManager::create_constant(SUN_GC, path, PerfData::U_Bytes, value, THREAD); 1.49 + } 1.50 + 1.51 + public: 1.52 + MetaspacePerfCounters(const char* ns, size_t min_capacity, size_t curr_capacity, size_t max_capacity, size_t used) { 1.53 + EXCEPTION_MARK; 1.54 + ResourceMark rm; 1.55 + 1.56 + create_constant(ns, "minCapacity", min_capacity, THREAD); 1.57 + _capacity = create_variable(ns, "capacity", curr_capacity, THREAD); 1.58 + _max_capacity = create_variable(ns, "maxCapacity", max_capacity, THREAD); 1.59 + _used = create_variable(ns, "used", used, THREAD); 1.60 + } 1.61 + 1.62 + void update(size_t capacity, size_t max_capacity, size_t used) { 1.63 + _capacity->set_value(capacity); 1.64 + _max_capacity->set_value(max_capacity); 1.65 + _used->set_value(used); 1.66 + } 1.67 +}; 1.68 + 1.69 +MetaspacePerfCounters* MetaspaceCounters::_perf_counters = NULL; 1.70 + 1.71 +size_t MetaspaceCounters::used() { 1.72 + return MetaspaceAux::used_bytes(); 1.73 +} 1.74 + 1.75 +size_t MetaspaceCounters::capacity() { 1.76 + return MetaspaceAux::committed_bytes(); 1.77 +} 1.78 + 1.79 +size_t MetaspaceCounters::max_capacity() { 1.80 + return MetaspaceAux::reserved_bytes(); 1.81 +} 1.82 + 1.83 +void MetaspaceCounters::initialize_performance_counters() { 1.84 + if (UsePerfData) { 1.85 + assert(_perf_counters == NULL, "Should only be initialized once"); 1.86 + 1.87 + size_t min_capacity = 0; 1.88 + _perf_counters = new MetaspacePerfCounters("metaspace", min_capacity, 1.89 + capacity(), max_capacity(), used()); 1.90 + } 1.91 +} 1.92 + 1.93 +void MetaspaceCounters::update_performance_counters() { 1.94 + if (UsePerfData) { 1.95 + assert(_perf_counters != NULL, "Should be initialized"); 1.96 + 1.97 + _perf_counters->update(capacity(), max_capacity(), used()); 1.98 + } 1.99 +} 1.100 + 1.101 +MetaspacePerfCounters* CompressedClassSpaceCounters::_perf_counters = NULL; 1.102 + 1.103 +size_t CompressedClassSpaceCounters::used() { 1.104 + return MetaspaceAux::used_bytes(Metaspace::ClassType); 1.105 +} 1.106 + 1.107 +size_t CompressedClassSpaceCounters::capacity() { 1.108 + return MetaspaceAux::committed_bytes(Metaspace::ClassType); 1.109 +} 1.110 + 1.111 +size_t CompressedClassSpaceCounters::max_capacity() { 1.112 + return MetaspaceAux::reserved_bytes(Metaspace::ClassType); 1.113 +} 1.114 + 1.115 +void CompressedClassSpaceCounters::update_performance_counters() { 1.116 + if (UsePerfData && UseCompressedClassPointers) { 1.117 + assert(_perf_counters != NULL, "Should be initialized"); 1.118 + 1.119 + _perf_counters->update(capacity(), max_capacity(), used()); 1.120 + } 1.121 +} 1.122 + 1.123 +void CompressedClassSpaceCounters::initialize_performance_counters() { 1.124 + if (UsePerfData) { 1.125 + assert(_perf_counters == NULL, "Should only be initialized once"); 1.126 + const char* ns = "compressedclassspace"; 1.127 + 1.128 + if (UseCompressedClassPointers) { 1.129 + size_t min_capacity = 0; 1.130 + _perf_counters = new MetaspacePerfCounters(ns, min_capacity, capacity(), 1.131 + max_capacity(), used()); 1.132 + } else { 1.133 + _perf_counters = new MetaspacePerfCounters(ns, 0, 0, 0, 0); 1.134 + } 1.135 + } 1.136 +}