1 /* 2 * Copyright (c) 2013, 2015 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 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1GCPHASETIMESLOG_HPP 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1GCPHASETIMESLOG_HPP 27 28 #include "memory/allocation.hpp" 29 #include "gc_interface/gcCause.hpp" 30 31 template <class T> 32 class WorkerDataArray : public CHeapObj<mtGC> { 33 T* _data; 34 uint _length; 35 const char* _print_format; 36 bool _print_sum; 37 38 NOT_PRODUCT(static const T _uninitialized;) 39 40 // We are caching the sum and average to only have to calculate them once. 41 // This is not done in an MT-safe way. It is intended to allow single 42 // threaded code to call sum() and average() multiple times in any order 43 // without having to worry about the cost. 44 bool _has_new_data; 45 T _sum; 46 double _average; 47 48 public: 49 WorkerDataArray(uint length, const char* print_format, bool print_sum = true) : 50 _length(length), _print_format(print_format), _print_sum(print_sum), _has_new_data(true) { 51 assert(length > 0, "Must have some workers to store data for"); 52 _data = NEW_C_HEAP_ARRAY(T, _length, mtGC); 53 } 54 55 ~WorkerDataArray() { 56 FREE_C_HEAP_ARRAY(T, _data); 57 } 58 59 void set(uint worker_i, T value) { 60 assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); 61 assert(_data[worker_i] == (T)-1, err_msg("Overwriting data for worker %d", worker_i)); 62 _data[worker_i] = value; 63 _has_new_data = true; 64 } 65 66 T get(uint worker_i) { 67 assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); 68 assert(_data[worker_i] != (T)-1, err_msg("No data to add to for worker %d", worker_i)); 69 return _data[worker_i]; 70 } 71 72 void add(uint worker_i, T value) { 73 assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); 74 assert(_data[worker_i] != (T)-1, err_msg("No data to add to for worker %d", worker_i)); 75 _data[worker_i] += value; 76 _has_new_data = true; 77 } 78 79 double average(){ 80 if (_has_new_data) { 81 calculate_totals(); 82 } 83 return _average; 84 } 85 86 T sum() { 87 if (_has_new_data) { 88 calculate_totals(); 89 } 90 return _sum; 91 } 92 93 void print(int level, const char* title); 94 95 void reset() PRODUCT_RETURN; 96 void verify() PRODUCT_RETURN; 97 98 private: 99 100 void calculate_totals(){ 101 _sum = (T)0; 102 for (uint i = 0; i < _length; ++i) { 103 _sum += _data[i]; 104 } 105 _average = (double)_sum / (double)_length; 106 _has_new_data = false; 107 } 108 }; 109 110 class GCPhaseTimeData : public PhaseTimeData { 111 private: 112 WorkerDataArray<double>** _data; 113 uint _num_phases; 114 uint _worker_id; 115 public: 116 GCPhaseTimeData(WorkerDataArray<double>** data, uint num_phases, uint worker_id) : 117 _data(data), _num_phases(num_phases), _worker_id(worker_id) { } 118 119 virtual bool active() const { return _num_phases > 0; } 120 121 virtual void set_value(uint phase, double value) { 122 assert(_data != NULL, "just checking"); 123 _data[phase]->set(_worker_id, value); 124 } 125 }; 126 127 class G1GCPhaseTimes : public CHeapObj<mtGC> { 128 129 private: 130 uint _active_gc_threads; 131 uint _max_gc_threads; 132 uint _num_ext_root_scan_phases; 133 134 bool track_ext_root_scan_phases() const { return _num_ext_root_scan_phases > 0; } 135 136 WorkerDataArray<double> _last_gc_worker_start_times_ms; 137 WorkerDataArray<double> _last_ext_root_scan_times_ms; 138 WorkerDataArray<double>** _last_ext_root_scan_phase_times_ms; 139 WorkerDataArray<double> _last_satb_filtering_times_ms; 140 WorkerDataArray<double> _last_update_rs_times_ms; 141 WorkerDataArray<int> _last_update_rs_processed_buffers; 142 WorkerDataArray<double> _last_scan_rs_times_ms; 143 WorkerDataArray<double> _last_strong_code_root_scan_times_ms; 144 WorkerDataArray<double> _last_obj_copy_times_ms; 145 WorkerDataArray<double> _last_termination_times_ms; 146 WorkerDataArray<size_t> _last_termination_attempts; 147 WorkerDataArray<double> _last_gc_worker_end_times_ms; 148 WorkerDataArray<double> _last_gc_worker_times_ms; 149 WorkerDataArray<double> _last_gc_worker_other_times_ms; 150 151 double _cur_collection_par_time_ms; 152 double _cur_collection_code_root_fixup_time_ms; 153 double _cur_strong_code_root_purge_time_ms; 154 155 double _cur_evac_fail_recalc_used; 156 double _cur_evac_fail_restore_remsets; 157 double _cur_evac_fail_remove_self_forwards; 158 159 double _cur_string_dedup_fixup_time_ms; 160 WorkerDataArray<double> _cur_string_dedup_queue_fixup_worker_times_ms; 161 WorkerDataArray<double> _cur_string_dedup_table_fixup_worker_times_ms; 162 163 double _cur_clear_ct_time_ms; 164 double _cur_ref_proc_time_ms; 165 double _cur_ref_enq_time_ms; 166 167 double _cur_collection_start_sec; 168 double _root_region_scan_wait_time_ms; 169 170 double _recorded_young_cset_choice_time_ms; 171 double _recorded_non_young_cset_choice_time_ms; 172 173 WorkerDataArray<double> _last_redirty_logged_cards_time_ms; 174 WorkerDataArray<size_t> _last_redirty_logged_cards_processed_cards; 175 double _recorded_redirty_logged_cards_time_ms; 176 177 double _recorded_young_free_cset_time_ms; 178 double _recorded_non_young_free_cset_time_ms; 179 180 double _cur_fast_reclaim_humongous_time_ms; 181 double _cur_fast_reclaim_humongous_register_time_ms; 182 size_t _cur_fast_reclaim_humongous_total; 183 size_t _cur_fast_reclaim_humongous_candidates; 184 size_t _cur_fast_reclaim_humongous_reclaimed; 185 186 double _cur_verify_before_time_ms; 187 double _cur_verify_after_time_ms; 188 189 // Helper methods for detailed logging 190 void print_stats(int level, const char* str, double value); 191 void print_stats(int level, const char* str, size_t value); 192 void print_stats(int level, const char* str, double value, uint workers); 193 194 public: 195 G1GCPhaseTimes(uint max_gc_threads, uint num_ext_root_scan_phases); 196 virtual ~G1GCPhaseTimes(); 197 198 WorkerDataArray<double>** get_ext_root_scan_phase_times() const { return _last_ext_root_scan_phase_times_ms; } 199 uint num_ext_root_scan_phases() const { return _num_ext_root_scan_phases; } 200 201 void note_gc_start(uint active_gc_threads); 202 void note_gc_end(); 203 void print(double pause_time_sec); 204 205 void record_gc_worker_start_time(uint worker_i, double ms) { 206 _last_gc_worker_start_times_ms.set(worker_i, ms); 207 } 208 209 void record_ext_root_scan_time(uint worker_i, double ms) { 210 _last_ext_root_scan_times_ms.set(worker_i, ms); 211 } 212 213 void record_satb_filtering_time(uint worker_i, double ms) { 214 _last_satb_filtering_times_ms.set(worker_i, ms); 215 } 216 217 void record_update_rs_time(uint worker_i, double ms) { 218 _last_update_rs_times_ms.set(worker_i, ms); 219 } 220 221 void record_update_rs_processed_buffers(uint worker_i, int processed_buffers) { 222 _last_update_rs_processed_buffers.set(worker_i, processed_buffers); 223 } 224 225 void record_scan_rs_time(uint worker_i, double ms) { 226 _last_scan_rs_times_ms.set(worker_i, ms); 227 } 228 229 void record_strong_code_root_scan_time(uint worker_i, double ms) { 230 _last_strong_code_root_scan_times_ms.set(worker_i, ms); 231 } 232 233 void record_obj_copy_time(uint worker_i, double ms) { 234 _last_obj_copy_times_ms.set(worker_i, ms); 235 } 236 237 void add_obj_copy_time(uint worker_i, double ms) { 238 _last_obj_copy_times_ms.add(worker_i, ms); 239 } 240 241 void record_termination(uint worker_i, double ms, size_t attempts) { 242 _last_termination_times_ms.set(worker_i, ms); 243 _last_termination_attempts.set(worker_i, attempts); 244 } 245 246 void record_gc_worker_end_time(uint worker_i, double ms) { 247 _last_gc_worker_end_times_ms.set(worker_i, ms); 248 } 249 250 void record_clear_ct_time(double ms) { 251 _cur_clear_ct_time_ms = ms; 252 } 253 254 void record_par_time(double ms) { 255 _cur_collection_par_time_ms = ms; 256 } 257 258 void record_code_root_fixup_time(double ms) { 259 _cur_collection_code_root_fixup_time_ms = ms; 260 } 261 262 void record_strong_code_root_purge_time(double ms) { 263 _cur_strong_code_root_purge_time_ms = ms; 264 } 265 266 void record_evac_fail_recalc_used_time(double ms) { 267 _cur_evac_fail_recalc_used = ms; 268 } 269 270 void record_evac_fail_restore_remsets(double ms) { 271 _cur_evac_fail_restore_remsets = ms; 272 } 273 274 void record_evac_fail_remove_self_forwards(double ms) { 275 _cur_evac_fail_remove_self_forwards = ms; 276 } 277 278 void note_string_dedup_fixup_start(); 279 void note_string_dedup_fixup_end(); 280 281 void record_string_dedup_fixup_time(double ms) { 282 _cur_string_dedup_fixup_time_ms = ms; 283 } 284 285 void record_string_dedup_queue_fixup_worker_time(uint worker_id, double ms) { 286 _cur_string_dedup_queue_fixup_worker_times_ms.set(worker_id, ms); 287 } 288 289 void record_string_dedup_table_fixup_worker_time(uint worker_id, double ms) { 290 _cur_string_dedup_table_fixup_worker_times_ms.set(worker_id, ms); 291 } 292 293 void record_ref_proc_time(double ms) { 294 _cur_ref_proc_time_ms = ms; 295 } 296 297 void record_ref_enq_time(double ms) { 298 _cur_ref_enq_time_ms = ms; 299 } 300 301 void record_root_region_scan_wait_time(double time_ms) { 302 _root_region_scan_wait_time_ms = time_ms; 303 } 304 305 void record_young_free_cset_time_ms(double time_ms) { 306 _recorded_young_free_cset_time_ms = time_ms; 307 } 308 309 void record_non_young_free_cset_time_ms(double time_ms) { 310 _recorded_non_young_free_cset_time_ms = time_ms; 311 } 312 313 void record_fast_reclaim_humongous_stats(double time_ms, size_t total, size_t candidates) { 314 _cur_fast_reclaim_humongous_register_time_ms = time_ms; 315 _cur_fast_reclaim_humongous_total = total; 316 _cur_fast_reclaim_humongous_candidates = candidates; 317 } 318 319 void record_fast_reclaim_humongous_time_ms(double value, size_t reclaimed) { 320 _cur_fast_reclaim_humongous_time_ms = value; 321 _cur_fast_reclaim_humongous_reclaimed = reclaimed; 322 } 323 324 void record_young_cset_choice_time_ms(double time_ms) { 325 _recorded_young_cset_choice_time_ms = time_ms; 326 } 327 328 void record_non_young_cset_choice_time_ms(double time_ms) { 329 _recorded_non_young_cset_choice_time_ms = time_ms; 330 } 331 332 void record_redirty_logged_cards_time_ms(uint worker_i, double time_ms) { 333 _last_redirty_logged_cards_time_ms.set(worker_i, time_ms); 334 } 335 336 void record_redirty_logged_cards_processed_cards(uint worker_i, size_t processed_buffers) { 337 _last_redirty_logged_cards_processed_cards.set(worker_i, processed_buffers); 338 } 339 340 void record_redirty_logged_cards_time_ms(double time_ms) { 341 _recorded_redirty_logged_cards_time_ms = time_ms; 342 } 343 344 void record_cur_collection_start_sec(double time_ms) { 345 _cur_collection_start_sec = time_ms; 346 } 347 348 void record_verify_before_time_ms(double time_ms) { 349 _cur_verify_before_time_ms = time_ms; 350 } 351 352 void record_verify_after_time_ms(double time_ms) { 353 _cur_verify_after_time_ms = time_ms; 354 } 355 356 double accounted_time_ms(); 357 358 double cur_collection_start_sec() { 359 return _cur_collection_start_sec; 360 } 361 362 double cur_collection_par_time_ms() { 363 return _cur_collection_par_time_ms; 364 } 365 366 double cur_clear_ct_time_ms() { 367 return _cur_clear_ct_time_ms; 368 } 369 370 double root_region_scan_wait_time_ms() { 371 return _root_region_scan_wait_time_ms; 372 } 373 374 double young_cset_choice_time_ms() { 375 return _recorded_young_cset_choice_time_ms; 376 } 377 378 double young_free_cset_time_ms() { 379 return _recorded_young_free_cset_time_ms; 380 } 381 382 double non_young_cset_choice_time_ms() { 383 return _recorded_non_young_cset_choice_time_ms; 384 } 385 386 double non_young_free_cset_time_ms() { 387 return _recorded_non_young_free_cset_time_ms; 388 } 389 390 double fast_reclaim_humongous_time_ms() { 391 return _cur_fast_reclaim_humongous_time_ms; 392 } 393 394 double average_last_update_rs_time() { 395 return _last_update_rs_times_ms.average(); 396 } 397 398 int sum_last_update_rs_processed_buffers() { 399 return _last_update_rs_processed_buffers.sum(); 400 } 401 402 double average_last_scan_rs_time(){ 403 return _last_scan_rs_times_ms.average(); 404 } 405 406 double average_last_strong_code_root_scan_time(){ 407 return _last_strong_code_root_scan_times_ms.average(); 408 } 409 410 double average_last_obj_copy_time() { 411 return _last_obj_copy_times_ms.average(); 412 } 413 414 double average_last_termination_time() { 415 return _last_termination_times_ms.average(); 416 } 417 418 double average_last_ext_root_scan_time() { 419 return _last_ext_root_scan_times_ms.average(); 420 } 421 422 double average_last_satb_filtering_times_ms() { 423 return _last_satb_filtering_times_ms.average(); 424 } 425 }; 426 427 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1GCPHASETIMESLOG_HPP