Mercurial > hg > graal-jvmci-8
comparison src/share/vm/compiler/compileBroker.cpp @ 4970:33df1aeaebbf
Merge with http://hg.openjdk.java.net/hsx/hsx24/hotspot/
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Mon, 27 Feb 2012 13:10:13 +0100 |
parents | 723df37192d6 09d00c18e323 |
children | 532be189cf09 |
comparison
equal
deleted
inserted
replaced
4703:2cfb7fb2dce7 | 4970:33df1aeaebbf |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
45 #include "runtime/sweeper.hpp" | 45 #include "runtime/sweeper.hpp" |
46 #include "utilities/dtrace.hpp" | 46 #include "utilities/dtrace.hpp" |
47 #ifdef GRAAL | 47 #ifdef GRAAL |
48 #include "graal/graalCompiler.hpp" | 48 #include "graal/graalCompiler.hpp" |
49 #endif | 49 #endif |
50 #include "utilities/events.hpp" | |
50 #ifdef COMPILER1 | 51 #ifdef COMPILER1 |
51 #include "c1/c1_Compiler.hpp" | 52 #include "c1/c1_Compiler.hpp" |
52 #endif | 53 #endif |
53 #ifdef COMPILER2 | 54 #ifdef COMPILER2 |
54 #include "opto/c2compiler.hpp" | 55 #include "opto/c2compiler.hpp" |
189 CompileQueue* CompileBroker::_c1_method_queue = NULL; | 190 CompileQueue* CompileBroker::_c1_method_queue = NULL; |
190 CompileTask* CompileBroker::_task_free_list = NULL; | 191 CompileTask* CompileBroker::_task_free_list = NULL; |
191 | 192 |
192 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL; | 193 GrowableArray<CompilerThread*>* CompileBroker::_method_threads = NULL; |
193 | 194 |
195 | |
196 class CompilationLog : public StringEventLog { | |
197 public: | |
198 CompilationLog() : StringEventLog("Compilation events") { | |
199 } | |
200 | |
201 void log_compile(JavaThread* thread, CompileTask* task) { | |
202 StringLogMessage lm; | |
203 stringStream msg = lm.stream(); | |
204 // msg.time_stamp().update_to(tty->time_stamp().ticks()); | |
205 task->print_compilation(&msg, true); | |
206 log(thread, "%s", (const char*)lm); | |
207 } | |
208 | |
209 void log_nmethod(JavaThread* thread, nmethod* nm) { | |
210 log(thread, "nmethod %d%s " INTPTR_FORMAT " code ["INTPTR_FORMAT ", " INTPTR_FORMAT "]", | |
211 nm->compile_id(), nm->is_osr_method() ? "%" : "", | |
212 nm, nm->code_begin(), nm->code_end()); | |
213 } | |
214 | |
215 void log_failure(JavaThread* thread, CompileTask* task, const char* reason, const char* retry_message) { | |
216 StringLogMessage lm; | |
217 lm.print("%4d COMPILE SKIPPED: %s", task->compile_id(), reason); | |
218 if (retry_message != NULL) { | |
219 lm.append(" (%s)", retry_message); | |
220 } | |
221 lm.print("\n"); | |
222 log(thread, "%s", (const char*)lm); | |
223 } | |
224 }; | |
225 | |
226 static CompilationLog* _compilation_log = NULL; | |
227 | |
228 void compileBroker_init() { | |
229 if (LogEvents) { | |
230 _compilation_log = new CompilationLog(); | |
231 } | |
232 } | |
194 | 233 |
195 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) { | 234 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) { |
196 CompilerThread* thread = CompilerThread::current(); | 235 CompilerThread* thread = CompilerThread::current(); |
197 thread->set_task(task); | 236 thread->set_task(task); |
198 CompileLog* log = thread->log(); | 237 CompileLog* log = thread->log(); |
327 } | 366 } |
328 | 367 |
329 | 368 |
330 // ------------------------------------------------------------------ | 369 // ------------------------------------------------------------------ |
331 // CompileTask::print_compilation_impl | 370 // CompileTask::print_compilation_impl |
332 void CompileTask::print_compilation_impl(outputStream* st, methodOop method, int compile_id, int comp_level, bool is_osr_method, int osr_bci, bool is_blocking, const char* msg) { | 371 void CompileTask::print_compilation_impl(outputStream* st, methodOop method, int compile_id, int comp_level, |
333 st->print("%7d ", (int) st->time_stamp().milliseconds()); // print timestamp | 372 bool is_osr_method, int osr_bci, bool is_blocking, |
373 const char* msg, bool short_form) { | |
374 if (!short_form) { | |
375 st->print("%7d ", (int) st->time_stamp().milliseconds()); // print timestamp | |
376 } | |
334 st->print("%4d ", compile_id); // print compilation number | 377 st->print("%4d ", compile_id); // print compilation number |
335 | 378 |
336 // For unloaded methods the transition to zombie occurs after the | 379 // For unloaded methods the transition to zombie occurs after the |
337 // method is cleared so it's impossible to report accurate | 380 // method is cleared so it's impossible to report accurate |
338 // information for that case. | 381 // information for that case. |
371 } | 414 } |
372 | 415 |
373 if (msg != NULL) { | 416 if (msg != NULL) { |
374 st->print(" %s", msg); | 417 st->print(" %s", msg); |
375 } | 418 } |
376 st->cr(); | 419 if (!short_form) { |
420 st->cr(); | |
421 } | |
377 } | 422 } |
378 | 423 |
379 // ------------------------------------------------------------------ | 424 // ------------------------------------------------------------------ |
380 // CompileTask::print_inlining | 425 // CompileTask::print_inlining |
381 void CompileTask::print_inlining(outputStream* st, ciMethod* method, int inline_level, int bci, const char* msg) { | 426 void CompileTask::print_inlining(outputStream* st, ciMethod* method, int inline_level, int bci, const char* msg) { |
427 for (int i = 0; i < inline_level; i++) st->print(" "); | 472 for (int i = 0; i < inline_level; i++) st->print(" "); |
428 } | 473 } |
429 | 474 |
430 // ------------------------------------------------------------------ | 475 // ------------------------------------------------------------------ |
431 // CompileTask::print_compilation | 476 // CompileTask::print_compilation |
432 void CompileTask::print_compilation(outputStream* st) { | 477 void CompileTask::print_compilation(outputStream* st, bool short_form) { |
433 oop rem = JNIHandles::resolve(method_handle()); | 478 oop rem = JNIHandles::resolve(method_handle()); |
434 assert(rem != NULL && rem->is_method(), "must be"); | 479 assert(rem != NULL && rem->is_method(), "must be"); |
435 methodOop method = (methodOop) rem; | 480 methodOop method = (methodOop) rem; |
436 bool is_osr_method = osr_bci() != InvocationEntryBci; | 481 bool is_osr_method = osr_bci() != InvocationEntryBci; |
437 print_compilation_impl(st, method, compile_id(), comp_level(), is_osr_method, osr_bci(), is_blocking()); | 482 print_compilation_impl(st, method, compile_id(), comp_level(), is_osr_method, osr_bci(), is_blocking(), NULL, short_form); |
438 } | 483 } |
439 | 484 |
440 // ------------------------------------------------------------------ | 485 // ------------------------------------------------------------------ |
441 // CompileTask::log_task | 486 // CompileTask::log_task |
442 void CompileTask::log_task(xmlStream* log) { | 487 void CompileTask::log_task(xmlStream* log) { |
860 java_lang_Thread::set_thread(thread_oop(), compiler_thread); | 905 java_lang_Thread::set_thread(thread_oop(), compiler_thread); |
861 | 906 |
862 // Note that this only sets the JavaThread _priority field, which by | 907 // Note that this only sets the JavaThread _priority field, which by |
863 // definition is limited to Java priorities and not OS priorities. | 908 // definition is limited to Java priorities and not OS priorities. |
864 // The os-priority is set in the CompilerThread startup code itself | 909 // The os-priority is set in the CompilerThread startup code itself |
910 | |
865 java_lang_Thread::set_priority(thread_oop(), NearMaxPriority); | 911 java_lang_Thread::set_priority(thread_oop(), NearMaxPriority); |
866 // CLEANUP PRIORITIES: This -if- statement hids a bug whereby the compiler | 912 |
867 // threads never have their OS priority set. The assumption here is to | 913 // Note that we cannot call os::set_priority because it expects Java |
868 // enable the Performance group to do flag tuning, figure out a suitable | 914 // priorities and we are *explicitly* using OS priorities so that it's |
869 // CompilerThreadPriority, and then remove this 'if' statement (and | 915 // possible to set the compiler thread priority higher than any Java |
870 // comment) and unconditionally set the priority. | 916 // thread. |
871 | 917 |
872 // Compiler Threads should be at the highest Priority | 918 int native_prio = CompilerThreadPriority; |
873 if ( CompilerThreadPriority != -1 ) | 919 if (native_prio == -1) { |
874 os::set_native_priority( compiler_thread, CompilerThreadPriority ); | 920 if (UseCriticalCompilerThreadPriority) { |
875 else | 921 native_prio = os::java_to_os_priority[CriticalPriority]; |
876 os::set_native_priority( compiler_thread, os::java_to_os_priority[NearMaxPriority]); | 922 } else { |
877 | 923 native_prio = os::java_to_os_priority[NearMaxPriority]; |
878 // Note that I cannot call os::set_priority because it expects Java | 924 } |
879 // priorities and I am *explicitly* using OS priorities so that it's | 925 } |
880 // possible to set the compiler thread priority higher than any Java | 926 os::set_native_priority(compiler_thread, native_prio); |
881 // thread. | |
882 | 927 |
883 java_lang_Thread::set_daemon(thread_oop()); | 928 java_lang_Thread::set_daemon(thread_oop()); |
884 | 929 |
885 compiler_thread->set_threadObj(thread_oop()); | 930 compiler_thread->set_threadObj(thread_oop()); |
886 Threads::add(compiler_thread); | 931 Threads::add(compiler_thread); |
887 Thread::start(compiler_thread); | 932 Thread::start(compiler_thread); |
888 } | 933 } |
934 | |
889 // Let go of Threads_lock before yielding | 935 // Let go of Threads_lock before yielding |
890 os::yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS) | 936 os::yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS) |
891 | 937 |
892 return compiler_thread; | 938 return compiler_thread; |
893 } | 939 } |
967 int osr_bci, | 1013 int osr_bci, |
968 int comp_level, | 1014 int comp_level, |
969 methodHandle hot_method, | 1015 methodHandle hot_method, |
970 int hot_count, | 1016 int hot_count, |
971 const char* comment, | 1017 const char* comment, |
972 TRAPS) { | 1018 Thread* thread) { |
973 // do nothing if compiler thread(s) is not available | 1019 // do nothing if compiler thread(s) is not available |
974 if (!_initialized ) { | 1020 if (!_initialized ) { |
975 return; | 1021 return; |
976 } | 1022 } |
977 | 1023 |
1043 bool blocking = false; | 1089 bool blocking = false; |
1044 CompileQueue* queue = compile_queue(comp_level); | 1090 CompileQueue* queue = compile_queue(comp_level); |
1045 | 1091 |
1046 // Acquire our lock. | 1092 // Acquire our lock. |
1047 { | 1093 { |
1048 MutexLocker locker(queue->lock(), THREAD); | 1094 MutexLocker locker(queue->lock(), thread); |
1049 | 1095 |
1050 if (JavaThread::current()->is_compiling() && !BackgroundCompilation) { | 1096 if (JavaThread::current()->is_compiling() && !BackgroundCompilation) { |
1051 #ifdef GRAAL | 1097 #ifdef GRAAL |
1052 TRACE_graal_1("Recursive compile %s!", method->name_and_sig_as_C_string()); | 1098 TRACE_graal_1("Recursive compile %s!", method->name_and_sig_as_C_string()); |
1053 #endif | 1099 #endif |
1145 | 1191 |
1146 | 1192 |
1147 nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci, | 1193 nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci, |
1148 int comp_level, | 1194 int comp_level, |
1149 methodHandle hot_method, int hot_count, | 1195 methodHandle hot_method, int hot_count, |
1150 const char* comment, TRAPS) { | 1196 const char* comment, Thread* THREAD) { |
1151 // make sure arguments make sense | 1197 // make sure arguments make sense |
1152 assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method"); | 1198 assert(method->method_holder()->klass_part()->oop_is_instance(), "not an instance method"); |
1153 assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range"); | 1199 assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range"); |
1154 assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods"); | 1200 assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods"); |
1155 assert(!instanceKlass::cast(method->method_holder())->is_not_initialized(), "method holder must be initialized"); | 1201 assert(!instanceKlass::cast(method->method_holder())->is_not_initialized(), "method holder must be initialized"); |
1199 } | 1245 } |
1200 | 1246 |
1201 assert(!HAS_PENDING_EXCEPTION, "No exception should be present"); | 1247 assert(!HAS_PENDING_EXCEPTION, "No exception should be present"); |
1202 // some prerequisites that are compiler specific | 1248 // some prerequisites that are compiler specific |
1203 if (compiler(comp_level)->is_c2() || compiler(comp_level)->is_shark()) { | 1249 if (compiler(comp_level)->is_c2() || compiler(comp_level)->is_shark()) { |
1204 method->constants()->resolve_string_constants(CHECK_0); | 1250 method->constants()->resolve_string_constants(CHECK_AND_CLEAR_NULL); |
1205 // Resolve all classes seen in the signature of the method | 1251 // Resolve all classes seen in the signature of the method |
1206 // we are compiling. | 1252 // we are compiling. |
1207 methodOopDesc::load_signature_classes(method, CHECK_0); | 1253 methodOopDesc::load_signature_classes(method, CHECK_AND_CLEAR_NULL); |
1208 } | 1254 } |
1209 | 1255 |
1210 // If the method is native, do the lookup in the thread requesting | 1256 // If the method is native, do the lookup in the thread requesting |
1211 // the compilation. Native lookups can load code, which is not | 1257 // the compilation. Native lookups can load code, which is not |
1212 // permitted during compilation. | 1258 // permitted during compilation. |
1256 (void) AdapterHandlerLibrary::create_native_wrapper(method, compile_id); | 1302 (void) AdapterHandlerLibrary::create_native_wrapper(method, compile_id); |
1257 } else { | 1303 } else { |
1258 return NULL; | 1304 return NULL; |
1259 } | 1305 } |
1260 } else { | 1306 } else { |
1261 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, CHECK_0); | 1307 compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, comment, THREAD); |
1262 } | 1308 } |
1263 | 1309 |
1264 // return requested nmethod | 1310 // return requested nmethod |
1265 // We accept a higher level osr method | 1311 // We accept a higher level osr method |
1266 return osr_bci == InvocationEntryBci ? method->code() : method->lookup_osr_nmethod_for(osr_bci, comp_level, false); | 1312 return osr_bci == InvocationEntryBci ? method->code() : method->lookup_osr_nmethod_for(osr_bci, comp_level, false); |
1674 elapsedTimer time; | 1720 elapsedTimer time; |
1675 | 1721 |
1676 CompilerThread* thread = CompilerThread::current(); | 1722 CompilerThread* thread = CompilerThread::current(); |
1677 ResourceMark rm(thread); | 1723 ResourceMark rm(thread); |
1678 | 1724 |
1725 if (LogEvents) { | |
1726 _compilation_log->log_compile(thread, task); | |
1727 } | |
1728 | |
1679 // Common flags. | 1729 // Common flags. |
1680 uint compile_id = task->compile_id(); | 1730 uint compile_id = task->compile_id(); |
1681 int osr_bci = task->osr_bci(); | 1731 int osr_bci = task->osr_bci(); |
1682 bool is_osr = (osr_bci != standard_entry_bci); | 1732 bool is_osr = (osr_bci != standard_entry_bci); |
1683 bool should_log = (thread->log() != NULL); | 1733 bool should_log = (thread->log() != NULL); |
1742 // The compiler elected, without comment, not to register a result. | 1792 // The compiler elected, without comment, not to register a result. |
1743 // Do not attempt further compilations of this method. | 1793 // Do not attempt further compilations of this method. |
1744 ci_env.record_method_not_compilable("compile failed", !TieredCompilation); | 1794 ci_env.record_method_not_compilable("compile failed", !TieredCompilation); |
1745 } | 1795 } |
1746 | 1796 |
1797 // Copy this bit to the enclosing block: | |
1798 compilable = ci_env.compilable(); | |
1799 | |
1747 if (ci_env.failing()) { | 1800 if (ci_env.failing()) { |
1748 // Copy this bit to the enclosing block: | 1801 const char* retry_message = ci_env.retry_message(); |
1749 compilable = ci_env.compilable(); | 1802 if (_compilation_log != NULL) { |
1803 _compilation_log->log_failure(thread, task, ci_env.failure_reason(), retry_message); | |
1804 } | |
1750 if (PrintCompilation) { | 1805 if (PrintCompilation) { |
1751 const char* reason = ci_env.failure_reason(); | 1806 tty->print("%4d COMPILE SKIPPED: %s", compile_id, ci_env.failure_reason()); |
1752 if (compilable == ciEnv::MethodCompilable_not_at_tier) { | 1807 if (retry_message != NULL) { |
1753 tty->print_cr("%4d COMPILE SKIPPED: %s (retry at different tier)", compile_id, reason); | 1808 tty->print(" (%s)", retry_message); |
1754 } else if (compilable == ciEnv::MethodCompilable_never) { | |
1755 tty->print_cr("%4d COMPILE SKIPPED: %s (not retryable)", compile_id, reason); | |
1756 } else if (compilable == ciEnv::MethodCompilable) { | |
1757 tty->print_cr("%4d COMPILE SKIPPED: %s", compile_id, reason); | |
1758 } | 1809 } |
1810 tty->cr(); | |
1759 } | 1811 } |
1760 } else { | 1812 } else { |
1761 task->mark_success(); | 1813 task->mark_success(); |
1762 task->set_num_inlined_bytecodes(ci_env.num_inlined_bytecodes()); | 1814 task->set_num_inlined_bytecodes(ci_env.num_inlined_bytecodes()); |
1815 if (_compilation_log != NULL) { | |
1816 nmethod* code = task->code(); | |
1817 if (code != NULL) { | |
1818 _compilation_log->log_nmethod(thread, code); | |
1819 } | |
1820 } | |
1763 } | 1821 } |
1764 } | 1822 } |
1765 pop_jni_handle_block(); | 1823 pop_jni_handle_block(); |
1766 | 1824 |
1767 methodHandle method(thread, | 1825 methodHandle method(thread, |