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) {
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) {
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
|
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
|