Mercurial > hg > graal-jvmci-8
diff src/share/vm/gc_implementation/shared/gcUtil.cpp @ 6060:78a1b285cda8
7158457: division by zero in adaptiveweightedaverage
Summary: Add ceiling to AdaptiveWeightedAverage
Reviewed-by: ysr, iveresov
author | mikael |
---|---|
date | Tue, 15 May 2012 00:56:06 +0200 |
parents | 1d1603768966 |
children | b9a9ed0f8eeb |
line wrap: on
line diff
--- a/src/share/vm/gc_implementation/shared/gcUtil.cpp Fri May 11 14:54:35 2012 -0700 +++ b/src/share/vm/gc_implementation/shared/gcUtil.cpp Tue May 15 00:56:06 2012 +0200 @@ -31,9 +31,15 @@ float average) { // We smooth the samples by not using weight() directly until we've // had enough data to make it meaningful. We'd like the first weight - // used to be 1, the second to be 1/2, etc until we have 100/weight - // samples. - unsigned count_weight = 100/count(); + // used to be 1, the second to be 1/2, etc until we have + // OLD_THRESHOLD/weight samples. + unsigned count_weight = 0; + + // Avoid division by zero if the counter wraps (7158457) + if (!is_old()) { + count_weight = OLD_THRESHOLD/count(); + } + unsigned adaptive_weight = (MAX2(weight(), count_weight)); float new_avg = exp_avg(average, new_sample, adaptive_weight); @@ -43,8 +49,6 @@ void AdaptiveWeightedAverage::sample(float new_sample) { increment_count(); - assert(count() != 0, - "Wraparound -- history would be incorrectly discarded"); // Compute the new weighted average float new_avg = compute_adaptive_average(new_sample, average());