comparison src/share/vm/runtime/sweeper.cpp @ 14197:d49557091d18

8029091: Bug in calculation of code cache sweeping interval Summary: Use signed data type so that no underflow can happen Reviewed-by: kvn, roland
author anoll
date Tue, 17 Dec 2013 08:31:06 +0100
parents 86e6d691f2e1
children 49a31fd8b93d
comparison
equal deleted inserted replaced
14174:050a626a8895 14197:d49557091d18
255 // As a result, we invoke the sweeper after 255 // As a result, we invoke the sweeper after
256 // 15 invocations of 'mark_active_nmethods. 256 // 15 invocations of 'mark_active_nmethods.
257 // Large ReservedCodeCacheSize: (e.g., 256M + code Cache is 90% full). The formula 257 // Large ReservedCodeCacheSize: (e.g., 256M + code Cache is 90% full). The formula
258 // computes: (256 / 16) - 10 = 6. 258 // computes: (256 / 16) - 10 = 6.
259 if (!_should_sweep) { 259 if (!_should_sweep) {
260 int time_since_last_sweep = _time_counter - _last_sweep; 260 const int time_since_last_sweep = _time_counter - _last_sweep;
261 double wait_until_next_sweep = (ReservedCodeCacheSize / (16 * M)) - time_since_last_sweep - 261 // ReservedCodeCacheSize has an 'unsigned' type. We need a 'signed' type for max_wait_time,
262 CodeCache::reverse_free_ratio(); 262 // since 'time_since_last_sweep' can be larger than 'max_wait_time'. If that happens using
263 // an unsigned type would cause an underflow (wait_until_next_sweep becomes a large positive
264 // value) that disables the intended periodic sweeps.
265 const int max_wait_time = ReservedCodeCacheSize / (16 * M);
266 double wait_until_next_sweep = max_wait_time - time_since_last_sweep - CodeCache::reverse_free_ratio();
267 assert(wait_until_next_sweep <= (double)max_wait_time, "Calculation of code cache sweeper interval is incorrect");
263 268
264 if ((wait_until_next_sweep <= 0.0) || !CompileBroker::should_compile_new_jobs()) { 269 if ((wait_until_next_sweep <= 0.0) || !CompileBroker::should_compile_new_jobs()) {
265 _should_sweep = true; 270 _should_sweep = true;
266 } 271 }
267 } 272 }