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 #include "gc_interface/gcCause.hpp"
30
31 class G1GCPhaseTimes : public CHeapObj<mtGC> {
32 friend class G1CollectorPolicy;
33 friend class TraceGen0TimeData;
34
35 private:
36 uint _active_gc_threads;
37 uint _max_gc_threads;
38
39 GCCause::Cause _gc_cause;
40 bool _is_young_gc;
41 bool _is_initial_mark_gc;
42
43 double _pause_start_time_sec;
44
45 double* _par_last_gc_worker_start_times_ms;
46 double* _par_last_ext_root_scan_times_ms;
47 double* _par_last_satb_filtering_times_ms;
48 double* _par_last_update_rs_times_ms;
49 double* _par_last_update_rs_processed_buffers;
50 double* _par_last_scan_rs_times_ms;
51 double* _par_last_obj_copy_times_ms;
52 double* _par_last_termination_times_ms;
53 double* _par_last_termination_attempts;
54 double* _par_last_gc_worker_end_times_ms;
55 double* _par_last_gc_worker_times_ms;
56 double* _par_last_gc_worker_other_times_ms;
57
58 double _cur_collection_par_time_ms;
59
60 double _cur_collection_code_root_fixup_time_ms;
61
62 double _cur_clear_ct_time_ms;
63 double _cur_ref_proc_time_ms;
64 double _cur_ref_enq_time_ms;
65
66 // Helper methods for detailed logging
67 void print_par_stats(int level, const char* str, double* data, bool showDecimals = true);
68 void print_stats(int level, const char* str, double value);
69 void print_stats(int level, const char* str, double value, int workers);
70 void print_stats(int level, const char* str, int value);
71 double avg_value(double* data);
72 double max_value(double* data);
73 double sum_of_values(double* data);
74 double max_sum(double* data1, double* data2);
75 double accounted_time_ms();
76
77 // Card Table Count Cache stats
78 double _min_clear_cc_time_ms; // min
79 double _max_clear_cc_time_ms; // max
80 double _cur_clear_cc_time_ms; // clearing time during current pause
81 double _cum_clear_cc_time_ms; // cummulative clearing time
82 jlong _num_cc_clears; // number of times the card count cache has been cleared
83
84 // The following insance variables are directly accessed by G1CollectorPolicy
85 // and TraceGen0TimeData. This is why those classes are declared friends.
86 // An alternative is to add getters and setters for all of these fields.
87 // It might also be possible to restructure the code to reduce these
88 // dependencies.
89 double _ext_root_scan_time;
90 double _satb_filtering_time;
91 double _update_rs_time;
92 double _update_rs_processed_buffers;
93 double _scan_rs_time;
94 double _obj_copy_time;
95 double _termination_time;
96
97 double _cur_collection_start_sec;
98 double _root_region_scan_wait_time_ms;
99
100 double _recorded_young_cset_choice_time_ms;
101 double _recorded_non_young_cset_choice_time_ms;
102
103 double _recorded_young_free_cset_time_ms;
104 double _recorded_non_young_free_cset_time_ms;
105
106 void print(double pause_time_ms);
107
108 public:
109 G1GCPhaseTimes(uint max_gc_threads);
110 void note_gc_start(double pause_start_time_sec, uint active_gc_threads,
111 bool is_young_gc, bool is_initial_mark_gc, GCCause::Cause gc_cause);
112 void note_gc_end(double pause_end_time_sec);
113 void collapse_par_times();
114
115 void record_gc_worker_start_time(uint worker_i, double ms) {
116 assert(worker_i >= 0, "worker index must be > 0");
117 assert(worker_i < _active_gc_threads, "worker index out of bounds");
118 _par_last_gc_worker_start_times_ms[worker_i] = ms;
119 }
120
121 void record_ext_root_scan_time(uint worker_i, double ms) {
122 assert(worker_i >= 0, "worker index must be > 0");
123 assert(worker_i < _active_gc_threads, "worker index out of bounds");
124 _par_last_ext_root_scan_times_ms[worker_i] = ms;
125 }
126
127 void record_satb_filtering_time(uint worker_i, double ms) {
128 assert(worker_i >= 0, "worker index must be > 0");
129 assert(worker_i < _active_gc_threads, "worker index out of bounds");
130 _par_last_satb_filtering_times_ms[worker_i] = ms;
131 }
132
133 void record_update_rs_time(uint worker_i, double ms) {
134 assert(worker_i >= 0, "worker index must be > 0");
135 assert(worker_i < _active_gc_threads, "worker index out of bounds");
136 _par_last_update_rs_times_ms[worker_i] = ms;
137 }
138
139 void record_update_rs_processed_buffers (uint worker_i,
140 double processed_buffers) {
141 assert(worker_i >= 0, "worker index must be > 0");
142 assert(worker_i < _active_gc_threads, "worker index out of bounds");
143 _par_last_update_rs_processed_buffers[worker_i] = processed_buffers;
144 }
145
146 void record_scan_rs_time(uint worker_i, double ms) {
147 assert(worker_i >= 0, "worker index must be > 0");
148 assert(worker_i < _active_gc_threads, "worker index out of bounds");
149 _par_last_scan_rs_times_ms[worker_i] = ms;
150 }
151
152 void reset_obj_copy_time(uint worker_i) {
153 assert(worker_i >= 0, "worker index must be > 0");
154 assert(worker_i < _active_gc_threads, "worker index out of bounds");
155 _par_last_obj_copy_times_ms[worker_i] = 0.0;
156 }
157
158 void reset_obj_copy_time() {
159 reset_obj_copy_time(0);
160 }
161
162 void record_obj_copy_time(uint worker_i, double ms) {
163 assert(worker_i >= 0, "worker index must be > 0");
164 assert(worker_i < _active_gc_threads, "worker index out of bounds");
165 _par_last_obj_copy_times_ms[worker_i] += ms;
166 }
167
168 void record_termination(uint worker_i, double ms, size_t attempts) {
169 assert(worker_i >= 0, "worker index must be > 0");
170 assert(worker_i < _active_gc_threads, "worker index out of bounds");
171 _par_last_termination_times_ms[worker_i] = ms;
172 _par_last_termination_attempts[worker_i] = (double) attempts;
173 }
174
175 void record_gc_worker_end_time(uint worker_i, double ms) {
176 assert(worker_i >= 0, "worker index must be > 0");
177 assert(worker_i < _active_gc_threads, "worker index out of bounds");
178 _par_last_gc_worker_end_times_ms[worker_i] = ms;
179 }
180
181 void record_clear_ct_time(double ms) {
182 _cur_clear_ct_time_ms = ms;
183 }
184
185 void record_par_time(double ms) {
186 _cur_collection_par_time_ms = ms;
187 }
188
189 void record_code_root_fixup_time(double ms) {
190 _cur_collection_code_root_fixup_time_ms = ms;
191 }
192
193 void record_ref_proc_time(double ms) {
194 _cur_ref_proc_time_ms = ms;
195 }
196
197 void record_ref_enq_time(double ms) {
198 _cur_ref_enq_time_ms = ms;
199 }
200
201 void record_root_region_scan_wait_time(double time_ms) {
202 _root_region_scan_wait_time_ms = time_ms;
203 }
204
205 void record_cc_clear_time_ms(double ms);
206
207 void record_young_free_cset_time_ms(double time_ms) {
208 _recorded_young_free_cset_time_ms = time_ms;
209 }
210
211 void record_non_young_free_cset_time_ms(double time_ms) {
212 _recorded_non_young_free_cset_time_ms = time_ms;
213 }
214 };
215
216 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1GCPHASETIMESLOG_HPP
|
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 #include "gc_interface/gcCause.hpp"
30
31 template <class T>
32 class WorkerDataArray : public CHeapObj<mtGC> {
33 T* _data;
34 uint _length;
35 const char* _print_format;
36 bool _print_sum;
37
38 // We are caching the sum and average to only have to calculate them once.
39 // This is not done in an MT-safe way. It is intetened to allow single
40 // threaded code to call sum() and average() multiple times in any order
41 // without having to worry about the cost.
42 bool _has_new_data;
43 T _sum;
44 double _average;
45
46 public:
47 WorkerDataArray(uint length, const char* print_format, bool print_sum = true) :
48 _length(length), _print_format(print_format), _print_sum(print_sum), _has_new_data(true) {
49 assert(length > 0, "Must have some workers to store data for");
50 _data = NEW_C_HEAP_ARRAY(T, _length, mtGC);
51 }
52
53 ~WorkerDataArray() {
54 FREE_C_HEAP_ARRAY(T, _data, mtGC);
55 }
56
57 void set(uint worker_i, T value) {
58 assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length));
59 assert(_data[worker_i] == (T)-1, err_msg("Overwriting data for worker %d", worker_i));
60 _data[worker_i] = value;
61 _has_new_data = true;
62 }
63
64 T get(uint worker_i) {
65 assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length));
66 assert(_data[worker_i] != (T)-1, err_msg("No data to add to for worker %d", worker_i));
67 return _data[worker_i];
68 }
69
70 void add(uint worker_i, T value) {
71 assert(worker_i < _length, err_msg("Worker %d is greater than max: %d", worker_i, _length));
72 assert(_data[worker_i] != (T)-1, err_msg("No data to add to for worker %d", worker_i));
73 _data[worker_i] += value;
74 _has_new_data = true;
75 }
76
77 double average(){
78 if (_has_new_data) {
79 calculate_totals();
80 }
81 return _average;
82 }
83
84 T sum() {
85 if (_has_new_data) {
86 calculate_totals();
87 }
88 return _sum;
89 }
90
91 void print(int level, const char* title);
92
93 void reset() PRODUCT_RETURN;
94 void verify() PRODUCT_RETURN;
95
96 private:
97
98 void calculate_totals(){
99 _sum = (T)0;
100 for (uint i = 0; i < _length; ++i) {
101 _sum += _data[i];
102 }
103 _average = (double)_sum / (double)_length;
104 _has_new_data = false;
105 }
106 };
107
108 class G1GCPhaseTimes : public CHeapObj<mtGC> {
109
110 private:
111 uint _active_gc_threads;
112 uint _max_gc_threads;
113
114 GCCause::Cause _gc_cause;
115 bool _is_young_gc;
116 bool _is_initial_mark_gc;
117
118 double _pause_start_time_sec;
119
120 WorkerDataArray<double> _last_gc_worker_start_times_ms;
121 WorkerDataArray<double> _last_ext_root_scan_times_ms;
122 WorkerDataArray<double> _last_satb_filtering_times_ms;
123 WorkerDataArray<double> _last_update_rs_times_ms;
124 WorkerDataArray<int> _last_update_rs_processed_buffers;
125 WorkerDataArray<double> _last_scan_rs_times_ms;
126 WorkerDataArray<double> _last_obj_copy_times_ms;
127 WorkerDataArray<double> _last_termination_times_ms;
128 WorkerDataArray<size_t> _last_termination_attempts;
129 WorkerDataArray<double> _last_gc_worker_end_times_ms;
130 WorkerDataArray<double> _last_gc_worker_times_ms;
131 WorkerDataArray<double> _last_gc_worker_other_times_ms;
132
133 double _cur_collection_par_time_ms;
134
135 double _cur_collection_code_root_fixup_time_ms;
136
137 double _cur_clear_ct_time_ms;
138 double _cur_ref_proc_time_ms;
139 double _cur_ref_enq_time_ms;
140
141 // Helper methods for detailed logging
142 void print_stats(int level, const char* str, double value);
143 void print_stats(int level, const char* str, double value, int workers);
144
145 // Card Table Count Cache stats
146 double _min_clear_cc_time_ms; // min
147 double _max_clear_cc_time_ms; // max
148 double _cur_clear_cc_time_ms; // clearing time during current pause
149 double _cum_clear_cc_time_ms; // cummulative clearing time
150 jlong _num_cc_clears; // number of times the card count cache has been cleared
151
152 double _cur_collection_start_sec;
153 double _root_region_scan_wait_time_ms;
154
155 double _recorded_young_cset_choice_time_ms;
156 double _recorded_non_young_cset_choice_time_ms;
157
158 double _recorded_young_free_cset_time_ms;
159 double _recorded_non_young_free_cset_time_ms;
160
161 void print(double pause_time_ms);
162
163 public:
164 G1GCPhaseTimes(uint max_gc_threads);
165 void note_gc_start(double pause_start_time_sec, uint active_gc_threads,
166 bool is_young_gc, bool is_initial_mark_gc, GCCause::Cause gc_cause);
167 void note_gc_end(double pause_end_time_sec);
168
169 void record_gc_worker_start_time(uint worker_i, double ms) {
170 _last_gc_worker_start_times_ms.set(worker_i, ms);
171 }
172
173 void record_ext_root_scan_time(uint worker_i, double ms) {
174 _last_ext_root_scan_times_ms.set(worker_i, ms);
175 }
176
177 void record_satb_filtering_time(uint worker_i, double ms) {
178 _last_satb_filtering_times_ms.set(worker_i, ms);
179 }
180
181 void record_update_rs_time(uint worker_i, double ms) {
182 _last_update_rs_times_ms.set(worker_i, ms);
183 }
184
185 void record_update_rs_processed_buffers(uint worker_i, int processed_buffers) {
186 _last_update_rs_processed_buffers.set(worker_i, processed_buffers);
187 }
188
189 void record_scan_rs_time(uint worker_i, double ms) {
190 _last_scan_rs_times_ms.set(worker_i, ms);
191 }
192
193 void record_obj_copy_time(uint worker_i, double ms) {
194 _last_obj_copy_times_ms.set(worker_i, ms);
195 }
196
197 void add_obj_copy_time(uint worker_i, double ms) {
198 _last_obj_copy_times_ms.add(worker_i, ms);
199 }
200
201 void record_termination(uint worker_i, double ms, size_t attempts) {
202 _last_termination_times_ms.set(worker_i, ms);
203 _last_termination_attempts.set(worker_i, attempts);
204 }
205
206 void record_gc_worker_end_time(uint worker_i, double ms) {
207 _last_gc_worker_end_times_ms.set(worker_i, ms);
208 }
209
210 void record_clear_ct_time(double ms) {
211 _cur_clear_ct_time_ms = ms;
212 }
213
214 void record_par_time(double ms) {
215 _cur_collection_par_time_ms = ms;
216 }
217
218 void record_code_root_fixup_time(double ms) {
219 _cur_collection_code_root_fixup_time_ms = ms;
220 }
221
222 void record_ref_proc_time(double ms) {
223 _cur_ref_proc_time_ms = ms;
224 }
225
226 void record_ref_enq_time(double ms) {
227 _cur_ref_enq_time_ms = ms;
228 }
229
230 void record_root_region_scan_wait_time(double time_ms) {
231 _root_region_scan_wait_time_ms = time_ms;
232 }
233
234 void record_cc_clear_time_ms(double ms);
235
236 void record_young_free_cset_time_ms(double time_ms) {
237 _recorded_young_free_cset_time_ms = time_ms;
238 }
239
240 void record_non_young_free_cset_time_ms(double time_ms) {
241 _recorded_non_young_free_cset_time_ms = time_ms;
242 }
243
244 void record_young_cset_choice_time_ms(double time_ms) {
245 _recorded_young_cset_choice_time_ms = time_ms;
246 }
247
248 void record_non_young_cset_choice_time_ms(double time_ms) {
249 _recorded_non_young_cset_choice_time_ms = time_ms;
250 }
251
252 void record_cur_collection_start_sec(double time_ms) {
253 _cur_collection_start_sec = time_ms;
254 }
255
256 double accounted_time_ms();
257
258 double cur_collection_start_sec() {
259 return _cur_collection_start_sec;
260 }
261
262 double cur_collection_par_time_ms() {
263 return _cur_collection_par_time_ms;
264 }
265
266 double cur_clear_ct_time_ms() {
267 return _cur_clear_ct_time_ms;
268 }
269
270 double root_region_scan_wait_time_ms() {
271 return _root_region_scan_wait_time_ms;
272 }
273
274 double young_cset_choice_time_ms() {
275 return _recorded_young_cset_choice_time_ms;
276 }
277
278 double young_free_cset_time_ms() {
279 return _recorded_young_free_cset_time_ms;
280 }
281
282 double non_young_cset_choice_time_ms() {
283 return _recorded_non_young_cset_choice_time_ms;
284 }
285
286 double non_young_free_cset_time_ms() {
287 return _recorded_non_young_free_cset_time_ms;
288 }
289
290 double average_last_update_rs_time() {
291 return _last_update_rs_times_ms.average();
292 }
293
294 int sum_last_update_rs_processed_buffers() {
295 return _last_update_rs_processed_buffers.sum();
296 }
297
298 double average_last_scan_rs_time(){
299 return _last_scan_rs_times_ms.average();
300 }
301
302 double average_last_obj_copy_time() {
303 return _last_obj_copy_times_ms.average();
304 }
305
306 double average_last_termination_time() {
307 return _last_termination_times_ms.average();
308 }
309
310 double average_last_ext_root_scan_time() {
311 return _last_ext_root_scan_times_ms.average();
312 }
313
314 double sum_last_satb_filtering_times_ms() {
315 return _last_satb_filtering_times_ms.sum();
316 }
317 };
318
319 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1GCPHASETIMESLOG_HPP
|