1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/g1/g1RemSetSummary.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,354 @@ 1.4 +/* 1.5 + * Copyright (c) 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/concurrentG1Refine.hpp" 1.30 +#include "gc_implementation/g1/concurrentG1RefineThread.hpp" 1.31 +#include "gc_implementation/g1/heapRegion.hpp" 1.32 +#include "gc_implementation/g1/g1CollectedHeap.inline.hpp" 1.33 +#include "gc_implementation/g1/g1RemSet.inline.hpp" 1.34 +#include "gc_implementation/g1/g1RemSetSummary.hpp" 1.35 +#include "gc_implementation/g1/heapRegionRemSet.hpp" 1.36 +#include "runtime/thread.inline.hpp" 1.37 + 1.38 +class GetRSThreadVTimeClosure : public ThreadClosure { 1.39 +private: 1.40 + G1RemSetSummary* _summary; 1.41 + uint _counter; 1.42 + 1.43 +public: 1.44 + GetRSThreadVTimeClosure(G1RemSetSummary * summary) : ThreadClosure(), _summary(summary), _counter(0) { 1.45 + assert(_summary != NULL, "just checking"); 1.46 + } 1.47 + 1.48 + virtual void do_thread(Thread* t) { 1.49 + ConcurrentG1RefineThread* crt = (ConcurrentG1RefineThread*) t; 1.50 + _summary->set_rs_thread_vtime(_counter, crt->vtime_accum()); 1.51 + _counter++; 1.52 + } 1.53 +}; 1.54 + 1.55 +void G1RemSetSummary::update() { 1.56 + _num_refined_cards = remset()->conc_refine_cards(); 1.57 + DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); 1.58 + _num_processed_buf_mutator = dcqs.processed_buffers_mut(); 1.59 + _num_processed_buf_rs_threads = dcqs.processed_buffers_rs_thread(); 1.60 + 1.61 + _num_coarsenings = HeapRegionRemSet::n_coarsenings(); 1.62 + 1.63 + ConcurrentG1Refine * cg1r = G1CollectedHeap::heap()->concurrent_g1_refine(); 1.64 + if (_rs_threads_vtimes != NULL) { 1.65 + GetRSThreadVTimeClosure p(this); 1.66 + cg1r->worker_threads_do(&p); 1.67 + } 1.68 + set_sampling_thread_vtime(cg1r->sampling_thread()->vtime_accum()); 1.69 +} 1.70 + 1.71 +void G1RemSetSummary::set_rs_thread_vtime(uint thread, double value) { 1.72 + assert(_rs_threads_vtimes != NULL, "just checking"); 1.73 + assert(thread < _num_vtimes, "just checking"); 1.74 + _rs_threads_vtimes[thread] = value; 1.75 +} 1.76 + 1.77 +double G1RemSetSummary::rs_thread_vtime(uint thread) const { 1.78 + assert(_rs_threads_vtimes != NULL, "just checking"); 1.79 + assert(thread < _num_vtimes, "just checking"); 1.80 + return _rs_threads_vtimes[thread]; 1.81 +} 1.82 + 1.83 +void G1RemSetSummary::initialize(G1RemSet* remset) { 1.84 + assert(_rs_threads_vtimes == NULL, "just checking"); 1.85 + assert(remset != NULL, "just checking"); 1.86 + 1.87 + _remset = remset; 1.88 + _num_vtimes = ConcurrentG1Refine::thread_num(); 1.89 + _rs_threads_vtimes = NEW_C_HEAP_ARRAY(double, _num_vtimes, mtGC); 1.90 + memset(_rs_threads_vtimes, 0, sizeof(double) * _num_vtimes); 1.91 + 1.92 + update(); 1.93 +} 1.94 + 1.95 +void G1RemSetSummary::set(G1RemSetSummary* other) { 1.96 + assert(other != NULL, "just checking"); 1.97 + assert(remset() == other->remset(), "just checking"); 1.98 + assert(_num_vtimes == other->_num_vtimes, "just checking"); 1.99 + 1.100 + _num_refined_cards = other->num_concurrent_refined_cards(); 1.101 + 1.102 + _num_processed_buf_mutator = other->num_processed_buf_mutator(); 1.103 + _num_processed_buf_rs_threads = other->num_processed_buf_rs_threads(); 1.104 + 1.105 + _num_coarsenings = other->_num_coarsenings; 1.106 + 1.107 + memcpy(_rs_threads_vtimes, other->_rs_threads_vtimes, sizeof(double) * _num_vtimes); 1.108 + 1.109 + set_sampling_thread_vtime(other->sampling_thread_vtime()); 1.110 +} 1.111 + 1.112 +void G1RemSetSummary::subtract_from(G1RemSetSummary* other) { 1.113 + assert(other != NULL, "just checking"); 1.114 + assert(remset() == other->remset(), "just checking"); 1.115 + assert(_num_vtimes == other->_num_vtimes, "just checking"); 1.116 + 1.117 + _num_refined_cards = other->num_concurrent_refined_cards() - _num_refined_cards; 1.118 + 1.119 + _num_processed_buf_mutator = other->num_processed_buf_mutator() - _num_processed_buf_mutator; 1.120 + _num_processed_buf_rs_threads = other->num_processed_buf_rs_threads() - _num_processed_buf_rs_threads; 1.121 + 1.122 + _num_coarsenings = other->num_coarsenings() - _num_coarsenings; 1.123 + 1.124 + for (uint i = 0; i < _num_vtimes; i++) { 1.125 + set_rs_thread_vtime(i, other->rs_thread_vtime(i) - rs_thread_vtime(i)); 1.126 + } 1.127 + 1.128 + _sampling_thread_vtime = other->sampling_thread_vtime() - _sampling_thread_vtime; 1.129 +} 1.130 + 1.131 +static double percent_of(size_t numerator, size_t denominator) { 1.132 + if (denominator != 0) { 1.133 + return (double)numerator / denominator * 100.0f; 1.134 + } else { 1.135 + return 0.0f; 1.136 + } 1.137 +} 1.138 + 1.139 +static size_t round_to_K(size_t value) { 1.140 + return value / K; 1.141 +} 1.142 + 1.143 +class RegionTypeCounter VALUE_OBJ_CLASS_SPEC { 1.144 +private: 1.145 + const char* _name; 1.146 + 1.147 + size_t _rs_mem_size; 1.148 + size_t _cards_occupied; 1.149 + size_t _amount; 1.150 + 1.151 + size_t _code_root_mem_size; 1.152 + size_t _code_root_elems; 1.153 + 1.154 + double rs_mem_size_percent_of(size_t total) { 1.155 + return percent_of(_rs_mem_size, total); 1.156 + } 1.157 + 1.158 + double cards_occupied_percent_of(size_t total) { 1.159 + return percent_of(_cards_occupied, total); 1.160 + } 1.161 + 1.162 + double code_root_mem_size_percent_of(size_t total) { 1.163 + return percent_of(_code_root_mem_size, total); 1.164 + } 1.165 + 1.166 + double code_root_elems_percent_of(size_t total) { 1.167 + return percent_of(_code_root_elems, total); 1.168 + } 1.169 + 1.170 + size_t amount() const { return _amount; } 1.171 + 1.172 +public: 1.173 + 1.174 + RegionTypeCounter(const char* name) : _name(name), _rs_mem_size(0), _cards_occupied(0), 1.175 + _amount(0), _code_root_mem_size(0), _code_root_elems(0) { } 1.176 + 1.177 + void add(size_t rs_mem_size, size_t cards_occupied, size_t code_root_mem_size, 1.178 + size_t code_root_elems) { 1.179 + _rs_mem_size += rs_mem_size; 1.180 + _cards_occupied += cards_occupied; 1.181 + _code_root_mem_size += code_root_mem_size; 1.182 + _code_root_elems += code_root_elems; 1.183 + _amount++; 1.184 + } 1.185 + 1.186 + size_t rs_mem_size() const { return _rs_mem_size; } 1.187 + size_t cards_occupied() const { return _cards_occupied; } 1.188 + 1.189 + size_t code_root_mem_size() const { return _code_root_mem_size; } 1.190 + size_t code_root_elems() const { return _code_root_elems; } 1.191 + 1.192 + void print_rs_mem_info_on(outputStream * out, size_t total) { 1.193 + out->print_cr(" "SIZE_FORMAT_W(8)"K (%5.1f%%) by "SIZE_FORMAT" %s regions", 1.194 + round_to_K(rs_mem_size()), rs_mem_size_percent_of(total), amount(), _name); 1.195 + } 1.196 + 1.197 + void print_cards_occupied_info_on(outputStream * out, size_t total) { 1.198 + out->print_cr(" "SIZE_FORMAT_W(8)" (%5.1f%%) entries by "SIZE_FORMAT" %s regions", 1.199 + cards_occupied(), cards_occupied_percent_of(total), amount(), _name); 1.200 + } 1.201 + 1.202 + void print_code_root_mem_info_on(outputStream * out, size_t total) { 1.203 + out->print_cr(" "SIZE_FORMAT_W(8)"K (%5.1f%%) by "SIZE_FORMAT" %s regions", 1.204 + round_to_K(code_root_mem_size()), code_root_mem_size_percent_of(total), amount(), _name); 1.205 + } 1.206 + 1.207 + void print_code_root_elems_info_on(outputStream * out, size_t total) { 1.208 + out->print_cr(" "SIZE_FORMAT_W(8)" (%5.1f%%) elements by "SIZE_FORMAT" %s regions", 1.209 + code_root_elems(), code_root_elems_percent_of(total), amount(), _name); 1.210 + } 1.211 +}; 1.212 + 1.213 + 1.214 +class HRRSStatsIter: public HeapRegionClosure { 1.215 +private: 1.216 + RegionTypeCounter _young; 1.217 + RegionTypeCounter _humonguous; 1.218 + RegionTypeCounter _free; 1.219 + RegionTypeCounter _old; 1.220 + RegionTypeCounter _all; 1.221 + 1.222 + size_t _max_rs_mem_sz; 1.223 + HeapRegion* _max_rs_mem_sz_region; 1.224 + 1.225 + size_t total_rs_mem_sz() const { return _all.rs_mem_size(); } 1.226 + size_t total_cards_occupied() const { return _all.cards_occupied(); } 1.227 + 1.228 + size_t max_rs_mem_sz() const { return _max_rs_mem_sz; } 1.229 + HeapRegion* max_rs_mem_sz_region() const { return _max_rs_mem_sz_region; } 1.230 + 1.231 + size_t _max_code_root_mem_sz; 1.232 + HeapRegion* _max_code_root_mem_sz_region; 1.233 + 1.234 + size_t total_code_root_mem_sz() const { return _all.code_root_mem_size(); } 1.235 + size_t total_code_root_elems() const { return _all.code_root_elems(); } 1.236 + 1.237 + size_t max_code_root_mem_sz() const { return _max_code_root_mem_sz; } 1.238 + HeapRegion* max_code_root_mem_sz_region() const { return _max_code_root_mem_sz_region; } 1.239 + 1.240 +public: 1.241 + HRRSStatsIter() : _all("All"), _young("Young"), _humonguous("Humonguous"), 1.242 + _free("Free"), _old("Old"), _max_code_root_mem_sz_region(NULL), _max_rs_mem_sz_region(NULL), 1.243 + _max_rs_mem_sz(0), _max_code_root_mem_sz(0) 1.244 + {} 1.245 + 1.246 + bool doHeapRegion(HeapRegion* r) { 1.247 + HeapRegionRemSet* hrrs = r->rem_set(); 1.248 + 1.249 + // HeapRegionRemSet::mem_size() includes the 1.250 + // size of the strong code roots 1.251 + size_t rs_mem_sz = hrrs->mem_size(); 1.252 + if (rs_mem_sz > _max_rs_mem_sz) { 1.253 + _max_rs_mem_sz = rs_mem_sz; 1.254 + _max_rs_mem_sz_region = r; 1.255 + } 1.256 + size_t occupied_cards = hrrs->occupied(); 1.257 + size_t code_root_mem_sz = hrrs->strong_code_roots_mem_size(); 1.258 + if (code_root_mem_sz > max_code_root_mem_sz()) { 1.259 + _max_code_root_mem_sz_region = r; 1.260 + } 1.261 + size_t code_root_elems = hrrs->strong_code_roots_list_length(); 1.262 + 1.263 + RegionTypeCounter* current = NULL; 1.264 + if (r->is_young()) { 1.265 + current = &_young; 1.266 + } else if (r->isHumongous()) { 1.267 + current = &_humonguous; 1.268 + } else if (r->is_empty()) { 1.269 + current = &_free; 1.270 + } else { 1.271 + current = &_old; 1.272 + } 1.273 + current->add(rs_mem_sz, occupied_cards, code_root_mem_sz, code_root_elems); 1.274 + _all.add(rs_mem_sz, occupied_cards, code_root_mem_sz, code_root_elems); 1.275 + 1.276 + return false; 1.277 + } 1.278 + 1.279 + void print_summary_on(outputStream* out) { 1.280 + RegionTypeCounter* counters[] = { &_young, &_humonguous, &_free, &_old, NULL }; 1.281 + 1.282 + out->print_cr("\n Current rem set statistics"); 1.283 + out->print_cr(" Total per region rem sets sizes = "SIZE_FORMAT"K." 1.284 + " Max = "SIZE_FORMAT"K.", 1.285 + round_to_K(total_rs_mem_sz()), round_to_K(max_rs_mem_sz())); 1.286 + for (RegionTypeCounter** current = &counters[0]; *current != NULL; current++) { 1.287 + (*current)->print_rs_mem_info_on(out, total_rs_mem_sz()); 1.288 + } 1.289 + 1.290 + out->print_cr(" Static structures = "SIZE_FORMAT"K," 1.291 + " free_lists = "SIZE_FORMAT"K.", 1.292 + round_to_K(HeapRegionRemSet::static_mem_size()), 1.293 + round_to_K(HeapRegionRemSet::fl_mem_size())); 1.294 + 1.295 + out->print_cr(" "SIZE_FORMAT" occupied cards represented.", 1.296 + total_cards_occupied()); 1.297 + for (RegionTypeCounter** current = &counters[0]; *current != NULL; current++) { 1.298 + (*current)->print_cards_occupied_info_on(out, total_cards_occupied()); 1.299 + } 1.300 + 1.301 + // Largest sized rem set region statistics 1.302 + HeapRegionRemSet* rem_set = max_rs_mem_sz_region()->rem_set(); 1.303 + out->print_cr(" Region with largest rem set = "HR_FORMAT", " 1.304 + "size = "SIZE_FORMAT "K, occupied = "SIZE_FORMAT"K.", 1.305 + HR_FORMAT_PARAMS(max_rs_mem_sz_region()), 1.306 + round_to_K(rem_set->mem_size()), 1.307 + round_to_K(rem_set->occupied())); 1.308 + 1.309 + // Strong code root statistics 1.310 + HeapRegionRemSet* max_code_root_rem_set = max_code_root_mem_sz_region()->rem_set(); 1.311 + out->print_cr(" Total heap region code root sets sizes = "SIZE_FORMAT"K." 1.312 + " Max = "SIZE_FORMAT"K.", 1.313 + round_to_K(total_code_root_mem_sz()), 1.314 + round_to_K(max_code_root_rem_set->strong_code_roots_mem_size())); 1.315 + for (RegionTypeCounter** current = &counters[0]; *current != NULL; current++) { 1.316 + (*current)->print_code_root_mem_info_on(out, total_code_root_mem_sz()); 1.317 + } 1.318 + 1.319 + out->print_cr(" "SIZE_FORMAT" code roots represented.", 1.320 + total_code_root_elems()); 1.321 + for (RegionTypeCounter** current = &counters[0]; *current != NULL; current++) { 1.322 + (*current)->print_code_root_elems_info_on(out, total_code_root_elems()); 1.323 + } 1.324 + 1.325 + out->print_cr(" Region with largest amount of code roots = "HR_FORMAT", " 1.326 + "size = "SIZE_FORMAT "K, num_elems = "SIZE_FORMAT".", 1.327 + HR_FORMAT_PARAMS(max_code_root_mem_sz_region()), 1.328 + round_to_K(max_code_root_rem_set->strong_code_roots_mem_size()), 1.329 + round_to_K(max_code_root_rem_set->strong_code_roots_list_length())); 1.330 + } 1.331 +}; 1.332 + 1.333 +void G1RemSetSummary::print_on(outputStream* out) { 1.334 + out->print_cr("\n Recent concurrent refinement statistics"); 1.335 + out->print_cr(" Processed "SIZE_FORMAT" cards", 1.336 + num_concurrent_refined_cards()); 1.337 + out->print_cr(" Of "SIZE_FORMAT" completed buffers:", num_processed_buf_total()); 1.338 + out->print_cr(" "SIZE_FORMAT_W(8)" (%5.1f%%) by concurrent RS threads.", 1.339 + num_processed_buf_total(), 1.340 + percent_of(num_processed_buf_rs_threads(), num_processed_buf_total())); 1.341 + out->print_cr(" "SIZE_FORMAT_W(8)" (%5.1f%%) by mutator threads.", 1.342 + num_processed_buf_mutator(), 1.343 + percent_of(num_processed_buf_mutator(), num_processed_buf_total())); 1.344 + out->print_cr(" Did "SIZE_FORMAT" coarsenings.", num_coarsenings()); 1.345 + out->print_cr(" Concurrent RS threads times (s)"); 1.346 + out->print(" "); 1.347 + for (uint i = 0; i < _num_vtimes; i++) { 1.348 + out->print(" %5.2f", rs_thread_vtime(i)); 1.349 + } 1.350 + out->cr(); 1.351 + out->print_cr(" Concurrent sampling threads times (s)"); 1.352 + out->print_cr(" %5.2f", sampling_thread_vtime()); 1.353 + 1.354 + HRRSStatsIter blk; 1.355 + G1CollectedHeap::heap()->heap_region_iterate(&blk); 1.356 + blk.print_summary_on(out); 1.357 +}