Mercurial > hg > truffle
annotate src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp @ 10810:4e1db4c9d4c5
Support data patches for values larger than long.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Thu, 18 Jul 2013 15:37:02 +0200 |
parents | 14d3f71f831d |
children | c49c7f835e8d |
rev | line source |
---|---|
0 | 1 /* |
10288
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
2 * Copyright (c) 2002, 2013, 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:
1387
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1387
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:
1387
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSADAPTIVESIZEPOLICY_HPP |
26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSADAPTIVESIZEPOLICY_HPP | |
27 | |
28 #include "gc_implementation/shared/adaptiveSizePolicy.hpp" | |
29 #include "gc_implementation/shared/gcStats.hpp" | |
30 #include "gc_implementation/shared/gcUtil.hpp" | |
31 #include "gc_interface/gcCause.hpp" | |
32 | |
0 | 33 // This class keeps statistical information and computes the |
34 // optimal free space for both the young and old generation | |
35 // based on current application characteristics (based on gc cost | |
36 // and application footprint). | |
37 // | |
38 // It also computes an optimal tenuring threshold between the young | |
39 // and old generations, so as to equalize the cost of collections | |
40 // of those generations, as well as optimial survivor space sizes | |
41 // for the young generation. | |
42 // | |
43 // While this class is specifically intended for a generational system | |
44 // consisting of a young gen (containing an Eden and two semi-spaces) | |
45 // and a tenured gen, as well as a perm gen for reflective data, it | |
46 // makes NO references to specific generations. | |
47 // | |
48 // 05/02/2003 Update | |
49 // The 1.5 policy makes use of data gathered for the costs of GC on | |
50 // specific generations. That data does reference specific | |
51 // generation. Also diagnostics specific to generations have | |
52 // been added. | |
53 | |
54 // Forward decls | |
55 class elapsedTimer; | |
1387
0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
jmasa
parents:
0
diff
changeset
|
56 class GenerationSizer; |
0 | 57 |
58 class PSAdaptiveSizePolicy : public AdaptiveSizePolicy { | |
59 friend class PSGCAdaptivePolicyCounters; | |
60 private: | |
61 // These values are used to record decisions made during the | |
62 // policy. For example, if the young generation was decreased | |
63 // to decrease the GC cost of minor collections the value | |
64 // decrease_young_gen_for_throughput_true is used. | |
65 | |
66 // Last calculated sizes, in bytes, and aligned | |
67 // NEEDS_CLEANUP should use sizes.hpp, but it works in ints, not size_t's | |
68 | |
69 // Time statistics | |
70 AdaptivePaddedAverage* _avg_major_pause; | |
71 | |
72 // Footprint statistics | |
73 AdaptiveWeightedAverage* _avg_base_footprint; | |
74 | |
75 // Statistical data gathered for GC | |
76 GCStats _gc_stats; | |
77 | |
78 size_t _survivor_size_limit; // Limit in bytes of survivor size | |
79 const double _collection_cost_margin_fraction; | |
80 | |
81 // Variable for estimating the major and minor pause times. | |
82 // These variables represent linear least-squares fits of | |
83 // the data. | |
84 // major pause time vs. old gen size | |
85 LinearLeastSquareFit* _major_pause_old_estimator; | |
86 // major pause time vs. young gen size | |
87 LinearLeastSquareFit* _major_pause_young_estimator; | |
88 | |
89 | |
90 // These record the most recent collection times. They | |
91 // are available as an alternative to using the averages | |
92 // for making ergonomic decisions. | |
93 double _latest_major_mutator_interval_seconds; | |
94 | |
95 const size_t _intra_generation_alignment; // alignment for eden, survivors | |
96 | |
97 const double _gc_minor_pause_goal_sec; // goal for maximum minor gc pause | |
98 | |
99 // The amount of live data in the heap at the last full GC, used | |
100 // as a baseline to help us determine when we need to perform the | |
101 // next full GC. | |
102 size_t _live_at_last_full_gc; | |
103 | |
104 // decrease/increase the old generation for minor pause time | |
105 int _change_old_gen_for_min_pauses; | |
106 | |
107 // increase/decrease the young generation for major pause time | |
108 int _change_young_gen_for_maj_pauses; | |
109 | |
110 | |
111 // Flag indicating that the adaptive policy is ready to use | |
112 bool _old_gen_policy_is_ready; | |
113 | |
114 // Changing the generation sizing depends on the data that is | |
115 // gathered about the effects of changes on the pause times and | |
116 // throughput. These variable count the number of data points | |
117 // gathered. The policy may use these counters as a threshhold | |
118 // for reliable data. | |
119 julong _young_gen_change_for_major_pause_count; | |
120 | |
121 // To facilitate faster growth at start up, supplement the normal | |
122 // growth percentage for the young gen eden and the | |
123 // old gen space for promotion with these value which decay | |
124 // with increasing collections. | |
125 uint _young_gen_size_increment_supplement; | |
126 uint _old_gen_size_increment_supplement; | |
127 | |
128 // The number of bytes absorbed from eden into the old gen by moving the | |
129 // boundary over live data. | |
130 size_t _bytes_absorbed_from_eden; | |
131 | |
132 private: | |
133 | |
134 // Accessors | |
135 AdaptivePaddedAverage* avg_major_pause() const { return _avg_major_pause; } | |
136 double gc_minor_pause_goal_sec() const { return _gc_minor_pause_goal_sec; } | |
137 | |
138 // Change the young generation size to achieve a minor GC pause time goal | |
10288
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
139 void adjust_promo_for_minor_pause_time(bool is_full_gc, |
0 | 140 size_t* desired_promo_size_ptr, |
141 size_t* desired_eden_size_ptr); | |
10288
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
142 void adjust_eden_for_minor_pause_time(bool is_full_gc, |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
143 size_t* desired_eden_size_ptr); |
0 | 144 // Change the generation sizes to achieve a GC pause time goal |
145 // Returned sizes are not necessarily aligned. | |
10288
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
146 void adjust_promo_for_pause_time(bool is_full_gc, |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
147 size_t* desired_promo_size_ptr, |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
148 size_t* desired_eden_size_ptr); |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
149 void adjust_eden_for_pause_time(bool is_full_gc, |
0 | 150 size_t* desired_promo_size_ptr, |
151 size_t* desired_eden_size_ptr); | |
152 // Change the generation sizes to achieve an application throughput goal | |
153 // Returned sizes are not necessarily aligned. | |
10288
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
154 void adjust_promo_for_throughput(bool is_full_gc, |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
155 size_t* desired_promo_size_ptr); |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
156 void adjust_eden_for_throughput(bool is_full_gc, |
0 | 157 size_t* desired_eden_size_ptr); |
158 // Change the generation sizes to achieve minimum footprint | |
159 // Returned sizes are not aligned. | |
160 size_t adjust_promo_for_footprint(size_t desired_promo_size, | |
161 size_t desired_total); | |
162 size_t adjust_eden_for_footprint(size_t desired_promo_size, | |
163 size_t desired_total); | |
164 | |
165 // Size in bytes for an increment or decrement of eden. | |
166 virtual size_t eden_increment(size_t cur_eden, uint percent_change); | |
167 virtual size_t eden_decrement(size_t cur_eden); | |
168 size_t eden_decrement_aligned_down(size_t cur_eden); | |
169 size_t eden_increment_with_supplement_aligned_up(size_t cur_eden); | |
170 | |
171 // Size in bytes for an increment or decrement of the promotion area | |
172 virtual size_t promo_increment(size_t cur_promo, uint percent_change); | |
173 virtual size_t promo_decrement(size_t cur_promo); | |
174 size_t promo_decrement_aligned_down(size_t cur_promo); | |
175 size_t promo_increment_with_supplement_aligned_up(size_t cur_promo); | |
176 | |
177 // Returns a change that has been scaled down. Result | |
178 // is not aligned. (If useful, move to some shared | |
179 // location.) | |
180 size_t scale_down(size_t change, double part, double total); | |
181 | |
182 protected: | |
183 // Time accessors | |
184 | |
185 // Footprint accessors | |
186 size_t live_space() const { | |
187 return (size_t)(avg_base_footprint()->average() + | |
188 avg_young_live()->average() + | |
189 avg_old_live()->average()); | |
190 } | |
191 size_t free_space() const { | |
192 return _eden_size + _promo_size; | |
193 } | |
194 | |
195 void set_promo_size(size_t new_size) { | |
196 _promo_size = new_size; | |
197 } | |
198 void set_survivor_size(size_t new_size) { | |
199 _survivor_size = new_size; | |
200 } | |
201 | |
202 // Update estimators | |
203 void update_minor_pause_old_estimator(double minor_pause_in_ms); | |
204 | |
205 virtual GCPolicyKind kind() const { return _gc_ps_adaptive_size_policy; } | |
206 | |
207 public: | |
208 // Use by ASPSYoungGen and ASPSOldGen to limit boundary moving. | |
209 size_t eden_increment_aligned_up(size_t cur_eden); | |
210 size_t eden_increment_aligned_down(size_t cur_eden); | |
211 size_t promo_increment_aligned_up(size_t cur_promo); | |
212 size_t promo_increment_aligned_down(size_t cur_promo); | |
213 | |
214 virtual size_t eden_increment(size_t cur_eden); | |
215 virtual size_t promo_increment(size_t cur_promo); | |
216 | |
217 // Accessors for use by performance counters | |
218 AdaptivePaddedNoZeroDevAverage* avg_promoted() const { | |
219 return _gc_stats.avg_promoted(); | |
220 } | |
221 AdaptiveWeightedAverage* avg_base_footprint() const { | |
222 return _avg_base_footprint; | |
223 } | |
224 | |
225 // Input arguments are initial free space sizes for young and old | |
226 // generations, the initial survivor space size, the | |
227 // alignment values and the pause & throughput goals. | |
228 // | |
229 // NEEDS_CLEANUP this is a singleton object | |
230 PSAdaptiveSizePolicy(size_t init_eden_size, | |
231 size_t init_promo_size, | |
232 size_t init_survivor_size, | |
233 size_t intra_generation_alignment, | |
234 double gc_pause_goal_sec, | |
235 double gc_minor_pause_goal_sec, | |
236 uint gc_time_ratio); | |
237 | |
238 // Methods indicating events of interest to the adaptive size policy, | |
239 // called by GC algorithms. It is the responsibility of users of this | |
240 // policy to call these methods at the correct times! | |
241 void major_collection_begin(); | |
242 void major_collection_end(size_t amount_live, GCCause::Cause gc_cause); | |
243 | |
244 // | |
245 void tenured_allocation(size_t size) { | |
246 _avg_pretenured->sample(size); | |
247 } | |
248 | |
249 // Accessors | |
250 // NEEDS_CLEANUP should use sizes.hpp | |
251 | |
252 size_t calculated_old_free_size_in_bytes() const { | |
253 return (size_t)(_promo_size + avg_promoted()->padded_average()); | |
254 } | |
255 | |
256 size_t average_old_live_in_bytes() const { | |
257 return (size_t) avg_old_live()->average(); | |
258 } | |
259 | |
260 size_t average_promoted_in_bytes() const { | |
261 return (size_t)avg_promoted()->average(); | |
262 } | |
263 | |
264 size_t padded_average_promoted_in_bytes() const { | |
265 return (size_t)avg_promoted()->padded_average(); | |
266 } | |
267 | |
268 int change_young_gen_for_maj_pauses() { | |
269 return _change_young_gen_for_maj_pauses; | |
270 } | |
271 void set_change_young_gen_for_maj_pauses(int v) { | |
272 _change_young_gen_for_maj_pauses = v; | |
273 } | |
274 | |
275 int change_old_gen_for_min_pauses() { | |
276 return _change_old_gen_for_min_pauses; | |
277 } | |
278 void set_change_old_gen_for_min_pauses(int v) { | |
279 _change_old_gen_for_min_pauses = v; | |
280 } | |
281 | |
282 // Return true if the old generation size was changed | |
283 // to try to reach a pause time goal. | |
284 bool old_gen_changed_for_pauses() { | |
285 bool result = _change_old_gen_for_maj_pauses != 0 || | |
286 _change_old_gen_for_min_pauses != 0; | |
287 return result; | |
288 } | |
289 | |
290 // Return true if the young generation size was changed | |
291 // to try to reach a pause time goal. | |
292 bool young_gen_changed_for_pauses() { | |
293 bool result = _change_young_gen_for_min_pauses != 0 || | |
294 _change_young_gen_for_maj_pauses != 0; | |
295 return result; | |
296 } | |
297 // end flags for pause goal | |
298 | |
299 // Return true if the old generation size was changed | |
300 // to try to reach a throughput goal. | |
301 bool old_gen_changed_for_throughput() { | |
302 bool result = _change_old_gen_for_throughput != 0; | |
303 return result; | |
304 } | |
305 | |
306 // Return true if the young generation size was changed | |
307 // to try to reach a throughput goal. | |
308 bool young_gen_changed_for_throughput() { | |
309 bool result = _change_young_gen_for_throughput != 0; | |
310 return result; | |
311 } | |
312 | |
313 int decrease_for_footprint() { return _decrease_for_footprint; } | |
314 | |
315 | |
316 // Accessors for estimators. The slope of the linear fit is | |
317 // currently all that is used for making decisions. | |
318 | |
319 LinearLeastSquareFit* major_pause_old_estimator() { | |
320 return _major_pause_old_estimator; | |
321 } | |
322 | |
323 LinearLeastSquareFit* major_pause_young_estimator() { | |
324 return _major_pause_young_estimator; | |
325 } | |
326 | |
327 | |
328 virtual void clear_generation_free_space_flags(); | |
329 | |
330 float major_pause_old_slope() { return _major_pause_old_estimator->slope(); } | |
331 float major_pause_young_slope() { | |
332 return _major_pause_young_estimator->slope(); | |
333 } | |
334 float major_collection_slope() { return _major_collection_estimator->slope();} | |
335 | |
336 bool old_gen_policy_is_ready() { return _old_gen_policy_is_ready; } | |
337 | |
338 // Given the amount of live data in the heap, should we | |
339 // perform a Full GC? | |
340 bool should_full_GC(size_t live_in_old_gen); | |
341 | |
10288
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
342 // Calculates optimal (free) space sizes for both the young and old |
0 | 343 // generations. Stores results in _eden_size and _promo_size. |
344 // Takes current used space in all generations as input, as well | |
345 // as an indication if a full gc has just been performed, for use | |
346 // in deciding if an OOM error should be thrown. | |
10359
14d3f71f831d
8007762: Rename a bunch of methods in size policy across collectors
tamao
parents:
10288
diff
changeset
|
347 void compute_generations_free_space(size_t young_live, |
14d3f71f831d
8007762: Rename a bunch of methods in size policy across collectors
tamao
parents:
10288
diff
changeset
|
348 size_t eden_live, |
14d3f71f831d
8007762: Rename a bunch of methods in size policy across collectors
tamao
parents:
10288
diff
changeset
|
349 size_t old_live, |
14d3f71f831d
8007762: Rename a bunch of methods in size policy across collectors
tamao
parents:
10288
diff
changeset
|
350 size_t cur_eden, // current eden in bytes |
14d3f71f831d
8007762: Rename a bunch of methods in size policy across collectors
tamao
parents:
10288
diff
changeset
|
351 size_t max_old_gen_size, |
14d3f71f831d
8007762: Rename a bunch of methods in size policy across collectors
tamao
parents:
10288
diff
changeset
|
352 size_t max_eden_size, |
14d3f71f831d
8007762: Rename a bunch of methods in size policy across collectors
tamao
parents:
10288
diff
changeset
|
353 bool is_full_gc); |
10288
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
354 |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
355 void compute_eden_space_size(size_t young_live, |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
356 size_t eden_live, |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
357 size_t cur_eden, // current eden in bytes |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
358 size_t max_eden_size, |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
359 bool is_full_gc); |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
360 |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
361 void compute_old_gen_free_space(size_t old_live, |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
362 size_t cur_eden, // current eden in bytes |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
363 size_t max_old_gen_size, |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
364 bool is_full_gc); |
0 | 365 |
366 // Calculates new survivor space size; returns a new tenuring threshold | |
367 // value. Stores new survivor size in _survivor_size. | |
6818 | 368 uint compute_survivor_space_size_and_threshold(bool is_survivor_overflow, |
369 uint tenuring_threshold, | |
370 size_t survivor_limit); | |
0 | 371 |
372 // Return the maximum size of a survivor space if the young generation were of | |
373 // size gen_size. | |
374 size_t max_survivor_size(size_t gen_size) { | |
375 // Never allow the target survivor size to grow more than MinSurvivorRatio | |
376 // of the young generation size. We cannot grow into a two semi-space | |
377 // system, with Eden zero sized. Even if the survivor space grows, from() | |
378 // might grow by moving the bottom boundary "down" -- so from space will | |
379 // remain almost full anyway (top() will be near end(), but there will be a | |
380 // large filler object at the bottom). | |
381 const size_t sz = gen_size / MinSurvivorRatio; | |
382 const size_t alignment = _intra_generation_alignment; | |
383 return sz > alignment ? align_size_down(sz, alignment) : alignment; | |
384 } | |
385 | |
386 size_t live_at_last_full_gc() { | |
387 return _live_at_last_full_gc; | |
388 } | |
389 | |
390 size_t bytes_absorbed_from_eden() const { return _bytes_absorbed_from_eden; } | |
391 void reset_bytes_absorbed_from_eden() { _bytes_absorbed_from_eden = 0; } | |
392 | |
393 void set_bytes_absorbed_from_eden(size_t val) { | |
394 _bytes_absorbed_from_eden = val; | |
395 } | |
396 | |
397 // Update averages that are always used (even | |
398 // if adaptive sizing is turned off). | |
399 void update_averages(bool is_survivor_overflow, | |
400 size_t survived, | |
401 size_t promoted); | |
402 | |
403 // Printing support | |
404 virtual bool print_adaptive_size_policy_on(outputStream* st) const; | |
10288
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
405 |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
406 // Decay the supplemental growth additive. |
eba99d16dc6f
8007763: Refactoring: split up compute_generation_free_space() into two functions for class PSAdaptiveSizePolicy
tamao
parents:
6818
diff
changeset
|
407 void decay_supplemental_growth(bool is_full_gc); |
0 | 408 }; |
1972 | 409 |
410 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSADAPTIVESIZEPOLICY_HPP |