1.1 --- a/src/share/vm/memory/metaspaceCounters.cpp Fri Aug 16 10:06:58 2013 -0700 1.2 +++ b/src/share/vm/memory/metaspaceCounters.cpp Wed Aug 07 16:47:32 2013 +0200 1.3 @@ -25,11 +25,47 @@ 1.4 #include "precompiled.hpp" 1.5 #include "memory/metaspaceCounters.hpp" 1.6 #include "memory/resourceArea.hpp" 1.7 +#include "runtime/globals.hpp" 1.8 +#include "runtime/perfData.hpp" 1.9 #include "utilities/exceptions.hpp" 1.10 1.11 -MetaspaceCounters* MetaspaceCounters::_metaspace_counters = NULL; 1.12 +class MetaspacePerfCounters: public CHeapObj<mtInternal> { 1.13 + friend class VMStructs; 1.14 + PerfVariable* _capacity; 1.15 + PerfVariable* _used; 1.16 + PerfVariable* _max_capacity; 1.17 1.18 -size_t MetaspaceCounters::calc_total_capacity() { 1.19 + PerfVariable* create_variable(const char *ns, const char *name, size_t value, TRAPS) { 1.20 + const char *path = PerfDataManager::counter_name(ns, name); 1.21 + return PerfDataManager::create_variable(SUN_GC, path, PerfData::U_Bytes, value, THREAD); 1.22 + } 1.23 + 1.24 + void create_constant(const char *ns, const char *name, size_t value, TRAPS) { 1.25 + const char *path = PerfDataManager::counter_name(ns, name); 1.26 + PerfDataManager::create_constant(SUN_GC, path, PerfData::U_Bytes, value, THREAD); 1.27 + } 1.28 + 1.29 + public: 1.30 + MetaspacePerfCounters(const char* ns, size_t min_capacity, size_t curr_capacity, size_t max_capacity, size_t used) { 1.31 + EXCEPTION_MARK; 1.32 + ResourceMark rm; 1.33 + 1.34 + create_constant(ns, "minCapacity", min_capacity, THREAD); 1.35 + _capacity = create_variable(ns, "capacity", curr_capacity, THREAD); 1.36 + _max_capacity = create_variable(ns, "maxCapacity", max_capacity, THREAD); 1.37 + _used = create_variable(ns, "used", used, THREAD); 1.38 + } 1.39 + 1.40 + void update(size_t capacity, size_t max_capacity, size_t used) { 1.41 + _capacity->set_value(capacity); 1.42 + _max_capacity->set_value(max_capacity); 1.43 + _used->set_value(used); 1.44 + } 1.45 +}; 1.46 + 1.47 +MetaspacePerfCounters* MetaspaceCounters::_perf_counters = NULL; 1.48 + 1.49 +size_t MetaspaceCounters::calculate_capacity() { 1.50 // The total capacity is the sum of 1.51 // 1) capacity of Metachunks in use by all Metaspaces 1.52 // 2) unused space at the end of each Metachunk 1.53 @@ -39,95 +75,65 @@ 1.54 return total_capacity; 1.55 } 1.56 1.57 -MetaspaceCounters::MetaspaceCounters() : 1.58 - _capacity(NULL), 1.59 - _used(NULL), 1.60 - _max_capacity(NULL) { 1.61 +void MetaspaceCounters::initialize_performance_counters() { 1.62 if (UsePerfData) { 1.63 + assert(_perf_counters == NULL, "Should only be initialized once"); 1.64 + 1.65 size_t min_capacity = MetaspaceAux::min_chunk_size(); 1.66 + size_t capacity = calculate_capacity(); 1.67 size_t max_capacity = MetaspaceAux::reserved_in_bytes(); 1.68 - size_t curr_capacity = calc_total_capacity(); 1.69 size_t used = MetaspaceAux::allocated_used_bytes(); 1.70 1.71 - initialize(min_capacity, max_capacity, curr_capacity, used); 1.72 - } 1.73 -} 1.74 - 1.75 -static PerfVariable* create_ms_variable(const char *ns, 1.76 - const char *name, 1.77 - size_t value, 1.78 - TRAPS) { 1.79 - const char *path = PerfDataManager::counter_name(ns, name); 1.80 - PerfVariable *result = 1.81 - PerfDataManager::create_variable(SUN_GC, path, PerfData::U_Bytes, value, 1.82 - CHECK_NULL); 1.83 - return result; 1.84 -} 1.85 - 1.86 -static void create_ms_constant(const char *ns, 1.87 - const char *name, 1.88 - size_t value, 1.89 - TRAPS) { 1.90 - const char *path = PerfDataManager::counter_name(ns, name); 1.91 - PerfDataManager::create_constant(SUN_GC, path, PerfData::U_Bytes, value, CHECK); 1.92 -} 1.93 - 1.94 -void MetaspaceCounters::initialize(size_t min_capacity, 1.95 - size_t max_capacity, 1.96 - size_t curr_capacity, 1.97 - size_t used) { 1.98 - 1.99 - if (UsePerfData) { 1.100 - EXCEPTION_MARK; 1.101 - ResourceMark rm; 1.102 - 1.103 - const char *ms = "metaspace"; 1.104 - 1.105 - create_ms_constant(ms, "minCapacity", min_capacity, CHECK); 1.106 - _max_capacity = create_ms_variable(ms, "maxCapacity", max_capacity, CHECK); 1.107 - _capacity = create_ms_variable(ms, "capacity", curr_capacity, CHECK); 1.108 - _used = create_ms_variable(ms, "used", used, CHECK); 1.109 - } 1.110 -} 1.111 - 1.112 -void MetaspaceCounters::update_capacity() { 1.113 - assert(UsePerfData, "Should not be called unless being used"); 1.114 - size_t total_capacity = calc_total_capacity(); 1.115 - _capacity->set_value(total_capacity); 1.116 -} 1.117 - 1.118 -void MetaspaceCounters::update_used() { 1.119 - assert(UsePerfData, "Should not be called unless being used"); 1.120 - size_t used_in_bytes = MetaspaceAux::allocated_used_bytes(); 1.121 - _used->set_value(used_in_bytes); 1.122 -} 1.123 - 1.124 -void MetaspaceCounters::update_max_capacity() { 1.125 - assert(UsePerfData, "Should not be called unless being used"); 1.126 - assert(_max_capacity != NULL, "Should be initialized"); 1.127 - size_t reserved_in_bytes = MetaspaceAux::reserved_in_bytes(); 1.128 - _max_capacity->set_value(reserved_in_bytes); 1.129 -} 1.130 - 1.131 -void MetaspaceCounters::update_all() { 1.132 - if (UsePerfData) { 1.133 - update_used(); 1.134 - update_capacity(); 1.135 - update_max_capacity(); 1.136 - } 1.137 -} 1.138 - 1.139 -void MetaspaceCounters::initialize_performance_counters() { 1.140 - if (UsePerfData) { 1.141 - assert(_metaspace_counters == NULL, "Should only be initialized once"); 1.142 - _metaspace_counters = new MetaspaceCounters(); 1.143 + _perf_counters = new MetaspacePerfCounters("metaspace", min_capacity, capacity, max_capacity, used); 1.144 } 1.145 } 1.146 1.147 void MetaspaceCounters::update_performance_counters() { 1.148 if (UsePerfData) { 1.149 - assert(_metaspace_counters != NULL, "Should be initialized"); 1.150 - _metaspace_counters->update_all(); 1.151 + assert(_perf_counters != NULL, "Should be initialized"); 1.152 + 1.153 + size_t capacity = calculate_capacity(); 1.154 + size_t max_capacity = MetaspaceAux::reserved_in_bytes(); 1.155 + size_t used = MetaspaceAux::allocated_used_bytes(); 1.156 + 1.157 + _perf_counters->update(capacity, max_capacity, used); 1.158 } 1.159 } 1.160 1.161 +MetaspacePerfCounters* CompressedClassSpaceCounters::_perf_counters = NULL; 1.162 + 1.163 +size_t CompressedClassSpaceCounters::calculate_capacity() { 1.164 + return MetaspaceAux::allocated_capacity_bytes(_class_type) + 1.165 + MetaspaceAux::free_bytes(_class_type) + 1.166 + MetaspaceAux::free_chunks_total_in_bytes(_class_type); 1.167 +} 1.168 + 1.169 +void CompressedClassSpaceCounters::update_performance_counters() { 1.170 + if (UsePerfData && UseCompressedKlassPointers) { 1.171 + assert(_perf_counters != NULL, "Should be initialized"); 1.172 + 1.173 + size_t capacity = calculate_capacity(); 1.174 + size_t max_capacity = MetaspaceAux::reserved_in_bytes(_class_type); 1.175 + size_t used = MetaspaceAux::allocated_used_bytes(_class_type); 1.176 + 1.177 + _perf_counters->update(capacity, max_capacity, used); 1.178 + } 1.179 +} 1.180 + 1.181 +void CompressedClassSpaceCounters::initialize_performance_counters() { 1.182 + if (UsePerfData) { 1.183 + assert(_perf_counters == NULL, "Should only be initialized once"); 1.184 + const char* ns = "compressedclassspace"; 1.185 + 1.186 + if (UseCompressedKlassPointers) { 1.187 + size_t min_capacity = MetaspaceAux::min_chunk_size(); 1.188 + size_t capacity = calculate_capacity(); 1.189 + size_t max_capacity = MetaspaceAux::reserved_in_bytes(_class_type); 1.190 + size_t used = MetaspaceAux::allocated_used_bytes(_class_type); 1.191 + 1.192 + _perf_counters = new MetaspacePerfCounters(ns, min_capacity, capacity, max_capacity, used); 1.193 + } else { 1.194 + _perf_counters = new MetaspacePerfCounters(ns, 0, 0, 0, 0); 1.195 + } 1.196 + } 1.197 +}