annotate src/share/vm/gc_implementation/shared/adaptiveSizePolicy.cpp @ 989:148e5441d916

6863023: need non-perm oops in code cache for JSR 292 Summary: Make a special root-list for those few nmethods which might contain non-perm oops. Reviewed-by: twisti, kvn, never, jmasa, ysr
author jrose
date Tue, 15 Sep 2009 21:53:47 -0700
parents a61af66fc99e
children 0bfd3fb24150
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_adaptiveSizePolicy.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 elapsedTimer AdaptiveSizePolicy::_minor_timer;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 elapsedTimer AdaptiveSizePolicy::_major_timer;
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // The throughput goal is implemented as
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // _throughput_goal = 1 - ( 1 / (1 + gc_cost_ratio))
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // gc_cost_ratio is the ratio
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // application cost / gc cost
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // For example a gc_cost_ratio of 4 translates into a
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // throughput goal of .80
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 AdaptiveSizePolicy::AdaptiveSizePolicy(size_t init_eden_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
38 size_t init_promo_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
39 size_t init_survivor_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
40 double gc_pause_goal_sec,
a61af66fc99e Initial load
duke
parents:
diff changeset
41 uint gc_cost_ratio) :
a61af66fc99e Initial load
duke
parents:
diff changeset
42 _eden_size(init_eden_size),
a61af66fc99e Initial load
duke
parents:
diff changeset
43 _promo_size(init_promo_size),
a61af66fc99e Initial load
duke
parents:
diff changeset
44 _survivor_size(init_survivor_size),
a61af66fc99e Initial load
duke
parents:
diff changeset
45 _gc_pause_goal_sec(gc_pause_goal_sec),
a61af66fc99e Initial load
duke
parents:
diff changeset
46 _throughput_goal(1.0 - double(1.0 / (1.0 + (double) gc_cost_ratio))),
a61af66fc99e Initial load
duke
parents:
diff changeset
47 _gc_time_limit_exceeded(false),
a61af66fc99e Initial load
duke
parents:
diff changeset
48 _print_gc_time_limit_would_be_exceeded(false),
a61af66fc99e Initial load
duke
parents:
diff changeset
49 _gc_time_limit_count(0),
a61af66fc99e Initial load
duke
parents:
diff changeset
50 _latest_minor_mutator_interval_seconds(0),
a61af66fc99e Initial load
duke
parents:
diff changeset
51 _threshold_tolerance_percent(1.0 + ThresholdTolerance/100.0),
a61af66fc99e Initial load
duke
parents:
diff changeset
52 _young_gen_change_for_minor_throughput(0),
a61af66fc99e Initial load
duke
parents:
diff changeset
53 _old_gen_change_for_major_throughput(0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 _avg_minor_pause =
a61af66fc99e Initial load
duke
parents:
diff changeset
55 new AdaptivePaddedAverage(AdaptiveTimeWeight, PausePadding);
a61af66fc99e Initial load
duke
parents:
diff changeset
56 _avg_minor_interval = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 _avg_minor_gc_cost = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 _avg_major_gc_cost = new AdaptiveWeightedAverage(AdaptiveTimeWeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 _avg_young_live = new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 _avg_old_live = new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 _avg_eden_live = new AdaptiveWeightedAverage(AdaptiveSizePolicyWeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 _avg_survived = new AdaptivePaddedAverage(AdaptiveSizePolicyWeight,
a61af66fc99e Initial load
duke
parents:
diff changeset
65 SurvivorPadding);
a61af66fc99e Initial load
duke
parents:
diff changeset
66 _avg_pretenured = new AdaptivePaddedNoZeroDevAverage(
a61af66fc99e Initial load
duke
parents:
diff changeset
67 AdaptiveSizePolicyWeight,
a61af66fc99e Initial load
duke
parents:
diff changeset
68 SurvivorPadding);
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 _minor_pause_old_estimator =
a61af66fc99e Initial load
duke
parents:
diff changeset
71 new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 _minor_pause_young_estimator =
a61af66fc99e Initial load
duke
parents:
diff changeset
73 new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 _minor_collection_estimator =
a61af66fc99e Initial load
duke
parents:
diff changeset
75 new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 _major_collection_estimator =
a61af66fc99e Initial load
duke
parents:
diff changeset
77 new LinearLeastSquareFit(AdaptiveSizePolicyWeight);
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // Start the timers
a61af66fc99e Initial load
duke
parents:
diff changeset
80 _minor_timer.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 _young_gen_policy_is_ready = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 bool AdaptiveSizePolicy::tenuring_threshold_change() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 return decrement_tenuring_threshold_for_gc_cost() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
87 increment_tenuring_threshold_for_gc_cost() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
88 decrement_tenuring_threshold_for_survivor_limit();
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 void AdaptiveSizePolicy::minor_collection_begin() {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // Update the interval time
a61af66fc99e Initial load
duke
parents:
diff changeset
93 _minor_timer.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // Save most recent collection time
a61af66fc99e Initial load
duke
parents:
diff changeset
95 _latest_minor_mutator_interval_seconds = _minor_timer.seconds();
a61af66fc99e Initial load
duke
parents:
diff changeset
96 _minor_timer.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
97 _minor_timer.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 void AdaptiveSizePolicy::update_minor_pause_young_estimator(
a61af66fc99e Initial load
duke
parents:
diff changeset
101 double minor_pause_in_ms) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 double eden_size_in_mbytes = ((double)_eden_size)/((double)M);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 _minor_pause_young_estimator->update(eden_size_in_mbytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
104 minor_pause_in_ms);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 void AdaptiveSizePolicy::minor_collection_end(GCCause::Cause gc_cause) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // Update the pause time.
a61af66fc99e Initial load
duke
parents:
diff changeset
109 _minor_timer.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (gc_cause != GCCause::_java_lang_system_gc ||
a61af66fc99e Initial load
duke
parents:
diff changeset
112 UseAdaptiveSizePolicyWithSystemGC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 double minor_pause_in_seconds = _minor_timer.seconds();
a61af66fc99e Initial load
duke
parents:
diff changeset
114 double minor_pause_in_ms = minor_pause_in_seconds * MILLIUNITS;
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // Sample for performance counter
a61af66fc99e Initial load
duke
parents:
diff changeset
117 _avg_minor_pause->sample(minor_pause_in_seconds);
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Cost of collection (unit-less)
a61af66fc99e Initial load
duke
parents:
diff changeset
120 double collection_cost = 0.0;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if ((_latest_minor_mutator_interval_seconds > 0.0) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
122 (minor_pause_in_seconds > 0.0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 double interval_in_seconds =
a61af66fc99e Initial load
duke
parents:
diff changeset
124 _latest_minor_mutator_interval_seconds + minor_pause_in_seconds;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 collection_cost =
a61af66fc99e Initial load
duke
parents:
diff changeset
126 minor_pause_in_seconds / interval_in_seconds;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 _avg_minor_gc_cost->sample(collection_cost);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // Sample for performance counter
a61af66fc99e Initial load
duke
parents:
diff changeset
129 _avg_minor_interval->sample(interval_in_seconds);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // The policy does not have enough data until at least some
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // minor collections have been done.
a61af66fc99e Initial load
duke
parents:
diff changeset
134 _young_gen_policy_is_ready =
a61af66fc99e Initial load
duke
parents:
diff changeset
135 (_avg_minor_gc_cost->count() >= AdaptiveSizePolicyReadyThreshold);
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // Calculate variables used to estimate pause time vs. gen sizes
a61af66fc99e Initial load
duke
parents:
diff changeset
138 double eden_size_in_mbytes = ((double)_eden_size)/((double)M);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 update_minor_pause_young_estimator(minor_pause_in_ms);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 update_minor_pause_old_estimator(minor_pause_in_ms);
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (PrintAdaptiveSizePolicy && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 gclog_or_tty->print("AdaptiveSizePolicy::minor_collection_end: "
a61af66fc99e Initial load
duke
parents:
diff changeset
144 "minor gc cost: %f average: %f", collection_cost,
a61af66fc99e Initial load
duke
parents:
diff changeset
145 _avg_minor_gc_cost->average());
a61af66fc99e Initial load
duke
parents:
diff changeset
146 gclog_or_tty->print_cr(" minor pause: %f minor period %f",
a61af66fc99e Initial load
duke
parents:
diff changeset
147 minor_pause_in_ms,
a61af66fc99e Initial load
duke
parents:
diff changeset
148 _latest_minor_mutator_interval_seconds * MILLIUNITS);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // Calculate variable used to estimate collection cost vs. gen sizes
a61af66fc99e Initial load
duke
parents:
diff changeset
152 assert(collection_cost >= 0.0, "Expected to be non-negative");
a61af66fc99e Initial load
duke
parents:
diff changeset
153 _minor_collection_estimator->update(eden_size_in_mbytes, collection_cost);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // Interval times use this timer to measure the mutator time.
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // Reset the timer after the GC pause.
a61af66fc99e Initial load
duke
parents:
diff changeset
158 _minor_timer.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
159 _minor_timer.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 size_t AdaptiveSizePolicy::eden_increment(size_t cur_eden,
a61af66fc99e Initial load
duke
parents:
diff changeset
163 uint percent_change) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 size_t eden_heap_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 eden_heap_delta = cur_eden / 100 * percent_change;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 return eden_heap_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 size_t AdaptiveSizePolicy::eden_increment(size_t cur_eden) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 return eden_increment(cur_eden, YoungGenerationSizeIncrement);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 size_t AdaptiveSizePolicy::eden_decrement(size_t cur_eden) {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 size_t eden_heap_delta = eden_increment(cur_eden) /
a61af66fc99e Initial load
duke
parents:
diff changeset
175 AdaptiveSizeDecrementScaleFactor;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 return eden_heap_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 size_t AdaptiveSizePolicy::promo_increment(size_t cur_promo,
a61af66fc99e Initial load
duke
parents:
diff changeset
180 uint percent_change) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 size_t promo_heap_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 promo_heap_delta = cur_promo / 100 * percent_change;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 return promo_heap_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 size_t AdaptiveSizePolicy::promo_increment(size_t cur_promo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 return promo_increment(cur_promo, TenuredGenerationSizeIncrement);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
189
a61af66fc99e Initial load
duke
parents:
diff changeset
190 size_t AdaptiveSizePolicy::promo_decrement(size_t cur_promo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 size_t promo_heap_delta = promo_increment(cur_promo);
a61af66fc99e Initial load
duke
parents:
diff changeset
192 promo_heap_delta = promo_heap_delta / AdaptiveSizeDecrementScaleFactor;
a61af66fc99e Initial load
duke
parents:
diff changeset
193 return promo_heap_delta;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 double AdaptiveSizePolicy::time_since_major_gc() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 _major_timer.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
198 double result = _major_timer.seconds();
a61af66fc99e Initial load
duke
parents:
diff changeset
199 _major_timer.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
200 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // Linear decay of major gc cost
a61af66fc99e Initial load
duke
parents:
diff changeset
204 double AdaptiveSizePolicy::decaying_major_gc_cost() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 double major_interval = major_gc_interval_average_for_decay();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 double major_gc_cost_average = major_gc_cost();
a61af66fc99e Initial load
duke
parents:
diff changeset
207 double decayed_major_gc_cost = major_gc_cost_average;
a61af66fc99e Initial load
duke
parents:
diff changeset
208 if(time_since_major_gc() > 0.0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 decayed_major_gc_cost = major_gc_cost() *
a61af66fc99e Initial load
duke
parents:
diff changeset
210 (((double) AdaptiveSizeMajorGCDecayTimeScale) * major_interval)
a61af66fc99e Initial load
duke
parents:
diff changeset
211 / time_since_major_gc();
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // The decayed cost should always be smaller than the
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // average cost but the vagaries of finite arithmetic could
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // produce a larger value in decayed_major_gc_cost so protect
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // against that.
a61af66fc99e Initial load
duke
parents:
diff changeset
218 return MIN2(major_gc_cost_average, decayed_major_gc_cost);
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // Use a value of the major gc cost that has been decayed
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // by the factor
a61af66fc99e Initial load
duke
parents:
diff changeset
223 //
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // average-interval-between-major-gc * AdaptiveSizeMajorGCDecayTimeScale /
a61af66fc99e Initial load
duke
parents:
diff changeset
225 // time-since-last-major-gc
a61af66fc99e Initial load
duke
parents:
diff changeset
226 //
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // if the average-interval-between-major-gc * AdaptiveSizeMajorGCDecayTimeScale
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // is less than time-since-last-major-gc.
a61af66fc99e Initial load
duke
parents:
diff changeset
229 //
a61af66fc99e Initial load
duke
parents:
diff changeset
230 // In cases where there are initial major gc's that
a61af66fc99e Initial load
duke
parents:
diff changeset
231 // are of a relatively high cost but no later major
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // gc's, the total gc cost can remain high because
a61af66fc99e Initial load
duke
parents:
diff changeset
233 // the major gc cost remains unchanged (since there are no major
a61af66fc99e Initial load
duke
parents:
diff changeset
234 // gc's). In such a situation the value of the unchanging
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // major gc cost can keep the mutator throughput below
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // the goal when in fact the major gc cost is becoming diminishingly
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // small. Use the decaying gc cost only to decide whether to
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // adjust for throughput. Using it also to determine the adjustment
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // to be made for throughput also seems reasonable but there is
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // no test case to use to decide if it is the right thing to do
a61af66fc99e Initial load
duke
parents:
diff changeset
241 // don't do it yet.
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243 double AdaptiveSizePolicy::decaying_gc_cost() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 double decayed_major_gc_cost = major_gc_cost();
a61af66fc99e Initial load
duke
parents:
diff changeset
245 double avg_major_interval = major_gc_interval_average_for_decay();
a61af66fc99e Initial load
duke
parents:
diff changeset
246 if (UseAdaptiveSizeDecayMajorGCCost &&
a61af66fc99e Initial load
duke
parents:
diff changeset
247 (AdaptiveSizeMajorGCDecayTimeScale > 0) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
248 (avg_major_interval > 0.00)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 double time_since_last_major_gc = time_since_major_gc();
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // Decay the major gc cost?
a61af66fc99e Initial load
duke
parents:
diff changeset
252 if (time_since_last_major_gc >
a61af66fc99e Initial load
duke
parents:
diff changeset
253 ((double) AdaptiveSizeMajorGCDecayTimeScale) * avg_major_interval) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255 // Decay using the time-since-last-major-gc
a61af66fc99e Initial load
duke
parents:
diff changeset
256 decayed_major_gc_cost = decaying_major_gc_cost();
a61af66fc99e Initial load
duke
parents:
diff changeset
257 if (PrintGCDetails && Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 gclog_or_tty->print_cr("\ndecaying_gc_cost: major interval average:"
a61af66fc99e Initial load
duke
parents:
diff changeset
259 " %f time since last major gc: %f",
a61af66fc99e Initial load
duke
parents:
diff changeset
260 avg_major_interval, time_since_last_major_gc);
a61af66fc99e Initial load
duke
parents:
diff changeset
261 gclog_or_tty->print_cr(" major gc cost: %f decayed major gc cost: %f",
a61af66fc99e Initial load
duke
parents:
diff changeset
262 major_gc_cost(), decayed_major_gc_cost);
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266 double result = MIN2(1.0, decayed_major_gc_cost + minor_gc_cost());
a61af66fc99e Initial load
duke
parents:
diff changeset
267 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 void AdaptiveSizePolicy::clear_generation_free_space_flags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 set_change_young_gen_for_min_pauses(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
273 set_change_old_gen_for_maj_pauses(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 set_change_old_gen_for_throughput(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
276 set_change_young_gen_for_throughput(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
277 set_decrease_for_footprint(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
278 set_decide_at_full_gc(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
279 }
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 // Printing
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 bool AdaptiveSizePolicy::print_adaptive_size_policy_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
284
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // Should only be used with adaptive size policy turned on.
a61af66fc99e Initial load
duke
parents:
diff changeset
286 // Otherwise, there may be variables that are undefined.
a61af66fc99e Initial load
duke
parents:
diff changeset
287 if (!UseAdaptiveSizePolicy) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // Print goal for which action is needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
290 char* action = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
291 bool change_for_pause = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 if ((change_old_gen_for_maj_pauses() ==
a61af66fc99e Initial load
duke
parents:
diff changeset
293 decrease_old_gen_for_maj_pauses_true) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
294 (change_young_gen_for_min_pauses() ==
a61af66fc99e Initial load
duke
parents:
diff changeset
295 decrease_young_gen_for_min_pauses_true)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 action = (char*) " *** pause time goal ***";
a61af66fc99e Initial load
duke
parents:
diff changeset
297 change_for_pause = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
298 } else if ((change_old_gen_for_throughput() ==
a61af66fc99e Initial load
duke
parents:
diff changeset
299 increase_old_gen_for_throughput_true) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
300 (change_young_gen_for_throughput() ==
a61af66fc99e Initial load
duke
parents:
diff changeset
301 increase_young_gen_for_througput_true)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
302 action = (char*) " *** throughput goal ***";
a61af66fc99e Initial load
duke
parents:
diff changeset
303 } else if (decrease_for_footprint()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 action = (char*) " *** reduced footprint ***";
a61af66fc99e Initial load
duke
parents:
diff changeset
305 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // No actions were taken. This can legitimately be the
a61af66fc99e Initial load
duke
parents:
diff changeset
307 // situation if not enough data has been gathered to make
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // decisions.
a61af66fc99e Initial load
duke
parents:
diff changeset
309 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312 // Pauses
a61af66fc99e Initial load
duke
parents:
diff changeset
313 // Currently the size of the old gen is only adjusted to
a61af66fc99e Initial load
duke
parents:
diff changeset
314 // change the major pause times.
a61af66fc99e Initial load
duke
parents:
diff changeset
315 char* young_gen_action = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 char* tenured_gen_action = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 char* shrink_msg = (char*) "(attempted to shrink)";
a61af66fc99e Initial load
duke
parents:
diff changeset
319 char* grow_msg = (char*) "(attempted to grow)";
a61af66fc99e Initial load
duke
parents:
diff changeset
320 char* no_change_msg = (char*) "(no change)";
a61af66fc99e Initial load
duke
parents:
diff changeset
321 if (change_young_gen_for_min_pauses() ==
a61af66fc99e Initial load
duke
parents:
diff changeset
322 decrease_young_gen_for_min_pauses_true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 young_gen_action = shrink_msg;
a61af66fc99e Initial load
duke
parents:
diff changeset
324 } else if (change_for_pause) {
a61af66fc99e Initial load
duke
parents:
diff changeset
325 young_gen_action = no_change_msg;
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327
a61af66fc99e Initial load
duke
parents:
diff changeset
328 if (change_old_gen_for_maj_pauses() == decrease_old_gen_for_maj_pauses_true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 tenured_gen_action = shrink_msg;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 } else if (change_for_pause) {
a61af66fc99e Initial load
duke
parents:
diff changeset
331 tenured_gen_action = no_change_msg;
a61af66fc99e Initial load
duke
parents:
diff changeset
332 }
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 // Throughput
a61af66fc99e Initial load
duke
parents:
diff changeset
335 if (change_old_gen_for_throughput() == increase_old_gen_for_throughput_true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 assert(change_young_gen_for_throughput() ==
a61af66fc99e Initial load
duke
parents:
diff changeset
337 increase_young_gen_for_througput_true,
a61af66fc99e Initial load
duke
parents:
diff changeset
338 "Both generations should be growing");
a61af66fc99e Initial load
duke
parents:
diff changeset
339 young_gen_action = grow_msg;
a61af66fc99e Initial load
duke
parents:
diff changeset
340 tenured_gen_action = grow_msg;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 } else if (change_young_gen_for_throughput() ==
a61af66fc99e Initial load
duke
parents:
diff changeset
342 increase_young_gen_for_througput_true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // Only the young generation may grow at start up (before
a61af66fc99e Initial load
duke
parents:
diff changeset
344 // enough full collections have been done to grow the old generation).
a61af66fc99e Initial load
duke
parents:
diff changeset
345 young_gen_action = grow_msg;
a61af66fc99e Initial load
duke
parents:
diff changeset
346 tenured_gen_action = no_change_msg;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 // Minimum footprint
a61af66fc99e Initial load
duke
parents:
diff changeset
350 if (decrease_for_footprint() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 young_gen_action = shrink_msg;
a61af66fc99e Initial load
duke
parents:
diff changeset
352 tenured_gen_action = shrink_msg;
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355 st->print_cr(" UseAdaptiveSizePolicy actions to meet %s", action);
a61af66fc99e Initial load
duke
parents:
diff changeset
356 st->print_cr(" GC overhead (%%)");
a61af66fc99e Initial load
duke
parents:
diff changeset
357 st->print_cr(" Young generation: %7.2f\t %s",
a61af66fc99e Initial load
duke
parents:
diff changeset
358 100.0 * avg_minor_gc_cost()->average(),
a61af66fc99e Initial load
duke
parents:
diff changeset
359 young_gen_action);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 st->print_cr(" Tenured generation: %7.2f\t %s",
a61af66fc99e Initial load
duke
parents:
diff changeset
361 100.0 * avg_major_gc_cost()->average(),
a61af66fc99e Initial load
duke
parents:
diff changeset
362 tenured_gen_action);
a61af66fc99e Initial load
duke
parents:
diff changeset
363 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
365
a61af66fc99e Initial load
duke
parents:
diff changeset
366 bool AdaptiveSizePolicy::print_adaptive_size_policy_on(
a61af66fc99e Initial load
duke
parents:
diff changeset
367 outputStream* st,
a61af66fc99e Initial load
duke
parents:
diff changeset
368 int tenuring_threshold_arg) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
369 if (!AdaptiveSizePolicy::print_adaptive_size_policy_on(st)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
370 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
372
a61af66fc99e Initial load
duke
parents:
diff changeset
373 // Tenuring threshold
a61af66fc99e Initial load
duke
parents:
diff changeset
374 bool tenuring_threshold_changed = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
375 if (decrement_tenuring_threshold_for_survivor_limit()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 st->print(" Tenuring threshold: (attempted to decrease to avoid"
a61af66fc99e Initial load
duke
parents:
diff changeset
377 " survivor space overflow) = ");
a61af66fc99e Initial load
duke
parents:
diff changeset
378 } else if (decrement_tenuring_threshold_for_gc_cost()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
379 st->print(" Tenuring threshold: (attempted to decrease to balance"
a61af66fc99e Initial load
duke
parents:
diff changeset
380 " GC costs) = ");
a61af66fc99e Initial load
duke
parents:
diff changeset
381 } else if (increment_tenuring_threshold_for_gc_cost()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 st->print(" Tenuring threshold: (attempted to increase to balance"
a61af66fc99e Initial load
duke
parents:
diff changeset
383 " GC costs) = ");
a61af66fc99e Initial load
duke
parents:
diff changeset
384 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
385 tenuring_threshold_changed = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
386 assert(!tenuring_threshold_change(), "(no change was attempted)");
a61af66fc99e Initial load
duke
parents:
diff changeset
387 }
a61af66fc99e Initial load
duke
parents:
diff changeset
388 if (tenuring_threshold_changed) {
a61af66fc99e Initial load
duke
parents:
diff changeset
389 st->print_cr("%d", tenuring_threshold_arg);
a61af66fc99e Initial load
duke
parents:
diff changeset
390 }
a61af66fc99e Initial load
duke
parents:
diff changeset
391 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
392 }