1 2 /* 3 * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates. 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 "memory/allocation.hpp" 29 #include "utilities/numberSeq.hpp" 30 #include "gc_implementation/shenandoah/shenandoahWorkerDataArray.hpp" 31 #include "gc_implementation/shenandoah/shenandoahWorkerDataArray.inline.hpp" 32 33 class ShenandoahCollectorPolicy; 34 class ShenandoahWorkerTimings; 35 class outputStream; 36 37 class ShenandoahPhaseTimings : public CHeapObj<mtGC> { 38 public: 39 enum Phase { 40 total_pause_gross, 41 total_pause, 42 43 init_mark_gross, 44 init_mark, 45 accumulate_stats, 46 make_parsable, 47 clear_liveness, 48 49 // Per-thread timer block, should have "roots" counters in consistent order 50 scan_roots, 51 scan_thread_roots, 52 scan_code_roots, 53 scan_string_table_roots, 54 scan_universe_roots, 55 scan_jni_roots, 56 scan_jni_weak_roots, 57 scan_synchronizer_roots, 58 scan_flat_profiler_roots, 59 scan_management_roots, 60 scan_system_dictionary_roots, 61 scan_cldg_roots, 62 scan_jvmti_roots, 63 scan_finish_queues, 64 65 resize_tlabs, 66 67 final_mark_gross, 68 final_mark, 69 70 // Per-thread timer block, should have "roots" counters in consistent order 71 update_roots, 72 update_thread_roots, 73 update_code_roots, 74 update_string_table_roots, 75 update_universe_roots, 76 update_jni_roots, 77 update_jni_weak_roots, 78 update_synchronizer_roots, 79 update_flat_profiler_roots, 80 update_management_roots, 81 update_system_dictionary_roots, 82 update_cldg_roots, 83 update_jvmti_roots, 84 update_finish_queues, 85 86 finish_queues, 87 weakrefs, 88 weakrefs_process, 89 weakrefs_enqueue, 90 purge, 91 purge_class_unload, 92 purge_par, 93 purge_par_codecache, 94 purge_par_symbstring, 95 purge_par_rmt, 96 purge_par_classes, 97 purge_par_sync, 98 purge_cldg, 99 clean_str_dedup_table, 100 prepare_evac, 101 recycle_regions, 102 103 // Per-thread timer block, should have "roots" counters in consistent order 104 init_evac, 105 evac_thread_roots, 106 evac_code_roots, 107 evac_string_table_roots, 108 evac_universe_roots, 109 evac_jni_roots, 110 evac_jni_weak_roots, 111 evac_synchronizer_roots, 112 evac_flat_profiler_roots, 113 evac_management_roots, 114 evac_system_dictionary_roots, 115 evac_cldg_roots, 116 evac_jvmti_roots, 117 evac_finish_queues, 118 119 final_evac_gross, 120 final_evac, 121 122 init_update_refs_gross, 123 init_update_refs, 124 125 final_update_refs_gross, 126 final_update_refs, 127 final_update_refs_finish_work, 128 129 // Per-thread timer block, should have "roots" counters in consistent order 130 final_update_refs_roots, 131 final_update_refs_thread_roots, 132 final_update_refs_code_roots, 133 final_update_refs_string_table_roots, 134 final_update_refs_universe_roots, 135 final_update_refs_jni_roots, 136 final_update_refs_jni_weak_roots, 137 final_update_refs_synchronizer_roots, 138 final_update_refs_flat_profiler_roots, 139 final_update_refs_management_roots, 140 final_update_refs_system_dict_roots, 141 final_update_refs_cldg_roots, 142 final_update_refs_jvmti_roots, 143 final_update_refs_finish_queues, 144 145 final_update_refs_recycle, 146 147 partial_gc_gross, 148 partial_gc, 149 partial_gc_prepare, 150 151 // Per-thread timer block, should have "roots" counters in consistent order 152 partial_gc_work, 153 partial_gc_thread_roots, 154 partial_gc_code_roots, 155 partial_gc_string_table_roots, 156 partial_gc_universe_roots, 157 partial_gc_jni_roots, 158 partial_gc_jni_weak_roots, 159 partial_gc_synchronizer_roots, 160 partial_gc_flat_profiler_roots, 161 partial_gc_management_roots, 162 partial_gc_system_dict_roots, 163 partial_gc_cldg_roots, 164 partial_gc_jvmti_roots, 165 partial_gc_update_str_dedup_table, 166 partial_gc_recycle, 167 168 degen_gc_gross, 169 degen_gc, 170 171 full_gc_gross, 172 full_gc, 173 full_gc_heapdumps, 174 full_gc_prepare, 175 176 // Per-thread timer block, should have "roots" counters in consistent order 177 full_gc_roots, 178 full_gc_thread_roots, 179 full_gc_code_roots, 180 full_gc_string_table_roots, 181 full_gc_universe_roots, 182 full_gc_jni_roots, 183 full_gc_jni_weak_roots, 184 full_gc_synchronizer_roots, 185 full_gc_flat_profiler_roots, 186 full_gc_management_roots, 187 full_gc_system_dictionary_roots, 188 full_gc_cldg_roots, 189 full_gc_jvmti_roots, 190 full_gc_finish_queues, 191 192 full_gc_mark, 193 full_gc_mark_finish_queues, 194 full_gc_weakrefs, 195 full_gc_weakrefs_process, 196 full_gc_weakrefs_enqueue, 197 full_gc_purge, 198 full_gc_purge_class_unload, 199 full_gc_purge_par, 200 full_gc_purge_par_codecache, 201 full_gc_purge_par_symbstring, 202 full_gc_purge_par_rmt, 203 full_gc_purge_par_classes, 204 full_gc_purge_par_sync, 205 full_gc_purge_cldg, 206 full_gc_calculate_addresses, 207 full_gc_calculate_addresses_regular, 208 full_gc_calculate_addresses_humong, 209 full_gc_adjust_pointers, 210 full_gc_copy_objects, 211 full_gc_copy_objects_regular, 212 full_gc_copy_objects_humong, 213 full_gc_update_str_dedup_table, 214 full_gc_resize_tlabs, 215 216 // Longer concurrent phases at the end 217 conc_mark, 218 conc_preclean, 219 conc_evac, 220 conc_update_refs, 221 conc_cleanup, 222 conc_cleanup_recycle, 223 conc_cleanup_reset_bitmaps, 224 225 // Unclassified 226 pause_other, 227 conc_other, 228 229 _num_phases 230 }; 231 232 233 // These are the subphases of GC phases (scan_roots, update_roots, 234 // init_evac, final_update_refs_roots, partial_gc_work and full_gc_roots). 235 // Make sure they are following this order. 236 enum GCParPhases { 237 ThreadRoots, 238 CodeCacheRoots, 239 StringTableRoots, 240 UniverseRoots, 241 JNIRoots, 242 JNIWeakRoots, 243 ObjectSynchronizerRoots, 244 FlatProfilerRoots, 245 ManagementRoots, 246 SystemDictionaryRoots, 247 CLDGRoots, 248 JVMTIRoots, 249 FinishQueues, 250 GCParPhasesSentinel 251 }; 252 253 private: 254 struct TimingData { 255 HdrSeq _secs; 256 double _start; 257 }; 258 259 private: 260 TimingData _timing_data[_num_phases]; 261 const char* _phase_names[_num_phases]; 262 263 ShenandoahWorkerTimings* _worker_times; 264 ShenandoahCollectorPolicy* _policy; 265 266 public: 267 ShenandoahPhaseTimings(); 268 269 ShenandoahWorkerTimings* worker_times() const { return _worker_times; } 270 271 // record phase start 272 void record_phase_start(Phase phase); 273 // record phase end and return elapsed time in seconds for the phase 274 void record_phase_end(Phase phase); 275 // record an elapsed time in seconds for the phase 276 void record_phase_time(Phase phase, jint time_us); 277 278 void record_workers_start(Phase phase); 279 void record_workers_end(Phase phase); 280 281 void print_on(outputStream* out) const; 282 283 private: 284 void init_phase_names(); 285 void print_summary_sd(outputStream* out, const char* str, const HdrSeq* seq) const; 286 }; 287 288 class ShenandoahWorkerTimings : public CHeapObj<mtGC> { 289 private: 290 uint _max_gc_threads; 291 ShenandoahWorkerDataArray<double>* _gc_par_phases[ShenandoahPhaseTimings::GCParPhasesSentinel]; 292 293 public: 294 ShenandoahWorkerTimings(uint max_gc_threads); 295 296 // record the time a phase took in seconds 297 void record_time_secs(ShenandoahPhaseTimings::GCParPhases phase, uint worker_i, double secs); 298 299 double average(uint i); 300 void reset(uint i); 301 void print(); 302 }; 303 304 class ShenandoahWorkerTimingsTracker : public StackObj { 305 double _start_time; 306 ShenandoahPhaseTimings::GCParPhases _phase; 307 ShenandoahWorkerTimings* _worker_times; 308 uint _worker_id; 309 public: 310 ShenandoahWorkerTimingsTracker(ShenandoahWorkerTimings* worker_times, ShenandoahPhaseTimings::GCParPhases phase, uint worker_id); 311 ~ShenandoahWorkerTimingsTracker(); 312 }; 313 314 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHGCPHASETIMEINGS_HPP