13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "code/codeCache.hpp"
29 #include "compiler/compileBroker.hpp"
30 #include "compiler/compileLog.hpp"
31 #include "compiler/compilerOracle.hpp"
32 #include "interpreter/linkResolver.hpp"
33 #include "memory/allocation.inline.hpp"
34 #include "oops/methodData.hpp"
35 #include "oops/method.hpp"
36 #include "oops/oop.inline.hpp"
37 #include "prims/nativeLookup.hpp"
38 #include "runtime/arguments.hpp"
39 #include "runtime/compilationPolicy.hpp"
40 #include "runtime/init.hpp"
41 #include "runtime/interfaceSupport.hpp"
42 #include "runtime/javaCalls.hpp"
43 #include "runtime/os.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/sweeper.hpp"
46 #include "trace/tracing.hpp"
47 #include "utilities/dtrace.hpp"
48 #include "utilities/events.hpp"
49 #ifdef COMPILER1
50 #include "c1/c1_Compiler.hpp"
51 #endif
52 #ifdef COMPILER2
53 #include "opto/c2compiler.hpp"
54 #endif
55 #ifdef SHARK
56 #include "shark/sharkCompiler.hpp"
57 #endif
58
59 #ifdef DTRACE_ENABLED
60
61 // Only bother with this argument setup if dtrace is available
62
63 #ifndef USDT2
64 HS_DTRACE_PROBE_DECL8(hotspot, method__compile__begin,
65 char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t);
66 HS_DTRACE_PROBE_DECL9(hotspot, method__compile__end,
1894 tty->print_cr("compiler thread " INTPTR_FORMAT " poll detects block request", p2i(Thread::current()));
1895 #endif
1896 ThreadInVMfromNative tivfn(JavaThread::current());
1897 }
1898 }
1899
1900 // wrapper for CodeCache::print_summary()
1901 static void codecache_print(bool detailed)
1902 {
1903 ResourceMark rm;
1904 stringStream s;
1905 // Dump code cache into a buffer before locking the tty,
1906 {
1907 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1908 CodeCache::print_summary(&s, detailed);
1909 }
1910 ttyLocker ttyl;
1911 tty->print("%s", s.as_string());
1912 }
1913
1914 // ------------------------------------------------------------------
1915 // CompileBroker::invoke_compiler_on_method
1916 //
1917 // Compile a method.
1918 //
1919 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
1920 if (PrintCompilation) {
1921 ResourceMark rm;
1922 task->print_line();
1923 }
1924 elapsedTimer time;
1925
1926 CompilerThread* thread = CompilerThread::current();
1927 ResourceMark rm(thread);
1928
1929 if (LogEvents) {
1930 _compilation_log->log_compile(thread, task);
1931 }
1932
1933 // Common flags.
1991 EventCompilation event;
1992
1993 AbstractCompiler *comp = compiler(task_level);
1994 if (comp == NULL) {
1995 ci_env.record_method_not_compilable("no compiler", !TieredCompilation);
1996 } else {
1997 comp->compile_method(&ci_env, target, osr_bci);
1998 }
1999
2000 if (!ci_env.failing() && task->code() == NULL) {
2001 //assert(false, "compiler should always document failure");
2002 // The compiler elected, without comment, not to register a result.
2003 // Do not attempt further compilations of this method.
2004 ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
2005 }
2006
2007 // Copy this bit to the enclosing block:
2008 compilable = ci_env.compilable();
2009
2010 if (ci_env.failing()) {
2011 task->set_failure_reason(ci_env.failure_reason());
2012 const char* retry_message = ci_env.retry_message();
2013 if (_compilation_log != NULL) {
2014 _compilation_log->log_failure(thread, task, ci_env.failure_reason(), retry_message);
2015 }
2016 if (PrintCompilation) {
2017 FormatBufferResource msg = retry_message != NULL ?
2018 err_msg_res("COMPILE SKIPPED: %s (%s)", ci_env.failure_reason(), retry_message) :
2019 err_msg_res("COMPILE SKIPPED: %s", ci_env.failure_reason());
2020 task->print_compilation(tty, msg);
2021 }
2022 } else {
2023 task->mark_success();
2024 task->set_num_inlined_bytecodes(ci_env.num_inlined_bytecodes());
2025 if (_compilation_log != NULL) {
2026 nmethod* code = task->code();
2027 if (code != NULL) {
2028 _compilation_log->log_nmethod(thread, code);
2029 }
2030 }
2031 }
2032 // simulate crash during compilation
2033 assert(task->compile_id() != CICrashAt, "just as planned");
2034 if (event.should_commit()) {
2035 event.set_method(target->get_Method());
2036 event.set_compileID(compile_id);
2037 event.set_compileLevel(task->comp_level());
2038 event.set_succeded(task->is_success());
2039 event.set_isOsr(is_osr);
2040 event.set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size());
2041 event.set_inlinedBytes(task->num_inlined_bytecodes());
2042 event.commit();
2043 }
2044 }
2045 pop_jni_handle_block();
2046
2047 methodHandle method(thread, task->method());
2048
2049 DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success());
2050
2051 collect_statistics(thread, time, task);
2052
2053 if (PrintCompilation && PrintCompilation2) {
2054 tty->print("%7d ", (int) tty->time_stamp().milliseconds()); // print timestamp
2055 tty->print("%4d ", compile_id); // print compilation number
2056 tty->print("%s ", (is_osr ? "%" : " "));
2057 if (task->code() != NULL) {
2058 tty->print("size: %d(%d) ", task->code()->total_size(), task->code()->insts_size());
2059 }
2060 tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes());
2061 }
2062
|
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "code/codeCache.hpp"
29 #include "compiler/compileBroker.hpp"
30 #include "compiler/compileLog.hpp"
31 #include "compiler/compilerOracle.hpp"
32 #include "interpreter/linkResolver.hpp"
33 #include "jfr/jfrEvents.hpp"
34 #include "memory/allocation.inline.hpp"
35 #include "oops/methodData.hpp"
36 #include "oops/method.hpp"
37 #include "oops/oop.inline.hpp"
38 #include "prims/nativeLookup.hpp"
39 #include "runtime/arguments.hpp"
40 #include "runtime/compilationPolicy.hpp"
41 #include "runtime/init.hpp"
42 #include "runtime/interfaceSupport.hpp"
43 #include "runtime/javaCalls.hpp"
44 #include "runtime/os.hpp"
45 #include "runtime/sharedRuntime.hpp"
46 #include "runtime/sweeper.hpp"
47 #include "utilities/dtrace.hpp"
48 #include "utilities/events.hpp"
49 #ifdef COMPILER1
50 #include "c1/c1_Compiler.hpp"
51 #endif
52 #ifdef COMPILER2
53 #include "opto/c2compiler.hpp"
54 #endif
55 #ifdef SHARK
56 #include "shark/sharkCompiler.hpp"
57 #endif
58
59 #ifdef DTRACE_ENABLED
60
61 // Only bother with this argument setup if dtrace is available
62
63 #ifndef USDT2
64 HS_DTRACE_PROBE_DECL8(hotspot, method__compile__begin,
65 char*, intptr_t, char*, intptr_t, char*, intptr_t, char*, intptr_t);
66 HS_DTRACE_PROBE_DECL9(hotspot, method__compile__end,
1894 tty->print_cr("compiler thread " INTPTR_FORMAT " poll detects block request", p2i(Thread::current()));
1895 #endif
1896 ThreadInVMfromNative tivfn(JavaThread::current());
1897 }
1898 }
1899
1900 // wrapper for CodeCache::print_summary()
1901 static void codecache_print(bool detailed)
1902 {
1903 ResourceMark rm;
1904 stringStream s;
1905 // Dump code cache into a buffer before locking the tty,
1906 {
1907 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1908 CodeCache::print_summary(&s, detailed);
1909 }
1910 ttyLocker ttyl;
1911 tty->print("%s", s.as_string());
1912 }
1913
1914 static void post_compilation_event(EventCompilation* event, CompileTask* task) {
1915 assert(event != NULL, "invariant");
1916 assert(event->should_commit(), "invariant");
1917 event->set_method(task->method());
1918 event->set_compileId(task->compile_id());
1919 event->set_compileLevel(task->comp_level());
1920 event->set_succeded(task->is_success());
1921 event->set_isOsr(task->osr_bci() != CompileBroker::standard_entry_bci);
1922 event->set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size());
1923 event->set_inlinedBytes(task->num_inlined_bytecodes());
1924 event->commit();
1925 }
1926
1927 // ------------------------------------------------------------------
1928 // CompileBroker::invoke_compiler_on_method
1929 //
1930 // Compile a method.
1931 //
1932 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
1933 if (PrintCompilation) {
1934 ResourceMark rm;
1935 task->print_line();
1936 }
1937 elapsedTimer time;
1938
1939 CompilerThread* thread = CompilerThread::current();
1940 ResourceMark rm(thread);
1941
1942 if (LogEvents) {
1943 _compilation_log->log_compile(thread, task);
1944 }
1945
1946 // Common flags.
2004 EventCompilation event;
2005
2006 AbstractCompiler *comp = compiler(task_level);
2007 if (comp == NULL) {
2008 ci_env.record_method_not_compilable("no compiler", !TieredCompilation);
2009 } else {
2010 comp->compile_method(&ci_env, target, osr_bci);
2011 }
2012
2013 if (!ci_env.failing() && task->code() == NULL) {
2014 //assert(false, "compiler should always document failure");
2015 // The compiler elected, without comment, not to register a result.
2016 // Do not attempt further compilations of this method.
2017 ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
2018 }
2019
2020 // Copy this bit to the enclosing block:
2021 compilable = ci_env.compilable();
2022
2023 if (ci_env.failing()) {
2024 const char *failure_reason = ci_env.failure_reason();
2025 const char* retry_message = ci_env.retry_message();
2026 task->set_failure_reason(failure_reason);
2027 if (_compilation_log != NULL) {
2028 _compilation_log->log_failure(thread, task, ci_env.failure_reason(), retry_message);
2029 }
2030 if (PrintCompilation) {
2031 FormatBufferResource msg = retry_message != NULL ?
2032 err_msg_res("COMPILE SKIPPED: %s (%s)", ci_env.failure_reason(), retry_message) :
2033 err_msg_res("COMPILE SKIPPED: %s", ci_env.failure_reason());
2034 task->print_compilation(tty, msg);
2035 }
2036
2037 EventCompilationFailure event;
2038 if (event.should_commit()) {
2039 event.set_compileId(compile_id);
2040 event.set_failureMessage(failure_reason);
2041 event.commit();
2042 }
2043 } else {
2044 task->mark_success();
2045 task->set_num_inlined_bytecodes(ci_env.num_inlined_bytecodes());
2046 if (_compilation_log != NULL) {
2047 nmethod* code = task->code();
2048 if (code != NULL) {
2049 _compilation_log->log_nmethod(thread, code);
2050 }
2051 }
2052 }
2053 // simulate crash during compilation
2054 assert(task->compile_id() != CICrashAt, "just as planned");
2055 if (event.should_commit()) {
2056 post_compilation_event(&event, task);
2057 }
2058 }
2059 pop_jni_handle_block();
2060
2061 methodHandle method(thread, task->method());
2062
2063 DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success());
2064
2065 collect_statistics(thread, time, task);
2066
2067 if (PrintCompilation && PrintCompilation2) {
2068 tty->print("%7d ", (int) tty->time_stamp().milliseconds()); // print timestamp
2069 tty->print("%4d ", compile_id); // print compilation number
2070 tty->print("%s ", (is_osr ? "%" : " "));
2071 if (task->code() != NULL) {
2072 tty->print("size: %d(%d) ", task->code()->total_size(), task->code()->insts_size());
2073 }
2074 tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes());
2075 }
2076
|