src/share/vm/compiler/compileBroker.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/compiler

src/share/vm/compiler/compileBroker.cpp

Print this page
rev 9032 : 8137167: JEP165: Compiler Control: Implementation task
Summary: Compiler Control JEP
Reviewed-by: roland, twisti


  12  * version 2 for more details (a copy is included in the LICENSE file that
  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 "prims/whitebox.hpp"
  39 #include "runtime/arguments.hpp"
  40 #include "runtime/atomic.inline.hpp"
  41 #include "runtime/compilationPolicy.hpp"
  42 #include "runtime/init.hpp"
  43 #include "runtime/interfaceSupport.hpp"
  44 #include "runtime/javaCalls.hpp"
  45 #include "runtime/os.hpp"
  46 #include "runtime/sharedRuntime.hpp"
  47 #include "runtime/sweeper.hpp"
  48 #include "trace/tracing.hpp"
  49 #include "utilities/dtrace.hpp"
  50 #include "utilities/events.hpp"
  51 #ifdef COMPILER1


 180     StringLogMessage lm;
 181     lm.print("%4d   COMPILE SKIPPED: %s", task->compile_id(), reason);
 182     if (retry_message != NULL) {
 183       lm.append(" (%s)", retry_message);
 184     }
 185     lm.print("\n");
 186     log(thread, "%s", (const char*)lm);
 187   }
 188 
 189   void log_metaspace_failure(const char* reason) {
 190     ResourceMark rm;
 191     StringLogMessage lm;
 192     lm.print("%4d   COMPILE PROFILING SKIPPED: %s", -1, reason);
 193     lm.print("\n");
 194     log(JavaThread::current(), "%s", (const char*)lm);
 195   }
 196 };
 197 
 198 static CompilationLog* _compilation_log = NULL;
 199 
 200 void compileBroker_init() {
 201   if (LogEvents) {
 202     _compilation_log = new CompilationLog();
 203   }








 204 }
 205 
 206 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) {
 207   CompilerThread* thread = CompilerThread::current();
 208   thread->set_task(task);
 209   CompileLog*     log  = thread->log();
 210   if (log != NULL)  task->log_task_start(log);
 211 }
 212 
 213 CompileTaskWrapper::~CompileTaskWrapper() {
 214   CompilerThread* thread = CompilerThread::current();
 215   CompileTask* task = thread->task();
 216   CompileLog*  log  = thread->log();
 217   if (log != NULL)  task->log_task_done(log);
 218   thread->set_task(NULL);
 219   task->set_code_handle(NULL);
 220   thread->set_env(NULL);
 221   if (task->is_blocking()) {
 222     MutexLocker notifier(task->lock(), thread);
 223     task->mark_complete();


1126 //
1127 // See if this compilation is not allowed.
1128 bool CompileBroker::compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level) {
1129   bool is_native = method->is_native();
1130   // Some compilers may not support the compilation of natives.
1131   AbstractCompiler *comp = compiler(comp_level);
1132   if (is_native &&
1133       (!CICompileNatives || comp == NULL || !comp->supports_native())) {
1134     method->set_not_compilable_quietly(comp_level);
1135     return true;
1136   }
1137 
1138   bool is_osr = (osr_bci != standard_entry_bci);
1139   // Some compilers may not support on stack replacement.
1140   if (is_osr &&
1141       (!CICompileOSR || comp == NULL || !comp->supports_osr())) {
1142     method->set_not_osr_compilable(comp_level);
1143     return true;
1144   }
1145 





1146   // The method may be explicitly excluded by the user.
1147   bool quietly;
1148   double scale;
1149   if (CompilerOracle::should_exclude(method, quietly)
1150       || (CompilerOracle::has_option_value(method, "CompileThresholdScaling", scale) && scale == 0)) {
1151     if (!quietly) {
1152       // This does not happen quietly...
1153       ResourceMark rm;
1154       tty->print("### Excluding %s:%s",
1155                  method->is_native() ? "generation of native wrapper" : "compile",
1156                  (method->is_static() ? " static" : ""));
1157       method->print_short_name(tty);
1158       tty->cr();
1159     }
1160     method->set_not_compilable(CompLevel_all, !quietly, "excluded by CompileCommand");
1161   }
1162 
1163   return false;
1164 }
1165 
1166 /**
1167  * Generate serialized IDs for compilation requests. If certain debugging flags are used
1168  * and the ID is not within the specified range, the method is not compiled and 0 is returned.
1169  * The function also allows to generate separate compilation IDs for OSR compilations.
1170  */
1171 int CompileBroker::assign_compile_id(methodHandle method, int osr_bci) {
1172 #ifdef ASSERT
1173   bool is_osr = (osr_bci != standard_entry_bci);
1174   int id;
1175   if (method->is_native()) {
1176     assert(!is_osr, "can't be osr");
1177     // Adapters, native wrappers and method handle intrinsics
1178     // should be generated always.
1179     return Atomic::add(1, &_compilation_id);
1180   } else if (CICountOSR && is_osr) {


1294 
1295   int system_dictionary_modification_counter;
1296   {
1297     MutexLocker locker(Compile_lock, thread);
1298     system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
1299   }
1300 
1301   {
1302     // Must switch to native to allocate ci_env
1303     ThreadToNativeFromVM ttn(thread);
1304     ciEnv ci_env(NULL, system_dictionary_modification_counter);
1305     // Cache Jvmti state
1306     ci_env.cache_jvmti_state();
1307     // Cache DTrace flags
1308     ci_env.cache_dtrace_flags();
1309 
1310     // Switch back to VM state to do compiler initialization
1311     ThreadInVMfromNative tv(thread);
1312     ResetNoHandleMark rnhm;
1313 
1314 
1315     if (!comp->is_shark()) {
1316       // Perform per-thread and global initializations
1317       comp->initialize();
1318     }
1319   }
1320 
1321   if (comp->is_failed()) {
1322     disable_compilation_forever();
1323     // If compiler initialization failed, no compiler thread that is specific to a
1324     // particular compiler runtime will ever start to compile methods.
1325     shutdown_compiler_runtime(comp, thread);
1326     return false;
1327   }
1328 
1329   // C1 specific check
1330   if (comp->is_c1() && (thread->get_buffer_blob() == NULL)) {
1331     warning("Initialization of %s thread failed (no space to run compilers)", thread->name());
1332     return false;
1333   }
1334 


1541       tty->print_cr("compiler thread " INTPTR_FORMAT " poll detects block request", p2i(Thread::current()));
1542 #endif
1543     ThreadInVMfromNative tivfn(JavaThread::current());
1544   }
1545 }
1546 
1547 // wrapper for CodeCache::print_summary()
1548 static void codecache_print(bool detailed)
1549 {
1550   ResourceMark rm;
1551   stringStream s;
1552   // Dump code cache  into a buffer before locking the tty,
1553   {
1554     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1555     CodeCache::print_summary(&s, detailed);
1556   }
1557   ttyLocker ttyl;
1558   tty->print("%s", s.as_string());
1559 }
1560 




1561 // ------------------------------------------------------------------
1562 // CompileBroker::invoke_compiler_on_method
1563 //
1564 // Compile a method.
1565 //
1566 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
1567   if (PrintCompilation) {
1568     ResourceMark rm;
1569     task->print_tty();
1570   }
1571   elapsedTimer time;
1572 
1573   CompilerThread* thread = CompilerThread::current();
1574   ResourceMark rm(thread);
1575 
1576   if (LogEvents) {
1577     _compilation_log->log_compile(thread, task);
1578   }
1579 
1580   // Common flags.
1581   uint compile_id = task->compile_id();
1582   int osr_bci = task->osr_bci();
1583   bool is_osr = (osr_bci != standard_entry_bci);
1584   bool should_log = (thread->log() != NULL);
1585   bool should_break = false;
1586   int task_level = task->comp_level();








1587   {
1588     // create the handle inside it's own block so it can't
1589     // accidentally be referenced once the thread transitions to
1590     // native.  The NoHandleMark before the transition should catch
1591     // any cases where this occurs in the future.
1592     methodHandle method(thread, task->method());
1593     should_break = check_break_at(method, compile_id, is_osr);
1594     if (should_log && !CompilerOracle::should_log(method)) {
1595       should_log = false;
1596     }
1597     assert(!method->is_native(), "no longer compile natives");
1598 
1599     // Save information about this method in case of failure.
1600     set_last_compile(thread, method, is_osr, task_level);
1601 
1602     DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, compiler_name(task_level));
1603   }
1604 
1605   // Allocate a new set of JNI handles.
1606   push_jni_handle_block();
1607   Method* target_handle = task->method();
1608   int compilable = ciEnv::MethodCompilable;
1609   {
1610     int system_dictionary_modification_counter;
1611     {
1612       MutexLocker locker(Compile_lock, thread);
1613       system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
1614     }
1615 
1616     NoHandleMark  nhm;


1630     ci_env.cache_jvmti_state();
1631 
1632     // Cache DTrace flags
1633     ci_env.cache_dtrace_flags();
1634 
1635     ciMethod* target = ci_env.get_method_from_handle(target_handle);
1636 
1637     TraceTime t1("compilation", &time);
1638     EventCompilation event;
1639 
1640     AbstractCompiler *comp = compiler(task_level);
1641     if (comp == NULL) {
1642       ci_env.record_method_not_compilable("no compiler", !TieredCompilation);
1643     } else {
1644       if (WhiteBoxAPI && WhiteBox::compilation_locked) {
1645         MonitorLockerEx locker(Compilation_lock, Mutex::_no_safepoint_check_flag);
1646         while (WhiteBox::compilation_locked) {
1647           locker.wait(Mutex::_no_safepoint_check_flag);
1648         }
1649       }
1650       comp->compile_method(&ci_env, target, osr_bci);
1651     }
1652 
1653     if (!ci_env.failing() && task->code() == NULL) {
1654       //assert(false, "compiler should always document failure");
1655       // The compiler elected, without comment, not to register a result.
1656       // Do not attempt further compilations of this method.
1657       ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
1658     }
1659 
1660     // Copy this bit to the enclosing block:
1661     compilable = ci_env.compilable();
1662 
1663     if (ci_env.failing()) {
1664       task->set_failure_reason(ci_env.failure_reason());
1665       ci_env.report_failure(ci_env.failure_reason());
1666       const char* retry_message = ci_env.retry_message();
1667       if (_compilation_log != NULL) {
1668         _compilation_log->log_failure(thread, task, ci_env.failure_reason(), retry_message);
1669       }
1670       if (PrintCompilation) {


1679       if (_compilation_log != NULL) {
1680         nmethod* code = task->code();
1681         if (code != NULL) {
1682           _compilation_log->log_nmethod(thread, code);
1683         }
1684       }
1685     }
1686     // simulate crash during compilation
1687     assert(task->compile_id() != CICrashAt, "just as planned");
1688     if (event.should_commit()) {
1689       event.set_method(target->get_Method());
1690       event.set_compileID(compile_id);
1691       event.set_compileLevel(task->comp_level());
1692       event.set_succeded(task->is_success());
1693       event.set_isOsr(is_osr);
1694       event.set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size());
1695       event.set_inlinedBytes(task->num_inlined_bytecodes());
1696       event.commit();
1697     }
1698   }

