hotspot/src/share/vm/runtime/safepoint.cpp
changeset 12108 b2ee55606008
parent 11637 030466036615
child 13087 673ea6efaf18
equal deleted inserted replaced
12107:0d67c9f2abf2 12108:b2ee55606008
   217   int ncpus = os::processor_count() ;
   217   int ncpus = os::processor_count() ;
   218 
   218 
   219 #ifdef ASSERT
   219 #ifdef ASSERT
   220   for (JavaThread *cur = Threads::first(); cur != NULL; cur = cur->next()) {
   220   for (JavaThread *cur = Threads::first(); cur != NULL; cur = cur->next()) {
   221     assert(cur->safepoint_state()->is_running(), "Illegal initial state");
   221     assert(cur->safepoint_state()->is_running(), "Illegal initial state");
       
   222     // Clear the visited flag to ensure that the critical counts are collected properly.
       
   223     cur->set_visited_for_critical_count(false);
   222   }
   224   }
   223 #endif // ASSERT
   225 #endif // ASSERT
   224 
   226 
   225   if (SafepointTimeout)
   227   if (SafepointTimeout)
   226     safepoint_limit_time = os::javaTimeNanos() + (jlong)SafepointTimeoutDelay * MICROUNITS;
   228     safepoint_limit_time = os::javaTimeNanos() + (jlong)SafepointTimeoutDelay * MICROUNITS;
   376   // Record state
   378   // Record state
   377   _state = _synchronized;
   379   _state = _synchronized;
   378 
   380 
   379   OrderAccess::fence();
   381   OrderAccess::fence();
   380 
   382 
       
   383 #ifdef ASSERT
       
   384   for (JavaThread *cur = Threads::first(); cur != NULL; cur = cur->next()) {
       
   385     // make sure all the threads were visited
       
   386     assert(cur->was_visited_for_critical_count(), "missed a thread");
       
   387   }
       
   388 #endif // ASSERT
       
   389 
   381   // Update the count of active JNI critical regions
   390   // Update the count of active JNI critical regions
   382   GC_locker::set_jni_lock_count(_current_jni_active_count);
   391   GC_locker::set_jni_lock_count(_current_jni_active_count);
   383 
   392 
   384   if (TraceSafepoint) {
   393   if (TraceSafepoint) {
   385     VM_Operation *op = VMThread::vm_operation();
   394     VM_Operation *op = VMThread::vm_operation();
   624         // Decrement the number of threads to wait for and signal vm thread
   633         // Decrement the number of threads to wait for and signal vm thread
   625         assert(_waiting_to_block > 0, "sanity check");
   634         assert(_waiting_to_block > 0, "sanity check");
   626         _waiting_to_block--;
   635         _waiting_to_block--;
   627         thread->safepoint_state()->set_has_called_back(true);
   636         thread->safepoint_state()->set_has_called_back(true);
   628 
   637 
       
   638         DEBUG_ONLY(thread->set_visited_for_critical_count(true));
   629         if (thread->in_critical()) {
   639         if (thread->in_critical()) {
   630           // Notice that this thread is in a critical section
   640           // Notice that this thread is in a critical section
   631           increment_jni_active_count();
   641           increment_jni_active_count();
   632         }
   642         }
   633 
   643 
   905 
   915 
   906   // Some JavaThread states have an initial safepoint state of
   916   // Some JavaThread states have an initial safepoint state of
   907   // running, but are actually at a safepoint. We will happily
   917   // running, but are actually at a safepoint. We will happily
   908   // agree and update the safepoint state here.
   918   // agree and update the safepoint state here.
   909   if (SafepointSynchronize::safepoint_safe(_thread, state)) {
   919   if (SafepointSynchronize::safepoint_safe(_thread, state)) {
       
   920     SafepointSynchronize::check_for_lazy_critical_native(_thread, state);
   910     roll_forward(_at_safepoint);
   921     roll_forward(_at_safepoint);
   911     SafepointSynchronize::check_for_lazy_critical_native(_thread, state);
       
   912     if (_thread->in_critical()) {
       
   913       // Notice that this thread is in a critical section
       
   914       SafepointSynchronize::increment_jni_active_count();
       
   915     }
       
   916     return;
   922     return;
   917   }
   923   }
   918 
   924 
   919   if (state == _thread_in_vm) {
   925   if (state == _thread_in_vm) {
   920     roll_forward(_call_back);
   926     roll_forward(_call_back);
   935   _type = type;
   941   _type = type;
   936 
   942 
   937   switch(_type) {
   943   switch(_type) {
   938     case _at_safepoint:
   944     case _at_safepoint:
   939       SafepointSynchronize::signal_thread_at_safepoint();
   945       SafepointSynchronize::signal_thread_at_safepoint();
       
   946       DEBUG_ONLY(_thread->set_visited_for_critical_count(true));
       
   947       if (_thread->in_critical()) {
       
   948         // Notice that this thread is in a critical section
       
   949         SafepointSynchronize::increment_jni_active_count();
       
   950       }
   940       break;
   951       break;
   941 
   952 
   942     case _call_back:
   953     case _call_back:
   943       set_has_called_back(false);
   954       set_has_called_back(false);
   944       break;
   955       break;