< prev index next >

src/hotspot/share/runtime/task.cpp

Print this page




  45   }
  46 }
  47 #endif
  48 
  49 void PeriodicTask::real_time_tick(int delay_time) {
  50   assert(Thread::current()->is_Watcher_thread(), "must be WatcherThread");
  51 
  52 #ifndef PRODUCT
  53   if (ProfilerCheckIntervals) {
  54     _ticks++;
  55     _timer.stop();
  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 
  64   {
  65     // The WatcherThread does not participate in the safepoint protocol
  66     // for the PeriodicTask_lock because it is not a JavaThread.
  67     MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag);
  68     int 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     }
  77   }
  78 }
  79 
  80 int PeriodicTask::time_to_wait() {
  81   assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required");
  82 
  83   if (_num_tasks == 0) {
  84     return 0; // sleep until shutdown or a task is enrolled
  85   }
  86 
  87   int delay = _tasks[0]->time_to_next_interval();




  45   }
  46 }
  47 #endif
  48 
  49 void PeriodicTask::real_time_tick(int delay_time) {
  50   assert(Thread::current()->is_Watcher_thread(), "must be WatcherThread");
  51 
  52 #ifndef PRODUCT
  53   if (ProfilerCheckIntervals) {
  54     _ticks++;
  55     _timer.stop();
  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 
  64   {
  65     MutexLocker ml(PeriodicTask_lock);


  66     int orig_num_tasks = _num_tasks;
  67 
  68     for(int index = 0; index < _num_tasks; index++) {
  69       _tasks[index]->execute_if_pending(delay_time);
  70       if (_num_tasks < orig_num_tasks) { // task dis-enrolled itself
  71         index--;  // re-do current slot as it has changed
  72         orig_num_tasks = _num_tasks;
  73       }
  74     }
  75   }
  76 }
  77 
  78 int PeriodicTask::time_to_wait() {
  79   assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required");
  80 
  81   if (_num_tasks == 0) {
  82     return 0; // sleep until shutdown or a task is enrolled
  83   }
  84 
  85   int delay = _tasks[0]->time_to_next_interval();


< prev index next >