< prev index next >

src/share/vm/runtime/safepoint.cpp

Print this page




  41 #include "runtime/deoptimization.hpp"
  42 #include "runtime/frame.inline.hpp"
  43 #include "runtime/interfaceSupport.hpp"
  44 #include "runtime/mutexLocker.hpp"
  45 #include "runtime/orderAccess.inline.hpp"
  46 #include "runtime/osThread.hpp"
  47 #include "runtime/safepoint.hpp"
  48 #include "runtime/signature.hpp"
  49 #include "runtime/stubCodeGenerator.hpp"
  50 #include "runtime/stubRoutines.hpp"
  51 #include "runtime/sweeper.hpp"
  52 #include "runtime/synchronizer.hpp"
  53 #include "runtime/thread.inline.hpp"
  54 #include "services/runtimeService.hpp"
  55 #include "utilities/events.hpp"
  56 #include "utilities/macros.hpp"
  57 #ifdef TARGET_ARCH_x86
  58 # include "nativeInst_x86.hpp"
  59 # include "vmreg_x86.inline.hpp"
  60 #endif




  61 #ifdef TARGET_ARCH_sparc
  62 # include "nativeInst_sparc.hpp"
  63 # include "vmreg_sparc.inline.hpp"
  64 #endif
  65 #ifdef TARGET_ARCH_zero
  66 # include "nativeInst_zero.hpp"
  67 # include "vmreg_zero.inline.hpp"
  68 #endif
  69 #ifdef TARGET_ARCH_arm
  70 # include "nativeInst_arm.hpp"
  71 # include "vmreg_arm.inline.hpp"
  72 #endif
  73 #ifdef TARGET_ARCH_ppc
  74 # include "nativeInst_ppc.hpp"
  75 # include "vmreg_ppc.inline.hpp"
  76 #endif
  77 #if INCLUDE_ALL_GCS
  78 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
  79 #include "gc_implementation/shared/suspendibleThreadSet.hpp"
  80 #endif // INCLUDE_ALL_GCS


 162 static volatile int PageArmed = 0 ;        // safepoint polling page is RO|RW vs PROT_NONE
 163 static volatile int TryingToBlock = 0 ;    // proximate value -- for advisory use only
 164 static bool timeout_error_printed = false;
 165 
 166 // Roll all threads forward to a safepoint and suspend them all
 167 void SafepointSynchronize::begin() {
 168   EventSafepointBegin begin_event;
 169   Thread* myThread = Thread::current();
 170   assert(myThread->is_VM_thread(), "Only VM thread may execute a safepoint");
 171 
 172   if (PrintSafepointStatistics || PrintSafepointStatisticsTimeout > 0) {
 173     _safepoint_begin_time = os::javaTimeNanos();
 174     _ts_of_current_safepoint = tty->time_stamp().seconds();
 175   }
 176 
 177 #if INCLUDE_ALL_GCS
 178   if (UseConcMarkSweepGC) {
 179     // In the future we should investigate whether CMS can use the
 180     // more-general mechanism below.  DLD (01/05).
 181     ConcurrentMarkSweepThread::synchronize(false);
 182   } else if (UseG1GC) {
 183     SuspendibleThreadSet::synchronize();
 184   }
 185 #endif // INCLUDE_ALL_GCS
 186 
 187   // By getting the Threads_lock, we assure that no threads are about to start or
 188   // exit. It is released again in SafepointSynchronize::end().
 189   Threads_lock->lock();
 190 
 191   assert( _state == _not_synchronized, "trying to safepoint synchronize with wrong state");
 192 
 193   int nof_threads = Threads::number_of_threads();
 194 
 195   if (TraceSafepoint) {
 196     tty->print_cr("Safepoint synchronization initiated. (%d)", nof_threads);
 197   }
 198 
 199   RuntimeService::record_safepoint_begin();
 200 
 201   MutexLocker mu(Safepoint_lock);
 202 


 568       if (VMThreadHintNoPreempt) {
 569         os::hint_no_preempt();
 570       }
 571       ThreadSafepointState* cur_state = current->safepoint_state();
 572       assert(cur_state->type() != ThreadSafepointState::_running, "Thread not suspended at safepoint");
 573       cur_state->restart();
 574       assert(cur_state->is_running(), "safepoint state has not been reset");
 575     }
 576 
 577     RuntimeService::record_safepoint_end();
 578 
 579     // Release threads lock, so threads can be created/destroyed again. It will also starts all threads
 580     // blocked in signal_thread_blocked
 581     Threads_lock->unlock();
 582 
 583   }
 584 #if INCLUDE_ALL_GCS
 585   // If there are any concurrent GC threads resume them.
 586   if (UseConcMarkSweepGC) {
 587     ConcurrentMarkSweepThread::desynchronize(false);
 588   } else if (UseG1GC) {
 589     SuspendibleThreadSet::desynchronize();
 590   }
 591 #endif // INCLUDE_ALL_GCS
 592   // record this time so VMThread can keep track how much time has elasped
 593   // since last safepoint.
 594   _end_of_last_safepoint = os::javaTimeMillis();
 595   if (event.should_commit()) {
 596     post_safepoint_end_event(&event);
 597   }
 598 }
 599 
 600 bool SafepointSynchronize::is_cleanup_needed() {
 601   // Need a safepoint if some inline cache buffers is non-empty
 602   if (!InlineCacheBuffer::is_empty()) return true;
 603   return false;
 604 }
 605 
 606 
 607 
 608 // Various cleaning tasks that should be done periodically at safepoints




  41 #include "runtime/deoptimization.hpp"
  42 #include "runtime/frame.inline.hpp"
  43 #include "runtime/interfaceSupport.hpp"
  44 #include "runtime/mutexLocker.hpp"
  45 #include "runtime/orderAccess.inline.hpp"
  46 #include "runtime/osThread.hpp"
  47 #include "runtime/safepoint.hpp"
  48 #include "runtime/signature.hpp"
  49 #include "runtime/stubCodeGenerator.hpp"
  50 #include "runtime/stubRoutines.hpp"
  51 #include "runtime/sweeper.hpp"
  52 #include "runtime/synchronizer.hpp"
  53 #include "runtime/thread.inline.hpp"
  54 #include "services/runtimeService.hpp"
  55 #include "utilities/events.hpp"
  56 #include "utilities/macros.hpp"
  57 #ifdef TARGET_ARCH_x86
  58 # include "nativeInst_x86.hpp"
  59 # include "vmreg_x86.inline.hpp"
  60 #endif
  61 #ifdef TARGET_ARCH_aarch64
  62 # include "nativeInst_aarch64.hpp"
  63 # include "vmreg_aarch64.inline.hpp"
  64 #endif
  65 #ifdef TARGET_ARCH_sparc
  66 # include "nativeInst_sparc.hpp"
  67 # include "vmreg_sparc.inline.hpp"
  68 #endif
  69 #ifdef TARGET_ARCH_zero
  70 # include "nativeInst_zero.hpp"
  71 # include "vmreg_zero.inline.hpp"
  72 #endif
  73 #ifdef TARGET_ARCH_arm
  74 # include "nativeInst_arm.hpp"
  75 # include "vmreg_arm.inline.hpp"
  76 #endif
  77 #ifdef TARGET_ARCH_ppc
  78 # include "nativeInst_ppc.hpp"
  79 # include "vmreg_ppc.inline.hpp"
  80 #endif
  81 #if INCLUDE_ALL_GCS
  82 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
  83 #include "gc_implementation/shared/suspendibleThreadSet.hpp"
  84 #endif // INCLUDE_ALL_GCS


 166 static volatile int PageArmed = 0 ;        // safepoint polling page is RO|RW vs PROT_NONE
 167 static volatile int TryingToBlock = 0 ;    // proximate value -- for advisory use only
 168 static bool timeout_error_printed = false;
 169 
 170 // Roll all threads forward to a safepoint and suspend them all
 171 void SafepointSynchronize::begin() {
 172   EventSafepointBegin begin_event;
 173   Thread* myThread = Thread::current();
 174   assert(myThread->is_VM_thread(), "Only VM thread may execute a safepoint");
 175 
 176   if (PrintSafepointStatistics || PrintSafepointStatisticsTimeout > 0) {
 177     _safepoint_begin_time = os::javaTimeNanos();
 178     _ts_of_current_safepoint = tty->time_stamp().seconds();
 179   }
 180 
 181 #if INCLUDE_ALL_GCS
 182   if (UseConcMarkSweepGC) {
 183     // In the future we should investigate whether CMS can use the
 184     // more-general mechanism below.  DLD (01/05).
 185     ConcurrentMarkSweepThread::synchronize(false);
 186   } else if (UseG1GC || (UseShenandoahGC && UseStringDeduplication)) {
 187     SuspendibleThreadSet::synchronize();
 188   }
 189 #endif // INCLUDE_ALL_GCS
 190 
 191   // By getting the Threads_lock, we assure that no threads are about to start or
 192   // exit. It is released again in SafepointSynchronize::end().
 193   Threads_lock->lock();
 194 
 195   assert( _state == _not_synchronized, "trying to safepoint synchronize with wrong state");
 196 
 197   int nof_threads = Threads::number_of_threads();
 198 
 199   if (TraceSafepoint) {
 200     tty->print_cr("Safepoint synchronization initiated. (%d)", nof_threads);
 201   }
 202 
 203   RuntimeService::record_safepoint_begin();
 204 
 205   MutexLocker mu(Safepoint_lock);
 206 


 572       if (VMThreadHintNoPreempt) {
 573         os::hint_no_preempt();
 574       }
 575       ThreadSafepointState* cur_state = current->safepoint_state();
 576       assert(cur_state->type() != ThreadSafepointState::_running, "Thread not suspended at safepoint");
 577       cur_state->restart();
 578       assert(cur_state->is_running(), "safepoint state has not been reset");
 579     }
 580 
 581     RuntimeService::record_safepoint_end();
 582 
 583     // Release threads lock, so threads can be created/destroyed again. It will also starts all threads
 584     // blocked in signal_thread_blocked
 585     Threads_lock->unlock();
 586 
 587   }
 588 #if INCLUDE_ALL_GCS
 589   // If there are any concurrent GC threads resume them.
 590   if (UseConcMarkSweepGC) {
 591     ConcurrentMarkSweepThread::desynchronize(false);
 592   } else if (UseG1GC || (UseShenandoahGC && UseStringDeduplication)) {
 593     SuspendibleThreadSet::desynchronize();
 594   }
 595 #endif // INCLUDE_ALL_GCS
 596   // record this time so VMThread can keep track how much time has elasped
 597   // since last safepoint.
 598   _end_of_last_safepoint = os::javaTimeMillis();
 599   if (event.should_commit()) {
 600     post_safepoint_end_event(&event);
 601   }
 602 }
 603 
 604 bool SafepointSynchronize::is_cleanup_needed() {
 605   // Need a safepoint if some inline cache buffers is non-empty
 606   if (!InlineCacheBuffer::is_empty()) return true;
 607   return false;
 608 }
 609 
 610 
 611 
 612 // Various cleaning tasks that should be done periodically at safepoints


< prev index next >