1238
1239 // Breaking the abstraction - directives are only used inside a compilation otherwise.
1240 DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, comp);
1241 bool excluded = directive->ExcludeOption;
1242 DirectivesStack::release(directive);
1243
1244 // The method may be explicitly excluded by the user.
1245 double scale;
1246 if (excluded || (CompilerOracle::has_option_value(method, "CompileThresholdScaling", scale) && scale == 0)) {
1247 bool quietly = CompilerOracle::should_exclude_quietly();
1248 if (PrintCompilation && !quietly) {
1249 // This does not happen quietly...
1250 ResourceMark rm;
1251 tty->print("### Excluding %s:%s",
1252 method->is_native() ? "generation of native wrapper" : "compile",
1253 (method->is_static() ? " static" : ""));
1254 method->print_short_name(tty);
1255 tty->cr();
1256 }
1257 method->set_not_compilable(comp_level, !quietly, "excluded by CompileCommand");
1258 }
1259
1260 return false;
1261 }
1262
1263 /**
1264 * Generate serialized IDs for compilation requests. If certain debugging flags are used
1265 * and the ID is not within the specified range, the method is not compiled and 0 is returned.
1266 * The function also allows to generate separate compilation IDs for OSR compilations.
1267 */
1268 int CompileBroker::assign_compile_id(const methodHandle& method, int osr_bci) {
1269 #ifdef ASSERT
1270 bool is_osr = (osr_bci != standard_entry_bci);
1271 int id;
1272 if (method->is_native()) {
1273 assert(!is_osr, "can't be osr");
1274 // Adapters, native wrappers and method handle intrinsics
1275 // should be generated always.
1276 return Atomic::add(1, &_compilation_id);
1277 } else if (CICountOSR && is_osr) {
1455 /**
1456 * Initialize compiler thread(s) + compiler object(s). The postcondition
1457 * of this function is that the compiler runtimes are initialized and that
1458 * compiler threads can start compiling.
1459 */
1460 bool CompileBroker::init_compiler_runtime() {
1461 CompilerThread* thread = CompilerThread::current();
1462 AbstractCompiler* comp = thread->compiler();
1463 // Final sanity check - the compiler object must exist
1464 guarantee(comp != NULL, "Compiler object must exist");
1465
1466 int system_dictionary_modification_counter;
1467 {
1468 MutexLocker locker(Compile_lock, thread);
1469 system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
1470 }
1471
1472 {
1473 // Must switch to native to allocate ci_env
1474 ThreadToNativeFromVM ttn(thread);
1475 ciEnv ci_env(NULL, system_dictionary_modification_counter);
1476 // Cache Jvmti state
1477 ci_env.cache_jvmti_state();
1478 // Cache DTrace flags
1479 ci_env.cache_dtrace_flags();
1480
1481 // Switch back to VM state to do compiler initialization
1482 ThreadInVMfromNative tv(thread);
1483 ResetNoHandleMark rnhm;
1484
1485 if (!comp->is_shark()) {
1486 // Perform per-thread and global initializations
1487 comp->initialize();
1488 }
1489 }
1490
1491 if (comp->is_failed()) {
1492 disable_compilation_forever();
1493 // If compiler initialization failed, no compiler thread that is specific to a
1494 // particular compiler runtime will ever start to compile methods.
1495 shutdown_compiler_runtime(comp, thread);
1496 return false;
1497 }
1498
1499 // C1 specific check
1500 if (comp->is_c1() && (thread->get_buffer_blob() == NULL)) {
1501 warning("Initialization of %s thread failed (no space to run compilers)", thread->name());
1502 return false;
1503 }
1504
1505 return true;
1506 }
1507
1508 /**
1828 EventCompilation event;
1829
1830 JVMCIEnv env(task, system_dictionary_modification_counter);
1831 methodHandle method(thread, target_handle);
1832 jvmci->compile_method(method, osr_bci, &env);
1833
1834 post_compile(thread, task, event, task->code() != NULL, NULL);
1835
1836 failure_reason = env.failure_reason();
1837 if (!env.retryable()) {
1838 retry_message = "not retryable";
1839 compilable = ciEnv::MethodCompilable_not_at_tier;
1840 }
1841
1842 } else
1843 #endif // INCLUDE_JVMCI
1844 {
1845 NoHandleMark nhm;
1846 ThreadToNativeFromVM ttn(thread);
1847
1848 ciEnv ci_env(task, system_dictionary_modification_counter);
1849 if (should_break) {
1850 ci_env.set_break_at_compile(true);
1851 }
1852 if (should_log) {
1853 ci_env.set_log(thread->log());
1854 }
1855 assert(thread->env() == &ci_env, "set by ci_env");
1856 // The thread-env() field is cleared in ~CompileTaskWrapper.
1857
1858 // Cache Jvmti state
1859 ci_env.cache_jvmti_state();
1860
1861 // Cache DTrace flags
1862 ci_env.cache_dtrace_flags();
1863
1864 ciMethod* target = ci_env.get_method_from_handle(target_handle);
1865
1866 TraceTime t1("compilation", &time);
1867 EventCompilation event;
1868
1869 if (comp == NULL) {
1870 ci_env.record_method_not_compilable("no compiler", !TieredCompilation);
1871 } else {
1872 if (WhiteBoxAPI && WhiteBox::compilation_locked) {
1873 MonitorLockerEx locker(Compilation_lock, Mutex::_no_safepoint_check_flag);
1874 while (WhiteBox::compilation_locked) {
1875 locker.wait(Mutex::_no_safepoint_check_flag);
1876 }
1877 }
1878 comp->compile_method(&ci_env, target, osr_bci, directive);
1879 }
1880
1881 if (!ci_env.failing() && task->code() == NULL) {
1882 //assert(false, "compiler should always document failure");
1883 // The compiler elected, without comment, not to register a result.
1884 // Do not attempt further compilations of this method.
1885 ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
1886 }
1887
1888 // Copy this bit to the enclosing block:
1889 compilable = ci_env.compilable();
1890
1891 if (ci_env.failing()) {
1892 failure_reason = ci_env.failure_reason();
1893 retry_message = ci_env.retry_message();
1894 ci_env.report_failure(failure_reason);
1895 }
1896
1897 post_compile(thread, task, event, !ci_env.failing(), &ci_env);
1898 }
|
1238
1239 // Breaking the abstraction - directives are only used inside a compilation otherwise.
1240 DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, comp);
1241 bool excluded = directive->ExcludeOption;
1242 DirectivesStack::release(directive);
1243
1244 // The method may be explicitly excluded by the user.
1245 double scale;
1246 if (excluded || (CompilerOracle::has_option_value(method, "CompileThresholdScaling", scale) && scale == 0)) {
1247 bool quietly = CompilerOracle::should_exclude_quietly();
1248 if (PrintCompilation && !quietly) {
1249 // This does not happen quietly...
1250 ResourceMark rm;
1251 tty->print("### Excluding %s:%s",
1252 method->is_native() ? "generation of native wrapper" : "compile",
1253 (method->is_static() ? " static" : ""));
1254 method->print_short_name(tty);
1255 tty->cr();
1256 }
1257 method->set_not_compilable(comp_level, !quietly, "excluded by CompileCommand");
1258 return true;
1259 }
1260
1261 return false;
1262 }
1263
1264 /**
1265 * Generate serialized IDs for compilation requests. If certain debugging flags are used
1266 * and the ID is not within the specified range, the method is not compiled and 0 is returned.
1267 * The function also allows to generate separate compilation IDs for OSR compilations.
1268 */
1269 int CompileBroker::assign_compile_id(const methodHandle& method, int osr_bci) {
1270 #ifdef ASSERT
1271 bool is_osr = (osr_bci != standard_entry_bci);
1272 int id;
1273 if (method->is_native()) {
1274 assert(!is_osr, "can't be osr");
1275 // Adapters, native wrappers and method handle intrinsics
1276 // should be generated always.
1277 return Atomic::add(1, &_compilation_id);
1278 } else if (CICountOSR && is_osr) {
1456 /**
1457 * Initialize compiler thread(s) + compiler object(s). The postcondition
1458 * of this function is that the compiler runtimes are initialized and that
1459 * compiler threads can start compiling.
1460 */
1461 bool CompileBroker::init_compiler_runtime() {
1462 CompilerThread* thread = CompilerThread::current();
1463 AbstractCompiler* comp = thread->compiler();
1464 // Final sanity check - the compiler object must exist
1465 guarantee(comp != NULL, "Compiler object must exist");
1466
1467 int system_dictionary_modification_counter;
1468 {
1469 MutexLocker locker(Compile_lock, thread);
1470 system_dictionary_modification_counter = SystemDictionary::number_of_modifications();
1471 }
1472
1473 {
1474 // Must switch to native to allocate ci_env
1475 ThreadToNativeFromVM ttn(thread);
1476 // Matching the default directive, we currently have no method to match.
1477 DirectiveSet* directive = DirectivesStack::getDefaultDirective(CompileBroker::compiler(CompLevel_full_optimization));
1478 ciEnv ci_env(NULL, system_dictionary_modification_counter, directive);
1479 // Cache Jvmti state
1480 ci_env.cache_jvmti_state();
1481 // Cache DTrace flags
1482 ci_env.cache_dtrace_flags();
1483
1484 // Switch back to VM state to do compiler initialization
1485 ThreadInVMfromNative tv(thread);
1486 ResetNoHandleMark rnhm;
1487
1488 if (!comp->is_shark()) {
1489 // Perform per-thread and global initializations
1490 comp->initialize();
1491 }
1492 DirectivesStack::release(directive);
1493 }
1494
1495 if (comp->is_failed()) {
1496 disable_compilation_forever();
1497 // If compiler initialization failed, no compiler thread that is specific to a
1498 // particular compiler runtime will ever start to compile methods.
1499 shutdown_compiler_runtime(comp, thread);
1500 return false;
1501 }
1502
1503 // C1 specific check
1504 if (comp->is_c1() && (thread->get_buffer_blob() == NULL)) {
1505 warning("Initialization of %s thread failed (no space to run compilers)", thread->name());
1506 return false;
1507 }
1508
1509 return true;
1510 }
1511
1512 /**
1832 EventCompilation event;
1833
1834 JVMCIEnv env(task, system_dictionary_modification_counter);
1835 methodHandle method(thread, target_handle);
1836 jvmci->compile_method(method, osr_bci, &env);
1837
1838 post_compile(thread, task, event, task->code() != NULL, NULL);
1839
1840 failure_reason = env.failure_reason();
1841 if (!env.retryable()) {
1842 retry_message = "not retryable";
1843 compilable = ciEnv::MethodCompilable_not_at_tier;
1844 }
1845
1846 } else
1847 #endif // INCLUDE_JVMCI
1848 {
1849 NoHandleMark nhm;
1850 ThreadToNativeFromVM ttn(thread);
1851
1852 ciEnv ci_env(task, system_dictionary_modification_counter, directive);
1853 if (should_break) {
1854 ci_env.set_break_at_compile(true);
1855 }
1856 if (should_log) {
1857 ci_env.set_log(thread->log());
1858 }
1859 assert(thread->env() == &ci_env, "set by ci_env");
1860 // The thread-env() field is cleared in ~CompileTaskWrapper.
1861
1862 // Cache Jvmti state
1863 ci_env.cache_jvmti_state();
1864
1865 // Cache DTrace flags
1866 ci_env.cache_dtrace_flags();
1867
1868 ciMethod* target = ci_env.get_method_from_handle(target_handle);
1869
1870 TraceTime t1("compilation", &time);
1871 EventCompilation event;
1872
1873 if (comp == NULL) {
1874 ci_env.record_method_not_compilable("no compiler", !TieredCompilation);
1875 } else {
1876 if (WhiteBoxAPI && WhiteBox::compilation_locked) {
1877 MonitorLockerEx locker(Compilation_lock, Mutex::_no_safepoint_check_flag);
1878 while (WhiteBox::compilation_locked) {
1879 locker.wait(Mutex::_no_safepoint_check_flag);
1880 }
1881 }
1882 comp->compile_method(&ci_env, target, osr_bci);
1883 }
1884
1885 if (!ci_env.failing() && task->code() == NULL) {
1886 //assert(false, "compiler should always document failure");
1887 // The compiler elected, without comment, not to register a result.
1888 // Do not attempt further compilations of this method.
1889 ci_env.record_method_not_compilable("compile failed", !TieredCompilation);
1890 }
1891
1892 // Copy this bit to the enclosing block:
1893 compilable = ci_env.compilable();
1894
1895 if (ci_env.failing()) {
1896 failure_reason = ci_env.failure_reason();
1897 retry_message = ci_env.retry_message();
1898 ci_env.report_failure(failure_reason);
1899 }
1900
1901 post_compile(thread, task, event, !ci_env.failing(), &ci_env);
1902 }
|