1699   pop_jni_handle_block();
1700 
1701   methodHandle method(thread, task->method());
1702 
1703   DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success());
1704 
1705   collect_statistics(thread, time, task);
1706 
1707   if (PrintCompilation && PrintCompilation2) {
1708     tty->print("%7d ", (int) tty->time_stamp().milliseconds());  // print timestamp
1709     tty->print("%4d ", compile_id);    // print compilation number
1710     tty->print("%s ", (is_osr ? "%" : " "));
1711     if (task->code() != NULL) {
1712       tty->print("size: %d(%d) ", task->code()->total_size(), task->code()->insts_size());
1713     }
1714     tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes());
1715   }
1716 
1717   if (PrintCodeCacheOnCompilation)
1718     codecache_print(/* detailed= */ false);


1864   compile_handles->set_pop_frame_link(java_handles);  // make sure java handles get gc'd.
1865   thread->set_active_handles(compile_handles);
1866 }
1867 
1868 
1869 // ------------------------------------------------------------------
1870 // CompileBroker::pop_jni_handle_block
1871 //
1872 // Pop off the current block of JNI handles.
1873 void CompileBroker::pop_jni_handle_block() {
1874   JavaThread* thread = JavaThread::current();
1875 
1876   // Release our JNI handle block
1877   JNIHandleBlock* compile_handles = thread->active_handles();
1878   JNIHandleBlock* java_handles = compile_handles->pop_frame_link();
1879   thread->set_active_handles(java_handles);
1880   compile_handles->set_pop_frame_link(NULL);
1881   JNIHandleBlock::release_block(compile_handles, thread); // may block
1882 }
1883 
1884 
1885 // ------------------------------------------------------------------
1886 // CompileBroker::check_break_at
1887 //
1888 // Should the compilation break at the current compilation.
1889 bool CompileBroker::check_break_at(methodHandle method, int compile_id, bool is_osr) {
1890   if (CICountOSR && is_osr && (compile_id == CIBreakAtOSR)) {
1891     return true;
1892   } else if( CompilerOracle::should_break_at(method) ) { // break when compiling
1893     return true;
1894   } else {
1895     return (compile_id == CIBreakAt);
1896   }
1897 }
1898 
1899 // ------------------------------------------------------------------
1900 // CompileBroker::collect_statistics
1901 //
1902 // Collect statistics about the compilation.
1903 
1904 void CompileBroker::collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task) {
1905   bool success = task->is_success();
1906   methodHandle method (thread, task->method());
1907   uint compile_id = task->compile_id();
1908   bool is_osr = (task->osr_bci() != standard_entry_bci);
1909   nmethod* code = task->code();
1910   CompilerCounters* counters = thread->counters();
1911 
1912   assert(code == NULL || code->is_locked_by_vm(), "will survive the MutexLocker");
1913   MutexLocker locker(CompileStatistics_lock);
1914 
1915   // _perf variables are production performance counters which are
1916   // updated regardless of the setting of the CITime and CITimeEach flags
1917   //
1918 


2058        compiler(_last_compile_level) != NULL &&
2059        _last_method_compiled != NULL &&
2060        _last_compile_type != no_compile) {
2061     if (_last_compile_type == osr_compile) {
2062       tty->print_cr("Last parse:  [osr]%d+++(%d) %s",
2063                     _osr_compilation_id, _last_compile_level, _last_method_compiled);
2064     } else {
2065       tty->print_cr("Last parse:  %d+++(%d) %s",
2066                     _compilation_id, _last_compile_level, _last_method_compiled);
2067     }
2068   }
2069 }
2070 
2071 
2072 void CompileBroker::print_compiler_threads_on(outputStream* st) {
2073 #ifndef PRODUCT
2074   st->print_cr("Compiler thread printing unimplemented.");
2075   st->cr();
2076 #endif
2077 }



  12  * version 2 for more details (a copy is included in the LICENSE file that
  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 "compiler/directivesParser.hpp"
  33 #include "interpreter/linkResolver.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 "prims/whitebox.hpp"
  40 #include "runtime/arguments.hpp"
  41 #include "runtime/atomic.inline.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 "trace/tracing.hpp"
  50 #include "utilities/dtrace.hpp"
  51 #include "utilities/events.hpp"
  52 #ifdef COMPILER1


 181     StringLogMessage lm;
 182     lm.print("%4d   COMPILE SKIPPED: %s", task->compile_id(), reason);
 183     if (retry_message != NULL) {
 184       lm.append(" (%s)", retry_message);
 185     }
 186     lm.print("\n");
 187     log(thread, "%s", (const char*)lm);
 188   }
 189 
 190   void log_metaspace_failure(const char* reason) {
 191     ResourceMark rm;
 192     StringLogMessage lm;
 193     lm.print("%4d   COMPILE PROFILING SKIPPED: %s", -1, reason);
 194     lm.print("\n");
 195     log(JavaThread::current(), "%s", (const char*)lm);
 196   }
 197 };
 198 
 199 static CompilationLog* _compilation_log = NULL;
 200 
 201 bool compileBroker_init() {
 202   if (LogEvents) {
 203     _compilation_log = new CompilationLog();
 204   }
 205 
 206   // init directives stack, adding default directive
 207   DirectivesStack::init();
 208 
 209   if (DirectivesParser::has_file()) {
 210     return DirectivesParser::parse_from_flag();
 211   }
 212   return true;
 213 }
 214 
 215 CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) {
 216   CompilerThread* thread = CompilerThread::current();
 217   thread->set_task(task);
 218   CompileLog*     log  = thread->log();
 219   if (log != NULL)  task->log_task_start(log);
 220 }
 221 
 222 CompileTaskWrapper::~CompileTaskWrapper() {
 223   CompilerThread* thread = CompilerThread::current();
 224   CompileTask* task = thread->task();
 225   CompileLog*  log  = thread->log();
 226   if (log != NULL)  task->log_task_done(log);
 227   thread->set_task(NULL);
 228   task->set_code_handle(NULL);
 229   thread->set_env(NULL);
 230   if (task->is_blocking()) {
 231     MutexLocker notifier(task->lock(), thread);
 232     task->mark_complete();


1135 //
1136 // See if this compilation is not allowed.
1137 bool CompileBroker::compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level) {
1138   bool is_native = method->is_native();
1139   // Some compilers may not support the compilation of natives.
1140   AbstractCompiler *comp = compiler(comp_level);
1141   if (is_native &&
1142       (!CICompileNatives || comp == NULL || !comp->supports_native())) {
1143     method->set_not_compilable_quietly(comp_level);
1144     return true;
1145   }
1146 
1147   bool is_osr = (osr_bci != standard_entry_bci);
1148   // Some compilers may not support on stack replacement.
1149   if (is_osr &&
1150       (!CICompileOSR || comp == NULL || !comp->supports_osr())) {
1151     method->set_not_osr_compilable(comp_level);
1152     return true;
1153   }
1154 
1155   // Breaking the abstraction - directives are only used inside a compilation otherwise.
1156   DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, comp);
1157   bool excluded = directive->ExcludeOption;
1158   DirectivesStack::release(directive);
1159 
1160   // The method may be explicitly excluded by the user.

1161   double scale;
1162   if (excluded || (CompilerOracle::has_option_value(method, "CompileThresholdScaling", scale) && scale == 0)) {
1163     bool quietly = CompilerOracle::should_exclude_quietly();
1164     if (!quietly) {
1165       // This does not happen quietly...
1166       ResourceMark rm;
1167       tty->print("### Excluding %s:%s",
1168                  method->is_native() ? "generation of native wrapper" : "compile",
1169                  (method->is_static() ? " static" : ""));
1170       method->print_short_name(tty);
1171       tty->cr();
1172     }
1173     method->set_not_compilable(comp_level, !quietly, "excluded by CompileCommand");
1174   }
1175 
1176   return false;
1177 }
1178 
1179 /**
1180  * Generate serialized IDs for compilation requests. If certain debugging flags are used
1181  * and the ID is not within the specified range, the method is not compiled and 0 is returned.
1182  * The function also allows to generate separate compilation IDs for OSR compilations.
1183  */
1184 int CompileBroker::assign_compile_id(methodHandle method, int osr_bci) {
1185 #ifdef ASSERT
1186   bool is_osr = (osr_bci != standard_entry_bci);
1187   int id;
1188   if (method->is_native()) {
1189     assert(!is_osr, "can't be osr");
1190     // Adapters, native wrappers and method handle intrinsics
1191     // should be generated always.
1192     return Atomic::add(1, &_compilation_id);
1193   } else if (CICountOSR && is_osr) {


1307 
1308   int system_dictionary_modification_counter;
1309   {
1310     MutexLocker locker(Compile_lock, thread);
1311     system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
1312   }
1313 
1314   {
1315     // Must switch to native to allocate ci_env
1316     ThreadToNativeFromVM ttn(thread);
1317     ciEnv ci_env(NULL, system_dictionary_modification_counter);
1318     // Cache Jvmti state
1319     ci_env.cache_jvmti_state();
1320     // Cache DTrace flags
1321     ci_env.cache_dtrace_flags();
1322 
1323     // Switch back to VM state to do compiler initialization
1324     ThreadInVMfromNative tv(thread);
1325     ResetNoHandleMark rnhm;
1326 

1327     if (!comp->is_shark()) {
1328       // Perform per-thread and global initializations
1329       comp->initialize();
1330     }
1331   }
1332 
1333   if (comp->is_failed()) {
1334     disable_compilation_forever();
1335     // If compiler initialization failed, no compiler thread that is specific to a
1336     // particular compiler runtime will ever start to compile methods.
1337     shutdown_compiler_runtime(comp, thread);
1338     return false;
1339   }
1340 
1341   // C1 specific check
1342   if (comp->is_c1() && (thread->get_buffer_blob() == NULL)) {
1343     warning("Initialization of %s thread failed (no space to run compilers)", thread->name());
1344     return false;
1345   }
1346 


1553       tty->print_cr("compiler thread " INTPTR_FORMAT " poll detects block request", p2i(Thread::current()));
1554 #endif
1555     ThreadInVMfromNative tivfn(JavaThread::current());
1556   }
1557 }
1558 
1559 // wrapper for CodeCache::print_summary()
1560 static void codecache_print(bool detailed)
1561 {
1562   ResourceMark rm;
1563   stringStream s;
1564   // Dump code cache  into a buffer before locking the tty,
1565   {
1566     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1567     CodeCache::print_summary(&s, detailed);
1568   }
1569   ttyLocker ttyl;
1570   tty->print("%s", s.as_string());
1571 }
1572 
1573 int DirectivesStack::_depth = 0;
1574 CompilerDirectives* DirectivesStack::_top = NULL;
1575 CompilerDirectives* DirectivesStack::_bottom = NULL;
1576 
1577 // ------------------------------------------------------------------
1578 // CompileBroker::invoke_compiler_on_method
1579 //
1580 // Compile a method.
1581 //
1582 void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
1583   if (PrintCompilation) {
1584     ResourceMark rm;
1585     task->print_tty();
1586   }
1587   elapsedTimer time;
1588 
1589   CompilerThread* thread = CompilerThread::current();
1590   ResourceMark rm(thread);
1591 
1592   if (LogEvents) {
1593     _compilation_log->log_compile(thread, task);
1594   }
1595 
1596   // Common flags.
1597   uint compile_id = task->compile_id();
1598   int osr_bci = task->osr_bci();
1599   bool is_osr = (osr_bci != standard_entry_bci);
1600   bool should_log = (thread->log() != NULL);
1601   bool should_break = false;
1602   int task_level = task->comp_level();
1603 
1604   // Look up matching directives
1605   DirectiveSet* directive = DirectivesStack::getMatchingDirective(task->method(), compiler(task_level));
1606 
1607   should_break = directive->BreakAtExecuteOption || task->check_break_at_flags();
1608   if (should_log && !directive->LogOption) {
1609     should_log = false;
1610   }
1611   {
1612     // create the handle inside it's own block so it can't
1613     // accidentally be referenced once the thread transitions to
1614     // native.  The NoHandleMark before the transition should catch
1615     // any cases where this occurs in the future.
1616     methodHandle method(thread, task->method());




1617     assert(!method->is_native(), "no longer compile natives");
1618 
1619     // Save information about this method in case of failure.
1620     set_last_compile(thread, method, is_osr, task_level);
1621 
1622     DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, compiler_name(task_level));
1623   }
1624 
1625   // Allocate a new set of JNI handles.
1626   push_jni_handle_block();
1627   Method* target_handle = task->method();
1628   int compilable = ciEnv::MethodCompilable;
1629   {
1630     int system_dictionary_modification_counter;
1631     {
1632       MutexLocker locker(Compile_lock, thread);
1633       system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
1634     }
1635 
1636     NoHandleMark  nhm;


1650     ci_env.cache_jvmti_state();
1651 
1652     // Cache DTrace flags
1653     ci_env.cache_dtrace_flags();
1654 
1655     ciMethod* target = ci_env.get_method_from_handle(target_handle);
1656 
1657     TraceTime t1("compilation", &time);
1658     EventCompilation event;
1659 
1660     AbstractCompiler *comp = compiler(task_level);
1661     if (comp == NULL) {
1662       ci_env.record_method_not_compilable("no compiler", !TieredCompilation);
1663     } else {
1664       if (WhiteBoxAPI && WhiteBox::compilation_locked) {
1665         MonitorLockerEx locker(Compilation_lock, Mutex::_no_safepoint_check_flag);
1666         while (WhiteBox::compilation_locked) {
1667           locker.wait(Mutex::_no_safepoint_check_flag);
1668         }
1669       }
1670       comp->compile_method(&ci_env, target, osr_bci, directive);
1671     }
1672 
1673     if (!ci_env.failing() && task->code() == NULL) {
1674       //assert(false, "compiler should always document failure");
1675       // The compiler elected, without comment, not to register a result.
1676       // Do not attempt further compilations of this method.
1677       ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
1678     }
1679 
1680     // Copy this bit to the enclosing block:
1681     compilable = ci_env.compilable();
1682 
1683     if (ci_env.failing()) {
1684       task->set_failure_reason(ci_env.failure_reason());
1685       ci_env.report_failure(ci_env.failure_reason());
1686       const char* retry_message = ci_env.retry_message();
1687       if (_compilation_log != NULL) {
1688         _compilation_log->log_failure(thread, task, ci_env.failure_reason(), retry_message);
1689       }
1690       if (PrintCompilation) {


1699       if (_compilation_log != NULL) {
1700         nmethod* code = task->code();
1701         if (code != NULL) {
1702           _compilation_log->log_nmethod(thread, code);
1703         }
1704       }
1705     }
1706     // simulate crash during compilation
1707     assert(task->compile_id() != CICrashAt, "just as planned");
1708     if (event.should_commit()) {
1709       event.set_method(target->get_Method());
1710       event.set_compileID(compile_id);
1711       event.set_compileLevel(task->comp_level());
1712       event.set_succeded(task->is_success());
1713       event.set_isOsr(is_osr);
1714       event.set_codeSize((task->code() == NULL) ? 0 : task->code()->total_size());
1715       event.set_inlinedBytes(task->num_inlined_bytecodes());
1716       event.commit();
1717     }
1718   }
1719   DirectivesStack::release(directive);
1720   pop_jni_handle_block();
1721 
1722   methodHandle method(thread, task->method());
1723 
1724   DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success());
1725 
1726   collect_statistics(thread, time, task);
1727 
1728   if (PrintCompilation && PrintCompilation2) {
1729     tty->print("%7d ", (int) tty->time_stamp().milliseconds());  // print timestamp
1730     tty->print("%4d ", compile_id);    // print compilation number
1731     tty->print("%s ", (is_osr ? "%" : " "));
1732     if (task->code() != NULL) {
1733       tty->print("size: %d(%d) ", task->code()->total_size(), task->code()->insts_size());
1734     }
1735     tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes());
1736   }
1737 
1738   if (PrintCodeCacheOnCompilation)
1739     codecache_print(/* detailed= */ false);


