comparison src/share/vm/gc_implementation/parallelScavenge/psAdaptiveSizePolicy.cpp @ 18058:54bc75c144b0

Merge
author asaha
date Thu, 29 May 2014 13:14:25 -0700
parents 78bbf4d43a14
children 52b4284cb496
comparison
equal deleted inserted replaced
18055:1fa005fb28f5 18058:54bc75c144b0
1 /* 1 /*
2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
21 * questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
26 #include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp" 27 #include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp"
27 #include "gc_implementation/parallelScavenge/psGCAdaptivePolicyCounters.hpp" 28 #include "gc_implementation/parallelScavenge/psGCAdaptivePolicyCounters.hpp"
28 #include "gc_implementation/parallelScavenge/psScavenge.hpp" 29 #include "gc_implementation/parallelScavenge/psScavenge.hpp"
29 #include "gc_implementation/shared/gcPolicyCounters.hpp" 30 #include "gc_implementation/shared/gcPolicyCounters.hpp"
30 #include "gc_interface/gcCause.hpp" 31 #include "gc_interface/gcCause.hpp"
31 #include "memory/collectorPolicy.hpp" 32 #include "memory/collectorPolicy.hpp"
32 #include "runtime/timer.hpp" 33 #include "runtime/timer.hpp"
33 #include "utilities/top.hpp" 34 #include "utilities/top.hpp"
34 35
35 #include <math.h> 36 #include <math.h>
37
38 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
36 39
37 PSAdaptiveSizePolicy::PSAdaptiveSizePolicy(size_t init_eden_size, 40 PSAdaptiveSizePolicy::PSAdaptiveSizePolicy(size_t init_eden_size,
38 size_t init_promo_size, 41 size_t init_promo_size,
39 size_t init_survivor_size, 42 size_t init_survivor_size,
40 size_t space_alignment, 43 size_t space_alignment,
72 75
73 // Start the timers 76 // Start the timers
74 _major_timer.start(); 77 _major_timer.start();
75 78
76 _old_gen_policy_is_ready = false; 79 _old_gen_policy_is_ready = false;
80 }
81
82 size_t PSAdaptiveSizePolicy::calculate_free_based_on_live(size_t live, uintx ratio_as_percentage) {
83 // We want to calculate how much free memory there can be based on the
84 // amount of live data currently in the old gen. Using the formula:
85 // ratio * (free + live) = free
86 // Some equation solving later we get:
87 // free = (live * ratio) / (1 - ratio)
88
89 const double ratio = ratio_as_percentage / 100.0;
90 const double ratio_inverse = 1.0 - ratio;
91 const double tmp = live * ratio;
92 size_t free = (size_t)(tmp / ratio_inverse);
93
94 return free;
95 }
96
97 size_t PSAdaptiveSizePolicy::calculated_old_free_size_in_bytes() const {
98 size_t free_size = (size_t)(_promo_size + avg_promoted()->padded_average());
99 size_t live = ParallelScavengeHeap::heap()->old_gen()->used_in_bytes();
100
101 if (MinHeapFreeRatio != 0) {
102 size_t min_free = calculate_free_based_on_live(live, MinHeapFreeRatio);
103 free_size = MAX2(free_size, min_free);
104 }
105
106 if (MaxHeapFreeRatio != 100) {
107 size_t max_free = calculate_free_based_on_live(live, MaxHeapFreeRatio);
108 free_size = MIN2(max_free, free_size);
109 }
110
111 return free_size;
77 } 112 }
78 113
79 void PSAdaptiveSizePolicy::major_collection_begin() { 114 void PSAdaptiveSizePolicy::major_collection_begin() {
80 // Update the interval time 115 // Update the interval time
81 _major_timer.stop(); 116 _major_timer.stop();
998 if (PrintAdaptiveSizePolicy && Verbose) { 1033 if (PrintAdaptiveSizePolicy && Verbose) {
999 gclog_or_tty->print_cr( 1034 gclog_or_tty->print_cr(
1000 "AdaptiveSizePolicy::adjust_promo_for_footprint " 1035 "AdaptiveSizePolicy::adjust_promo_for_footprint "
1001 "adjusting tenured gen for footprint. " 1036 "adjusting tenured gen for footprint. "
1002 "starting promo size " SIZE_FORMAT 1037 "starting promo size " SIZE_FORMAT
1003 " reduced promo size " SIZE_FORMAT, 1038 " reduced promo size " SIZE_FORMAT
1004 " promo delta " SIZE_FORMAT, 1039 " promo delta " SIZE_FORMAT,
1005 desired_promo_size, reduced_size, change ); 1040 desired_promo_size, reduced_size, change );
1006 } 1041 }
1007 1042
1008 assert(reduced_size <= desired_promo_size, "Inconsistent result"); 1043 assert(reduced_size <= desired_promo_size, "Inconsistent result");
1290 1325
1291 return AdaptiveSizePolicy::print_adaptive_size_policy_on( 1326 return AdaptiveSizePolicy::print_adaptive_size_policy_on(
1292 st, 1327 st,
1293 PSScavenge::tenuring_threshold()); 1328 PSScavenge::tenuring_threshold());
1294 } 1329 }
1330
1331 #ifndef PRODUCT
1332
1333 void TestOldFreeSpaceCalculation_test() {
1334 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 20) == 25, "Calculation of free memory failed");
1335 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 50) == 100, "Calculation of free memory failed");
1336 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 60) == 150, "Calculation of free memory failed");
1337 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(100, 75) == 300, "Calculation of free memory failed");
1338 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 20) == 100, "Calculation of free memory failed");
1339 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 50) == 400, "Calculation of free memory failed");
1340 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 60) == 600, "Calculation of free memory failed");
1341 assert(PSAdaptiveSizePolicy::calculate_free_based_on_live(400, 75) == 1200, "Calculation of free memory failed");
1342 }
1343
1344 #endif /* !PRODUCT */