@@ -967,6 +967,21 @@ JavaThread* CompileBroker::make_thread(ThreadType type, jobject thread_handle, C
967
967
return new_thread;
968
968
}
969
969
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
+ }
970
985
971
986
void CompileBroker::init_compiler_sweeper_threads () {
972
987
NMethodSweeper::set_sweep_threshold_bytes (static_cast <size_t >(SweeperThreshold * ReservedCodeCacheSize / 100.0 ));
@@ -1009,11 +1024,13 @@ void CompileBroker::init_compiler_sweeper_threads() {
1009
1024
JavaThread *ct = make_thread (compiler_t , thread_handle, _c2_compile_queue, _compilers[1 ], THREAD);
1010
1025
assert (ct != NULL , " should have been handled for initial thread" );
1011
1026
_compilers[1 ]->set_num_compiler_threads (i + 1 );
1012
- if (TraceCompilerThreads ) {
1027
+ if (trace_compiler_threads () ) {
1013
1028
ResourceMark rm;
1014
1029
ThreadsListHandle tlh; // get_thread_name() depends on the TLH.
1015
1030
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);
1017
1034
}
1018
1035
}
1019
1036
}
@@ -1030,11 +1047,13 @@ void CompileBroker::init_compiler_sweeper_threads() {
1030
1047
JavaThread *ct = make_thread (compiler_t , thread_handle, _c1_compile_queue, _compilers[0 ], THREAD);
1031
1048
assert (ct != NULL , " should have been handled for initial thread" );
1032
1049
_compilers[0 ]->set_num_compiler_threads (i + 1 );
1033
- if (TraceCompilerThreads ) {
1050
+ if (trace_compiler_threads () ) {
1034
1051
ResourceMark rm;
1035
1052
ThreadsListHandle tlh; // get_thread_name() depends on the TLH.
1036
1053
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);
1038
1057
}
1039
1058
}
1040
1059
}
@@ -1099,10 +1118,12 @@ void CompileBroker::possibly_add_compiler_threads(JavaThread* THREAD) {
1099
1118
thread_oop = create_thread_oop (name_buffer, THREAD);
1100
1119
}
1101
1120
if (HAS_PENDING_EXCEPTION) {
1102
- if (TraceCompilerThreads ) {
1121
+ if (trace_compiler_threads () ) {
1103
1122
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);
1106
1127
}
1107
1128
CLEAR_PENDING_EXCEPTION;
1108
1129
break ;
@@ -1117,12 +1138,14 @@ void CompileBroker::possibly_add_compiler_threads(JavaThread* THREAD) {
1117
1138
JavaThread *ct = make_thread (compiler_t , compiler2_object (i), _c2_compile_queue, _compilers[1 ], THREAD);
1118
1139
if (ct == NULL ) break ;
1119
1140
_compilers[1 ]->set_num_compiler_threads (i + 1 );
1120
- if (TraceCompilerThreads ) {
1141
+ if (trace_compiler_threads () ) {
1121
1142
ResourceMark rm;
1122
1143
ThreadsListHandle tlh; // get_thread_name() depends on the TLH.
1123
1144
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);
1126
1149
}
1127
1150
}
1128
1151
}
@@ -1138,12 +1161,14 @@ void CompileBroker::possibly_add_compiler_threads(JavaThread* THREAD) {
1138
1161
JavaThread *ct = make_thread (compiler_t , compiler1_object (i), _c1_compile_queue, _compilers[0 ], THREAD);
1139
1162
if (ct == NULL ) break ;
1140
1163
_compilers[0 ]->set_num_compiler_threads (i + 1 );
1141
- if (TraceCompilerThreads ) {
1164
+ if (trace_compiler_threads () ) {
1142
1165
ResourceMark rm;
1143
1166
ThreadsListHandle tlh; // get_thread_name() depends on the TLH.
1144
1167
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);
1147
1172
}
1148
1173
}
1149
1174
}
@@ -1959,9 +1984,12 @@ void CompileBroker::compiler_thread_loop() {
1959
1984
// Access compiler_count under lock to enforce consistency.
1960
1985
MutexLocker only_one (CompileThread_lock);
1961
1986
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);
1965
1993
}
1966
1994
// Free buffer blob, if allocated
1967
1995
if (thread->get_buffer_blob () != NULL ) {
0 commit comments