g1GCPhaseTimes.hpp 11.8 KB
Newer Older
1
/*
2
 * Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1GCPHASETIMESLOG_HPP
#define SHARE_VM_GC_IMPLEMENTATION_G1_G1GCPHASETIMESLOG_HPP

#include "memory/allocation.hpp"
#include "gc_interface/gcCause.hpp"

31 32 33 34 35 36 37
template <class T>
class WorkerDataArray  : public CHeapObj<mtGC> {
  T*          _data;
  uint        _length;
  const char* _print_format;
  bool        _print_sum;

38 39
  NOT_PRODUCT(static const T _uninitialized;)

40
  // We are caching the sum and average to only have to calculate them once.
S
sla 已提交
41
  // This is not done in an MT-safe way. It is intended to allow single
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
  // threaded code to call sum() and average() multiple times in any order
  // without having to worry about the cost.
  bool   _has_new_data;
  T      _sum;
  double _average;

 public:
  WorkerDataArray(uint length, const char* print_format, bool print_sum = true) :
  _length(length), _print_format(print_format), _print_sum(print_sum), _has_new_data(true) {
    assert(length > 0, "Must have some workers to store data for");
    _data = NEW_C_HEAP_ARRAY(T, _length, mtGC);
  }

  ~WorkerDataArray() {
    FREE_C_HEAP_ARRAY(T, _data, mtGC);
  }

  void set(uint worker_i, T value) {
    assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length));
    assert(_data[worker_i] == (T)-1, err_msg("Overwriting data for worker %d", worker_i));
    _data[worker_i] = value;
    _has_new_data = true;
  }

  T get(uint worker_i) {
    assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length));
    assert(_data[worker_i] != (T)-1, err_msg("No data to add to for worker %d", worker_i));
    return _data[worker_i];
  }

  void add(uint worker_i, T value) {
    assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length));
    assert(_data[worker_i] != (T)-1, err_msg("No data to add to for worker %d", worker_i));
    _data[worker_i] += value;
    _has_new_data = true;
  }

  double average(){
    if (_has_new_data) {
      calculate_totals();
    }
    return _average;
  }

  T sum() {
    if (_has_new_data) {
      calculate_totals();
    }
    return _sum;
  }

  void print(int level, const char* title);

  void reset() PRODUCT_RETURN;
  void verify() PRODUCT_RETURN;

 private:

  void calculate_totals(){
    _sum = (T)0;
    for (uint i = 0; i < _length; ++i) {
      _sum += _data[i];
    }
    _average = (double)_sum / (double)_length;
    _has_new_data = false;
  }
};

J
Merge  
jmasa 已提交
110
class G1GCPhaseTimes : public CHeapObj<mtGC> {
111 112 113 114 115

 private:
  uint _active_gc_threads;
  uint _max_gc_threads;

116 117 118 119 120 121
  WorkerDataArray<double> _last_gc_worker_start_times_ms;
  WorkerDataArray<double> _last_ext_root_scan_times_ms;
  WorkerDataArray<double> _last_satb_filtering_times_ms;
  WorkerDataArray<double> _last_update_rs_times_ms;
  WorkerDataArray<int>    _last_update_rs_processed_buffers;
  WorkerDataArray<double> _last_scan_rs_times_ms;
J
johnc 已提交
122
  WorkerDataArray<double> _last_strong_code_root_scan_times_ms;
123 124 125 126 127 128
  WorkerDataArray<double> _last_obj_copy_times_ms;
  WorkerDataArray<double> _last_termination_times_ms;
  WorkerDataArray<size_t> _last_termination_attempts;
  WorkerDataArray<double> _last_gc_worker_end_times_ms;
  WorkerDataArray<double> _last_gc_worker_times_ms;
  WorkerDataArray<double> _last_gc_worker_other_times_ms;
129 130 131

  double _cur_collection_par_time_ms;
  double _cur_collection_code_root_fixup_time_ms;
132
  double _cur_strong_code_root_purge_time_ms;
133

134 135 136 137
  double _cur_evac_fail_recalc_used;
  double _cur_evac_fail_restore_remsets;
  double _cur_evac_fail_remove_self_forwards;

P
pliden 已提交
138 139 140 141
  double                  _cur_string_dedup_fixup_time_ms;
  WorkerDataArray<double> _cur_string_dedup_queue_fixup_worker_times_ms;
  WorkerDataArray<double> _cur_string_dedup_table_fixup_worker_times_ms;

142 143 144 145 146 147 148 149 150 151
  double _cur_clear_ct_time_ms;
  double _cur_ref_proc_time_ms;
  double _cur_ref_enq_time_ms;

  double _cur_collection_start_sec;
  double _root_region_scan_wait_time_ms;

  double _recorded_young_cset_choice_time_ms;
  double _recorded_non_young_cset_choice_time_ms;

152 153
  WorkerDataArray<double> _last_redirty_logged_cards_time_ms;
  WorkerDataArray<size_t> _last_redirty_logged_cards_processed_cards;
154 155
  double _recorded_redirty_logged_cards_time_ms;

156 157 158
  double _recorded_young_free_cset_time_ms;
  double _recorded_non_young_free_cset_time_ms;

159 160 161 162 163
  double _cur_fast_reclaim_humongous_time_ms;
  size_t _cur_fast_reclaim_humongous_total;
  size_t _cur_fast_reclaim_humongous_candidates;
  size_t _cur_fast_reclaim_humongous_reclaimed;

164 165 166 167 168
  double _cur_verify_before_time_ms;
  double _cur_verify_after_time_ms;

  // Helper methods for detailed logging
  void print_stats(int level, const char* str, double value);
169
  void print_stats(int level, const char* str, size_t value);
170
  void print_stats(int level, const char* str, double value, uint workers);
171 172 173

 public:
  G1GCPhaseTimes(uint max_gc_threads);
174 175 176
  void note_gc_start(uint active_gc_threads);
  void note_gc_end();
  void print(double pause_time_sec);
177 178

  void record_gc_worker_start_time(uint worker_i, double ms) {
179
    _last_gc_worker_start_times_ms.set(worker_i, ms);
180 181 182
  }

  void record_ext_root_scan_time(uint worker_i, double ms) {
183
    _last_ext_root_scan_times_ms.set(worker_i, ms);
184 185 186
  }

  void record_satb_filtering_time(uint worker_i, double ms) {
187
    _last_satb_filtering_times_ms.set(worker_i, ms);
188 189 190
  }

  void record_update_rs_time(uint worker_i, double ms) {
191
    _last_update_rs_times_ms.set(worker_i, ms);
192 193
  }

194 195
  void record_update_rs_processed_buffers(uint worker_i, int processed_buffers) {
    _last_update_rs_processed_buffers.set(worker_i, processed_buffers);
196 197 198
  }

  void record_scan_rs_time(uint worker_i, double ms) {
199
    _last_scan_rs_times_ms.set(worker_i, ms);
200 201
  }

J
johnc 已提交
202 203 204 205
  void record_strong_code_root_scan_time(uint worker_i, double ms) {
    _last_strong_code_root_scan_times_ms.set(worker_i, ms);
  }

206 207
  void record_obj_copy_time(uint worker_i, double ms) {
    _last_obj_copy_times_ms.set(worker_i, ms);
208 209
  }

210 211
  void add_obj_copy_time(uint worker_i, double ms) {
    _last_obj_copy_times_ms.add(worker_i, ms);
212 213 214
  }

  void record_termination(uint worker_i, double ms, size_t attempts) {
215 216
    _last_termination_times_ms.set(worker_i, ms);
    _last_termination_attempts.set(worker_i, attempts);
217 218 219
  }

  void record_gc_worker_end_time(uint worker_i, double ms) {
220
    _last_gc_worker_end_times_ms.set(worker_i, ms);
221 222 223 224 225 226 227 228 229 230 231 232 233 234
  }

  void record_clear_ct_time(double ms) {
    _cur_clear_ct_time_ms = ms;
  }

  void record_par_time(double ms) {
    _cur_collection_par_time_ms = ms;
  }

  void record_code_root_fixup_time(double ms) {
    _cur_collection_code_root_fixup_time_ms = ms;
  }

235 236 237 238
  void record_strong_code_root_purge_time(double ms) {
    _cur_strong_code_root_purge_time_ms = ms;
  }

239 240 241 242 243 244 245 246 247 248 249 250
  void record_evac_fail_recalc_used_time(double ms) {
    _cur_evac_fail_recalc_used = ms;
  }

  void record_evac_fail_restore_remsets(double ms) {
    _cur_evac_fail_restore_remsets = ms;
  }

  void record_evac_fail_remove_self_forwards(double ms) {
    _cur_evac_fail_remove_self_forwards = ms;
  }

P
pliden 已提交
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
  void note_string_dedup_fixup_start();
  void note_string_dedup_fixup_end();

  void record_string_dedup_fixup_time(double ms) {
    _cur_string_dedup_fixup_time_ms = ms;
  }

  void record_string_dedup_queue_fixup_worker_time(uint worker_id, double ms) {
    _cur_string_dedup_queue_fixup_worker_times_ms.set(worker_id, ms);
  }

  void record_string_dedup_table_fixup_worker_time(uint worker_id, double ms) {
    _cur_string_dedup_table_fixup_worker_times_ms.set(worker_id, ms);
  }

266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
  void record_ref_proc_time(double ms) {
    _cur_ref_proc_time_ms = ms;
  }

  void record_ref_enq_time(double ms) {
    _cur_ref_enq_time_ms = ms;
  }

  void record_root_region_scan_wait_time(double time_ms) {
    _root_region_scan_wait_time_ms = time_ms;
  }

  void record_young_free_cset_time_ms(double time_ms) {
    _recorded_young_free_cset_time_ms = time_ms;
  }

  void record_non_young_free_cset_time_ms(double time_ms) {
    _recorded_non_young_free_cset_time_ms = time_ms;
  }
285

286 287 288 289 290 291 292 293 294 295
  void record_fast_reclaim_humongous_stats(size_t total, size_t candidates) {
    _cur_fast_reclaim_humongous_total = total;
    _cur_fast_reclaim_humongous_candidates = candidates;
  }

  void record_fast_reclaim_humongous_time_ms(double value, size_t reclaimed) {
    _cur_fast_reclaim_humongous_time_ms = value;
    _cur_fast_reclaim_humongous_reclaimed = reclaimed;
  }

296 297 298 299 300 301 302 303
  void record_young_cset_choice_time_ms(double time_ms) {
    _recorded_young_cset_choice_time_ms = time_ms;
  }

  void record_non_young_cset_choice_time_ms(double time_ms) {
    _recorded_non_young_cset_choice_time_ms = time_ms;
  }

304 305 306 307 308 309 310 311
  void record_redirty_logged_cards_time_ms(uint worker_i, double time_ms) {
    _last_redirty_logged_cards_time_ms.set(worker_i, time_ms);
  }

  void record_redirty_logged_cards_processed_cards(uint worker_i, size_t processed_buffers) {
    _last_redirty_logged_cards_processed_cards.set(worker_i, processed_buffers);
  }

312 313 314 315
  void record_redirty_logged_cards_time_ms(double time_ms) {
    _recorded_redirty_logged_cards_time_ms = time_ms;
  }

316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
  void record_cur_collection_start_sec(double time_ms) {
    _cur_collection_start_sec = time_ms;
  }

  void record_verify_before_time_ms(double time_ms) {
    _cur_verify_before_time_ms = time_ms;
  }

  void record_verify_after_time_ms(double time_ms) {
    _cur_verify_after_time_ms = time_ms;
  }

  double accounted_time_ms();

  double cur_collection_start_sec() {
    return _cur_collection_start_sec;
  }

  double cur_collection_par_time_ms() {
    return _cur_collection_par_time_ms;
  }

  double cur_clear_ct_time_ms() {
    return _cur_clear_ct_time_ms;
  }

  double root_region_scan_wait_time_ms() {
    return _root_region_scan_wait_time_ms;
  }

  double young_cset_choice_time_ms() {
    return _recorded_young_cset_choice_time_ms;
  }

  double young_free_cset_time_ms() {
    return _recorded_young_free_cset_time_ms;
  }

  double non_young_cset_choice_time_ms() {
    return _recorded_non_young_cset_choice_time_ms;
  }

  double non_young_free_cset_time_ms() {
    return _recorded_non_young_free_cset_time_ms;
  }

362 363 364 365
  double fast_reclaim_humongous_time_ms() {
    return _cur_fast_reclaim_humongous_time_ms;
  }

366 367 368 369 370 371 372 373 374 375 376 377
  double average_last_update_rs_time() {
    return _last_update_rs_times_ms.average();
  }

  int sum_last_update_rs_processed_buffers() {
    return _last_update_rs_processed_buffers.sum();
  }

  double average_last_scan_rs_time(){
    return _last_scan_rs_times_ms.average();
  }

J
johnc 已提交
378 379 380 381
  double average_last_strong_code_root_scan_time(){
    return _last_strong_code_root_scan_times_ms.average();
  }

382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
  double average_last_obj_copy_time() {
    return _last_obj_copy_times_ms.average();
  }

  double average_last_termination_time() {
    return _last_termination_times_ms.average();
  }

  double average_last_ext_root_scan_time() {
    return _last_ext_root_scan_times_ms.average();
  }

  double average_last_satb_filtering_times_ms() {
    return _last_satb_filtering_times_ms.average();
  }
397 398 399
};

#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1GCPHASETIMESLOG_HPP