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 SHENANDOAH_PAR_PHASE_DO(conc_weak_roots_, " CWR: ", f) \ 95 f(conc_cleanup_early, "Concurrent Cleanup") \ 96 f(conc_class_unloading, "Concurrent Class Unloading") \ 97 f(conc_strong_roots, "Concurrent Strong Roots") \ 98 SHENANDOAH_PAR_PHASE_DO(conc_strong_roots_, " CSR: ", f) \ 99 f(conc_evac, "Concurrent Evacuation") \ 100 \ 101 f(init_update_refs_gross, "Pause Init Update Refs (G)") \ 102 f(init_update_refs, "Pause Init Update Refs (N)") \ 103 f(init_update_refs_retire_gclabs, " Retire GCLABs") \ 104 \ 105 f(conc_update_refs, "Concurrent Update Refs") \ 106 \ 107 f(final_update_refs_gross, "Pause Final Update Refs (G)") \ 108 f(final_update_refs, "Pause Final Update Refs (N)") \ 109 f(final_update_refs_finish_work, " Finish Work") \ 110 f(final_update_refs_roots, " Update Roots") \ 111 SHENANDOAH_PAR_PHASE_DO(final_update_, " UR: ", f) \ 112 f(final_update_refs_update_region_states, " Update Region States") \ 113 f(final_update_refs_trash_cset, " Trash Collection Set") \ 114 f(final_update_refs_rebuild_freeset, " Rebuild Free Set") \ 115 \ 116 f(conc_cleanup_complete, "Concurrent Cleanup") \ 117 \ 118 f(degen_gc_gross, "Pause Degenerated GC (G)") \ 119 f(degen_gc, "Pause Degenerated GC (N)") \ 120 f(degen_gc_update_roots, " Degen Update Roots") \ 121 SHENANDOAH_PAR_PHASE_DO(degen_gc_update_, " DU: ", f) \ 122 \ 123 f(full_gc_gross, "Pause Full GC (G)") \ 124 f(full_gc, "Pause Full GC (N)") \ 125 f(full_gc_heapdump_pre, " Pre Heap Dump") \ 126 f(full_gc_prepare, " Prepare") \ 127 f(full_gc_scan_roots, " Scan Roots") \ 128 SHENANDOAH_PAR_PHASE_DO(full_gc_scan_roots_, " FS: ", f) \ 129 f(full_gc_update_roots, " Update Roots") \ 130 SHENANDOAH_PAR_PHASE_DO(full_gc_update_roots_, " FU: ", f) \ 131 f(full_gc_mark, " Mark") \ 132 f(full_gc_mark_finish_queues, " Finish Queues") \ 133 f(full_gc_weakrefs, " Weak References") \ 134 f(full_gc_weakrefs_process, " Process") \ 135 f(full_gc_purge, " System Purge") \ 136 f(full_gc_purge_class_unload, " Unload Classes") \ 137 SHENANDOAH_PAR_PHASE_DO(full_gc_purge_cu_par_, " CU: ", f) \ 138 f(full_gc_purge_weak_par, " Weak Roots") \ 139 SHENANDOAH_PAR_PHASE_DO(full_gc_purge_weak_p_, " WR: ", f) \ 140 f(full_gc_purge_cldg, " CLDG") \ 141 f(full_gc_calculate_addresses, " Calculate Addresses") \ 142 f(full_gc_calculate_addresses_regular, " Regular Objects") \ 143 f(full_gc_calculate_addresses_humong, " Humongous Objects") \ 144 f(full_gc_adjust_pointers, " Adjust Pointers") \ 145 f(full_gc_adjust_roots, " Adjust Roots") \ 146 SHENANDOAH_PAR_PHASE_DO(full_gc_adjust_roots_, " FA: ", f) \ 147 f(full_gc_copy_objects, " Copy Objects") \ 148 f(full_gc_copy_objects_regular, " Regular Objects") \ 149 f(full_gc_copy_objects_humong, " Humongous Objects") \ 150 f(full_gc_copy_objects_reset_complete, " Reset Complete Bitmap") \ 151 f(full_gc_copy_objects_rebuild, " Rebuild Region Sets") \ 152 f(full_gc_resize_tlabs, " Resize TLABs") \ 153 f(full_gc_heapdump_post, " Post Heap Dump") \ 154 \ 155 f(conc_uncommit, "Concurrent Uncommit") \ 156 \ 157 f(heap_iteration_roots, "Heap Iteration") \ 158 SHENANDOAH_PAR_PHASE_DO(heap_iteration_roots_, " HI: ", f) \ 159 // end 160 161 typedef WorkerDataArray<double> ShenandoahWorkerData; 162 163 class ShenandoahPhaseTimings : public CHeapObj<mtGC> { 164 friend class ShenandoahGCPhase; 165 friend class ShenandoahWorkerTimingsTracker; 166 public: 167 #define SHENANDOAH_PHASE_DECLARE_ENUM(type, title) type, 168 169 enum Phase { 170 SHENANDOAH_PHASE_DO(SHENANDOAH_PHASE_DECLARE_ENUM) 171 _num_phases, 172 _invalid_phase = _num_phases 173 }; 174 175 enum ParPhase { 176 SHENANDOAH_PAR_PHASE_DO(,, SHENANDOAH_PHASE_DECLARE_ENUM) 177 _num_par_phases 178 }; 179 180 #undef SHENANDOAH_PHASE_DECLARE_ENUM 181 182 private: 183 uint _max_workers; 184 double _cycle_data[_num_phases]; 185 HdrSeq _global_data[_num_phases]; 186 static const char* _phase_names[_num_phases]; 187 188 ShenandoahWorkerData* _worker_data[_num_phases]; 189 ShenandoahCollectorPolicy* _policy; 190 191 static bool is_worker_phase(Phase phase); 192 static bool is_root_work_phase(Phase phase); 193 194 ShenandoahWorkerData* worker_data(Phase phase, ParPhase par_phase); 195 Phase worker_par_phase(Phase phase, ParPhase par_phase); 196 197 void set_cycle_data(Phase phase, double time); 198 static double uninitialized() { return -1; } 199 200 public: 201 ShenandoahPhaseTimings(uint _max_workers); 202 203 void record_phase_time(Phase phase, double time); 204 205 void record_workers_start(Phase phase); 206 void record_workers_end(Phase phase); 207 208 void flush_par_workers_to_cycle(); 209 void flush_cycle_to_global(); 210 211 static const char* phase_name(Phase phase) { 212 assert(phase >= 0 && phase < _num_phases, "Out of bound"); 213 return _phase_names[phase]; 214 } 215 216 void print_cycle_on(outputStream* out) const; 217 void print_global_on(outputStream* out) const; 218 }; 219 220 class ShenandoahWorkerTimingsTracker : public StackObj { 221 private: 222 ShenandoahPhaseTimings* const _timings; 223 ShenandoahPhaseTimings::Phase const _phase; 224 ShenandoahPhaseTimings::ParPhase const _par_phase; 225 uint const _worker_id; 226 227 double _start_time; 228 EventGCPhaseParallel _event; 229 public: 230 ShenandoahWorkerTimingsTracker(ShenandoahPhaseTimings::Phase phase, ShenandoahPhaseTimings::ParPhase par_phase, uint worker_id); 231 ~ShenandoahWorkerTimingsTracker(); 232 }; 233 234 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHPHASETIMINGS_HPP