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 ## CLDGRoots, DESC_PREFIX "CLDG Roots") \ 52 f(CNT_PREFIX ## JVMTIRoots, DESC_PREFIX "JVMTI Roots") \ 53 f(CNT_PREFIX ## StringDedupTableRoots, DESC_PREFIX "Dedup Table Roots") \ 54 f(CNT_PREFIX ## StringDedupQueueRoots, DESC_PREFIX "Dedup Queue Roots") \ 55 f(CNT_PREFIX ## FinishQueues, DESC_PREFIX "Finish Queues") \ 56 // end 57 58 #define SHENANDOAH_PHASE_DO(f) \ 59 f(conc_reset, "Concurrent Reset") \ 60 \ 61 f(init_mark_gross, "Pause Init Mark (G)") \ 62 f(init_mark, "Pause Init Mark (N)") \ 63 f(init_manage_tlabs, " Manage TLABs") \ 64 f(init_update_region_states, " Update Region States") \ 65 f(scan_roots, " Scan Roots") \ 66 SHENANDOAH_PAR_PHASE_DO(scan_, " S: ", f) \ 67 \ 68 f(conc_mark, "Concurrent Marking") \ 69 f(conc_mark_roots, " Roots ") \ 70 SHENANDOAH_PAR_PHASE_DO(conc_mark_roots, " CM: ", f) \ 71 \ 72 f(conc_preclean, "Concurrent Precleaning") \ 73 \ 74 f(final_mark_gross, "Pause Final Mark (G)") \ 75 f(final_mark, "Pause Final Mark (N)") \ 76 f(update_roots, " Update Roots") \ 77 SHENANDOAH_PAR_PHASE_DO(update_, " U: ", f) \ 78 f(finish_queues, " Finish Queues") \ 79 f(weakrefs, " Weak References") \ 80 f(weakrefs_process, " Process") \ 81 f(purge, " System Purge") \ 82 f(purge_class_unload, " Unload Classes") \ 83 SHENANDOAH_PAR_PHASE_DO(purge_cu_par_, " CU: ", f) \ 84 f(purge_weak_par, " Weak Roots") \ 85 SHENANDOAH_PAR_PHASE_DO(purge_weak_par_, " WR: ", f) \ 86 f(purge_cldg, " CLDG") \ 87 f(final_update_region_states, " Update Region States") \ 88 f(final_manage_labs, " Manage GC/TLABs") \ 89 f(choose_cset, " Choose Collection Set") \ 90 f(final_rebuild_freeset, " Rebuild Free Set") \ 91 f(init_evac, " Initial Evacuation") \ 92 SHENANDOAH_PAR_PHASE_DO(evac_, " E: ", f) \ 93 \ 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 \ 113 f(init_update_refs_gross, "Pause Init Update Refs (G)") \ 114 f(init_update_refs, "Pause Init Update Refs (N)") \ 115 f(init_update_refs_manage_gclabs, " Manage GCLABs") \ 116 \ 117 f(conc_update_refs, "Concurrent Update Refs") \ 118 \ 119 f(final_update_refs_gross, "Pause Final Update Refs (G)") \ 120 f(final_update_refs, "Pause Final Update Refs (N)") \ 121 f(final_update_refs_finish_work, " Finish Work") \ 122 f(final_update_refs_roots, " Update Roots") \ 123 SHENANDOAH_PAR_PHASE_DO(final_update_, " UR: ", f) \ 124 f(final_update_refs_update_region_states, " Update Region States") \ 125 f(final_update_refs_trash_cset, " Trash Collection Set") \ 126 f(final_update_refs_rebuild_freeset, " Rebuild Free Set") \ 127 \ 128 f(conc_cleanup_complete, "Concurrent Cleanup") \ 129 \ 130 f(degen_gc_gross, "Pause Degenerated GC (G)") \ 131 f(degen_gc, "Pause Degenerated GC (N)") \ 132 f(degen_gc_scan_conc_roots, " Degen Mark Roots") \ 133 SHENANDOAH_PAR_PHASE_DO(degen_gc_conc_mark_, " DM: ", f) \ 134 f(degen_gc_update_roots, " Degen Update Roots") \ 135 SHENANDOAH_PAR_PHASE_DO(degen_gc_update_, " DU: ", f) \ 136 \ 137 f(full_gc_gross, "Pause Full GC (G)") \ 138 f(full_gc, "Pause Full GC (N)") \ 139 f(full_gc_heapdump_pre, " Pre Heap Dump") \ 140 f(full_gc_prepare, " Prepare") \ 141 f(full_gc_scan_roots, " Scan Roots") \ 142 SHENANDOAH_PAR_PHASE_DO(full_gc_scan_roots_, " FS: ", f) \ 143 f(full_gc_scan_conc_roots, " Scan Concurrent Roots") \ 144 SHENANDOAH_PAR_PHASE_DO(full_gc_scan_conc_roots, " FCS: ", f) \ 145 f(full_gc_update_roots, " Update Roots") \ 146 SHENANDOAH_PAR_PHASE_DO(full_gc_update_roots_, " FU: ", f) \ 147 f(full_gc_mark, " Mark") \ 148 f(full_gc_mark_finish_queues, " Finish Queues") \ 149 f(full_gc_weakrefs, " Weak References") \ 150 f(full_gc_weakrefs_process, " Process") \ 151 f(full_gc_purge, " System Purge") \ 152 f(full_gc_purge_class_unload, " Unload Classes") \ 153 SHENANDOAH_PAR_PHASE_DO(full_gc_purge_cu_par_, " CU: ", f) \ 154 f(full_gc_purge_weak_par, " Weak Roots") \ 155 SHENANDOAH_PAR_PHASE_DO(full_gc_purge_weak_p_, " WR: ", f) \ 156 f(full_gc_purge_cldg, " CLDG") \ 157 f(full_gc_calculate_addresses, " Calculate Addresses") \ 158 f(full_gc_calculate_addresses_regular, " Regular Objects") \ 159 f(full_gc_calculate_addresses_humong, " Humongous Objects") \ 160 f(full_gc_adjust_pointers, " Adjust Pointers") \ 161 f(full_gc_adjust_roots, " Adjust Roots") \ 162 SHENANDOAH_PAR_PHASE_DO(full_gc_adjust_roots_, " FA: ", f) \ 163 f(full_gc_copy_objects, " Copy Objects") \ 164 f(full_gc_copy_objects_regular, " Regular Objects") \ 165 f(full_gc_copy_objects_humong, " Humongous Objects") \ 166 f(full_gc_copy_objects_reset_complete, " Reset Complete Bitmap") \ 167 f(full_gc_copy_objects_rebuild, " Rebuild Region Sets") \ 168 f(full_gc_heapdump_post, " Post Heap Dump") \ 169 \ 170 f(conc_uncommit, "Concurrent Uncommit") \ 171 \ 172 f(heap_iteration_roots, "Heap Iteration") \ 173 SHENANDOAH_PAR_PHASE_DO(heap_iteration_roots_, " HI: ", f) \ 174 // end 175 176 typedef WorkerDataArray<double> ShenandoahWorkerData; 177 178 class ShenandoahPhaseTimings : public CHeapObj<mtGC> { 179 friend class ShenandoahGCPhase; 180 friend class ShenandoahWorkerTimingsTracker; 181 public: 182 #define SHENANDOAH_PHASE_DECLARE_ENUM(type, title) type, 183 184 enum Phase { 185 SHENANDOAH_PHASE_DO(SHENANDOAH_PHASE_DECLARE_ENUM) 186 _num_phases, 187 _invalid_phase = _num_phases 188 }; 189 190 enum ParPhase { 191 SHENANDOAH_PAR_PHASE_DO(,, SHENANDOAH_PHASE_DECLARE_ENUM) 192 _num_par_phases 193 }; 194 195 #undef SHENANDOAH_PHASE_DECLARE_ENUM 196 197 private: 198 uint _max_workers; 199 double _cycle_data[_num_phases]; 200 HdrSeq _global_data[_num_phases]; 201 static const char* _phase_names[_num_phases]; 202 203 ShenandoahWorkerData* _worker_data[_num_phases]; 204 ShenandoahCollectorPolicy* _policy; 205 206 static bool is_worker_phase(Phase phase); 207 static bool is_root_work_phase(Phase phase); 208 209 ShenandoahWorkerData* worker_data(Phase phase, ParPhase par_phase); 210 Phase worker_par_phase(Phase phase, ParPhase par_phase); 211 212 void set_cycle_data(Phase phase, double time); 213 static double uninitialized() { return -1; } 214 215 public: 216 ShenandoahPhaseTimings(uint max_workers); 217 218 void record_phase_time(Phase phase, double time); 219 220 void record_workers_start(Phase phase); 221 void record_workers_end(Phase phase); 222 223 void flush_par_workers_to_cycle(); 224 void flush_cycle_to_global(); 225 226 static const char* phase_name(Phase phase) { 227 assert(phase >= 0 && phase < _num_phases, "Out of bound"); 228 return _phase_names[phase]; 229 } 230 231 void print_cycle_on(outputStream* out) const; 232 void print_global_on(outputStream* out) const; 233 }; 234 235 class ShenandoahWorkerTimingsTracker : public StackObj { 236 private: 237 ShenandoahPhaseTimings* const _timings; 238 ShenandoahPhaseTimings::Phase const _phase; 239 ShenandoahPhaseTimings::ParPhase const _par_phase; 240 uint const _worker_id; 241 242 double _start_time; 243 EventGCPhaseParallel _event; 244 public: 245 ShenandoahWorkerTimingsTracker(ShenandoahPhaseTimings::Phase phase, ShenandoahPhaseTimings::ParPhase par_phase, uint worker_id); 246 ~ShenandoahWorkerTimingsTracker(); 247 }; 248 249 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHPHASETIMINGS_HPP