27 #include "classfile/vmSymbols.hpp" |
27 #include "classfile/vmSymbols.hpp" |
28 #include "code/codeCache.hpp" |
28 #include "code/codeCache.hpp" |
29 #include "compiler/compileBroker.hpp" |
29 #include "compiler/compileBroker.hpp" |
30 #include "compiler/compileLog.hpp" |
30 #include "compiler/compileLog.hpp" |
31 #include "compiler/compilerOracle.hpp" |
31 #include "compiler/compilerOracle.hpp" |
|
32 #include "compiler/directivesParser.hpp" |
32 #include "interpreter/linkResolver.hpp" |
33 #include "interpreter/linkResolver.hpp" |
33 #include "memory/allocation.inline.hpp" |
34 #include "memory/allocation.inline.hpp" |
34 #include "oops/methodData.hpp" |
35 #include "oops/methodData.hpp" |
35 #include "oops/method.hpp" |
36 #include "oops/method.hpp" |
36 #include "oops/oop.inline.hpp" |
37 #include "oops/oop.inline.hpp" |
200 } |
201 } |
201 }; |
202 }; |
202 |
203 |
203 static CompilationLog* _compilation_log = NULL; |
204 static CompilationLog* _compilation_log = NULL; |
204 |
205 |
205 void compileBroker_init() { |
206 bool compileBroker_init() { |
206 if (LogEvents) { |
207 if (LogEvents) { |
207 _compilation_log = new CompilationLog(); |
208 _compilation_log = new CompilationLog(); |
208 } |
209 } |
|
210 |
|
211 // init directives stack, adding default directive |
|
212 DirectivesStack::init(); |
|
213 |
|
214 if (DirectivesParser::has_file()) { |
|
215 return DirectivesParser::parse_from_flag(); |
|
216 } else if (PrintCompilerDirectives) { |
|
217 // Print default directive even when no other was added |
|
218 DirectivesStack::print(tty); |
|
219 } |
|
220 |
|
221 return true; |
209 } |
222 } |
210 |
223 |
211 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) { |
224 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) { |
212 CompilerThread* thread = CompilerThread::current(); |
225 CompilerThread* thread = CompilerThread::current(); |
213 thread->set_task(task); |
226 thread->set_task(task); |
1120 // ------------------------------------------------------------------ |
1133 // ------------------------------------------------------------------ |
1121 // CompileBroker::compilation_is_complete |
1134 // CompileBroker::compilation_is_complete |
1122 // |
1135 // |
1123 // See if compilation of this method is already complete. |
1136 // See if compilation of this method is already complete. |
1124 bool CompileBroker::compilation_is_complete(const methodHandle& method, |
1137 bool CompileBroker::compilation_is_complete(const methodHandle& method, |
1125 int osr_bci, |
1138 int osr_bci, |
1126 int comp_level) { |
1139 int comp_level) { |
1127 bool is_osr = (osr_bci != standard_entry_bci); |
1140 bool is_osr = (osr_bci != standard_entry_bci); |
1128 if (is_osr) { |
1141 if (is_osr) { |
1129 if (method->is_not_osr_compilable(comp_level)) { |
1142 if (method->is_not_osr_compilable(comp_level)) { |
1130 return true; |
1143 return true; |
1131 } else { |
1144 } else { |
1178 (!CICompileOSR || comp == NULL || !comp->supports_osr())) { |
1191 (!CICompileOSR || comp == NULL || !comp->supports_osr())) { |
1179 method->set_not_osr_compilable(comp_level); |
1192 method->set_not_osr_compilable(comp_level); |
1180 return true; |
1193 return true; |
1181 } |
1194 } |
1182 |
1195 |
|
1196 // Breaking the abstraction - directives are only used inside a compilation otherwise. |
|
1197 DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, comp); |
|
1198 bool excluded = directive->ExcludeOption; |
|
1199 DirectivesStack::release(directive); |
|
1200 |
1183 // The method may be explicitly excluded by the user. |
1201 // The method may be explicitly excluded by the user. |
1184 bool quietly; |
|
1185 double scale; |
1202 double scale; |
1186 if (CompilerOracle::should_exclude(method, quietly) |
1203 if (excluded || (CompilerOracle::has_option_value(method, "CompileThresholdScaling", scale) && scale == 0)) { |
1187 || (CompilerOracle::has_option_value(method, "CompileThresholdScaling", scale) && scale == 0)) { |
1204 bool quietly = CompilerOracle::should_exclude_quietly(); |
1188 if (!quietly) { |
1205 if (PrintCompilation && !quietly) { |
1189 // This does not happen quietly... |
1206 // This does not happen quietly... |
1190 ResourceMark rm; |
1207 ResourceMark rm; |
1191 tty->print("### Excluding %s:%s", |
1208 tty->print("### Excluding %s:%s", |
1192 method->is_native() ? "generation of native wrapper" : "compile", |
1209 method->is_native() ? "generation of native wrapper" : "compile", |
1193 (method->is_static() ? " static" : "")); |
1210 (method->is_static() ? " static" : "")); |
1194 method->print_short_name(tty); |
1211 method->print_short_name(tty); |
1195 tty->cr(); |
1212 tty->cr(); |
1196 } |
1213 } |
1197 method->set_not_compilable(CompLevel_all, !quietly, "excluded by CompileCommand"); |
1214 method->set_not_compilable(comp_level, !quietly, "excluded by CompileCommand"); |
1198 } |
1215 } |
1199 |
1216 |
1200 return false; |
1217 return false; |
1201 } |
1218 } |
1202 |
1219 |
1266 // ------------------------------------------------------------------ |
1283 // ------------------------------------------------------------------ |
1267 // CompileBroker::create_compile_task |
1284 // CompileBroker::create_compile_task |
1268 // |
1285 // |
1269 // Create a CompileTask object representing the current request for |
1286 // Create a CompileTask object representing the current request for |
1270 // compilation. Add this task to the queue. |
1287 // compilation. Add this task to the queue. |
1271 CompileTask* CompileBroker::create_compile_task(CompileQueue* queue, |
1288 CompileTask* CompileBroker::create_compile_task(CompileQueue* queue, |
1272 int compile_id, |
1289 int compile_id, |
1273 const methodHandle& method, |
1290 const methodHandle& method, |
1274 int osr_bci, |
1291 int osr_bci, |
1275 int comp_level, |
1292 int comp_level, |
1276 const methodHandle& hot_method, |
1293 const methodHandle& hot_method, |
1277 int hot_count, |
1294 int hot_count, |
1278 const char* comment, |
1295 const char* comment, |
1279 bool blocking) { |
1296 bool blocking) { |
1280 CompileTask* new_task = CompileTask::allocate(); |
1297 CompileTask* new_task = CompileTask::allocate(); |
1281 new_task->initialize(compile_id, method, osr_bci, comp_level, |
1298 new_task->initialize(compile_id, method, osr_bci, comp_level, |
1282 hot_method, hot_count, comment, |
1299 hot_method, hot_count, comment, |
1283 blocking); |
1300 blocking); |
1284 queue->add(new_task); |
1301 queue->add(new_task); |
1354 ci_env.cache_dtrace_flags(); |
1371 ci_env.cache_dtrace_flags(); |
1355 |
1372 |
1356 // Switch back to VM state to do compiler initialization |
1373 // Switch back to VM state to do compiler initialization |
1357 ThreadInVMfromNative tv(thread); |
1374 ThreadInVMfromNative tv(thread); |
1358 ResetNoHandleMark rnhm; |
1375 ResetNoHandleMark rnhm; |
1359 |
|
1360 |
1376 |
1361 if (!comp->is_shark()) { |
1377 if (!comp->is_shark()) { |
1362 // Perform per-thread and global initializations |
1378 // Perform per-thread and global initializations |
1363 comp->initialize(); |
1379 comp->initialize(); |
1364 } |
1380 } |
1627 event.set_inlinedBytes(task->num_inlined_bytecodes()); |
1643 event.set_inlinedBytes(task->num_inlined_bytecodes()); |
1628 event.commit(); |
1644 event.commit(); |
1629 } |
1645 } |
1630 } |
1646 } |
1631 |
1647 |
|
1648 int DirectivesStack::_depth = 0; |
|
1649 CompilerDirectives* DirectivesStack::_top = NULL; |
|
1650 CompilerDirectives* DirectivesStack::_bottom = NULL; |
|
1651 |
1632 // ------------------------------------------------------------------ |
1652 // ------------------------------------------------------------------ |
1633 // CompileBroker::invoke_compiler_on_method |
1653 // CompileBroker::invoke_compiler_on_method |
1634 // |
1654 // |
1635 // Compile a method. |
1655 // Compile a method. |
1636 // |
1656 // |
1653 int osr_bci = task->osr_bci(); |
1673 int osr_bci = task->osr_bci(); |
1654 bool is_osr = (osr_bci != standard_entry_bci); |
1674 bool is_osr = (osr_bci != standard_entry_bci); |
1655 bool should_log = (thread->log() != NULL); |
1675 bool should_log = (thread->log() != NULL); |
1656 bool should_break = false; |
1676 bool should_break = false; |
1657 int task_level = task->comp_level(); |
1677 int task_level = task->comp_level(); |
|
1678 |
|
1679 // Look up matching directives |
|
1680 DirectiveSet* directive = DirectivesStack::getMatchingDirective(task->method(), compiler(task_level)); |
|
1681 |
|
1682 should_break = directive->BreakAtExecuteOption || task->check_break_at_flags(); |
|
1683 if (should_log && !directive->LogOption) { |
|
1684 should_log = false; |
|
1685 } |
1658 { |
1686 { |
1659 // create the handle inside it's own block so it can't |
1687 // create the handle inside it's own block so it can't |
1660 // accidentally be referenced once the thread transitions to |
1688 // accidentally be referenced once the thread transitions to |
1661 // native. The NoHandleMark before the transition should catch |
1689 // native. The NoHandleMark before the transition should catch |
1662 // any cases where this occurs in the future. |
1690 // any cases where this occurs in the future. |
1663 methodHandle method(thread, task->method()); |
1691 methodHandle method(thread, task->method()); |
1664 should_break = check_break_at(method, compile_id, is_osr); |
|
1665 if (should_log && !CompilerOracle::should_log(method)) { |
|
1666 should_log = false; |
|
1667 } |
|
1668 assert(!method->is_native(), "no longer compile natives"); |
1692 assert(!method->is_native(), "no longer compile natives"); |
1669 |
1693 |
1670 // Save information about this method in case of failure. |
1694 // Save information about this method in case of failure. |
1671 set_last_compile(thread, method, is_osr, task_level); |
1695 set_last_compile(thread, method, is_osr, task_level); |
1672 |
1696 |
1730 MonitorLockerEx locker(Compilation_lock, Mutex::_no_safepoint_check_flag); |
1754 MonitorLockerEx locker(Compilation_lock, Mutex::_no_safepoint_check_flag); |
1731 while (WhiteBox::compilation_locked) { |
1755 while (WhiteBox::compilation_locked) { |
1732 locker.wait(Mutex::_no_safepoint_check_flag); |
1756 locker.wait(Mutex::_no_safepoint_check_flag); |
1733 } |
1757 } |
1734 } |
1758 } |
1735 comp->compile_method(&ci_env, target, osr_bci); |
1759 comp->compile_method(&ci_env, target, osr_bci, directive); |
1736 } |
1760 } |
1737 |
1761 |
1738 if (!ci_env.failing() && task->code() == NULL) { |
1762 if (!ci_env.failing() && task->code() == NULL) { |
1739 //assert(false, "compiler should always document failure"); |
1763 //assert(false, "compiler should always document failure"); |
1740 // The compiler elected, without comment, not to register a result. |
1764 // The compiler elected, without comment, not to register a result. |
1760 } |
1784 } |
1761 } |
1785 } |
1762 |
1786 |
1763 post_compile(thread, task, event, !ci_env.failing(), &ci_env); |
1787 post_compile(thread, task, event, !ci_env.failing(), &ci_env); |
1764 } |
1788 } |
|
1789 DirectivesStack::release(directive); |
1765 pop_jni_handle_block(); |
1790 pop_jni_handle_block(); |
1766 |
1791 |
1767 methodHandle method(thread, task->method()); |
1792 methodHandle method(thread, task->method()); |
1768 |
1793 |
1769 DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success()); |
1794 DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success()); |
1945 thread->set_active_handles(java_handles); |
1970 thread->set_active_handles(java_handles); |
1946 compile_handles->set_pop_frame_link(NULL); |
1971 compile_handles->set_pop_frame_link(NULL); |
1947 JNIHandleBlock::release_block(compile_handles, thread); // may block |
1972 JNIHandleBlock::release_block(compile_handles, thread); // may block |
1948 } |
1973 } |
1949 |
1974 |
1950 |
|
1951 // ------------------------------------------------------------------ |
|
1952 // CompileBroker::check_break_at |
|
1953 // |
|
1954 // Should the compilation break at the current compilation. |
|
1955 bool CompileBroker::check_break_at(const methodHandle& method, int compile_id, bool is_osr) { |
|
1956 if (CICountOSR && is_osr && (compile_id == CIBreakAtOSR)) { |
|
1957 return true; |
|
1958 } else if( CompilerOracle::should_break_at(method) ) { // break when compiling |
|
1959 return true; |
|
1960 } else { |
|
1961 return (compile_id == CIBreakAt); |
|
1962 } |
|
1963 } |
|
1964 |
|
1965 // ------------------------------------------------------------------ |
1975 // ------------------------------------------------------------------ |
1966 // CompileBroker::collect_statistics |
1976 // CompileBroker::collect_statistics |
1967 // |
1977 // |
1968 // Collect statistics about the compilation. |
1978 // Collect statistics about the compilation. |
1969 |
1979 |