29 #include "runtime/thread.inline.hpp" |
29 #include "runtime/thread.inline.hpp" |
30 #include "runtime/timer.hpp" |
30 #include "runtime/timer.hpp" |
31 |
31 |
32 int PeriodicTask::_num_tasks = 0; |
32 int PeriodicTask::_num_tasks = 0; |
33 PeriodicTask* PeriodicTask::_tasks[PeriodicTask::max_tasks]; |
33 PeriodicTask* PeriodicTask::_tasks[PeriodicTask::max_tasks]; |
34 #ifndef PRODUCT |
|
35 elapsedTimer PeriodicTask::_timer; |
|
36 int PeriodicTask::_intervalHistogram[PeriodicTask::max_interval]; |
|
37 int PeriodicTask::_ticks; |
|
38 |
|
39 void PeriodicTask::print_intervals() { |
|
40 if (ProfilerCheckIntervals) { |
|
41 for (int i = 0; i < PeriodicTask::max_interval; i++) { |
|
42 int n = _intervalHistogram[i]; |
|
43 if (n > 0) tty->print_cr("%3d: %5d (%4.1f%%)", i, n, 100.0 * n / _ticks); |
|
44 } |
|
45 } |
|
46 } |
|
47 #endif |
|
48 |
34 |
49 void PeriodicTask::real_time_tick(int delay_time) { |
35 void PeriodicTask::real_time_tick(int delay_time) { |
50 assert(Thread::current()->is_Watcher_thread(), "must be WatcherThread"); |
36 assert(Thread::current()->is_Watcher_thread(), "must be WatcherThread"); |
51 |
37 |
52 #ifndef PRODUCT |
38 // The WatcherThread does not participate in the safepoint protocol |
53 if (ProfilerCheckIntervals) { |
39 // for the PeriodicTask_lock because it is not a JavaThread. |
54 _ticks++; |
40 MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag); |
55 _timer.stop(); |
41 int orig_num_tasks = _num_tasks; |
56 int ms = (int)_timer.milliseconds(); |
|
57 _timer.reset(); |
|
58 _timer.start(); |
|
59 if (ms >= PeriodicTask::max_interval) ms = PeriodicTask::max_interval - 1; |
|
60 _intervalHistogram[ms]++; |
|
61 } |
|
62 #endif |
|
63 |
42 |
64 { |
43 for(int index = 0; index < _num_tasks; index++) { |
65 // The WatcherThread does not participate in the safepoint protocol |
44 _tasks[index]->execute_if_pending(delay_time); |
66 // for the PeriodicTask_lock because it is not a JavaThread. |
45 if (_num_tasks < orig_num_tasks) { // task dis-enrolled itself |
67 MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag); |
46 index--; // re-do current slot as it has changed |
68 int orig_num_tasks = _num_tasks; |
47 orig_num_tasks = _num_tasks; |
69 |
|
70 for(int index = 0; index < _num_tasks; index++) { |
|
71 _tasks[index]->execute_if_pending(delay_time); |
|
72 if (_num_tasks < orig_num_tasks) { // task dis-enrolled itself |
|
73 index--; // re-do current slot as it has changed |
|
74 orig_num_tasks = _num_tasks; |
|
75 } |
|
76 } |
48 } |
77 } |
49 } |
78 } |
50 } |
79 |
51 |
80 int PeriodicTask::time_to_wait() { |
52 int PeriodicTask::time_to_wait() { |