1 
   2 /*
   3  * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.
   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_SHENANDOAH_SHENANDOAHPHASETIMEINGS_HPP
  26 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHPHASETIMEINGS_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "gc_implementation/shenandoah/shenandoahNumberSeq.hpp"
  30 #include "gc_implementation/shenandoah/shenandoahWorkerDataArray.hpp"
  31 #include "gc_implementation/shenandoah/shenandoahWorkerDataArray.inline.hpp"
  32 
  33 class ShenandoahCollectorPolicy;
  34 class ShenandoahWorkerTimings;
  35 class ShenandoahTerminationTimings;
  36 class outputStream;
  37 
  38 #define SHENANDOAH_GC_PHASE_DO(f)                                                       \
  39   f(total_pause_gross,                              "Total Pauses (G)")                 \
  40   f(total_pause,                                    "Total Pauses (N)")                 \
  41   f(init_mark_gross,                                "Pause Init Mark (G)")              \
  42   f(init_mark,                                      "Pause Init Mark (N)")              \
  43   f(accumulate_stats,                               "  Accumulate Stats")               \
  44   f(make_parsable,                                  "  Make Parsable")                  \
  45   f(clear_liveness,                                 "  Clear Liveness")                 \
  46                                                                                         \
  47   /* Per-thread timer block, should have "roots" counters in consistent order */        \
  48   f(scan_roots,                                     "  Scan Roots")                     \
  49   f(scan_thread_roots,                              "    S: Thread Roots")              \
  50   f(scan_code_roots,                                "    S: Code Cache Roots")          \
  51   f(scan_string_table_roots,                        "    S: String Table Roots")        \
  52   f(scan_universe_roots,                            "    S: Universe Roots")            \
  53   f(scan_jni_roots,                                 "    S: JNI Roots")                 \
  54   f(scan_jni_weak_roots,                            "    S: JNI Weak Roots")            \
  55   f(scan_synchronizer_roots,                        "    S: Synchronizer Roots")        \
  56   f(scan_flat_profiler_roots,                       "    S: FlatProfiler Roots")        \
  57   f(scan_management_roots,                          "    S: Management Roots")          \
  58   f(scan_system_dictionary_roots,                   "    S: System Dict Roots")         \
  59   f(scan_cldg_roots,                                "    S: CLDG Roots")                \
  60   f(scan_jvmti_roots,                               "    S: JVMTI Roots")               \
  61   f(scan_string_dedup_roots,                        "    S: String Dedup Roots")        \
  62   f(scan_finish_queues,                             "    S: Finish Queues" )            \
  63                                                                                         \
  64   f(resize_tlabs,                                   "  Resize TLABs")                   \
  65                                                                                         \
  66   f(final_mark_gross,                               "Pause Final Mark (G)")             \
  67   f(final_mark,                                     "Pause Final Mark (N)")             \
  68                                                                                         \
  69   /* Per-thread timer block, should have "roots" counters in consistent order */        \
  70   f(update_roots,                                   "  Update Roots")                   \
  71   f(update_thread_roots,                            "    U: Thread Roots")              \
  72   f(update_code_roots,                              "    U: Code Cache Roots")          \
  73   f(update_string_table_roots,                      "    U: String Table Roots")        \
  74   f(update_universe_roots,                          "    U: Universe Roots")            \
  75   f(update_jni_roots,                               "    U: JNI Roots")                 \
  76   f(update_jni_weak_roots,                          "    U: JNI Weak Roots")            \
  77   f(update_synchronizer_roots,                      "    U: Synchronizer Roots")        \
  78   f(update_flat_profiler_roots,                     "    U: FlatProfiler Roots")        \
  79   f(update_management_roots,                        "    U: Management Roots")          \
  80   f(update_system_dictionary_roots,                 "    U: System Dict Roots")         \
  81   f(update_cldg_roots,                              "    U: CLDG Roots")                \
  82   f(update_jvmti_roots,                             "    U: JVMTI Roots")               \
  83   f(update_string_dedup_roots,                      "    U: String Dedup Roots")        \
  84   f(update_finish_queues,                           "    U: Finish Queues")             \
  85                                                                                         \
  86   f(finish_queues,                                  "  Finish Queues")                  \
  87   f(termination,                                    "    Termination")                  \
  88   f(weakrefs,                                       "  Weak References")                \
  89   f(weakrefs_process,                               "    Process")                      \
  90   f(weakrefs_termination,                           "      Termination")                \
  91   f(weakrefs_enqueue,                               "    Enqueue")                      \
  92   f(purge,                                          "  System Purge")                   \
  93   f(purge_class_unload,                             "    Unload Classes")               \
  94   f(purge_par,                                      "    Parallel Cleanup")             \
  95   f(purge_cldg,                                     "    CLDG")                         \
  96   f(purge_string_dedup,                             "    String Dedup")                 \
  97   f(complete_liveness,                              "  Complete Liveness")              \
  98   f(retire_tlabs,                                   "  Retire TLABs")                   \
  99   f(sync_pinned,                                    "  Sync Pinned")                    \
 100   f(trash_cset,                                     "  Trash CSet")                     \
 101   f(prepare_evac,                                   "  Prepare Evacuation")             \
 102                                                                                         \
 103   /* Per-thread timer block, should have "roots" counters in consistent order */        \
 104   f(init_evac,                                      "  Initial Evacuation")             \
 105   f(evac_thread_roots,                              "    E: Thread Roots")              \
 106   f(evac_code_roots,                                "    E: Code Cache Roots")          \
 107   f(evac_string_table_roots,                        "    E: String Table Roots")        \
 108   f(evac_universe_roots,                            "    E: Universe Roots")            \
 109   f(evac_jni_roots,                                 "    E: JNI Roots")                 \
 110   f(evac_jni_weak_roots,                            "    E: JNI Weak Roots")            \
 111   f(evac_synchronizer_roots,                        "    E: Synchronizer Roots")        \
 112   f(evac_flat_profiler_roots,                       "    E: FlatProfiler Roots")        \
 113   f(evac_management_roots,                          "    E: Management Roots")          \
 114   f(evac_system_dictionary_roots,                   "    E: System Dict Roots")         \
 115   f(evac_cldg_roots,                                "    E: CLDG Roots")                \
 116   f(evac_jvmti_roots,                               "    E: JVMTI Roots")               \
 117   f(evac_string_dedup_roots,                        "    E: String Dedup Roots")        \
 118   f(evac_finish_queues,                             "    E: Finish Queues")             \
 119                                                                                         \
 120   f(final_evac_gross,                               "Pause Final Evac (G)")             \
 121   f(final_evac,                                     "Pause Final Evac (N)")             \
 122   f(final_evac_retire_gclabs,                       "  Retire GCLABs")                  \
 123                                                                                         \
 124   f(init_update_refs_gross,                         "Pause Init  Update Refs (G)")      \
 125   f(init_update_refs,                               "Pause Init  Update Refs (N)")      \
 126   f(init_update_refs_retire_gclabs,                 "  Retire GCLABs")                  \
 127   f(init_update_refs_prepare,                       "  Prepare")                        \
 128                                                                                         \
 129   f(final_update_refs_gross,                         "Pause Final Update Refs (G)")     \
 130   f(final_update_refs,                               "Pause Final Update Refs (N)")     \
 131   f(final_update_refs_finish_work,                   "  Finish Work")                   \
 132                                                                                         \
 133   /* Per-thread timer block, should have "roots" counters in consistent order */        \
 134   f(final_update_refs_roots,                         "  Update Roots")                  \
 135   f(final_update_refs_thread_roots,                  "    UR: Thread Roots")            \
 136   f(final_update_refs_code_roots,                    "    UR: Code Cache Roots")        \
 137   f(final_update_refs_string_table_roots,            "    UR: String Table Roots")      \
 138   f(final_update_refs_universe_roots,                "    UR: Universe Roots")          \
 139   f(final_update_refs_jni_roots,                     "    UR: JNI Roots")               \
 140   f(final_update_refs_jni_weak_roots,                "    UR: JNI Weak Roots")          \
 141   f(final_update_refs_synchronizer_roots,            "    UR: Synchronizer Roots")      \
 142   f(final_update_refs_flat_profiler_roots,           "    UR: FlatProfiler Roots")      \
 143   f(final_update_refs_management_roots,              "    UR: Management Roots")        \
 144   f(final_update_refs_system_dict_roots,             "    UR: System Dict Roots")       \
 145   f(final_update_refs_cldg_roots,                    "    UR: CLDG Roots")              \
 146   f(final_update_refs_jvmti_roots,                   "    UR: JVMTI Roots")             \
 147   f(final_update_refs_string_dedup_roots,            "    UR: String Dedup Roots")      \
 148   f(final_update_refs_finish_queues,                 "    UR: Finish Queues")           \
 149                                                                                         \
 150   f(final_update_refs_sync_pinned,                   "  Sync Pinned")                   \
 151   f(final_update_refs_trash_cset,                    "  Trash CSet")                    \
 152                                                                                         \
 153   f(degen_gc_gross,                                  "Pause Degenerated GC (G)")        \
 154   f(degen_gc,                                        "Pause Degenerated GC (N)")        \
 155                                                                                         \
 156   /* Per-thread timer block, should have "roots" counters in consistent order */        \
 157   f(degen_gc_update_roots,                           "  Degen Update Roots")            \
 158   f(degen_gc_update_thread_roots,                    "    DU: Thread Roots")            \
 159   f(degen_gc_update_code_roots,                      "    DU: Code Cache Roots")        \
 160   f(degen_gc_update_string_table_roots,              "    DU: String Table Roots")      \
 161   f(degen_gc_update_universe_roots,                  "    DU: Universe Roots")          \
 162   f(degen_gc_update_jni_roots,                       "    DU: JNI Roots")               \
 163   f(degen_gc_update_jni_weak_roots,                  "    DU: JNI Weak Roots")          \
 164   f(degen_gc_update_synchronizer_roots,              "    DU: Synchronizer Roots")      \
 165   f(degen_gc_update_flat_profiler_roots,             "    DU: FlatProfiler Roots")      \
 166   f(degen_gc_update_management_roots,                "    DU: Management Roots")        \
 167   f(degen_gc_update_system_dict_roots,               "    DU: System Dict Roots")       \
 168   f(degen_gc_update_cldg_roots,                      "    DU: CLDG Roots")              \
 169   f(degen_gc_update_jvmti_roots,                     "    DU: JVMTI Roots")             \
 170   f(degen_gc_update_string_dedup_roots,              "    DU: String Dedup Roots")      \
 171   f(degen_gc_update_finish_queues,                   "    DU: Finish Queues")           \
 172                                                                                         \
 173   f(full_gc_gross,                                   "Pause Full GC (G)")               \
 174   f(full_gc,                                         "Pause Full GC (N)")               \
 175   f(full_gc_heapdumps,                               "  Heap Dumps")                    \
 176   f(full_gc_prepare,                                 "  Prepare")                       \
 177                                                                                         \
 178   /* Per-thread timer block, should have "roots" counters in consistent order */        \
 179   f(full_gc_roots,                                   "  Roots")                         \
 180   f(full_gc_thread_roots,                            "    F: Thread Roots")             \
 181   f(full_gc_code_roots,                              "    F: Code Cache Roots")         \
 182   f(full_gc_string_table_roots,                      "    F: String Table Roots")       \
 183   f(full_gc_universe_roots,                          "    F: Universe Roots")           \
 184   f(full_gc_jni_roots,                               "    F: JNI Roots")                \
 185   f(full_gc_jni_weak_roots,                          "    F: JNI Weak Roots")           \
 186   f(full_gc_synchronizer_roots,                      "    F: Synchronizer Roots")       \
 187   f(full_gc_flat_profiler_roots,                     "    F: FlatProfiler Roots")       \
 188   f(full_gc_management_roots,                        "    F: Management Roots")         \
 189   f(full_gc_system_dictionary_roots,                 "    F: System Dict Roots")        \
 190   f(full_gc_cldg_roots,                              "    F: CLDG Roots")               \
 191   f(full_gc_jvmti_roots,                             "    F: JVMTI Roots")              \
 192   f(full_gc_string_dedup_roots,                      "    F: String Dedup Roots")       \
 193   f(full_gc_finish_queues,                           "    F: Finish Queues")            \
 194                                                                                         \
 195   f(full_gc_mark,                                    "  Mark")                          \
 196   f(full_gc_mark_finish_queues,                      "    Finish Queues")               \
 197   f(full_gc_mark_termination,                        "      Termination")               \
 198   f(full_gc_weakrefs,                                "    Weak References")             \
 199   f(full_gc_weakrefs_process,                        "      Process")                   \
 200   f(full_gc_weakrefs_termination,                    "        Termination")             \
 201   f(full_gc_weakrefs_enqueue,                        "      Enqueue")                   \
 202   f(full_gc_purge,                                   "    System Purge")                \
 203   f(full_gc_purge_class_unload,                      "      Unload Classes")            \
 204   f(full_gc_purge_par,                               "    Parallel Cleanup")            \
 205   f(full_gc_purge_cldg,                              "    CLDG")                        \
 206   f(full_gc_purge_string_dedup,                      "    String Dedup")                \
 207   f(full_gc_calculate_addresses,                     "  Calculate Addresses")           \
 208   f(full_gc_calculate_addresses_regular,             "    Regular Objects")             \
 209   f(full_gc_calculate_addresses_humong,              "    Humongous Objects")           \
 210   f(full_gc_adjust_pointers,                         "  Adjust Pointers")               \
 211   f(full_gc_copy_objects,                            "  Copy Objects")                  \
 212   f(full_gc_copy_objects_regular,                    "    Regular Objects")             \
 213   f(full_gc_copy_objects_humong,                     "    Humongous Objects")           \
 214   f(full_gc_copy_objects_reset_complete,             "    Reset Complete Bitmap")       \
 215   f(full_gc_copy_objects_rebuild,                    "    Rebuild Region Sets")         \
 216   f(full_gc_resize_tlabs,                            "  Resize TLABs")                  \
 217                                                                                         \
 218   /* Longer concurrent phases at the end */                                             \
 219   f(conc_reset,                                      "Concurrent Reset")                \
 220   f(conc_mark,                                       "Concurrent Marking")              \
 221   f(conc_termination,                                "  Termination")                   \
 222   f(conc_preclean,                                   "Concurrent Precleaning")          \
 223   f(conc_evac,                                       "Concurrent Evacuation")           \
 224   f(conc_update_refs,                                "Concurrent Update Refs")          \
 225   f(conc_cleanup,                                    "Concurrent Cleanup")              \
 226   f(conc_traversal,                                  "Concurrent Traversal")            \
 227   f(conc_traversal_termination,                      "  Termination")                   \
 228                                                                                         \
 229   f(conc_uncommit,                                   "Concurrent Uncommit")             \
 230                                                                                         \
 231   /* Unclassified */                                                                    \
 232   f(pause_other,                                     "Pause Other")                     \
 233   f(conc_other,                                      "Concurrent Other")                \
 234   // end
 235 
 236 #define SHENANDOAH_GC_PAR_PHASE_DO(f)                           \
 237   f(ThreadRoots,             "Thread Roots (ms):")              \
 238   f(CodeCacheRoots,          "CodeCache Roots (ms):")           \
 239   f(StringTableRoots,        "StringTable Roots (ms):")         \
 240   f(UniverseRoots,           "Universe Roots (ms):")            \
 241   f(JNIRoots,                "JNI Handles Roots (ms):")         \
 242   f(JNIWeakRoots,            "JNI Weak Roots (ms):")            \
 243   f(ObjectSynchronizerRoots, "ObjectSynchronizer Roots (ms):")  \
 244   f(FlatProfilerRoots,       "FlatProfiler Roots (ms):")        \
 245   f(ManagementRoots,         "Management Roots (ms):")          \
 246   f(SystemDictionaryRoots,   "SystemDictionary Roots (ms):")    \
 247   f(CLDGRoots,               "CLDG Roots (ms):")                \
 248   f(JVMTIRoots,              "JVMTI Roots (ms):")               \
 249   f(StringDedupRoots,        "String Dedup Roots (ms):")        \
 250   f(FinishQueues,            "Finish Queues (ms):")             \
 251   // end
 252 
 253 class ShenandoahPhaseTimings : public CHeapObj<mtGC> {
 254 public:
 255 #define GC_PHASE_DECLARE_ENUM(type, title)   type,
 256   enum Phase {
 257     SHENANDOAH_GC_PHASE_DO(GC_PHASE_DECLARE_ENUM)
 258     _num_phases
 259   };
 260 
 261   // These are the subphases of GC phases (scan_roots, update_roots,
 262   // init_evac, final_update_refs_roots, and full_gc_roots).
 263   // Make sure they are following this order.
 264   enum GCParPhases {
 265     SHENANDOAH_GC_PAR_PHASE_DO(GC_PHASE_DECLARE_ENUM)
 266     GCParPhasesSentinel
 267   };
 268 
 269 #undef GC_PHASE_DECLARE_ENUM
 270 
 271 private:
 272   struct TimingData {
 273     HdrSeq _secs;
 274     double _start;
 275   };
 276 
 277 private:
 278   TimingData          _timing_data[_num_phases];
 279   static const char*  _phase_names[_num_phases];
 280 
 281   ShenandoahWorkerTimings*      _worker_times;
 282   ShenandoahTerminationTimings* _termination_times;
 283 
 284   ShenandoahCollectorPolicy* _policy;
 285 
 286 public:
 287   ShenandoahPhaseTimings();
 288 
 289   ShenandoahWorkerTimings* const worker_times() const { return _worker_times; }
 290   ShenandoahTerminationTimings* const termination_times() const { return _termination_times; }
 291 
 292   // record phase start
 293   void record_phase_start(Phase phase);
 294   // record phase end and return elapsed time in seconds for the phase
 295   void record_phase_end(Phase phase);
 296   // record an elapsed time for the phase
 297   void record_phase_time(Phase phase, double time);
 298 
 299   void record_workers_start(Phase phase);
 300   void record_workers_end(Phase phase);
 301 
 302   static const char* phase_name(Phase phase) {
 303     assert(phase >= 0 && phase < _num_phases, "Out of bound");
 304     return _phase_names[phase];
 305   }
 306 
 307   void print_on(outputStream* out) const;
 308 
 309 private:
 310   void init_phase_names();
 311   void print_summary_sd(outputStream* out, const char* str, const HdrSeq* seq) const;
 312 };
 313 
 314 class ShenandoahWorkerTimings : public CHeapObj<mtGC> {
 315 private:
 316   uint _max_gc_threads;
 317   ShenandoahWorkerDataArray<double>* _gc_par_phases[ShenandoahPhaseTimings::GCParPhasesSentinel];
 318 
 319 public:
 320   ShenandoahWorkerTimings(uint max_gc_threads);
 321 
 322   // record the time a phase took in seconds
 323   void record_time_secs(ShenandoahPhaseTimings::GCParPhases phase, uint worker_i, double secs);
 324 
 325   double average(uint i);
 326   void reset(uint i);
 327   void print();
 328 };
 329 
 330 class ShenandoahTerminationTimings : public CHeapObj<mtGC> {
 331 private:
 332   ShenandoahWorkerDataArray<double>* _gc_termination_phase;
 333 public:
 334   ShenandoahTerminationTimings(uint max_gc_threads);
 335 
 336   // record the time a phase took in seconds
 337   void record_time_secs(uint worker_i, double secs);
 338 
 339   double average() const;
 340   void reset();
 341 
 342   void print() const;
 343 };
 344 
 345 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHGCPHASETIMEINGS_HPP