43 #include "runtime/compilationPolicy.hpp"
44 #include "runtime/deoptimization.hpp"
45 #include "runtime/frame.inline.hpp"
46 #include "runtime/interfaceSupport.hpp"
47 #include "runtime/mutexLocker.hpp"
48 #include "runtime/orderAccess.inline.hpp"
49 #include "runtime/osThread.hpp"
50 #include "runtime/safepoint.hpp"
51 #include "runtime/signature.hpp"
52 #include "runtime/stubCodeGenerator.hpp"
53 #include "runtime/stubRoutines.hpp"
54 #include "runtime/sweeper.hpp"
55 #include "runtime/synchronizer.hpp"
56 #include "runtime/thread.inline.hpp"
57 #include "runtime/timerTrace.hpp"
58 #include "services/runtimeService.hpp"
59 #include "trace/tracing.hpp"
60 #include "trace/traceMacros.hpp"
61 #include "utilities/events.hpp"
62 #include "utilities/macros.hpp"
63 #if INCLUDE_ALL_GCS
64 #include "gc/cms/concurrentMarkSweepThread.hpp"
65 #include "gc/g1/suspendibleThreadSet.hpp"
66 #endif // INCLUDE_ALL_GCS
67 #ifdef COMPILER1
68 #include "c1/c1_globals.hpp"
69 #endif
70
71 // --------------------------------------------------------------------------------------------------
72 // Implementation of Safepoint begin/end
73
74 SafepointSynchronize::SynchronizeState volatile SafepointSynchronize::_state = SafepointSynchronize::_not_synchronized;
75 volatile int SafepointSynchronize::_waiting_to_block = 0;
76 volatile int SafepointSynchronize::_safepoint_counter = 0;
77 int SafepointSynchronize::_current_jni_active_count = 0;
78 long SafepointSynchronize::_end_of_last_safepoint = 0;
79 static volatile int PageArmed = 0 ; // safepoint polling page is RO|RW vs PROT_NONE
80 static volatile int TryingToBlock = 0 ; // proximate value -- for advisory use only
81 static bool timeout_error_printed = false;
82
83 // Roll all threads forward to a safepoint and suspend them all
84 void SafepointSynchronize::begin() {
85 EventSafepointBegin begin_event;
86 Thread* myThread = Thread::current();
87 assert(myThread->is_VM_thread(), "Only VM thread may execute a safepoint");
88
89 if (PrintSafepointStatistics || PrintSafepointStatisticsTimeout > 0) {
90 _safepoint_begin_time = os::javaTimeNanos();
91 _ts_of_current_safepoint = tty->time_stamp().seconds();
92 }
93
94 #if INCLUDE_ALL_GCS
95 if (UseConcMarkSweepGC) {
96 // In the future we should investigate whether CMS can use the
97 // more-general mechanism below. DLD (01/05).
98 ConcurrentMarkSweepThread::synchronize(false);
99 } else if (UseG1GC) {
100 SuspendibleThreadSet::synchronize();
101 }
102 #endif // INCLUDE_ALL_GCS
103
104 // By getting the Threads_lock, we assure that no threads are about to start or
105 // exit. It is released again in SafepointSynchronize::end().
106 Threads_lock->lock();
107
108 assert( _state == _not_synchronized, "trying to safepoint synchronize with wrong state");
109
110 int nof_threads = Threads::number_of_threads();
111
112 log_debug(safepoint)("Safepoint synchronization initiated. (%d)", nof_threads);
113
114 RuntimeService::record_safepoint_begin();
115
116 MutexLocker mu(Safepoint_lock);
117
118 // Reset the count of active JNI critical threads
119 _current_jni_active_count = 0;
120
121 // Set number of threads to wait for, before we initiate the callbacks
122 _waiting_to_block = nof_threads;
491 // of suspending threads.
492 //
493 // TODO-FIXME: the comments above are vestigial and no longer apply.
494 // Furthermore, using solaris' schedctl in this particular context confers no benefit
495 if (VMThreadHintNoPreempt) {
496 os::hint_no_preempt();
497 }
498 ThreadSafepointState* cur_state = current->safepoint_state();
499 assert(cur_state->type() != ThreadSafepointState::_running, "Thread not suspended at safepoint");
500 cur_state->restart();
501 assert(cur_state->is_running(), "safepoint state has not been reset");
502 }
503
504 RuntimeService::record_safepoint_end();
505
506 // Release threads lock, so threads can be created/destroyed again. It will also starts all threads
507 // blocked in signal_thread_blocked
508 Threads_lock->unlock();
509
510 }
511 #if INCLUDE_ALL_GCS
512 // If there are any concurrent GC threads resume them.
513 if (UseConcMarkSweepGC) {
514 ConcurrentMarkSweepThread::desynchronize(false);
515 } else if (UseG1GC) {
516 SuspendibleThreadSet::desynchronize();
517 }
518 #endif // INCLUDE_ALL_GCS
519 // record this time so VMThread can keep track how much time has elapsed
520 // since last safepoint.
521 _end_of_last_safepoint = os::javaTimeMillis();
522
523 if (event.should_commit()) {
524 event.set_safepointId(safepoint_id);
525 event.commit();
526 }
527 }
528
529 bool SafepointSynchronize::is_cleanup_needed() {
530 // Need a safepoint if some inline cache buffers is non-empty
531 if (!InlineCacheBuffer::is_empty()) return true;
532 return false;
533 }
534
535 static void event_safepoint_cleanup_task_commit(EventSafepointCleanupTask& event, const char* name) {
536 if (event.should_commit()) {
537 event.set_safepointId(SafepointSynchronize::safepoint_counter());
538 event.set_name(name);
|
43 #include "runtime/compilationPolicy.hpp"
44 #include "runtime/deoptimization.hpp"
45 #include "runtime/frame.inline.hpp"
46 #include "runtime/interfaceSupport.hpp"
47 #include "runtime/mutexLocker.hpp"
48 #include "runtime/orderAccess.inline.hpp"
49 #include "runtime/osThread.hpp"
50 #include "runtime/safepoint.hpp"
51 #include "runtime/signature.hpp"
52 #include "runtime/stubCodeGenerator.hpp"
53 #include "runtime/stubRoutines.hpp"
54 #include "runtime/sweeper.hpp"
55 #include "runtime/synchronizer.hpp"
56 #include "runtime/thread.inline.hpp"
57 #include "runtime/timerTrace.hpp"
58 #include "services/runtimeService.hpp"
59 #include "trace/tracing.hpp"
60 #include "trace/traceMacros.hpp"
61 #include "utilities/events.hpp"
62 #include "utilities/macros.hpp"
63 #ifdef COMPILER1
64 #include "c1/c1_globals.hpp"
65 #endif
66
67 // --------------------------------------------------------------------------------------------------
68 // Implementation of Safepoint begin/end
69
70 SafepointSynchronize::SynchronizeState volatile SafepointSynchronize::_state = SafepointSynchronize::_not_synchronized;
71 volatile int SafepointSynchronize::_waiting_to_block = 0;
72 volatile int SafepointSynchronize::_safepoint_counter = 0;
73 int SafepointSynchronize::_current_jni_active_count = 0;
74 long SafepointSynchronize::_end_of_last_safepoint = 0;
75 static volatile int PageArmed = 0 ; // safepoint polling page is RO|RW vs PROT_NONE
76 static volatile int TryingToBlock = 0 ; // proximate value -- for advisory use only
77 static bool timeout_error_printed = false;
78
79 // Roll all threads forward to a safepoint and suspend them all
80 void SafepointSynchronize::begin() {
81 EventSafepointBegin begin_event;
82 Thread* myThread = Thread::current();
83 assert(myThread->is_VM_thread(), "Only VM thread may execute a safepoint");
84
85 if (PrintSafepointStatistics || PrintSafepointStatisticsTimeout > 0) {
86 _safepoint_begin_time = os::javaTimeNanos();
87 _ts_of_current_safepoint = tty->time_stamp().seconds();
88 }
89
90 Universe::heap()->safepoint_synchronize_begin();
91
92 // By getting the Threads_lock, we assure that no threads are about to start or
93 // exit. It is released again in SafepointSynchronize::end().
94 Threads_lock->lock();
95
96 assert( _state == _not_synchronized, "trying to safepoint synchronize with wrong state");
97
98 int nof_threads = Threads::number_of_threads();
99
100 log_debug(safepoint)("Safepoint synchronization initiated. (%d)", nof_threads);
101
102 RuntimeService::record_safepoint_begin();
103
104 MutexLocker mu(Safepoint_lock);
105
106 // Reset the count of active JNI critical threads
107 _current_jni_active_count = 0;
108
109 // Set number of threads to wait for, before we initiate the callbacks
110 _waiting_to_block = nof_threads;
479 // of suspending threads.
480 //
481 // TODO-FIXME: the comments above are vestigial and no longer apply.
482 // Furthermore, using solaris' schedctl in this particular context confers no benefit
483 if (VMThreadHintNoPreempt) {
484 os::hint_no_preempt();
485 }
486 ThreadSafepointState* cur_state = current->safepoint_state();
487 assert(cur_state->type() != ThreadSafepointState::_running, "Thread not suspended at safepoint");
488 cur_state->restart();
489 assert(cur_state->is_running(), "safepoint state has not been reset");
490 }
491
492 RuntimeService::record_safepoint_end();
493
494 // Release threads lock, so threads can be created/destroyed again. It will also starts all threads
495 // blocked in signal_thread_blocked
496 Threads_lock->unlock();
497
498 }
499 Universe::heap()->safepoint_synchronize_end();
500 // record this time so VMThread can keep track how much time has elapsed
501 // since last safepoint.
502 _end_of_last_safepoint = os::javaTimeMillis();
503
504 if (event.should_commit()) {
505 event.set_safepointId(safepoint_id);
506 event.commit();
507 }
508 }
509
510 bool SafepointSynchronize::is_cleanup_needed() {
511 // Need a safepoint if some inline cache buffers is non-empty
512 if (!InlineCacheBuffer::is_empty()) return true;
513 return false;
514 }
515
516 static void event_safepoint_cleanup_task_commit(EventSafepointCleanupTask& event, const char* name) {
517 if (event.should_commit()) {
518 event.set_safepointId(SafepointSynchronize::safepoint_counter());
519 event.set_name(name);
|