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 #include "precompiled.hpp" 26 #include "gc/g1/g1CollectedHeap.inline.hpp" 27 #include "gc/g1/g1GCPhaseTimes.hpp" 28 #include "gc/g1/g1Log.hpp" 29 #include "gc/g1/g1StringDedup.hpp" 30 #include "memory/allocation.hpp" 31 #include "runtime/os.hpp" 32 33 // Helper class for avoiding interleaved logging 34 class LineBuffer: public StackObj { 35 36 private: 37 static const int BUFFER_LEN = 1024; 38 static const int INDENT_CHARS = 3; 39 char _buffer[BUFFER_LEN]; 40 int _indent_level; 41 int _cur; 42 43 void vappend(const char* format, va_list ap) ATTRIBUTE_PRINTF(2, 0) { 44 int res = vsnprintf(&_buffer[_cur], BUFFER_LEN - _cur, format, ap); 45 if (res != -1) { 46 _cur += res; 47 } else { 48 DEBUG_ONLY(warning("buffer too small in LineBuffer");) 49 _buffer[BUFFER_LEN -1] = 0; 50 _cur = BUFFER_LEN; // vsnprintf above should not add to _buffer if we are called again 51 } 52 } 53 54 public: 55 explicit LineBuffer(int indent_level): _indent_level(indent_level), _cur(0) { 56 for (; (_cur < BUFFER_LEN && _cur < (_indent_level * INDENT_CHARS)); _cur++) { 57 _buffer[_cur] = ' '; 58 } 59 } 60 61 #ifndef PRODUCT 62 ~LineBuffer() { 63 assert(_cur == _indent_level * INDENT_CHARS, "pending data in buffer - append_and_print_cr() not called?"); 64 } 65 #endif 66 67 void append(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) { 68 va_list ap; 69 va_start(ap, format); 70 vappend(format, ap); 71 va_end(ap); 72 } 73 74 void print_cr() { 75 gclog_or_tty->print_cr("%s", _buffer); 76 _cur = _indent_level * INDENT_CHARS; 77 } 78 79 void append_and_print_cr(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) { 80 va_list ap; 81 va_start(ap, format); 82 vappend(format, ap); 83 va_end(ap); 84 print_cr(); 85 } 86 }; 87 88 template <class T> 89 class WorkerDataArray : public CHeapObj<mtGC> { 90 friend class G1GCParPhasePrinter; 91 T* _data; 92 uint _length; 93 const char* _title; 94 bool _print_sum; 95 int _log_level; 96 uint _indent_level; 97 bool _enabled; 98 99 WorkerDataArray<size_t>* _thread_work_items; 100 101 NOT_PRODUCT(T uninitialized();) 102 103 // We are caching the sum and average to only have to calculate them once. 104 // This is not done in an MT-safe way. It is intended to allow single 105 // threaded code to call sum() and average() multiple times in any order 106 // without having to worry about the cost. 107 bool _has_new_data; 108 T _sum; 109 T _min; 110 T _max; 111 double _average; 112 113 public: 114 WorkerDataArray(uint length, const char* title, bool print_sum, int log_level, uint indent_level) : 115 _title(title), _length(0), _print_sum(print_sum), _log_level(log_level), _indent_level(indent_level), 116 _has_new_data(true), _thread_work_items(NULL), _enabled(true) { 117 assert(length > 0, "Must have some workers to store data for"); 118 _length = length; 119 _data = NEW_C_HEAP_ARRAY(T, _length, mtGC); 120 } 121 122 ~WorkerDataArray() { 123 FREE_C_HEAP_ARRAY(T, _data); 124 } 125 126 void link_thread_work_items(WorkerDataArray<size_t>* thread_work_items) { 127 _thread_work_items = thread_work_items; 128 } 129 130 WorkerDataArray<size_t>* thread_work_items() { return _thread_work_items; } 131 132 void set(uint worker_i, T value) { 133 assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); 134 assert(_data[worker_i] == WorkerDataArray<T>::uninitialized(), err_msg("Overwriting data for worker %d in %s", worker_i, _title)); 135 _data[worker_i] = value; 136 _has_new_data = true; 137 } 138 139 void set_thread_work_item(uint worker_i, size_t value) { 140 assert(_thread_work_items != NULL, "No sub count"); 141 _thread_work_items->set(worker_i, value); 142 } 143 144 T get(uint worker_i) { 145 assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); 146 assert(_data[worker_i] != WorkerDataArray<T>::uninitialized(), err_msg("No data added for worker %d", worker_i)); 147 return _data[worker_i]; 148 } 149 150 void add(uint worker_i, T value) { 151 assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length)); 152 assert(_data[worker_i] != WorkerDataArray<T>::uninitialized(), err_msg("No data to add to for worker %d", worker_i)); 153 _data[worker_i] += value; 154 _has_new_data = true; 155 } 156 157 double average(uint active_threads){ 158 calculate_totals(active_threads); 159 return _average; 160 } 161 162 T sum(uint active_threads) { 163 calculate_totals(active_threads); 164 return _sum; 165 } 166 167 T minimum(uint active_threads) { 168 calculate_totals(active_threads); 169 return _min; 170 } 171 172 T maximum(uint active_threads) { 173 calculate_totals(active_threads); 174 return _max; 175 } 176 177 void reset() PRODUCT_RETURN; 178 void verify(uint active_threads) PRODUCT_RETURN; 179 180 void set_enabled(bool enabled) { _enabled = enabled; } 181 182 int log_level() { return _log_level; } 183 184 private: 185 186 void calculate_totals(uint active_threads){ 187 if (!_has_new_data) { 188 return; 189 } 190 191 _sum = (T)0; 192 _min = _data[0]; 193 _max = _min; 194 assert(active_threads <= _length, "Wrong number of active threads"); 195 for (uint i = 0; i < active_threads; ++i) { 196 T val = _data[i]; 197 _sum += val; 198 _min = MIN2(_min, val); 199 _max = MAX2(_max, val); 200 } 201 _average = (double)_sum / (double)active_threads; 202 _has_new_data = false; 203 } 204 }; 205 206 207 #ifndef PRODUCT 208 209 template <> 210 size_t WorkerDataArray<size_t>::uninitialized() { 211 return (size_t)-1; 212 } 213 214 template <> 215 double WorkerDataArray<double>::uninitialized() { 216 return -1.0; 217 } 218 219 template <class T> 220 void WorkerDataArray<T>::reset() { 221 for (uint i = 0; i < _length; i++) { 222 _data[i] = WorkerDataArray<T>::uninitialized(); 223 } 224 if (_thread_work_items != NULL) { 225 _thread_work_items->reset(); 226 } 227 } 228 229 template <class T> 230 void WorkerDataArray<T>::verify(uint active_threads) { 231 if (!_enabled) { 232 return; 233 } 234 235 assert(active_threads <= _length, "Wrong number of active threads"); 236 for (uint i = 0; i < active_threads; i++) { 237 assert(_data[i] != WorkerDataArray<T>::uninitialized(), 238 err_msg("Invalid data for worker %u in '%s'", i, _title)); 239 } 240 if (_thread_work_items != NULL) { 241 _thread_work_items->verify(active_threads); 242 } 243 } 244 245 #endif 246 247 G1GCPhaseTimes::G1GCPhaseTimes(uint max_gc_threads) : 248 _max_gc_threads(max_gc_threads) 249 { 250 assert(max_gc_threads > 0, "Must have some GC threads"); 251 252 _gc_par_phases[GCWorkerStart] = new WorkerDataArray<double>(max_gc_threads, "GC Worker Start (ms)", false, G1Log::LevelFiner, 2); 253 _gc_par_phases[ExtRootScan] = new WorkerDataArray<double>(max_gc_threads, "Ext Root Scanning (ms)", true, G1Log::LevelFiner, 2); 254 255 // Root scanning phases 256 _gc_par_phases[ThreadRoots] = new WorkerDataArray<double>(max_gc_threads, "Thread Roots (ms)", true, G1Log::LevelFinest, 3); 257 _gc_par_phases[StringTableRoots] = new WorkerDataArray<double>(max_gc_threads, "StringTable Roots (ms)", true, G1Log::LevelFinest, 3); 258 _gc_par_phases[UniverseRoots] = new WorkerDataArray<double>(max_gc_threads, "Universe Roots (ms)", true, G1Log::LevelFinest, 3); 259 _gc_par_phases[JNIRoots] = new WorkerDataArray<double>(max_gc_threads, "JNI Handles Roots (ms)", true, G1Log::LevelFinest, 3); 260 _gc_par_phases[ObjectSynchronizerRoots] = new WorkerDataArray<double>(max_gc_threads, "ObjectSynchronizer Roots (ms)", true, G1Log::LevelFinest, 3); 261 _gc_par_phases[FlatProfilerRoots] = new WorkerDataArray<double>(max_gc_threads, "FlatProfiler Roots (ms)", true, G1Log::LevelFinest, 3); 262 _gc_par_phases[ManagementRoots] = new WorkerDataArray<double>(max_gc_threads, "Management Roots (ms)", true, G1Log::LevelFinest, 3); 263 _gc_par_phases[SystemDictionaryRoots] = new WorkerDataArray<double>(max_gc_threads, "SystemDictionary Roots (ms)", true, G1Log::LevelFinest, 3); 264 _gc_par_phases[CLDGRoots] = new WorkerDataArray<double>(max_gc_threads, "CLDG Roots (ms)", true, G1Log::LevelFinest, 3); 265 _gc_par_phases[JVMTIRoots] = new WorkerDataArray<double>(max_gc_threads, "JVMTI Roots (ms)", true, G1Log::LevelFinest, 3); 266 _gc_par_phases[CMRefRoots] = new WorkerDataArray<double>(max_gc_threads, "CM RefProcessor Roots (ms)", true, G1Log::LevelFinest, 3); 267 _gc_par_phases[WaitForStrongCLD] = new WorkerDataArray<double>(max_gc_threads, "Wait For Strong CLD (ms)", true, G1Log::LevelFinest, 3); 268 _gc_par_phases[WeakCLDRoots] = new WorkerDataArray<double>(max_gc_threads, "Weak CLD Roots (ms)", true, G1Log::LevelFinest, 3); 269 _gc_par_phases[SATBFiltering] = new WorkerDataArray<double>(max_gc_threads, "SATB Filtering (ms)", true, G1Log::LevelFinest, 3); 270 271 _gc_par_phases[UpdateRS] = new WorkerDataArray<double>(max_gc_threads, "Update RS (ms)", true, G1Log::LevelFiner, 2); 272 _gc_par_phases[ScanRS] = new WorkerDataArray<double>(max_gc_threads, "Scan RS (ms)", true, G1Log::LevelFiner, 2); 273 _gc_par_phases[CodeRoots] = new WorkerDataArray<double>(max_gc_threads, "Code Root Scanning (ms)", true, G1Log::LevelFiner, 2); 274 _gc_par_phases[ObjCopy] = new WorkerDataArray<double>(max_gc_threads, "Object Copy (ms)", true, G1Log::LevelFiner, 2); 275 _gc_par_phases[Termination] = new WorkerDataArray<double>(max_gc_threads, "Termination (ms)", true, G1Log::LevelFiner, 2); 276 _gc_par_phases[GCWorkerTotal] = new WorkerDataArray<double>(max_gc_threads, "GC Worker Total (ms)", true, G1Log::LevelFiner, 2); 277 _gc_par_phases[GCWorkerEnd] = new WorkerDataArray<double>(max_gc_threads, "GC Worker End (ms)", false, G1Log::LevelFiner, 2); 278 _gc_par_phases[Other] = new WorkerDataArray<double>(max_gc_threads, "GC Worker Other (ms)", true, G1Log::LevelFiner, 2); 279 280 _update_rs_processed_buffers = new WorkerDataArray<size_t>(max_gc_threads, "Processed Buffers", true, G1Log::LevelFiner, 3); 281 _gc_par_phases[UpdateRS]->link_thread_work_items(_update_rs_processed_buffers); 282 283 _termination_attempts = new WorkerDataArray<size_t>(max_gc_threads, "Termination Attempts", true, G1Log::LevelFinest, 3); 284 _gc_par_phases[Termination]->link_thread_work_items(_termination_attempts); 285 286 _gc_par_phases[StringDedupQueueFixup] = new WorkerDataArray<double>(max_gc_threads, "Queue Fixup (ms)", true, G1Log::LevelFiner, 2); 287 _gc_par_phases[StringDedupTableFixup] = new WorkerDataArray<double>(max_gc_threads, "Table Fixup (ms)", true, G1Log::LevelFiner, 2); 288 289 _gc_par_phases[RedirtyCards] = new WorkerDataArray<double>(max_gc_threads, "Parallel Redirty", true, G1Log::LevelFinest, 3); 290 _redirtied_cards = new WorkerDataArray<size_t>(max_gc_threads, "Redirtied Cards", true, G1Log::LevelFinest, 3); 291 _gc_par_phases[RedirtyCards]->link_thread_work_items(_redirtied_cards); 292 } 293 294 void G1GCPhaseTimes::note_gc_start(uint active_gc_threads, bool mark_in_progress) { 295 assert(active_gc_threads > 0, "The number of threads must be > 0"); 296 assert(active_gc_threads <= _max_gc_threads, "The number of active threads must be <= the max number of threads"); 297 _active_gc_threads = active_gc_threads; 298 299 for (int i = 0; i < GCParPhasesSentinel; i++) { 300 _gc_par_phases[i]->reset(); 301 } 302 303 _gc_par_phases[StringDedupQueueFixup]->set_enabled(G1StringDedup::is_enabled()); 304 _gc_par_phases[StringDedupTableFixup]->set_enabled(G1StringDedup::is_enabled()); 305 } 306 307 void G1GCPhaseTimes::note_gc_end() { 308 for (uint i = 0; i < _active_gc_threads; i++) { 309 double worker_time = _gc_par_phases[GCWorkerEnd]->get(i) - _gc_par_phases[GCWorkerStart]->get(i); 310 record_time_secs(GCWorkerTotal, i , worker_time); 311 312 double worker_known_time = 313 _gc_par_phases[ExtRootScan]->get(i) + 314 _gc_par_phases[SATBFiltering]->get(i) + 315 _gc_par_phases[UpdateRS]->get(i) + 316 _gc_par_phases[ScanRS]->get(i) + 317 _gc_par_phases[CodeRoots]->get(i) + 318 _gc_par_phases[ObjCopy]->get(i) + 319 _gc_par_phases[Termination]->get(i); 320 321 record_time_secs(Other, i, worker_time - worker_known_time); 322 } 323 324 for (int i = 0; i < GCParPhasesSentinel; i++) { 325 _gc_par_phases[i]->verify(_active_gc_threads); 326 } 327 } 328 329 void G1GCPhaseTimes::print_stats(int level, const char* str, double value) { 330 LineBuffer(level).append_and_print_cr("[%s: %.1lf ms]", str, value); 331 } 332 333 void G1GCPhaseTimes::print_stats(int level, const char* str, size_t value) { 334 LineBuffer(level).append_and_print_cr("[%s: "SIZE_FORMAT"]", str, value); 335 } 336 337 void G1GCPhaseTimes::print_stats(int level, const char* str, double value, uint workers) { 338 LineBuffer(level).append_and_print_cr("[%s: %.1lf ms, GC Workers: %u]", str, value, workers); 339 } 340 341 double G1GCPhaseTimes::accounted_time_ms() { 342 // Subtract the root region scanning wait time. It's initialized to 343 // zero at the start of the pause. 344 double misc_time_ms = _root_region_scan_wait_time_ms; 345 346 misc_time_ms += _cur_collection_par_time_ms; 347 348 // Now subtract the time taken to fix up roots in generated code 349 misc_time_ms += _cur_collection_code_root_fixup_time_ms; 350 351 // Strong code root purge time 352 misc_time_ms += _cur_strong_code_root_purge_time_ms; 353 354 if (G1StringDedup::is_enabled()) { 355 // String dedup fixup time 356 misc_time_ms += _cur_string_dedup_fixup_time_ms; 357 } 358 359 // Subtract the time taken to clean the card table from the 360 // current value of "other time" 361 misc_time_ms += _cur_clear_ct_time_ms; 362 363 return misc_time_ms; 364 } 365 366 // record the time a phase took in seconds 367 void G1GCPhaseTimes::record_time_secs(GCParPhases phase, uint worker_i, double secs) { 368 _gc_par_phases[phase]->set(worker_i, secs); 369 } 370 371 // add a number of seconds to a phase 372 void G1GCPhaseTimes::add_time_secs(GCParPhases phase, uint worker_i, double secs) { 373 _gc_par_phases[phase]->add(worker_i, secs); 374 } 375 376 void G1GCPhaseTimes::record_thread_work_item(GCParPhases phase, uint worker_i, size_t count) { 377 _gc_par_phases[phase]->set_thread_work_item(worker_i, count); 378 } 379 380 // return the average time for a phase in milliseconds 381 double G1GCPhaseTimes::average_time_ms(GCParPhases phase) { 382 return _gc_par_phases[phase]->average(_active_gc_threads) * 1000.0; 383 } 384 385 double G1GCPhaseTimes::get_time_ms(GCParPhases phase, uint worker_i) { 386 return _gc_par_phases[phase]->get(worker_i) * 1000.0; 387 } 388 389 double G1GCPhaseTimes::sum_time_ms(GCParPhases phase) { 390 return _gc_par_phases[phase]->sum(_active_gc_threads) * 1000.0; 391 } 392 393 double G1GCPhaseTimes::min_time_ms(GCParPhases phase) { 394 return _gc_par_phases[phase]->minimum(_active_gc_threads) * 1000.0; 395 } 396 397 double G1GCPhaseTimes::max_time_ms(GCParPhases phase) { 398 return _gc_par_phases[phase]->maximum(_active_gc_threads) * 1000.0; 399 } 400 401 size_t G1GCPhaseTimes::get_thread_work_item(GCParPhases phase, uint worker_i) { 402 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); 403 return _gc_par_phases[phase]->thread_work_items()->get(worker_i); 404 } 405 406 size_t G1GCPhaseTimes::sum_thread_work_items(GCParPhases phase) { 407 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); 408 return _gc_par_phases[phase]->thread_work_items()->sum(_active_gc_threads); 409 } 410 411 double G1GCPhaseTimes::average_thread_work_items(GCParPhases phase) { 412 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); 413 return _gc_par_phases[phase]->thread_work_items()->average(_active_gc_threads); 414 } 415 416 size_t G1GCPhaseTimes::min_thread_work_items(GCParPhases phase) { 417 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); 418 return _gc_par_phases[phase]->thread_work_items()->minimum(_active_gc_threads); 419 } 420 421 size_t G1GCPhaseTimes::max_thread_work_items(GCParPhases phase) { 422 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); 423 return _gc_par_phases[phase]->thread_work_items()->maximum(_active_gc_threads); 424 } 425 426 class G1GCParPhasePrinter : public StackObj { 427 G1GCPhaseTimes* _phase_times; 428 public: 429 G1GCParPhasePrinter(G1GCPhaseTimes* phase_times) : _phase_times(phase_times) {} 430 431 void print(G1GCPhaseTimes::GCParPhases phase_id) { 432 WorkerDataArray<double>* phase = _phase_times->_gc_par_phases[phase_id]; 433 434 if (phase->_log_level > G1Log::level() || !phase->_enabled) { 435 return; 436 } 437 438 if (phase->_length == 1) { 439 print_single_length(phase_id, phase); 440 } else { 441 print_multi_length(phase_id, phase); 442 } 443 } 444 445 private: 446 447 void print_single_length(G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray<double>* phase) { 448 // No need for min, max, average and sum for only one worker 449 LineBuffer buf(phase->_indent_level); 450 buf.append_and_print_cr("[%s: %.1lf]", phase->_title, _phase_times->get_time_ms(phase_id, 0)); 451 452 if (phase->_thread_work_items != NULL) { 453 LineBuffer buf2(phase->_thread_work_items->_indent_level); 454 buf2.append_and_print_cr("[%s: "SIZE_FORMAT"]", phase->_thread_work_items->_title, _phase_times->sum_thread_work_items(phase_id)); 455 } 456 } 457 458 void print_time_values(LineBuffer& buf, G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray<double>* phase) { 459 uint active_length = _phase_times->_active_gc_threads; 460 for (uint i = 0; i < active_length; ++i) { 461 buf.append(" %.1lf", _phase_times->get_time_ms(phase_id, i)); 462 } 463 buf.print_cr(); 464 } 465 466 void print_count_values(LineBuffer& buf, G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray<size_t>* thread_work_items) { 467 uint active_length = _phase_times->_active_gc_threads; 468 for (uint i = 0; i < active_length; ++i) { 469 buf.append(" " SIZE_FORMAT, _phase_times->get_thread_work_item(phase_id, i)); 470 } 471 buf.print_cr(); 472 } 473 474 void print_thread_work_items(G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray<size_t>* thread_work_items) { 475 LineBuffer buf(thread_work_items->_indent_level); 476 buf.append("[%s:", thread_work_items->_title); 477 478 if (G1Log::finest()) { 479 print_count_values(buf, phase_id, thread_work_items); 480 } 481 482 assert(thread_work_items->_print_sum, err_msg("%s does not have print sum true even though it is a count", thread_work_items->_title)); 483 484 buf.append_and_print_cr(" Min: " SIZE_FORMAT ", Avg: %.1lf, Max: " SIZE_FORMAT ", Diff: " SIZE_FORMAT ", Sum: " SIZE_FORMAT "]", 485 _phase_times->min_thread_work_items(phase_id), _phase_times->average_thread_work_items(phase_id), _phase_times->max_thread_work_items(phase_id), 486 _phase_times->max_thread_work_items(phase_id) - _phase_times->min_thread_work_items(phase_id), _phase_times->sum_thread_work_items(phase_id)); 487 } 488 489 void print_multi_length(G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray<double>* phase) { 490 LineBuffer buf(phase->_indent_level); 491 buf.append("[%s:", phase->_title); 492 493 if (G1Log::finest()) { 494 print_time_values(buf, phase_id, phase); 495 } 496 497 buf.append(" Min: %.1lf, Avg: %.1lf, Max: %.1lf, Diff: %.1lf", 498 _phase_times->min_time_ms(phase_id), _phase_times->average_time_ms(phase_id), _phase_times->max_time_ms(phase_id), 499 _phase_times->max_time_ms(phase_id) - _phase_times->min_time_ms(phase_id)); 500 501 if (phase->_print_sum) { 502 // for things like the start and end times the sum is not 503 // that relevant 504 buf.append(", Sum: %.1lf", _phase_times->sum_time_ms(phase_id)); 505 } 506 507 buf.append_and_print_cr("]"); 508 509 if (phase->_thread_work_items != NULL) { 510 print_thread_work_items(phase_id, phase->_thread_work_items); 511 } 512 } 513 }; 514 515 void G1GCPhaseTimes::print(double pause_time_sec) { 516 G1GCParPhasePrinter par_phase_printer(this); 517 518 if (_root_region_scan_wait_time_ms > 0.0) { 519 print_stats(1, "Root Region Scan Waiting", _root_region_scan_wait_time_ms); 520 } 521 522 print_stats(1, "Parallel Time", _cur_collection_par_time_ms, _active_gc_threads); 523 for (int i = 0; i <= GCMainParPhasesLast; i++) { 524 par_phase_printer.print((GCParPhases) i); 525 } 526 527 print_stats(1, "Code Root Fixup", _cur_collection_code_root_fixup_time_ms); 528 print_stats(1, "Code Root Purge", _cur_strong_code_root_purge_time_ms); 529 if (G1StringDedup::is_enabled()) { 530 print_stats(1, "String Dedup Fixup", _cur_string_dedup_fixup_time_ms, _active_gc_threads); 531 for (int i = StringDedupPhasesFirst; i <= StringDedupPhasesLast; i++) { 532 par_phase_printer.print((GCParPhases) i); 533 } 534 } 535 print_stats(1, "Clear CT", _cur_clear_ct_time_ms); 536 double misc_time_ms = pause_time_sec * MILLIUNITS - accounted_time_ms(); 537 print_stats(1, "Other", misc_time_ms); 538 if (_cur_verify_before_time_ms > 0.0) { 539 print_stats(2, "Verify Before", _cur_verify_before_time_ms); 540 } 541 if (G1CollectedHeap::heap()->evacuation_failed()) { 542 double evac_fail_handling = _cur_evac_fail_recalc_used + _cur_evac_fail_remove_self_forwards + 543 _cur_evac_fail_restore_remsets; 544 print_stats(2, "Evacuation Failure", evac_fail_handling); 545 if (G1Log::finest()) { 546 print_stats(3, "Recalculate Used", _cur_evac_fail_recalc_used); 547 print_stats(3, "Remove Self Forwards", _cur_evac_fail_remove_self_forwards); 548 print_stats(3, "Restore RemSet", _cur_evac_fail_restore_remsets); 549 } 550 } 551 print_stats(2, "Choose CSet", 552 (_recorded_young_cset_choice_time_ms + 553 _recorded_non_young_cset_choice_time_ms)); 554 print_stats(2, "Ref Proc", _cur_ref_proc_time_ms); 555 print_stats(2, "Ref Enq", _cur_ref_enq_time_ms); 556 print_stats(2, "Redirty Cards", _recorded_redirty_logged_cards_time_ms); 557 par_phase_printer.print(RedirtyCards); 558 if (G1EagerReclaimHumongousObjects) { 559 print_stats(2, "Humongous Register", _cur_fast_reclaim_humongous_register_time_ms); 560 if (G1Log::finest()) { 561 print_stats(3, "Humongous Total", _cur_fast_reclaim_humongous_total); 562 print_stats(3, "Humongous Candidate", _cur_fast_reclaim_humongous_candidates); 563 } 564 print_stats(2, "Humongous Reclaim", _cur_fast_reclaim_humongous_time_ms); 565 if (G1Log::finest()) { 566 print_stats(3, "Humongous Reclaimed", _cur_fast_reclaim_humongous_reclaimed); 567 } 568 } 569 print_stats(2, "Free CSet", 570 (_recorded_young_free_cset_time_ms + 571 _recorded_non_young_free_cset_time_ms)); 572 if (G1Log::finest()) { 573 print_stats(3, "Young Free CSet", _recorded_young_free_cset_time_ms); 574 print_stats(3, "Non-Young Free CSet", _recorded_non_young_free_cset_time_ms); 575 } 576 if (_cur_verify_after_time_ms > 0.0) { 577 print_stats(2, "Verify After", _cur_verify_after_time_ms); 578 } 579 } 580 581 G1GCParPhaseTimesTracker::G1GCParPhaseTimesTracker(G1GCPhaseTimes* phase_times, G1GCPhaseTimes::GCParPhases phase, uint worker_id) : 582 _phase_times(phase_times), _phase(phase), _worker_id(worker_id) { 583 if (_phase_times != NULL) { 584 _start_time = os::elapsedTime(); 585 } 586 } 587 588 G1GCParPhaseTimesTracker::~G1GCParPhaseTimesTracker() { 589 if (_phase_times != NULL) { 590 _phase_times->record_time_secs(_phase, _worker_id, os::elapsedTime() - _start_time); 591 } 592 } 593