src/hotspot/share/runtime/vmThread.cpp
changeset 54645 05aaccf7d558
parent 54623 1126f0607c70
child 54663 f03d5a093093
equal deleted inserted replaced
54644:8d52b4c6f9d8 54645:05aaccf7d558
   340     // VM thread to enter any lock at Safepoint as long as its _owner is NULL.
   340     // VM thread to enter any lock at Safepoint as long as its _owner is NULL.
   341     // If that happens after _terminate_lock->wait() has unset _owner
   341     // If that happens after _terminate_lock->wait() has unset _owner
   342     // but before it actually drops the lock and waits, the notification below
   342     // but before it actually drops the lock and waits, the notification below
   343     // may get lost and we will have a hang. To avoid this, we need to use
   343     // may get lost and we will have a hang. To avoid this, we need to use
   344     // Mutex::lock_without_safepoint_check().
   344     // Mutex::lock_without_safepoint_check().
   345     MutexLocker ml(_terminate_lock, Mutex::_no_safepoint_check_flag);
   345     MonitorLocker ml(_terminate_lock, Mutex::_no_safepoint_check_flag);
   346     _terminated = true;
   346     _terminated = true;
   347     _terminate_lock->notify();
   347     ml.notify();
   348   }
   348   }
   349 
   349 
   350   // We are now racing with the VM termination being carried out in
   350   // We are now racing with the VM termination being carried out in
   351   // another thread, so we don't "delete this". Numerous threads don't
   351   // another thread, so we don't "delete this". Numerous threads don't
   352   // get deleted when the VM terminates
   352   // get deleted when the VM terminates
   371 
   371 
   372   // Wait until VM thread is terminated
   372   // Wait until VM thread is terminated
   373   // Note: it should be OK to use Terminator_lock here. But this is called
   373   // Note: it should be OK to use Terminator_lock here. But this is called
   374   // at a very delicate time (VM shutdown) and we are operating in non- VM
   374   // at a very delicate time (VM shutdown) and we are operating in non- VM
   375   // thread at Safepoint. It's safer to not share lock with other threads.
   375   // thread at Safepoint. It's safer to not share lock with other threads.
   376   { MutexLocker ml(_terminate_lock, Mutex::_no_safepoint_check_flag);
   376   { MonitorLocker ml(_terminate_lock, Mutex::_no_safepoint_check_flag);
   377     while(!VMThread::is_terminated()) {
   377     while(!VMThread::is_terminated()) {
   378         _terminate_lock->wait_without_safepoint_check();
   378       ml.wait();
   379     }
   379     }
   380   }
   380   }
   381 }
   381 }
   382 
   382 
   383 static void post_vm_operation_event(EventExecuteVMOperation* event, VM_Operation* op) {
   383 static void post_vm_operation_event(EventExecuteVMOperation* event, VM_Operation* op) {
   474     VM_Operation* safepoint_ops = NULL;
   474     VM_Operation* safepoint_ops = NULL;
   475     //
   475     //
   476     // Wait for VM operation
   476     // Wait for VM operation
   477     //
   477     //
   478     // use no_safepoint_check to get lock without attempting to "sneak"
   478     // use no_safepoint_check to get lock without attempting to "sneak"
   479     { MutexLocker mu_queue(VMOperationQueue_lock,
   479     { MonitorLocker mu_queue(VMOperationQueue_lock,
   480                            Mutex::_no_safepoint_check_flag);
   480                              Mutex::_no_safepoint_check_flag);
   481 
   481 
   482       // Look for new operation
   482       // Look for new operation
   483       assert(_cur_vm_operation == NULL, "no current one should be executing");
   483       assert(_cur_vm_operation == NULL, "no current one should be executing");
   484       _cur_vm_operation = _vm_queue->remove_next();
   484       _cur_vm_operation = _vm_queue->remove_next();
   485 
   485 
   492       }
   492       }
   493 
   493 
   494       while (!should_terminate() && _cur_vm_operation == NULL) {
   494       while (!should_terminate() && _cur_vm_operation == NULL) {
   495         // wait with a timeout to guarantee safepoints at regular intervals
   495         // wait with a timeout to guarantee safepoints at regular intervals
   496         bool timedout =
   496         bool timedout =
   497           VMOperationQueue_lock->wait_without_safepoint_check(GuaranteedSafepointInterval);
   497           mu_queue.wait(GuaranteedSafepointInterval);
   498 
   498 
   499         // Support for self destruction
   499         // Support for self destruction
   500         if ((SelfDestructTimer != 0) && !VMError::is_error_reported() &&
   500         if ((SelfDestructTimer != 0) && !VMError::is_error_reported() &&
   501             (os::elapsedTime() > (double)SelfDestructTimer * 60.0)) {
   501             (os::elapsedTime() > (double)SelfDestructTimer * 60.0)) {
   502           tty->print_cr("VM self-destructed");
   502           tty->print_cr("VM self-destructed");
   716     }
   716     }
   717 
   717 
   718     if (!concurrent) {
   718     if (!concurrent) {
   719       // Wait for completion of request (non-concurrent)
   719       // Wait for completion of request (non-concurrent)
   720       // Note: only a JavaThread triggers the safepoint check when locking
   720       // Note: only a JavaThread triggers the safepoint check when locking
   721       MutexLocker mu(VMOperationRequest_lock);
   721       MonitorLocker ml(VMOperationRequest_lock,
       
   722                        t->is_Java_thread() ? Mutex::_safepoint_check_flag : Mutex::_no_safepoint_check_flag);
   722       while(t->vm_operation_completed_count() < ticket) {
   723       while(t->vm_operation_completed_count() < ticket) {
   723         if (t->is_Java_thread()) {
   724         ml.wait();
   724           VMOperationRequest_lock->wait();
       
   725         } else {
       
   726           VMOperationRequest_lock->wait_without_safepoint_check();
       
   727         }
       
   728       }
   725       }
   729     }
   726     }
   730 
   727 
   731     if (execute_epilog) {
   728     if (execute_epilog) {
   732       op->doit_epilogue();
   729       op->doit_epilogue();