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