< prev index next >

src/share/vm/compiler/compileBroker.cpp

Print this page




  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,


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 // ------------------------------------------------------------------
1917 // CompileBroker::invoke_compiler_on_method
1918 //
1919 // Compile a method.
1920 //
1921 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
1922   if (PrintCompilation) {
1923     ResourceMark rm;
1924     task->print_line();
1925   }
1926   elapsedTimer time;
1927 
1928   CompilerThread* thread = CompilerThread::current();
1929   ResourceMark rm(thread);
1930 
1931   if (LogEvents) {
1932     _compilation_log->log_compile(thread, task);
1933   }
1934 
1935   // Common flags.


1993     EventCompilation event;
1994 
1995     AbstractCompiler *comp = compiler(task_level);
1996     if (comp == NULL) {
1997       ci_env.record_method_not_compilable("no compiler", !TieredCompilation);
1998     } else {
1999       comp->compile_method(&ci_env, target, osr_bci);
2000     }
2001 
2002     if (!ci_env.failing() && task->code() == NULL) {
2003       //assert(false, "compiler should always document failure");
2004       // The compiler elected, without comment, not to register a result.
2005       // Do not attempt further compilations of this method.
2006       ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
2007     }
2008 
2009     // Copy this bit to the enclosing block:
2010     compilable = ci_env.compilable();
2011 
2012     if (ci_env.failing()) {
2013       task->set_failure_reason(ci_env.failure_reason());
2014       const char* retry_message = ci_env.retry_message();

2015       if (_compilation_log != NULL) {
2016         _compilation_log->log_failure(thread, task, ci_env.failure_reason(), retry_message);
2017       }
2018       if (PrintCompilation) {
2019         FormatBufferResource msg = retry_message != NULL ?
2020             err_msg_res("COMPILE SKIPPED: %s (%s)", ci_env.failure_reason(), retry_message) :
2021             err_msg_res("COMPILE SKIPPED: %s",      ci_env.failure_reason());
2022         task->print_compilation(tty, msg);
2023       }







2024     } else {
2025       task->mark_success();
2026       task->set_num_inlined_bytecodes(ci_env.num_inlined_bytecodes());
2027       if (_compilation_log != NULL) {
2028         nmethod* code = task->code();
2029         if (code != NULL) {
2030           _compilation_log->log_nmethod(thread, code);
2031         }
2032       }
2033     }
2034     // simulate crash during compilation
2035     assert(task->compile_id() != CICrashAt, "just as planned");
2036     if (event.should_commit()) {
2037       event.set_method(target->get_Method());
2038       event.set_compileID(compile_id);
2039       event.set_compileLevel(task->comp_level());
2040       event.set_succeded(task->is_success());
2041       event.set_isOsr(is_osr);
2042       event.set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size());
2043       event.set_inlinedBytes(task->num_inlined_bytecodes());
2044       event.commit();
2045     }
2046   }
2047   pop_jni_handle_block();
2048 
2049   methodHandle method(thread, task->method());
2050 
2051   DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success());
2052 
2053   collect_statistics(thread, time, task);
2054 
2055   if (PrintCompilation && PrintCompilation2) {
2056     tty->print("%7d ", (int) tty->time_stamp().milliseconds());  // print timestamp
2057     tty->print("%4d ", compile_id);    // print compilation number
2058     tty->print("%s ", (is_osr ? "%" : " "));
2059     if (task->code() != NULL) {
2060       tty->print("size: %d(%d) ", task->code()->total_size(), task->code()->insts_size());
2061     }
2062     tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes());
2063   }
2064 




  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,


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 
1948   // Common flags.


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 


< prev index next >