1.1 --- a/src/share/vm/compiler/compileBroker.cpp Fri Jan 29 08:33:24 2010 -0800 1.2 +++ b/src/share/vm/compiler/compileBroker.cpp Fri Jan 29 09:27:22 2010 -0800 1.3 @@ -69,6 +69,7 @@ 1.4 1.5 bool CompileBroker::_initialized = false; 1.6 volatile bool CompileBroker::_should_block = false; 1.7 +volatile jint CompileBroker::_should_compile_new_jobs = run_compilation; 1.8 1.9 // The installed compiler(s) 1.10 AbstractCompiler* CompileBroker::_compilers[2]; 1.11 @@ -986,6 +987,13 @@ 1.12 return method_code; 1.13 } 1.14 if (method->is_not_compilable(comp_level)) return NULL; 1.15 + 1.16 + nmethod* saved = CodeCache::find_and_remove_saved_code(method()); 1.17 + if (saved != NULL) { 1.18 + method->set_code(method, saved); 1.19 + return saved; 1.20 + } 1.21 + 1.22 } else { 1.23 // osr compilation 1.24 #ifndef TIERED 1.25 @@ -1037,6 +1045,14 @@ 1.26 method->jmethod_id(); 1.27 } 1.28 1.29 + // If the compiler is shut off due to code cache flushing or otherwise, 1.30 + // fail out now so blocking compiles dont hang the java thread 1.31 + if (!should_compile_new_jobs() || (UseCodeCacheFlushing && CodeCache::needs_flushing())) { 1.32 + method->invocation_counter()->decay(); 1.33 + method->backedge_counter()->decay(); 1.34 + return NULL; 1.35 + } 1.36 + 1.37 // do the compilation 1.38 if (method->is_native()) { 1.39 if (!PreferInterpreterNativeStubs) { 1.40 @@ -1325,26 +1341,13 @@ 1.41 { 1.42 // We need this HandleMark to avoid leaking VM handles. 1.43 HandleMark hm(thread); 1.44 + 1.45 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) { 1.46 - // The CodeCache is full. Print out warning and disable compilation. 1.47 - UseInterpreter = true; 1.48 - if (UseCompiler || AlwaysCompileLoopMethods ) { 1.49 - if (log != NULL) { 1.50 - log->begin_elem("code_cache_full"); 1.51 - log->stamp(); 1.52 - log->end_elem(); 1.53 - } 1.54 -#ifndef PRODUCT 1.55 - warning("CodeCache is full. Compiler has been disabled"); 1.56 - if (CompileTheWorld || ExitOnFullCodeCache) { 1.57 - before_exit(thread); 1.58 - exit_globals(); // will delete tty 1.59 - vm_direct_exit(CompileTheWorld ? 0 : 1); 1.60 - } 1.61 -#endif 1.62 - UseCompiler = false; 1.63 - AlwaysCompileLoopMethods = false; 1.64 - } 1.65 + // the code cache is really full 1.66 + handle_full_code_cache(); 1.67 + } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) { 1.68 + // Attempt to start cleaning the code cache while there is still a little headroom 1.69 + NMethodSweeper::handle_full_code_cache(false); 1.70 } 1.71 1.72 CompileTask* task = queue->get(); 1.73 @@ -1369,7 +1372,7 @@ 1.74 // Never compile a method if breakpoints are present in it 1.75 if (method()->number_of_breakpoints() == 0) { 1.76 // Compile the method. 1.77 - if (UseCompiler || AlwaysCompileLoopMethods) { 1.78 + if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) { 1.79 #ifdef COMPILER1 1.80 // Allow repeating compilations for the purpose of benchmarking 1.81 // compile speed. This is not useful for customers. 1.82 @@ -1614,6 +1617,38 @@ 1.83 1.84 1.85 // ------------------------------------------------------------------ 1.86 +// CompileBroker::handle_full_code_cache 1.87 +// 1.88 +// The CodeCache is full. Print out warning and disable compilation or 1.89 +// try code cache cleaning so compilation can continue later. 1.90 +void CompileBroker::handle_full_code_cache() { 1.91 + UseInterpreter = true; 1.92 + if (UseCompiler || AlwaysCompileLoopMethods ) { 1.93 + CompilerThread* thread = CompilerThread::current(); 1.94 + CompileLog* log = thread->log(); 1.95 + if (log != NULL) { 1.96 + log->begin_elem("code_cache_full"); 1.97 + log->stamp(); 1.98 + log->end_elem(); 1.99 + } 1.100 + #ifndef PRODUCT 1.101 + warning("CodeCache is full. Compiler has been disabled"); 1.102 + if (CompileTheWorld || ExitOnFullCodeCache) { 1.103 + before_exit(JavaThread::current()); 1.104 + exit_globals(); // will delete tty 1.105 + vm_direct_exit(CompileTheWorld ? 0 : 1); 1.106 + } 1.107 + #endif 1.108 + if (UseCodeCacheFlushing) { 1.109 + NMethodSweeper::handle_full_code_cache(true); 1.110 + } else { 1.111 + UseCompiler = false; 1.112 + AlwaysCompileLoopMethods = false; 1.113 + } 1.114 + } 1.115 +} 1.116 + 1.117 +// ------------------------------------------------------------------ 1.118 // CompileBroker::set_last_compile 1.119 // 1.120 // Record this compilation for debugging purposes.