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