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
26 #include "precompiled.hpp"
27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
28 #include "gc_implementation/g1/g1GCPhaseTimes.hpp"
29 #include "gc_implementation/g1/g1Log.hpp"
30 #include "gc_implementation/g1/g1StringDedup.hpp"
31
32 // Helper class for avoiding interleaved logging
33 class LineBuffer: public StackObj {
34
35 private:
36 static const int BUFFER_LEN = 1024;
37 static const int INDENT_CHARS = 3;
38 char _buffer[BUFFER_LEN];
39 int _indent_level;
40 int _cur;
41
42 void vappend(const char* format, va_list ap) ATTRIBUTE_PRINTF(2, 0) {
43 int res = vsnprintf(&_buffer[_cur], BUFFER_LEN - _cur, format, ap);
44 if (res != -1) {
45 _cur += res;
46 } else {
47 DEBUG_ONLY(warning("buffer too small in LineBuffer");)
48 _buffer[BUFFER_LEN -1] = 0;
49 _cur = BUFFER_LEN; // vsnprintf above should not add to _buffer if we are called again
50 }
133 }
134 PRAGMA_DIAG_POP
135
136 #ifndef PRODUCT
137
138 template <> const int WorkerDataArray<int>::_uninitialized = -1;
139 template <> const double WorkerDataArray<double>::_uninitialized = -1.0;
140 template <> const size_t WorkerDataArray<size_t>::_uninitialized = (size_t)-1;
141
142 template <class T>
143 void WorkerDataArray<T>::reset() {
144 for (uint i = 0; i < _length; i++) {
145 _data[i] = (T)_uninitialized;
146 }
147 }
148
149 template <class T>
150 void WorkerDataArray<T>::verify() {
151 for (uint i = 0; i < _length; i++) {
152 assert(_data[i] != _uninitialized,
153 err_msg("Invalid data for worker " UINT32_FORMAT ", data: %lf, uninitialized: %lf",
154 i, (double)_data[i], (double)_uninitialized));
155 }
156 }
157
158 #endif
159
160 G1GCPhaseTimes::G1GCPhaseTimes(uint max_gc_threads) :
161 _max_gc_threads(max_gc_threads),
162 _last_gc_worker_start_times_ms(_max_gc_threads, "%.1lf", false),
163 _last_ext_root_scan_times_ms(_max_gc_threads, "%.1lf"),
164 _last_satb_filtering_times_ms(_max_gc_threads, "%.1lf"),
165 _last_update_rs_times_ms(_max_gc_threads, "%.1lf"),
166 _last_update_rs_processed_buffers(_max_gc_threads, "%d"),
167 _last_scan_rs_times_ms(_max_gc_threads, "%.1lf"),
168 _last_strong_code_root_scan_times_ms(_max_gc_threads, "%.1lf"),
169 _last_obj_copy_times_ms(_max_gc_threads, "%.1lf"),
170 _last_termination_times_ms(_max_gc_threads, "%.1lf"),
171 _last_termination_attempts(_max_gc_threads, SIZE_FORMAT),
172 _last_gc_worker_end_times_ms(_max_gc_threads, "%.1lf", false),
173 _last_gc_worker_times_ms(_max_gc_threads, "%.1lf"),
242
243 void G1GCPhaseTimes::note_string_dedup_fixup_start() {
244 _cur_string_dedup_queue_fixup_worker_times_ms.reset();
245 _cur_string_dedup_table_fixup_worker_times_ms.reset();
246 }
247
248 void G1GCPhaseTimes::note_string_dedup_fixup_end() {
249 _cur_string_dedup_queue_fixup_worker_times_ms.verify();
250 _cur_string_dedup_table_fixup_worker_times_ms.verify();
251 }
252
253 void G1GCPhaseTimes::print_stats(int level, const char* str, double value) {
254 LineBuffer(level).append_and_print_cr("[%s: %.1lf ms]", str, value);
255 }
256
257 void G1GCPhaseTimes::print_stats(int level, const char* str, size_t value) {
258 LineBuffer(level).append_and_print_cr("[%s: "SIZE_FORMAT"]", str, value);
259 }
260
261 void G1GCPhaseTimes::print_stats(int level, const char* str, double value, uint workers) {
262 LineBuffer(level).append_and_print_cr("[%s: %.1lf ms, GC Workers: " UINT32_FORMAT "]", str, value, workers);
263 }
264
265 double G1GCPhaseTimes::accounted_time_ms() {
266 // Subtract the root region scanning wait time. It's initialized to
267 // zero at the start of the pause.
268 double misc_time_ms = _root_region_scan_wait_time_ms;
269
270 misc_time_ms += _cur_collection_par_time_ms;
271
272 // Now subtract the time taken to fix up roots in generated code
273 misc_time_ms += _cur_collection_code_root_fixup_time_ms;
274
275 // Strong code root purge time
276 misc_time_ms += _cur_strong_code_root_purge_time_ms;
277
278 if (G1StringDedup::is_enabled()) {
279 // String dedup fixup time
280 misc_time_ms += _cur_string_dedup_fixup_time_ms;
281 }
282
283 // Subtract the time taken to clean the card table from the
284 // current value of "other time"
285 misc_time_ms += _cur_clear_ct_time_ms;
286
287 return misc_time_ms;
288 }
289
290 void G1GCPhaseTimes::print(double pause_time_sec) {
291 if (_root_region_scan_wait_time_ms > 0.0) {
292 print_stats(1, "Root Region Scan Waiting", _root_region_scan_wait_time_ms);
293 }
294 if (G1CollectedHeap::use_parallel_gc_threads()) {
295 print_stats(1, "Parallel Time", _cur_collection_par_time_ms, _active_gc_threads);
296 _last_gc_worker_start_times_ms.print(2, "GC Worker Start (ms)");
297 _last_ext_root_scan_times_ms.print(2, "Ext Root Scanning (ms)");
298 if (_last_satb_filtering_times_ms.sum() > 0.0) {
299 _last_satb_filtering_times_ms.print(2, "SATB Filtering (ms)");
300 }
301 _last_update_rs_times_ms.print(2, "Update RS (ms)");
302 _last_update_rs_processed_buffers.print(3, "Processed Buffers");
303 _last_scan_rs_times_ms.print(2, "Scan RS (ms)");
304 _last_strong_code_root_scan_times_ms.print(2, "Code Root Scanning (ms)");
305 _last_obj_copy_times_ms.print(2, "Object Copy (ms)");
306 _last_termination_times_ms.print(2, "Termination (ms)");
307 if (G1Log::finest()) {
308 _last_termination_attempts.print(3, "Termination Attempts");
309 }
310 _last_gc_worker_other_times_ms.print(2, "GC Worker Other (ms)");
311 _last_gc_worker_times_ms.print(2, "GC Worker Total (ms)");
312 _last_gc_worker_end_times_ms.print(2, "GC Worker End (ms)");
313 } else {
314 _last_ext_root_scan_times_ms.print(1, "Ext Root Scanning (ms)");
315 if (_last_satb_filtering_times_ms.sum() > 0.0) {
316 _last_satb_filtering_times_ms.print(1, "SATB Filtering (ms)");
317 }
318 _last_update_rs_times_ms.print(1, "Update RS (ms)");
319 _last_update_rs_processed_buffers.print(2, "Processed Buffers");
320 _last_scan_rs_times_ms.print(1, "Scan RS (ms)");
321 _last_strong_code_root_scan_times_ms.print(1, "Code Root Scanning (ms)");
322 _last_obj_copy_times_ms.print(1, "Object Copy (ms)");
323 }
324 print_stats(1, "Code Root Fixup", _cur_collection_code_root_fixup_time_ms);
325 print_stats(1, "Code Root Purge", _cur_strong_code_root_purge_time_ms);
326 if (G1StringDedup::is_enabled()) {
327 print_stats(1, "String Dedup Fixup", _cur_string_dedup_fixup_time_ms, _active_gc_threads);
328 _cur_string_dedup_queue_fixup_worker_times_ms.print(2, "Queue Fixup (ms)");
329 _cur_string_dedup_table_fixup_worker_times_ms.print(2, "Table Fixup (ms)");
330 }
331 print_stats(1, "Clear CT", _cur_clear_ct_time_ms);
332 double misc_time_ms = pause_time_sec * MILLIUNITS - accounted_time_ms();
333 print_stats(1, "Other", misc_time_ms);
334 if (_cur_verify_before_time_ms > 0.0) {
335 print_stats(2, "Verify Before", _cur_verify_before_time_ms);
336 }
337 if (G1CollectedHeap::heap()->evacuation_failed()) {
338 double evac_fail_handling = _cur_evac_fail_recalc_used + _cur_evac_fail_remove_self_forwards +
339 _cur_evac_fail_restore_remsets;
340 print_stats(2, "Evacuation Failure", evac_fail_handling);
341 if (G1Log::finest()) {
342 print_stats(3, "Recalculate Used", _cur_evac_fail_recalc_used);
343 print_stats(3, "Remove Self Forwards", _cur_evac_fail_remove_self_forwards);
|
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
26 #include "precompiled.hpp"
27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
28 #include "gc_implementation/g1/g1GCPhaseTimes.hpp"
29 #include "gc_implementation/g1/g1Log.hpp"
30 #include "gc_implementation/g1/g1StringDedup.hpp"
31 #include "runtime/atomic.inline.hpp"
32
33 // Helper class for avoiding interleaved logging
34 class LineBuffer: public StackObj {
35
36 private:
37 static const int BUFFER_LEN = 1024;
38 static const int INDENT_CHARS = 3;
39 char _buffer[BUFFER_LEN];
40 int _indent_level;
41 int _cur;
42
43 void vappend(const char* format, va_list ap) ATTRIBUTE_PRINTF(2, 0) {
44 int res = vsnprintf(&_buffer[_cur], BUFFER_LEN - _cur, format, ap);
45 if (res != -1) {
46 _cur += res;
47 } else {
48 DEBUG_ONLY(warning("buffer too small in LineBuffer");)
49 _buffer[BUFFER_LEN -1] = 0;
50 _cur = BUFFER_LEN; // vsnprintf above should not add to _buffer if we are called again
51 }
134 }
135 PRAGMA_DIAG_POP
136
137 #ifndef PRODUCT
138
139 template <> const int WorkerDataArray<int>::_uninitialized = -1;
140 template <> const double WorkerDataArray<double>::_uninitialized = -1.0;
141 template <> const size_t WorkerDataArray<size_t>::_uninitialized = (size_t)-1;
142
143 template <class T>
144 void WorkerDataArray<T>::reset() {
145 for (uint i = 0; i < _length; i++) {
146 _data[i] = (T)_uninitialized;
147 }
148 }
149
150 template <class T>
151 void WorkerDataArray<T>::verify() {
152 for (uint i = 0; i < _length; i++) {
153 assert(_data[i] != _uninitialized,
154 err_msg("Invalid data for worker %u, data: %lf, uninitialized: %lf",
155 i, (double)_data[i], (double)_uninitialized));
156 }
157 }
158
159 #endif
160
161 G1GCPhaseTimes::G1GCPhaseTimes(uint max_gc_threads) :
162 _max_gc_threads(max_gc_threads),
163 _last_gc_worker_start_times_ms(_max_gc_threads, "%.1lf", false),
164 _last_ext_root_scan_times_ms(_max_gc_threads, "%.1lf"),
165 _last_satb_filtering_times_ms(_max_gc_threads, "%.1lf"),
166 _last_update_rs_times_ms(_max_gc_threads, "%.1lf"),
167 _last_update_rs_processed_buffers(_max_gc_threads, "%d"),
168 _last_scan_rs_times_ms(_max_gc_threads, "%.1lf"),
169 _last_strong_code_root_scan_times_ms(_max_gc_threads, "%.1lf"),
170 _last_obj_copy_times_ms(_max_gc_threads, "%.1lf"),
171 _last_termination_times_ms(_max_gc_threads, "%.1lf"),
172 _last_termination_attempts(_max_gc_threads, SIZE_FORMAT),
173 _last_gc_worker_end_times_ms(_max_gc_threads, "%.1lf", false),
174 _last_gc_worker_times_ms(_max_gc_threads, "%.1lf"),
243
244 void G1GCPhaseTimes::note_string_dedup_fixup_start() {
245 _cur_string_dedup_queue_fixup_worker_times_ms.reset();
246 _cur_string_dedup_table_fixup_worker_times_ms.reset();
247 }
248
249 void G1GCPhaseTimes::note_string_dedup_fixup_end() {
250 _cur_string_dedup_queue_fixup_worker_times_ms.verify();
251 _cur_string_dedup_table_fixup_worker_times_ms.verify();
252 }
253
254 void G1GCPhaseTimes::print_stats(int level, const char* str, double value) {
255 LineBuffer(level).append_and_print_cr("[%s: %.1lf ms]", str, value);
256 }
257
258 void G1GCPhaseTimes::print_stats(int level, const char* str, size_t value) {
259 LineBuffer(level).append_and_print_cr("[%s: "SIZE_FORMAT"]", str, value);
260 }
261
262 void G1GCPhaseTimes::print_stats(int level, const char* str, double value, uint workers) {
263 LineBuffer(level).append_and_print_cr("[%s: %.1lf ms, GC Workers: %u]", str, value, workers);
264 }
265
266 double G1GCPhaseTimes::accounted_time_ms() {
267 // Subtract the root region scanning wait time. It's initialized to
268 // zero at the start of the pause.
269 double misc_time_ms = _root_region_scan_wait_time_ms;
270
271 misc_time_ms += _cur_collection_par_time_ms;
272
273 // Now subtract the time taken to fix up roots in generated code
274 misc_time_ms += _cur_collection_code_root_fixup_time_ms;
275
276 // Strong code root purge time
277 misc_time_ms += _cur_strong_code_root_purge_time_ms;
278
279 if (G1StringDedup::is_enabled()) {
280 // String dedup fixup time
281 misc_time_ms += _cur_string_dedup_fixup_time_ms;
282 }
283
284 // Subtract the time taken to clean the card table from the
285 // current value of "other time"
286 misc_time_ms += _cur_clear_ct_time_ms;
287
288 return misc_time_ms;
289 }
290
291 void G1GCPhaseTimes::print(double pause_time_sec) {
292 if (_root_region_scan_wait_time_ms > 0.0) {
293 print_stats(1, "Root Region Scan Waiting", _root_region_scan_wait_time_ms);
294 }
295 print_stats(1, "Parallel Time", _cur_collection_par_time_ms, _active_gc_threads);
296 _last_gc_worker_start_times_ms.print(2, "GC Worker Start (ms)");
297 _last_ext_root_scan_times_ms.print(2, "Ext Root Scanning (ms)");
298 if (_last_satb_filtering_times_ms.sum() > 0.0) {
299 _last_satb_filtering_times_ms.print(2, "SATB Filtering (ms)");
300 }
301 _last_update_rs_times_ms.print(2, "Update RS (ms)");
302 _last_update_rs_processed_buffers.print(3, "Processed Buffers");
303 _last_scan_rs_times_ms.print(2, "Scan RS (ms)");
304 _last_strong_code_root_scan_times_ms.print(2, "Code Root Scanning (ms)");
305 _last_obj_copy_times_ms.print(2, "Object Copy (ms)");
306 _last_termination_times_ms.print(2, "Termination (ms)");
307 if (G1Log::finest()) {
308 _last_termination_attempts.print(3, "Termination Attempts");
309 }
310 _last_gc_worker_other_times_ms.print(2, "GC Worker Other (ms)");
311 _last_gc_worker_times_ms.print(2, "GC Worker Total (ms)");
312 _last_gc_worker_end_times_ms.print(2, "GC Worker End (ms)");
313
314 print_stats(1, "Code Root Fixup", _cur_collection_code_root_fixup_time_ms);
315 print_stats(1, "Code Root Purge", _cur_strong_code_root_purge_time_ms);
316 if (G1StringDedup::is_enabled()) {
317 print_stats(1, "String Dedup Fixup", _cur_string_dedup_fixup_time_ms, _active_gc_threads);
318 _cur_string_dedup_queue_fixup_worker_times_ms.print(2, "Queue Fixup (ms)");
319 _cur_string_dedup_table_fixup_worker_times_ms.print(2, "Table Fixup (ms)");
320 }
321 print_stats(1, "Clear CT", _cur_clear_ct_time_ms);
322 double misc_time_ms = pause_time_sec * MILLIUNITS - accounted_time_ms();
323 print_stats(1, "Other", misc_time_ms);
324 if (_cur_verify_before_time_ms > 0.0) {
325 print_stats(2, "Verify Before", _cur_verify_before_time_ms);
326 }
327 if (G1CollectedHeap::heap()->evacuation_failed()) {
328 double evac_fail_handling = _cur_evac_fail_recalc_used + _cur_evac_fail_remove_self_forwards +
329 _cur_evac_fail_restore_remsets;
330 print_stats(2, "Evacuation Failure", evac_fail_handling);
331 if (G1Log::finest()) {
332 print_stats(3, "Recalculate Used", _cur_evac_fail_recalc_used);
333 print_stats(3, "Remove Self Forwards", _cur_evac_fail_remove_self_forwards);
|