Mercurial > hg > graal-compiler
annotate src/share/vm/gc_implementation/shared/gcUtil.hpp @ 1465:2c754f3a2722
Inlining of static final field values. Java mirror instead of VmID. Support for PrintMetrics option.
author | Thomas Wuerthinger <wuerthinger@ssw.jku.at> |
---|---|
date | Thu, 18 Nov 2010 17:27:43 +0100 |
parents | e018e6884bd8 |
children | c18cbe5936b8 |
rev | line source |
---|---|
0 | 1 /* |
337 | 2 * Copyright 2002-2008 Sun Microsystems, Inc. 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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // Catch-all file for utility classes | |
26 | |
27 // A weighted average maintains a running, weighted average | |
28 // of some float value (templates would be handy here if we | |
29 // need different types). | |
30 // | |
31 // The average is adaptive in that we smooth it for the | |
32 // initial samples; we don't use the weight until we have | |
33 // enough samples for it to be meaningful. | |
34 // | |
35 // This serves as our best estimate of a future unknown. | |
36 // | |
37 class AdaptiveWeightedAverage : public CHeapObj { | |
38 private: | |
39 float _average; // The last computed average | |
40 unsigned _sample_count; // How often we've sampled this average | |
41 unsigned _weight; // The weight used to smooth the averages | |
42 // A higher weight favors the most | |
43 // recent data. | |
44 | |
45 protected: | |
46 float _last_sample; // The last value sampled. | |
47 | |
48 void increment_count() { _sample_count++; } | |
49 void set_average(float avg) { _average = avg; } | |
50 | |
51 // Helper function, computes an adaptive weighted average | |
52 // given a sample and the last average | |
53 float compute_adaptive_average(float new_sample, float average); | |
54 | |
55 public: | |
56 // Input weight must be between 0 and 100 | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
57 AdaptiveWeightedAverage(unsigned weight, float avg = 0.0) : |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
58 _average(avg), _sample_count(0), _weight(weight), _last_sample(0.0) { |
0 | 59 } |
60 | |
268
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
61 void clear() { |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
62 _average = 0; |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
63 _sample_count = 0; |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
64 _last_sample = 0; |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
65 } |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
66 |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
67 // Useful for modifying static structures after startup. |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
68 void modify(size_t avg, unsigned wt, bool force = false) { |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
69 assert(force, "Are you sure you want to call this?"); |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
70 _average = (float)avg; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
71 _weight = wt; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
72 } |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
73 |
0 | 74 // Accessors |
75 float average() const { return _average; } | |
76 unsigned weight() const { return _weight; } | |
77 unsigned count() const { return _sample_count; } | |
78 float last_sample() const { return _last_sample; } | |
79 | |
80 // Update data with a new sample. | |
81 void sample(float new_sample); | |
82 | |
83 static inline float exp_avg(float avg, float sample, | |
84 unsigned int weight) { | |
85 assert(0 <= weight && weight <= 100, "weight must be a percent"); | |
86 return (100.0F - weight) * avg / 100.0F + weight * sample / 100.0F; | |
87 } | |
88 static inline size_t exp_avg(size_t avg, size_t sample, | |
89 unsigned int weight) { | |
90 // Convert to float and back to avoid integer overflow. | |
91 return (size_t)exp_avg((float)avg, (float)sample, weight); | |
92 } | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
93 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
94 // Printing |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
95 void print_on(outputStream* st) const; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
96 void print() const; |
0 | 97 }; |
98 | |
99 | |
100 // A weighted average that includes a deviation from the average, | |
101 // some multiple of which is added to the average. | |
102 // | |
103 // This serves as our best estimate of an upper bound on a future | |
104 // unknown. | |
105 class AdaptivePaddedAverage : public AdaptiveWeightedAverage { | |
106 private: | |
107 float _padded_avg; // The last computed padded average | |
108 float _deviation; // Running deviation from the average | |
109 unsigned _padding; // A multiple which, added to the average, | |
110 // gives us an upper bound guess. | |
111 | |
112 protected: | |
113 void set_padded_average(float avg) { _padded_avg = avg; } | |
114 void set_deviation(float dev) { _deviation = dev; } | |
115 | |
116 public: | |
117 AdaptivePaddedAverage() : | |
118 AdaptiveWeightedAverage(0), | |
119 _padded_avg(0.0), _deviation(0.0), _padding(0) {} | |
120 | |
121 AdaptivePaddedAverage(unsigned weight, unsigned padding) : | |
122 AdaptiveWeightedAverage(weight), | |
123 _padded_avg(0.0), _deviation(0.0), _padding(padding) {} | |
124 | |
125 // Placement support | |
126 void* operator new(size_t ignored, void* p) { return p; } | |
127 // Allocator | |
128 void* operator new(size_t size) { return CHeapObj::operator new(size); } | |
129 | |
130 // Accessor | |
131 float padded_average() const { return _padded_avg; } | |
132 float deviation() const { return _deviation; } | |
133 unsigned padding() const { return _padding; } | |
134 | |
268
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
135 void clear() { |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
136 AdaptiveWeightedAverage::clear(); |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
137 _padded_avg = 0; |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
138 _deviation = 0; |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
139 } |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
0
diff
changeset
|
140 |
0 | 141 // Override |
142 void sample(float new_sample); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
143 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
144 // Printing |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
145 void print_on(outputStream* st) const; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
146 void print() const; |
0 | 147 }; |
148 | |
149 // A weighted average that includes a deviation from the average, | |
150 // some multiple of which is added to the average. | |
151 // | |
152 // This serves as our best estimate of an upper bound on a future | |
153 // unknown. | |
154 // A special sort of padded average: it doesn't update deviations | |
155 // if the sample is zero. The average is allowed to change. We're | |
156 // preventing the zero samples from drastically changing our padded | |
157 // average. | |
158 class AdaptivePaddedNoZeroDevAverage : public AdaptivePaddedAverage { | |
159 public: | |
160 AdaptivePaddedNoZeroDevAverage(unsigned weight, unsigned padding) : | |
161 AdaptivePaddedAverage(weight, padding) {} | |
162 // Override | |
163 void sample(float new_sample); | |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
164 |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
165 // Printing |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
166 void print_on(outputStream* st) const; |
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
167 void print() const; |
0 | 168 }; |
1145
e018e6884bd8
6631166: CMS: better heuristics when combatting fragmentation
ysr
parents:
337
diff
changeset
|
169 |
0 | 170 // Use a least squares fit to a set of data to generate a linear |
171 // equation. | |
172 // y = intercept + slope * x | |
173 | |
174 class LinearLeastSquareFit : public CHeapObj { | |
175 double _sum_x; // sum of all independent data points x | |
176 double _sum_x_squared; // sum of all independent data points x**2 | |
177 double _sum_y; // sum of all dependent data points y | |
178 double _sum_xy; // sum of all x * y. | |
179 double _intercept; // constant term | |
180 double _slope; // slope | |
181 // The weighted averages are not currently used but perhaps should | |
182 // be used to get decaying averages. | |
183 AdaptiveWeightedAverage _mean_x; // weighted mean of independent variable | |
184 AdaptiveWeightedAverage _mean_y; // weighted mean of dependent variable | |
185 | |
186 public: | |
187 LinearLeastSquareFit(unsigned weight); | |
188 void update(double x, double y); | |
189 double y(double x); | |
190 double slope() { return _slope; } | |
191 // Methods to decide if a change in the dependent variable will | |
192 // achive a desired goal. Note that these methods are not | |
193 // complementary and both are needed. | |
194 bool decrement_will_decrease(); | |
195 bool increment_will_decrease(); | |
196 }; | |
197 | |
198 class GCPauseTimer : StackObj { | |
199 elapsedTimer* _timer; | |
200 public: | |
201 GCPauseTimer(elapsedTimer* timer) { | |
202 _timer = timer; | |
203 _timer->stop(); | |
204 } | |
205 ~GCPauseTimer() { | |
206 _timer->start(); | |
207 } | |
208 }; |