Mercurial > hg > truffle
comparison src/share/vm/compiler/compileBroker.cpp @ 1202:5f24d0319e54
4360113: Evict nmethods when code cache gets full
Summary: Speculatively unload the oldest nmethods when code cache gets full.
Reviewed-by: never, kvn
Contributed-by: eric.caspole@amd.com
author | kvn |
---|---|
date | Fri, 29 Jan 2010 09:27:22 -0800 |
parents | 40e7c1d24e4a |
children | cef333a48af6 |
comparison
equal
deleted
inserted
replaced
1201:24128c2ffa87 | 1202:5f24d0319e54 |
---|---|
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, |
1033 | 1041 |
1034 // JVMTI -- post_compile_event requires jmethod_id() that may require | 1042 // JVMTI -- post_compile_event requires jmethod_id() that may require |
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(); |
1046 } | |
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; | |
1038 } | 1054 } |
1039 | 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) { |
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; |
1612 #endif | 1615 #endif |
1613 } | 1616 } |
1614 | 1617 |
1615 | 1618 |
1616 // ------------------------------------------------------------------ | 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 } | |
1650 | |
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. |
1620 void CompileBroker::set_last_compile(CompilerThread* thread, methodHandle method, bool is_osr, int comp_level) { | 1655 void CompileBroker::set_last_compile(CompilerThread* thread, methodHandle method, bool is_osr, int comp_level) { |
1621 ResourceMark rm; | 1656 ResourceMark rm; |