< prev index next >

src/share/vm/runtime/task.cpp

Print this page
rev 8847 : 8140482: Various minor code improvements (runtime)
Reviewed-by: dholmes, coleenp, sspitsyn, dsamersoff


 104 PeriodicTask::PeriodicTask(size_t interval_time) :
 105   _counter(0), _interval((int) interval_time) {
 106   // Sanity check the interval time
 107   assert(_interval >= PeriodicTask::min_interval &&
 108          _interval %  PeriodicTask::interval_gran == 0,
 109               "improper PeriodicTask interval time");
 110 }
 111 
 112 PeriodicTask::~PeriodicTask() {
 113   disenroll();
 114 }
 115 
 116 /* enroll could be called from a JavaThread, so we have to check for
 117  * safepoint when taking the lock to avoid deadlocking */
 118 void PeriodicTask::enroll() {
 119   MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
 120                      NULL : PeriodicTask_lock);
 121 
 122   if (_num_tasks == PeriodicTask::max_tasks) {
 123     fatal("Overflow in PeriodicTask table");
 124   }
 125   _tasks[_num_tasks++] = this;

 126 
 127   WatcherThread* thread = WatcherThread::watcher_thread();
 128   if (thread) {
 129     thread->unpark();
 130   } else {
 131     WatcherThread::start();
 132   }
 133 }
 134 
 135 /* disenroll could be called from a JavaThread, so we have to check for
 136  * safepoint when taking the lock to avoid deadlocking */
 137 void PeriodicTask::disenroll() {
 138   MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
 139                      NULL : PeriodicTask_lock);
 140 
 141   int index;
 142   for(index = 0; index < _num_tasks && _tasks[index] != this; index++)
 143     ;
 144 
 145   if (index == _num_tasks) {


 104 PeriodicTask::PeriodicTask(size_t interval_time) :
 105   _counter(0), _interval((int) interval_time) {
 106   // Sanity check the interval time
 107   assert(_interval >= PeriodicTask::min_interval &&
 108          _interval %  PeriodicTask::interval_gran == 0,
 109               "improper PeriodicTask interval time");
 110 }
 111 
 112 PeriodicTask::~PeriodicTask() {
 113   disenroll();
 114 }
 115 
 116 /* enroll could be called from a JavaThread, so we have to check for
 117  * safepoint when taking the lock to avoid deadlocking */
 118 void PeriodicTask::enroll() {
 119   MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
 120                      NULL : PeriodicTask_lock);
 121 
 122   if (_num_tasks == PeriodicTask::max_tasks) {
 123     fatal("Overflow in PeriodicTask table");
 124   } else {
 125     _tasks[_num_tasks++] = this;
 126   }
 127 
 128   WatcherThread* thread = WatcherThread::watcher_thread();
 129   if (thread) {
 130     thread->unpark();
 131   } else {
 132     WatcherThread::start();
 133   }
 134 }
 135 
 136 /* disenroll could be called from a JavaThread, so we have to check for
 137  * safepoint when taking the lock to avoid deadlocking */
 138 void PeriodicTask::disenroll() {
 139   MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ?
 140                      NULL : PeriodicTask_lock);
 141 
 142   int index;
 143   for(index = 0; index < _num_tasks && _tasks[index] != this; index++)
 144     ;
 145 
 146   if (index == _num_tasks) {
< prev index next >