< prev index next >

src/share/vm/runtime/vmThread.cpp

Print this page




 209 void VMThread::create() {
 210   assert(vm_thread() == NULL, "we can only allocate one VMThread");
 211   _vm_thread = new VMThread();
 212 
 213   // Create VM operation queue
 214   _vm_queue = new VMOperationQueue();
 215   guarantee(_vm_queue != NULL, "just checking");
 216 
 217   _terminate_lock = new Monitor(Mutex::safepoint, "VMThread::_terminate_lock", true,
 218                                 Monitor::_safepoint_check_never);
 219 
 220   if (UsePerfData) {
 221     // jvmstat performance counters
 222     Thread* THREAD = Thread::current();
 223     _perf_accumulated_vm_operation_time =
 224                  PerfDataManager::create_counter(SUN_THREADS, "vmOperationTime",
 225                                                  PerfData::U_Ticks, CHECK);
 226   }
 227 }
 228 
 229 
 230 VMThread::VMThread() : NamedThread() {
 231   set_name("VM Thread");
 232 }
 233 
 234 void VMThread::destroy() {
 235   if (_vm_thread != NULL) {
 236     delete _vm_thread;
 237     _vm_thread = NULL;      // VM thread is gone
 238   }
 239 }
 240 
 241 void VMThread::run() {
 242   assert(this == vm_thread(), "check");
 243 
 244   this->initialize_named_thread();
 245   this->record_stack_base_and_size();
 246   // Notify_lock wait checks on active_handles() to rewait in
 247   // case of spurious wakeup, it should wait on the last
 248   // value set prior to the notify
 249   this->set_active_handles(JNIHandleBlock::allocate_block());
 250 
 251   {
 252     MutexLocker ml(Notify_lock);
 253     Notify_lock->notify();
 254   }
 255   // Notify_lock is destroyed by Threads::create_vm()
 256 
 257   int prio = (VMThreadPriority == -1)
 258     ? os::java_to_os_priority[NearMaxPriority]


 291 
 292   CompileBroker::set_should_block();
 293 
 294   // wait for threads (compiler threads or daemon threads) in the
 295   // _thread_in_native state to block.
 296   VM_Exit::wait_for_threads_in_native_to_block();
 297 
 298   // signal other threads that VM process is gone
 299   {
 300     // Note: we must have the _no_safepoint_check_flag. Mutex::lock() allows
 301     // VM thread to enter any lock at Safepoint as long as its _owner is NULL.
 302     // If that happens after _terminate_lock->wait() has unset _owner
 303     // but before it actually drops the lock and waits, the notification below
 304     // may get lost and we will have a hang. To avoid this, we need to use
 305     // Mutex::lock_without_safepoint_check().
 306     MutexLockerEx ml(_terminate_lock, Mutex::_no_safepoint_check_flag);
 307     _terminated = true;
 308     _terminate_lock->notify();
 309   }
 310 
 311   // Deletion must be done synchronously by the JNI DestroyJavaVM thread
 312   // so that the VMThread deletion completes before the main thread frees
 313   // up the CodeHeap.
 314 
 315 }
 316 
 317 
 318 // Notify the VMThread that the last non-daemon JavaThread has terminated,
 319 // and wait until operation is performed.
 320 void VMThread::wait_for_vm_thread_exit() {
 321   { MutexLocker mu(VMOperationQueue_lock);
 322     _should_terminate = true;
 323     VMOperationQueue_lock->notify();
 324   }
 325 
 326   // Note: VM thread leaves at Safepoint. We are not stopped by Safepoint
 327   // because this thread has been removed from the threads list. But anything
 328   // that could get blocked by Safepoint should not be used after this point,
 329   // otherwise we will hang, since there is no one can end the safepoint.
 330 
 331   // Wait until VM thread is terminated
 332   // Note: it should be OK to use Terminator_lock here. But this is called
 333   // at a very delicate time (VM shutdown) and we are operating in non- VM




 209 void VMThread::create() {
 210   assert(vm_thread() == NULL, "we can only allocate one VMThread");
 211   _vm_thread = new VMThread();
 212 
 213   // Create VM operation queue
 214   _vm_queue = new VMOperationQueue();
 215   guarantee(_vm_queue != NULL, "just checking");
 216 
 217   _terminate_lock = new Monitor(Mutex::safepoint, "VMThread::_terminate_lock", true,
 218                                 Monitor::_safepoint_check_never);
 219 
 220   if (UsePerfData) {
 221     // jvmstat performance counters
 222     Thread* THREAD = Thread::current();
 223     _perf_accumulated_vm_operation_time =
 224                  PerfDataManager::create_counter(SUN_THREADS, "vmOperationTime",
 225                                                  PerfData::U_Ticks, CHECK);
 226   }
 227 }
 228 

 229 VMThread::VMThread() : NamedThread() {
 230   set_name("VM Thread");
 231 }
 232 
 233 void VMThread::destroy() {


 234   _vm_thread = NULL;      // VM thread is gone

 235 }
 236 
 237 void VMThread::run() {
 238   assert(this == vm_thread(), "check");
 239 
 240   this->initialize_named_thread();
 241   this->record_stack_base_and_size();
 242   // Notify_lock wait checks on active_handles() to rewait in
 243   // case of spurious wakeup, it should wait on the last
 244   // value set prior to the notify
 245   this->set_active_handles(JNIHandleBlock::allocate_block());
 246 
 247   {
 248     MutexLocker ml(Notify_lock);
 249     Notify_lock->notify();
 250   }
 251   // Notify_lock is destroyed by Threads::create_vm()
 252 
 253   int prio = (VMThreadPriority == -1)
 254     ? os::java_to_os_priority[NearMaxPriority]


 287 
 288   CompileBroker::set_should_block();
 289 
 290   // wait for threads (compiler threads or daemon threads) in the
 291   // _thread_in_native state to block.
 292   VM_Exit::wait_for_threads_in_native_to_block();
 293 
 294   // signal other threads that VM process is gone
 295   {
 296     // Note: we must have the _no_safepoint_check_flag. Mutex::lock() allows
 297     // VM thread to enter any lock at Safepoint as long as its _owner is NULL.
 298     // If that happens after _terminate_lock->wait() has unset _owner
 299     // but before it actually drops the lock and waits, the notification below
 300     // may get lost and we will have a hang. To avoid this, we need to use
 301     // Mutex::lock_without_safepoint_check().
 302     MutexLockerEx ml(_terminate_lock, Mutex::_no_safepoint_check_flag);
 303     _terminated = true;
 304     _terminate_lock->notify();
 305   }
 306 
 307   // We are now racing with the VM termination being carried out in
 308   // another thread, so we don't "delete this". Numerous threads don't
 309   // get deleted when the VM terminates
 310 
 311 }
 312 
 313 
 314 // Notify the VMThread that the last non-daemon JavaThread has terminated,
 315 // and wait until operation is performed.
 316 void VMThread::wait_for_vm_thread_exit() {
 317   { MutexLocker mu(VMOperationQueue_lock);
 318     _should_terminate = true;
 319     VMOperationQueue_lock->notify();
 320   }
 321 
 322   // Note: VM thread leaves at Safepoint. We are not stopped by Safepoint
 323   // because this thread has been removed from the threads list. But anything
 324   // that could get blocked by Safepoint should not be used after this point,
 325   // otherwise we will hang, since there is no one can end the safepoint.
 326 
 327   // Wait until VM thread is terminated
 328   // Note: it should be OK to use Terminator_lock here. But this is called
 329   // at a very delicate time (VM shutdown) and we are operating in non- VM


< prev index next >