Mercurial > hg > truffle
comparison src/share/vm/gc_implementation/shared/gcUtil.hpp @ 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 | f95d63e2154a |
children | d2a62e0f25eb |
comparison
equal
deleted
inserted
replaced
6054:56d1af561395 | 6060:78a1b285cda8 |
---|---|
48 float _average; // The last computed average | 48 float _average; // The last computed average |
49 unsigned _sample_count; // How often we've sampled this average | 49 unsigned _sample_count; // How often we've sampled this average |
50 unsigned _weight; // The weight used to smooth the averages | 50 unsigned _weight; // The weight used to smooth the averages |
51 // A higher weight favors the most | 51 // A higher weight favors the most |
52 // recent data. | 52 // recent data. |
53 bool _is_old; // Has enough historical data | |
54 | |
55 const static unsigned OLD_THRESHOLD = 100; | |
53 | 56 |
54 protected: | 57 protected: |
55 float _last_sample; // The last value sampled. | 58 float _last_sample; // The last value sampled. |
56 | 59 |
57 void increment_count() { _sample_count++; } | 60 void increment_count() { |
61 _sample_count++; | |
62 if (!_is_old && _sample_count > OLD_THRESHOLD) { | |
63 _is_old = true; | |
64 } | |
65 } | |
66 | |
58 void set_average(float avg) { _average = avg; } | 67 void set_average(float avg) { _average = avg; } |
59 | 68 |
60 // Helper function, computes an adaptive weighted average | 69 // Helper function, computes an adaptive weighted average |
61 // given a sample and the last average | 70 // given a sample and the last average |
62 float compute_adaptive_average(float new_sample, float average); | 71 float compute_adaptive_average(float new_sample, float average); |
63 | 72 |
64 public: | 73 public: |
65 // Input weight must be between 0 and 100 | 74 // Input weight must be between 0 and 100 |
66 AdaptiveWeightedAverage(unsigned weight, float avg = 0.0) : | 75 AdaptiveWeightedAverage(unsigned weight, float avg = 0.0) : |
67 _average(avg), _sample_count(0), _weight(weight), _last_sample(0.0) { | 76 _average(avg), _sample_count(0), _weight(weight), _last_sample(0.0), |
77 _is_old(false) { | |
68 } | 78 } |
69 | 79 |
70 void clear() { | 80 void clear() { |
71 _average = 0; | 81 _average = 0; |
72 _sample_count = 0; | 82 _sample_count = 0; |
73 _last_sample = 0; | 83 _last_sample = 0; |
84 _is_old = false; | |
74 } | 85 } |
75 | 86 |
76 // Useful for modifying static structures after startup. | 87 // Useful for modifying static structures after startup. |
77 void modify(size_t avg, unsigned wt, bool force = false) { | 88 void modify(size_t avg, unsigned wt, bool force = false) { |
78 assert(force, "Are you sure you want to call this?"); | 89 assert(force, "Are you sure you want to call this?"); |
82 | 93 |
83 // Accessors | 94 // Accessors |
84 float average() const { return _average; } | 95 float average() const { return _average; } |
85 unsigned weight() const { return _weight; } | 96 unsigned weight() const { return _weight; } |
86 unsigned count() const { return _sample_count; } | 97 unsigned count() const { return _sample_count; } |
87 float last_sample() const { return _last_sample; } | 98 float last_sample() const { return _last_sample; } |
99 bool is_old() const { return _is_old; } | |
88 | 100 |
89 // Update data with a new sample. | 101 // Update data with a new sample. |
90 void sample(float new_sample); | 102 void sample(float new_sample); |
91 | 103 |
92 static inline float exp_avg(float avg, float sample, | 104 static inline float exp_avg(float avg, float sample, |