src/share/vm/gc_implementation/g1/g1GCPhaseTimes.cpp

changeset 8310
6c57a16d0238
parent 7893
a5b77ac78ad2
child 8604
04d83ba48607
child 9327
f96fcd9e1e1b
equal deleted inserted replaced
8309:240ea32410fa 8310:6c57a16d0238
152 assert(_data[worker_i] != WorkerDataArray<T>::uninitialized(), err_msg("No data to add to for worker %d", worker_i)); 152 assert(_data[worker_i] != WorkerDataArray<T>::uninitialized(), err_msg("No data to add to for worker %d", worker_i));
153 _data[worker_i] += value; 153 _data[worker_i] += value;
154 _has_new_data = true; 154 _has_new_data = true;
155 } 155 }
156 156
157 double average(){ 157 double average(uint active_threads){
158 calculate_totals(); 158 calculate_totals(active_threads);
159 return _average; 159 return _average;
160 } 160 }
161 161
162 T sum() { 162 T sum(uint active_threads) {
163 calculate_totals(); 163 calculate_totals(active_threads);
164 return _sum; 164 return _sum;
165 } 165 }
166 166
167 T minimum() { 167 T minimum(uint active_threads) {
168 calculate_totals(); 168 calculate_totals(active_threads);
169 return _min; 169 return _min;
170 } 170 }
171 171
172 T maximum() { 172 T maximum(uint active_threads) {
173 calculate_totals(); 173 calculate_totals(active_threads);
174 return _max; 174 return _max;
175 } 175 }
176 176
177 void reset() PRODUCT_RETURN; 177 void reset() PRODUCT_RETURN;
178 void verify() PRODUCT_RETURN; 178 void verify(uint active_threads) PRODUCT_RETURN;
179 179
180 void set_enabled(bool enabled) { _enabled = enabled; } 180 void set_enabled(bool enabled) { _enabled = enabled; }
181 181
182 int log_level() { return _log_level; } 182 int log_level() { return _log_level; }
183 183
184 private: 184 private:
185 185
186 void calculate_totals(){ 186 void calculate_totals(uint active_threads){
187 if (!_has_new_data) { 187 if (!_has_new_data) {
188 return; 188 return;
189 } 189 }
190 190
191 _sum = (T)0; 191 _sum = (T)0;
192 _min = _data[0]; 192 _min = _data[0];
193 _max = _min; 193 _max = _min;
194 for (uint i = 0; i < _length; ++i) { 194 assert(active_threads <= _length, "Wrong number of active threads");
195 for (uint i = 0; i < active_threads; ++i) {
195 T val = _data[i]; 196 T val = _data[i];
196 _sum += val; 197 _sum += val;
197 _min = MIN2(_min, val); 198 _min = MIN2(_min, val);
198 _max = MAX2(_max, val); 199 _max = MAX2(_max, val);
199 } 200 }
200 _average = (double)_sum / (double)_length; 201 _average = (double)_sum / (double)active_threads;
201 _has_new_data = false; 202 _has_new_data = false;
202 } 203 }
203 }; 204 };
204 205
205 206
224 _thread_work_items->reset(); 225 _thread_work_items->reset();
225 } 226 }
226 } 227 }
227 228
228 template <class T> 229 template <class T>
229 void WorkerDataArray<T>::verify() { 230 void WorkerDataArray<T>::verify(uint active_threads) {
230 if (!_enabled) { 231 if (!_enabled) {
231 return; 232 return;
232 } 233 }
233 234
234 for (uint i = 0; i < _length; i++) { 235 assert(active_threads <= _length, "Wrong number of active threads");
236 for (uint i = 0; i < active_threads; i++) {
235 assert(_data[i] != WorkerDataArray<T>::uninitialized(), 237 assert(_data[i] != WorkerDataArray<T>::uninitialized(),
236 err_msg("Invalid data for worker %u in '%s'", i, _title)); 238 err_msg("Invalid data for worker %u in '%s'", i, _title));
237 } 239 }
238 if (_thread_work_items != NULL) { 240 if (_thread_work_items != NULL) {
239 _thread_work_items->verify(); 241 _thread_work_items->verify(active_threads);
240 } 242 }
241 } 243 }
242 244
243 #endif 245 #endif
244 246
319 321
320 record_time_secs(Other, i, worker_time - worker_known_time); 322 record_time_secs(Other, i, worker_time - worker_known_time);
321 } 323 }
322 324
323 for (int i = 0; i < GCParPhasesSentinel; i++) { 325 for (int i = 0; i < GCParPhasesSentinel; i++) {
324 _gc_par_phases[i]->verify(); 326 _gc_par_phases[i]->verify(_active_gc_threads);
325 } 327 }
326 } 328 }
327 329
328 void G1GCPhaseTimes::print_stats(int level, const char* str, double value) { 330 void G1GCPhaseTimes::print_stats(int level, const char* str, double value) {
329 LineBuffer(level).append_and_print_cr("[%s: %.1lf ms]", str, value); 331 LineBuffer(level).append_and_print_cr("[%s: %.1lf ms]", str, value);
376 _gc_par_phases[phase]->set_thread_work_item(worker_i, count); 378 _gc_par_phases[phase]->set_thread_work_item(worker_i, count);
377 } 379 }
378 380
379 // return the average time for a phase in milliseconds 381 // return the average time for a phase in milliseconds
380 double G1GCPhaseTimes::average_time_ms(GCParPhases phase) { 382 double G1GCPhaseTimes::average_time_ms(GCParPhases phase) {
381 return _gc_par_phases[phase]->average() * 1000.0; 383 return _gc_par_phases[phase]->average(_active_gc_threads) * 1000.0;
382 } 384 }
383 385
384 double G1GCPhaseTimes::get_time_ms(GCParPhases phase, uint worker_i) { 386 double G1GCPhaseTimes::get_time_ms(GCParPhases phase, uint worker_i) {
385 return _gc_par_phases[phase]->get(worker_i) * 1000.0; 387 return _gc_par_phases[phase]->get(worker_i) * 1000.0;
386 } 388 }
387 389
388 double G1GCPhaseTimes::sum_time_ms(GCParPhases phase) { 390 double G1GCPhaseTimes::sum_time_ms(GCParPhases phase) {
389 return _gc_par_phases[phase]->sum() * 1000.0; 391 return _gc_par_phases[phase]->sum(_active_gc_threads) * 1000.0;
390 } 392 }
391 393
392 double G1GCPhaseTimes::min_time_ms(GCParPhases phase) { 394 double G1GCPhaseTimes::min_time_ms(GCParPhases phase) {
393 return _gc_par_phases[phase]->minimum() * 1000.0; 395 return _gc_par_phases[phase]->minimum(_active_gc_threads) * 1000.0;
394 } 396 }
395 397
396 double G1GCPhaseTimes::max_time_ms(GCParPhases phase) { 398 double G1GCPhaseTimes::max_time_ms(GCParPhases phase) {
397 return _gc_par_phases[phase]->maximum() * 1000.0; 399 return _gc_par_phases[phase]->maximum(_active_gc_threads) * 1000.0;
398 } 400 }
399 401
400 size_t G1GCPhaseTimes::get_thread_work_item(GCParPhases phase, uint worker_i) { 402 size_t G1GCPhaseTimes::get_thread_work_item(GCParPhases phase, uint worker_i) {
401 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); 403 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count");
402 return _gc_par_phases[phase]->thread_work_items()->get(worker_i); 404 return _gc_par_phases[phase]->thread_work_items()->get(worker_i);
403 } 405 }
404 406
405 size_t G1GCPhaseTimes::sum_thread_work_items(GCParPhases phase) { 407 size_t G1GCPhaseTimes::sum_thread_work_items(GCParPhases phase) {
406 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); 408 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count");
407 return _gc_par_phases[phase]->thread_work_items()->sum(); 409 return _gc_par_phases[phase]->thread_work_items()->sum(_active_gc_threads);
408 } 410 }
409 411
410 double G1GCPhaseTimes::average_thread_work_items(GCParPhases phase) { 412 double G1GCPhaseTimes::average_thread_work_items(GCParPhases phase) {
411 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); 413 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count");
412 return _gc_par_phases[phase]->thread_work_items()->average(); 414 return _gc_par_phases[phase]->thread_work_items()->average(_active_gc_threads);
413 } 415 }
414 416
415 size_t G1GCPhaseTimes::min_thread_work_items(GCParPhases phase) { 417 size_t G1GCPhaseTimes::min_thread_work_items(GCParPhases phase) {
416 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); 418 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count");
417 return _gc_par_phases[phase]->thread_work_items()->minimum(); 419 return _gc_par_phases[phase]->thread_work_items()->minimum(_active_gc_threads);
418 } 420 }
419 421
420 size_t G1GCPhaseTimes::max_thread_work_items(GCParPhases phase) { 422 size_t G1GCPhaseTimes::max_thread_work_items(GCParPhases phase) {
421 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count"); 423 assert(_gc_par_phases[phase]->thread_work_items() != NULL, "No sub count");
422 return _gc_par_phases[phase]->thread_work_items()->maximum(); 424 return _gc_par_phases[phase]->thread_work_items()->maximum(_active_gc_threads);
423 } 425 }
424 426
425 class G1GCParPhasePrinter : public StackObj { 427 class G1GCParPhasePrinter : public StackObj {
426 G1GCPhaseTimes* _phase_times; 428 G1GCPhaseTimes* _phase_times;
427 public: 429 public:
453 buf2.append_and_print_cr("[%s: "SIZE_FORMAT"]", phase->_thread_work_items->_title, _phase_times->sum_thread_work_items(phase_id)); 455 buf2.append_and_print_cr("[%s: "SIZE_FORMAT"]", phase->_thread_work_items->_title, _phase_times->sum_thread_work_items(phase_id));
454 } 456 }
455 } 457 }
456 458
457 void print_time_values(LineBuffer& buf, G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray<double>* phase) { 459 void print_time_values(LineBuffer& buf, G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray<double>* phase) {
458 for (uint i = 0; i < phase->_length; ++i) { 460 uint active_length = _phase_times->_active_gc_threads;
461 for (uint i = 0; i < active_length; ++i) {
459 buf.append(" %.1lf", _phase_times->get_time_ms(phase_id, i)); 462 buf.append(" %.1lf", _phase_times->get_time_ms(phase_id, i));
460 } 463 }
461 buf.print_cr(); 464 buf.print_cr();
462 } 465 }
463 466
464 void print_count_values(LineBuffer& buf, G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray<size_t>* thread_work_items) { 467 void print_count_values(LineBuffer& buf, G1GCPhaseTimes::GCParPhases phase_id, WorkerDataArray<size_t>* thread_work_items) {
465 for (uint i = 0; i < thread_work_items->_length; ++i) { 468 uint active_length = _phase_times->_active_gc_threads;
469 for (uint i = 0; i < active_length; ++i) {
466 buf.append(" " SIZE_FORMAT, _phase_times->get_thread_work_item(phase_id, i)); 470 buf.append(" " SIZE_FORMAT, _phase_times->get_thread_work_item(phase_id, i));
467 } 471 }
468 buf.print_cr(); 472 buf.print_cr();
469 } 473 }
470 474

mercurial