Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/shared/gcUtil.hpp @ 3710:4e037604f6ee
use alignment for constants specified in DataPatch.alignment
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Mon, 05 Dec 2011 18:15:25 -0800 |
parents | f95d63e2154a |
children | 78a1b285cda8 |
rev | line source |
---|---|
0 | 1 /* |
1972 | 2 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1145
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1145
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1145
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_GCUTIL_HPP |
26 #define SHARE_VM_GC_IMPLEMENTATION_SHARED_GCUTIL_HPP | |
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 | |
0 | 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 // | |
46 class AdaptiveWeightedAverage : public CHeapObj { | |
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. | |
53 | |
54 protected: | |
55 float _last_sample; // The last value sampled. | |
56 | |
57 void increment_count() { _sample_count++; } | |
58 void set_average(float avg) { _average = avg; } | |
59 | |
60 // Helper function, computes an adaptive weighted average | |
61 // given a sample and the last average | |
62 float compute_adaptive_average(float new_sample, float average); | |
63 | |
64 public: | |
65 // Input weight must be between 0 and 100 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
66 AdaptiveWeightedAverage(unsigned weight, float avg = 0.0) : |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
67 _average(avg), _sample_count(0), _weight(weight), _last_sample(0.0) { |
0 | 68 } |
69 | |
268
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
70 void clear() { |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
71 _average = 0; |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
72 _sample_count = 0; |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
73 _last_sample = 0; |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
74 } |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
75 |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
76 // Useful for modifying static structures after startup. |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
77 void modify(size_t avg, unsigned wt, bool force = false) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
78 assert(force, "Are you sure you want to call this?"); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
79 _average = (float)avg; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
80 _weight = wt; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
81 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
82 |
0 | 83 // Accessors |
84 float average() const { return _average; } | |
85 unsigned weight() const { return _weight; } | |
86 unsigned count() const { return _sample_count; } | |
87 float last_sample() const { return _last_sample; } | |
88 | |
89 // Update data with a new sample. | |
90 void sample(float new_sample); | |
91 | |
92 static inline float exp_avg(float avg, float sample, | |
93 unsigned int weight) { | |
94 assert(0 <= weight && weight <= 100, "weight must be a percent"); | |
95 return (100.0F - weight) * avg / 100.0F + weight * sample / 100.0F; | |
96 } | |
97 static inline size_t exp_avg(size_t avg, size_t sample, | |
98 unsigned int weight) { | |
99 // Convert to float and back to avoid integer overflow. | |
100 return (size_t)exp_avg((float)avg, (float)sample, weight); | |
101 } | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
102 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
103 // Printing |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
104 void print_on(outputStream* st) const; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
105 void print() const; |
0 | 106 }; |
107 | |
108 | |
109 // A weighted average that includes a deviation from the average, | |
110 // some multiple of which is added to the average. | |
111 // | |
112 // This serves as our best estimate of an upper bound on a future | |
113 // unknown. | |
114 class AdaptivePaddedAverage : public AdaptiveWeightedAverage { | |
115 private: | |
116 float _padded_avg; // The last computed padded average | |
117 float _deviation; // Running deviation from the average | |
118 unsigned _padding; // A multiple which, added to the average, | |
119 // gives us an upper bound guess. | |
120 | |
121 protected: | |
122 void set_padded_average(float avg) { _padded_avg = avg; } | |
123 void set_deviation(float dev) { _deviation = dev; } | |
124 | |
125 public: | |
126 AdaptivePaddedAverage() : | |
127 AdaptiveWeightedAverage(0), | |
128 _padded_avg(0.0), _deviation(0.0), _padding(0) {} | |
129 | |
130 AdaptivePaddedAverage(unsigned weight, unsigned padding) : | |
131 AdaptiveWeightedAverage(weight), | |
132 _padded_avg(0.0), _deviation(0.0), _padding(padding) {} | |
133 | |
134 // Placement support | |
135 void* operator new(size_t ignored, void* p) { return p; } | |
136 // Allocator | |
137 void* operator new(size_t size) { return CHeapObj::operator new(size); } | |
138 | |
139 // Accessor | |
140 float padded_average() const { return _padded_avg; } | |
141 float deviation() const { return _deviation; } | |
142 unsigned padding() const { return _padding; } | |
143 | |
268
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
144 void clear() { |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
145 AdaptiveWeightedAverage::clear(); |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
146 _padded_avg = 0; |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
147 _deviation = 0; |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
148 } |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
149 |
0 | 150 // Override |
151 void sample(float new_sample); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
152 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
153 // Printing |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
154 void print_on(outputStream* st) const; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
155 void print() const; |
0 | 156 }; |
157 | |
158 // A weighted average that includes a deviation from the average, | |
159 // some multiple of which is added to the average. | |
160 // | |
161 // This serves as our best estimate of an upper bound on a future | |
162 // unknown. | |
163 // A special sort of padded average: it doesn't update deviations | |
164 // if the sample is zero. The average is allowed to change. We're | |
165 // preventing the zero samples from drastically changing our padded | |
166 // average. | |
167 class AdaptivePaddedNoZeroDevAverage : public AdaptivePaddedAverage { | |
168 public: | |
169 AdaptivePaddedNoZeroDevAverage(unsigned weight, unsigned padding) : | |
170 AdaptivePaddedAverage(weight, padding) {} | |
171 // Override | |
172 void sample(float new_sample); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
173 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
174 // Printing |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
175 void print_on(outputStream* st) const; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
176 void print() const; |
0 | 177 }; |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
178 |
0 | 179 // Use a least squares fit to a set of data to generate a linear |
180 // equation. | |
181 // y = intercept + slope * x | |
182 | |
183 class LinearLeastSquareFit : public CHeapObj { | |
184 double _sum_x; // sum of all independent data points x | |
185 double _sum_x_squared; // sum of all independent data points x**2 | |
186 double _sum_y; // sum of all dependent data points y | |
187 double _sum_xy; // sum of all x * y. | |
188 double _intercept; // constant term | |
189 double _slope; // slope | |
190 // The weighted averages are not currently used but perhaps should | |
191 // be used to get decaying averages. | |
192 AdaptiveWeightedAverage _mean_x; // weighted mean of independent variable | |
193 AdaptiveWeightedAverage _mean_y; // weighted mean of dependent variable | |
194 | |
195 public: | |
196 LinearLeastSquareFit(unsigned weight); | |
197 void update(double x, double y); | |
198 double y(double x); | |
199 double slope() { return _slope; } | |
200 // Methods to decide if a change in the dependent variable will | |
201 // achive a desired goal. Note that these methods are not | |
202 // complementary and both are needed. | |
203 bool decrement_will_decrease(); | |
204 bool increment_will_decrease(); | |
205 }; | |
206 | |
207 class GCPauseTimer : StackObj { | |
208 elapsedTimer* _timer; | |
209 public: | |
210 GCPauseTimer(elapsedTimer* timer) { | |
211 _timer = timer; | |
212 _timer->stop(); | |
213 } | |
214 ~GCPauseTimer() { | |
215 _timer->start(); | |
216 } | |
217 }; | |
1972 | 218 |
219 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_GCUTIL_HPP |