1 2 /* 3 * Copyright (c) 2017, 2020, Red Hat, Inc. All rights reserved. 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_VM_GC_SHENANDOAH_SHENANDOAHPHASETIMEINGS_HPP 26 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHPHASETIMEINGS_HPP 27 28 #include "gc/shenandoah/shenandoahNumberSeq.hpp" 29 #include "gc/shared/workerDataArray.hpp" 30 #include "memory/allocation.hpp" 31 32 class ShenandoahCollectorPolicy; 33 class outputStream; 34 35 #define SHENANDOAH_PAR_PHASE_DO(CNT_PREFIX, DESC_PREFIX, f) \ 36 f(CNT_PREFIX ## TotalWork, DESC_PREFIX "<total>") \ 37 f(CNT_PREFIX ## ThreadRoots, DESC_PREFIX "Thread Roots") \ 38 f(CNT_PREFIX ## CodeCacheRoots, DESC_PREFIX "Code Cache Roots") \ 39 f(CNT_PREFIX ## UniverseRoots, DESC_PREFIX "Universe Roots") \ 40 f(CNT_PREFIX ## JNIRoots, DESC_PREFIX "JNI Handles Roots") \ 41 f(CNT_PREFIX ## JVMTIWeakRoots, DESC_PREFIX "JVMTI Weak Roots") \ 42 f(CNT_PREFIX ## JFRWeakRoots, DESC_PREFIX "JFR Weak Roots") \ 43 f(CNT_PREFIX ## JNIWeakRoots, DESC_PREFIX "JNI Weak Roots") \ 44 f(CNT_PREFIX ## StringTableRoots, DESC_PREFIX "String Table Roots") \ 45 f(CNT_PREFIX ## ResolvedMethodTableRoots, DESC_PREFIX "Resolved Table Roots") \ 46 f(CNT_PREFIX ## VMGlobalRoots, DESC_PREFIX "VM Global Roots") \ 47 f(CNT_PREFIX ## VMWeakRoots, DESC_PREFIX "VM Weak Roots") \ 48 f(CNT_PREFIX ## ObjectSynchronizerRoots, DESC_PREFIX "Synchronizer Roots") \ 49 f(CNT_PREFIX ## ManagementRoots, DESC_PREFIX "Management Roots") \ 50 f(CNT_PREFIX ## SystemDictionaryRoots, DESC_PREFIX "System Dict 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(accumulate_stats, " Accumulate Stats") \ 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_cleanup_early, "Concurrent Cleanup") \ 94 f(conc_evac, "Concurrent Evacuation") \ 95 \ 96 f(init_update_refs_gross, "Pause Init Update Refs (G)") \ 97 f(init_update_refs, "Pause Init Update Refs (N)") \ 98 f(init_update_refs_retire_gclabs, " Retire GCLABs") \ 99 \ 100 f(conc_update_refs, "Concurrent Update Refs") \ 101 \ 102 f(final_update_refs_gross, "Pause Final Update Refs (G)") \ 103 f(final_update_refs, "Pause Final Update Refs (N)") \ 104 f(final_update_refs_finish_work, " Finish Work") \ 105 f(final_update_refs_roots, " Update Roots") \ 106 SHENANDOAH_PAR_PHASE_DO(final_update_, " UR: ", f) \ 107 f(final_update_refs_update_region_states, " Update Region States") \ 108 f(final_update_refs_trash_cset, " Trash Collection Set") \ 109 f(final_update_refs_rebuild_freeset, " Rebuild Free Set") \ 110 \ 111 f(conc_cleanup_complete, "Concurrent Cleanup") \ 112 \ 113 f(degen_gc_gross, "Pause Degenerated GC (G)") \ 114 f(degen_gc, "Pause Degenerated GC (N)") \ 115 f(degen_gc_update_roots, " Degen Update Roots") \ 116 SHENANDOAH_PAR_PHASE_DO(degen_gc_update_, " DU: ", f) \ 117 \ 118 f(full_gc_gross, "Pause Full GC (G)") \ 119 f(full_gc, "Pause Full GC (N)") \ 120 f(full_gc_heapdump_pre, " Pre Heap Dump") \ 121 f(full_gc_prepare, " Prepare") \ 122 f(full_gc_scan_roots, " Scan Roots") \ 123 SHENANDOAH_PAR_PHASE_DO(full_gc_scan_roots_, " FS: ", f) \ 124 f(full_gc_update_roots, " Update Roots") \ 125 SHENANDOAH_PAR_PHASE_DO(full_gc_update_roots_, " FU: ", f) \ 126 f(full_gc_mark, " Mark") \ 127 f(full_gc_mark_finish_queues, " Finish Queues") \ 128 f(full_gc_weakrefs, " Weak References") \ 129 f(full_gc_weakrefs_process, " Process") \ 130 f(full_gc_purge, " System Purge") \ 131 f(full_gc_purge_class_unload, " Unload Classes") \ 132 SHENANDOAH_PAR_PHASE_DO(full_gc_purge_cu_par_, " CU: ", f) \ 133 f(full_gc_purge_weak_par, " Weak Roots") \ 134 SHENANDOAH_PAR_PHASE_DO(full_gc_purge_weak_p_, " WR: ", f) \ 135 f(full_gc_purge_cldg, " CLDG") \ 136 f(full_gc_calculate_addresses, " Calculate Addresses") \ 137 f(full_gc_calculate_addresses_regular, " Regular Objects") \ 138 f(full_gc_calculate_addresses_humong, " Humongous Objects") \ 139 f(full_gc_adjust_pointers, " Adjust Pointers") \ 140 f(full_gc_adjust_roots, " Adjust Roots") \ 141 SHENANDOAH_PAR_PHASE_DO(full_gc_adjust_roots_, " FA: ", f) \ 142 f(full_gc_copy_objects, " Copy Objects") \ 143 f(full_gc_copy_objects_regular, " Regular Objects") \ 144 f(full_gc_copy_objects_humong, " Humongous Objects") \ 145 f(full_gc_copy_objects_reset_complete, " Reset Complete Bitmap") \ 146 f(full_gc_copy_objects_rebuild, " Rebuild Region Sets") \ 147 f(full_gc_resize_tlabs, " Resize TLABs") \ 148 f(full_gc_heapdump_post, " Post Heap Dump") \ 149 \ 150 f(conc_uncommit, "Concurrent Uncommit") \ 151 \ 152 f(heap_iteration_roots, "Heap Iteration") \ 153 SHENANDOAH_PAR_PHASE_DO(heap_iteration_roots_, " HI: ", f) \ 154 // end 155 156 typedef WorkerDataArray<double> ShenandoahWorkerData; 157 158 class ShenandoahPhaseTimings : public CHeapObj<mtGC> { 159 friend class ShenandoahGCPhase; 160 friend class ShenandoahWorkerTimingsTracker; 161 public: 162 #define SHENANDOAH_PHASE_DECLARE_ENUM(type, title) type, 163 164 enum Phase { 165 SHENANDOAH_PHASE_DO(SHENANDOAH_PHASE_DECLARE_ENUM) 166 _num_phases, 167 _invalid_phase = _num_phases 168 }; 169 170 enum ParPhase { 171 SHENANDOAH_PAR_PHASE_DO(,, SHENANDOAH_PHASE_DECLARE_ENUM) 172 _num_par_phases 173 }; 174 175 #undef SHENANDOAH_PHASE_DECLARE_ENUM 176 177 private: 178 uint _max_workers; 179 double _cycle_data[_num_phases]; 180 HdrSeq _global_data[_num_phases]; 181 static const char* _phase_names[_num_phases]; 182 183 ShenandoahWorkerData* _worker_data[_num_phases]; 184 ShenandoahCollectorPolicy* _policy; 185 186 static bool is_worker_phase(Phase phase); 187 static bool is_root_work_phase(Phase phase); 188 189 ShenandoahWorkerData* worker_data(Phase phase, ParPhase par_phase); 190 Phase worker_par_phase(Phase phase, ParPhase par_phase); 191 192 void set_cycle_data(Phase phase, double time); 193 static double uninitialized() { return -1; } 194 195 public: 196 ShenandoahPhaseTimings(uint max_workers); 197 198 void record_phase_time(Phase phase, double time); 199 200 void record_workers_start(Phase phase); 201 void record_workers_end(Phase phase); 202 203 void flush_par_workers_to_cycle(); 204 void flush_cycle_to_global(); 205 206 static const char* phase_name(Phase phase) { 207 assert(phase >= 0 && phase < _num_phases, "Out of bound"); 208 return _phase_names[phase]; 209 } 210 211 void print_cycle_on(outputStream* out) const; 212 void print_global_on(outputStream* out) const; 213 }; 214 215 class ShenandoahWorkerTimingsTracker : public StackObj { 216 private: 217 ShenandoahPhaseTimings* const _timings; 218 ShenandoahPhaseTimings::Phase const _phase; 219 ShenandoahPhaseTimings::ParPhase const _par_phase; 220 uint const _worker_id; 221 222 double _start_time; 223 public: 224 ShenandoahWorkerTimingsTracker(ShenandoahPhaseTimings::Phase phase, ShenandoahPhaseTimings::ParPhase par_phase, uint worker_id); 225 ~ShenandoahWorkerTimingsTracker(); 226 }; 227 228 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHGCPHASETIMEINGS_HPP