1 /* 2 * Copyright (c) 2013, 2015, 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 "memory/allocation.hpp" 29 30 class LineBuffer; 31 32 template <class T> class WorkerDataArray; 33 34 class G1GCPhaseTimes : public CHeapObj<mtGC> { 35 uint _active_gc_threads; 36 uint _max_gc_threads; 37 jlong _gc_start_counter; 38 double _gc_pause_time_ms; 39 40 public: 41 enum GCParPhases { 42 GCWorkerStart, 43 ExtRootScan, 44 ThreadRoots, 45 StringTableRoots, 46 UniverseRoots, 47 JNIRoots, 48 ObjectSynchronizerRoots, 49 FlatProfilerRoots, 50 ManagementRoots, 51 SystemDictionaryRoots, 52 CLDGRoots, 53 JVMTIRoots, 54 CMRefRoots, 55 WaitForStrongCLD, 56 WeakCLDRoots, 57 SATBFiltering, 58 UpdateRS, 59 ScanHCC, 60 ScanRS, 61 CodeRoots, 62 ObjCopy, 63 Termination, 64 Other, 65 GCWorkerTotal, 66 GCWorkerEnd, 67 StringDedupQueueFixup, 68 StringDedupTableFixup, 69 RedirtyCards, 70 GCParPhasesSentinel 71 }; 72 73 private: 74 // Markers for grouping the phases in the GCPhases enum above 75 static const int GCMainParPhasesLast = GCWorkerEnd; 76 static const int StringDedupPhasesFirst = StringDedupQueueFixup; 77 static const int StringDedupPhasesLast = StringDedupTableFixup; 78 79 WorkerDataArray<double>* _gc_par_phases[GCParPhasesSentinel]; 80 WorkerDataArray<size_t>* _update_rs_processed_buffers; 81 WorkerDataArray<size_t>* _termination_attempts; 82 WorkerDataArray<size_t>* _redirtied_cards; 83 84 double _cur_collection_par_time_ms; 85 double _cur_collection_code_root_fixup_time_ms; 86 double _cur_strong_code_root_purge_time_ms; 87 88 double _cur_evac_fail_recalc_used; 89 double _cur_evac_fail_restore_remsets; 90 double _cur_evac_fail_remove_self_forwards; 91 92 double _cur_string_dedup_fixup_time_ms; 93 94 double _cur_clear_ct_time_ms; 95 double _cur_expand_heap_time_ms; 96 double _cur_ref_proc_time_ms; 97 double _cur_ref_enq_time_ms; 98 99 double _cur_collection_start_sec; 100 double _root_region_scan_wait_time_ms; 101 102 double _external_accounted_time_ms; 103 104 double _recorded_young_cset_choice_time_ms; 105 double _recorded_non_young_cset_choice_time_ms; 106 107 double _recorded_redirty_logged_cards_time_ms; 108 109 double _recorded_young_free_cset_time_ms; 110 double _recorded_non_young_free_cset_time_ms; 111 112 double _cur_fast_reclaim_humongous_time_ms; 113 double _cur_fast_reclaim_humongous_register_time_ms; 114 size_t _cur_fast_reclaim_humongous_total; 115 size_t _cur_fast_reclaim_humongous_candidates; 116 size_t _cur_fast_reclaim_humongous_reclaimed; 117 118 double _cur_verify_before_time_ms; 119 double _cur_verify_after_time_ms; 120 121 // Helper methods for detailed logging 122 void info_line(const char* str, double value); 123 void debug_line(const char* str, double value); 124 void trace_line(const char* str, double value); 125 void trace_line(const char* str, size_t value); 126 void trace_phase_tasks(const char* indent, G1GCPhaseTimes::GCParPhases phase_id); 127 void trace_phase_counts(const char* indent, G1GCPhaseTimes::GCParPhases phase_id); 128 void debug_phase(G1GCPhaseTimes::GCParPhases phase_id); 129 void trace_phase(G1GCPhaseTimes::GCParPhases phase_id); 130 void trace_phase_no_sum(G1GCPhaseTimes::GCParPhases phase_id); 131 132 void note_gc_end(); 133 134 public: 135 G1GCPhaseTimes(uint max_gc_threads); 136 void note_gc_start(uint active_gc_threads); 137 void print(); 138 139 // record the time a phase took in seconds 140 void record_time_secs(GCParPhases phase, uint worker_i, double secs); 141 142 // add a number of seconds to a phase 143 void add_time_secs(GCParPhases phase, uint worker_i, double secs); 144 145 void record_thread_work_item(GCParPhases phase, uint worker_i, size_t count); 146 147 // return the average time for a phase in milliseconds 148 double average_time_ms(GCParPhases phase); 149 150 size_t sum_thread_work_items(GCParPhases phase); 151 152 private: 153 double get_time_ms(GCParPhases phase, uint worker_i); 154 double sum_time_ms(GCParPhases phase); 155 double min_time_ms(GCParPhases phase); 156 double max_time_ms(GCParPhases phase); 157 size_t get_thread_work_item(GCParPhases phase, uint worker_i); 158 double average_thread_work_items(GCParPhases phase); 159 size_t min_thread_work_items(GCParPhases phase); 160 size_t max_thread_work_items(GCParPhases phase); 161 162 public: 163 164 void record_clear_ct_time(double ms) { 165 _cur_clear_ct_time_ms = ms; 166 } 167 168 void record_expand_heap_time(double ms) { 169 _cur_expand_heap_time_ms = ms; 170 } 171 172 void record_par_time(double ms) { 173 _cur_collection_par_time_ms = ms; 174 } 175 176 void record_code_root_fixup_time(double ms) { 177 _cur_collection_code_root_fixup_time_ms = ms; 178 } 179 180 void record_strong_code_root_purge_time(double ms) { 181 _cur_strong_code_root_purge_time_ms = ms; 182 } 183 184 void record_evac_fail_recalc_used_time(double ms) { 185 _cur_evac_fail_recalc_used = ms; 186 } 187 188 void record_evac_fail_restore_remsets(double ms) { 189 _cur_evac_fail_restore_remsets = ms; 190 } 191 192 void record_evac_fail_remove_self_forwards(double ms) { 193 _cur_evac_fail_remove_self_forwards = ms; 194 } 195 196 void record_string_dedup_fixup_time(double ms) { 197 _cur_string_dedup_fixup_time_ms = ms; 198 } 199 200 void record_ref_proc_time(double ms) { 201 _cur_ref_proc_time_ms = ms; 202 } 203 204 void record_ref_enq_time(double ms) { 205 _cur_ref_enq_time_ms = ms; 206 } 207 208 void record_root_region_scan_wait_time(double time_ms) { 209 _root_region_scan_wait_time_ms = time_ms; 210 } 211 212 void record_young_free_cset_time_ms(double time_ms) { 213 _recorded_young_free_cset_time_ms = time_ms; 214 } 215 216 void record_non_young_free_cset_time_ms(double time_ms) { 217 _recorded_non_young_free_cset_time_ms = time_ms; 218 } 219 220 void record_fast_reclaim_humongous_stats(double time_ms, size_t total, size_t candidates) { 221 _cur_fast_reclaim_humongous_register_time_ms = time_ms; 222 _cur_fast_reclaim_humongous_total = total; 223 _cur_fast_reclaim_humongous_candidates = candidates; 224 } 225 226 void record_fast_reclaim_humongous_time_ms(double value, size_t reclaimed) { 227 _cur_fast_reclaim_humongous_time_ms = value; 228 _cur_fast_reclaim_humongous_reclaimed = reclaimed; 229 } 230 231 void record_young_cset_choice_time_ms(double time_ms) { 232 _recorded_young_cset_choice_time_ms = time_ms; 233 } 234 235 void record_non_young_cset_choice_time_ms(double time_ms) { 236 _recorded_non_young_cset_choice_time_ms = time_ms; 237 } 238 239 void record_redirty_logged_cards_time_ms(double time_ms) { 240 _recorded_redirty_logged_cards_time_ms = time_ms; 241 } 242 243 void record_cur_collection_start_sec(double time_ms) { 244 _cur_collection_start_sec = time_ms; 245 } 246 247 void record_verify_before_time_ms(double time_ms) { 248 _cur_verify_before_time_ms = time_ms; 249 } 250 251 void record_verify_after_time_ms(double time_ms) { 252 _cur_verify_after_time_ms = time_ms; 253 } 254 255 void inc_external_accounted_time_ms(double time_ms) { 256 _external_accounted_time_ms += time_ms; 257 } 258 259 double accounted_time_ms(); 260 261 double cur_collection_start_sec() { 262 return _cur_collection_start_sec; 263 } 264 265 double cur_collection_par_time_ms() { 266 return _cur_collection_par_time_ms; 267 } 268 269 double cur_clear_ct_time_ms() { 270 return _cur_clear_ct_time_ms; 271 } 272 273 double cur_expand_heap_time_ms() { 274 return _cur_expand_heap_time_ms; 275 } 276 277 double root_region_scan_wait_time_ms() { 278 return _root_region_scan_wait_time_ms; 279 } 280 281 double young_cset_choice_time_ms() { 282 return _recorded_young_cset_choice_time_ms; 283 } 284 285 double young_free_cset_time_ms() { 286 return _recorded_young_free_cset_time_ms; 287 } 288 289 double non_young_cset_choice_time_ms() { 290 return _recorded_non_young_cset_choice_time_ms; 291 } 292 293 double non_young_free_cset_time_ms() { 294 return _recorded_non_young_free_cset_time_ms; 295 } 296 297 double fast_reclaim_humongous_time_ms() { 298 return _cur_fast_reclaim_humongous_time_ms; 299 } 300 }; 301 302 class G1GCParPhaseTimesTracker : public StackObj { 303 double _start_time; 304 G1GCPhaseTimes::GCParPhases _phase; 305 G1GCPhaseTimes* _phase_times; 306 uint _worker_id; 307 public: 308 G1GCParPhaseTimesTracker(G1GCPhaseTimes* phase_times, G1GCPhaseTimes::GCParPhases phase, uint worker_id); 309 ~G1GCParPhaseTimesTracker(); 310 }; 311 312 #endif // SHARE_VM_GC_G1_G1GCPHASETIMES_HPP