1 /*
2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
86
87 // Useful for modifying static structures after startup.
88 void modify(size_t avg, unsigned wt, bool force = false) {
89 assert(force, "Are you sure you want to call this?");
90 _average = (float)avg;
91 _weight = wt;
92 }
93
94 // Accessors
95 float average() const { return _average; }
96 unsigned weight() const { return _weight; }
97 unsigned count() const { return _sample_count; }
98 float last_sample() const { return _last_sample; }
99 bool is_old() const { return _is_old; }
100
101 // Update data with a new sample.
102 void sample(float new_sample);
103
104 static inline float exp_avg(float avg, float sample,
105 unsigned int weight) {
106 assert(0 <= weight && weight <= 100, "weight must be a percent");
107 return (100.0F - weight) * avg / 100.0F + weight * sample / 100.0F;
108 }
109 static inline size_t exp_avg(size_t avg, size_t sample,
110 unsigned int weight) {
111 // Convert to float and back to avoid integer overflow.
112 return (size_t)exp_avg((float)avg, (float)sample, weight);
113 }
114
115 // Printing
116 void print_on(outputStream* st) const;
117 void print() const;
118 };
119
120
121 // A weighted average that includes a deviation from the average,
122 // some multiple of which is added to the average.
123 //
124 // This serves as our best estimate of an upper bound on a future
125 // unknown.
126 class AdaptivePaddedAverage : public AdaptiveWeightedAverage {
|
1 /*
2 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
86
87 // Useful for modifying static structures after startup.
88 void modify(size_t avg, unsigned wt, bool force = false) {
89 assert(force, "Are you sure you want to call this?");
90 _average = (float)avg;
91 _weight = wt;
92 }
93
94 // Accessors
95 float average() const { return _average; }
96 unsigned weight() const { return _weight; }
97 unsigned count() const { return _sample_count; }
98 float last_sample() const { return _last_sample; }
99 bool is_old() const { return _is_old; }
100
101 // Update data with a new sample.
102 void sample(float new_sample);
103
104 static inline float exp_avg(float avg, float sample,
105 unsigned int weight) {
106 assert(weight <= 100, "weight must be a percent");
107 return (100.0F - weight) * avg / 100.0F + weight * sample / 100.0F;
108 }
109 static inline size_t exp_avg(size_t avg, size_t sample,
110 unsigned int weight) {
111 // Convert to float and back to avoid integer overflow.
112 return (size_t)exp_avg((float)avg, (float)sample, weight);
113 }
114
115 // Printing
116 void print_on(outputStream* st) const;
117 void print() const;
118 };
119
120
121 // A weighted average that includes a deviation from the average,
122 // some multiple of which is added to the average.
123 //
124 // This serves as our best estimate of an upper bound on a future
125 // unknown.
126 class AdaptivePaddedAverage : public AdaptiveWeightedAverage {
|