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" 1896 tty->print_cr("compiler thread " INTPTR_FORMAT " poll detects block request", p2i(Thread::current())); 1897 #endif 1898 ThreadInVMfromNative tivfn(JavaThread::current()); 1899 } 1900 } 1901 1902 // wrapper for CodeCache::print_summary() 1903 static void codecache_print(bool detailed) 1904 { 1905 ResourceMark rm; 1906 stringStream s; 1907 // Dump code cache into a buffer before locking the tty, 1908 { 1909 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1910 CodeCache::print_summary(&s, detailed); 1911 } 1912 ttyLocker ttyl; 1913 tty->print("%s", s.as_string()); 1914 } 1915 1916 static void post_compilation_event(EventCompilation* event, CompileTask* task) { 1917 assert(event != NULL, "invariant"); 1918 assert(event->should_commit(), "invariant"); 1919 event->set_method(task->method()); 1920 event->set_compileId(task->compile_id()); 1921 event->set_compileLevel(task->comp_level()); 1922 event->set_succeded(task->is_success()); 1923 event->set_isOsr(task->osr_bci() != CompileBroker::standard_entry_bci); 1924 event->set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size()); 1925 event->set_inlinedBytes(task->num_inlined_bytecodes()); 1926 event->commit(); 1927 } 1928 1929 // ------------------------------------------------------------------ 1930 // CompileBroker::invoke_compiler_on_method 1931 // 1932 // Compile a method. 1933 // 1934 void CompileBroker::invoke_compiler_on_method(CompileTask* task) { 1935 if (PrintCompilation) { 1936 ResourceMark rm; 1937 task->print_line(); 1938 } 1939 elapsedTimer time; 1940 1941 CompilerThread* thread = CompilerThread::current(); 1942 ResourceMark rm(thread); 1943 1944 if (LogEvents) { 1945 _compilation_log->log_compile(thread, task); 1946 } 1947 1986 1987 ciEnv ci_env(task, system_dictionary_modification_counter); 1988 if (should_break) { 1989 ci_env.set_break_at_compile(true); 1990 } 1991 if (should_log) { 1992 ci_env.set_log(thread->log()); 1993 } 1994 assert(thread->env() == &ci_env, "set by ci_env"); 1995 // The thread-env() field is cleared in ~CompileTaskWrapper. 1996 1997 // Cache Jvmti state 1998 ci_env.cache_jvmti_state(); 1999 2000 // Cache DTrace flags 2001 ci_env.cache_dtrace_flags(); 2002 2003 ciMethod* target = ci_env.get_method_from_handle(target_handle); 2004 2005 TraceTime t1("compilation", &time); 2006 EventCompilation event; 2007 2008 AbstractCompiler *comp = compiler(task_level); 2009 if (comp == NULL) { 2010 ci_env.record_method_not_compilable("no compiler", !TieredCompilation); 2011 } else { 2012 comp->compile_method(&ci_env, target, osr_bci); 2013 } 2014 2015 if (!ci_env.failing() && task->code() == NULL) { 2016 //assert(false, "compiler should always document failure"); 2017 // The compiler elected, without comment, not to register a result. 2018 // Do not attempt further compilations of this method. 2019 ci_env.record_method_not_compilable("compile failed", !TieredCompilation); 2020 } 2021 2022 // Copy this bit to the enclosing block: 2023 compilable = ci_env.compilable(); 2024 2025 if (ci_env.failing()) { 2026 const char *failure_reason = ci_env.failure_reason(); 2027 const char* retry_message = ci_env.retry_message(); 2028 task->set_failure_reason(failure_reason); 2029 if (_compilation_log != NULL) { 2030 _compilation_log->log_failure(thread, task, ci_env.failure_reason(), retry_message); 2031 } 2032 if (PrintCompilation) { 2033 FormatBufferResource msg = retry_message != NULL ? 2034 err_msg_res("COMPILE SKIPPED: %s (%s)", ci_env.failure_reason(), retry_message) : 2035 err_msg_res("COMPILE SKIPPED: %s", ci_env.failure_reason()); 2036 task->print_compilation(tty, msg); 2037 } 2038 2039 EventCompilationFailure event; 2040 if (event.should_commit()) { 2041 event.set_compileId(compile_id); 2042 event.set_failureMessage(failure_reason); 2043 event.commit(); 2044 } 2045 } else { 2046 task->mark_success(); 2047 task->set_num_inlined_bytecodes(ci_env.num_inlined_bytecodes()); 2048 if (_compilation_log != NULL) { 2049 nmethod* code = task->code(); 2050 if (code != NULL) { 2051 _compilation_log->log_nmethod(thread, code); 2052 } 2053 } 2054 } 2055 // simulate crash during compilation 2056 assert(task->compile_id() != CICrashAt, "just as planned"); 2057 if (event.should_commit()) { 2058 post_compilation_event(&event, task); 2059 } 2060 } 2061 pop_jni_handle_block(); 2062 2063 methodHandle method(thread, task->method()); 2064 2065 DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success()); 2066 2067 collect_statistics(thread, time, task); 2068 2069 if (PrintCompilation && PrintCompilation2) { 2070 tty->print("%7d ", (int) tty->time_stamp().milliseconds()); // print timestamp 2071 tty->print("%4d ", compile_id); // print compilation number 2072 tty->print("%s ", (is_osr ? "%" : " ")); 2073 if (task->code() != NULL) { 2074 tty->print("size: %d(%d) ", task->code()->total_size(), task->code()->insts_size()); 2075 } 2076 tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes()); 2077 } 2078 2079 if (PrintCodeCacheOnCompilation) | 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 #if INCLUDE_JFR 34 #include "jfr/jfrEvents.hpp" 35 #endif 36 #include "memory/allocation.inline.hpp" 37 #include "oops/methodData.hpp" 38 #include "oops/method.hpp" 39 #include "oops/oop.inline.hpp" 40 #include "prims/nativeLookup.hpp" 41 #include "runtime/arguments.hpp" 42 #include "runtime/compilationPolicy.hpp" 43 #include "runtime/init.hpp" 44 #include "runtime/interfaceSupport.hpp" 45 #include "runtime/javaCalls.hpp" 46 #include "runtime/os.hpp" 47 #include "runtime/sharedRuntime.hpp" 48 #include "runtime/sweeper.hpp" 49 #include "utilities/dtrace.hpp" 50 #include "utilities/events.hpp" 51 #ifdef COMPILER1 52 #include "c1/c1_Compiler.hpp" 53 #endif 54 #ifdef COMPILER2 55 #include "opto/c2compiler.hpp" 1898 tty->print_cr("compiler thread " INTPTR_FORMAT " poll detects block request", p2i(Thread::current())); 1899 #endif 1900 ThreadInVMfromNative tivfn(JavaThread::current()); 1901 } 1902 } 1903 1904 // wrapper for CodeCache::print_summary() 1905 static void codecache_print(bool detailed) 1906 { 1907 ResourceMark rm; 1908 stringStream s; 1909 // Dump code cache into a buffer before locking the tty, 1910 { 1911 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1912 CodeCache::print_summary(&s, detailed); 1913 } 1914 ttyLocker ttyl; 1915 tty->print("%s", s.as_string()); 1916 } 1917 1918 #if INCLUDE_JFR 1919 static void post_compilation_event(EventCompilation* event, CompileTask* task) { 1920 assert(event != NULL, "invariant"); 1921 assert(event->should_commit(), "invariant"); 1922 event->set_method(task->method()); 1923 event->set_compileId(task->compile_id()); 1924 event->set_compileLevel(task->comp_level()); 1925 event->set_succeded(task->is_success()); 1926 event->set_isOsr(task->osr_bci() != CompileBroker::standard_entry_bci); 1927 event->set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size()); 1928 event->set_inlinedBytes(task->num_inlined_bytecodes()); 1929 event->commit(); 1930 } 1931 #endif 1932 1933 // ------------------------------------------------------------------ 1934 // CompileBroker::invoke_compiler_on_method 1935 // 1936 // Compile a method. 1937 // 1938 void CompileBroker::invoke_compiler_on_method(CompileTask* task) { 1939 if (PrintCompilation) { 1940 ResourceMark rm; 1941 task->print_line(); 1942 } 1943 elapsedTimer time; 1944 1945 CompilerThread* thread = CompilerThread::current(); 1946 ResourceMark rm(thread); 1947 1948 if (LogEvents) { 1949 _compilation_log->log_compile(thread, task); 1950 } 1951 1990 1991 ciEnv ci_env(task, system_dictionary_modification_counter); 1992 if (should_break) { 1993 ci_env.set_break_at_compile(true); 1994 } 1995 if (should_log) { 1996 ci_env.set_log(thread->log()); 1997 } 1998 assert(thread->env() == &ci_env, "set by ci_env"); 1999 // The thread-env() field is cleared in ~CompileTaskWrapper. 2000 2001 // Cache Jvmti state 2002 ci_env.cache_jvmti_state(); 2003 2004 // Cache DTrace flags 2005 ci_env.cache_dtrace_flags(); 2006 2007 ciMethod* target = ci_env.get_method_from_handle(target_handle); 2008 2009 TraceTime t1("compilation", &time); 2010 #if INCLUDE_JFR 2011 EventCompilation event; 2012 #endif 2013 2014 AbstractCompiler *comp = compiler(task_level); 2015 if (comp == NULL) { 2016 ci_env.record_method_not_compilable("no compiler", !TieredCompilation); 2017 } else { 2018 comp->compile_method(&ci_env, target, osr_bci); 2019 } 2020 2021 if (!ci_env.failing() && task->code() == NULL) { 2022 //assert(false, "compiler should always document failure"); 2023 // The compiler elected, without comment, not to register a result. 2024 // Do not attempt further compilations of this method. 2025 ci_env.record_method_not_compilable("compile failed", !TieredCompilation); 2026 } 2027 2028 // Copy this bit to the enclosing block: 2029 compilable = ci_env.compilable(); 2030 2031 if (ci_env.failing()) { 2032 const char *failure_reason = ci_env.failure_reason(); 2033 const char* retry_message = ci_env.retry_message(); 2034 task->set_failure_reason(failure_reason); 2035 if (_compilation_log != NULL) { 2036 _compilation_log->log_failure(thread, task, ci_env.failure_reason(), retry_message); 2037 } 2038 if (PrintCompilation) { 2039 FormatBufferResource msg = retry_message != NULL ? 2040 err_msg_res("COMPILE SKIPPED: %s (%s)", ci_env.failure_reason(), retry_message) : 2041 err_msg_res("COMPILE SKIPPED: %s", ci_env.failure_reason()); 2042 task->print_compilation(tty, msg); 2043 } 2044 2045 #if INCLUDE_JFR 2046 EventCompilationFailure event; 2047 if (event.should_commit()) { 2048 event.set_compileId(compile_id); 2049 event.set_failureMessage(failure_reason); 2050 event.commit(); 2051 } 2052 #endif 2053 } else { 2054 task->mark_success(); 2055 task->set_num_inlined_bytecodes(ci_env.num_inlined_bytecodes()); 2056 if (_compilation_log != NULL) { 2057 nmethod* code = task->code(); 2058 if (code != NULL) { 2059 _compilation_log->log_nmethod(thread, code); 2060 } 2061 } 2062 } 2063 // simulate crash during compilation 2064 assert(task->compile_id() != CICrashAt, "just as planned"); 2065 #if INCLUDE_JFR 2066 if (event.should_commit()) { 2067 post_compilation_event(&event, task); 2068 } 2069 #endif 2070 } 2071 pop_jni_handle_block(); 2072 2073 methodHandle method(thread, task->method()); 2074 2075 DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success()); 2076 2077 collect_statistics(thread, time, task); 2078 2079 if (PrintCompilation && PrintCompilation2) { 2080 tty->print("%7d ", (int) tty->time_stamp().milliseconds()); // print timestamp 2081 tty->print("%4d ", compile_id); // print compilation number 2082 tty->print("%s ", (is_osr ? "%" : " ")); 2083 if (task->code() != NULL) { 2084 tty->print("size: %d(%d) ", task->code()->total_size(), task->code()->insts_size()); 2085 } 2086 tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes()); 2087 } 2088 2089 if (PrintCodeCacheOnCompilation) |