1 /*
   2  * Copyright (c) 2013, 2018, 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_G1_G1GCPHASETIMES_HPP
  26 #define SHARE_VM_GC_G1_G1GCPHASETIMES_HPP
  27 
  28 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
  29 #include "logging/logLevel.hpp"
  30 #include "memory/allocation.hpp"
  31 #include "utilities/macros.hpp"
  32 
  33 class LineBuffer;
  34 class G1ParScanThreadState;
  35 class STWGCTimer;
  36 
  37 template <class T> class WorkerDataArray;
  38 
  39 class G1GCPhaseTimes : public CHeapObj<mtGC> {
  40   uint _max_gc_threads;
  41   jlong _gc_start_counter;
  42   double _gc_pause_time_ms;
  43 
  44  public:
  45   enum GCParPhases {
  46     GCWorkerStart,
  47     ExtRootScan,
  48     ThreadRoots,
  49     StringTableRoots,
  50     UniverseRoots,
  51     JNIRoots,
  52     ObjectSynchronizerRoots,
  53     ManagementRoots,
  54     SystemDictionaryRoots,
  55     CLDGRoots,
  56     JVMTIRoots,
  57     CMRefRoots,
  58     WaitForStrongCLD,
  59     WeakCLDRoots,
  60     SATBFiltering,
  61     UpdateRS,
  62     ScanHCC,
  63     ScanRS,
  64     CodeRoots,
  65 #if INCLUDE_AOT
  66     AOTCodeRoots,
  67 #endif
  68     ObjCopy,
  69     Termination,
  70     Other,
  71     GCWorkerTotal,
  72     GCWorkerEnd,
  73     StringDedupQueueFixup,
  74     StringDedupTableFixup,
  75     RedirtyCards,
  76     PreserveCMReferents,
  77     YoungFreeCSet,
  78     NonYoungFreeCSet,
  79     GCParPhasesSentinel
  80   };
  81 
  82   enum GCScanRSWorkItems {
  83     ScanRSScannedCards,
  84     ScanRSClaimedCards,
  85     ScanRSSkippedCards
  86   };
  87 
  88   enum GCUpdateRSWorkItems {
  89     UpdateRSProcessedBuffers,
  90     UpdateRSScannedCards,
  91     UpdateRSSkippedCards
  92   };
  93 
  94  private:
  95   // Markers for grouping the phases in the GCPhases enum above
  96   static const int GCMainParPhasesLast = GCWorkerEnd;
  97   static const int StringDedupPhasesFirst = StringDedupQueueFixup;
  98   static const int StringDedupPhasesLast = StringDedupTableFixup;
  99 
 100   WorkerDataArray<double>* _gc_par_phases[GCParPhasesSentinel];
 101 
 102   WorkerDataArray<size_t>* _update_rs_processed_buffers;
 103   WorkerDataArray<size_t>* _update_rs_scanned_cards;
 104   WorkerDataArray<size_t>* _update_rs_skipped_cards;
 105 
 106   WorkerDataArray<size_t>* _scan_rs_scanned_cards;
 107   WorkerDataArray<size_t>* _scan_rs_claimed_cards;
 108   WorkerDataArray<size_t>* _scan_rs_skipped_cards;
 109 
 110   WorkerDataArray<size_t>* _termination_attempts;
 111 
 112   WorkerDataArray<size_t>* _redirtied_cards;
 113 
 114   double _cur_collection_par_time_ms;
 115   double _cur_collection_code_root_fixup_time_ms;
 116   double _cur_strong_code_root_purge_time_ms;
 117 
 118   double _cur_evac_fail_recalc_used;
 119   double _cur_evac_fail_remove_self_forwards;
 120 
 121   double _cur_string_dedup_fixup_time_ms;
 122 
 123   double _cur_prepare_tlab_time_ms;
 124   double _cur_resize_tlab_time_ms;
 125 
 126   double _cur_derived_pointer_table_update_time_ms;
 127 
 128   double _cur_clear_ct_time_ms;
 129   double _cur_expand_heap_time_ms;
 130   double _cur_ref_proc_time_ms;
 131   double _cur_ref_enq_time_ms;
 132 
 133   double _cur_collection_start_sec;
 134   double _root_region_scan_wait_time_ms;
 135 
 136   double _external_accounted_time_ms;
 137 
 138   double _recorded_clear_claimed_marks_time_ms;
 139 
 140   double _recorded_young_cset_choice_time_ms;
 141   double _recorded_non_young_cset_choice_time_ms;
 142 
 143   double _recorded_redirty_logged_cards_time_ms;
 144 
 145   double _recorded_preserve_cm_referents_time_ms;
 146 
 147   double _recorded_merge_pss_time_ms;
 148 
 149   double _recorded_start_new_cset_time_ms;
 150 
 151   double _recorded_total_free_cset_time_ms;
 152 
 153   double _recorded_serial_free_cset_time_ms;
 154 
 155   double _cur_fast_reclaim_humongous_time_ms;
 156   double _cur_fast_reclaim_humongous_register_time_ms;
 157   size_t _cur_fast_reclaim_humongous_total;
 158   size_t _cur_fast_reclaim_humongous_candidates;
 159   size_t _cur_fast_reclaim_humongous_reclaimed;
 160 
 161   double _cur_verify_before_time_ms;
 162   double _cur_verify_after_time_ms;
 163 
 164   ReferenceProcessorPhaseTimes _ref_phase_times;
 165 
 166   double worker_time(GCParPhases phase, uint worker);
 167   void note_gc_end();
 168   void reset();
 169 
 170   template <class T>
 171   void details(T* phase, const char* indent) const;
 172 
 173   void log_phase(WorkerDataArray<double>* phase, uint indent, outputStream* out, bool print_sum) const;
 174   void debug_phase(WorkerDataArray<double>* phase) const;
 175   void trace_phase(WorkerDataArray<double>* phase, bool print_sum = true) const;
 176 
 177   void info_time(const char* name, double value) const;
 178   void debug_time(const char* name, double value) const;
 179   // This will print logs for both 'gc+phases' and 'gc+phases+ref'.
 180   void debug_time_for_reference(const char* name, double value) const;
 181   void trace_time(const char* name, double value) const;
 182   void trace_count(const char* name, size_t value) const;
 183 
 184   double print_pre_evacuate_collection_set() const;
 185   double print_evacuate_collection_set() const;
 186   double print_post_evacuate_collection_set() const;
 187   void print_other(double accounted_ms) const;
 188 
 189  public:
 190   G1GCPhaseTimes(STWGCTimer* gc_timer, uint max_gc_threads);
 191   void note_gc_start();
 192   void print();
 193 
 194   // record the time a phase took in seconds
 195   void record_time_secs(GCParPhases phase, uint worker_i, double secs);
 196 
 197   // add a number of seconds to a phase
 198   void add_time_secs(GCParPhases phase, uint worker_i, double secs);
 199 
 200   void record_or_add_objcopy_time_secs(uint worker_i, double secs);
 201 
 202   void record_thread_work_item(GCParPhases phase, uint worker_i, size_t count, uint index = 0);
 203 
 204   // return the average time for a phase in milliseconds
 205   double average_time_ms(GCParPhases phase);
 206 
 207   size_t sum_thread_work_items(GCParPhases phase, uint index = 0);
 208 
 209  public:
 210 
 211   void record_prepare_tlab_time_ms(double ms) {
 212     _cur_prepare_tlab_time_ms = ms;
 213   }
 214 
 215   void record_resize_tlab_time_ms(double ms) {
 216     _cur_resize_tlab_time_ms = ms;
 217   }
 218 
 219   void record_derived_pointer_table_update_time(double ms) {
 220     _cur_derived_pointer_table_update_time_ms = ms;
 221   }
 222 
 223   void record_clear_ct_time(double ms) {
 224     _cur_clear_ct_time_ms = ms;
 225   }
 226 
 227   void record_expand_heap_time(double ms) {
 228     _cur_expand_heap_time_ms = ms;
 229   }
 230 
 231   void record_par_time(double ms) {
 232     _cur_collection_par_time_ms = ms;
 233   }
 234 
 235   void record_code_root_fixup_time(double ms) {
 236     _cur_collection_code_root_fixup_time_ms = ms;
 237   }
 238 
 239   void record_strong_code_root_purge_time(double ms) {
 240     _cur_strong_code_root_purge_time_ms = ms;
 241   }
 242 
 243   void record_evac_fail_recalc_used_time(double ms) {
 244     _cur_evac_fail_recalc_used = ms;
 245   }
 246 
 247   void record_evac_fail_remove_self_forwards(double ms) {
 248     _cur_evac_fail_remove_self_forwards = ms;
 249   }
 250 
 251   void record_string_dedup_fixup_time(double ms) {
 252     _cur_string_dedup_fixup_time_ms = ms;
 253   }
 254 
 255   void record_ref_proc_time(double ms) {
 256     _cur_ref_proc_time_ms = ms;
 257   }
 258 
 259   void record_ref_enq_time(double ms) {
 260     _cur_ref_enq_time_ms = ms;
 261   }
 262 
 263   void record_root_region_scan_wait_time(double time_ms) {
 264     _root_region_scan_wait_time_ms = time_ms;
 265   }
 266 
 267   void record_total_free_cset_time_ms(double time_ms) {
 268     _recorded_total_free_cset_time_ms = time_ms;
 269   }
 270 
 271   void record_serial_free_cset_time_ms(double time_ms) {
 272     _recorded_serial_free_cset_time_ms = time_ms;
 273   }
 274 
 275   void record_fast_reclaim_humongous_stats(double time_ms, size_t total, size_t candidates) {
 276     _cur_fast_reclaim_humongous_register_time_ms = time_ms;
 277     _cur_fast_reclaim_humongous_total = total;
 278     _cur_fast_reclaim_humongous_candidates = candidates;
 279   }
 280 
 281   void record_fast_reclaim_humongous_time_ms(double value, size_t reclaimed) {
 282     _cur_fast_reclaim_humongous_time_ms = value;
 283     _cur_fast_reclaim_humongous_reclaimed = reclaimed;
 284   }
 285 
 286   void record_young_cset_choice_time_ms(double time_ms) {
 287     _recorded_young_cset_choice_time_ms = time_ms;
 288   }
 289 
 290   void record_non_young_cset_choice_time_ms(double time_ms) {
 291     _recorded_non_young_cset_choice_time_ms = time_ms;
 292   }
 293 
 294   void record_redirty_logged_cards_time_ms(double time_ms) {
 295     _recorded_redirty_logged_cards_time_ms = time_ms;
 296   }
 297 
 298   void record_preserve_cm_referents_time_ms(double time_ms) {
 299     _recorded_preserve_cm_referents_time_ms = time_ms;
 300   }
 301 
 302   void record_merge_pss_time_ms(double time_ms) {
 303     _recorded_merge_pss_time_ms = time_ms;
 304   }
 305 
 306   void record_start_new_cset_time_ms(double time_ms) {
 307     _recorded_start_new_cset_time_ms = time_ms;
 308   }
 309 
 310   void record_cur_collection_start_sec(double time_ms) {
 311     _cur_collection_start_sec = time_ms;
 312   }
 313 
 314   void record_verify_before_time_ms(double time_ms) {
 315     _cur_verify_before_time_ms = time_ms;
 316   }
 317 
 318   void record_verify_after_time_ms(double time_ms) {
 319     _cur_verify_after_time_ms = time_ms;
 320   }
 321 
 322   void inc_external_accounted_time_ms(double time_ms) {
 323     _external_accounted_time_ms += time_ms;
 324   }
 325 
 326   void record_clear_claimed_marks_time_ms(double recorded_clear_claimed_marks_time_ms) {
 327     _recorded_clear_claimed_marks_time_ms = recorded_clear_claimed_marks_time_ms;
 328   }
 329 
 330   double cur_collection_start_sec() {
 331     return _cur_collection_start_sec;
 332   }
 333 
 334   double cur_collection_par_time_ms() {
 335     return _cur_collection_par_time_ms;
 336   }
 337 
 338   double cur_clear_ct_time_ms() {
 339     return _cur_clear_ct_time_ms;
 340   }
 341 
 342   double cur_expand_heap_time_ms() {
 343     return _cur_expand_heap_time_ms;
 344   }
 345 
 346   double root_region_scan_wait_time_ms() {
 347     return _root_region_scan_wait_time_ms;
 348   }
 349 
 350   double young_cset_choice_time_ms() {
 351     return _recorded_young_cset_choice_time_ms;
 352   }
 353 
 354   double total_free_cset_time_ms() {
 355     return _recorded_total_free_cset_time_ms;
 356   }
 357 
 358   double non_young_cset_choice_time_ms() {
 359     return _recorded_non_young_cset_choice_time_ms;
 360   }
 361 
 362   double fast_reclaim_humongous_time_ms() {
 363     return _cur_fast_reclaim_humongous_time_ms;
 364   }
 365 
 366   ReferenceProcessorPhaseTimes* ref_phase_times() { return &_ref_phase_times; }
 367 };
 368 
 369 class G1EvacPhaseWithTrimTimeTracker : public StackObj {
 370   G1ParScanThreadState* _pss;
 371   Ticks _start;
 372 
 373   Tickspan& _total_time;
 374   Tickspan& _trim_time;
 375 public:
 376   G1EvacPhaseWithTrimTimeTracker(G1ParScanThreadState* pss, Tickspan& total_time, Tickspan& trim_time);
 377   ~G1EvacPhaseWithTrimTimeTracker();
 378 };
 379 
 380 class G1GCParPhaseTimesTracker : public CHeapObj<mtGC> {
 381 protected:
 382   Ticks _start_time;
 383   G1GCPhaseTimes::GCParPhases _phase;
 384   G1GCPhaseTimes* _phase_times;
 385   uint _worker_id;
 386 public:
 387   G1GCParPhaseTimesTracker(G1GCPhaseTimes* phase_times, G1GCPhaseTimes::GCParPhases phase, uint worker_id);
 388   virtual ~G1GCParPhaseTimesTracker();
 389 };
 390 
 391 class G1EvacPhaseTimesTracker : public G1GCParPhaseTimesTracker {
 392   Tickspan _total_time;
 393   Tickspan _trim_time;
 394 
 395   G1EvacPhaseWithTrimTimeTracker _trim_tracker;
 396 public:
 397   G1EvacPhaseTimesTracker(G1GCPhaseTimes* phase_times, G1ParScanThreadState* pss, G1GCPhaseTimes::GCParPhases phase, uint worker_id);
 398   virtual ~G1EvacPhaseTimesTracker();
 399 };
 400 
 401 #endif // SHARE_VM_GC_G1_G1GCPHASETIMES_HPP