author | dholmes |
Fri, 04 Dec 2015 04:06:37 -0500 | |
changeset 34633 | 2a6c7c7b30a7 |
parent 30764 | fec48bf5a827 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
29580
a67a581cfe11
8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents:
25485
diff
changeset
|
2 |
* Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4574
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4574
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4574
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
30764 | 25 |
#ifndef SHARE_VM_GC_SHARED_GCUTIL_HPP |
26 |
#define SHARE_VM_GC_SHARED_GCUTIL_HPP |
|
7397 | 27 |
|
28 |
#include "memory/allocation.hpp" |
|
29 |
#include "runtime/timer.hpp" |
|
30 |
#include "utilities/debug.hpp" |
|
31 |
#include "utilities/globalDefinitions.hpp" |
|
32 |
#include "utilities/ostream.hpp" |
|
33 |
||
1 | 34 |
// Catch-all file for utility classes |
35 |
||
36 |
// A weighted average maintains a running, weighted average |
|
37 |
// of some float value (templates would be handy here if we |
|
38 |
// need different types). |
|
39 |
// |
|
40 |
// The average is adaptive in that we smooth it for the |
|
41 |
// initial samples; we don't use the weight until we have |
|
42 |
// enough samples for it to be meaningful. |
|
43 |
// |
|
44 |
// This serves as our best estimate of a future unknown. |
|
45 |
// |
|
13195 | 46 |
class AdaptiveWeightedAverage : public CHeapObj<mtGC> { |
1 | 47 |
private: |
48 |
float _average; // The last computed average |
|
49 |
unsigned _sample_count; // How often we've sampled this average |
|
50 |
unsigned _weight; // The weight used to smooth the averages |
|
51 |
// A higher weight favors the most |
|
52 |
// recent data. |
|
12626
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
53 |
bool _is_old; // Has enough historical data |
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
54 |
|
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
55 |
const static unsigned OLD_THRESHOLD = 100; |
1 | 56 |
|
57 |
protected: |
|
58 |
float _last_sample; // The last value sampled. |
|
59 |
||
12626
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
60 |
void increment_count() { |
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
61 |
_sample_count++; |
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
62 |
if (!_is_old && _sample_count > OLD_THRESHOLD) { |
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
63 |
_is_old = true; |
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
64 |
} |
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
65 |
} |
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
66 |
|
1 | 67 |
void set_average(float avg) { _average = avg; } |
68 |
||
69 |
// Helper function, computes an adaptive weighted average |
|
70 |
// given a sample and the last average |
|
71 |
float compute_adaptive_average(float new_sample, float average); |
|
72 |
||
73 |
public: |
|
74 |
// Input weight must be between 0 and 100 |
|
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
75 |
AdaptiveWeightedAverage(unsigned weight, float avg = 0.0) : |
12626
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
76 |
_average(avg), _sample_count(0), _weight(weight), _last_sample(0.0), |
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
77 |
_is_old(false) { |
1 | 78 |
} |
79 |
||
976
241230d48896
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
1
diff
changeset
|
80 |
void clear() { |
241230d48896
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
1
diff
changeset
|
81 |
_average = 0; |
241230d48896
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
1
diff
changeset
|
82 |
_sample_count = 0; |
241230d48896
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
1
diff
changeset
|
83 |
_last_sample = 0; |
12626
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
84 |
_is_old = false; |
976
241230d48896
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
1
diff
changeset
|
85 |
} |
241230d48896
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
1
diff
changeset
|
86 |
|
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
87 |
// Useful for modifying static structures after startup. |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
88 |
void modify(size_t avg, unsigned wt, bool force = false) { |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
89 |
assert(force, "Are you sure you want to call this?"); |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
90 |
_average = (float)avg; |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
91 |
_weight = wt; |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
92 |
} |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
93 |
|
1 | 94 |
// Accessors |
95 |
float average() const { return _average; } |
|
96 |
unsigned weight() const { return _weight; } |
|
97 |
unsigned count() const { return _sample_count; } |
|
12626
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
98 |
float last_sample() const { return _last_sample; } |
042841456ce1
7158457: division by zero in adaptiveweightedaverage
mikael
parents:
7397
diff
changeset
|
99 |
bool is_old() const { return _is_old; } |
1 | 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) { |
|
29580
a67a581cfe11
8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents:
25485
diff
changeset
|
106 |
assert(weight <= 100, "weight must be a percent"); |
1 | 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 |
} |
|
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
114 |
|
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
115 |
// Printing |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
116 |
void print_on(outputStream* st) const; |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
117 |
void print() const; |
1 | 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 { |
|
127 |
private: |
|
128 |
float _padded_avg; // The last computed padded average |
|
129 |
float _deviation; // Running deviation from the average |
|
130 |
unsigned _padding; // A multiple which, added to the average, |
|
131 |
// gives us an upper bound guess. |
|
132 |
||
133 |
protected: |
|
134 |
void set_padded_average(float avg) { _padded_avg = avg; } |
|
135 |
void set_deviation(float dev) { _deviation = dev; } |
|
136 |
||
137 |
public: |
|
138 |
AdaptivePaddedAverage() : |
|
139 |
AdaptiveWeightedAverage(0), |
|
140 |
_padded_avg(0.0), _deviation(0.0), _padding(0) {} |
|
141 |
||
142 |
AdaptivePaddedAverage(unsigned weight, unsigned padding) : |
|
143 |
AdaptiveWeightedAverage(weight), |
|
144 |
_padded_avg(0.0), _deviation(0.0), _padding(padding) {} |
|
145 |
||
146 |
// Placement support |
|
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
13963
diff
changeset
|
147 |
void* operator new(size_t ignored, void* p) throw() { return p; } |
1 | 148 |
// Allocator |
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
13963
diff
changeset
|
149 |
void* operator new(size_t size) throw() { return CHeapObj<mtGC>::operator new(size); } |
1 | 150 |
|
151 |
// Accessor |
|
152 |
float padded_average() const { return _padded_avg; } |
|
153 |
float deviation() const { return _deviation; } |
|
154 |
unsigned padding() const { return _padding; } |
|
155 |
||
976
241230d48896
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
1
diff
changeset
|
156 |
void clear() { |
241230d48896
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
1
diff
changeset
|
157 |
AdaptiveWeightedAverage::clear(); |
241230d48896
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
1
diff
changeset
|
158 |
_padded_avg = 0; |
241230d48896
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
1
diff
changeset
|
159 |
_deviation = 0; |
241230d48896
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
1
diff
changeset
|
160 |
} |
241230d48896
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
1
diff
changeset
|
161 |
|
1 | 162 |
// Override |
163 |
void sample(float new_sample); |
|
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
164 |
|
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
165 |
// Printing |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
166 |
void print_on(outputStream* st) const; |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
167 |
void print() const; |
1 | 168 |
}; |
169 |
||
170 |
// A weighted average that includes a deviation from the average, |
|
171 |
// some multiple of which is added to the average. |
|
172 |
// |
|
173 |
// This serves as our best estimate of an upper bound on a future |
|
174 |
// unknown. |
|
175 |
// A special sort of padded average: it doesn't update deviations |
|
176 |
// if the sample is zero. The average is allowed to change. We're |
|
177 |
// preventing the zero samples from drastically changing our padded |
|
178 |
// average. |
|
179 |
class AdaptivePaddedNoZeroDevAverage : public AdaptivePaddedAverage { |
|
180 |
public: |
|
181 |
AdaptivePaddedNoZeroDevAverage(unsigned weight, unsigned padding) : |
|
182 |
AdaptivePaddedAverage(weight, padding) {} |
|
183 |
// Override |
|
184 |
void sample(float new_sample); |
|
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
185 |
|
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
186 |
// Printing |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
187 |
void print_on(outputStream* st) const; |
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
188 |
void print() const; |
1 | 189 |
}; |
4574
b2d5b0975515
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
1217
diff
changeset
|
190 |
|
1 | 191 |
// Use a least squares fit to a set of data to generate a linear |
192 |
// equation. |
|
193 |
// y = intercept + slope * x |
|
194 |
||
13195 | 195 |
class LinearLeastSquareFit : public CHeapObj<mtGC> { |
1 | 196 |
double _sum_x; // sum of all independent data points x |
197 |
double _sum_x_squared; // sum of all independent data points x**2 |
|
198 |
double _sum_y; // sum of all dependent data points y |
|
199 |
double _sum_xy; // sum of all x * y. |
|
200 |
double _intercept; // constant term |
|
201 |
double _slope; // slope |
|
202 |
// The weighted averages are not currently used but perhaps should |
|
203 |
// be used to get decaying averages. |
|
204 |
AdaptiveWeightedAverage _mean_x; // weighted mean of independent variable |
|
205 |
AdaptiveWeightedAverage _mean_y; // weighted mean of dependent variable |
|
206 |
||
207 |
public: |
|
208 |
LinearLeastSquareFit(unsigned weight); |
|
209 |
void update(double x, double y); |
|
210 |
double y(double x); |
|
211 |
double slope() { return _slope; } |
|
212 |
// Methods to decide if a change in the dependent variable will |
|
22551 | 213 |
// achieve a desired goal. Note that these methods are not |
1 | 214 |
// complementary and both are needed. |
215 |
bool decrement_will_decrease(); |
|
216 |
bool increment_will_decrease(); |
|
217 |
}; |
|
218 |
||
30764 | 219 |
#endif // SHARE_VM_GC_SHARED_GCUTIL_HPP |