1.1 --- a/src/share/vm/compiler/compileBroker.cpp Fri Sep 27 08:39:19 2013 +0200 1.2 +++ b/src/share/vm/compiler/compileBroker.cpp Fri Sep 27 10:50:55 2013 +0200 1.3 @@ -634,19 +634,36 @@ 1.4 NMethodSweeper::possibly_sweep(); 1.5 1.6 MutexLocker locker(lock()); 1.7 - // Wait for an available CompileTask. 1.8 + // If _first is NULL we have no more compile jobs. There are two reasons for 1.9 + // having no compile jobs: First, we compiled everything we wanted. Second, 1.10 + // we ran out of code cache so compilation has been disabled. In the latter 1.11 + // case we perform code cache sweeps to free memory such that we can re-enable 1.12 + // compilation. 1.13 while (_first == NULL) { 1.14 - // There is no work to be done right now. Wait. 1.15 - if (UseCodeCacheFlushing && (!CompileBroker::should_compile_new_jobs() || CodeCache::needs_flushing())) { 1.16 - // During the emergency sweeping periods, wake up and sweep occasionally 1.17 - bool timedout = lock()->wait(!Mutex::_no_safepoint_check_flag, NmethodSweepCheckInterval*1000); 1.18 - if (timedout) { 1.19 + if (UseCodeCacheFlushing && !CompileBroker::should_compile_new_jobs()) { 1.20 + // Wait a certain amount of time to possibly do another sweep. 1.21 + // We must wait until stack scanning has happened so that we can 1.22 + // transition a method's state from 'not_entrant' to 'zombie'. 1.23 + long wait_time = NmethodSweepCheckInterval * 1000; 1.24 + if (FLAG_IS_DEFAULT(NmethodSweepCheckInterval)) { 1.25 + // Only one thread at a time can do sweeping. Scale the 1.26 + // wait time according to the number of compiler threads. 1.27 + // As a result, the next sweep is likely to happen every 100ms 1.28 + // with an arbitrary number of threads that do sweeping. 1.29 + wait_time = 100 * CICompilerCount; 1.30 + } 1.31 + bool timeout = lock()->wait(!Mutex::_no_safepoint_check_flag, wait_time); 1.32 + if (timeout) { 1.33 MutexUnlocker ul(lock()); 1.34 - // When otherwise not busy, run nmethod sweeping 1.35 NMethodSweeper::possibly_sweep(); 1.36 } 1.37 } else { 1.38 - // During normal operation no need to wake up on timer 1.39 + // If there are no compilation tasks and we can compile new jobs 1.40 + // (i.e., there is enough free space in the code cache) there is 1.41 + // no need to invoke the sweeper. As a result, the hotness of methods 1.42 + // remains unchanged. This behavior is desired, since we want to keep 1.43 + // the stable state, i.e., we do not want to evict methods from the 1.44 + // code cache if it is unnecessary. 1.45 lock()->wait(); 1.46 } 1.47 } 1.48 @@ -1227,16 +1244,9 @@ 1.49 return method_code; 1.50 } 1.51 } 1.52 - if (method->is_not_compilable(comp_level)) return NULL; 1.53 - 1.54 - if (UseCodeCacheFlushing) { 1.55 - nmethod* saved = CodeCache::reanimate_saved_code(method()); 1.56 - if (saved != NULL) { 1.57 - method->set_code(method, saved); 1.58 - return saved; 1.59 - } 1.60 + if (method->is_not_compilable(comp_level)) { 1.61 + return NULL; 1.62 } 1.63 - 1.64 } else { 1.65 // osr compilation 1.66 #ifndef TIERED 1.67 @@ -1585,9 +1595,6 @@ 1.68 if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) { 1.69 // the code cache is really full 1.70 handle_full_code_cache(); 1.71 - } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) { 1.72 - // Attempt to start cleaning the code cache while there is still a little headroom 1.73 - NMethodSweeper::handle_full_code_cache(false); 1.74 } 1.75 1.76 CompileTask* task = queue->get(); 1.77 @@ -1943,7 +1950,11 @@ 1.78 } 1.79 #endif 1.80 if (UseCodeCacheFlushing) { 1.81 - NMethodSweeper::handle_full_code_cache(true); 1.82 + // Since code cache is full, immediately stop new compiles 1.83 + if (CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation)) { 1.84 + NMethodSweeper::log_sweep("disable_compiler"); 1.85 + NMethodSweeper::possibly_sweep(); 1.86 + } 1.87 } else { 1.88 UseCompiler = false; 1.89 AlwaysCompileLoopMethods = false;