1 /* 2 * Copyright (c) 2017, 2021, Red Hat, Inc. All rights reserved. 3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHPHASETIMINGS_HPP 27 #define SHARE_GC_SHENANDOAH_SHENANDOAHPHASETIMINGS_HPP 28 29 #include "jfr/jfrEvents.hpp" 30 #include "gc/shenandoah/shenandoahNumberSeq.hpp" 31 #include "gc/shared/workerDataArray.hpp" 32 #include "memory/allocation.hpp" 33 34 class ShenandoahCollectorPolicy; 35 class outputStream; 36 37 #define SHENANDOAH_PAR_PHASE_DO(CNT_PREFIX, DESC_PREFIX, f) \ 38 f(CNT_PREFIX ## TotalWork, DESC_PREFIX "<total>") \ 39 f(CNT_PREFIX ## ThreadRoots, DESC_PREFIX "Thread Roots") \ 40 f(CNT_PREFIX ## CodeCacheRoots, DESC_PREFIX "Code Cache Roots") \ 41 f(CNT_PREFIX ## VMStrongRoots, DESC_PREFIX "VM Strong Roots") \ 42 f(CNT_PREFIX ## VMWeakRoots, DESC_PREFIX "VM Weak Roots") \ 43 f(CNT_PREFIX ## CLDGRoots, DESC_PREFIX "CLDG Roots") \ 44 f(CNT_PREFIX ## CodeCacheUnload, DESC_PREFIX "Unload Code Caches") \ 45 f(CNT_PREFIX ## CLDUnlink, DESC_PREFIX "Unlink CLDs") \ 46 f(CNT_PREFIX ## WeakRefProc, DESC_PREFIX "Weak References") \ 47 f(CNT_PREFIX ## ParallelMark, DESC_PREFIX "Parallel Mark") \ 48 f(CNT_PREFIX ## ScanClusters, DESC_PREFIX "Scan Clusters") \ 49 // end 50 51 #define SHENANDOAH_PHASE_DO(f) \ 52 f(conc_reset, "Concurrent Reset") \ 53 f(conc_reset_after_collect, "Concurrent Reset After Collect") \ 54 f(conc_reset_old, "Concurrent Reset (OLD)") \ 55 f(init_mark_gross, "Pause Init Mark (G)") \ 56 f(init_mark, "Pause Init Mark (N)") \ 57 f(init_mark_verify, " Verify") \ 58 f(init_manage_tlabs, " Manage TLABs") \ 59 f(init_swap_rset, " Swap Remembered Set") \ 60 f(init_transfer_satb, " Transfer Old From SATB") \ 61 f(init_update_region_states, " Update Region States") \ 62 f(init_propagate_gc_state, " Propagate GC State") \ 63 \ 64 f(init_scan_rset, "Concurrent Scan Remembered Set") \ 65 SHENANDOAH_PAR_PHASE_DO(init_scan_rset_, " RS: ", f) \ 66 \ 67 f(conc_mark_roots, "Concurrent Mark Roots ") \ 68 SHENANDOAH_PAR_PHASE_DO(conc_mark_roots, " CMR: ", f) \ 69 f(conc_mark, "Concurrent Marking") \ 70 SHENANDOAH_PAR_PHASE_DO(conc_mark, " CM: ", f) \ 71 f(conc_mark_satb_flush, " Flush SATB") \ 72 \ 73 f(final_mark_gross, "Pause Final Mark (G)") \ 74 f(final_mark, "Pause Final Mark (N)") \ 75 f(final_mark_verify, " Verify") \ 76 f(finish_mark, " Finish Mark") \ 77 f(final_mark_propagate_gc_state, " Propagate GC State") \ 78 SHENANDOAH_PAR_PHASE_DO(finish_mark_, " FM: ", f) \ 79 f(purge, " System Purge") \ 80 SHENANDOAH_PAR_PHASE_DO(purge_cu_par_, " CU: ", f) \ 81 f(purge_weak_par, " Weak Roots") \ 82 SHENANDOAH_PAR_PHASE_DO(purge_weak_par_, " WR: ", f) \ 83 f(final_update_region_states, " Update Region States") \ 84 f(final_manage_labs, " Manage GC/TLABs") \ 85 f(choose_cset, " Choose Collection Set") \ 86 f(final_rebuild_freeset, " Rebuild Free Set") \ 87 f(init_evac, " Initial Evacuation") \ 88 SHENANDOAH_PAR_PHASE_DO(evac_, " E: ", f) \ 89 \ 90 f(conc_thread_roots, "Concurrent Thread Roots") \ 91 SHENANDOAH_PAR_PHASE_DO(conc_thread_roots_, " CTR: ", f) \ 92 f(conc_weak_refs, "Concurrent Weak References") \ 93 SHENANDOAH_PAR_PHASE_DO(conc_weak_refs_, " CWRF: ", f) \ 94 f(conc_weak_roots, "Concurrent Weak Roots") \ 95 f(conc_weak_roots_work, " Roots") \ 96 SHENANDOAH_PAR_PHASE_DO(conc_weak_roots_work_, " CWR: ", f) \ 97 f(conc_weak_roots_rendezvous, " Rendezvous") \ 98 f(conc_cleanup_early, "Concurrent Cleanup") \ 99 f(conc_class_unload, "Concurrent Class Unloading") \ 100 f(conc_class_unload_unlink, " Unlink Stale") \ 101 f(conc_class_unload_unlink_sd, " System Dictionary") \ 102 f(conc_class_unload_unlink_weak_klass, " Weak Class Links") \ 103 f(conc_class_unload_unlink_code_roots, " Code Roots") \ 104 f(conc_class_unload_rendezvous, " Rendezvous") \ 105 f(conc_class_unload_purge, " Purge Unlinked") \ 106 f(conc_class_unload_purge_coderoots, " Code Roots") \ 107 f(conc_class_unload_purge_cldg, " CLDG") \ 108 f(conc_class_unload_purge_ec, " Exception Caches") \ 109 f(conc_strong_roots, "Concurrent Strong Roots") \ 110 SHENANDOAH_PAR_PHASE_DO(conc_strong_roots_, " CSR: ", f) \ 111 f(conc_evac, "Concurrent Evacuation") \ 112 f(conc_final_roots, "Concurrent Final Roots") \ 113 f(promote_in_place, " Promote Regions") \ 114 f(final_roots_gross, "Pause Verify Final Roots (G)") \ 115 f(final_roots, "Pause Verify Final Roots (N)") \ 116 \ 117 f(init_update_refs_gross, "Pause Init Update Refs (G)") \ 118 f(init_update_refs, "Pause Init Update Refs (N)") \ 119 f(init_update_refs_verify, " Verify") \ 120 \ 121 f(conc_update_refs_prepare, "Concurrent Update Refs Prepare") \ 122 f(conc_update_refs, "Concurrent Update Refs") \ 123 f(conc_update_thread_roots, "Concurrent Update Thread Roots") \ 124 \ 125 f(final_update_refs_gross, "Pause Final Update Refs (G)") \ 126 f(final_update_refs, "Pause Final Update Refs (N)") \ 127 f(final_update_refs_verify, " Verify") \ 128 f(final_update_refs_update_region_states, " Update Region States") \ 129 f(final_update_refs_trash_cset, " Trash Collection Set") \ 130 f(final_update_refs_rebuild_freeset, " Rebuild Free Set") \ 131 f(final_update_refs_propagate_gc_state, " Propagate GC State") \ 132 \ 133 f(conc_cleanup_complete, "Concurrent Cleanup") \ 134 f(conc_coalesce_and_fill, "Concurrent Coalesce and Fill") \ 135 SHENANDOAH_PAR_PHASE_DO(conc_coalesce_, " CC&F: ", f) \ 136 \ 137 f(degen_gc_gross, "Pause Degenerated GC (G)") \ 138 f(degen_gc, "Pause Degenerated GC (N)") \ 139 f(degen_gc_stw_mark, " Degen STW Mark") \ 140 SHENANDOAH_PAR_PHASE_DO(degen_gc_stw_mark_, " DSM: ", f) \ 141 f(degen_gc_mark, " Degen Mark") \ 142 SHENANDOAH_PAR_PHASE_DO(degen_gc_mark_, " DM: ", f) \ 143 f(degen_gc_purge, " System Purge") \ 144 f(degen_gc_weakrefs, " Weak References") \ 145 SHENANDOAH_PAR_PHASE_DO(degen_gc_weakrefs_p_, " WRP: ", f) \ 146 f(degen_gc_purge_class_unload, " Unload Classes") \ 147 SHENANDOAH_PAR_PHASE_DO(degen_gc_purge_cu_par_, " DCU: ", f) \ 148 f(degen_gc_purge_weak_par, " Weak Roots") \ 149 SHENANDOAH_PAR_PHASE_DO(degen_gc_purge_weak_p_, " DWR: ", f) \ 150 f(degen_gc_purge_cldg, " CLDG") \ 151 f(degen_gc_final_update_region_states, " Update Region States") \ 152 f(degen_gc_final_manage_labs, " Manage GC/TLABs") \ 153 f(degen_gc_choose_cset, " Choose Collection Set") \ 154 f(degen_gc_final_rebuild_freeset, " Rebuild Free Set") \ 155 f(degen_gc_stw_evac, " Evacuation") \ 156 f(degen_gc_init_update_refs_manage_gclabs, " Manage GCLABs") \ 157 f(degen_gc_update_refs, " Update References") \ 158 f(degen_gc_final_update_refs_update_region_states," Update Region States") \ 159 f(degen_gc_final_update_refs_trash_cset, " Trash Collection Set") \ 160 f(degen_gc_final_update_refs_rebuild_freeset, " Rebuild Free Set") \ 161 f(degen_gc_update_roots, " Degen Update Roots") \ 162 SHENANDOAH_PAR_PHASE_DO(degen_gc_update_, " DU: ", f) \ 163 f(degen_gc_cleanup_complete, " Cleanup") \ 164 f(degen_gc_promote_regions, " Degen Promote Regions") \ 165 f(degen_gc_coalesce_and_fill, " Degen Coalesce and Fill") \ 166 SHENANDOAH_PAR_PHASE_DO(degen_coalesce_, " DC&F", f) \ 167 f(degen_gc_propagate_gc_state, " Propagate GC State") \ 168 \ 169 f(full_gc_gross, "Pause Full GC (G)") \ 170 f(full_gc, "Pause Full GC (N)") \ 171 f(full_gc_heapdump_pre, " Pre Heap Dump") \ 172 f(full_gc_prepare, " Prepare") \ 173 f(full_gc_update_roots, " Update Roots") \ 174 SHENANDOAH_PAR_PHASE_DO(full_gc_update_roots_, " FU: ", f) \ 175 f(full_gc_mark, " Mark") \ 176 SHENANDOAH_PAR_PHASE_DO(full_gc_mark_, " FM: ", f) \ 177 f(full_gc_purge, " System Purge") \ 178 f(full_gc_weakrefs, " Weak References") \ 179 SHENANDOAH_PAR_PHASE_DO(full_gc_weakrefs_p_, " WRP: ", f) \ 180 f(full_gc_purge_class_unload, " Unload Classes") \ 181 SHENANDOAH_PAR_PHASE_DO(full_gc_purge_cu_par_, " CU: ", f) \ 182 f(full_gc_purge_weak_par, " Weak Roots") \ 183 SHENANDOAH_PAR_PHASE_DO(full_gc_purge_weak_p_, " WR: ", f) \ 184 f(full_gc_purge_cldg, " CLDG") \ 185 f(full_gc_calculate_addresses, " Calculate Addresses") \ 186 f(full_gc_calculate_addresses_regular, " Regular Objects") \ 187 f(full_gc_calculate_addresses_humong, " Humongous Objects") \ 188 f(full_gc_adjust_pointers, " Adjust Pointers") \ 189 f(full_gc_adjust_roots, " Adjust Roots") \ 190 SHENANDOAH_PAR_PHASE_DO(full_gc_adjust_roots_, " FA: ", f) \ 191 f(full_gc_copy_objects, " Copy Objects") \ 192 f(full_gc_copy_objects_regular, " Regular Objects") \ 193 f(full_gc_copy_objects_humong, " Humongous Objects") \ 194 f(full_gc_recompute_generation_usage, " Recompute generation usage") \ 195 f(full_gc_copy_objects_reset_complete, " Reset Complete Bitmap") \ 196 f(full_gc_copy_objects_rebuild, " Rebuild Region Sets") \ 197 f(full_gc_reconstruct_remembered_set, " Reconstruct Remembered Set") \ 198 f(full_gc_heapdump_post, " Post Heap Dump") \ 199 f(full_gc_propagate_gc_state, " Propagate GC State") \ 200 \ 201 f(pacing, "Pacing") \ 202 \ 203 f(heap_iteration_roots, "Heap Iteration") \ 204 SHENANDOAH_PAR_PHASE_DO(heap_iteration_roots_, " HI: ", f) \ 205 // end 206 207 typedef WorkerDataArray<double> ShenandoahWorkerData; 208 209 class ShenandoahPhaseTimings : public CHeapObj<mtGC> { 210 friend class ShenandoahGCPhase; 211 friend class ShenandoahWorkerTimingsTracker; 212 public: 213 #define SHENANDOAH_PHASE_DECLARE_ENUM(type, title) type, 214 215 enum Phase { 216 SHENANDOAH_PHASE_DO(SHENANDOAH_PHASE_DECLARE_ENUM) 217 _num_phases, 218 _invalid_phase = _num_phases 219 }; 220 221 enum ParPhase { 222 SHENANDOAH_PAR_PHASE_DO(,, SHENANDOAH_PHASE_DECLARE_ENUM) 223 _num_par_phases 224 }; 225 226 #undef SHENANDOAH_PHASE_DECLARE_ENUM 227 228 private: 229 uint _max_workers; 230 double _cycle_data[_num_phases]; 231 HdrSeq _global_data[_num_phases]; 232 static const char* _phase_names[_num_phases]; 233 234 ShenandoahWorkerData* _worker_data[_num_phases]; 235 ShenandoahCollectorPolicy* _policy; 236 237 static bool is_worker_phase(Phase phase); 238 static bool is_root_work_phase(Phase phase); 239 240 ShenandoahWorkerData* worker_data(Phase phase, ParPhase par_phase); 241 Phase worker_par_phase(Phase phase, ParPhase par_phase); 242 243 void set_cycle_data(Phase phase, double time, bool should_aggregate = false); 244 static double uninitialized() { return -1; } 245 246 public: 247 ShenandoahPhaseTimings(uint max_workers); 248 249 void record_phase_time(Phase phase, double time, bool should_aggregate = false); 250 251 void record_workers_start(Phase phase); 252 void record_workers_end(Phase phase); 253 254 void flush_par_workers_to_cycle(); 255 void flush_cycle_to_global(); 256 257 static const char* phase_name(Phase phase) { 258 assert(phase >= 0 && phase < _num_phases, "Out of bound"); 259 return _phase_names[phase]; 260 } 261 262 void print_cycle_on(outputStream* out) const; 263 void print_global_on(outputStream* out) const; 264 }; 265 266 class ShenandoahWorkerTimingsTracker : public StackObj { 267 private: 268 ShenandoahPhaseTimings* const _timings; 269 ShenandoahPhaseTimings::Phase const _phase; 270 ShenandoahPhaseTimings::ParPhase const _par_phase; 271 uint const _worker_id; 272 273 double _start_time; 274 EventGCPhaseParallel _event; 275 public: 276 ShenandoahWorkerTimingsTracker(ShenandoahPhaseTimings::Phase phase, 277 ShenandoahPhaseTimings::ParPhase par_phase, 278 uint worker_id, 279 bool cumulative = false); 280 ~ShenandoahWorkerTimingsTracker(); 281 }; 282 283 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHPHASETIMINGS_HPP