< prev index next >

src/hotspot/share/utilities/numberSeq.cpp

Print this page

 93     return 0.0;
 94 
 95   double result = _dvariance;
 96   if (result < 0.0) {
 97     // due to loss-of-precision errors, the variance might be negative
 98     // by a small bit
 99 
100     guarantee(-0.1 < result && result < 0.0,
101                "if variance is negative, it should be very small");
102     result = 0.0;
103   }
104   return result;
105 }
106 
107 double AbsSeq::dsd() const {
108   double var = dvariance();
109   guarantee( var >= 0.0, "variance should not be negative" );
110   return sqrt(var);
111 }
112 


























113 NumberSeq::NumberSeq(double alpha) :
114   AbsSeq(alpha), _last(0.0), _maximum(0.0) {
115 }
116 
117 bool NumberSeq::check_nums(NumberSeq *total, int n, NumberSeq **parts) {
118   for (int i = 0; i < n; ++i) {
119     if (parts[i] != nullptr && total->num() != parts[i]->num())
120       return false;
121   }
122   return true;
123 }
124 
125 void NumberSeq::add(double val) {
126   AbsSeq::add(val);
127 
128   _last = val;
129   if (_num == 0) {
130     _maximum = val;
131   } else {
132     if (val > _maximum)
133       _maximum = val;
134   }
135   _sum += val;
136   _sum_of_squares += val * val;
137   ++_num;
138 }
139 
















140 
141 TruncatedSeq::TruncatedSeq(int length, double alpha):
142   AbsSeq(alpha), _length(length), _next(0) {
143   _sequence = NEW_C_HEAP_ARRAY(double, _length, mtInternal);
144   for (int i = 0; i < _length; ++i)
145     _sequence[i] = 0.0;
146 }
147 
148 TruncatedSeq::~TruncatedSeq() {
149   FREE_C_HEAP_ARRAY(double, _sequence);
150 }
151 
152 void TruncatedSeq::add(double val) {
153   AbsSeq::add(val);
154 
155   // get the oldest value in the sequence...
156   double old_val = _sequence[_next];
157   // ...remove it from the sum and sum of squares
158   _sum -= old_val;
159   _sum_of_squares -= old_val * old_val;

 93     return 0.0;
 94 
 95   double result = _dvariance;
 96   if (result < 0.0) {
 97     // due to loss-of-precision errors, the variance might be negative
 98     // by a small bit
 99 
100     guarantee(-0.1 < result && result < 0.0,
101                "if variance is negative, it should be very small");
102     result = 0.0;
103   }
104   return result;
105 }
106 
107 double AbsSeq::dsd() const {
108   double var = dvariance();
109   guarantee( var >= 0.0, "variance should not be negative" );
110   return sqrt(var);
111 }
112 
113 void AbsSeq::merge(AbsSeq& abs2, bool clear_this) {
114 
115   if (num() == 0) return;  // nothing to do
116 
117   abs2._num += _num;
118   abs2._sum += _sum;
119   abs2._sum_of_squares += _sum_of_squares;
120 
121   // Decaying stats need a bit more thought
122   assert(abs2._alpha == _alpha, "Caution: merge incompatible?");
123   // Until JDK-8298902 is fixed, we taint the decaying statistics
124   if (abs2._davg != NAN) {
125     abs2._davg = NAN;
126     abs2._dvariance = NAN;
127   }
128 
129   if (clear_this) {
130     _num = 0;
131     _sum = 0;
132     _sum_of_squares = 0;
133     _davg = 0;
134     _dvariance = 0;
135   }
136 }
137 
138 
139 NumberSeq::NumberSeq(double alpha) :
140   AbsSeq(alpha), _last(0.0), _maximum(0.0) {
141 }
142 
143 bool NumberSeq::check_nums(NumberSeq *total, int n, NumberSeq **parts) {
144   for (int i = 0; i < n; ++i) {
145     if (parts[i] != nullptr && total->num() != parts[i]->num())
146       return false;
147   }
148   return true;
149 }
150 
151 void NumberSeq::add(double val) {
152   AbsSeq::add(val);
153 
154   _last = val;
155   if (_num == 0) {
156     _maximum = val;
157   } else {
158     if (val > _maximum)
159       _maximum = val;
160   }
161   _sum += val;
162   _sum_of_squares += val * val;
163   ++_num;
164 }
165 
166 void NumberSeq::merge(NumberSeq& nseq2, bool clear_this) {
167 
168   if (num() == 0) return;  // nothing to do
169 
170   nseq2._last = _last;   // this is newer than that
171   nseq2._maximum = MAX2(_maximum, nseq2._maximum);
172 
173   AbsSeq::merge(nseq2, clear_this);
174 
175   if (clear_this) {
176     _last = 0;
177     _maximum = 0;
178     assert(num() == 0, "Not cleared");
179   }
180 }
181 
182 
183 TruncatedSeq::TruncatedSeq(int length, double alpha):
184   AbsSeq(alpha), _length(length), _next(0) {
185   _sequence = NEW_C_HEAP_ARRAY(double, _length, mtInternal);
186   for (int i = 0; i < _length; ++i)
187     _sequence[i] = 0.0;
188 }
189 
190 TruncatedSeq::~TruncatedSeq() {
191   FREE_C_HEAP_ARRAY(double, _sequence);
192 }
193 
194 void TruncatedSeq::add(double val) {
195   AbsSeq::add(val);
196 
197   // get the oldest value in the sequence...
198   double old_val = _sequence[_next];
199   // ...remove it from the sum and sum of squares
200   _sum -= old_val;
201   _sum_of_squares -= old_val * old_val;
< prev index next >