1 /*
   2  * Copyright (c) 2013, 2016, 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 "memory/allocation.hpp"
  29 
  30 class LineBuffer;
  31 
  32 template <class T> class WorkerDataArray;
  33 
  34 class G1GCPhaseTimes : public CHeapObj<mtGC> {
  35   uint _max_gc_threads;
  36   jlong _gc_start_counter;
  37   double _gc_pause_time_ms;
  38 
  39  public:
  40   enum GCParPhases {
  41     GCWorkerStart,
  42     ExtRootScan,
  43     ThreadRoots,
  44     StringTableRoots,
  45     UniverseRoots,
  46     JNIRoots,
  47     ObjectSynchronizerRoots,
  48     FlatProfilerRoots,
  49     ManagementRoots,
  50     SystemDictionaryRoots,
  51     CLDGRoots,
  52     JVMTIRoots,
  53     CMRefRoots,
  54     WaitForStrongCLD,
  55     WeakCLDRoots,
  56     SATBFiltering,
  57     UpdateRS,
  58     ScanHCC,
  59     ScanRS,
  60     CodeRoots,
  61     ObjCopy,
  62     Termination,
  63     Other,
  64     GCWorkerTotal,
  65     GCWorkerEnd,
  66     StringDedupQueueFixup,
  67     StringDedupTableFixup,
  68     RedirtyCards,
  69     PreserveCMReferents,
  70     YoungFreeCSet,
  71     NonYoungFreeCSet,
  72     GCParPhasesSentinel
  73   };
  74 
  75  private:
  76   // Markers for grouping the phases in the GCPhases enum above
  77   static const int GCMainParPhasesLast = GCWorkerEnd;
  78   static const int StringDedupPhasesFirst = StringDedupQueueFixup;
  79   static const int StringDedupPhasesLast = StringDedupTableFixup;
  80 
  81   WorkerDataArray<double>* _gc_par_phases[GCParPhasesSentinel];
  82   WorkerDataArray<size_t>* _update_rs_processed_buffers;
  83   WorkerDataArray<size_t>* _termination_attempts;
  84   WorkerDataArray<size_t>* _redirtied_cards;
  85 
  86   double _cur_collection_par_time_ms;
  87   double _cur_collection_code_root_fixup_time_ms;
  88   double _cur_strong_code_root_purge_time_ms;
  89 
  90   double _cur_evac_fail_recalc_used;
  91   double _cur_evac_fail_restore_remsets;
  92   double _cur_evac_fail_remove_self_forwards;
  93 
  94   double _cur_string_dedup_fixup_time_ms;
  95 
  96   double _cur_clear_ct_time_ms;
  97   double _cur_expand_heap_time_ms;
  98   double _cur_ref_proc_time_ms;
  99   double _cur_ref_enq_time_ms;
 100 
 101   double _cur_collection_start_sec;
 102   double _root_region_scan_wait_time_ms;
 103 
 104   double _external_accounted_time_ms;
 105 
 106   double _recorded_clear_claimed_marks_time_ms;
 107 
 108   double _recorded_young_cset_choice_time_ms;
 109   double _recorded_non_young_cset_choice_time_ms;
 110 
 111   double _recorded_redirty_logged_cards_time_ms;
 112 
 113   double _recorded_preserve_cm_referents_time_ms;
 114 
 115   double _recorded_merge_pss_time_ms;
 116 
 117   double _recorded_total_free_cset_time_ms;
 118 
 119   double _recorded_serial_free_cset_time_ms;
 120 
 121   double _cur_fast_reclaim_humongous_time_ms;
 122   double _cur_fast_reclaim_humongous_register_time_ms;
 123   size_t _cur_fast_reclaim_humongous_total;
 124   size_t _cur_fast_reclaim_humongous_candidates;
 125   size_t _cur_fast_reclaim_humongous_reclaimed;
 126 
 127   double _cur_verify_before_time_ms;
 128   double _cur_verify_after_time_ms;
 129 
 130   double worker_time(GCParPhases phase, uint worker);
 131   void note_gc_end();
 132 
 133   template <class T>
 134   void details(T* phase, const char* indent);
 135   void log_phase(WorkerDataArray<double>* phase, uint indent, outputStream* out, bool print_sum);
 136   void debug_phase(WorkerDataArray<double>* phase);
 137   void trace_phase(WorkerDataArray<double>* phase, bool print_sum = true);
 138 
 139  public:
 140   G1GCPhaseTimes(uint max_gc_threads);
 141   void note_gc_start();
 142   void print();
 143 
 144   // record the time a phase took in seconds
 145   void record_time_secs(GCParPhases phase, uint worker_i, double secs);
 146 
 147   // add a number of seconds to a phase
 148   void add_time_secs(GCParPhases phase, uint worker_i, double secs);
 149 
 150   void record_thread_work_item(GCParPhases phase, uint worker_i, size_t count);
 151 
 152   // return the average time for a phase in milliseconds
 153   double average_time_ms(GCParPhases phase);
 154 
 155   size_t sum_thread_work_items(GCParPhases phase);
 156 
 157  public:
 158 
 159   void record_clear_ct_time(double ms) {
 160     _cur_clear_ct_time_ms = ms;
 161   }
 162 
 163   void record_expand_heap_time(double ms) {
 164     _cur_expand_heap_time_ms = ms;
 165   }
 166 
 167   void record_par_time(double ms) {
 168     _cur_collection_par_time_ms = ms;
 169   }
 170 
 171   void record_code_root_fixup_time(double ms) {
 172     _cur_collection_code_root_fixup_time_ms = ms;
 173   }
 174 
 175   void record_strong_code_root_purge_time(double ms) {
 176     _cur_strong_code_root_purge_time_ms = ms;
 177   }
 178 
 179   void record_evac_fail_recalc_used_time(double ms) {
 180     _cur_evac_fail_recalc_used = ms;
 181   }
 182 
 183   void record_evac_fail_restore_remsets(double ms) {
 184     _cur_evac_fail_restore_remsets = ms;
 185   }
 186 
 187   void record_evac_fail_remove_self_forwards(double ms) {
 188     _cur_evac_fail_remove_self_forwards = ms;
 189   }
 190 
 191   void record_string_dedup_fixup_time(double ms) {
 192     _cur_string_dedup_fixup_time_ms = ms;
 193   }
 194 
 195   void record_ref_proc_time(double ms) {
 196     _cur_ref_proc_time_ms = ms;
 197   }
 198 
 199   void record_ref_enq_time(double ms) {
 200     _cur_ref_enq_time_ms = ms;
 201   }
 202 
 203   void record_root_region_scan_wait_time(double time_ms) {
 204     _root_region_scan_wait_time_ms = time_ms;
 205   }
 206 
 207   void record_total_free_cset_time_ms(double time_ms) {
 208     _recorded_total_free_cset_time_ms = time_ms;
 209   }
 210 
 211   void record_serial_free_cset_time_ms(double time_ms) {
 212     _recorded_serial_free_cset_time_ms = time_ms;
 213   }
 214 
 215   void record_fast_reclaim_humongous_stats(double time_ms, size_t total, size_t candidates) {
 216     _cur_fast_reclaim_humongous_register_time_ms = time_ms;
 217     _cur_fast_reclaim_humongous_total = total;
 218     _cur_fast_reclaim_humongous_candidates = candidates;
 219   }
 220 
 221   void record_fast_reclaim_humongous_time_ms(double value, size_t reclaimed) {
 222     _cur_fast_reclaim_humongous_time_ms = value;
 223     _cur_fast_reclaim_humongous_reclaimed = reclaimed;
 224   }
 225 
 226   void record_young_cset_choice_time_ms(double time_ms) {
 227     _recorded_young_cset_choice_time_ms = time_ms;
 228   }
 229 
 230   void record_non_young_cset_choice_time_ms(double time_ms) {
 231     _recorded_non_young_cset_choice_time_ms = time_ms;
 232   }
 233 
 234   void record_redirty_logged_cards_time_ms(double time_ms) {
 235     _recorded_redirty_logged_cards_time_ms = time_ms;
 236   }
 237 
 238   void record_preserve_cm_referents_time_ms(double time_ms) {
 239     _recorded_preserve_cm_referents_time_ms = time_ms;
 240   }
 241 
 242   void record_merge_pss_time_ms(double time_ms) {
 243     _recorded_merge_pss_time_ms = time_ms;
 244   }
 245 
 246   void record_cur_collection_start_sec(double time_ms) {
 247     _cur_collection_start_sec = time_ms;
 248   }
 249 
 250   void record_verify_before_time_ms(double time_ms) {
 251     _cur_verify_before_time_ms = time_ms;
 252   }
 253 
 254   void record_verify_after_time_ms(double time_ms) {
 255     _cur_verify_after_time_ms = time_ms;
 256   }
 257 
 258   void inc_external_accounted_time_ms(double time_ms) {
 259     _external_accounted_time_ms += time_ms;
 260   }
 261 
 262   void record_clear_claimed_marks_time_ms(double recorded_clear_claimed_marks_time_ms) {
 263     _recorded_clear_claimed_marks_time_ms = recorded_clear_claimed_marks_time_ms;
 264   }
 265 
 266   double cur_collection_start_sec() {
 267     return _cur_collection_start_sec;
 268   }
 269 
 270   double cur_collection_par_time_ms() {
 271     return _cur_collection_par_time_ms;
 272   }
 273 
 274   double cur_clear_ct_time_ms() {
 275     return _cur_clear_ct_time_ms;
 276   }
 277 
 278   double cur_expand_heap_time_ms() {
 279     return _cur_expand_heap_time_ms;
 280   }
 281 
 282   double root_region_scan_wait_time_ms() {
 283     return _root_region_scan_wait_time_ms;
 284   }
 285 
 286   double young_cset_choice_time_ms() {
 287     return _recorded_young_cset_choice_time_ms;
 288   }
 289 
 290   double total_free_cset_time_ms() {
 291     return _recorded_total_free_cset_time_ms;
 292   }
 293 
 294   double non_young_cset_choice_time_ms() {
 295     return _recorded_non_young_cset_choice_time_ms;
 296   }
 297 
 298   double fast_reclaim_humongous_time_ms() {
 299     return _cur_fast_reclaim_humongous_time_ms;
 300   }
 301 };
 302 
 303 class G1GCParPhaseTimesTracker : public StackObj {
 304   double _start_time;
 305   G1GCPhaseTimes::GCParPhases _phase;
 306   G1GCPhaseTimes* _phase_times;
 307   uint _worker_id;
 308 public:
 309   G1GCParPhaseTimesTracker(G1GCPhaseTimes* phase_times, G1GCPhaseTimes::GCParPhases phase, uint worker_id);
 310   ~G1GCParPhaseTimesTracker();
 311 };
 312 
 313 #endif // SHARE_VM_GC_G1_G1GCPHASETIMES_HPP