1885   compile_handles->set_pop_frame_link(java_handles);  // make sure java handles get gc'd.
1886   thread->set_active_handles(compile_handles);
1887 }
1888 
1889 
1890 // ------------------------------------------------------------------
1891 // CompileBroker::pop_jni_handle_block
1892 //
1893 // Pop off the current block of JNI handles.
1894 void CompileBroker::pop_jni_handle_block() {
1895   JavaThread* thread = JavaThread::current();
1896 
1897   // Release our JNI handle block
1898   JNIHandleBlock* compile_handles = thread->active_handles();
1899   JNIHandleBlock* java_handles = compile_handles->pop_frame_link();
1900   thread->set_active_handles(java_handles);
1901   compile_handles->set_pop_frame_link(NULL);
1902   JNIHandleBlock::release_block(compile_handles, thread); // may block
1903 }
1904 















1905 // ------------------------------------------------------------------
1906 // CompileBroker::collect_statistics
1907 //
1908 // Collect statistics about the compilation.
1909 
1910 void CompileBroker::collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task) {
1911   bool success = task->is_success();
1912   methodHandle method (thread, task->method());
1913   uint compile_id = task->compile_id();
1914   bool is_osr = (task->osr_bci() != standard_entry_bci);
1915   nmethod* code = task->code();
1916   CompilerCounters* counters = thread->counters();
1917 
1918   assert(code == NULL || code->is_locked_by_vm(), "will survive the MutexLocker");
1919   MutexLocker locker(CompileStatistics_lock);
1920 
1921   // _perf variables are production performance counters which are
1922   // updated regardless of the setting of the CITime and CITimeEach flags
1923   //
1924 


2064        compiler(_last_compile_level) != NULL &&
2065        _last_method_compiled != NULL &&
2066        _last_compile_type != no_compile) {
2067     if (_last_compile_type == osr_compile) {
2068       tty->print_cr("Last parse:  [osr]%d+++(%d) %s",
2069                     _osr_compilation_id, _last_compile_level, _last_method_compiled);
2070     } else {
2071       tty->print_cr("Last parse:  %d+++(%d) %s",
2072                     _compilation_id, _last_compile_level, _last_method_compiled);
2073     }
2074   }
2075 }
2076 
2077 
2078 void CompileBroker::print_compiler_threads_on(outputStream* st) {
2079 #ifndef PRODUCT
2080   st->print_cr("Compiler thread printing unimplemented.");
2081   st->cr();
2082 #endif
2083 }
2084 
src/share/vm/compiler/compileBroker.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File