src/share/vm/gc_implementation/g1/g1GCPhaseTimes.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7218
6948da6d7c13
parent 6876
710a3c8b516e
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25
aoqi@0 26 #include "precompiled.hpp"
aoqi@0 27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
aoqi@0 28 #include "gc_implementation/g1/g1GCPhaseTimes.hpp"
aoqi@0 29 #include "gc_implementation/g1/g1Log.hpp"
aoqi@0 30 #include "gc_implementation/g1/g1StringDedup.hpp"
aoqi@0 31
aoqi@0 32 // Helper class for avoiding interleaved logging
aoqi@0 33 class LineBuffer: public StackObj {
aoqi@0 34
aoqi@0 35 private:
aoqi@0 36 static const int BUFFER_LEN = 1024;
aoqi@0 37 static const int INDENT_CHARS = 3;
aoqi@0 38 char _buffer[BUFFER_LEN];
aoqi@0 39 int _indent_level;
aoqi@0 40 int _cur;
aoqi@0 41
aoqi@0 42 void vappend(const char* format, va_list ap) ATTRIBUTE_PRINTF(2, 0) {
aoqi@0 43 int res = vsnprintf(&_buffer[_cur], BUFFER_LEN - _cur, format, ap);
aoqi@0 44 if (res != -1) {
aoqi@0 45 _cur += res;
aoqi@0 46 } else {
aoqi@0 47 DEBUG_ONLY(warning("buffer too small in LineBuffer");)
aoqi@0 48 _buffer[BUFFER_LEN -1] = 0;
aoqi@0 49 _cur = BUFFER_LEN; // vsnprintf above should not add to _buffer if we are called again
aoqi@0 50 }
aoqi@0 51 }
aoqi@0 52
aoqi@0 53 public:
aoqi@0 54 explicit LineBuffer(int indent_level): _indent_level(indent_level), _cur(0) {
aoqi@0 55 for (; (_cur < BUFFER_LEN && _cur < (_indent_level * INDENT_CHARS)); _cur++) {
aoqi@0 56 _buffer[_cur] = ' ';
aoqi@0 57 }
aoqi@0 58 }
aoqi@0 59
aoqi@0 60 #ifndef PRODUCT
aoqi@0 61 ~LineBuffer() {
aoqi@0 62 assert(_cur == _indent_level * INDENT_CHARS, "pending data in buffer - append_and_print_cr() not called?");
aoqi@0 63 }
aoqi@0 64 #endif
aoqi@0 65
aoqi@0 66 void append(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) {
aoqi@0 67 va_list ap;
aoqi@0 68 va_start(ap, format);
aoqi@0 69 vappend(format, ap);
aoqi@0 70 va_end(ap);
aoqi@0 71 }
aoqi@0 72
aoqi@0 73 void append_and_print_cr(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) {
aoqi@0 74 va_list ap;
aoqi@0 75 va_start(ap, format);
aoqi@0 76 vappend(format, ap);
aoqi@0 77 va_end(ap);
aoqi@0 78 gclog_or_tty->print_cr("%s", _buffer);
aoqi@0 79 _cur = _indent_level * INDENT_CHARS;
aoqi@0 80 }
aoqi@0 81 };
aoqi@0 82
aoqi@0 83 PRAGMA_DIAG_PUSH
aoqi@0 84 PRAGMA_FORMAT_NONLITERAL_IGNORED
aoqi@0 85 template <class T>
aoqi@0 86 void WorkerDataArray<T>::print(int level, const char* title) {
aoqi@0 87 if (_length == 1) {
aoqi@0 88 // No need for min, max, average and sum for only one worker
aoqi@0 89 LineBuffer buf(level);
aoqi@0 90 buf.append("[%s: ", title);
aoqi@0 91 buf.append(_print_format, _data[0]);
aoqi@0 92 buf.append_and_print_cr("]");
aoqi@0 93 return;
aoqi@0 94 }
aoqi@0 95
aoqi@0 96 T min = _data[0];
aoqi@0 97 T max = _data[0];
aoqi@0 98 T sum = 0;
aoqi@0 99
aoqi@0 100 LineBuffer buf(level);
aoqi@0 101 buf.append("[%s:", title);
aoqi@0 102 for (uint i = 0; i < _length; ++i) {
aoqi@0 103 T val = _data[i];
aoqi@0 104 min = MIN2(val, min);
aoqi@0 105 max = MAX2(val, max);
aoqi@0 106 sum += val;
aoqi@0 107 if (G1Log::finest()) {
aoqi@0 108 buf.append(" ");
aoqi@0 109 buf.append(_print_format, val);
aoqi@0 110 }
aoqi@0 111 }
aoqi@0 112
aoqi@0 113 if (G1Log::finest()) {
aoqi@0 114 buf.append_and_print_cr("%s", "");
aoqi@0 115 }
aoqi@0 116
aoqi@0 117 double avg = (double)sum / (double)_length;
aoqi@0 118 buf.append(" Min: ");
aoqi@0 119 buf.append(_print_format, min);
aoqi@0 120 buf.append(", Avg: ");
aoqi@0 121 buf.append("%.1lf", avg); // Always print average as a double
aoqi@0 122 buf.append(", Max: ");
aoqi@0 123 buf.append(_print_format, max);
aoqi@0 124 buf.append(", Diff: ");
aoqi@0 125 buf.append(_print_format, max - min);
aoqi@0 126 if (_print_sum) {
aoqi@0 127 // for things like the start and end times the sum is not
aoqi@0 128 // that relevant
aoqi@0 129 buf.append(", Sum: ");
aoqi@0 130 buf.append(_print_format, sum);
aoqi@0 131 }
aoqi@0 132 buf.append_and_print_cr("]");
aoqi@0 133 }
aoqi@0 134 PRAGMA_DIAG_POP
aoqi@0 135
aoqi@0 136 #ifndef PRODUCT
aoqi@0 137
aoqi@0 138 template <> const int WorkerDataArray<int>::_uninitialized = -1;
aoqi@0 139 template <> const double WorkerDataArray<double>::_uninitialized = -1.0;
aoqi@0 140 template <> const size_t WorkerDataArray<size_t>::_uninitialized = (size_t)-1;
aoqi@0 141
aoqi@0 142 template <class T>
aoqi@0 143 void WorkerDataArray<T>::reset() {
aoqi@0 144 for (uint i = 0; i < _length; i++) {
aoqi@0 145 _data[i] = (T)_uninitialized;
aoqi@0 146 }
aoqi@0 147 }
aoqi@0 148
aoqi@0 149 template <class T>
aoqi@0 150 void WorkerDataArray<T>::verify() {
aoqi@0 151 for (uint i = 0; i < _length; i++) {
aoqi@0 152 assert(_data[i] != _uninitialized,
aoqi@0 153 err_msg("Invalid data for worker " UINT32_FORMAT ", data: %lf, uninitialized: %lf",
aoqi@0 154 i, (double)_data[i], (double)_uninitialized));
aoqi@0 155 }
aoqi@0 156 }
aoqi@0 157
aoqi@0 158 #endif
aoqi@0 159
aoqi@0 160 G1GCPhaseTimes::G1GCPhaseTimes(uint max_gc_threads) :
aoqi@0 161 _max_gc_threads(max_gc_threads),
aoqi@0 162 _last_gc_worker_start_times_ms(_max_gc_threads, "%.1lf", false),
aoqi@0 163 _last_ext_root_scan_times_ms(_max_gc_threads, "%.1lf"),
aoqi@0 164 _last_satb_filtering_times_ms(_max_gc_threads, "%.1lf"),
aoqi@0 165 _last_update_rs_times_ms(_max_gc_threads, "%.1lf"),
aoqi@0 166 _last_update_rs_processed_buffers(_max_gc_threads, "%d"),
aoqi@0 167 _last_scan_rs_times_ms(_max_gc_threads, "%.1lf"),
aoqi@0 168 _last_strong_code_root_scan_times_ms(_max_gc_threads, "%.1lf"),
aoqi@0 169 _last_obj_copy_times_ms(_max_gc_threads, "%.1lf"),
aoqi@0 170 _last_termination_times_ms(_max_gc_threads, "%.1lf"),
aoqi@0 171 _last_termination_attempts(_max_gc_threads, SIZE_FORMAT),
aoqi@0 172 _last_gc_worker_end_times_ms(_max_gc_threads, "%.1lf", false),
aoqi@0 173 _last_gc_worker_times_ms(_max_gc_threads, "%.1lf"),
aoqi@0 174 _last_gc_worker_other_times_ms(_max_gc_threads, "%.1lf"),
tschatzl@6930 175 _last_redirty_logged_cards_time_ms(_max_gc_threads, "%.1lf"),
tschatzl@6930 176 _last_redirty_logged_cards_processed_cards(_max_gc_threads, SIZE_FORMAT),
aoqi@0 177 _cur_string_dedup_queue_fixup_worker_times_ms(_max_gc_threads, "%.1lf"),
aoqi@0 178 _cur_string_dedup_table_fixup_worker_times_ms(_max_gc_threads, "%.1lf")
aoqi@0 179 {
aoqi@0 180 assert(max_gc_threads > 0, "Must have some GC threads");
aoqi@0 181 }
aoqi@0 182
aoqi@0 183 void G1GCPhaseTimes::note_gc_start(uint active_gc_threads) {
aoqi@0 184 assert(active_gc_threads > 0, "The number of threads must be > 0");
aoqi@0 185 assert(active_gc_threads <= _max_gc_threads, "The number of active threads must be <= the max nubmer of threads");
aoqi@0 186 _active_gc_threads = active_gc_threads;
aoqi@0 187
aoqi@0 188 _last_gc_worker_start_times_ms.reset();
aoqi@0 189 _last_ext_root_scan_times_ms.reset();
aoqi@0 190 _last_satb_filtering_times_ms.reset();
aoqi@0 191 _last_update_rs_times_ms.reset();
aoqi@0 192 _last_update_rs_processed_buffers.reset();
aoqi@0 193 _last_scan_rs_times_ms.reset();
aoqi@0 194 _last_strong_code_root_scan_times_ms.reset();
aoqi@0 195 _last_obj_copy_times_ms.reset();
aoqi@0 196 _last_termination_times_ms.reset();
aoqi@0 197 _last_termination_attempts.reset();
aoqi@0 198 _last_gc_worker_end_times_ms.reset();
aoqi@0 199 _last_gc_worker_times_ms.reset();
aoqi@0 200 _last_gc_worker_other_times_ms.reset();
tschatzl@6930 201
tschatzl@6930 202 _last_redirty_logged_cards_time_ms.reset();
tschatzl@6930 203 _last_redirty_logged_cards_processed_cards.reset();
tschatzl@6930 204
aoqi@0 205 }
aoqi@0 206
aoqi@0 207 void G1GCPhaseTimes::note_gc_end() {
aoqi@0 208 _last_gc_worker_start_times_ms.verify();
aoqi@0 209 _last_ext_root_scan_times_ms.verify();
aoqi@0 210 _last_satb_filtering_times_ms.verify();
aoqi@0 211 _last_update_rs_times_ms.verify();
aoqi@0 212 _last_update_rs_processed_buffers.verify();
aoqi@0 213 _last_scan_rs_times_ms.verify();
aoqi@0 214 _last_strong_code_root_scan_times_ms.verify();
aoqi@0 215 _last_obj_copy_times_ms.verify();
aoqi@0 216 _last_termination_times_ms.verify();
aoqi@0 217 _last_termination_attempts.verify();
aoqi@0 218 _last_gc_worker_end_times_ms.verify();
aoqi@0 219
aoqi@0 220 for (uint i = 0; i < _active_gc_threads; i++) {
aoqi@0 221 double worker_time = _last_gc_worker_end_times_ms.get(i) - _last_gc_worker_start_times_ms.get(i);
aoqi@0 222 _last_gc_worker_times_ms.set(i, worker_time);
aoqi@0 223
aoqi@0 224 double worker_known_time = _last_ext_root_scan_times_ms.get(i) +
aoqi@0 225 _last_satb_filtering_times_ms.get(i) +
aoqi@0 226 _last_update_rs_times_ms.get(i) +
aoqi@0 227 _last_scan_rs_times_ms.get(i) +
aoqi@0 228 _last_strong_code_root_scan_times_ms.get(i) +
aoqi@0 229 _last_obj_copy_times_ms.get(i) +
aoqi@0 230 _last_termination_times_ms.get(i);
aoqi@0 231
aoqi@0 232 double worker_other_time = worker_time - worker_known_time;
aoqi@0 233 _last_gc_worker_other_times_ms.set(i, worker_other_time);
aoqi@0 234 }
aoqi@0 235
aoqi@0 236 _last_gc_worker_times_ms.verify();
aoqi@0 237 _last_gc_worker_other_times_ms.verify();
tschatzl@6930 238
tschatzl@7218 239 _last_redirty_logged_cards_time_ms.verify();
tschatzl@7218 240 _last_redirty_logged_cards_processed_cards.verify();
aoqi@0 241 }
aoqi@0 242
aoqi@0 243 void G1GCPhaseTimes::note_string_dedup_fixup_start() {
aoqi@0 244 _cur_string_dedup_queue_fixup_worker_times_ms.reset();
aoqi@0 245 _cur_string_dedup_table_fixup_worker_times_ms.reset();
aoqi@0 246 }
aoqi@0 247
aoqi@0 248 void G1GCPhaseTimes::note_string_dedup_fixup_end() {
aoqi@0 249 _cur_string_dedup_queue_fixup_worker_times_ms.verify();
aoqi@0 250 _cur_string_dedup_table_fixup_worker_times_ms.verify();
aoqi@0 251 }
aoqi@0 252
aoqi@0 253 void G1GCPhaseTimes::print_stats(int level, const char* str, double value) {
aoqi@0 254 LineBuffer(level).append_and_print_cr("[%s: %.1lf ms]", str, value);
aoqi@0 255 }
aoqi@0 256
tschatzl@7010 257 void G1GCPhaseTimes::print_stats(int level, const char* str, size_t value) {
tschatzl@7010 258 LineBuffer(level).append_and_print_cr("[%s: "SIZE_FORMAT"]", str, value);
tschatzl@7010 259 }
tschatzl@7010 260
aoqi@0 261 void G1GCPhaseTimes::print_stats(int level, const char* str, double value, uint workers) {
aoqi@0 262 LineBuffer(level).append_and_print_cr("[%s: %.1lf ms, GC Workers: " UINT32_FORMAT "]", str, value, workers);
aoqi@0 263 }
aoqi@0 264
aoqi@0 265 double G1GCPhaseTimes::accounted_time_ms() {
aoqi@0 266 // Subtract the root region scanning wait time. It's initialized to
aoqi@0 267 // zero at the start of the pause.
aoqi@0 268 double misc_time_ms = _root_region_scan_wait_time_ms;
aoqi@0 269
aoqi@0 270 misc_time_ms += _cur_collection_par_time_ms;
aoqi@0 271
aoqi@0 272 // Now subtract the time taken to fix up roots in generated code
aoqi@0 273 misc_time_ms += _cur_collection_code_root_fixup_time_ms;
aoqi@0 274
aoqi@0 275 // Strong code root purge time
aoqi@0 276 misc_time_ms += _cur_strong_code_root_purge_time_ms;
aoqi@0 277
aoqi@0 278 if (G1StringDedup::is_enabled()) {
aoqi@0 279 // String dedup fixup time
aoqi@0 280 misc_time_ms += _cur_string_dedup_fixup_time_ms;
aoqi@0 281 }
aoqi@0 282
aoqi@0 283 // Subtract the time taken to clean the card table from the
aoqi@0 284 // current value of "other time"
aoqi@0 285 misc_time_ms += _cur_clear_ct_time_ms;
aoqi@0 286
aoqi@0 287 return misc_time_ms;
aoqi@0 288 }
aoqi@0 289
aoqi@0 290 void G1GCPhaseTimes::print(double pause_time_sec) {
aoqi@0 291 if (_root_region_scan_wait_time_ms > 0.0) {
aoqi@0 292 print_stats(1, "Root Region Scan Waiting", _root_region_scan_wait_time_ms);
aoqi@0 293 }
aoqi@0 294 if (G1CollectedHeap::use_parallel_gc_threads()) {
aoqi@0 295 print_stats(1, "Parallel Time", _cur_collection_par_time_ms, _active_gc_threads);
aoqi@0 296 _last_gc_worker_start_times_ms.print(2, "GC Worker Start (ms)");
aoqi@0 297 _last_ext_root_scan_times_ms.print(2, "Ext Root Scanning (ms)");
aoqi@0 298 if (_last_satb_filtering_times_ms.sum() > 0.0) {
aoqi@0 299 _last_satb_filtering_times_ms.print(2, "SATB Filtering (ms)");
aoqi@0 300 }
aoqi@0 301 _last_update_rs_times_ms.print(2, "Update RS (ms)");
aoqi@0 302 _last_update_rs_processed_buffers.print(3, "Processed Buffers");
aoqi@0 303 _last_scan_rs_times_ms.print(2, "Scan RS (ms)");
aoqi@0 304 _last_strong_code_root_scan_times_ms.print(2, "Code Root Scanning (ms)");
aoqi@0 305 _last_obj_copy_times_ms.print(2, "Object Copy (ms)");
aoqi@0 306 _last_termination_times_ms.print(2, "Termination (ms)");
aoqi@0 307 if (G1Log::finest()) {
aoqi@0 308 _last_termination_attempts.print(3, "Termination Attempts");
aoqi@0 309 }
aoqi@0 310 _last_gc_worker_other_times_ms.print(2, "GC Worker Other (ms)");
aoqi@0 311 _last_gc_worker_times_ms.print(2, "GC Worker Total (ms)");
aoqi@0 312 _last_gc_worker_end_times_ms.print(2, "GC Worker End (ms)");
aoqi@0 313 } else {
aoqi@0 314 _last_ext_root_scan_times_ms.print(1, "Ext Root Scanning (ms)");
aoqi@0 315 if (_last_satb_filtering_times_ms.sum() > 0.0) {
aoqi@0 316 _last_satb_filtering_times_ms.print(1, "SATB Filtering (ms)");
aoqi@0 317 }
aoqi@0 318 _last_update_rs_times_ms.print(1, "Update RS (ms)");
aoqi@0 319 _last_update_rs_processed_buffers.print(2, "Processed Buffers");
aoqi@0 320 _last_scan_rs_times_ms.print(1, "Scan RS (ms)");
aoqi@0 321 _last_strong_code_root_scan_times_ms.print(1, "Code Root Scanning (ms)");
aoqi@0 322 _last_obj_copy_times_ms.print(1, "Object Copy (ms)");
aoqi@0 323 }
aoqi@0 324 print_stats(1, "Code Root Fixup", _cur_collection_code_root_fixup_time_ms);
aoqi@0 325 print_stats(1, "Code Root Purge", _cur_strong_code_root_purge_time_ms);
aoqi@0 326 if (G1StringDedup::is_enabled()) {
aoqi@0 327 print_stats(1, "String Dedup Fixup", _cur_string_dedup_fixup_time_ms, _active_gc_threads);
aoqi@0 328 _cur_string_dedup_queue_fixup_worker_times_ms.print(2, "Queue Fixup (ms)");
aoqi@0 329 _cur_string_dedup_table_fixup_worker_times_ms.print(2, "Table Fixup (ms)");
aoqi@0 330 }
aoqi@0 331 print_stats(1, "Clear CT", _cur_clear_ct_time_ms);
aoqi@0 332 double misc_time_ms = pause_time_sec * MILLIUNITS - accounted_time_ms();
aoqi@0 333 print_stats(1, "Other", misc_time_ms);
aoqi@0 334 if (_cur_verify_before_time_ms > 0.0) {
aoqi@0 335 print_stats(2, "Verify Before", _cur_verify_before_time_ms);
aoqi@0 336 }
aoqi@0 337 if (G1CollectedHeap::heap()->evacuation_failed()) {
aoqi@0 338 double evac_fail_handling = _cur_evac_fail_recalc_used + _cur_evac_fail_remove_self_forwards +
aoqi@0 339 _cur_evac_fail_restore_remsets;
aoqi@0 340 print_stats(2, "Evacuation Failure", evac_fail_handling);
aoqi@0 341 if (G1Log::finest()) {
aoqi@0 342 print_stats(3, "Recalculate Used", _cur_evac_fail_recalc_used);
aoqi@0 343 print_stats(3, "Remove Self Forwards", _cur_evac_fail_remove_self_forwards);
aoqi@0 344 print_stats(3, "Restore RemSet", _cur_evac_fail_restore_remsets);
aoqi@0 345 }
aoqi@0 346 }
aoqi@0 347 print_stats(2, "Choose CSet",
aoqi@0 348 (_recorded_young_cset_choice_time_ms +
aoqi@0 349 _recorded_non_young_cset_choice_time_ms));
aoqi@0 350 print_stats(2, "Ref Proc", _cur_ref_proc_time_ms);
aoqi@0 351 print_stats(2, "Ref Enq", _cur_ref_enq_time_ms);
tschatzl@7218 352 print_stats(2, "Redirty Cards", _recorded_redirty_logged_cards_time_ms);
tschatzl@7218 353 if (G1Log::finest()) {
tschatzl@7218 354 _last_redirty_logged_cards_time_ms.print(3, "Parallel Redirty");
tschatzl@7218 355 _last_redirty_logged_cards_processed_cards.print(3, "Redirtied Cards");
drchase@6680 356 }
tschatzl@7010 357 if (G1ReclaimDeadHumongousObjectsAtYoungGC) {
tschatzl@7010 358 print_stats(2, "Humongous Reclaim", _cur_fast_reclaim_humongous_time_ms);
tschatzl@7010 359 if (G1Log::finest()) {
tschatzl@7010 360 print_stats(3, "Humongous Total", _cur_fast_reclaim_humongous_total);
tschatzl@7010 361 print_stats(3, "Humongous Candidate", _cur_fast_reclaim_humongous_candidates);
tschatzl@7010 362 print_stats(3, "Humongous Reclaimed", _cur_fast_reclaim_humongous_reclaimed);
tschatzl@7010 363 }
aoqi@0 364 }
aoqi@0 365 print_stats(2, "Free CSet",
aoqi@0 366 (_recorded_young_free_cset_time_ms +
aoqi@0 367 _recorded_non_young_free_cset_time_ms));
aoqi@0 368 if (G1Log::finest()) {
aoqi@0 369 print_stats(3, "Young Free CSet", _recorded_young_free_cset_time_ms);
aoqi@0 370 print_stats(3, "Non-Young Free CSet", _recorded_non_young_free_cset_time_ms);
aoqi@0 371 }
aoqi@0 372 if (_cur_verify_after_time_ms > 0.0) {
aoqi@0 373 print_stats(2, "Verify After", _cur_verify_after_time_ms);
aoqi@0 374 }
aoqi@0 375 }

mercurial