Skip to content

Commit 1992b69

Browse files
committed
8369283: Improve trace logs in safepoint machinery
Reviewed-by: fbredberg, dholmes, rehn
1 parent 501fa20 commit 1992b69

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/hotspot/share/runtime/safepoint.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

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

968983
void SafepointTracing::leave() {
969984
_last_safepoint_leave_time_ns = os::javaTimeNanos();
985+
log_debug(safepoint)("Leaving safepoint");
970986
}
971987

972988
void 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
}

src/hotspot/share/runtime/sharedRuntime.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include "runtime/java.hpp"
6868
#include "runtime/javaCalls.hpp"
6969
#include "runtime/jniHandles.inline.hpp"
70+
#include "runtime/osThread.hpp"
7071
#include "runtime/perfData.hpp"
7172
#include "runtime/sharedRuntime.hpp"
7273
#include "runtime/stackWatermarkSet.hpp"
@@ -677,10 +678,13 @@ address SharedRuntime::get_poll_stub(address pc) {
677678
"polling page safepoint stub not created yet");
678679
stub = SharedRuntime::polling_page_safepoint_handler_blob()->entry_point();
679680
}
680-
log_debug(safepoint)("... found polling page %s exception at pc = "
681-
INTPTR_FORMAT ", stub =" INTPTR_FORMAT,
681+
log_trace(safepoint)("Polling page exception: thread = " INTPTR_FORMAT " [%d], pc = "
682+
INTPTR_FORMAT " (%s), stub = " INTPTR_FORMAT,
683+
p2i(Thread::current()),
684+
Thread::current()->osthread()->thread_id(),
685+
p2i(pc),
682686
at_poll_return ? "return" : "loop",
683-
(intptr_t)pc, (intptr_t)stub);
687+
p2i(stub));
684688
return stub;
685689
}
686690

0 commit comments

Comments
 (0)