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 }
128 // for things like the start and end times the sum is not
129 // that relevant
130 buf.append(", Sum: ");
131 buf.append(_print_format, sum);
132 }
133 buf.append_and_print_cr("]");
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"),
175 _last_gc_worker_other_times_ms(_max_gc_threads, "%.1lf"),
176 _last_redirty_logged_cards_time_ms(_max_gc_threads, "%.1lf"),
177 _last_redirty_logged_cards_processed_cards(_max_gc_threads, SIZE_FORMAT),
178 _cur_string_dedup_queue_fixup_worker_times_ms(_max_gc_threads, "%.1lf"),
179 _cur_string_dedup_table_fixup_worker_times_ms(_max_gc_threads, "%.1lf")
180 {
181 assert(max_gc_threads > 0, "Must have some GC threads");
182 }
183
184 void G1GCPhaseTimes::note_gc_start(uint active_gc_threads) {
185 assert(active_gc_threads > 0, "The number of threads must be > 0");
186 assert(active_gc_threads <= _max_gc_threads, "The number of active threads must be <= the max nubmer of threads");
187 _active_gc_threads = active_gc_threads;
188
189 _last_gc_worker_start_times_ms.reset();
190 _last_ext_root_scan_times_ms.reset();
191 _last_satb_filtering_times_ms.reset();
192 _last_update_rs_times_ms.reset();
193 _last_update_rs_processed_buffers.reset();
194 _last_scan_rs_times_ms.reset();
195 _last_strong_code_root_scan_times_ms.reset();
196 _last_obj_copy_times_ms.reset();
197 _last_termination_times_ms.reset();
198 _last_termination_attempts.reset();
199 _last_gc_worker_end_times_ms.reset();
200 _last_gc_worker_times_ms.reset();
201 _last_gc_worker_other_times_ms.reset();
202
203 _last_redirty_logged_cards_time_ms.reset();
204 _last_redirty_logged_cards_processed_cards.reset();
205
206 }
207
208 void G1GCPhaseTimes::note_gc_end() {
209 _last_gc_worker_start_times_ms.verify();
210 _last_ext_root_scan_times_ms.verify();
211 _last_satb_filtering_times_ms.verify();
212 _last_update_rs_times_ms.verify();
213 _last_update_rs_processed_buffers.verify();
214 _last_scan_rs_times_ms.verify();
215 _last_strong_code_root_scan_times_ms.verify();
216 _last_obj_copy_times_ms.verify();
217 _last_termination_times_ms.verify();
218 _last_termination_attempts.verify();
219 _last_gc_worker_end_times_ms.verify();
220
221 for (uint i = 0; i < _active_gc_threads; i++) {
222 double worker_time = _last_gc_worker_end_times_ms.get(i) - _last_gc_worker_start_times_ms.get(i);
223 _last_gc_worker_times_ms.set(i, worker_time);
224
225 double worker_known_time = _last_ext_root_scan_times_ms.get(i) +
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);
|
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 #include "g1CollectedHeap.hpp"
33
34 // Helper class for avoiding interleaved logging
35 class LineBuffer: public StackObj {
36
37 private:
38 static const int BUFFER_LEN = 1024;
39 static const int INDENT_CHARS = 3;
40 char _buffer[BUFFER_LEN];
41 int _indent_level;
42 int _cur;
43
44 void vappend(const char* format, va_list ap) ATTRIBUTE_PRINTF(2, 0) {
45 int res = vsnprintf(&_buffer[_cur], BUFFER_LEN - _cur, format, ap);
46 if (res != -1) {
47 _cur += res;
48 } else {
49 DEBUG_ONLY(warning("buffer too small in LineBuffer");)
50 _buffer[BUFFER_LEN -1] = 0;
51 _cur = BUFFER_LEN; // vsnprintf above should not add to _buffer if we are called again
52 }
129 // for things like the start and end times the sum is not
130 // that relevant
131 buf.append(", Sum: ");
132 buf.append(_print_format, sum);
133 }
134 buf.append_and_print_cr("]");
135 }
136 PRAGMA_DIAG_POP
137
138 #ifndef PRODUCT
139
140 template <> const int WorkerDataArray<int>::_uninitialized = -1;
141 template <> const double WorkerDataArray<double>::_uninitialized = -1.0;
142 template <> const size_t WorkerDataArray<size_t>::_uninitialized = (size_t)-1;
143
144 template <class T>
145 void WorkerDataArray<T>::reset() {
146 for (uint i = 0; i < _length; i++) {
147 _data[i] = (T)_uninitialized;
148 }
149 _has_new_data = true;
150 }
151
152 template <class T>
153 void WorkerDataArray<T>::verify() {
154 for (uint i = 0; i < _length; i++) {
155 assert(_data[i] != _uninitialized,
156 err_msg("Invalid data for worker %u, data: %lf, uninitialized: %lf",
157 i, (double)_data[i], (double)_uninitialized));
158 }
159 }
160
161 #endif
162
163 G1GCPhaseTimes::G1GCPhaseTimes(uint max_gc_threads, uint num_ext_root_scan_phases) :
164 _max_gc_threads(max_gc_threads),
165 _num_ext_root_scan_phases(num_ext_root_scan_phases),
166 _last_gc_worker_start_times_ms(_max_gc_threads, "%.1lf", false),
167 _last_ext_root_scan_times_ms(_max_gc_threads, "%.1lf"),
168 _last_ext_root_scan_phase_times_ms(NULL),
169 _last_satb_filtering_times_ms(_max_gc_threads, "%.1lf"),
170 _last_update_rs_times_ms(_max_gc_threads, "%.1lf"),
171 _last_update_rs_processed_buffers(_max_gc_threads, "%d"),
172 _last_scan_rs_times_ms(_max_gc_threads, "%.1lf"),
173 _last_strong_code_root_scan_times_ms(_max_gc_threads, "%.1lf"),
174 _last_obj_copy_times_ms(_max_gc_threads, "%.1lf"),
175 _last_termination_times_ms(_max_gc_threads, "%.1lf"),
176 _last_termination_attempts(_max_gc_threads, SIZE_FORMAT),
177 _last_gc_worker_end_times_ms(_max_gc_threads, "%.1lf", false),
178 _last_gc_worker_times_ms(_max_gc_threads, "%.1lf"),
179 _last_gc_worker_other_times_ms(_max_gc_threads, "%.1lf"),
180 _last_redirty_logged_cards_time_ms(_max_gc_threads, "%.1lf"),
181 _last_redirty_logged_cards_processed_cards(_max_gc_threads, SIZE_FORMAT),
182 _cur_string_dedup_queue_fixup_worker_times_ms(_max_gc_threads, "%.1lf"),
183 _cur_string_dedup_table_fixup_worker_times_ms(_max_gc_threads, "%.1lf")
184 {
185 assert(max_gc_threads > 0, "Must have some GC threads");
186 if (track_ext_root_scan_phases()) {
187 _last_ext_root_scan_phase_times_ms = NEW_C_HEAP_ARRAY(WorkerDataArray<double>*, num_ext_root_scan_phases, mtGC);
188 for (uint i = 0; i < num_ext_root_scan_phases; i++) {
189 _last_ext_root_scan_phase_times_ms[i] = new WorkerDataArray<double>(_max_gc_threads, "%.1lf");
190 }
191 }
192 }
193
194 G1GCPhaseTimes::~G1GCPhaseTimes() {
195 if (track_ext_root_scan_phases()) {
196 for (uint i = 0; i < _num_ext_root_scan_phases; i++) {
197 delete _last_ext_root_scan_phase_times_ms[i];
198 }
199 FREE_C_HEAP_ARRAY(WorkerDataArray<double>*, _last_ext_root_scan_phase_times_ms);
200 }
201 }
202
203 void G1GCPhaseTimes::note_gc_start(uint active_gc_threads) {
204 assert(active_gc_threads > 0, "The number of threads must be > 0");
205 assert(active_gc_threads <= _max_gc_threads, "The number of active threads must be <= the max nubmer of threads");
206 _active_gc_threads = active_gc_threads;
207
208 _last_gc_worker_start_times_ms.reset();
209 _last_ext_root_scan_times_ms.reset();
210 _last_satb_filtering_times_ms.reset();
211 _last_update_rs_times_ms.reset();
212 _last_update_rs_processed_buffers.reset();
213 _last_scan_rs_times_ms.reset();
214 _last_strong_code_root_scan_times_ms.reset();
215 _last_obj_copy_times_ms.reset();
216 _last_termination_times_ms.reset();
217 _last_termination_attempts.reset();
218 _last_gc_worker_end_times_ms.reset();
219 _last_gc_worker_times_ms.reset();
220 _last_gc_worker_other_times_ms.reset();
221
222 _last_redirty_logged_cards_time_ms.reset();
223 _last_redirty_logged_cards_processed_cards.reset();
224
225 for (uint i = 0; i < _num_ext_root_scan_phases; i++) {
226 _last_ext_root_scan_phase_times_ms[i]->reset();
227 }
228 }
229
230 void G1GCPhaseTimes::note_gc_end() {
231 _last_gc_worker_start_times_ms.verify();
232 _last_ext_root_scan_times_ms.verify();
233 _last_satb_filtering_times_ms.verify();
234 _last_update_rs_times_ms.verify();
235 _last_update_rs_processed_buffers.verify();
236 _last_scan_rs_times_ms.verify();
237 _last_strong_code_root_scan_times_ms.verify();
238 _last_obj_copy_times_ms.verify();
239 _last_termination_times_ms.verify();
240 _last_termination_attempts.verify();
241 _last_gc_worker_end_times_ms.verify();
242
243 for (uint i = 0; i < _active_gc_threads; i++) {
244 double worker_time = _last_gc_worker_end_times_ms.get(i) - _last_gc_worker_start_times_ms.get(i);
245 _last_gc_worker_times_ms.set(i, worker_time);
246
247 double worker_known_time = _last_ext_root_scan_times_ms.get(i) +
300
301 if (G1StringDedup::is_enabled()) {
302 // String dedup fixup time
303 misc_time_ms += _cur_string_dedup_fixup_time_ms;
304 }
305
306 // Subtract the time taken to clean the card table from the
307 // current value of "other time"
308 misc_time_ms += _cur_clear_ct_time_ms;
309
310 return misc_time_ms;
311 }
312
313 void G1GCPhaseTimes::print(double pause_time_sec) {
314 if (_root_region_scan_wait_time_ms > 0.0) {
315 print_stats(1, "Root Region Scan Waiting", _root_region_scan_wait_time_ms);
316 }
317 print_stats(1, "Parallel Time", _cur_collection_par_time_ms, _active_gc_threads);
318 _last_gc_worker_start_times_ms.print(2, "GC Worker Start (ms)");
319 _last_ext_root_scan_times_ms.print(2, "Ext Root Scanning (ms)");
320 if (track_ext_root_scan_phases()) {
321 for (uint i = 0; i < _num_ext_root_scan_phases; i++) {
322 WorkerDataArray<double>* data = _last_ext_root_scan_phase_times_ms[i];
323 data->print(3, G1CollectedHeap::ext_roots_task_string(i));
324 }
325 }
326 if (_last_satb_filtering_times_ms.sum() > 0.0) {
327 _last_satb_filtering_times_ms.print(2, "SATB Filtering (ms)");
328 }
329 _last_update_rs_times_ms.print(2, "Update RS (ms)");
330 _last_update_rs_processed_buffers.print(3, "Processed Buffers");
331 _last_scan_rs_times_ms.print(2, "Scan RS (ms)");
332 _last_strong_code_root_scan_times_ms.print(2, "Code Root Scanning (ms)");
333 _last_obj_copy_times_ms.print(2, "Object Copy (ms)");
334 _last_termination_times_ms.print(2, "Termination (ms)");
335 if (G1Log::finest()) {
336 _last_termination_attempts.print(3, "Termination Attempts");
337 }
338 _last_gc_worker_other_times_ms.print(2, "GC Worker Other (ms)");
339 _last_gc_worker_times_ms.print(2, "GC Worker Total (ms)");
340 _last_gc_worker_end_times_ms.print(2, "GC Worker End (ms)");
341
342 print_stats(1, "Code Root Fixup", _cur_collection_code_root_fixup_time_ms);
343 print_stats(1, "Code Root Purge", _cur_strong_code_root_purge_time_ms);
344 if (G1StringDedup::is_enabled()) {
345 print_stats(1, "String Dedup Fixup", _cur_string_dedup_fixup_time_ms, _active_gc_threads);
|