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_mark_roots, " Concurrent Mark Roots ") \ 72 SHENANDOAH_PAR_PHASE_DO(conc_mark_roots, " CM: ", f) \ 73 \ 74 f(conc_preclean, "Concurrent Precleaning") \ 75 \ 76 f(final_mark_gross, "Pause Final Mark (G)") \ 77 f(final_mark, "Pause Final Mark (N)") \ 78 f(update_roots, " Update Roots") \ 79 SHENANDOAH_PAR_PHASE_DO(update_, " U: ", f) \ 80 f(finish_queues, " Finish Queues") \ 81 f(weakrefs, " Weak References") \ 82 f(weakrefs_process, " Process") \ 83 f(purge, " System Purge") \ 84 f(purge_class_unload, " Unload Classes") \ 85 SHENANDOAH_PAR_PHASE_DO(purge_cu_par_, " CU: ", f) \ 86 f(purge_weak_par, " Weak Roots") \ 87 SHENANDOAH_PAR_PHASE_DO(purge_weak_par_, " WR: ", f) \ 88 f(purge_cldg, " CLDG") \ 89 f(final_update_region_states, " Update Region States") \ 90 f(retire_tlabs, " Retire TLABs") \ 91 f(choose_cset, " Choose Collection Set") \ 92 f(final_rebuild_freeset, " Rebuild Free Set") \ 93 f(init_evac, " Initial Evacuation") \ 94 SHENANDOAH_PAR_PHASE_DO(evac_, " E: ", f) \ 95 \ 96 f(conc_weak_roots, "Concurrent Weak Roots") \ 97 f(conc_weak_roots_work, " Roots") \ 98 SHENANDOAH_PAR_PHASE_DO(conc_weak_roots_work_, " CWR: ", f) \ 99 f(conc_weak_roots_rendezvous, " Rendezvous") \ 100 f(conc_cleanup_early, "Concurrent Cleanup") \ 101 f(conc_class_unload, "Concurrent Class Unloading") \ 102 f(conc_class_unload_unlink, " Unlink Stale") \ 103 f(conc_class_unload_unlink_sd, " System Dictionary") \ 104 f(conc_class_unload_unlink_weak_klass, " Weak Class Links") \ 105 f(conc_class_unload_unlink_code_roots, " Code Roots") \ 106 f(conc_class_unload_rendezvous, " Rendezvous") \ 107 f(conc_class_unload_purge, " Purge Unlinked") \ 108 f(conc_class_unload_purge_coderoots, " Code Roots") \ 109 f(conc_class_unload_purge_cldg, " CLDG") \ 110 f(conc_class_unload_purge_ec, " Exception Caches") \ 111 f(conc_strong_roots, "Concurrent Strong Roots") \ 112 SHENANDOAH_PAR_PHASE_DO(conc_strong_roots_, " CSR: ", f) \ 113 f(conc_evac, "Concurrent Evacuation") \ 114 \ 115 f(init_update_refs_gross, "Pause Init Update Refs (G)") \ 116 f(init_update_refs, "Pause Init Update Refs (N)") \ 117 f(init_update_refs_retire_gclabs, " Retire GCLABs") \ 118 \ 119 f(conc_update_refs, "Concurrent Update Refs") \ 120 \ 121 f(final_update_refs_gross, "Pause Final Update Refs (G)") \ 122 f(final_update_refs, "Pause Final Update Refs (N)") \ 123 f(final_update_refs_finish_work, " Finish Work") \ 124 f(final_update_refs_roots, " Update Roots") \ 125 SHENANDOAH_PAR_PHASE_DO(final_update_, " UR: ", f) \ 126 f(final_update_refs_update_region_states, " Update Region States") \ 127 f(final_update_refs_trash_cset, " Trash Collection Set") \ 128 f(final_update_refs_rebuild_freeset, " Rebuild Free Set") \ 129 \ 130 f(conc_cleanup_complete, "Concurrent Cleanup") \ 131 \ 132 f(degen_gc_gross, "Pause Degenerated GC (G)") \ 133 f(degen_gc, "Pause Degenerated GC (N)") \ 134 f(degen_gc_scan_conc_roots, " Degen Mark Roots") \ 135 SHENANDOAH_PAR_PHASE_DO(degen_gc_conc_mark_, " DM: ", f) \ 136 f(degen_gc_update_roots, " Degen Update Roots") \ 137 SHENANDOAH_PAR_PHASE_DO(degen_gc_update_, " DU: ", f) \ 138 \ 139 f(full_gc_gross, "Pause Full GC (G)") \ 140 f(full_gc, "Pause Full GC (N)") \ 141 f(full_gc_heapdump_pre, " Pre Heap Dump") \ 142 f(full_gc_prepare, " Prepare") \ 143 f(full_gc_scan_roots, " Scan Roots") \ 144 SHENANDOAH_PAR_PHASE_DO(full_gc_scan_roots_, " FS: ", f) \ 145 f(full_gc_scan_conc_roots, " Scan Concurrnet Roots") \ 146 SHENANDOAH_PAR_PHASE_DO(full_gc_scan_conc_roots, " FCS: ", f) \ 147 f(full_gc_update_roots, " Update Roots") \ 148 SHENANDOAH_PAR_PHASE_DO(full_gc_update_roots_, " FU: ", f) \ 149 f(full_gc_mark, " Mark") \ 150 f(full_gc_mark_finish_queues, " Finish Queues") \ 151 f(full_gc_weakrefs, " Weak References") \ 152 f(full_gc_weakrefs_process, " Process") \ 153 f(full_gc_purge, " System Purge") \ 154 f(full_gc_purge_class_unload, " Unload Classes") \ 155 SHENANDOAH_PAR_PHASE_DO(full_gc_purge_cu_par_, " CU: ", f) \ 156 f(full_gc_purge_weak_par, " Weak Roots") \ 157 SHENANDOAH_PAR_PHASE_DO(full_gc_purge_weak_p_, " WR: ", f) \ 158 f(full_gc_purge_cldg, " CLDG") \ 159 f(full_gc_calculate_addresses, " Calculate Addresses") \ 160 f(full_gc_calculate_addresses_regular, " Regular Objects") \ 161 f(full_gc_calculate_addresses_humong, " Humongous Objects") \ 162 f(full_gc_adjust_pointers, " Adjust Pointers") \ 163 f(full_gc_adjust_roots, " Adjust Roots") \ 164 SHENANDOAH_PAR_PHASE_DO(full_gc_adjust_roots_, " FA: ", f) \ 165 f(full_gc_copy_objects, " Copy Objects") \ 166 f(full_gc_copy_objects_regular, " Regular Objects") \ 167 f(full_gc_copy_objects_humong, " Humongous Objects") \ 168 f(full_gc_copy_objects_reset_complete, " Reset Complete Bitmap") \ 169 f(full_gc_copy_objects_rebuild, " Rebuild Region Sets") \ 170 f(full_gc_resize_tlabs, " Resize TLABs") \ 171 f(full_gc_heapdump_post, " Post Heap Dump") \ 172 \ 173 f(conc_uncommit, "Concurrent Uncommit") \ 174 \ 175 f(heap_iteration_roots, "Heap Iteration") \ 176 SHENANDOAH_PAR_PHASE_DO(heap_iteration_roots_, " HI: ", f) \ 177 // end 178 179 typedef WorkerDataArray<double> ShenandoahWorkerData; 180 181 class ShenandoahPhaseTimings : public CHeapObj<mtGC> { 182 friend class ShenandoahGCPhase; 183 friend class ShenandoahWorkerTimingsTracker; 184 public: 185 #define SHENANDOAH_PHASE_DECLARE_ENUM(type, title) type, 186 187 enum Phase { 188 SHENANDOAH_PHASE_DO(SHENANDOAH_PHASE_DECLARE_ENUM) 189 _num_phases, 190 _invalid_phase = _num_phases 191 }; 192 193 enum ParPhase { 194 SHENANDOAH_PAR_PHASE_DO(,, SHENANDOAH_PHASE_DECLARE_ENUM) 195 _num_par_phases 196 }; 197 198 #undef SHENANDOAH_PHASE_DECLARE_ENUM 199 200 private: 201 uint _max_workers; 202 double _cycle_data[_num_phases]; 203 HdrSeq _global_data[_num_phases]; 204 static const char* _phase_names[_num_phases]; 205 206 ShenandoahWorkerData* _worker_data[_num_phases]; 207 ShenandoahCollectorPolicy* _policy; 208 209 static bool is_worker_phase(Phase phase); 210 static bool is_root_work_phase(Phase phase); 211 212 ShenandoahWorkerData* worker_data(Phase phase, ParPhase par_phase); 213 Phase worker_par_phase(Phase phase, ParPhase par_phase); 214 215 void set_cycle_data(Phase phase, double time); 216 static double uninitialized() { return -1; } 217 218 public: 219 ShenandoahPhaseTimings(uint max_workers); 220 221 void record_phase_time(Phase phase, double time); 222 223 void record_workers_start(Phase phase); 224 void record_workers_end(Phase phase); 225 226 void flush_par_workers_to_cycle(); 227 void flush_cycle_to_global(); 228 229 static const char* phase_name(Phase phase) { 230 assert(phase >= 0 && phase < _num_phases, "Out of bound"); 231 return _phase_names[phase]; 232 } 233 234 void print_cycle_on(outputStream* out) const; 235 void print_global_on(outputStream* out) const; 236 }; 237 238 class ShenandoahWorkerTimingsTracker : public StackObj { 239 private: 240 ShenandoahPhaseTimings* const _timings; 241 ShenandoahPhaseTimings::Phase const _phase; 242 ShenandoahPhaseTimings::ParPhase const _par_phase; 243 uint const _worker_id; 244 245 double _start_time; 246 EventGCPhaseParallel _event; 247 public: 248 ShenandoahWorkerTimingsTracker(ShenandoahPhaseTimings::Phase phase, ShenandoahPhaseTimings::ParPhase par_phase, uint worker_id); 249 ~ShenandoahWorkerTimingsTracker(); 250 }; 251 252 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHPHASETIMINGS_HPP