1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/g1/g1MonitoringSupport.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,274 @@ 1.4 +/* 1.5 + * Copyright (c) 2011, 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 "gc_implementation/g1/g1MonitoringSupport.hpp" 1.30 +#include "gc_implementation/g1/g1CollectedHeap.inline.hpp" 1.31 +#include "gc_implementation/g1/g1CollectorPolicy.hpp" 1.32 + 1.33 +G1GenerationCounters::G1GenerationCounters(G1MonitoringSupport* g1mm, 1.34 + const char* name, 1.35 + int ordinal, int spaces, 1.36 + size_t min_capacity, 1.37 + size_t max_capacity, 1.38 + size_t curr_capacity) 1.39 + : GenerationCounters(name, ordinal, spaces, min_capacity, 1.40 + max_capacity, curr_capacity), _g1mm(g1mm) { } 1.41 + 1.42 +// We pad the capacity three times given that the young generation 1.43 +// contains three spaces (eden and two survivors). 1.44 +G1YoungGenerationCounters::G1YoungGenerationCounters(G1MonitoringSupport* g1mm, 1.45 + const char* name) 1.46 + : G1GenerationCounters(g1mm, name, 0 /* ordinal */, 3 /* spaces */, 1.47 + G1MonitoringSupport::pad_capacity(0, 3) /* min_capacity */, 1.48 + G1MonitoringSupport::pad_capacity(g1mm->young_gen_max(), 3), 1.49 + G1MonitoringSupport::pad_capacity(0, 3) /* curr_capacity */) { 1.50 + if (UsePerfData) { 1.51 + update_all(); 1.52 + } 1.53 +} 1.54 + 1.55 +G1OldGenerationCounters::G1OldGenerationCounters(G1MonitoringSupport* g1mm, 1.56 + const char* name) 1.57 + : G1GenerationCounters(g1mm, name, 1 /* ordinal */, 1 /* spaces */, 1.58 + G1MonitoringSupport::pad_capacity(0) /* min_capacity */, 1.59 + G1MonitoringSupport::pad_capacity(g1mm->old_gen_max()), 1.60 + G1MonitoringSupport::pad_capacity(0) /* curr_capacity */) { 1.61 + if (UsePerfData) { 1.62 + update_all(); 1.63 + } 1.64 +} 1.65 + 1.66 +void G1YoungGenerationCounters::update_all() { 1.67 + size_t committed = 1.68 + G1MonitoringSupport::pad_capacity(_g1mm->young_gen_committed(), 3); 1.69 + _current_size->set_value(committed); 1.70 +} 1.71 + 1.72 +void G1OldGenerationCounters::update_all() { 1.73 + size_t committed = 1.74 + G1MonitoringSupport::pad_capacity(_g1mm->old_gen_committed()); 1.75 + _current_size->set_value(committed); 1.76 +} 1.77 + 1.78 +G1MonitoringSupport::G1MonitoringSupport(G1CollectedHeap* g1h) : 1.79 + _g1h(g1h), 1.80 + _incremental_collection_counters(NULL), 1.81 + _full_collection_counters(NULL), 1.82 + _old_collection_counters(NULL), 1.83 + _old_space_counters(NULL), 1.84 + _young_collection_counters(NULL), 1.85 + _eden_counters(NULL), 1.86 + _from_counters(NULL), 1.87 + _to_counters(NULL), 1.88 + 1.89 + _overall_reserved(0), 1.90 + _overall_committed(0), _overall_used(0), 1.91 + _young_region_num(0), 1.92 + _young_gen_committed(0), 1.93 + _eden_committed(0), _eden_used(0), 1.94 + _survivor_committed(0), _survivor_used(0), 1.95 + _old_committed(0), _old_used(0) { 1.96 + 1.97 + _overall_reserved = g1h->max_capacity(); 1.98 + recalculate_sizes(); 1.99 + 1.100 + // Counters for GC collections 1.101 + // 1.102 + // name "collector.0". In a generational collector this would be the 1.103 + // young generation collection. 1.104 + _incremental_collection_counters = 1.105 + new CollectorCounters("G1 incremental collections", 0); 1.106 + // name "collector.1". In a generational collector this would be the 1.107 + // old generation collection. 1.108 + _full_collection_counters = 1.109 + new CollectorCounters("G1 stop-the-world full collections", 1); 1.110 + 1.111 + // timer sampling for all counters supporting sampling only update the 1.112 + // used value. See the take_sample() method. G1 requires both used and 1.113 + // capacity updated so sampling is not currently used. It might 1.114 + // be sufficient to update all counters in take_sample() even though 1.115 + // take_sample() only returns "used". When sampling was used, there 1.116 + // were some anomolous values emitted which may have been the consequence 1.117 + // of not updating all values simultaneously (i.e., see the calculation done 1.118 + // in eden_space_used(), is it possbile that the values used to 1.119 + // calculate either eden_used or survivor_used are being updated by 1.120 + // the collector when the sample is being done?). 1.121 + const bool sampled = false; 1.122 + 1.123 + // "Generation" and "Space" counters. 1.124 + // 1.125 + // name "generation.1" This is logically the old generation in 1.126 + // generational GC terms. The "1, 1" parameters are for 1.127 + // the n-th generation (=1) with 1 space. 1.128 + // Counters are created from minCapacity, maxCapacity, and capacity 1.129 + _old_collection_counters = new G1OldGenerationCounters(this, "old"); 1.130 + 1.131 + // name "generation.1.space.0" 1.132 + // Counters are created from maxCapacity, capacity, initCapacity, 1.133 + // and used. 1.134 + _old_space_counters = new HSpaceCounters("space", 0 /* ordinal */, 1.135 + pad_capacity(overall_reserved()) /* max_capacity */, 1.136 + pad_capacity(old_space_committed()) /* init_capacity */, 1.137 + _old_collection_counters); 1.138 + 1.139 + // Young collection set 1.140 + // name "generation.0". This is logically the young generation. 1.141 + // The "0, 3" are paremeters for the n-th genertaion (=0) with 3 spaces. 1.142 + // See _old_collection_counters for additional counters 1.143 + _young_collection_counters = new G1YoungGenerationCounters(this, "young"); 1.144 + 1.145 + // name "generation.0.space.0" 1.146 + // See _old_space_counters for additional counters 1.147 + _eden_counters = new HSpaceCounters("eden", 0 /* ordinal */, 1.148 + pad_capacity(overall_reserved()) /* max_capacity */, 1.149 + pad_capacity(eden_space_committed()) /* init_capacity */, 1.150 + _young_collection_counters); 1.151 + 1.152 + // name "generation.0.space.1" 1.153 + // See _old_space_counters for additional counters 1.154 + // Set the arguments to indicate that this survivor space is not used. 1.155 + _from_counters = new HSpaceCounters("s0", 1 /* ordinal */, 1.156 + pad_capacity(0) /* max_capacity */, 1.157 + pad_capacity(0) /* init_capacity */, 1.158 + _young_collection_counters); 1.159 + 1.160 + // name "generation.0.space.2" 1.161 + // See _old_space_counters for additional counters 1.162 + _to_counters = new HSpaceCounters("s1", 2 /* ordinal */, 1.163 + pad_capacity(overall_reserved()) /* max_capacity */, 1.164 + pad_capacity(survivor_space_committed()) /* init_capacity */, 1.165 + _young_collection_counters); 1.166 + 1.167 + if (UsePerfData) { 1.168 + // Given that this survivor space is not used, we update it here 1.169 + // once to reflect that its used space is 0 so that we don't have to 1.170 + // worry about updating it again later. 1.171 + _from_counters->update_used(0); 1.172 + } 1.173 +} 1.174 + 1.175 +void G1MonitoringSupport::recalculate_sizes() { 1.176 + G1CollectedHeap* g1 = g1h(); 1.177 + 1.178 + // Recalculate all the sizes from scratch. We assume that this is 1.179 + // called at a point where no concurrent updates to the various 1.180 + // values we read here are possible (i.e., at a STW phase at the end 1.181 + // of a GC). 1.182 + 1.183 + uint young_list_length = g1->young_list()->length(); 1.184 + uint survivor_list_length = g1->g1_policy()->recorded_survivor_regions(); 1.185 + assert(young_list_length >= survivor_list_length, "invariant"); 1.186 + uint eden_list_length = young_list_length - survivor_list_length; 1.187 + // Max length includes any potential extensions to the young gen 1.188 + // we'll do when the GC locker is active. 1.189 + uint young_list_max_length = g1->g1_policy()->young_list_max_length(); 1.190 + assert(young_list_max_length >= survivor_list_length, "invariant"); 1.191 + uint eden_list_max_length = young_list_max_length - survivor_list_length; 1.192 + 1.193 + _overall_used = g1->used_unlocked(); 1.194 + _eden_used = (size_t) eden_list_length * HeapRegion::GrainBytes; 1.195 + _survivor_used = (size_t) survivor_list_length * HeapRegion::GrainBytes; 1.196 + _young_region_num = young_list_length; 1.197 + _old_used = subtract_up_to_zero(_overall_used, _eden_used + _survivor_used); 1.198 + 1.199 + // First calculate the committed sizes that can be calculated independently. 1.200 + _survivor_committed = _survivor_used; 1.201 + _old_committed = HeapRegion::align_up_to_region_byte_size(_old_used); 1.202 + 1.203 + // Next, start with the overall committed size. 1.204 + _overall_committed = g1->capacity(); 1.205 + size_t committed = _overall_committed; 1.206 + 1.207 + // Remove the committed size we have calculated so far (for the 1.208 + // survivor and old space). 1.209 + assert(committed >= (_survivor_committed + _old_committed), "sanity"); 1.210 + committed -= _survivor_committed + _old_committed; 1.211 + 1.212 + // Next, calculate and remove the committed size for the eden. 1.213 + _eden_committed = (size_t) eden_list_max_length * HeapRegion::GrainBytes; 1.214 + // Somewhat defensive: be robust in case there are inaccuracies in 1.215 + // the calculations 1.216 + _eden_committed = MIN2(_eden_committed, committed); 1.217 + committed -= _eden_committed; 1.218 + 1.219 + // Finally, give the rest to the old space... 1.220 + _old_committed += committed; 1.221 + // ..and calculate the young gen committed. 1.222 + _young_gen_committed = _eden_committed + _survivor_committed; 1.223 + 1.224 + assert(_overall_committed == 1.225 + (_eden_committed + _survivor_committed + _old_committed), 1.226 + "the committed sizes should add up"); 1.227 + // Somewhat defensive: cap the eden used size to make sure it 1.228 + // never exceeds the committed size. 1.229 + _eden_used = MIN2(_eden_used, _eden_committed); 1.230 + // _survivor_committed and _old_committed are calculated in terms of 1.231 + // the corresponding _*_used value, so the next two conditions 1.232 + // should hold. 1.233 + assert(_survivor_used <= _survivor_committed, "post-condition"); 1.234 + assert(_old_used <= _old_committed, "post-condition"); 1.235 +} 1.236 + 1.237 +void G1MonitoringSupport::recalculate_eden_size() { 1.238 + G1CollectedHeap* g1 = g1h(); 1.239 + 1.240 + // When a new eden region is allocated, only the eden_used size is 1.241 + // affected (since we have recalculated everything else at the last GC). 1.242 + 1.243 + uint young_region_num = g1h()->young_list()->length(); 1.244 + if (young_region_num > _young_region_num) { 1.245 + uint diff = young_region_num - _young_region_num; 1.246 + _eden_used += (size_t) diff * HeapRegion::GrainBytes; 1.247 + // Somewhat defensive: cap the eden used size to make sure it 1.248 + // never exceeds the committed size. 1.249 + _eden_used = MIN2(_eden_used, _eden_committed); 1.250 + _young_region_num = young_region_num; 1.251 + } 1.252 +} 1.253 + 1.254 +void G1MonitoringSupport::update_sizes() { 1.255 + recalculate_sizes(); 1.256 + if (UsePerfData) { 1.257 + eden_counters()->update_capacity(pad_capacity(eden_space_committed())); 1.258 + eden_counters()->update_used(eden_space_used()); 1.259 + // only the to survivor space (s1) is active, so we don't need to 1.260 + // update the counteres for the from survivor space (s0) 1.261 + to_counters()->update_capacity(pad_capacity(survivor_space_committed())); 1.262 + to_counters()->update_used(survivor_space_used()); 1.263 + old_space_counters()->update_capacity(pad_capacity(old_space_committed())); 1.264 + old_space_counters()->update_used(old_space_used()); 1.265 + old_collection_counters()->update_all(); 1.266 + young_collection_counters()->update_all(); 1.267 + MetaspaceCounters::update_performance_counters(); 1.268 + CompressedClassSpaceCounters::update_performance_counters(); 1.269 + } 1.270 +} 1.271 + 1.272 +void G1MonitoringSupport::update_eden_size() { 1.273 + recalculate_eden_size(); 1.274 + if (UsePerfData) { 1.275 + eden_counters()->update_used(eden_space_used()); 1.276 + } 1.277 +}