1 /* 2 * Copyright (c) 2013, 2017, Oracle and/or its affiliates. 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_VM_GC_G1_G1GCPHASETIMES_HPP 26 #define SHARE_VM_GC_G1_G1GCPHASETIMES_HPP 27 28 #include "logging/logLevel.hpp" 29 #include "memory/allocation.hpp" 30 #include "utilities/macros.hpp" 31 32 class LineBuffer; 33 34 template <class T> class WorkerDataArray; 35 36 class G1GCPhaseTimes : public CHeapObj<mtGC> { 37 uint _max_gc_threads; 38 jlong _gc_start_counter; 39 double _gc_pause_time_ms; 40 41 public: 42 enum GCParPhases { 43 GCWorkerStart, 44 ExtRootScan, 45 ThreadRoots, 46 StringTableRoots, 47 UniverseRoots, 48 JNIRoots, 49 ObjectSynchronizerRoots, 50 FlatProfilerRoots, 51 ManagementRoots, 52 SystemDictionaryRoots, 53 CLDGRoots, 54 JVMTIRoots, 55 CMRefRoots, 56 WaitForStrongCLD, 57 WeakCLDRoots, 58 SATBFiltering, 59 UpdateRS, 60 ScanHCC, 61 ScanRS, 62 CodeRoots, 63 #if INCLUDE_AOT 64 AOTCodeRoots, 65 #endif 66 ObjCopy, 67 Termination, 68 Other, 69 GCWorkerTotal, 70 GCWorkerEnd, 71 StringDedupQueueFixup, 72 StringDedupTableFixup, 73 RedirtyCards, 74 PreserveCMReferents, 75 YoungFreeCSet, 76 NonYoungFreeCSet, 77 GCParPhasesSentinel 78 }; 79 80 enum GCScanRSWorkItems { 81 ScannedCards, 82 ClaimedCards, 83 SkippedCards 84 }; 85 86 private: 87 // Markers for grouping the phases in the GCPhases enum above 88 static const int GCMainParPhasesLast = GCWorkerEnd; 89 static const int StringDedupPhasesFirst = StringDedupQueueFixup; 90 static const int StringDedupPhasesLast = StringDedupTableFixup; 91 92 WorkerDataArray<double>* _gc_par_phases[GCParPhasesSentinel]; 93 94 WorkerDataArray<size_t>* _update_rs_processed_buffers; 95 96 WorkerDataArray<size_t>* _scan_rs_scanned_cards; 97 WorkerDataArray<size_t>* _scan_rs_claimed_cards; 98 WorkerDataArray<size_t>* _scan_rs_skipped_cards; 99 100 WorkerDataArray<size_t>* _termination_attempts; 101 102 WorkerDataArray<size_t>* _redirtied_cards; 103 104 double _cur_collection_par_time_ms; 105 double _cur_collection_code_root_fixup_time_ms; 106 double _cur_strong_code_root_purge_time_ms; 107 108 double _cur_evac_fail_recalc_used; 109 double _cur_evac_fail_remove_self_forwards; 110 111 double _cur_string_dedup_fixup_time_ms; 112 113 double _cur_prepare_tlab_time_ms; 114 double _cur_resize_tlab_time_ms; 115 116 double _cur_derived_pointer_table_update_time_ms; 117 118 double _cur_clear_ct_time_ms; 119 double _cur_expand_heap_time_ms; 120 double _cur_ref_proc_time_ms; 121 double _cur_ref_enq_time_ms; 122 123 double _cur_collection_start_sec; 124 double _root_region_scan_wait_time_ms; 125 126 double _external_accounted_time_ms; 127 128 double _recorded_clear_claimed_marks_time_ms; 129 130 double _recorded_young_cset_choice_time_ms; 131 double _recorded_non_young_cset_choice_time_ms; 132 133 double _recorded_redirty_logged_cards_time_ms; 134 135 double _recorded_preserve_cm_referents_time_ms; 136 137 double _recorded_merge_pss_time_ms; 138 139 double _recorded_start_new_cset_time_ms; 140 141 double _recorded_total_free_cset_time_ms; 142 143 double _recorded_serial_free_cset_time_ms; 144 145 double _cur_fast_reclaim_humongous_time_ms; 146 double _cur_fast_reclaim_humongous_register_time_ms; 147 size_t _cur_fast_reclaim_humongous_total; 148 size_t _cur_fast_reclaim_humongous_candidates; 149 size_t _cur_fast_reclaim_humongous_reclaimed; 150 151 double _cur_verify_before_time_ms; 152 double _cur_verify_after_time_ms; 153 154 double worker_time(GCParPhases phase, uint worker); 155 void note_gc_end(); 156 void reset(); 157 158 template <class T> 159 void details(T* phase, const char* indent) const; 160 161 void log_phase(WorkerDataArray<double>* phase, uint indent, outputStream* out, bool print_sum) const; 162 void debug_phase(WorkerDataArray<double>* phase) const; 163 void trace_phase(WorkerDataArray<double>* phase, bool print_sum = true) const; 164 165 void info_time(const char* name, double value) const; 166 void debug_time(const char* name, double value) const; 167 // This will print logs for both 'gc+phases' and 'gc+phases+ref'. 168 void debug_time_for_reference(const char* name, double value) const; 169 void trace_time(const char* name, double value) const; 170 void trace_count(const char* name, size_t value) const; 171 172 double print_pre_evacuate_collection_set() const; 173 double print_evacuate_collection_set() const; 174 double print_post_evacuate_collection_set() const; 175 void print_other(double accounted_ms) const; 176 177 public: 178 G1GCPhaseTimes(uint max_gc_threads); 179 void note_gc_start(); 180 void print(); 181 182 // record the time a phase took in seconds 183 void record_time_secs(GCParPhases phase, uint worker_i, double secs); 184 185 // add a number of seconds to a phase 186 void add_time_secs(GCParPhases phase, uint worker_i, double secs); 187 188 void record_thread_work_item(GCParPhases phase, uint worker_i, size_t count, uint index = 0); 189 190 // return the average time for a phase in milliseconds 191 double average_time_ms(GCParPhases phase); 192 193 size_t sum_thread_work_items(GCParPhases phase, uint index = 0); 194 195 public: 196 197 void record_prepare_tlab_time_ms(double ms) { 198 _cur_prepare_tlab_time_ms = ms; 199 } 200 201 void record_resize_tlab_time_ms(double ms) { 202 _cur_resize_tlab_time_ms = ms; 203 } 204 205 void record_derived_pointer_table_update_time(double ms) { 206 _cur_derived_pointer_table_update_time_ms = ms; 207 } 208 209 void record_clear_ct_time(double ms) { 210 _cur_clear_ct_time_ms = ms; 211 } 212 213 void record_expand_heap_time(double ms) { 214 _cur_expand_heap_time_ms = ms; 215 } 216 217 void record_par_time(double ms) { 218 _cur_collection_par_time_ms = ms; 219 } 220 221 void record_code_root_fixup_time(double ms) { 222 _cur_collection_code_root_fixup_time_ms = ms; 223 } 224 225 void record_strong_code_root_purge_time(double ms) { 226 _cur_strong_code_root_purge_time_ms = ms; 227 } 228 229 void record_evac_fail_recalc_used_time(double ms) { 230 _cur_evac_fail_recalc_used = ms; 231 } 232 233 void record_evac_fail_remove_self_forwards(double ms) { 234 _cur_evac_fail_remove_self_forwards = ms; 235 } 236 237 void record_string_dedup_fixup_time(double ms) { 238 _cur_string_dedup_fixup_time_ms = ms; 239 } 240 241 void record_ref_proc_time(double ms) { 242 _cur_ref_proc_time_ms = ms; 243 } 244 245 void record_ref_enq_time(double ms) { 246 _cur_ref_enq_time_ms = ms; 247 } 248 249 void record_root_region_scan_wait_time(double time_ms) { 250 _root_region_scan_wait_time_ms = time_ms; 251 } 252 253 void record_total_free_cset_time_ms(double time_ms) { 254 _recorded_total_free_cset_time_ms = time_ms; 255 } 256 257 void record_serial_free_cset_time_ms(double time_ms) { 258 _recorded_serial_free_cset_time_ms = time_ms; 259 } 260 261 void record_fast_reclaim_humongous_stats(double time_ms, size_t total, size_t candidates) { 262 _cur_fast_reclaim_humongous_register_time_ms = time_ms; 263 _cur_fast_reclaim_humongous_total = total; 264 _cur_fast_reclaim_humongous_candidates = candidates; 265 } 266 267 void record_fast_reclaim_humongous_time_ms(double value, size_t reclaimed) { 268 _cur_fast_reclaim_humongous_time_ms = value; 269 _cur_fast_reclaim_humongous_reclaimed = reclaimed; 270 } 271 272 void record_young_cset_choice_time_ms(double time_ms) { 273 _recorded_young_cset_choice_time_ms = time_ms; 274 } 275 276 void record_non_young_cset_choice_time_ms(double time_ms) { 277 _recorded_non_young_cset_choice_time_ms = time_ms; 278 } 279 280 void record_redirty_logged_cards_time_ms(double time_ms) { 281 _recorded_redirty_logged_cards_time_ms = time_ms; 282 } 283 284 void record_preserve_cm_referents_time_ms(double time_ms) { 285 _recorded_preserve_cm_referents_time_ms = time_ms; 286 } 287 288 void record_merge_pss_time_ms(double time_ms) { 289 _recorded_merge_pss_time_ms = time_ms; 290 } 291 292 void record_start_new_cset_time_ms(double time_ms) { 293 _recorded_start_new_cset_time_ms = time_ms; 294 } 295 296 void record_cur_collection_start_sec(double time_ms) { 297 _cur_collection_start_sec = time_ms; 298 } 299 300 void record_verify_before_time_ms(double time_ms) { 301 _cur_verify_before_time_ms = time_ms; 302 } 303 304 void record_verify_after_time_ms(double time_ms) { 305 _cur_verify_after_time_ms = time_ms; 306 } 307 308 void inc_external_accounted_time_ms(double time_ms) { 309 _external_accounted_time_ms += time_ms; 310 } 311 312 void record_clear_claimed_marks_time_ms(double recorded_clear_claimed_marks_time_ms) { 313 _recorded_clear_claimed_marks_time_ms = recorded_clear_claimed_marks_time_ms; 314 } 315 316 double cur_collection_start_sec() { 317 return _cur_collection_start_sec; 318 } 319 320 double cur_collection_par_time_ms() { 321 return _cur_collection_par_time_ms; 322 } 323 324 double cur_clear_ct_time_ms() { 325 return _cur_clear_ct_time_ms; 326 } 327 328 double cur_expand_heap_time_ms() { 329 return _cur_expand_heap_time_ms; 330 } 331 332 double root_region_scan_wait_time_ms() { 333 return _root_region_scan_wait_time_ms; 334 } 335 336 double young_cset_choice_time_ms() { 337 return _recorded_young_cset_choice_time_ms; 338 } 339 340 double total_free_cset_time_ms() { 341 return _recorded_total_free_cset_time_ms; 342 } 343 344 double non_young_cset_choice_time_ms() { 345 return _recorded_non_young_cset_choice_time_ms; 346 } 347 348 double fast_reclaim_humongous_time_ms() { 349 return _cur_fast_reclaim_humongous_time_ms; 350 } 351 }; 352 353 class G1GCParPhaseTimesTracker : public StackObj { 354 double _start_time; 355 G1GCPhaseTimes::GCParPhases _phase; 356 G1GCPhaseTimes* _phase_times; 357 uint _worker_id; 358 public: 359 G1GCParPhaseTimesTracker(G1GCPhaseTimes* phase_times, G1GCPhaseTimes::GCParPhases phase, uint worker_id); 360 ~G1GCParPhaseTimesTracker(); 361 }; 362 363 #endif // SHARE_VM_GC_G1_G1GCPHASETIMES_HPP