@@ -161,11 +161,6 @@ bool SafepointSynchronize::thread_not_running(ThreadSafepointState *cur_state) {
161
161
if (!cur_state->is_running ()) {
162
162
return true ;
163
163
}
164
- LogTarget (Trace, safepoint) lt;
165
- if (lt.is_enabled ()) {
166
- LogStream ls (lt);
167
- cur_state->print_on (&ls);
168
- }
169
164
return false ;
170
165
}
171
166
@@ -223,6 +218,8 @@ int SafepointSynchronize::synchronize_threads(jlong safepoint_limit_time, int no
223
218
224
219
*initial_running = still_running;
225
220
221
+ log_trace (safepoint)(" %d total threads, waiting for %d threads to block" , nof_threads, still_running);
222
+
226
223
// If there is no thread still running, we are already done.
227
224
if (still_running <= 0 ) {
228
225
assert (tss_head == nullptr , " Must be empty" );
@@ -233,6 +230,8 @@ int SafepointSynchronize::synchronize_threads(jlong safepoint_limit_time, int no
233
230
int64_t start_time = os::javaTimeNanos ();
234
231
235
232
do {
233
+ log_trace (safepoint)(" Checking thread status" );
234
+
236
235
// Check if this has taken too long:
237
236
if (SafepointTimeout && safepoint_limit_time < os::javaTimeNanos ()) {
238
237
print_safepoint_timeout ();
@@ -243,12 +242,16 @@ int SafepointSynchronize::synchronize_threads(jlong safepoint_limit_time, int no
243
242
while (cur_tss != nullptr ) {
244
243
assert (cur_tss->is_running (), " Illegal initial state" );
245
244
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 ());
246
247
--still_running;
247
248
*p_prev = nullptr ;
248
249
ThreadSafepointState *tmp = cur_tss;
249
250
cur_tss = cur_tss->get_next ();
250
251
tmp->set_next (nullptr );
251
252
} else {
253
+ log_trace (safepoint)(" Thread " INTPTR_FORMAT " [%d] is still running" ,
254
+ p2i (cur_tss->thread ()), cur_tss->thread ()->osthread ()->thread_id ());
252
255
*p_prev = cur_tss;
253
256
p_prev = cur_tss->next_ptr ();
254
257
cur_tss = cur_tss->get_next ();
@@ -258,6 +261,7 @@ int SafepointSynchronize::synchronize_threads(jlong safepoint_limit_time, int no
258
261
DEBUG_ONLY (assert_list_is_valid (tss_head, still_running);)
259
262
260
263
if (still_running > 0 ) {
264
+ log_trace (safepoint)(" Waiting for %d threads to block" , still_running);
261
265
back_off (start_time);
262
266
}
263
267
@@ -332,10 +336,12 @@ void SafepointSynchronize::begin() {
332
336
EventSafepointBegin begin_event;
333
337
SafepointTracing::begin (VMThread::vm_op_type ());
334
338
339
+ log_trace (safepoint)(" Suspending GC threads" );
335
340
Universe::heap ()->safepoint_synchronize_begin ();
336
341
337
342
// By getting the Threads_lock, we assure that no threads are about to start or
338
343
// exit. It is released again in SafepointSynchronize::end().
344
+ log_trace (safepoint)(" Blocking threads from starting/exiting" );
339
345
Threads_lock->lock ();
340
346
341
347
assert ( _state == _not_synchronized, " trying to safepoint synchronize with wrong state" );
@@ -344,8 +350,6 @@ void SafepointSynchronize::begin() {
344
350
345
351
_nof_threads_hit_polling_page = 0 ;
346
352
347
- log_debug (safepoint)(" Safepoint synchronization initiated using %s wait barrier. (%d threads)" , _wait_barrier->description (), nof_threads);
348
-
349
353
// Reset the count of active JNI critical threads
350
354
_current_jni_active_count = 0 ;
351
355
@@ -364,6 +368,7 @@ void SafepointSynchronize::begin() {
364
368
int initial_running = 0 ;
365
369
366
370
// 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 ());
367
372
arm_safepoint ();
368
373
369
374
// Will spin until all threads are safe.
@@ -471,8 +476,10 @@ void SafepointSynchronize::end() {
471
476
EventSafepointEnd event;
472
477
assert (Thread::current ()->is_VM_thread (), " Only VM thread can execute a safepoint" );
473
478
479
+ log_trace (safepoint)(" Disarming safepoint" );
474
480
disarm_safepoint ();
475
481
482
+ log_trace (safepoint)(" Resuming GC threads" );
476
483
Universe::heap ()->safepoint_synchronize_end ();
477
484
478
485
SafepointTracing::end ();
@@ -551,6 +558,9 @@ void SafepointSynchronize::block(JavaThread *thread) {
551
558
// Threads shouldn't block if they are in the middle of printing, but...
552
559
ttyLocker::break_tty_lock_for_safepoint (os::current_thread_id ());
553
560
561
+ log_trace (safepoint)(" Blocking thread " INTPTR_FORMAT " [%d]" ,
562
+ p2i (thread), thread->osthread ()->thread_id ());
563
+
554
564
// Only bail from the block() call if the thread is gone from the
555
565
// thread list; starting to exit should still block.
556
566
if (thread->is_terminated ()) {
@@ -594,6 +604,9 @@ void SafepointSynchronize::block(JavaThread *thread) {
594
604
595
605
// cross_modify_fence is done by SafepointMechanism::process_if_requested
596
606
// which is the only caller here.
607
+
608
+ log_trace (safepoint)(" Unblocking thread " INTPTR_FORMAT " [%d]" ,
609
+ p2i (thread), thread->osthread ()->thread_id ());
597
610
}
598
611
599
612
// ------------------------------------------------------------------------------------------------------
@@ -955,6 +968,7 @@ void SafepointTracing::begin(VM_Operation::VMOp_Type type) {
955
968
_last_safepoint_end_time_ns = 0 ;
956
969
957
970
RuntimeService::record_safepoint_begin (_last_app_time_ns);
971
+ log_debug (safepoint)(" Safepoint synchronization initiated" );
958
972
}
959
973
960
974
void 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)
963
977
_nof_running = nof_running;
964
978
_page_trap = traps;
965
979
RuntimeService::record_safepoint_synchronized (_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns);
980
+ log_debug (safepoint)(" Safepoint synchronization complete" );
966
981
}
967
982
968
983
void SafepointTracing::leave () {
969
984
_last_safepoint_leave_time_ns = os::javaTimeNanos ();
985
+ log_debug (safepoint)(" Leaving safepoint" );
970
986
}
971
987
972
988
void SafepointTracing::end () {
@@ -1001,4 +1017,5 @@ void SafepointTracing::end() {
1001
1017
);
1002
1018
1003
1019
RuntimeService::record_safepoint_end (_last_safepoint_end_time_ns - _last_safepoint_sync_time_ns);
1020
+ log_debug (safepoint)(" Safepoint complete" );
1004
1021
}
0 commit comments