src/hotspot/share/runtime/vmThread.cpp
changeset 54278 16999bd91ba6
parent 53895 b22d8ae270a2
child 54623 1126f0607c70
equal deleted inserted replaced
54277:f283f6871336 54278:16999bd91ba6
   432 }
   432 }
   433 
   433 
   434 static VM_None    safepointALot_op("SafepointALot");
   434 static VM_None    safepointALot_op("SafepointALot");
   435 static VM_Cleanup cleanup_op;
   435 static VM_Cleanup cleanup_op;
   436 
   436 
   437 VM_Operation* VMThread::no_op_safepoint(bool check_time) {
   437 class HandshakeALotTC : public ThreadClosure {
       
   438  public:
       
   439   virtual void do_thread(Thread* thread) {
       
   440 #ifdef ASSERT
       
   441     assert(thread->is_Java_thread(), "must be");
       
   442     JavaThread* jt = (JavaThread*)thread;
       
   443     jt->verify_states_for_handshake();
       
   444 #endif
       
   445   }
       
   446 };
       
   447 
       
   448 VM_Operation* VMThread::no_op_safepoint() {
       
   449   // Check for handshakes first since we may need to return a VMop.
       
   450   if (HandshakeALot) {
       
   451     HandshakeALotTC haltc;
       
   452     Handshake::execute(&haltc);
       
   453   }
       
   454   // Check for a cleanup before SafepointALot to keep stats correct.
       
   455   long interval_ms = SafepointTracing::time_since_last_safepoint_ms();
       
   456   bool max_time_exceeded = GuaranteedSafepointInterval != 0 &&
       
   457                            (interval_ms >= GuaranteedSafepointInterval);
       
   458   if (max_time_exceeded && SafepointSynchronize::is_cleanup_needed()) {
       
   459     return &cleanup_op;
       
   460   }
   438   if (SafepointALot) {
   461   if (SafepointALot) {
   439     return &safepointALot_op;
   462     return &safepointALot_op;
   440   }
   463   }
   441   if (!SafepointSynchronize::is_cleanup_needed()) {
   464   // Nothing to be done.
   442     return NULL;
   465   return NULL;
   443   }
       
   444   if (check_time) {
       
   445     long interval_ms = SafepointTracing::time_since_last_safepoint_ms();
       
   446     bool max_time_exceeded = GuaranteedSafepointInterval != 0 &&
       
   447                              (interval_ms > GuaranteedSafepointInterval);
       
   448     if (!max_time_exceeded) {
       
   449       return NULL;
       
   450     }
       
   451   }
       
   452   return &cleanup_op;
       
   453 }
   466 }
   454 
   467 
   455 void VMThread::loop() {
   468 void VMThread::loop() {
   456   assert(_cur_vm_operation == NULL, "no current one should be executing");
   469   assert(_cur_vm_operation == NULL, "no current one should be executing");
   457 
   470 
   489             (os::elapsedTime() > (double)SelfDestructTimer * 60.0)) {
   502             (os::elapsedTime() > (double)SelfDestructTimer * 60.0)) {
   490           tty->print_cr("VM self-destructed");
   503           tty->print_cr("VM self-destructed");
   491           exit(-1);
   504           exit(-1);
   492         }
   505         }
   493 
   506 
   494         if (timedout && (_cur_vm_operation = VMThread::no_op_safepoint(false)) != NULL) {
   507         if (timedout) {
   495           MutexUnlockerEx mul(VMOperationQueue_lock,
   508           // Have to unlock VMOperationQueue_lock just in case no_op_safepoint()
   496                               Mutex::_no_safepoint_check_flag);
   509           // has to do a handshake.
   497           // Force a safepoint since we have not had one for at least
   510           MutexUnlockerEx mul(VMOperationQueue_lock, Mutex::_no_safepoint_check_flag);
   498           // 'GuaranteedSafepointInterval' milliseconds.  This will run all
   511           if ((_cur_vm_operation = VMThread::no_op_safepoint()) != NULL) {
   499           // the clean-up processing that needs to be done regularly at a
   512             // Force a safepoint since we have not had one for at least
   500           // safepoint
   513             // 'GuaranteedSafepointInterval' milliseconds and we need to clean
   501           SafepointSynchronize::begin();
   514             // something. This will run all the clean-up processing that needs
   502           #ifdef ASSERT
   515             // to be done at a safepoint.
       
   516             SafepointSynchronize::begin();
       
   517             #ifdef ASSERT
   503             if (GCALotAtAllSafepoints) InterfaceSupport::check_gc_alot();
   518             if (GCALotAtAllSafepoints) InterfaceSupport::check_gc_alot();
   504           #endif
   519             #endif
   505           SafepointSynchronize::end();
   520             SafepointSynchronize::end();
   506           _cur_vm_operation = NULL;
   521             _cur_vm_operation = NULL;
       
   522           }
   507         }
   523         }
   508         _cur_vm_operation = _vm_queue->remove_next();
   524         _cur_vm_operation = _vm_queue->remove_next();
   509 
   525 
   510         // If we are at a safepoint we will evaluate all the operations that
   526         // If we are at a safepoint we will evaluate all the operations that
   511         // follow that also require a safepoint
   527         // follow that also require a safepoint
   613     { MutexLockerEx mu(VMOperationRequest_lock,
   629     { MutexLockerEx mu(VMOperationRequest_lock,
   614                        Mutex::_no_safepoint_check_flag);
   630                        Mutex::_no_safepoint_check_flag);
   615       VMOperationRequest_lock->notify_all();
   631       VMOperationRequest_lock->notify_all();
   616     }
   632     }
   617 
   633 
   618     //
   634     // We want to make sure that we get to a safepoint regularly
   619     // We want to make sure that we get to a safepoint regularly.
   635     // even when executing VMops that don't require safepoints.
   620     //
   636     if ((_cur_vm_operation = VMThread::no_op_safepoint()) != NULL) {
   621     if ((_cur_vm_operation = VMThread::no_op_safepoint(false)) != NULL) {
       
   622       HandleMark hm(VMThread::vm_thread());
   637       HandleMark hm(VMThread::vm_thread());
   623       SafepointSynchronize::begin();
   638       SafepointSynchronize::begin();
   624       SafepointSynchronize::end();
   639       SafepointSynchronize::end();
   625       _cur_vm_operation = NULL;
   640       _cur_vm_operation = NULL;
   626     }
   641     }