< prev index next >

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

Print this page




  34 #include "runtime/os.hpp"
  35 
  36 ConcurrentGCThread::ConcurrentGCThread() :
  37   _should_terminate(false), _has_terminated(false) {
  38 };
  39 
  40 void ConcurrentGCThread::create_and_start() {
  41   if (os::create_thread(this, os::cgc_thread)) {
  42     // XXX: need to set this to low priority
  43     // unless "aggressive mode" set; priority
  44     // should be just less than that of VMThread.
  45     os::set_priority(this, NearMaxPriority);
  46     if (!_should_terminate && !DisableStartThread) {
  47       os::start_thread(this);
  48     }
  49   }
  50 }
  51 
  52 void ConcurrentGCThread::initialize_in_thread() {
  53   this->record_stack_base_and_size();
  54   this->initialize_thread_local_storage();
  55   this->initialize_named_thread();
  56   this->set_active_handles(JNIHandleBlock::allocate_block());
  57   // From this time Thread::current() should be working.
  58   assert(this == Thread::current(), "just checking");
  59 }
  60 
  61 void ConcurrentGCThread::wait_for_universe_init() {
  62   MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
  63   while (!is_init_completed() && !_should_terminate) {
  64     CGC_lock->wait(Mutex::_no_safepoint_check_flag, 200);
  65   }
  66 }
  67 
  68 void ConcurrentGCThread::terminate() {
  69   assert(_should_terminate, "Should only be called on terminate request.");
  70   // Signal that it is terminated
  71   {
  72     MutexLockerEx mu(Terminator_lock,
  73                      Mutex::_no_safepoint_check_flag);
  74     _has_terminated = true;
  75     Terminator_lock->notify();
  76   }
  77 
  78   // Thread destructor usually does this..
  79   ThreadLocalStorage::set_thread(NULL);
  80 }
  81 
  82 static void _sltLoop(JavaThread* thread, TRAPS) {
  83   SurrogateLockerThread* slt = (SurrogateLockerThread*)thread;
  84   slt->loop();
  85 }
  86 
  87 SurrogateLockerThread::SurrogateLockerThread() :
  88   JavaThread(&_sltLoop),
  89   _monitor(Mutex::nonleaf, "SLTMonitor", false,
  90            Monitor::_safepoint_check_sometimes),
  91   _buffer(empty)
  92 {}
  93 
  94 SurrogateLockerThread* SurrogateLockerThread::make(TRAPS) {
  95   Klass* k =
  96     SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(),
  97                                       true, CHECK_NULL);
  98   instanceKlassHandle klass (THREAD, k);
  99   instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL);




  34 #include "runtime/os.hpp"
  35 
  36 ConcurrentGCThread::ConcurrentGCThread() :
  37   _should_terminate(false), _has_terminated(false) {
  38 };
  39 
  40 void ConcurrentGCThread::create_and_start() {
  41   if (os::create_thread(this, os::cgc_thread)) {
  42     // XXX: need to set this to low priority
  43     // unless "aggressive mode" set; priority
  44     // should be just less than that of VMThread.
  45     os::set_priority(this, NearMaxPriority);
  46     if (!_should_terminate && !DisableStartThread) {
  47       os::start_thread(this);
  48     }
  49   }
  50 }
  51 
  52 void ConcurrentGCThread::initialize_in_thread() {
  53   this->record_stack_base_and_size();

  54   this->initialize_named_thread();
  55   this->set_active_handles(JNIHandleBlock::allocate_block());
  56   // From this time Thread::current() should be working.
  57   assert(this == Thread::current(), "just checking");
  58 }
  59 
  60 void ConcurrentGCThread::wait_for_universe_init() {
  61   MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
  62   while (!is_init_completed() && !_should_terminate) {
  63     CGC_lock->wait(Mutex::_no_safepoint_check_flag, 200);
  64   }
  65 }
  66 
  67 void ConcurrentGCThread::terminate() {
  68   assert(_should_terminate, "Should only be called on terminate request.");
  69   // Signal that it is terminated
  70   {
  71     MutexLockerEx mu(Terminator_lock,
  72                      Mutex::_no_safepoint_check_flag);
  73     _has_terminated = true;
  74     Terminator_lock->notify();
  75   }



  76 }
  77 
  78 static void _sltLoop(JavaThread* thread, TRAPS) {
  79   SurrogateLockerThread* slt = (SurrogateLockerThread*)thread;
  80   slt->loop();
  81 }
  82 
  83 SurrogateLockerThread::SurrogateLockerThread() :
  84   JavaThread(&_sltLoop),
  85   _monitor(Mutex::nonleaf, "SLTMonitor", false,
  86            Monitor::_safepoint_check_sometimes),
  87   _buffer(empty)
  88 {}
  89 
  90 SurrogateLockerThread* SurrogateLockerThread::make(TRAPS) {
  91   Klass* k =
  92     SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(),
  93                                       true, CHECK_NULL);
  94   instanceKlassHandle klass (THREAD, k);
  95   instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL);


< prev index next >