--- old/src/share/vm/compiler/compileBroker.cpp 2010-01-13 16:08:17.000000000 -0800 +++ new/src/share/vm/compiler/compileBroker.cpp 2010-01-13 16:08:17.000000000 -0800 @@ -69,6 +69,7 @@ bool CompileBroker::_initialized = false; volatile bool CompileBroker::_should_block = false; +volatile jint CompileBroker::_should_compile_new_jobs = run_compilation; // The installed compiler(s) AbstractCompiler* CompileBroker::_compilers[2]; @@ -461,9 +462,9 @@ // Get the next CompileTask from a CompileQueue CompileTask* CompileQueue::get() { MutexLocker locker(lock()); - + // Wait for an available CompileTask. - while (_first == NULL) { + while ((_first == NULL) || (!CompileBroker::should_compile_new_jobs())) { // There is no work to be done right now. Wait. lock()->wait(); } @@ -1325,27 +1326,14 @@ { // We need this HandleMark to avoid leaking VM handles. HandleMark hm(thread); + if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) { - // The CodeCache is full. Print out warning and disable compilation. - UseInterpreter = true; - if (UseCompiler || AlwaysCompileLoopMethods ) { - if (log != NULL) { - log->begin_elem("code_cache_full"); - log->stamp(); - log->end_elem(); - } -#ifndef PRODUCT - warning("CodeCache is full. Compiler has been disabled"); - if (CompileTheWorld || ExitOnFullCodeCache) { - before_exit(thread); - exit_globals(); // will delete tty - vm_direct_exit(CompileTheWorld ? 0 : 1); - } -#endif - UseCompiler = false; - AlwaysCompileLoopMethods = false; - } - } + // the code cache is really full + handle_full_code_cache(); + } else if (UseCodeCacheFlushing && (CodeCache::unallocated_capacity() < CodeCacheFlushingMinimumFreeSpace)) { + // Attempt to start cleaning the code cache while there is still a little headroom + NMethodSweeper::handle_full_code_cache(false); + } CompileTask* task = queue->get(); @@ -1369,7 +1357,7 @@ // Never compile a method if breakpoints are present in it if (method()->number_of_breakpoints() == 0) { // Compile the method. - if (UseCompiler || AlwaysCompileLoopMethods) { + if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) { #ifdef COMPILER1 // Allow repeating compilations for the purpose of benchmarking // compile speed. This is not useful for customers. @@ -1614,6 +1602,31 @@ // ------------------------------------------------------------------ +// CompileBroker::handle_full_code_cache +// +// The CodeCache is full. Print out warning and disable compilation or +// try code cache cleaning so compilation can continue later. +void CompileBroker::handle_full_code_cache() { + UseInterpreter = true; + if (UseCompiler || AlwaysCompileLoopMethods ) { + #ifndef PRODUCT + warning("CodeCache is full. Compiler has been disabled"); + if (CompileTheWorld || ExitOnFullCodeCache) { + before_exit(JavaThread::current()); + exit_globals(); // will delete tty + vm_direct_exit(CompileTheWorld ? 0 : 1); + } + #endif + if (UseCodeCacheFlushing) { + NMethodSweeper::handle_full_code_cache(true); + } else { + UseCompiler = false; + AlwaysCompileLoopMethods = false; + } + } +} + +// ------------------------------------------------------------------ // CompileBroker::set_last_compile // // Record this compilation for debugging purposes.