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 *
23 */
24
25 #ifndef SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_HPP
26 #define SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_HPP
27
28 #include "gc/shared/collectedHeap.hpp"
29 #include "gc/shared/gcCause.hpp"
30 #include "gc/shared/gcUtil.hpp"
31 #include "logging/log.hpp"
32 #include "memory/allocation.hpp"
33 #include "memory/universe.hpp"
34
35 // This class keeps statistical information and computes the
36 // size of the heap.
37
38 // Forward decls
39 class elapsedTimer;
40 class SoftRefPolicy;
41
42 class AdaptiveSizePolicy : public CHeapObj<mtGC> {
43 friend class GCAdaptivePolicyCounters;
44 friend class PSGCAdaptivePolicyCounters;
45 friend class CMSGCAdaptivePolicyCounters;
46 protected:
47
48 enum GCPolicyKind {
49 _gc_adaptive_size_policy,
50 _gc_ps_adaptive_size_policy,
51 _gc_cms_adaptive_size_policy
52 };
53 virtual GCPolicyKind kind() const { return _gc_adaptive_size_policy; }
171 // decrease the tenuring threshold because of the the total minor GC
172 // cost is greater than the total major GC cost
173 bool _decrement_tenuring_threshold_for_gc_cost;
174 // decrease due to survivor size limit
175 bool _decrement_tenuring_threshold_for_survivor_limit;
176
177 // decrease generation sizes for footprint
178 int _decrease_for_footprint;
179
180 // Set if the ergonomic decisions were made at a full GC.
181 int _decide_at_full_gc;
182
183 // Changing the generation sizing depends on the data that is
184 // gathered about the effects of changes on the pause times and
185 // throughput. These variable count the number of data points
186 // gathered. The policy may use these counters as a threshold
187 // for reliable data.
188 julong _young_gen_change_for_minor_throughput;
189 julong _old_gen_change_for_major_throughput;
190
191 static const uint GCWorkersPerJavaThread = 2;
192
193 // Accessors
194
195 double gc_pause_goal_sec() const { return _gc_pause_goal_sec; }
196 // The value returned is unitless: it's the proportion of time
197 // spent in a particular collection type.
198 // An interval time will be 0.0 if a collection type hasn't occurred yet.
199 // The 1.4.2 implementation put a floor on the values of major_gc_cost
200 // and minor_gc_cost. This was useful because of the way major_gc_cost
201 // and minor_gc_cost was used in calculating the sizes of the generations.
202 // Do not use a floor in this implementation because any finite value
203 // will put a limit on the throughput that can be achieved and any
204 // throughput goal above that limit will drive the generations sizes
205 // to extremes.
206 double major_gc_cost() const {
207 return MAX2(0.0F, _avg_major_gc_cost->average());
208 }
209
210 // The value returned is unitless: it's the proportion of time
211 // spent in a particular collection type.
212 // An interval time will be 0.0 if a collection type hasn't occurred yet.
317 return _decrement_tenuring_threshold_for_gc_cost;
318 }
319 void set_decrement_tenuring_threshold_for_gc_cost(bool v) {
320 _decrement_tenuring_threshold_for_gc_cost = v;
321 }
322 bool increment_tenuring_threshold_for_gc_cost() const {
323 return _increment_tenuring_threshold_for_gc_cost;
324 }
325 void set_increment_tenuring_threshold_for_gc_cost(bool v) {
326 _increment_tenuring_threshold_for_gc_cost = v;
327 }
328 bool decrement_tenuring_threshold_for_survivor_limit() const {
329 return _decrement_tenuring_threshold_for_survivor_limit;
330 }
331 void set_decrement_tenuring_threshold_for_survivor_limit(bool v) {
332 _decrement_tenuring_threshold_for_survivor_limit = v;
333 }
334 // Return true if the policy suggested a change.
335 bool tenuring_threshold_change() const;
336
337 static bool _debug_perturbation;
338
339 public:
340 AdaptiveSizePolicy(size_t init_eden_size,
341 size_t init_promo_size,
342 size_t init_survivor_size,
343 double gc_pause_goal_sec,
344 uint gc_cost_ratio);
345
346 // Return number default GC threads to use in the next GC.
347 static uint calc_default_active_workers(uintx total_workers,
348 const uintx min_workers,
349 uintx active_workers,
350 uintx application_workers);
351
352 // Return number of GC threads to use in the next GC.
353 // This is called sparingly so as not to change the
354 // number of GC workers gratuitously.
355 // For ParNew collections
356 // For PS scavenge and ParOld collections
357 // For G1 evacuation pauses (subject to update)
358 // For G1 Full GCs (subject to update)
359 // Other collection phases inherit the number of
360 // GC workers from the calls above. For example,
361 // a CMS parallel remark uses the same number of GC
362 // workers as the most recent ParNew collection.
363 static uint calc_active_workers(uintx total_workers,
364 uintx active_workers,
365 uintx application_workers);
366
367 // Return number of GC threads to use in the next concurrent GC phase.
368 static uint calc_active_conc_workers(uintx total_workers,
369 uintx active_workers,
370 uintx application_workers);
371
372 bool is_gc_cms_adaptive_size_policy() {
373 return kind() == _gc_cms_adaptive_size_policy;
374 }
375 bool is_gc_ps_adaptive_size_policy() {
376 return kind() == _gc_ps_adaptive_size_policy;
377 }
378
379 AdaptivePaddedAverage* avg_minor_pause() const { return _avg_minor_pause; }
380 AdaptiveWeightedAverage* avg_minor_interval() const {
381 return _avg_minor_interval;
382 }
383 AdaptiveWeightedAverage* avg_minor_gc_cost() const {
384 return _avg_minor_gc_cost;
385 }
386
387 AdaptiveWeightedAverage* avg_major_gc_cost() const {
388 return _avg_major_gc_cost;
389 }
390
|
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 *
23 */
24
25 #ifndef SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_HPP
26 #define SHARE_VM_GC_SHARED_ADAPTIVESIZEPOLICY_HPP
27
28 #include "gc/shared/gcCause.hpp"
29 #include "gc/shared/gcUtil.hpp"
30 #include "memory/allocation.hpp"
31
32 // This class keeps statistical information and computes the
33 // size of the heap.
34
35 // Forward decls
36 class elapsedTimer;
37 class SoftRefPolicy;
38
39 class AdaptiveSizePolicy : public CHeapObj<mtGC> {
40 friend class GCAdaptivePolicyCounters;
41 friend class PSGCAdaptivePolicyCounters;
42 friend class CMSGCAdaptivePolicyCounters;
43 protected:
44
45 enum GCPolicyKind {
46 _gc_adaptive_size_policy,
47 _gc_ps_adaptive_size_policy,
48 _gc_cms_adaptive_size_policy
49 };
50 virtual GCPolicyKind kind() const { return _gc_adaptive_size_policy; }
168 // decrease the tenuring threshold because of the the total minor GC
169 // cost is greater than the total major GC cost
170 bool _decrement_tenuring_threshold_for_gc_cost;
171 // decrease due to survivor size limit
172 bool _decrement_tenuring_threshold_for_survivor_limit;
173
174 // decrease generation sizes for footprint
175 int _decrease_for_footprint;
176
177 // Set if the ergonomic decisions were made at a full GC.
178 int _decide_at_full_gc;
179
180 // Changing the generation sizing depends on the data that is
181 // gathered about the effects of changes on the pause times and
182 // throughput. These variable count the number of data points
183 // gathered. The policy may use these counters as a threshold
184 // for reliable data.
185 julong _young_gen_change_for_minor_throughput;
186 julong _old_gen_change_for_major_throughput;
187
188 // Accessors
189
190 double gc_pause_goal_sec() const { return _gc_pause_goal_sec; }
191 // The value returned is unitless: it's the proportion of time
192 // spent in a particular collection type.
193 // An interval time will be 0.0 if a collection type hasn't occurred yet.
194 // The 1.4.2 implementation put a floor on the values of major_gc_cost
195 // and minor_gc_cost. This was useful because of the way major_gc_cost
196 // and minor_gc_cost was used in calculating the sizes of the generations.
197 // Do not use a floor in this implementation because any finite value
198 // will put a limit on the throughput that can be achieved and any
199 // throughput goal above that limit will drive the generations sizes
200 // to extremes.
201 double major_gc_cost() const {
202 return MAX2(0.0F, _avg_major_gc_cost->average());
203 }
204
205 // The value returned is unitless: it's the proportion of time
206 // spent in a particular collection type.
207 // An interval time will be 0.0 if a collection type hasn't occurred yet.
312 return _decrement_tenuring_threshold_for_gc_cost;
313 }
314 void set_decrement_tenuring_threshold_for_gc_cost(bool v) {
315 _decrement_tenuring_threshold_for_gc_cost = v;
316 }
317 bool increment_tenuring_threshold_for_gc_cost() const {
318 return _increment_tenuring_threshold_for_gc_cost;
319 }
320 void set_increment_tenuring_threshold_for_gc_cost(bool v) {
321 _increment_tenuring_threshold_for_gc_cost = v;
322 }
323 bool decrement_tenuring_threshold_for_survivor_limit() const {
324 return _decrement_tenuring_threshold_for_survivor_limit;
325 }
326 void set_decrement_tenuring_threshold_for_survivor_limit(bool v) {
327 _decrement_tenuring_threshold_for_survivor_limit = v;
328 }
329 // Return true if the policy suggested a change.
330 bool tenuring_threshold_change() const;
331
332 public:
333 AdaptiveSizePolicy(size_t init_eden_size,
334 size_t init_promo_size,
335 size_t init_survivor_size,
336 double gc_pause_goal_sec,
337 uint gc_cost_ratio);
338
339 bool is_gc_cms_adaptive_size_policy() {
340 return kind() == _gc_cms_adaptive_size_policy;
341 }
342 bool is_gc_ps_adaptive_size_policy() {
343 return kind() == _gc_ps_adaptive_size_policy;
344 }
345
346 AdaptivePaddedAverage* avg_minor_pause() const { return _avg_minor_pause; }
347 AdaptiveWeightedAverage* avg_minor_interval() const {
348 return _avg_minor_interval;
349 }
350 AdaptiveWeightedAverage* avg_minor_gc_cost() const {
351 return _avg_minor_gc_cost;
352 }
353
354 AdaptiveWeightedAverage* avg_major_gc_cost() const {
355 return _avg_major_gc_cost;
356 }
357
|