1 /*
   2  * Copyright (c) 2017, 2020, Red Hat, Inc. 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_GC_SHENANDOAH_SHENANDOAHPHASETIMINGS_HPP
  26 #define SHARE_GC_SHENANDOAH_SHENANDOAHPHASETIMINGS_HPP
  27 
  28 #include "jfr/jfrEvents.hpp"
  29 #include "gc/shenandoah/shenandoahNumberSeq.hpp"
  30 #include "gc/shared/workerDataArray.hpp"
  31 #include "memory/allocation.hpp"
  32 
  33 class ShenandoahCollectorPolicy;
  34 class outputStream;
  35 
  36 #define SHENANDOAH_PAR_PHASE_DO(CNT_PREFIX, DESC_PREFIX, f)                            \
  37   f(CNT_PREFIX ## TotalWork,                DESC_PREFIX "<total>")                     \
  38   f(CNT_PREFIX ## ThreadRoots,              DESC_PREFIX "Thread Roots")                \
  39   f(CNT_PREFIX ## CodeCacheRoots,           DESC_PREFIX "Code Cache Roots")            \
  40   f(CNT_PREFIX ## UniverseRoots,            DESC_PREFIX "Universe Roots")              \
  41   f(CNT_PREFIX ## JNIRoots,                 DESC_PREFIX "JNI Handles Roots")           \
  42   f(CNT_PREFIX ## JVMTIWeakRoots,           DESC_PREFIX "JVMTI Weak Roots")            \
  43   f(CNT_PREFIX ## JFRWeakRoots,             DESC_PREFIX "JFR Weak Roots")              \
  44   f(CNT_PREFIX ## JNIWeakRoots,             DESC_PREFIX "JNI Weak Roots")              \
  45   f(CNT_PREFIX ## StringTableRoots,         DESC_PREFIX "String Table Roots")          \
  46   f(CNT_PREFIX ## ResolvedMethodTableRoots, DESC_PREFIX "Resolved Table Roots")        \
  47   f(CNT_PREFIX ## VMGlobalRoots,            DESC_PREFIX "VM Global Roots")             \
  48   f(CNT_PREFIX ## VMWeakRoots,              DESC_PREFIX "VM Weak Roots")               \
  49   f(CNT_PREFIX ## ObjectSynchronizerRoots,  DESC_PREFIX "Synchronizer Roots")          \
  50   f(CNT_PREFIX ## ManagementRoots,          DESC_PREFIX "Management Roots")            \
  51   f(CNT_PREFIX ## SystemDictionaryRoots,    DESC_PREFIX "System Dict Roots")           \
  52   f(CNT_PREFIX ## CLDGRoots,                DESC_PREFIX "CLDG Roots")                  \
  53   f(CNT_PREFIX ## JVMTIRoots,               DESC_PREFIX "JVMTI Roots")                 \
  54   f(CNT_PREFIX ## StringDedupTableRoots,    DESC_PREFIX "Dedup Table Roots")           \
  55   f(CNT_PREFIX ## StringDedupQueueRoots,    DESC_PREFIX "Dedup Queue Roots")           \
  56   f(CNT_PREFIX ## FinishQueues,             DESC_PREFIX "Finish Queues")               \
  57   // end
  58 
  59 #define SHENANDOAH_PHASE_DO(f)                                                         \
  60   f(conc_reset,                                     "Concurrent Reset")                \
  61                                                                                        \
  62   f(init_mark_gross,                                "Pause Init Mark (G)")             \
  63   f(init_mark,                                      "Pause Init Mark (N)")             \
  64   f(make_parsable,                                  "  Make Parsable")                 \
  65   f(init_update_region_states,                      "  Update Region States")          \
  66   f(scan_roots,                                     "  Scan Roots")                    \
  67   SHENANDOAH_PAR_PHASE_DO(scan_,                    "    S: ", f)                      \
  68   f(resize_tlabs,                                   "  Resize TLABs")                  \
  69                                                                                        \
  70   f(conc_mark,                                      "Concurrent Marking")              \
  71   f(conc_preclean,                                  "Concurrent Precleaning")          \
  72                                                                                        \
  73   f(final_mark_gross,                               "Pause Final Mark (G)")            \
  74   f(final_mark,                                     "Pause Final Mark (N)")            \
  75   f(update_roots,                                   "  Update Roots")                  \
  76   SHENANDOAH_PAR_PHASE_DO(update_,                  "    U: ", f)                      \
  77   f(finish_queues,                                  "  Finish Queues")                 \
  78   f(weakrefs,                                       "  Weak References")               \
  79   f(weakrefs_process,                               "    Process")                     \
  80   f(purge,                                          "  System Purge")                  \
  81   f(purge_class_unload,                             "    Unload Classes")              \
  82   SHENANDOAH_PAR_PHASE_DO(purge_cu_par_,            "      CU: ", f)                   \
  83   f(purge_weak_par,                                 "    Weak Roots")                  \
  84   SHENANDOAH_PAR_PHASE_DO(purge_weak_par_,          "      WR: ", f)                   \
  85   f(purge_cldg,                                     "    CLDG")                        \
  86   f(final_update_region_states,                     "  Update Region States")          \
  87   f(retire_tlabs,                                   "  Retire TLABs")                  \
  88   f(choose_cset,                                    "  Choose Collection Set")         \
  89   f(final_rebuild_freeset,                          "  Rebuild Free Set")              \
  90   f(init_evac,                                      "  Initial Evacuation")            \
  91   SHENANDOAH_PAR_PHASE_DO(evac_,                    "    E: ", f)                      \
  92                                                                                        \
  93   f(conc_weak_roots,                                "Concurrent Weak Roots")           \
  94   f(conc_weak_roots_work,                           "  Roots")                         \
  95   SHENANDOAH_PAR_PHASE_DO(conc_weak_roots_work_,    "    CWR: ", f)                    \
  96   f(conc_weak_roots_rendezvous,                     "  Rendezvous")                    \
  97   f(conc_cleanup_early,                             "Concurrent Cleanup")              \
  98   f(conc_class_unload,                              "Concurrent Class Unloading")      \
  99   f(conc_class_unload_unlink,                       "  Unlink Stale")                  \
 100   f(conc_class_unload_unlink_sd,                    "    System Dictionary")           \
 101   f(conc_class_unload_unlink_weak_klass,            "    Weak Class Links")            \
 102   f(conc_class_unload_unlink_code_roots,            "    Code Roots")                  \
 103   f(conc_class_unload_rendezvous,                   "  Rendezvous")                    \
 104   f(conc_class_unload_purge,                        "  Purge Unlinked")                \
 105   f(conc_class_unload_purge_coderoots,              "    Code Roots")                  \
 106   f(conc_class_unload_purge_cldg,                   "    CLDG")                        \
 107   f(conc_class_unload_purge_ec,                     "    Exception Caches")            \
 108   f(conc_strong_roots,                              "Concurrent Strong Roots")         \
 109   SHENANDOAH_PAR_PHASE_DO(conc_strong_roots_,       "  CSR: ", f)                      \
 110   f(conc_evac,                                      "Concurrent Evacuation")           \
 111                                                                                        \
 112   f(init_update_refs_gross,                         "Pause Init  Update Refs (G)")     \
 113   f(init_update_refs,                               "Pause Init  Update Refs (N)")     \
 114   f(init_update_refs_retire_gclabs,                 "  Retire GCLABs")                 \
 115                                                                                        \
 116   f(conc_update_refs,                               "Concurrent Update Refs")          \
 117                                                                                        \
 118   f(final_update_refs_gross,                        "Pause Final Update Refs (G)")     \
 119   f(final_update_refs,                              "Pause Final Update Refs (N)")     \
 120   f(final_update_refs_finish_work,                  "  Finish Work")                   \
 121   f(final_update_refs_roots,                        "  Update Roots")                  \
 122   SHENANDOAH_PAR_PHASE_DO(final_update_,            "    UR: ", f)                     \
 123   f(final_update_refs_update_region_states,         "  Update Region States")          \
 124   f(final_update_refs_trash_cset,                   "  Trash Collection Set")          \
 125   f(final_update_refs_rebuild_freeset,              "  Rebuild Free Set")              \
 126                                                                                        \
 127   f(conc_cleanup_complete,                          "Concurrent Cleanup")              \
 128                                                                                        \
 129   f(degen_gc_gross,                                 "Pause Degenerated GC (G)")        \
 130   f(degen_gc,                                       "Pause Degenerated GC (N)")        \
 131   f(degen_gc_update_roots,                          "  Degen Update Roots")            \
 132   SHENANDOAH_PAR_PHASE_DO(degen_gc_update_,         "    DU: ", f)                     \
 133                                                                                        \
 134   f(full_gc_gross,                                  "Pause Full GC (G)")               \
 135   f(full_gc,                                        "Pause Full GC (N)")               \
 136   f(full_gc_heapdump_pre,                           "  Pre Heap Dump")                 \
 137   f(full_gc_prepare,                                "  Prepare")                       \
 138   f(full_gc_scan_roots,                             "  Scan Roots")                    \
 139   SHENANDOAH_PAR_PHASE_DO(full_gc_scan_roots_,      "    FS: ", f)                     \
 140   f(full_gc_update_roots,                           "  Update Roots")                  \
 141   SHENANDOAH_PAR_PHASE_DO(full_gc_update_roots_,    "    FU: ", f)                     \
 142   f(full_gc_mark,                                   "  Mark")                          \
 143   f(full_gc_mark_finish_queues,                     "    Finish Queues")               \
 144   f(full_gc_weakrefs,                               "    Weak References")             \
 145   f(full_gc_weakrefs_process,                       "      Process")                   \
 146   f(full_gc_purge,                                  "    System Purge")                \
 147   f(full_gc_purge_class_unload,                     "      Unload Classes")            \
 148   SHENANDOAH_PAR_PHASE_DO(full_gc_purge_cu_par_,    "        CU: ", f)                 \
 149   f(full_gc_purge_weak_par,                         "      Weak Roots")                \
 150   SHENANDOAH_PAR_PHASE_DO(full_gc_purge_weak_p_,    "        WR: ", f)                 \
 151   f(full_gc_purge_cldg,                             "      CLDG")                      \
 152   f(full_gc_calculate_addresses,                    "  Calculate Addresses")           \
 153   f(full_gc_calculate_addresses_regular,            "    Regular Objects")             \
 154   f(full_gc_calculate_addresses_humong,             "    Humongous Objects")           \
 155   f(full_gc_adjust_pointers,                        "  Adjust Pointers")               \
 156   f(full_gc_adjust_roots,                           "  Adjust Roots")                  \
 157   SHENANDOAH_PAR_PHASE_DO(full_gc_adjust_roots_,    "    FA: ", f)                     \
 158   f(full_gc_copy_objects,                           "  Copy Objects")                  \
 159   f(full_gc_copy_objects_regular,                   "    Regular Objects")             \
 160   f(full_gc_copy_objects_humong,                    "    Humongous Objects")           \
 161   f(full_gc_copy_objects_reset_complete,            "    Reset Complete Bitmap")       \
 162   f(full_gc_copy_objects_rebuild,                   "    Rebuild Region Sets")         \
 163   f(full_gc_resize_tlabs,                           "  Resize TLABs")                  \
 164   f(full_gc_heapdump_post,                          "  Post Heap Dump")                \
 165                                                                                        \
 166   f(conc_uncommit,                                  "Concurrent Uncommit")             \
 167                                                                                        \
 168   f(heap_iteration_roots,                           "Heap Iteration")                  \
 169   SHENANDOAH_PAR_PHASE_DO(heap_iteration_roots_,    "  HI: ", f)                       \
 170   // end
 171 
 172 typedef WorkerDataArray<double> ShenandoahWorkerData;
 173 
 174 class ShenandoahPhaseTimings : public CHeapObj<mtGC> {
 175   friend class ShenandoahGCPhase;
 176   friend class ShenandoahWorkerTimingsTracker;
 177 public:
 178 #define SHENANDOAH_PHASE_DECLARE_ENUM(type, title)   type,
 179 
 180   enum Phase {
 181     SHENANDOAH_PHASE_DO(SHENANDOAH_PHASE_DECLARE_ENUM)
 182     _num_phases,
 183     _invalid_phase = _num_phases
 184   };
 185 
 186   enum ParPhase {
 187     SHENANDOAH_PAR_PHASE_DO(,, SHENANDOAH_PHASE_DECLARE_ENUM)
 188     _num_par_phases
 189   };
 190 
 191 #undef SHENANDOAH_PHASE_DECLARE_ENUM
 192 
 193 private:
 194   uint                _max_workers;
 195   double              _cycle_data[_num_phases];
 196   HdrSeq              _global_data[_num_phases];
 197   static const char*  _phase_names[_num_phases];
 198 
 199   ShenandoahWorkerData* _worker_data[_num_phases];
 200   ShenandoahCollectorPolicy* _policy;
 201 
 202   static bool is_worker_phase(Phase phase);
 203   static bool is_root_work_phase(Phase phase);
 204 
 205   ShenandoahWorkerData* worker_data(Phase phase, ParPhase par_phase);
 206   Phase worker_par_phase(Phase phase, ParPhase par_phase);
 207 
 208   void set_cycle_data(Phase phase, double time);
 209   static double uninitialized() { return -1; }
 210 
 211 public:
 212   ShenandoahPhaseTimings(uint max_workers);
 213 
 214   void record_phase_time(Phase phase, double time);
 215 
 216   void record_workers_start(Phase phase);
 217   void record_workers_end(Phase phase);
 218 
 219   void flush_par_workers_to_cycle();
 220   void flush_cycle_to_global();
 221 
 222   static const char* phase_name(Phase phase) {
 223     assert(phase >= 0 && phase < _num_phases, "Out of bound");
 224     return _phase_names[phase];
 225   }
 226 
 227   void print_cycle_on(outputStream* out) const;
 228   void print_global_on(outputStream* out) const;
 229 };
 230 
 231 class ShenandoahWorkerTimingsTracker : public StackObj {
 232 private:
 233   ShenandoahPhaseTimings*          const _timings;
 234   ShenandoahPhaseTimings::Phase    const _phase;
 235   ShenandoahPhaseTimings::ParPhase const _par_phase;
 236   uint const _worker_id;
 237 
 238   double _start_time;
 239   EventGCPhaseParallel _event;
 240 public:
 241   ShenandoahWorkerTimingsTracker(ShenandoahPhaseTimings::Phase phase, ShenandoahPhaseTimings::ParPhase par_phase, uint worker_id);
 242   ~ShenandoahWorkerTimingsTracker();
 243 };
 244 
 245 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHPHASETIMINGS_HPP