98 static volatile int PageArmed = 0 ; // safepoint polling page is RO|RW vs PROT_NONE
99 static volatile int TryingToBlock = 0 ; // proximate value -- for advisory use only
100 static bool timeout_error_printed = false;
101
102 // Roll all threads forward to a safepoint and suspend them all
103 void SafepointSynchronize::begin() {
104
105 Thread* myThread = Thread::current();
106 assert(myThread->is_VM_thread(), "Only VM thread may execute a safepoint");
107
108 if (PrintSafepointStatistics || PrintSafepointStatisticsTimeout > 0) {
109 _safepoint_begin_time = os::javaTimeNanos();
110 _ts_of_current_safepoint = tty->time_stamp().seconds();
111 }
112
113 #if INCLUDE_ALL_GCS
114 if (UseConcMarkSweepGC) {
115 // In the future we should investigate whether CMS can use the
116 // more-general mechanism below. DLD (01/05).
117 ConcurrentMarkSweepThread::synchronize(false);
118 } else if (UseG1GC) {
119 SuspendibleThreadSet::synchronize();
120 }
121 #endif // INCLUDE_ALL_GCS
122
123 // By getting the Threads_lock, we assure that no threads are about to start or
124 // exit. It is released again in SafepointSynchronize::end().
125 Threads_lock->lock();
126
127 assert( _state == _not_synchronized, "trying to safepoint synchronize with wrong state");
128
129 int nof_threads = Threads::number_of_threads();
130
131 if (TraceSafepoint) {
132 tty->print_cr("Safepoint synchronization initiated. (%d)", nof_threads);
133 }
134
135 RuntimeService::record_safepoint_begin();
136
137 MutexLocker mu(Safepoint_lock);
138
474 if (VMThreadHintNoPreempt) {
475 os::hint_no_preempt();
476 }
477 ThreadSafepointState* cur_state = current->safepoint_state();
478 assert(cur_state->type() != ThreadSafepointState::_running, "Thread not suspended at safepoint");
479 cur_state->restart();
480 assert(cur_state->is_running(), "safepoint state has not been reset");
481 }
482
483 RuntimeService::record_safepoint_end();
484
485 // Release threads lock, so threads can be created/destroyed again. It will also starts all threads
486 // blocked in signal_thread_blocked
487 Threads_lock->unlock();
488
489 }
490 #if INCLUDE_ALL_GCS
491 // If there are any concurrent GC threads resume them.
492 if (UseConcMarkSweepGC) {
493 ConcurrentMarkSweepThread::desynchronize(false);
494 } else if (UseG1GC) {
495 SuspendibleThreadSet::desynchronize();
496 }
497 #endif // INCLUDE_ALL_GCS
498 // record this time so VMThread can keep track how much time has elasped
499 // since last safepoint.
500 _end_of_last_safepoint = os::javaTimeMillis();
501 }
502
503 bool SafepointSynchronize::is_cleanup_needed() {
504 // Need a safepoint if some inline cache buffers is non-empty
505 if (!InlineCacheBuffer::is_empty()) return true;
506 return false;
507 }
508
509
510
511 // Various cleaning tasks that should be done periodically at safepoints
512 void SafepointSynchronize::do_cleanup_tasks() {
513 {
514 TraceTime t1("deflating idle monitors", TraceSafepointCleanupTime);
|
98 static volatile int PageArmed = 0 ; // safepoint polling page is RO|RW vs PROT_NONE
99 static volatile int TryingToBlock = 0 ; // proximate value -- for advisory use only
100 static bool timeout_error_printed = false;
101
102 // Roll all threads forward to a safepoint and suspend them all
103 void SafepointSynchronize::begin() {
104
105 Thread* myThread = Thread::current();
106 assert(myThread->is_VM_thread(), "Only VM thread may execute a safepoint");
107
108 if (PrintSafepointStatistics || PrintSafepointStatisticsTimeout > 0) {
109 _safepoint_begin_time = os::javaTimeNanos();
110 _ts_of_current_safepoint = tty->time_stamp().seconds();
111 }
112
113 #if INCLUDE_ALL_GCS
114 if (UseConcMarkSweepGC) {
115 // In the future we should investigate whether CMS can use the
116 // more-general mechanism below. DLD (01/05).
117 ConcurrentMarkSweepThread::synchronize(false);
118 } else if (UseG1GC || (UseShenandoahGC && UseStringDeduplication)) {
119 SuspendibleThreadSet::synchronize();
120 }
121 #endif // INCLUDE_ALL_GCS
122
123 // By getting the Threads_lock, we assure that no threads are about to start or
124 // exit. It is released again in SafepointSynchronize::end().
125 Threads_lock->lock();
126
127 assert( _state == _not_synchronized, "trying to safepoint synchronize with wrong state");
128
129 int nof_threads = Threads::number_of_threads();
130
131 if (TraceSafepoint) {
132 tty->print_cr("Safepoint synchronization initiated. (%d)", nof_threads);
133 }
134
135 RuntimeService::record_safepoint_begin();
136
137 MutexLocker mu(Safepoint_lock);
138
474 if (VMThreadHintNoPreempt) {
475 os::hint_no_preempt();
476 }
477 ThreadSafepointState* cur_state = current->safepoint_state();
478 assert(cur_state->type() != ThreadSafepointState::_running, "Thread not suspended at safepoint");
479 cur_state->restart();
480 assert(cur_state->is_running(), "safepoint state has not been reset");
481 }
482
483 RuntimeService::record_safepoint_end();
484
485 // Release threads lock, so threads can be created/destroyed again. It will also starts all threads
486 // blocked in signal_thread_blocked
487 Threads_lock->unlock();
488
489 }
490 #if INCLUDE_ALL_GCS
491 // If there are any concurrent GC threads resume them.
492 if (UseConcMarkSweepGC) {
493 ConcurrentMarkSweepThread::desynchronize(false);
494 } else if (UseG1GC || (UseShenandoahGC && UseStringDeduplication)) {
495 SuspendibleThreadSet::desynchronize();
496 }
497 #endif // INCLUDE_ALL_GCS
498 // record this time so VMThread can keep track how much time has elasped
499 // since last safepoint.
500 _end_of_last_safepoint = os::javaTimeMillis();
501 }
502
503 bool SafepointSynchronize::is_cleanup_needed() {
504 // Need a safepoint if some inline cache buffers is non-empty
505 if (!InlineCacheBuffer::is_empty()) return true;
506 return false;
507 }
508
509
510
511 // Various cleaning tasks that should be done periodically at safepoints
512 void SafepointSynchronize::do_cleanup_tasks() {
513 {
514 TraceTime t1("deflating idle monitors", TraceSafepointCleanupTime);
|