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