Skip to content

Commit 86aca8b

Browse files
committedMay 8, 2023
8302508: Add timestamp to the output TraceCompilerThreads
Reviewed-by: shade Backport-of: f813dc71836e002814622fead8a2b0464b49c83a
1 parent b5e6753 commit 86aca8b

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed
 

‎src/hotspot/share/compiler/compileBroker.cpp

+44-16
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,21 @@ JavaThread* CompileBroker::make_thread(ThreadType type, jobject thread_handle, C
967967
return new_thread;
968968
}
969969

970+
static bool trace_compiler_threads() {
971+
LogTarget(Debug, jit, thread) lt;
972+
return TraceCompilerThreads || lt.is_enabled();
973+
}
974+
975+
static void print_compiler_threads(stringStream& msg) {
976+
if (TraceCompilerThreads) {
977+
tty->print_cr("%7d %s", (int)tty->time_stamp().milliseconds(), msg.as_string());
978+
}
979+
LogTarget(Debug, jit, thread) lt;
980+
if (lt.is_enabled()) {
981+
LogStream ls(lt);
982+
ls.print_cr("%s", msg.as_string());
983+
}
984+
}
970985

971986
void CompileBroker::init_compiler_sweeper_threads() {
972987
NMethodSweeper::set_sweep_threshold_bytes(static_cast<size_t>(SweeperThreshold * ReservedCodeCacheSize / 100.0));
@@ -1009,11 +1024,13 @@ void CompileBroker::init_compiler_sweeper_threads() {
10091024
JavaThread *ct = make_thread(compiler_t, thread_handle, _c2_compile_queue, _compilers[1], THREAD);
10101025
assert(ct != NULL, "should have been handled for initial thread");
10111026
_compilers[1]->set_num_compiler_threads(i + 1);
1012-
if (TraceCompilerThreads) {
1027+
if (trace_compiler_threads()) {
10131028
ResourceMark rm;
10141029
ThreadsListHandle tlh; // get_thread_name() depends on the TLH.
10151030
assert(tlh.includes(ct), "ct=" INTPTR_FORMAT " exited unexpectedly.", p2i(ct));
1016-
tty->print_cr("Added initial compiler thread %s", ct->get_thread_name());
1031+
stringStream msg;
1032+
msg.print("Added initial compiler thread %s", ct->get_thread_name());
1033+
print_compiler_threads(msg);
10171034
}
10181035
}
10191036
}
@@ -1030,11 +1047,13 @@ void CompileBroker::init_compiler_sweeper_threads() {
10301047
JavaThread *ct = make_thread(compiler_t, thread_handle, _c1_compile_queue, _compilers[0], THREAD);
10311048
assert(ct != NULL, "should have been handled for initial thread");
10321049
_compilers[0]->set_num_compiler_threads(i + 1);
1033-
if (TraceCompilerThreads) {
1050+
if (trace_compiler_threads()) {
10341051
ResourceMark rm;
10351052
ThreadsListHandle tlh; // get_thread_name() depends on the TLH.
10361053
assert(tlh.includes(ct), "ct=" INTPTR_FORMAT " exited unexpectedly.", p2i(ct));
1037-
tty->print_cr("Added initial compiler thread %s", ct->get_thread_name());
1054+
stringStream msg;
1055+
msg.print("Added initial compiler thread %s", ct->get_thread_name());
1056+
print_compiler_threads(msg);
10381057
}
10391058
}
10401059
}
@@ -1099,10 +1118,12 @@ void CompileBroker::possibly_add_compiler_threads(JavaThread* THREAD) {
10991118
thread_oop = create_thread_oop(name_buffer, THREAD);
11001119
}
11011120
if (HAS_PENDING_EXCEPTION) {
1102-
if (TraceCompilerThreads) {
1121+
if (trace_compiler_threads()) {
11031122
ResourceMark rm;
1104-
tty->print_cr("JVMCI compiler thread creation failed:");
1105-
PENDING_EXCEPTION->print();
1123+
stringStream msg;
1124+
msg.print_cr("JVMCI compiler thread creation failed:");
1125+
PENDING_EXCEPTION->print_on(&msg);
1126+
print_compiler_threads(msg);
11061127
}
11071128
CLEAR_PENDING_EXCEPTION;
11081129
break;
@@ -1117,12 +1138,14 @@ void CompileBroker::possibly_add_compiler_threads(JavaThread* THREAD) {
11171138
JavaThread *ct = make_thread(compiler_t, compiler2_object(i), _c2_compile_queue, _compilers[1], THREAD);
11181139
if (ct == NULL) break;
11191140
_compilers[1]->set_num_compiler_threads(i + 1);
1120-
if (TraceCompilerThreads) {
1141+
if (trace_compiler_threads()) {
11211142
ResourceMark rm;
11221143
ThreadsListHandle tlh; // get_thread_name() depends on the TLH.
11231144
assert(tlh.includes(ct), "ct=" INTPTR_FORMAT " exited unexpectedly.", p2i(ct));
1124-
tty->print_cr("Added compiler thread %s (available memory: %dMB, available non-profiled code cache: %dMB)",
1125-
ct->get_thread_name(), (int)(available_memory/M), (int)(available_cc_np/M));
1145+
stringStream msg;
1146+
msg.print("Added compiler thread %s (available memory: %dMB, available non-profiled code cache: %dMB)",
1147+
ct->get_thread_name(), (int)(available_memory/M), (int)(available_cc_np/M));
1148+
print_compiler_threads(msg);
11261149
}
11271150
}
11281151
}
@@ -1138,12 +1161,14 @@ void CompileBroker::possibly_add_compiler_threads(JavaThread* THREAD) {
11381161
JavaThread *ct = make_thread(compiler_t, compiler1_object(i), _c1_compile_queue, _compilers[0], THREAD);
11391162
if (ct == NULL) break;
11401163
_compilers[0]->set_num_compiler_threads(i + 1);
1141-
if (TraceCompilerThreads) {
1164+
if (trace_compiler_threads()) {
11421165
ResourceMark rm;
11431166
ThreadsListHandle tlh; // get_thread_name() depends on the TLH.
11441167
assert(tlh.includes(ct), "ct=" INTPTR_FORMAT " exited unexpectedly.", p2i(ct));
1145-
tty->print_cr("Added compiler thread %s (available memory: %dMB, available profiled code cache: %dMB)",
1146-
ct->get_thread_name(), (int)(available_memory/M), (int)(available_cc_p/M));
1168+
stringStream msg;
1169+
msg.print("Added compiler thread %s (available memory: %dMB, available profiled code cache: %dMB)",
1170+
ct->get_thread_name(), (int)(available_memory/M), (int)(available_cc_p/M));
1171+
print_compiler_threads(msg);
11471172
}
11481173
}
11491174
}
@@ -1959,9 +1984,12 @@ void CompileBroker::compiler_thread_loop() {
19591984
// Access compiler_count under lock to enforce consistency.
19601985
MutexLocker only_one(CompileThread_lock);
19611986
if (can_remove(thread, true)) {
1962-
if (TraceCompilerThreads) {
1963-
tty->print_cr("Removing compiler thread %s after " JLONG_FORMAT " ms idle time",
1964-
thread->name(), thread->idle_time_millis());
1987+
if (trace_compiler_threads()) {
1988+
ResourceMark rm;
1989+
stringStream msg;
1990+
msg.print("Removing compiler thread %s after " JLONG_FORMAT " ms idle time",
1991+
thread->name(), thread->idle_time_millis());
1992+
print_compiler_threads(msg);
19651993
}
19661994
// Free buffer blob, if allocated
19671995
if (thread->get_buffer_blob() != NULL) {

0 commit comments

Comments
 (0)
Please sign in to comment.