@@ -161,11 +161,6 @@ bool SafepointSynchronize::thread_not_running(ThreadSafepointState *cur_state) {
161161 if (!cur_state->is_running ()) {
162162 return true ;
163163 }
164- LogTarget (Trace, safepoint) lt;
165- if (lt.is_enabled ()) {
166- LogStream ls (lt);
167- cur_state->print_on (&ls);
168- }
169164 return false ;
170165}
171166
@@ -223,6 +218,8 @@ int SafepointSynchronize::synchronize_threads(jlong safepoint_limit_time, int no
223218
224219 *initial_running = still_running;
225220
221+ log_trace (safepoint)(" %d total threads, waiting for %d threads to block" , nof_threads, still_running);
222+
226223 // If there is no thread still running, we are already done.
227224 if (still_running <= 0 ) {
228225 assert (tss_head == nullptr , " Must be empty" );
@@ -233,6 +230,8 @@ int SafepointSynchronize::synchronize_threads(jlong safepoint_limit_time, int no
233230 int64_t start_time = os::javaTimeNanos ();
234231
235232 do {
233+ log_trace (safepoint)(" Checking thread status" );
234+
236235 // Check if this has taken too long:
237236 if (SafepointTimeout && safepoint_limit_time < os::javaTimeNanos ()) {
238237 print_safepoint_timeout ();
@@ -243,12 +242,16 @@ int SafepointSynchronize::synchronize_threads(jlong safepoint_limit_time, int no
243242 while (cur_tss != nullptr ) {
244243 assert (cur_tss->is_running (), " Illegal initial state" );
245244 if (thread_not_running (cur_tss)) {
245+ log_trace (safepoint)(" Thread " INTPTR_FORMAT " [%d] is now blocked" ,
246+ p2i (cur_tss->thread ()), cur_tss->thread ()->osthread ()->thread_id ());
246247 --still_running;
247248 *p_prev = nullptr ;
248249 ThreadSafepointState *tmp = cur_tss;
249250 cur_tss = cur_tss->get_next ();
250251 tmp->set_next (nullptr );
251252 } else {
253+ log_trace (safepoint)(" Thread " INTPTR_FORMAT " [%d] is still running" ,
254+ p2i (cur_tss->thread ()), cur_tss->thread ()->osthread ()->thread_id ());
252255 *p_prev = cur_tss;
253256 p_prev = cur_tss->next_ptr ();
254257 cur_tss = cur_tss->get_next ();
@@ -258,6 +261,7 @@ int SafepointSynchronize::synchronize_threads(jlong safepoint_limit_time, int no
258261 DEBUG_ONLY (assert_list_is_valid (tss_head, still_running);)
259262
260263 if (still_running > 0 ) {
264+ log_trace (safepoint)(" Waiting for %d threads to block" , still_running);
261265 back_off (start_time);
262266 }
263267
@@ -332,10 +336,12 @@ void SafepointSynchronize::begin() {
332336 EventSafepointBegin begin_event;
333337 SafepointTracing::begin (VMThread::vm_op_type ());
334338
339+ log_trace (safepoint)(" Suspending GC threads" );
335340 Universe::heap ()->safepoint_synchronize_begin ();
336341
337342 // By getting the Threads_lock, we assure that no threads are about to start or
338343 // exit. It is released again in SafepointSynchronize::end().
344+ log_trace (safepoint)(" Blocking threads from starting/exiting" );
339345 Threads_lock->lock ();
340346
341347 assert ( _state == _not_synchronized, " trying to safepoint synchronize with wrong state" );
@@ -344,8 +350,6 @@ void SafepointSynchronize::begin() {
344350
345351 _nof_threads_hit_polling_page = 0 ;
346352
347- log_debug (safepoint)(" Safepoint synchronization initiated using %s wait barrier. (%d threads)" , _wait_barrier->description (), nof_threads);
348-
349353 // Reset the count of active JNI critical threads
350354 _current_jni_active_count = 0 ;
351355
@@ -364,6 +368,7 @@ void SafepointSynchronize::begin() {
364368 int initial_running = 0 ;
365369
366370 // Arms the safepoint, _current_jni_active_count and _waiting_to_block must be set before.
371+ log_trace (safepoint)(" Arming safepoint using %s wait barrier" , _wait_barrier->description ());
367372 arm_safepoint ();
368373
369374 // Will spin until all threads are safe.
@@ -471,8 +476,10 @@ void SafepointSynchronize::end() {
471476 EventSafepointEnd event;
472477 assert (Thread::current ()->is_VM_thread (), " Only VM thread can execute a safepoint" );
473478
479+ log_trace (safepoint)(" Disarming safepoint" );
474480 disarm_safepoint ();
475481
482+ log_trace (safepoint)(" Resuming GC threads" );
476483 Universe::heap ()->safepoint_synchronize_end ();
477484
478485 SafepointTracing::end ();
@@ -551,6 +558,9 @@ void SafepointSynchronize::block(JavaThread *thread) {
551558 // Threads shouldn't block if they are in the middle of printing, but...
552559 ttyLocker::break_tty_lock_for_safepoint (os::current_thread_id ());
553560
561+ log_trace (safepoint)(" Blocking thread " INTPTR_FORMAT " [%d]" ,
562+ p2i (thread), thread->osthread ()->thread_id ());
563+
554564 // Only bail from the block() call if the thread is gone from the
555565 // thread list; starting to exit should still block.
556566 if (thread->is_terminated ()) {
@@ -594,6 +604,9 @@ void SafepointSynchronize::block(JavaThread *thread) {
594604
595605 // cross_modify_fence is done by SafepointMechanism::process_if_requested
596606 // which is the only caller here.
607+
608+ log_trace (safepoint)(" Unblocking thread " INTPTR_FORMAT " [%d]" ,
609+ p2i (thread), thread->osthread ()->thread_id ());
597610}
598611
599612// ------------------------------------------------------------------------------------------------------
@@ -955,6 +968,7 @@ void SafepointTracing::begin(VM_Operation::VMOp_Type type) {
955968 _last_safepoint_end_time_ns = 0 ;
956969
957970 RuntimeService::record_safepoint_begin (_last_app_time_ns);
971+ log_debug (safepoint)(" Safepoint synchronization initiated" );
958972}
959973
960974void SafepointTracing::synchronized (int nof_threads, int nof_running, int traps) {
@@ -963,10 +977,12 @@ void SafepointTracing::synchronized(int nof_threads, int nof_running, int traps)
963977 _nof_running = nof_running;
964978 _page_trap = traps;
965979 RuntimeService::record_safepoint_synchronized (_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns);
980+ log_debug (safepoint)(" Safepoint synchronization complete" );
966981}
967982
968983void SafepointTracing::leave () {
969984 _last_safepoint_leave_time_ns = os::javaTimeNanos ();
985+ log_debug (safepoint)(" Leaving safepoint" );
970986}
971987
972988void SafepointTracing::end () {
@@ -1001,4 +1017,5 @@ void SafepointTracing::end() {
10011017 );
10021018
10031019 RuntimeService::record_safepoint_end (_last_safepoint_end_time_ns - _last_safepoint_sync_time_ns);
1020+ log_debug (safepoint)(" Safepoint complete" );
10041021}
0 commit comments