Skip to content

Commit

Permalink
8302508: Add timestamp to the output TraceCompilerThreads
Browse files Browse the repository at this point in the history
Reviewed-by: thartmann
  • Loading branch information
Vladimir Kozlov committed Mar 8, 2023
1 parent 404d5bd commit f813dc7
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions src/hotspot/share/compiler/compileBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,21 @@ JavaThread* CompileBroker::make_thread(ThreadType type, jobject thread_handle, C
return new_thread;
}

static bool trace_compiler_threads() {
LogTarget(Debug, jit, thread) lt;
return TraceCompilerThreads || lt.is_enabled();
}

static void print_compiler_threads(stringStream& msg) {
if (TraceCompilerThreads) {
tty->print_cr("%7d %s", (int)tty->time_stamp().milliseconds(), msg.as_string());
}
LogTarget(Debug, jit, thread) lt;
if (lt.is_enabled()) {
LogStream ls(lt);
ls.print_cr("%s", msg.as_string());
}
}

void CompileBroker::init_compiler_threads() {
// Ensure any exceptions lead to vm_exit_during_initialization.
Expand Down Expand Up @@ -943,11 +958,13 @@ void CompileBroker::init_compiler_threads() {
JavaThread *ct = make_thread(compiler_t, thread_handle, _c2_compile_queue, _compilers[1], THREAD);
assert(ct != nullptr, "should have been handled for initial thread");
_compilers[1]->set_num_compiler_threads(i + 1);
if (TraceCompilerThreads) {
if (trace_compiler_threads()) {
ResourceMark rm;
ThreadsListHandle tlh; // name() depends on the TLH.
assert(tlh.includes(ct), "ct=" INTPTR_FORMAT " exited unexpectedly.", p2i(ct));
tty->print_cr("Added initial compiler thread %s", ct->name());
stringStream msg;
msg.print("Added initial compiler thread %s", ct->name());
print_compiler_threads(msg);
}
}
}
Expand All @@ -964,11 +981,13 @@ void CompileBroker::init_compiler_threads() {
JavaThread *ct = make_thread(compiler_t, thread_handle, _c1_compile_queue, _compilers[0], THREAD);
assert(ct != nullptr, "should have been handled for initial thread");
_compilers[0]->set_num_compiler_threads(i + 1);
if (TraceCompilerThreads) {
if (trace_compiler_threads()) {
ResourceMark rm;
ThreadsListHandle tlh; // name() depends on the TLH.
assert(tlh.includes(ct), "ct=" INTPTR_FORMAT " exited unexpectedly.", p2i(ct));
tty->print_cr("Added initial compiler thread %s", ct->name());
stringStream msg;
msg.print("Added initial compiler thread %s", ct->name());
print_compiler_threads(msg);
}
}
}
Expand Down Expand Up @@ -1026,10 +1045,12 @@ void CompileBroker::possibly_add_compiler_threads(JavaThread* THREAD) {
thread_oop = create_thread_oop(name_buffer, THREAD);
}
if (HAS_PENDING_EXCEPTION) {
if (TraceCompilerThreads) {
if (trace_compiler_threads()) {
ResourceMark rm;
tty->print_cr("JVMCI compiler thread creation failed:");
PENDING_EXCEPTION->print();
stringStream msg;
msg.print_cr("JVMCI compiler thread creation failed:");
PENDING_EXCEPTION->print_on(&msg);
print_compiler_threads(msg);
}
CLEAR_PENDING_EXCEPTION;
break;
Expand All @@ -1044,12 +1065,14 @@ void CompileBroker::possibly_add_compiler_threads(JavaThread* THREAD) {
JavaThread *ct = make_thread(compiler_t, compiler2_object(i), _c2_compile_queue, _compilers[1], THREAD);
if (ct == nullptr) break;
_compilers[1]->set_num_compiler_threads(i + 1);
if (TraceCompilerThreads) {
if (trace_compiler_threads()) {
ResourceMark rm;
ThreadsListHandle tlh; // name() depends on the TLH.
assert(tlh.includes(ct), "ct=" INTPTR_FORMAT " exited unexpectedly.", p2i(ct));
tty->print_cr("Added compiler thread %s (available memory: %dMB, available non-profiled code cache: %dMB)",
ct->name(), (int)(available_memory/M), (int)(available_cc_np/M));
stringStream msg;
msg.print("Added compiler thread %s (available memory: %dMB, available non-profiled code cache: %dMB)",
ct->name(), (int)(available_memory/M), (int)(available_cc_np/M));
print_compiler_threads(msg);
}
}
}
Expand All @@ -1065,12 +1088,14 @@ void CompileBroker::possibly_add_compiler_threads(JavaThread* THREAD) {
JavaThread *ct = make_thread(compiler_t, compiler1_object(i), _c1_compile_queue, _compilers[0], THREAD);
if (ct == nullptr) break;
_compilers[0]->set_num_compiler_threads(i + 1);
if (TraceCompilerThreads) {
if (trace_compiler_threads()) {
ResourceMark rm;
ThreadsListHandle tlh; // name() depends on the TLH.
assert(tlh.includes(ct), "ct=" INTPTR_FORMAT " exited unexpectedly.", p2i(ct));
tty->print_cr("Added compiler thread %s (available memory: %dMB, available profiled code cache: %dMB)",
ct->name(), (int)(available_memory/M), (int)(available_cc_p/M));
stringStream msg;
msg.print("Added compiler thread %s (available memory: %dMB, available profiled code cache: %dMB)",
ct->name(), (int)(available_memory/M), (int)(available_cc_p/M));
print_compiler_threads(msg);
}
}
}
Expand Down Expand Up @@ -1885,9 +1910,12 @@ void CompileBroker::compiler_thread_loop() {
// Access compiler_count under lock to enforce consistency.
MutexLocker only_one(CompileThread_lock);
if (can_remove(thread, true)) {
if (TraceCompilerThreads) {
tty->print_cr("Removing compiler thread %s after " JLONG_FORMAT " ms idle time",
thread->name(), thread->idle_time_millis());
if (trace_compiler_threads()) {
ResourceMark rm;
stringStream msg;
msg.print("Removing compiler thread %s after " JLONG_FORMAT " ms idle time",
thread->name(), thread->idle_time_millis());
print_compiler_threads(msg);
}

// Notify compiler that the compiler thread is about to stop
Expand Down

1 comment on commit f813dc7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.