< prev index next >

src/hotspot/share/gc/shared/concurrentGCThread.cpp

Print this page




  34     _has_terminated(false) {}
  35 
  36 void ConcurrentGCThread::create_and_start(ThreadPriority prio) {
  37   if (os::create_thread(this, os::cgc_thread)) {
  38     os::set_priority(this, prio);
  39     os::start_thread(this);
  40   }
  41 }
  42 
  43 void ConcurrentGCThread::run() {
  44   // Setup handle area
  45   set_active_handles(JNIHandleBlock::allocate_block());
  46 
  47   // Wait for initialization to complete
  48   wait_init_completed();
  49 
  50   run_service();
  51 
  52   // Signal thread has terminated
  53   MonitorLocker ml(Terminator_lock);
  54   OrderAccess::release_store(&_has_terminated, true);
  55   ml.notify_all();
  56 }
  57 
  58 void ConcurrentGCThread::stop() {
  59   assert(!should_terminate(), "Invalid state");
  60   assert(!has_terminated(), "Invalid state");
  61 
  62   // Signal thread to terminate
  63   OrderAccess::release_store_fence(&_should_terminate, true);
  64 
  65   stop_service();
  66 
  67   // Wait for thread to terminate
  68   MonitorLocker ml(Terminator_lock);
  69   while (!_has_terminated) {
  70     ml.wait();
  71   }
  72 }
  73 
  74 bool ConcurrentGCThread::should_terminate() const {
  75   return OrderAccess::load_acquire(&_should_terminate);
  76 }
  77 
  78 bool ConcurrentGCThread::has_terminated() const {
  79   return OrderAccess::load_acquire(&_has_terminated);
  80 }


  34     _has_terminated(false) {}
  35 
  36 void ConcurrentGCThread::create_and_start(ThreadPriority prio) {
  37   if (os::create_thread(this, os::cgc_thread)) {
  38     os::set_priority(this, prio);
  39     os::start_thread(this);
  40   }
  41 }
  42 
  43 void ConcurrentGCThread::run() {
  44   // Setup handle area
  45   set_active_handles(JNIHandleBlock::allocate_block());
  46 
  47   // Wait for initialization to complete
  48   wait_init_completed();
  49 
  50   run_service();
  51 
  52   // Signal thread has terminated
  53   MonitorLocker ml(Terminator_lock);
  54   Atomic::release_store(&_has_terminated, true);
  55   ml.notify_all();
  56 }
  57 
  58 void ConcurrentGCThread::stop() {
  59   assert(!should_terminate(), "Invalid state");
  60   assert(!has_terminated(), "Invalid state");
  61 
  62   // Signal thread to terminate
  63   Atomic::release_store_fence(&_should_terminate, true);
  64 
  65   stop_service();
  66 
  67   // Wait for thread to terminate
  68   MonitorLocker ml(Terminator_lock);
  69   while (!_has_terminated) {
  70     ml.wait();
  71   }
  72 }
  73 
  74 bool ConcurrentGCThread::should_terminate() const {
  75   return Atomic::load_acquire(&_should_terminate);
  76 }
  77 
  78 bool ConcurrentGCThread::has_terminated() const {
  79   return Atomic::load_acquire(&_has_terminated);
  80 }
< prev index next >