Mercurial > hg > truffle
comparison src/share/vm/compiler/compileBroker.cpp @ 1339:09ac706c2623
Merge
author | asaha |
---|---|
date | Wed, 24 Mar 2010 17:16:33 -0700 |
parents | cef333a48af6 |
children | 428a9c451986 |
comparison
equal
deleted
inserted
replaced
1338:f5dd08ad65df | 1339:09ac706c2623 |
---|---|
1 /* | 1 /* |
2 * Copyright 1999-2009 Sun Microsystems, Inc. All Rights Reserved. | 2 * Copyright 1999-2010 Sun Microsystems, Inc. All Rights Reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
67 | 67 |
68 #endif // ndef DTRACE_ENABLED | 68 #endif // ndef DTRACE_ENABLED |
69 | 69 |
70 bool CompileBroker::_initialized = false; | 70 bool CompileBroker::_initialized = false; |
71 volatile bool CompileBroker::_should_block = false; | 71 volatile bool CompileBroker::_should_block = false; |
72 volatile jint CompileBroker::_should_compile_new_jobs = run_compilation; | |
72 | 73 |
73 // The installed compiler(s) | 74 // The installed compiler(s) |
74 AbstractCompiler* CompileBroker::_compilers[2]; | 75 AbstractCompiler* CompileBroker::_compilers[2]; |
75 | 76 |
76 // These counters are used for assigning id's to each compilation | 77 // These counters are used for assigning id's to each compilation |
984 #endif // TIERED | 985 #endif // TIERED |
985 ) { | 986 ) { |
986 return method_code; | 987 return method_code; |
987 } | 988 } |
988 if (method->is_not_compilable(comp_level)) return NULL; | 989 if (method->is_not_compilable(comp_level)) return NULL; |
990 | |
991 nmethod* saved = CodeCache::find_and_remove_saved_code(method()); | |
992 if (saved != NULL) { | |
993 method->set_code(method, saved); | |
994 return saved; | |
995 } | |
996 | |
989 } else { | 997 } else { |
990 // osr compilation | 998 // osr compilation |
991 #ifndef TIERED | 999 #ifndef TIERED |
992 // seems like an assert of dubious value | 1000 // seems like an assert of dubious value |
993 assert(comp_level == CompLevel_full_optimization, | 1001 assert(comp_level == CompLevel_full_optimization, |
1035 // a lock the compiling thread can not acquire. Prefetch it here. | 1043 // a lock the compiling thread can not acquire. Prefetch it here. |
1036 if (JvmtiExport::should_post_compiled_method_load()) { | 1044 if (JvmtiExport::should_post_compiled_method_load()) { |
1037 method->jmethod_id(); | 1045 method->jmethod_id(); |
1038 } | 1046 } |
1039 | 1047 |
1048 // If the compiler is shut off due to code cache flushing or otherwise, | |
1049 // fail out now so blocking compiles dont hang the java thread | |
1050 if (!should_compile_new_jobs() || (UseCodeCacheFlushing && CodeCache::needs_flushing())) { | |
1051 method->invocation_counter()->decay(); | |
1052 method->backedge_counter()->decay(); | |
1053 return NULL; | |
1054 } | |
1055 | |
1040 // do the compilation | 1056 // do the compilation |
1041 if (method->is_native()) { | 1057 if (method->is_native()) { |
1042 if (!PreferInterpreterNativeStubs) { | 1058 if (!PreferInterpreterNativeStubs) { |
1043 (void) AdapterHandlerLibrary::create_native_wrapper(method); | 1059 (void) AdapterHandlerLibrary::create_native_wrapper(method); |
1044 } else { | 1060 } else { |
1114 // Some compilers may not support the compilation of natives. | 1130 // Some compilers may not support the compilation of natives. |
1115 // QQQ this needs some work ought to only record not compilable at | 1131 // QQQ this needs some work ought to only record not compilable at |
1116 // the specified level | 1132 // the specified level |
1117 if (is_native && | 1133 if (is_native && |
1118 (!CICompileNatives || !compiler(comp_level)->supports_native())) { | 1134 (!CICompileNatives || !compiler(comp_level)->supports_native())) { |
1119 method->set_not_compilable(); | 1135 method->set_not_compilable_quietly(); |
1120 return true; | 1136 return true; |
1121 } | 1137 } |
1122 | 1138 |
1123 bool is_osr = (osr_bci != standard_entry_bci); | 1139 bool is_osr = (osr_bci != standard_entry_bci); |
1124 // Some compilers may not support on stack replacement. | 1140 // Some compilers may not support on stack replacement. |
1138 method->is_native() ? "generation of native wrapper" : "compile", | 1154 method->is_native() ? "generation of native wrapper" : "compile", |
1139 (method->is_static() ? " static" : "")); | 1155 (method->is_static() ? " static" : "")); |
1140 method->print_short_name(tty); | 1156 method->print_short_name(tty); |
1141 tty->cr(); | 1157 tty->cr(); |
1142 } | 1158 } |
1143 method->set_not_compilable(); | 1159 method->set_not_compilable_quietly(); |
1144 } | 1160 } |
1145 | 1161 |
1146 return false; | 1162 return false; |
1147 } | 1163 } |
1148 | 1164 |
1171 return id; | 1187 return id; |
1172 } | 1188 } |
1173 } | 1189 } |
1174 | 1190 |
1175 // Method was not in the appropriate compilation range. | 1191 // Method was not in the appropriate compilation range. |
1176 method->set_not_compilable(); | 1192 method->set_not_compilable_quietly(); |
1177 return 0; | 1193 return 0; |
1178 } | 1194 } |
1179 | 1195 |
1180 | 1196 |
1181 // ------------------------------------------------------------------ | 1197 // ------------------------------------------------------------------ |
1323 | 1339 |
1324 while (true) { | 1340 while (true) { |
1325 { | 1341 { |
1326 // We need this HandleMark to avoid leaking VM handles. | 1342 // We need this HandleMark to avoid leaking VM handles. |
1327 HandleMark hm(thread); | 1343 HandleMark hm(thread); |
1344 | |
1328 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) { | 1345 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) { |
1329 // The CodeCache is full. Print out warning and disable compilation. | 1346 // the code cache is really full |
1330 UseInterpreter = true; | 1347 handle_full_code_cache(); |
1331 if (UseCompiler || AlwaysCompileLoopMethods ) { | 1348 } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) { |
1332 if (log != NULL) { | 1349 // Attempt to start cleaning the code cache while there is still a little headroom |
1333 log->begin_elem("code_cache_full"); | 1350 NMethodSweeper::handle_full_code_cache(false); |
1334 log->stamp(); | |
1335 log->end_elem(); | |
1336 } | |
1337 #ifndef PRODUCT | |
1338 warning("CodeCache is full. Compiler has been disabled"); | |
1339 if (CompileTheWorld || ExitOnFullCodeCache) { | |
1340 before_exit(thread); | |
1341 exit_globals(); // will delete tty | |
1342 vm_direct_exit(CompileTheWorld ? 0 : 1); | |
1343 } | |
1344 #endif | |
1345 UseCompiler = false; | |
1346 AlwaysCompileLoopMethods = false; | |
1347 } | |
1348 } | 1351 } |
1349 | 1352 |
1350 CompileTask* task = queue->get(); | 1353 CompileTask* task = queue->get(); |
1351 | 1354 |
1352 // Give compiler threads an extra quanta. They tend to be bursty and | 1355 // Give compiler threads an extra quanta. They tend to be bursty and |
1367 (methodOop)JNIHandles::resolve(task->method_handle())); | 1370 (methodOop)JNIHandles::resolve(task->method_handle())); |
1368 | 1371 |
1369 // Never compile a method if breakpoints are present in it | 1372 // Never compile a method if breakpoints are present in it |
1370 if (method()->number_of_breakpoints() == 0) { | 1373 if (method()->number_of_breakpoints() == 0) { |
1371 // Compile the method. | 1374 // Compile the method. |
1372 if (UseCompiler || AlwaysCompileLoopMethods) { | 1375 if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) { |
1373 #ifdef COMPILER1 | 1376 #ifdef COMPILER1 |
1374 // Allow repeating compilations for the purpose of benchmarking | 1377 // Allow repeating compilations for the purpose of benchmarking |
1375 // compile speed. This is not useful for customers. | 1378 // compile speed. This is not useful for customers. |
1376 if (CompilationRepeat != 0) { | 1379 if (CompilationRepeat != 0) { |
1377 int compile_count = CompilationRepeat; | 1380 int compile_count = CompilationRepeat; |
1585 | 1588 |
1586 if (compilable == ciEnv::MethodCompilable_never) { | 1589 if (compilable == ciEnv::MethodCompilable_never) { |
1587 if (is_osr) { | 1590 if (is_osr) { |
1588 method->set_not_osr_compilable(); | 1591 method->set_not_osr_compilable(); |
1589 } else { | 1592 } else { |
1590 method->set_not_compilable(); | 1593 method->set_not_compilable_quietly(); |
1591 } | 1594 } |
1592 } else if (compilable == ciEnv::MethodCompilable_not_at_tier) { | 1595 } else if (compilable == ciEnv::MethodCompilable_not_at_tier) { |
1593 method->set_not_compilable(task->comp_level()); | 1596 method->set_not_compilable_quietly(task->comp_level()); |
1594 } | 1597 } |
1595 | 1598 |
1596 // Note that the queued_for_compilation bits are cleared without | 1599 // Note that the queued_for_compilation bits are cleared without |
1597 // protection of a mutex. [They were set by the requester thread, | 1600 // protection of a mutex. [They were set by the requester thread, |
1598 // when adding the task to the complie queue -- at which time the | 1601 // when adding the task to the complie queue -- at which time the |
1610 vm_exit(0); | 1613 vm_exit(0); |
1611 } | 1614 } |
1612 #endif | 1615 #endif |
1613 } | 1616 } |
1614 | 1617 |
1618 | |
1619 // ------------------------------------------------------------------ | |
1620 // CompileBroker::handle_full_code_cache | |
1621 // | |
1622 // The CodeCache is full. Print out warning and disable compilation or | |
1623 // try code cache cleaning so compilation can continue later. | |
1624 void CompileBroker::handle_full_code_cache() { | |
1625 UseInterpreter = true; | |
1626 if (UseCompiler || AlwaysCompileLoopMethods ) { | |
1627 CompilerThread* thread = CompilerThread::current(); | |
1628 CompileLog* log = thread->log(); | |
1629 if (log != NULL) { | |
1630 log->begin_elem("code_cache_full"); | |
1631 log->stamp(); | |
1632 log->end_elem(); | |
1633 } | |
1634 #ifndef PRODUCT | |
1635 warning("CodeCache is full. Compiler has been disabled"); | |
1636 if (CompileTheWorld || ExitOnFullCodeCache) { | |
1637 before_exit(JavaThread::current()); | |
1638 exit_globals(); // will delete tty | |
1639 vm_direct_exit(CompileTheWorld ? 0 : 1); | |
1640 } | |
1641 #endif | |
1642 if (UseCodeCacheFlushing) { | |
1643 NMethodSweeper::handle_full_code_cache(true); | |
1644 } else { | |
1645 UseCompiler = false; | |
1646 AlwaysCompileLoopMethods = false; | |
1647 } | |
1648 } | |
1649 } | |
1615 | 1650 |
1616 // ------------------------------------------------------------------ | 1651 // ------------------------------------------------------------------ |
1617 // CompileBroker::set_last_compile | 1652 // CompileBroker::set_last_compile |
1618 // | 1653 // |
1619 // Record this compilation for debugging purposes. | 1654 // Record this compilation for debugging purposes. |
1818 tty->print_cr(" Total compilation time : %6.3f s", CompileBroker::_t_total_compilation.seconds()); | 1853 tty->print_cr(" Total compilation time : %6.3f s", CompileBroker::_t_total_compilation.seconds()); |
1819 tty->print_cr(" Standard compilation : %6.3f s, Average : %2.3f", | 1854 tty->print_cr(" Standard compilation : %6.3f s, Average : %2.3f", |
1820 CompileBroker::_t_standard_compilation.seconds(), | 1855 CompileBroker::_t_standard_compilation.seconds(), |
1821 CompileBroker::_t_standard_compilation.seconds() / CompileBroker::_total_standard_compile_count); | 1856 CompileBroker::_t_standard_compilation.seconds() / CompileBroker::_total_standard_compile_count); |
1822 tty->print_cr(" On stack replacement : %6.3f s, Average : %2.3f", CompileBroker::_t_osr_compilation.seconds(), CompileBroker::_t_osr_compilation.seconds() / CompileBroker::_total_osr_compile_count); | 1857 tty->print_cr(" On stack replacement : %6.3f s, Average : %2.3f", CompileBroker::_t_osr_compilation.seconds(), CompileBroker::_t_osr_compilation.seconds() / CompileBroker::_total_osr_compile_count); |
1823 compiler(CompLevel_fast_compile)->print_timers(); | 1858 |
1824 if (compiler(CompLevel_fast_compile) != compiler(CompLevel_highest_tier)) { | 1859 if (compiler(CompLevel_fast_compile)) { |
1825 compiler(CompLevel_highest_tier)->print_timers(); | 1860 compiler(CompLevel_fast_compile)->print_timers(); |
1861 if (compiler(CompLevel_fast_compile) != compiler(CompLevel_highest_tier)) | |
1862 compiler(CompLevel_highest_tier)->print_timers(); | |
1826 } | 1863 } |
1827 | 1864 |
1828 tty->cr(); | 1865 tty->cr(); |
1829 int tcb = CompileBroker::_sum_osr_bytes_compiled + CompileBroker::_sum_standard_bytes_compiled; | 1866 int tcb = CompileBroker::_sum_osr_bytes_compiled + CompileBroker::_sum_standard_bytes_compiled; |
1830 tty->print_cr(" Total compiled bytecodes : %6d bytes", tcb); | 1867 tty->print_cr(" Total compiled bytecodes : %6d bytes", tcb); |