hotspot/src/share/vm/runtime/vmThread.cpp
changeset 46496 76ed99d51a67
parent 40667 f9cf2db7f59f
child 46589 f1c04490ded1
equal deleted inserted replaced
46495:34f7d403039f 46496:76ed99d51a67
   202 Monitor*          VMThread::_terminate_lock     = NULL;
   202 Monitor*          VMThread::_terminate_lock     = NULL;
   203 VMThread*         VMThread::_vm_thread          = NULL;
   203 VMThread*         VMThread::_vm_thread          = NULL;
   204 VM_Operation*     VMThread::_cur_vm_operation   = NULL;
   204 VM_Operation*     VMThread::_cur_vm_operation   = NULL;
   205 VMOperationQueue* VMThread::_vm_queue           = NULL;
   205 VMOperationQueue* VMThread::_vm_queue           = NULL;
   206 PerfCounter*      VMThread::_perf_accumulated_vm_operation_time = NULL;
   206 PerfCounter*      VMThread::_perf_accumulated_vm_operation_time = NULL;
       
   207 const char*       VMThread::_no_op_reason       = NULL;
   207 
   208 
   208 
   209 
   209 void VMThread::create() {
   210 void VMThread::create() {
   210   assert(vm_thread() == NULL, "we can only allocate one VMThread");
   211   assert(vm_thread() == NULL, "we can only allocate one VMThread");
   211   _vm_thread = new VMThread();
   212   _vm_thread = new VMThread();
   271     xtty->end_elem();
   272     xtty->end_elem();
   272     assert(should_terminate(), "termination flag must be set");
   273     assert(should_terminate(), "termination flag must be set");
   273   }
   274   }
   274 
   275 
   275   // 4526887 let VM thread exit at Safepoint
   276   // 4526887 let VM thread exit at Safepoint
       
   277   _no_op_reason = "Halt";
   276   SafepointSynchronize::begin();
   278   SafepointSynchronize::begin();
   277 
   279 
   278   if (VerifyBeforeExit) {
   280   if (VerifyBeforeExit) {
   279     HandleMark hm(VMThread::vm_thread());
   281     HandleMark hm(VMThread::vm_thread());
   280     // Among other things, this ensures that Eden top is correct.
   282     // Among other things, this ensures that Eden top is correct.
   378   if (c_heap_allocated) {
   380   if (c_heap_allocated) {
   379     delete _cur_vm_operation;
   381     delete _cur_vm_operation;
   380   }
   382   }
   381 }
   383 }
   382 
   384 
       
   385 bool VMThread::no_op_safepoint_needed(bool check_time) {
       
   386   if (SafepointALot) {
       
   387     _no_op_reason = "SafepointALot";
       
   388     return true;
       
   389   }
       
   390   if (!SafepointSynchronize::is_cleanup_needed()) {
       
   391     return false;
       
   392   }
       
   393   if (check_time) {
       
   394     long interval = SafepointSynchronize::last_non_safepoint_interval();
       
   395     bool max_time_exceeded = GuaranteedSafepointInterval != 0 &&
       
   396                              (interval > GuaranteedSafepointInterval);
       
   397     if (!max_time_exceeded) {
       
   398       return false;
       
   399     }
       
   400   }
       
   401   _no_op_reason = "Cleanup";
       
   402   return true;
       
   403 }
   383 
   404 
   384 void VMThread::loop() {
   405 void VMThread::loop() {
   385   assert(_cur_vm_operation == NULL, "no current one should be executing");
   406   assert(_cur_vm_operation == NULL, "no current one should be executing");
   386 
   407 
   387   while(true) {
   408   while(true) {
   416             (os::elapsedTime() > (double)SelfDestructTimer * 60.0)) {
   437             (os::elapsedTime() > (double)SelfDestructTimer * 60.0)) {
   417           tty->print_cr("VM self-destructed");
   438           tty->print_cr("VM self-destructed");
   418           exit(-1);
   439           exit(-1);
   419         }
   440         }
   420 
   441 
   421         if (timedout && (SafepointALot ||
   442         if (timedout && VMThread::no_op_safepoint_needed(false)) {
   422                          SafepointSynchronize::is_cleanup_needed())) {
       
   423           MutexUnlockerEx mul(VMOperationQueue_lock,
   443           MutexUnlockerEx mul(VMOperationQueue_lock,
   424                               Mutex::_no_safepoint_check_flag);
   444                               Mutex::_no_safepoint_check_flag);
   425           // Force a safepoint since we have not had one for at least
   445           // Force a safepoint since we have not had one for at least
   426           // 'GuaranteedSafepointInterval' milliseconds.  This will run all
   446           // 'GuaranteedSafepointInterval' milliseconds.  This will run all
   427           // the clean-up processing that needs to be done regularly at a
   447           // the clean-up processing that needs to be done regularly at a
   540     }
   560     }
   541 
   561 
   542     //
   562     //
   543     // We want to make sure that we get to a safepoint regularly.
   563     // We want to make sure that we get to a safepoint regularly.
   544     //
   564     //
   545     if (SafepointALot || SafepointSynchronize::is_cleanup_needed()) {
   565     if (VMThread::no_op_safepoint_needed(true)) {
   546       long interval          = SafepointSynchronize::last_non_safepoint_interval();
   566       HandleMark hm(VMThread::vm_thread());
   547       bool max_time_exceeded = GuaranteedSafepointInterval != 0 && (interval > GuaranteedSafepointInterval);
   567       SafepointSynchronize::begin();
   548       if (SafepointALot || max_time_exceeded) {
   568       SafepointSynchronize::end();
   549         HandleMark hm(VMThread::vm_thread());
       
   550         SafepointSynchronize::begin();
       
   551         SafepointSynchronize::end();
       
   552       }
       
   553     }
   569     }
   554   }
   570   }
   555 }
   571 }
   556 
   572 
   557 void VMThread::execute(VM_Operation* op) {
   573 void VMThread::execute(VM_Operation* op) {