152 elapsedTimer CompileBroker::_t_standard_compilation;
153 elapsedTimer CompileBroker::_t_invalidated_compilation;
154 elapsedTimer CompileBroker::_t_bailedout_compilation;
155
156 int CompileBroker::_total_bailout_count = 0;
157 int CompileBroker::_total_invalidated_count = 0;
158 int CompileBroker::_total_compile_count = 0;
159 int CompileBroker::_total_osr_compile_count = 0;
160 int CompileBroker::_total_standard_compile_count = 0;
161
162 int CompileBroker::_sum_osr_bytes_compiled = 0;
163 int CompileBroker::_sum_standard_bytes_compiled = 0;
164 int CompileBroker::_sum_nmethod_size = 0;
165 int CompileBroker::_sum_nmethod_code_size = 0;
166
167 long CompileBroker::_peak_compilation_time = 0;
168
169 CompileQueue* CompileBroker::_c2_compile_queue = NULL;
170 CompileQueue* CompileBroker::_c1_compile_queue = NULL;
171
172 class CompilationLog : public StringEventLog {
173 public:
174 CompilationLog() : StringEventLog("Compilation events") {
175 }
176
177 void log_compile(JavaThread* thread, CompileTask* task) {
178 StringLogMessage lm;
179 stringStream sstr = lm.stream();
180 // msg.time_stamp().update_to(tty->time_stamp().ticks());
181 task->print(&sstr, NULL, true, false);
182 log(thread, "%s", (const char*)lm);
183 }
184
185 void log_nmethod(JavaThread* thread, nmethod* nm) {
186 log(thread, "nmethod %d%s " INTPTR_FORMAT " code [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",
187 nm->compile_id(), nm->is_osr_method() ? "%" : "",
188 p2i(nm), p2i(nm->code_begin()), p2i(nm->code_end()));
189 }
190
191 void log_failure(JavaThread* thread, CompileTask* task, const char* reason, const char* retry_message) {
827 assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
828 // Since we are at a safepoint, we do not need a lock to access
829 // the compile queues.
830 if (_c2_compile_queue != NULL) {
831 _c2_compile_queue->mark_on_stack();
832 }
833 if (_c1_compile_queue != NULL) {
834 _c1_compile_queue->mark_on_stack();
835 }
836 }
837
838 // ------------------------------------------------------------------
839 // CompileBroker::compile_method
840 //
841 // Request compilation of a method.
842 void CompileBroker::compile_method_base(const methodHandle& method,
843 int osr_bci,
844 int comp_level,
845 const methodHandle& hot_method,
846 int hot_count,
847 const char* comment,
848 bool blocking,
849 Thread* thread) {
850 guarantee(!method->is_abstract(), "cannot compile abstract methods");
851 assert(method->method_holder()->is_instance_klass(),
852 "sanity check");
853 assert(!method->method_holder()->is_not_initialized(),
854 "method holder must be initialized");
855 assert(!method->is_method_handle_intrinsic(), "do not enqueue these guys");
856
857 if (CIPrintRequests) {
858 tty->print("request: ");
859 method->print_short_name(tty);
860 if (osr_bci != InvocationEntryBci) {
861 tty->print(" osr_bci: %d", osr_bci);
862 }
863 tty->print(" level: %d comment: %s count: %d", comp_level, comment, hot_count);
864 if (!hot_method.is_null()) {
865 tty->print(" hot: ");
866 if (hot_method() != method()) {
867 hot_method->print_short_name(tty);
868 } else {
869 tty->print("yes");
870 }
871 }
872 tty->cr();
873 }
874
875 // A request has been made for compilation. Before we do any
876 // real work, check to see if the method has been compiled
877 // in the meantime with a definitive result.
878 if (compilation_is_complete(method, osr_bci, comp_level)) {
879 return;
880 }
881
882 #ifndef PRODUCT
883 if (osr_bci != -1 && !FLAG_IS_DEFAULT(OSROnlyBCI)) {
1007 // <RESULT, QUEUE> :
1008 // <0, 1> : in compile queue, but not yet compiled
1009 // <1, 1> : compiled but queue bit not cleared
1010 // <1, 0> : compiled and queue bit cleared
1011 // Because we first check the queue bits then check the result bits,
1012 // we are assured that we cannot introduce a duplicate task.
1013 // Note that if we did the tests in the reverse order (i.e. check
1014 // result then check queued bit), we could get the result bit before
1015 // the compilation completed, and the queue bit after the compilation
1016 // completed, and end up introducing a "duplicate" (redundant) task.
1017 // In that case, the compiler thread should first check if a method
1018 // has already been compiled before trying to compile it.
1019 // NOTE: in the event that there are multiple compiler threads and
1020 // there is de-optimization/recompilation, things will get hairy,
1021 // and in that case it's best to protect both the testing (here) of
1022 // these bits, and their updating (here and elsewhere) under a
1023 // common lock.
1024 task = create_compile_task(queue,
1025 compile_id, method,
1026 osr_bci, comp_level,
1027 hot_method, hot_count, comment,
1028 blocking);
1029 }
1030
1031 if (blocking) {
1032 wait_for_completion(task);
1033 }
1034 }
1035
1036 nmethod* CompileBroker::compile_method(const methodHandle& method, int osr_bci,
1037 int comp_level,
1038 const methodHandle& hot_method, int hot_count,
1039 const char* comment, Thread* THREAD) {
1040 // do nothing if compilebroker is not available
1041 if (!_initialized) {
1042 return NULL;
1043 }
1044 AbstractCompiler *comp = CompileBroker::compiler(comp_level);
1045 assert(comp != NULL, "Ensure we don't compile before compilebroker init");
1046 DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, comp);
1047 nmethod* nm = CompileBroker::compile_method(method, osr_bci, comp_level, hot_method, hot_count, comment, directive, THREAD);
1048 DirectivesStack::release(directive);
1049 return nm;
1050 }
1051
1052 nmethod* CompileBroker::compile_method(const methodHandle& method, int osr_bci,
1053 int comp_level,
1054 const methodHandle& hot_method, int hot_count,
1055 const char* comment, DirectiveSet* directive,
1056 Thread* THREAD) {
1057
1058 // make sure arguments make sense
1059 assert(method->method_holder()->is_instance_klass(), "not an instance method");
1060 assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
1061 assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods");
1062 assert(!method->method_holder()->is_not_initialized(), "method holder must be initialized");
1063 // allow any levels for WhiteBox
1064 assert(WhiteBoxAPI || TieredCompilation || comp_level == CompLevel_highest_tier, "only CompLevel_highest_tier must be used in non-tiered");
1065 // return quickly if possible
1066
1067 // lock, make sure that the compilation
1068 // isn't prohibited in a straightforward way.
1069 AbstractCompiler *comp = CompileBroker::compiler(comp_level);
1070 if (!comp->can_compile_method(method) ||
1071 compilation_is_prohibited(method, osr_bci, comp_level, directive->ExcludeOption)) {
1072 return NULL;
1073 }
1074
1075 if (osr_bci == InvocationEntryBci) {
1160 return NULL;
1161 }
1162
1163 // To properly handle the appendix argument for out-of-line calls we are using a small trampoline that
1164 // pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime).
1165 //
1166 // Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter
1167 // in this case. If we can't generate one and use it we can not execute the out-of-line method handle calls.
1168 AdapterHandlerLibrary::create_native_wrapper(method);
1169 } else {
1170 return NULL;
1171 }
1172 } else {
1173 // If the compiler is shut off due to code cache getting full
1174 // fail out now so blocking compiles dont hang the java thread
1175 if (!should_compile_new_jobs()) {
1176 CompilationPolicy::policy()->delay_compilation(method());
1177 return NULL;
1178 }
1179 bool is_blocking = !directive->BackgroundCompilationOption || CompileTheWorld || ReplayCompiles;
1180 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, is_blocking, THREAD);
1181 }
1182
1183 // return requested nmethod
1184 // We accept a higher level osr method
1185 if (osr_bci == InvocationEntryBci) {
1186 return method->code();
1187 }
1188 return method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1189 }
1190
1191
1192 // ------------------------------------------------------------------
1193 // CompileBroker::compilation_is_complete
1194 //
1195 // See if compilation of this method is already complete.
1196 bool CompileBroker::compilation_is_complete(const methodHandle& method,
1197 int osr_bci,
1198 int comp_level) {
1199 bool is_osr = (osr_bci != standard_entry_bci);
1200 if (is_osr) {
1319 // ------------------------------------------------------------------
1320 // CompileBroker::preload_classes
1321 void CompileBroker::preload_classes(const methodHandle& method, TRAPS) {
1322 // Move this code over from c1_Compiler.cpp
1323 ShouldNotReachHere();
1324 }
1325
1326
1327 // ------------------------------------------------------------------
1328 // CompileBroker::create_compile_task
1329 //
1330 // Create a CompileTask object representing the current request for
1331 // compilation. Add this task to the queue.
1332 CompileTask* CompileBroker::create_compile_task(CompileQueue* queue,
1333 int compile_id,
1334 const methodHandle& method,
1335 int osr_bci,
1336 int comp_level,
1337 const methodHandle& hot_method,
1338 int hot_count,
1339 const char* comment,
1340 bool blocking) {
1341 CompileTask* new_task = CompileTask::allocate();
1342 new_task->initialize(compile_id, method, osr_bci, comp_level,
1343 hot_method, hot_count, comment,
1344 blocking);
1345 queue->add(new_task);
1346 return new_task;
1347 }
1348
1349 #if INCLUDE_JVMCI
1350 // The number of milliseconds to wait before checking if
1351 // JVMCI compilation has made progress.
1352 static const long JVMCI_COMPILATION_PROGRESS_WAIT_TIMESLICE = 500;
1353
1354 // The number of JVMCI compilation progress checks that must fail
1355 // before unblocking a thread waiting for a blocking compilation.
1356 static const int JVMCI_COMPILATION_PROGRESS_WAIT_ATTEMPTS = 5;
1357
1358 /**
1359 * Waits for a JVMCI compiler to complete a given task. This thread
1360 * waits until either the task completes or it sees no JVMCI compilation
1361 * progress for N consecutive milliseconds where N is
1362 * JVMCI_COMPILATION_PROGRESS_WAIT_TIMESLICE *
1363 * JVMCI_COMPILATION_PROGRESS_WAIT_ATTEMPTS.
|
152 elapsedTimer CompileBroker::_t_standard_compilation;
153 elapsedTimer CompileBroker::_t_invalidated_compilation;
154 elapsedTimer CompileBroker::_t_bailedout_compilation;
155
156 int CompileBroker::_total_bailout_count = 0;
157 int CompileBroker::_total_invalidated_count = 0;
158 int CompileBroker::_total_compile_count = 0;
159 int CompileBroker::_total_osr_compile_count = 0;
160 int CompileBroker::_total_standard_compile_count = 0;
161
162 int CompileBroker::_sum_osr_bytes_compiled = 0;
163 int CompileBroker::_sum_standard_bytes_compiled = 0;
164 int CompileBroker::_sum_nmethod_size = 0;
165 int CompileBroker::_sum_nmethod_code_size = 0;
166
167 long CompileBroker::_peak_compilation_time = 0;
168
169 CompileQueue* CompileBroker::_c2_compile_queue = NULL;
170 CompileQueue* CompileBroker::_c1_compile_queue = NULL;
171
172 const char * CompileBroker::reason_names[] = {
173 "no_reason",
174 "count",
175 "backedge_count",
176 "tiered",
177 "CTW",
178 "replay",
179 "whitebox",
180 "must_be_compiled",
181 "bootstrap"
182 };
183
184 class CompilationLog : public StringEventLog {
185 public:
186 CompilationLog() : StringEventLog("Compilation events") {
187 }
188
189 void log_compile(JavaThread* thread, CompileTask* task) {
190 StringLogMessage lm;
191 stringStream sstr = lm.stream();
192 // msg.time_stamp().update_to(tty->time_stamp().ticks());
193 task->print(&sstr, NULL, true, false);
194 log(thread, "%s", (const char*)lm);
195 }
196
197 void log_nmethod(JavaThread* thread, nmethod* nm) {
198 log(thread, "nmethod %d%s " INTPTR_FORMAT " code [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",
199 nm->compile_id(), nm->is_osr_method() ? "%" : "",
200 p2i(nm), p2i(nm->code_begin()), p2i(nm->code_end()));
201 }
202
203 void log_failure(JavaThread* thread, CompileTask* task, const char* reason, const char* retry_message) {
839 assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
840 // Since we are at a safepoint, we do not need a lock to access
841 // the compile queues.
842 if (_c2_compile_queue != NULL) {
843 _c2_compile_queue->mark_on_stack();
844 }
845 if (_c1_compile_queue != NULL) {
846 _c1_compile_queue->mark_on_stack();
847 }
848 }
849
850 // ------------------------------------------------------------------
851 // CompileBroker::compile_method
852 //
853 // Request compilation of a method.
854 void CompileBroker::compile_method_base(const methodHandle& method,
855 int osr_bci,
856 int comp_level,
857 const methodHandle& hot_method,
858 int hot_count,
859 int compile_reason,
860 bool blocking,
861 Thread* thread) {
862 guarantee(!method->is_abstract(), "cannot compile abstract methods");
863 assert(method->method_holder()->is_instance_klass(),
864 "sanity check");
865 assert(!method->method_holder()->is_not_initialized(),
866 "method holder must be initialized");
867 assert(!method->is_method_handle_intrinsic(), "do not enqueue these guys");
868
869 if (CIPrintRequests) {
870 tty->print("request: ");
871 method->print_short_name(tty);
872 if (osr_bci != InvocationEntryBci) {
873 tty->print(" osr_bci: %d", osr_bci);
874 }
875 tty->print(" level: %d comment: %s count: %d", comp_level, CompileBroker::reason_names[compile_reason], hot_count);
876 if (!hot_method.is_null()) {
877 tty->print(" hot: ");
878 if (hot_method() != method()) {
879 hot_method->print_short_name(tty);
880 } else {
881 tty->print("yes");
882 }
883 }
884 tty->cr();
885 }
886
887 // A request has been made for compilation. Before we do any
888 // real work, check to see if the method has been compiled
889 // in the meantime with a definitive result.
890 if (compilation_is_complete(method, osr_bci, comp_level)) {
891 return;
892 }
893
894 #ifndef PRODUCT
895 if (osr_bci != -1 && !FLAG_IS_DEFAULT(OSROnlyBCI)) {
1019 // <RESULT, QUEUE> :
1020 // <0, 1> : in compile queue, but not yet compiled
1021 // <1, 1> : compiled but queue bit not cleared
1022 // <1, 0> : compiled and queue bit cleared
1023 // Because we first check the queue bits then check the result bits,
1024 // we are assured that we cannot introduce a duplicate task.
1025 // Note that if we did the tests in the reverse order (i.e. check
1026 // result then check queued bit), we could get the result bit before
1027 // the compilation completed, and the queue bit after the compilation
1028 // completed, and end up introducing a "duplicate" (redundant) task.
1029 // In that case, the compiler thread should first check if a method
1030 // has already been compiled before trying to compile it.
1031 // NOTE: in the event that there are multiple compiler threads and
1032 // there is de-optimization/recompilation, things will get hairy,
1033 // and in that case it's best to protect both the testing (here) of
1034 // these bits, and their updating (here and elsewhere) under a
1035 // common lock.
1036 task = create_compile_task(queue,
1037 compile_id, method,
1038 osr_bci, comp_level,
1039 hot_method, hot_count, compile_reason,
1040 blocking);
1041 }
1042
1043 if (blocking) {
1044 wait_for_completion(task);
1045 }
1046 }
1047
1048 nmethod* CompileBroker::compile_method(const methodHandle& method, int osr_bci,
1049 int comp_level,
1050 const methodHandle& hot_method, int hot_count,
1051 int compile_reason, Thread* THREAD) {
1052 // do nothing if compilebroker is not available
1053 if (!_initialized) {
1054 return NULL;
1055 }
1056 AbstractCompiler *comp = CompileBroker::compiler(comp_level);
1057 assert(comp != NULL, "Ensure we don't compile before compilebroker init");
1058 DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, comp);
1059 nmethod* nm = CompileBroker::compile_method(method, osr_bci, comp_level, hot_method, hot_count, compile_reason, directive, THREAD);
1060 DirectivesStack::release(directive);
1061 return nm;
1062 }
1063
1064 nmethod* CompileBroker::compile_method(const methodHandle& method, int osr_bci,
1065 int comp_level,
1066 const methodHandle& hot_method, int hot_count,
1067 int compile_reason, DirectiveSet* directive,
1068 Thread* THREAD) {
1069
1070 // make sure arguments make sense
1071 assert(method->method_holder()->is_instance_klass(), "not an instance method");
1072 assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
1073 assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods");
1074 assert(!method->method_holder()->is_not_initialized(), "method holder must be initialized");
1075 // allow any levels for WhiteBox
1076 assert(WhiteBoxAPI || TieredCompilation || comp_level == CompLevel_highest_tier, "only CompLevel_highest_tier must be used in non-tiered");
1077 // return quickly if possible
1078
1079 // lock, make sure that the compilation
1080 // isn't prohibited in a straightforward way.
1081 AbstractCompiler *comp = CompileBroker::compiler(comp_level);
1082 if (!comp->can_compile_method(method) ||
1083 compilation_is_prohibited(method, osr_bci, comp_level, directive->ExcludeOption)) {
1084 return NULL;
1085 }
1086
1087 if (osr_bci == InvocationEntryBci) {
1172 return NULL;
1173 }
1174
1175 // To properly handle the appendix argument for out-of-line calls we are using a small trampoline that
1176 // pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime).
1177 //
1178 // Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter
1179 // in this case. If we can't generate one and use it we can not execute the out-of-line method handle calls.
1180 AdapterHandlerLibrary::create_native_wrapper(method);
1181 } else {
1182 return NULL;
1183 }
1184 } else {
1185 // If the compiler is shut off due to code cache getting full
1186 // fail out now so blocking compiles dont hang the java thread
1187 if (!should_compile_new_jobs()) {
1188 CompilationPolicy::policy()->delay_compilation(method());
1189 return NULL;
1190 }
1191 bool is_blocking = !directive->BackgroundCompilationOption || CompileTheWorld || ReplayCompiles;
1192 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, compile_reason, is_blocking, THREAD);
1193 }
1194
1195 // return requested nmethod
1196 // We accept a higher level osr method
1197 if (osr_bci == InvocationEntryBci) {
1198 return method->code();
1199 }
1200 return method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1201 }
1202
1203
1204 // ------------------------------------------------------------------
1205 // CompileBroker::compilation_is_complete
1206 //
1207 // See if compilation of this method is already complete.
1208 bool CompileBroker::compilation_is_complete(const methodHandle& method,
1209 int osr_bci,
1210 int comp_level) {
1211 bool is_osr = (osr_bci != standard_entry_bci);
1212 if (is_osr) {
1331 // ------------------------------------------------------------------
1332 // CompileBroker::preload_classes
1333 void CompileBroker::preload_classes(const methodHandle& method, TRAPS) {
1334 // Move this code over from c1_Compiler.cpp
1335 ShouldNotReachHere();
1336 }
1337
1338
1339 // ------------------------------------------------------------------
1340 // CompileBroker::create_compile_task
1341 //
1342 // Create a CompileTask object representing the current request for
1343 // compilation. Add this task to the queue.
1344 CompileTask* CompileBroker::create_compile_task(CompileQueue* queue,
1345 int compile_id,
1346 const methodHandle& method,
1347 int osr_bci,
1348 int comp_level,
1349 const methodHandle& hot_method,
1350 int hot_count,
1351 int compile_reason,
1352 bool blocking) {
1353 CompileTask* new_task = CompileTask::allocate();
1354 new_task->initialize(compile_id, method, osr_bci, comp_level,
1355 hot_method, hot_count, compile_reason,
1356 blocking);
1357 queue->add(new_task);
1358 return new_task;
1359 }
1360
1361 #if INCLUDE_JVMCI
1362 // The number of milliseconds to wait before checking if
1363 // JVMCI compilation has made progress.
1364 static const long JVMCI_COMPILATION_PROGRESS_WAIT_TIMESLICE = 500;
1365
1366 // The number of JVMCI compilation progress checks that must fail
1367 // before unblocking a thread waiting for a blocking compilation.
1368 static const int JVMCI_COMPILATION_PROGRESS_WAIT_ATTEMPTS = 5;
1369
1370 /**
1371 * Waits for a JVMCI compiler to complete a given task. This thread
1372 * waits until either the task completes or it sees no JVMCI compilation
1373 * progress for N consecutive milliseconds where N is
1374 * JVMCI_COMPILATION_PROGRESS_WAIT_TIMESLICE *
1375 * JVMCI_COMPILATION_PROGRESS_WAIT_ATTEMPTS.
|