Mercurial > hg > graal-compiler
annotate src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp @ 912:308762b2bf14
6872000: G1: compilation fails on linux/older gcc
Reviewed-by: jcoomes, tonyp
author | apetrusenko |
---|---|
date | Fri, 14 Aug 2009 13:44:15 -0700 |
parents | 6cb8e9df7174 |
children | e1fdf4fd34dc |
rev | line source |
---|---|
342 | 1 /* |
579 | 2 * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved. |
342 | 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 #include "incls/_precompiled.incl" | |
26 #include "incls/_g1CollectorPolicy.cpp.incl" | |
27 | |
28 #define PREDICTIONS_VERBOSE 0 | |
29 | |
30 // <NEW PREDICTION> | |
31 | |
32 // Different defaults for different number of GC threads | |
33 // They were chosen by running GCOld and SPECjbb on debris with different | |
34 // numbers of GC threads and choosing them based on the results | |
35 | |
36 // all the same | |
37 static double rs_length_diff_defaults[] = { | |
38 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 | |
39 }; | |
40 | |
41 static double cost_per_card_ms_defaults[] = { | |
42 0.01, 0.005, 0.005, 0.003, 0.003, 0.002, 0.002, 0.0015 | |
43 }; | |
44 | |
45 static double cost_per_scan_only_region_ms_defaults[] = { | |
46 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 | |
47 }; | |
48 | |
49 // all the same | |
50 static double fully_young_cards_per_entry_ratio_defaults[] = { | |
51 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 | |
52 }; | |
53 | |
54 static double cost_per_entry_ms_defaults[] = { | |
55 0.015, 0.01, 0.01, 0.008, 0.008, 0.0055, 0.0055, 0.005 | |
56 }; | |
57 | |
58 static double cost_per_byte_ms_defaults[] = { | |
59 0.00006, 0.00003, 0.00003, 0.000015, 0.000015, 0.00001, 0.00001, 0.000009 | |
60 }; | |
61 | |
62 // these should be pretty consistent | |
63 static double constant_other_time_ms_defaults[] = { | |
64 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 | |
65 }; | |
66 | |
67 | |
68 static double young_other_cost_per_region_ms_defaults[] = { | |
69 0.3, 0.2, 0.2, 0.15, 0.15, 0.12, 0.12, 0.1 | |
70 }; | |
71 | |
72 static double non_young_other_cost_per_region_ms_defaults[] = { | |
73 1.0, 0.7, 0.7, 0.5, 0.5, 0.42, 0.42, 0.30 | |
74 }; | |
75 | |
76 // </NEW PREDICTION> | |
77 | |
78 G1CollectorPolicy::G1CollectorPolicy() : | |
79 _parallel_gc_threads((ParallelGCThreads > 0) ? ParallelGCThreads : 1), | |
80 _n_pauses(0), | |
81 _recent_CH_strong_roots_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)), | |
82 _recent_G1_strong_roots_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)), | |
83 _recent_evac_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)), | |
84 _recent_pause_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)), | |
85 _recent_rs_sizes(new TruncatedSeq(NumPrevPausesForHeuristics)), | |
86 _recent_gc_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)), | |
87 _all_pause_times_ms(new NumberSeq()), | |
88 _stop_world_start(0.0), | |
89 _all_stop_world_times_ms(new NumberSeq()), | |
90 _all_yield_times_ms(new NumberSeq()), | |
91 | |
92 _all_mod_union_times_ms(new NumberSeq()), | |
93 | |
677 | 94 _summary(new Summary()), |
95 _abandoned_summary(new AbandonedSummary()), | |
342 | 96 |
890
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
97 #ifndef PRODUCT |
342 | 98 _cur_clear_ct_time_ms(0.0), |
890
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
99 _min_clear_cc_time_ms(-1.0), |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
100 _max_clear_cc_time_ms(-1.0), |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
101 _cur_clear_cc_time_ms(0.0), |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
102 _cum_clear_cc_time_ms(0.0), |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
103 _num_cc_clears(0L), |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
104 #endif |
342 | 105 |
106 _region_num_young(0), | |
107 _region_num_tenured(0), | |
108 _prev_region_num_young(0), | |
109 _prev_region_num_tenured(0), | |
110 | |
111 _aux_num(10), | |
112 _all_aux_times_ms(new NumberSeq[_aux_num]), | |
113 _cur_aux_start_times_ms(new double[_aux_num]), | |
114 _cur_aux_times_ms(new double[_aux_num]), | |
115 _cur_aux_times_set(new bool[_aux_num]), | |
116 | |
117 _concurrent_mark_init_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)), | |
118 _concurrent_mark_remark_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)), | |
119 _concurrent_mark_cleanup_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)), | |
120 | |
121 // <NEW PREDICTION> | |
122 | |
123 _alloc_rate_ms_seq(new TruncatedSeq(TruncatedSeqLength)), | |
124 _prev_collection_pause_end_ms(0.0), | |
125 _pending_card_diff_seq(new TruncatedSeq(TruncatedSeqLength)), | |
126 _rs_length_diff_seq(new TruncatedSeq(TruncatedSeqLength)), | |
127 _cost_per_card_ms_seq(new TruncatedSeq(TruncatedSeqLength)), | |
128 _cost_per_scan_only_region_ms_seq(new TruncatedSeq(TruncatedSeqLength)), | |
129 _fully_young_cards_per_entry_ratio_seq(new TruncatedSeq(TruncatedSeqLength)), | |
130 _partially_young_cards_per_entry_ratio_seq( | |
131 new TruncatedSeq(TruncatedSeqLength)), | |
132 _cost_per_entry_ms_seq(new TruncatedSeq(TruncatedSeqLength)), | |
133 _partially_young_cost_per_entry_ms_seq(new TruncatedSeq(TruncatedSeqLength)), | |
134 _cost_per_byte_ms_seq(new TruncatedSeq(TruncatedSeqLength)), | |
135 _cost_per_byte_ms_during_cm_seq(new TruncatedSeq(TruncatedSeqLength)), | |
136 _cost_per_scan_only_region_ms_during_cm_seq(new TruncatedSeq(TruncatedSeqLength)), | |
137 _constant_other_time_ms_seq(new TruncatedSeq(TruncatedSeqLength)), | |
138 _young_other_cost_per_region_ms_seq(new TruncatedSeq(TruncatedSeqLength)), | |
139 _non_young_other_cost_per_region_ms_seq( | |
140 new TruncatedSeq(TruncatedSeqLength)), | |
141 | |
142 _pending_cards_seq(new TruncatedSeq(TruncatedSeqLength)), | |
143 _scanned_cards_seq(new TruncatedSeq(TruncatedSeqLength)), | |
144 _rs_lengths_seq(new TruncatedSeq(TruncatedSeqLength)), | |
145 | |
751 | 146 _pause_time_target_ms((double) MaxGCPauseMillis), |
342 | 147 |
148 // </NEW PREDICTION> | |
149 | |
150 _in_young_gc_mode(false), | |
151 _full_young_gcs(true), | |
152 _full_young_pause_num(0), | |
153 _partial_young_pause_num(0), | |
154 | |
155 _during_marking(false), | |
156 _in_marking_window(false), | |
157 _in_marking_window_im(false), | |
158 | |
159 _known_garbage_ratio(0.0), | |
160 _known_garbage_bytes(0), | |
161 | |
162 _young_gc_eff_seq(new TruncatedSeq(TruncatedSeqLength)), | |
163 _target_pause_time_ms(-1.0), | |
164 | |
165 _recent_prev_end_times_for_all_gcs_sec(new TruncatedSeq(NumPrevPausesForHeuristics)), | |
166 | |
167 _recent_CS_bytes_used_before(new TruncatedSeq(NumPrevPausesForHeuristics)), | |
168 _recent_CS_bytes_surviving(new TruncatedSeq(NumPrevPausesForHeuristics)), | |
169 | |
170 _recent_avg_pause_time_ratio(0.0), | |
171 _num_markings(0), | |
172 _n_marks(0), | |
173 _n_pauses_at_mark_end(0), | |
174 | |
175 _all_full_gc_times_ms(new NumberSeq()), | |
176 | |
177 // G1PausesBtwnConcMark defaults to -1 | |
178 // so the hack is to do the cast QQQ FIXME | |
179 _pauses_btwn_concurrent_mark((size_t)G1PausesBtwnConcMark), | |
180 _n_marks_since_last_pause(0), | |
181 _conc_mark_initiated(false), | |
182 _should_initiate_conc_mark(false), | |
183 _should_revert_to_full_young_gcs(false), | |
184 _last_full_young_gc(false), | |
185 | |
186 _prev_collection_pause_used_at_end_bytes(0), | |
187 | |
188 _collection_set(NULL), | |
189 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away | |
190 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list | |
191 #endif // _MSC_VER | |
192 | |
193 _short_lived_surv_rate_group(new SurvRateGroup(this, "Short Lived", | |
194 G1YoungSurvRateNumRegionsSummary)), | |
195 _survivor_surv_rate_group(new SurvRateGroup(this, "Survivor", | |
545 | 196 G1YoungSurvRateNumRegionsSummary)), |
342 | 197 // add here any more surv rate groups |
545 | 198 _recorded_survivor_regions(0), |
199 _recorded_survivor_head(NULL), | |
200 _recorded_survivor_tail(NULL), | |
201 _survivors_age_table(true) | |
202 | |
342 | 203 { |
204 _recent_prev_end_times_for_all_gcs_sec->add(os::elapsedTime()); | |
205 _prev_collection_pause_end_ms = os::elapsedTime() * 1000.0; | |
206 | |
207 _par_last_ext_root_scan_times_ms = new double[_parallel_gc_threads]; | |
208 _par_last_mark_stack_scan_times_ms = new double[_parallel_gc_threads]; | |
209 _par_last_scan_only_times_ms = new double[_parallel_gc_threads]; | |
210 _par_last_scan_only_regions_scanned = new double[_parallel_gc_threads]; | |
211 | |
212 _par_last_update_rs_start_times_ms = new double[_parallel_gc_threads]; | |
213 _par_last_update_rs_times_ms = new double[_parallel_gc_threads]; | |
214 _par_last_update_rs_processed_buffers = new double[_parallel_gc_threads]; | |
215 | |
216 _par_last_scan_rs_start_times_ms = new double[_parallel_gc_threads]; | |
217 _par_last_scan_rs_times_ms = new double[_parallel_gc_threads]; | |
218 _par_last_scan_new_refs_times_ms = new double[_parallel_gc_threads]; | |
219 | |
220 _par_last_obj_copy_times_ms = new double[_parallel_gc_threads]; | |
221 | |
222 _par_last_termination_times_ms = new double[_parallel_gc_threads]; | |
223 | |
224 // start conservatively | |
751 | 225 _expensive_region_limit_ms = 0.5 * (double) MaxGCPauseMillis; |
342 | 226 |
227 // <NEW PREDICTION> | |
228 | |
229 int index; | |
230 if (ParallelGCThreads == 0) | |
231 index = 0; | |
232 else if (ParallelGCThreads > 8) | |
233 index = 7; | |
234 else | |
235 index = ParallelGCThreads - 1; | |
236 | |
237 _pending_card_diff_seq->add(0.0); | |
238 _rs_length_diff_seq->add(rs_length_diff_defaults[index]); | |
239 _cost_per_card_ms_seq->add(cost_per_card_ms_defaults[index]); | |
240 _cost_per_scan_only_region_ms_seq->add( | |
241 cost_per_scan_only_region_ms_defaults[index]); | |
242 _fully_young_cards_per_entry_ratio_seq->add( | |
243 fully_young_cards_per_entry_ratio_defaults[index]); | |
244 _cost_per_entry_ms_seq->add(cost_per_entry_ms_defaults[index]); | |
245 _cost_per_byte_ms_seq->add(cost_per_byte_ms_defaults[index]); | |
246 _constant_other_time_ms_seq->add(constant_other_time_ms_defaults[index]); | |
247 _young_other_cost_per_region_ms_seq->add( | |
248 young_other_cost_per_region_ms_defaults[index]); | |
249 _non_young_other_cost_per_region_ms_seq->add( | |
250 non_young_other_cost_per_region_ms_defaults[index]); | |
251 | |
252 // </NEW PREDICTION> | |
253 | |
751 | 254 double time_slice = (double) GCPauseIntervalMillis / 1000.0; |
255 double max_gc_time = (double) MaxGCPauseMillis / 1000.0; | |
342 | 256 guarantee(max_gc_time < time_slice, |
257 "Max GC time should not be greater than the time slice"); | |
258 _mmu_tracker = new G1MMUTrackerQueue(time_slice, max_gc_time); | |
751 | 259 _sigma = (double) G1ConfidencePercent / 100.0; |
342 | 260 |
261 // start conservatively (around 50ms is about right) | |
262 _concurrent_mark_init_times_ms->add(0.05); | |
263 _concurrent_mark_remark_times_ms->add(0.05); | |
264 _concurrent_mark_cleanup_times_ms->add(0.20); | |
265 _tenuring_threshold = MaxTenuringThreshold; | |
266 | |
751 | 267 if (G1UseSurvivorSpaces) { |
545 | 268 // if G1FixedSurvivorSpaceSize is 0 which means the size is not |
269 // fixed, then _max_survivor_regions will be calculated at | |
547
1e458753107d
6802413: G1: G1FixedSurvivorSpaceSize should be converted into regions in calculate_survivors_policy()
apetrusenko
parents:
545
diff
changeset
|
270 // calculate_young_list_target_config during initialization |
545 | 271 _max_survivor_regions = G1FixedSurvivorSpaceSize / HeapRegion::GrainBytes; |
272 } else { | |
273 _max_survivor_regions = 0; | |
274 } | |
275 | |
342 | 276 initialize_all(); |
277 } | |
278 | |
279 // Increment "i", mod "len" | |
280 static void inc_mod(int& i, int len) { | |
281 i++; if (i == len) i = 0; | |
282 } | |
283 | |
284 void G1CollectorPolicy::initialize_flags() { | |
285 set_min_alignment(HeapRegion::GrainBytes); | |
286 set_max_alignment(GenRemSet::max_alignment_constraint(rem_set_name())); | |
547
1e458753107d
6802413: G1: G1FixedSurvivorSpaceSize should be converted into regions in calculate_survivors_policy()
apetrusenko
parents:
545
diff
changeset
|
287 if (SurvivorRatio < 1) { |
1e458753107d
6802413: G1: G1FixedSurvivorSpaceSize should be converted into regions in calculate_survivors_policy()
apetrusenko
parents:
545
diff
changeset
|
288 vm_exit_during_initialization("Invalid survivor ratio specified"); |
1e458753107d
6802413: G1: G1FixedSurvivorSpaceSize should be converted into regions in calculate_survivors_policy()
apetrusenko
parents:
545
diff
changeset
|
289 } |
342 | 290 CollectorPolicy::initialize_flags(); |
291 } | |
292 | |
293 void G1CollectorPolicy::init() { | |
294 // Set aside an initial future to_space. | |
295 _g1 = G1CollectedHeap::heap(); | |
296 size_t regions = Universe::heap()->capacity() / HeapRegion::GrainBytes; | |
297 | |
298 assert(Heap_lock->owned_by_self(), "Locking discipline."); | |
299 | |
300 if (G1SteadyStateUsed < 50) { | |
301 vm_exit_during_initialization("G1SteadyStateUsed must be at least 50%."); | |
302 } | |
303 | |
545 | 304 initialize_gc_policy_counters(); |
305 | |
342 | 306 if (G1Gen) { |
307 _in_young_gc_mode = true; | |
308 | |
309 if (G1YoungGenSize == 0) { | |
310 set_adaptive_young_list_length(true); | |
311 _young_list_fixed_length = 0; | |
312 } else { | |
313 set_adaptive_young_list_length(false); | |
314 _young_list_fixed_length = (G1YoungGenSize / HeapRegion::GrainBytes); | |
315 } | |
316 _free_regions_at_end_of_collection = _g1->free_regions(); | |
317 _scan_only_regions_at_end_of_collection = 0; | |
318 calculate_young_list_min_length(); | |
319 guarantee( _young_list_min_length == 0, "invariant, not enough info" ); | |
320 calculate_young_list_target_config(); | |
321 } else { | |
322 _young_list_fixed_length = 0; | |
323 _in_young_gc_mode = false; | |
324 } | |
325 } | |
326 | |
545 | 327 // Create the jstat counters for the policy. |
328 void G1CollectorPolicy::initialize_gc_policy_counters() | |
329 { | |
330 _gc_policy_counters = new GCPolicyCounters("GarbageFirst", 1, 2 + G1Gen); | |
331 } | |
332 | |
342 | 333 void G1CollectorPolicy::calculate_young_list_min_length() { |
334 _young_list_min_length = 0; | |
335 | |
336 if (!adaptive_young_list_length()) | |
337 return; | |
338 | |
339 if (_alloc_rate_ms_seq->num() > 3) { | |
340 double now_sec = os::elapsedTime(); | |
341 double when_ms = _mmu_tracker->when_max_gc_sec(now_sec) * 1000.0; | |
342 double alloc_rate_ms = predict_alloc_rate_ms(); | |
343 int min_regions = (int) ceil(alloc_rate_ms * when_ms); | |
344 int current_region_num = (int) _g1->young_list_length(); | |
345 _young_list_min_length = min_regions + current_region_num; | |
346 } | |
347 } | |
348 | |
349 void G1CollectorPolicy::calculate_young_list_target_config() { | |
350 if (adaptive_young_list_length()) { | |
351 size_t rs_lengths = (size_t) get_new_prediction(_rs_lengths_seq); | |
352 calculate_young_list_target_config(rs_lengths); | |
353 } else { | |
354 if (full_young_gcs()) | |
355 _young_list_target_length = _young_list_fixed_length; | |
356 else | |
357 _young_list_target_length = _young_list_fixed_length / 2; | |
358 _young_list_target_length = MAX2(_young_list_target_length, (size_t)1); | |
359 size_t so_length = calculate_optimal_so_length(_young_list_target_length); | |
360 guarantee( so_length < _young_list_target_length, "invariant" ); | |
361 _young_list_so_prefix_length = so_length; | |
362 } | |
545 | 363 calculate_survivors_policy(); |
342 | 364 } |
365 | |
366 // This method calculate the optimal scan-only set for a fixed young | |
367 // gen size. I couldn't work out how to reuse the more elaborate one, | |
368 // i.e. calculate_young_list_target_config(rs_length), as the loops are | |
369 // fundamentally different (the other one finds a config for different | |
370 // S-O lengths, whereas here we need to do the opposite). | |
371 size_t G1CollectorPolicy::calculate_optimal_so_length( | |
372 size_t young_list_length) { | |
373 if (!G1UseScanOnlyPrefix) | |
374 return 0; | |
375 | |
376 if (_all_pause_times_ms->num() < 3) { | |
377 // we won't use a scan-only set at the beginning to allow the rest | |
378 // of the predictors to warm up | |
379 return 0; | |
380 } | |
381 | |
382 if (_cost_per_scan_only_region_ms_seq->num() < 3) { | |
383 // then, we'll only set the S-O set to 1 for a little bit of time, | |
384 // to get enough information on the scanning cost | |
385 return 1; | |
386 } | |
387 | |
388 size_t pending_cards = (size_t) get_new_prediction(_pending_cards_seq); | |
389 size_t rs_lengths = (size_t) get_new_prediction(_rs_lengths_seq); | |
390 size_t adj_rs_lengths = rs_lengths + predict_rs_length_diff(); | |
391 size_t scanned_cards; | |
392 if (full_young_gcs()) | |
393 scanned_cards = predict_young_card_num(adj_rs_lengths); | |
394 else | |
395 scanned_cards = predict_non_young_card_num(adj_rs_lengths); | |
396 double base_time_ms = predict_base_elapsed_time_ms(pending_cards, | |
397 scanned_cards); | |
398 | |
399 size_t so_length = 0; | |
400 double max_gc_eff = 0.0; | |
401 for (size_t i = 0; i < young_list_length; ++i) { | |
402 double gc_eff = 0.0; | |
403 double pause_time_ms = 0.0; | |
404 predict_gc_eff(young_list_length, i, base_time_ms, | |
405 &gc_eff, &pause_time_ms); | |
406 if (gc_eff > max_gc_eff) { | |
407 max_gc_eff = gc_eff; | |
408 so_length = i; | |
409 } | |
410 } | |
411 | |
412 // set it to 95% of the optimal to make sure we sample the "area" | |
413 // around the optimal length to get up-to-date survival rate data | |
414 return so_length * 950 / 1000; | |
415 } | |
416 | |
417 // This is a really cool piece of code! It finds the best | |
418 // target configuration (young length / scan-only prefix length) so | |
419 // that GC efficiency is maximized and that we also meet a pause | |
420 // time. It's a triple nested loop. These loops are explained below | |
421 // from the inside-out :-) | |
422 // | |
423 // (a) The innermost loop will try to find the optimal young length | |
424 // for a fixed S-O length. It uses a binary search to speed up the | |
425 // process. We assume that, for a fixed S-O length, as we add more | |
426 // young regions to the CSet, the GC efficiency will only go up (I'll | |
427 // skip the proof). So, using a binary search to optimize this process | |
428 // makes perfect sense. | |
429 // | |
430 // (b) The middle loop will fix the S-O length before calling the | |
431 // innermost one. It will vary it between two parameters, increasing | |
432 // it by a given increment. | |
433 // | |
434 // (c) The outermost loop will call the middle loop three times. | |
435 // (1) The first time it will explore all possible S-O length values | |
436 // from 0 to as large as it can get, using a coarse increment (to | |
437 // quickly "home in" to where the optimal seems to be). | |
438 // (2) The second time it will explore the values around the optimal | |
439 // that was found by the first iteration using a fine increment. | |
440 // (3) Once the optimal config has been determined by the second | |
441 // iteration, we'll redo the calculation, but setting the S-O length | |
442 // to 95% of the optimal to make sure we sample the "area" | |
443 // around the optimal length to get up-to-date survival rate data | |
444 // | |
445 // Termination conditions for the iterations are several: the pause | |
446 // time is over the limit, we do not have enough to-space, etc. | |
447 | |
448 void G1CollectorPolicy::calculate_young_list_target_config(size_t rs_lengths) { | |
449 guarantee( adaptive_young_list_length(), "pre-condition" ); | |
450 | |
451 double start_time_sec = os::elapsedTime(); | |
751 | 452 size_t min_reserve_perc = MAX2((size_t)2, (size_t)G1MinReservePercent); |
342 | 453 min_reserve_perc = MIN2((size_t) 50, min_reserve_perc); |
454 size_t reserve_regions = | |
455 (size_t) ((double) min_reserve_perc * (double) _g1->n_regions() / 100.0); | |
456 | |
457 if (full_young_gcs() && _free_regions_at_end_of_collection > 0) { | |
458 // we are in fully-young mode and there are free regions in the heap | |
459 | |
545 | 460 double survivor_regions_evac_time = |
461 predict_survivor_regions_evac_time(); | |
462 | |
342 | 463 size_t min_so_length = 0; |
464 size_t max_so_length = 0; | |
465 | |
466 if (G1UseScanOnlyPrefix) { | |
467 if (_all_pause_times_ms->num() < 3) { | |
468 // we won't use a scan-only set at the beginning to allow the rest | |
469 // of the predictors to warm up | |
470 min_so_length = 0; | |
471 max_so_length = 0; | |
472 } else if (_cost_per_scan_only_region_ms_seq->num() < 3) { | |
473 // then, we'll only set the S-O set to 1 for a little bit of time, | |
474 // to get enough information on the scanning cost | |
475 min_so_length = 1; | |
476 max_so_length = 1; | |
477 } else if (_in_marking_window || _last_full_young_gc) { | |
478 // no S-O prefix during a marking phase either, as at the end | |
479 // of the marking phase we'll have to use a very small young | |
480 // length target to fill up the rest of the CSet with | |
481 // non-young regions and, if we have lots of scan-only regions | |
482 // left-over, we will not be able to add any more non-young | |
483 // regions. | |
484 min_so_length = 0; | |
485 max_so_length = 0; | |
486 } else { | |
487 // this is the common case; we'll never reach the maximum, we | |
488 // one of the end conditions will fire well before that | |
489 // (hopefully!) | |
490 min_so_length = 0; | |
491 max_so_length = _free_regions_at_end_of_collection - 1; | |
492 } | |
493 } else { | |
494 // no S-O prefix, as the switch is not set, but we still need to | |
495 // do one iteration to calculate the best young target that | |
496 // meets the pause time; this way we reuse the same code instead | |
497 // of replicating it | |
498 min_so_length = 0; | |
499 max_so_length = 0; | |
500 } | |
501 | |
502 double target_pause_time_ms = _mmu_tracker->max_gc_time() * 1000.0; | |
503 size_t pending_cards = (size_t) get_new_prediction(_pending_cards_seq); | |
504 size_t adj_rs_lengths = rs_lengths + predict_rs_length_diff(); | |
505 size_t scanned_cards; | |
506 if (full_young_gcs()) | |
507 scanned_cards = predict_young_card_num(adj_rs_lengths); | |
508 else | |
509 scanned_cards = predict_non_young_card_num(adj_rs_lengths); | |
510 // calculate this once, so that we don't have to recalculate it in | |
511 // the innermost loop | |
545 | 512 double base_time_ms = predict_base_elapsed_time_ms(pending_cards, scanned_cards) |
513 + survivor_regions_evac_time; | |
342 | 514 // the result |
515 size_t final_young_length = 0; | |
516 size_t final_so_length = 0; | |
517 double final_gc_eff = 0.0; | |
518 // we'll also keep track of how many times we go into the inner loop | |
519 // this is for profiling reasons | |
520 size_t calculations = 0; | |
521 | |
522 // this determines which of the three iterations the outer loop is in | |
523 typedef enum { | |
524 pass_type_coarse, | |
525 pass_type_fine, | |
526 pass_type_final | |
527 } pass_type_t; | |
528 | |
529 // range of the outer loop's iteration | |
530 size_t from_so_length = min_so_length; | |
531 size_t to_so_length = max_so_length; | |
532 guarantee( from_so_length <= to_so_length, "invariant" ); | |
533 | |
534 // this will keep the S-O length that's found by the second | |
535 // iteration of the outer loop; we'll keep it just in case the third | |
536 // iteration fails to find something | |
537 size_t fine_so_length = 0; | |
538 | |
539 // the increment step for the coarse (first) iteration | |
540 size_t so_coarse_increments = 5; | |
541 | |
542 // the common case, we'll start with the coarse iteration | |
543 pass_type_t pass = pass_type_coarse; | |
544 size_t so_length_incr = so_coarse_increments; | |
545 | |
546 if (from_so_length == to_so_length) { | |
547 // not point in doing the coarse iteration, we'll go directly into | |
548 // the fine one (we essentially trying to find the optimal young | |
549 // length for a fixed S-O length). | |
550 so_length_incr = 1; | |
551 pass = pass_type_final; | |
552 } else if (to_so_length - from_so_length < 3 * so_coarse_increments) { | |
553 // again, the range is too short so no point in foind the coarse | |
554 // iteration either | |
555 so_length_incr = 1; | |
556 pass = pass_type_fine; | |
557 } | |
558 | |
559 bool done = false; | |
560 // this is the outermost loop | |
561 while (!done) { | |
545 | 562 #ifdef TRACE_CALC_YOUNG_CONFIG |
342 | 563 // leave this in for debugging, just in case |
564 gclog_or_tty->print_cr("searching between " SIZE_FORMAT " and " SIZE_FORMAT | |
565 ", incr " SIZE_FORMAT ", pass %s", | |
566 from_so_length, to_so_length, so_length_incr, | |
567 (pass == pass_type_coarse) ? "coarse" : | |
568 (pass == pass_type_fine) ? "fine" : "final"); | |
545 | 569 #endif // TRACE_CALC_YOUNG_CONFIG |
342 | 570 |
571 size_t so_length = from_so_length; | |
572 size_t init_free_regions = | |
573 MAX2((size_t)0, | |
574 _free_regions_at_end_of_collection + | |
575 _scan_only_regions_at_end_of_collection - reserve_regions); | |
576 | |
577 // this determines whether a configuration was found | |
578 bool gc_eff_set = false; | |
579 // this is the middle loop | |
580 while (so_length <= to_so_length) { | |
581 // base time, which excludes region-related time; again we | |
582 // calculate it once to avoid recalculating it in the | |
583 // innermost loop | |
584 double base_time_with_so_ms = | |
585 base_time_ms + predict_scan_only_time_ms(so_length); | |
586 // it's already over the pause target, go around | |
587 if (base_time_with_so_ms > target_pause_time_ms) | |
588 break; | |
589 | |
590 size_t starting_young_length = so_length+1; | |
591 | |
592 // we make sure that the short young length that makes sense | |
593 // (one more than the S-O length) is feasible | |
594 size_t min_young_length = starting_young_length; | |
595 double min_gc_eff; | |
596 bool min_ok; | |
597 ++calculations; | |
598 min_ok = predict_gc_eff(min_young_length, so_length, | |
599 base_time_with_so_ms, | |
600 init_free_regions, target_pause_time_ms, | |
601 &min_gc_eff); | |
602 | |
603 if (min_ok) { | |
604 // the shortest young length is indeed feasible; we'll know | |
605 // set up the max young length and we'll do a binary search | |
606 // between min_young_length and max_young_length | |
607 size_t max_young_length = _free_regions_at_end_of_collection - 1; | |
608 double max_gc_eff = 0.0; | |
609 bool max_ok = false; | |
610 | |
611 // the innermost loop! (finally!) | |
612 while (max_young_length > min_young_length) { | |
613 // we'll make sure that min_young_length is always at a | |
614 // feasible config | |
615 guarantee( min_ok, "invariant" ); | |
616 | |
617 ++calculations; | |
618 max_ok = predict_gc_eff(max_young_length, so_length, | |
619 base_time_with_so_ms, | |
620 init_free_regions, target_pause_time_ms, | |
621 &max_gc_eff); | |
622 | |
623 size_t diff = (max_young_length - min_young_length) / 2; | |
624 if (max_ok) { | |
625 min_young_length = max_young_length; | |
626 min_gc_eff = max_gc_eff; | |
627 min_ok = true; | |
628 } | |
629 max_young_length = min_young_length + diff; | |
630 } | |
631 | |
632 // the innermost loop found a config | |
633 guarantee( min_ok, "invariant" ); | |
634 if (min_gc_eff > final_gc_eff) { | |
635 // it's the best config so far, so we'll keep it | |
636 final_gc_eff = min_gc_eff; | |
637 final_young_length = min_young_length; | |
638 final_so_length = so_length; | |
639 gc_eff_set = true; | |
640 } | |
641 } | |
642 | |
643 // incremental the fixed S-O length and go around | |
644 so_length += so_length_incr; | |
645 } | |
646 | |
647 // this is the end of the outermost loop and we need to decide | |
648 // what to do during the next iteration | |
649 if (pass == pass_type_coarse) { | |
650 // we just did the coarse pass (first iteration) | |
651 | |
652 if (!gc_eff_set) | |
653 // we didn't find a feasible config so we'll just bail out; of | |
654 // course, it might be the case that we missed it; but I'd say | |
655 // it's a bit unlikely | |
656 done = true; | |
657 else { | |
658 // We did find a feasible config with optimal GC eff during | |
659 // the first pass. So the second pass we'll only consider the | |
660 // S-O lengths around that config with a fine increment. | |
661 | |
662 guarantee( so_length_incr == so_coarse_increments, "invariant" ); | |
663 guarantee( final_so_length >= min_so_length, "invariant" ); | |
664 | |
545 | 665 #ifdef TRACE_CALC_YOUNG_CONFIG |
342 | 666 // leave this in for debugging, just in case |
667 gclog_or_tty->print_cr(" coarse pass: SO length " SIZE_FORMAT, | |
668 final_so_length); | |
545 | 669 #endif // TRACE_CALC_YOUNG_CONFIG |
342 | 670 |
671 from_so_length = | |
672 (final_so_length - min_so_length > so_coarse_increments) ? | |
673 final_so_length - so_coarse_increments + 1 : min_so_length; | |
674 to_so_length = | |
675 (max_so_length - final_so_length > so_coarse_increments) ? | |
676 final_so_length + so_coarse_increments - 1 : max_so_length; | |
677 | |
678 pass = pass_type_fine; | |
679 so_length_incr = 1; | |
680 } | |
681 } else if (pass == pass_type_fine) { | |
682 // we just finished the second pass | |
683 | |
684 if (!gc_eff_set) { | |
685 // we didn't find a feasible config (yes, it's possible; | |
686 // notice that, sometimes, we go directly into the fine | |
687 // iteration and skip the coarse one) so we bail out | |
688 done = true; | |
689 } else { | |
690 // We did find a feasible config with optimal GC eff | |
691 guarantee( so_length_incr == 1, "invariant" ); | |
692 | |
693 if (final_so_length == 0) { | |
694 // The config is of an empty S-O set, so we'll just bail out | |
695 done = true; | |
696 } else { | |
697 // we'll go around once more, setting the S-O length to 95% | |
698 // of the optimal | |
699 size_t new_so_length = 950 * final_so_length / 1000; | |
700 | |
545 | 701 #ifdef TRACE_CALC_YOUNG_CONFIG |
342 | 702 // leave this in for debugging, just in case |
703 gclog_or_tty->print_cr(" fine pass: SO length " SIZE_FORMAT | |
704 ", setting it to " SIZE_FORMAT, | |
705 final_so_length, new_so_length); | |
545 | 706 #endif // TRACE_CALC_YOUNG_CONFIG |
342 | 707 |
708 from_so_length = new_so_length; | |
709 to_so_length = new_so_length; | |
710 fine_so_length = final_so_length; | |
711 | |
712 pass = pass_type_final; | |
713 } | |
714 } | |
715 } else if (pass == pass_type_final) { | |
716 // we just finished the final (third) pass | |
717 | |
718 if (!gc_eff_set) | |
719 // we didn't find a feasible config, so we'll just use the one | |
720 // we found during the second pass, which we saved | |
721 final_so_length = fine_so_length; | |
722 | |
723 // and we're done! | |
724 done = true; | |
725 } else { | |
726 guarantee( false, "should never reach here" ); | |
727 } | |
728 | |
729 // we now go around the outermost loop | |
730 } | |
731 | |
732 // we should have at least one region in the target young length | |
545 | 733 _young_list_target_length = |
734 MAX2((size_t) 1, final_young_length + _recorded_survivor_regions); | |
342 | 735 if (final_so_length >= final_young_length) |
736 // and we need to ensure that the S-O length is not greater than | |
737 // the target young length (this is being a bit careful) | |
738 final_so_length = 0; | |
739 _young_list_so_prefix_length = final_so_length; | |
740 guarantee( !_in_marking_window || !_last_full_young_gc || | |
741 _young_list_so_prefix_length == 0, "invariant" ); | |
742 | |
743 // let's keep an eye of how long we spend on this calculation | |
744 // right now, I assume that we'll print it when we need it; we | |
745 // should really adde it to the breakdown of a pause | |
746 double end_time_sec = os::elapsedTime(); | |
747 double elapsed_time_ms = (end_time_sec - start_time_sec) * 1000.0; | |
748 | |
545 | 749 #ifdef TRACE_CALC_YOUNG_CONFIG |
342 | 750 // leave this in for debugging, just in case |
751 gclog_or_tty->print_cr("target = %1.1lf ms, young = " SIZE_FORMAT | |
752 ", SO = " SIZE_FORMAT ", " | |
753 "elapsed %1.2lf ms, calcs: " SIZE_FORMAT " (%s%s) " | |
754 SIZE_FORMAT SIZE_FORMAT, | |
755 target_pause_time_ms, | |
756 _young_list_target_length - _young_list_so_prefix_length, | |
757 _young_list_so_prefix_length, | |
758 elapsed_time_ms, | |
759 calculations, | |
760 full_young_gcs() ? "full" : "partial", | |
761 should_initiate_conc_mark() ? " i-m" : "", | |
545 | 762 _in_marking_window, |
763 _in_marking_window_im); | |
764 #endif // TRACE_CALC_YOUNG_CONFIG | |
342 | 765 |
766 if (_young_list_target_length < _young_list_min_length) { | |
767 // bummer; this means that, if we do a pause when the optimal | |
768 // config dictates, we'll violate the pause spacing target (the | |
769 // min length was calculate based on the application's current | |
770 // alloc rate); | |
771 | |
772 // so, we have to bite the bullet, and allocate the minimum | |
773 // number. We'll violate our target, but we just can't meet it. | |
774 | |
775 size_t so_length = 0; | |
776 // a note further up explains why we do not want an S-O length | |
777 // during marking | |
778 if (!_in_marking_window && !_last_full_young_gc) | |
779 // but we can still try to see whether we can find an optimal | |
780 // S-O length | |
781 so_length = calculate_optimal_so_length(_young_list_min_length); | |
782 | |
545 | 783 #ifdef TRACE_CALC_YOUNG_CONFIG |
342 | 784 // leave this in for debugging, just in case |
785 gclog_or_tty->print_cr("adjusted target length from " | |
786 SIZE_FORMAT " to " SIZE_FORMAT | |
787 ", SO " SIZE_FORMAT, | |
788 _young_list_target_length, _young_list_min_length, | |
789 so_length); | |
545 | 790 #endif // TRACE_CALC_YOUNG_CONFIG |
342 | 791 |
792 _young_list_target_length = | |
793 MAX2(_young_list_min_length, (size_t)1); | |
794 _young_list_so_prefix_length = so_length; | |
795 } | |
796 } else { | |
797 // we are in a partially-young mode or we've run out of regions (due | |
798 // to evacuation failure) | |
799 | |
545 | 800 #ifdef TRACE_CALC_YOUNG_CONFIG |
342 | 801 // leave this in for debugging, just in case |
802 gclog_or_tty->print_cr("(partial) setting target to " SIZE_FORMAT | |
803 ", SO " SIZE_FORMAT, | |
804 _young_list_min_length, 0); | |
545 | 805 #endif // TRACE_CALC_YOUNG_CONFIG |
342 | 806 |
807 // we'll do the pause as soon as possible and with no S-O prefix | |
808 // (see above for the reasons behind the latter) | |
809 _young_list_target_length = | |
810 MAX2(_young_list_min_length, (size_t) 1); | |
811 _young_list_so_prefix_length = 0; | |
812 } | |
813 | |
814 _rs_lengths_prediction = rs_lengths; | |
815 } | |
816 | |
817 // This is used by: calculate_optimal_so_length(length). It returns | |
818 // the GC eff and predicted pause time for a particular config | |
819 void | |
820 G1CollectorPolicy::predict_gc_eff(size_t young_length, | |
821 size_t so_length, | |
822 double base_time_ms, | |
823 double* ret_gc_eff, | |
824 double* ret_pause_time_ms) { | |
825 double so_time_ms = predict_scan_only_time_ms(so_length); | |
826 double accum_surv_rate_adj = 0.0; | |
827 if (so_length > 0) | |
828 accum_surv_rate_adj = accum_yg_surv_rate_pred((int)(so_length - 1)); | |
829 double accum_surv_rate = | |
830 accum_yg_surv_rate_pred((int)(young_length - 1)) - accum_surv_rate_adj; | |
831 size_t bytes_to_copy = | |
832 (size_t) (accum_surv_rate * (double) HeapRegion::GrainBytes); | |
833 double copy_time_ms = predict_object_copy_time_ms(bytes_to_copy); | |
834 double young_other_time_ms = | |
835 predict_young_other_time_ms(young_length - so_length); | |
836 double pause_time_ms = | |
837 base_time_ms + so_time_ms + copy_time_ms + young_other_time_ms; | |
838 size_t reclaimed_bytes = | |
839 (young_length - so_length) * HeapRegion::GrainBytes - bytes_to_copy; | |
840 double gc_eff = (double) reclaimed_bytes / pause_time_ms; | |
841 | |
842 *ret_gc_eff = gc_eff; | |
843 *ret_pause_time_ms = pause_time_ms; | |
844 } | |
845 | |
846 // This is used by: calculate_young_list_target_config(rs_length). It | |
847 // returns the GC eff of a particular config. It returns false if that | |
848 // config violates any of the end conditions of the search in the | |
849 // calling method, or true upon success. The end conditions were put | |
850 // here since it's called twice and it was best not to replicate them | |
851 // in the caller. Also, passing the parameteres avoids having to | |
852 // recalculate them in the innermost loop. | |
853 bool | |
854 G1CollectorPolicy::predict_gc_eff(size_t young_length, | |
855 size_t so_length, | |
856 double base_time_with_so_ms, | |
857 size_t init_free_regions, | |
858 double target_pause_time_ms, | |
859 double* ret_gc_eff) { | |
860 *ret_gc_eff = 0.0; | |
861 | |
862 if (young_length >= init_free_regions) | |
863 // end condition 1: not enough space for the young regions | |
864 return false; | |
865 | |
866 double accum_surv_rate_adj = 0.0; | |
867 if (so_length > 0) | |
868 accum_surv_rate_adj = accum_yg_surv_rate_pred((int)(so_length - 1)); | |
869 double accum_surv_rate = | |
870 accum_yg_surv_rate_pred((int)(young_length - 1)) - accum_surv_rate_adj; | |
871 size_t bytes_to_copy = | |
872 (size_t) (accum_surv_rate * (double) HeapRegion::GrainBytes); | |
873 double copy_time_ms = predict_object_copy_time_ms(bytes_to_copy); | |
874 double young_other_time_ms = | |
875 predict_young_other_time_ms(young_length - so_length); | |
876 double pause_time_ms = | |
877 base_time_with_so_ms + copy_time_ms + young_other_time_ms; | |
878 | |
879 if (pause_time_ms > target_pause_time_ms) | |
880 // end condition 2: over the target pause time | |
881 return false; | |
882 | |
883 size_t reclaimed_bytes = | |
884 (young_length - so_length) * HeapRegion::GrainBytes - bytes_to_copy; | |
885 size_t free_bytes = | |
886 (init_free_regions - young_length) * HeapRegion::GrainBytes; | |
887 | |
888 if ((2.0 + sigma()) * (double) bytes_to_copy > (double) free_bytes) | |
889 // end condition 3: out of to-space (conservatively) | |
890 return false; | |
891 | |
892 // success! | |
893 double gc_eff = (double) reclaimed_bytes / pause_time_ms; | |
894 *ret_gc_eff = gc_eff; | |
895 | |
896 return true; | |
897 } | |
898 | |
545 | 899 double G1CollectorPolicy::predict_survivor_regions_evac_time() { |
900 double survivor_regions_evac_time = 0.0; | |
901 for (HeapRegion * r = _recorded_survivor_head; | |
902 r != NULL && r != _recorded_survivor_tail->get_next_young_region(); | |
903 r = r->get_next_young_region()) { | |
904 survivor_regions_evac_time += predict_region_elapsed_time_ms(r, true); | |
905 } | |
906 return survivor_regions_evac_time; | |
907 } | |
908 | |
342 | 909 void G1CollectorPolicy::check_prediction_validity() { |
910 guarantee( adaptive_young_list_length(), "should not call this otherwise" ); | |
911 | |
912 size_t rs_lengths = _g1->young_list_sampled_rs_lengths(); | |
913 if (rs_lengths > _rs_lengths_prediction) { | |
914 // add 10% to avoid having to recalculate often | |
915 size_t rs_lengths_prediction = rs_lengths * 1100 / 1000; | |
916 calculate_young_list_target_config(rs_lengths_prediction); | |
917 } | |
918 } | |
919 | |
920 HeapWord* G1CollectorPolicy::mem_allocate_work(size_t size, | |
921 bool is_tlab, | |
922 bool* gc_overhead_limit_was_exceeded) { | |
923 guarantee(false, "Not using this policy feature yet."); | |
924 return NULL; | |
925 } | |
926 | |
927 // This method controls how a collector handles one or more | |
928 // of its generations being fully allocated. | |
929 HeapWord* G1CollectorPolicy::satisfy_failed_allocation(size_t size, | |
930 bool is_tlab) { | |
931 guarantee(false, "Not using this policy feature yet."); | |
932 return NULL; | |
933 } | |
934 | |
935 | |
936 #ifndef PRODUCT | |
937 bool G1CollectorPolicy::verify_young_ages() { | |
938 HeapRegion* head = _g1->young_list_first_region(); | |
939 return | |
940 verify_young_ages(head, _short_lived_surv_rate_group); | |
941 // also call verify_young_ages on any additional surv rate groups | |
942 } | |
943 | |
944 bool | |
945 G1CollectorPolicy::verify_young_ages(HeapRegion* head, | |
946 SurvRateGroup *surv_rate_group) { | |
947 guarantee( surv_rate_group != NULL, "pre-condition" ); | |
948 | |
949 const char* name = surv_rate_group->name(); | |
950 bool ret = true; | |
951 int prev_age = -1; | |
952 | |
953 for (HeapRegion* curr = head; | |
954 curr != NULL; | |
955 curr = curr->get_next_young_region()) { | |
956 SurvRateGroup* group = curr->surv_rate_group(); | |
957 if (group == NULL && !curr->is_survivor()) { | |
958 gclog_or_tty->print_cr("## %s: encountered NULL surv_rate_group", name); | |
959 ret = false; | |
960 } | |
961 | |
962 if (surv_rate_group == group) { | |
963 int age = curr->age_in_surv_rate_group(); | |
964 | |
965 if (age < 0) { | |
966 gclog_or_tty->print_cr("## %s: encountered negative age", name); | |
967 ret = false; | |
968 } | |
969 | |
970 if (age <= prev_age) { | |
971 gclog_or_tty->print_cr("## %s: region ages are not strictly increasing " | |
972 "(%d, %d)", name, age, prev_age); | |
973 ret = false; | |
974 } | |
975 prev_age = age; | |
976 } | |
977 } | |
978 | |
979 return ret; | |
980 } | |
981 #endif // PRODUCT | |
982 | |
983 void G1CollectorPolicy::record_full_collection_start() { | |
984 _cur_collection_start_sec = os::elapsedTime(); | |
985 // Release the future to-space so that it is available for compaction into. | |
986 _g1->set_full_collection(); | |
987 } | |
988 | |
989 void G1CollectorPolicy::record_full_collection_end() { | |
990 // Consider this like a collection pause for the purposes of allocation | |
991 // since last pause. | |
992 double end_sec = os::elapsedTime(); | |
993 double full_gc_time_sec = end_sec - _cur_collection_start_sec; | |
994 double full_gc_time_ms = full_gc_time_sec * 1000.0; | |
995 | |
996 checkpoint_conc_overhead(); | |
997 | |
998 _all_full_gc_times_ms->add(full_gc_time_ms); | |
999 | |
595
3698e8f47799
6804746: G1: guarantee(variance() > -1.0,"variance should be >= 0") (due to evacuation failure)
tonyp
parents:
547
diff
changeset
|
1000 update_recent_gc_times(end_sec, full_gc_time_ms); |
342 | 1001 |
1002 _g1->clear_full_collection(); | |
1003 | |
1004 // "Nuke" the heuristics that control the fully/partially young GC | |
1005 // transitions and make sure we start with fully young GCs after the | |
1006 // Full GC. | |
1007 set_full_young_gcs(true); | |
1008 _last_full_young_gc = false; | |
1009 _should_revert_to_full_young_gcs = false; | |
1010 _should_initiate_conc_mark = false; | |
1011 _known_garbage_bytes = 0; | |
1012 _known_garbage_ratio = 0.0; | |
1013 _in_marking_window = false; | |
1014 _in_marking_window_im = false; | |
1015 | |
1016 _short_lived_surv_rate_group->record_scan_only_prefix(0); | |
1017 _short_lived_surv_rate_group->start_adding_regions(); | |
1018 // also call this on any additional surv rate groups | |
1019 | |
545 | 1020 record_survivor_regions(0, NULL, NULL); |
1021 | |
342 | 1022 _prev_region_num_young = _region_num_young; |
1023 _prev_region_num_tenured = _region_num_tenured; | |
1024 | |
1025 _free_regions_at_end_of_collection = _g1->free_regions(); | |
1026 _scan_only_regions_at_end_of_collection = 0; | |
545 | 1027 // Reset survivors SurvRateGroup. |
1028 _survivor_surv_rate_group->reset(); | |
342 | 1029 calculate_young_list_min_length(); |
1030 calculate_young_list_target_config(); | |
1031 } | |
1032 | |
1033 void G1CollectorPolicy::record_before_bytes(size_t bytes) { | |
1034 _bytes_in_to_space_before_gc += bytes; | |
1035 } | |
1036 | |
1037 void G1CollectorPolicy::record_after_bytes(size_t bytes) { | |
1038 _bytes_in_to_space_after_gc += bytes; | |
1039 } | |
1040 | |
1041 void G1CollectorPolicy::record_stop_world_start() { | |
1042 _stop_world_start = os::elapsedTime(); | |
1043 } | |
1044 | |
1045 void G1CollectorPolicy::record_collection_pause_start(double start_time_sec, | |
1046 size_t start_used) { | |
1047 if (PrintGCDetails) { | |
1048 gclog_or_tty->stamp(PrintGCTimeStamps); | |
1049 gclog_or_tty->print("[GC pause"); | |
1050 if (in_young_gc_mode()) | |
1051 gclog_or_tty->print(" (%s)", full_young_gcs() ? "young" : "partial"); | |
1052 } | |
1053 | |
1054 assert(_g1->used_regions() == _g1->recalculate_used_regions(), | |
1055 "sanity"); | |
636 | 1056 assert(_g1->used() == _g1->recalculate_used(), "sanity"); |
342 | 1057 |
1058 double s_w_t_ms = (start_time_sec - _stop_world_start) * 1000.0; | |
1059 _all_stop_world_times_ms->add(s_w_t_ms); | |
1060 _stop_world_start = 0.0; | |
1061 | |
1062 _cur_collection_start_sec = start_time_sec; | |
1063 _cur_collection_pause_used_at_start_bytes = start_used; | |
1064 _cur_collection_pause_used_regions_at_start = _g1->used_regions(); | |
1065 _pending_cards = _g1->pending_card_num(); | |
1066 _max_pending_cards = _g1->max_pending_card_num(); | |
1067 | |
1068 _bytes_in_to_space_before_gc = 0; | |
1069 _bytes_in_to_space_after_gc = 0; | |
1070 _bytes_in_collection_set_before_gc = 0; | |
1071 | |
1072 #ifdef DEBUG | |
1073 // initialise these to something well known so that we can spot | |
1074 // if they are not set properly | |
1075 | |
1076 for (int i = 0; i < _parallel_gc_threads; ++i) { | |
1077 _par_last_ext_root_scan_times_ms[i] = -666.0; | |
1078 _par_last_mark_stack_scan_times_ms[i] = -666.0; | |
1079 _par_last_scan_only_times_ms[i] = -666.0; | |
1080 _par_last_scan_only_regions_scanned[i] = -666.0; | |
1081 _par_last_update_rs_start_times_ms[i] = -666.0; | |
1082 _par_last_update_rs_times_ms[i] = -666.0; | |
1083 _par_last_update_rs_processed_buffers[i] = -666.0; | |
1084 _par_last_scan_rs_start_times_ms[i] = -666.0; | |
1085 _par_last_scan_rs_times_ms[i] = -666.0; | |
1086 _par_last_scan_new_refs_times_ms[i] = -666.0; | |
1087 _par_last_obj_copy_times_ms[i] = -666.0; | |
1088 _par_last_termination_times_ms[i] = -666.0; | |
1089 } | |
1090 #endif | |
1091 | |
1092 for (int i = 0; i < _aux_num; ++i) { | |
1093 _cur_aux_times_ms[i] = 0.0; | |
1094 _cur_aux_times_set[i] = false; | |
1095 } | |
1096 | |
1097 _satb_drain_time_set = false; | |
1098 _last_satb_drain_processed_buffers = -1; | |
1099 | |
1100 if (in_young_gc_mode()) | |
1101 _last_young_gc_full = false; | |
1102 | |
1103 | |
1104 // do that for any other surv rate groups | |
1105 _short_lived_surv_rate_group->stop_adding_regions(); | |
1106 size_t short_lived_so_length = _young_list_so_prefix_length; | |
1107 _short_lived_surv_rate_group->record_scan_only_prefix(short_lived_so_length); | |
1108 tag_scan_only(short_lived_so_length); | |
1109 | |
751 | 1110 if (G1UseSurvivorSpaces) { |
545 | 1111 _survivors_age_table.clear(); |
1112 } | |
1113 | |
342 | 1114 assert( verify_young_ages(), "region age verification" ); |
1115 } | |
1116 | |
1117 void G1CollectorPolicy::tag_scan_only(size_t short_lived_scan_only_length) { | |
1118 // done in a way that it can be extended for other surv rate groups too... | |
1119 | |
1120 HeapRegion* head = _g1->young_list_first_region(); | |
1121 bool finished_short_lived = (short_lived_scan_only_length == 0); | |
1122 | |
1123 if (finished_short_lived) | |
1124 return; | |
1125 | |
1126 for (HeapRegion* curr = head; | |
1127 curr != NULL; | |
1128 curr = curr->get_next_young_region()) { | |
1129 SurvRateGroup* surv_rate_group = curr->surv_rate_group(); | |
1130 int age = curr->age_in_surv_rate_group(); | |
1131 | |
1132 if (surv_rate_group == _short_lived_surv_rate_group) { | |
1133 if ((size_t)age < short_lived_scan_only_length) | |
1134 curr->set_scan_only(); | |
1135 else | |
1136 finished_short_lived = true; | |
1137 } | |
1138 | |
1139 | |
1140 if (finished_short_lived) | |
1141 return; | |
1142 } | |
1143 | |
1144 guarantee( false, "we should never reach here" ); | |
1145 } | |
1146 | |
1147 void G1CollectorPolicy::record_mark_closure_time(double mark_closure_time_ms) { | |
1148 _mark_closure_time_ms = mark_closure_time_ms; | |
1149 } | |
1150 | |
1151 void G1CollectorPolicy::record_concurrent_mark_init_start() { | |
1152 _mark_init_start_sec = os::elapsedTime(); | |
1153 guarantee(!in_young_gc_mode(), "should not do be here in young GC mode"); | |
1154 } | |
1155 | |
1156 void G1CollectorPolicy::record_concurrent_mark_init_end_pre(double | |
1157 mark_init_elapsed_time_ms) { | |
1158 _during_marking = true; | |
1159 _should_initiate_conc_mark = false; | |
1160 _cur_mark_stop_world_time_ms = mark_init_elapsed_time_ms; | |
1161 } | |
1162 | |
1163 void G1CollectorPolicy::record_concurrent_mark_init_end() { | |
1164 double end_time_sec = os::elapsedTime(); | |
1165 double elapsed_time_ms = (end_time_sec - _mark_init_start_sec) * 1000.0; | |
1166 _concurrent_mark_init_times_ms->add(elapsed_time_ms); | |
1167 checkpoint_conc_overhead(); | |
1168 record_concurrent_mark_init_end_pre(elapsed_time_ms); | |
1169 | |
1170 _mmu_tracker->add_pause(_mark_init_start_sec, end_time_sec, true); | |
1171 } | |
1172 | |
1173 void G1CollectorPolicy::record_concurrent_mark_remark_start() { | |
1174 _mark_remark_start_sec = os::elapsedTime(); | |
1175 _during_marking = false; | |
1176 } | |
1177 | |
1178 void G1CollectorPolicy::record_concurrent_mark_remark_end() { | |
1179 double end_time_sec = os::elapsedTime(); | |
1180 double elapsed_time_ms = (end_time_sec - _mark_remark_start_sec)*1000.0; | |
1181 checkpoint_conc_overhead(); | |
1182 _concurrent_mark_remark_times_ms->add(elapsed_time_ms); | |
1183 _cur_mark_stop_world_time_ms += elapsed_time_ms; | |
1184 _prev_collection_pause_end_ms += elapsed_time_ms; | |
1185 | |
1186 _mmu_tracker->add_pause(_mark_remark_start_sec, end_time_sec, true); | |
1187 } | |
1188 | |
1189 void G1CollectorPolicy::record_concurrent_mark_cleanup_start() { | |
1190 _mark_cleanup_start_sec = os::elapsedTime(); | |
1191 } | |
1192 | |
1193 void | |
1194 G1CollectorPolicy::record_concurrent_mark_cleanup_end(size_t freed_bytes, | |
1195 size_t max_live_bytes) { | |
1196 record_concurrent_mark_cleanup_end_work1(freed_bytes, max_live_bytes); | |
1197 record_concurrent_mark_cleanup_end_work2(); | |
1198 } | |
1199 | |
1200 void | |
1201 G1CollectorPolicy:: | |
1202 record_concurrent_mark_cleanup_end_work1(size_t freed_bytes, | |
1203 size_t max_live_bytes) { | |
1204 if (_n_marks < 2) _n_marks++; | |
1205 if (G1PolicyVerbose > 0) | |
1206 gclog_or_tty->print_cr("At end of marking, max_live is " SIZE_FORMAT " MB " | |
1207 " (of " SIZE_FORMAT " MB heap).", | |
1208 max_live_bytes/M, _g1->capacity()/M); | |
1209 } | |
1210 | |
1211 // The important thing about this is that it includes "os::elapsedTime". | |
1212 void G1CollectorPolicy::record_concurrent_mark_cleanup_end_work2() { | |
1213 checkpoint_conc_overhead(); | |
1214 double end_time_sec = os::elapsedTime(); | |
1215 double elapsed_time_ms = (end_time_sec - _mark_cleanup_start_sec)*1000.0; | |
1216 _concurrent_mark_cleanup_times_ms->add(elapsed_time_ms); | |
1217 _cur_mark_stop_world_time_ms += elapsed_time_ms; | |
1218 _prev_collection_pause_end_ms += elapsed_time_ms; | |
1219 | |
1220 _mmu_tracker->add_pause(_mark_cleanup_start_sec, end_time_sec, true); | |
1221 | |
1222 _num_markings++; | |
1223 | |
1224 // We did a marking, so reset the "since_last_mark" variables. | |
1225 double considerConcMarkCost = 1.0; | |
1226 // If there are available processors, concurrent activity is free... | |
1227 if (Threads::number_of_non_daemon_threads() * 2 < | |
1228 os::active_processor_count()) { | |
1229 considerConcMarkCost = 0.0; | |
1230 } | |
1231 _n_pauses_at_mark_end = _n_pauses; | |
1232 _n_marks_since_last_pause++; | |
1233 _conc_mark_initiated = false; | |
1234 } | |
1235 | |
1236 void | |
1237 G1CollectorPolicy::record_concurrent_mark_cleanup_completed() { | |
1238 if (in_young_gc_mode()) { | |
1239 _should_revert_to_full_young_gcs = false; | |
1240 _last_full_young_gc = true; | |
1241 _in_marking_window = false; | |
1242 if (adaptive_young_list_length()) | |
1243 calculate_young_list_target_config(); | |
1244 } | |
1245 } | |
1246 | |
1247 void G1CollectorPolicy::record_concurrent_pause() { | |
1248 if (_stop_world_start > 0.0) { | |
1249 double yield_ms = (os::elapsedTime() - _stop_world_start) * 1000.0; | |
1250 _all_yield_times_ms->add(yield_ms); | |
1251 } | |
1252 } | |
1253 | |
1254 void G1CollectorPolicy::record_concurrent_pause_end() { | |
1255 } | |
1256 | |
1257 void G1CollectorPolicy::record_collection_pause_end_CH_strong_roots() { | |
1258 _cur_CH_strong_roots_end_sec = os::elapsedTime(); | |
1259 _cur_CH_strong_roots_dur_ms = | |
1260 (_cur_CH_strong_roots_end_sec - _cur_collection_start_sec) * 1000.0; | |
1261 } | |
1262 | |
1263 void G1CollectorPolicy::record_collection_pause_end_G1_strong_roots() { | |
1264 _cur_G1_strong_roots_end_sec = os::elapsedTime(); | |
1265 _cur_G1_strong_roots_dur_ms = | |
1266 (_cur_G1_strong_roots_end_sec - _cur_CH_strong_roots_end_sec) * 1000.0; | |
1267 } | |
1268 | |
1269 template<class T> | |
1270 T sum_of(T* sum_arr, int start, int n, int N) { | |
1271 T sum = (T)0; | |
1272 for (int i = 0; i < n; i++) { | |
1273 int j = (start + i) % N; | |
1274 sum += sum_arr[j]; | |
1275 } | |
1276 return sum; | |
1277 } | |
1278 | |
1279 void G1CollectorPolicy::print_par_stats (int level, | |
1280 const char* str, | |
1281 double* data, | |
1282 bool summary) { | |
1283 double min = data[0], max = data[0]; | |
1284 double total = 0.0; | |
1285 int j; | |
1286 for (j = 0; j < level; ++j) | |
1287 gclog_or_tty->print(" "); | |
1288 gclog_or_tty->print("[%s (ms):", str); | |
1289 for (uint i = 0; i < ParallelGCThreads; ++i) { | |
1290 double val = data[i]; | |
1291 if (val < min) | |
1292 min = val; | |
1293 if (val > max) | |
1294 max = val; | |
1295 total += val; | |
1296 gclog_or_tty->print(" %3.1lf", val); | |
1297 } | |
1298 if (summary) { | |
1299 gclog_or_tty->print_cr(""); | |
1300 double avg = total / (double) ParallelGCThreads; | |
1301 gclog_or_tty->print(" "); | |
1302 for (j = 0; j < level; ++j) | |
1303 gclog_or_tty->print(" "); | |
1304 gclog_or_tty->print("Avg: %5.1lf, Min: %5.1lf, Max: %5.1lf", | |
1305 avg, min, max); | |
1306 } | |
1307 gclog_or_tty->print_cr("]"); | |
1308 } | |
1309 | |
1310 void G1CollectorPolicy::print_par_buffers (int level, | |
1311 const char* str, | |
1312 double* data, | |
1313 bool summary) { | |
1314 double min = data[0], max = data[0]; | |
1315 double total = 0.0; | |
1316 int j; | |
1317 for (j = 0; j < level; ++j) | |
1318 gclog_or_tty->print(" "); | |
1319 gclog_or_tty->print("[%s :", str); | |
1320 for (uint i = 0; i < ParallelGCThreads; ++i) { | |
1321 double val = data[i]; | |
1322 if (val < min) | |
1323 min = val; | |
1324 if (val > max) | |
1325 max = val; | |
1326 total += val; | |
1327 gclog_or_tty->print(" %d", (int) val); | |
1328 } | |
1329 if (summary) { | |
1330 gclog_or_tty->print_cr(""); | |
1331 double avg = total / (double) ParallelGCThreads; | |
1332 gclog_or_tty->print(" "); | |
1333 for (j = 0; j < level; ++j) | |
1334 gclog_or_tty->print(" "); | |
1335 gclog_or_tty->print("Sum: %d, Avg: %d, Min: %d, Max: %d", | |
1336 (int)total, (int)avg, (int)min, (int)max); | |
1337 } | |
1338 gclog_or_tty->print_cr("]"); | |
1339 } | |
1340 | |
1341 void G1CollectorPolicy::print_stats (int level, | |
1342 const char* str, | |
1343 double value) { | |
1344 for (int j = 0; j < level; ++j) | |
1345 gclog_or_tty->print(" "); | |
1346 gclog_or_tty->print_cr("[%s: %5.1lf ms]", str, value); | |
1347 } | |
1348 | |
1349 void G1CollectorPolicy::print_stats (int level, | |
1350 const char* str, | |
1351 int value) { | |
1352 for (int j = 0; j < level; ++j) | |
1353 gclog_or_tty->print(" "); | |
1354 gclog_or_tty->print_cr("[%s: %d]", str, value); | |
1355 } | |
1356 | |
1357 double G1CollectorPolicy::avg_value (double* data) { | |
1358 if (ParallelGCThreads > 0) { | |
1359 double ret = 0.0; | |
1360 for (uint i = 0; i < ParallelGCThreads; ++i) | |
1361 ret += data[i]; | |
1362 return ret / (double) ParallelGCThreads; | |
1363 } else { | |
1364 return data[0]; | |
1365 } | |
1366 } | |
1367 | |
1368 double G1CollectorPolicy::max_value (double* data) { | |
1369 if (ParallelGCThreads > 0) { | |
1370 double ret = data[0]; | |
1371 for (uint i = 1; i < ParallelGCThreads; ++i) | |
1372 if (data[i] > ret) | |
1373 ret = data[i]; | |
1374 return ret; | |
1375 } else { | |
1376 return data[0]; | |
1377 } | |
1378 } | |
1379 | |
1380 double G1CollectorPolicy::sum_of_values (double* data) { | |
1381 if (ParallelGCThreads > 0) { | |
1382 double sum = 0.0; | |
1383 for (uint i = 0; i < ParallelGCThreads; i++) | |
1384 sum += data[i]; | |
1385 return sum; | |
1386 } else { | |
1387 return data[0]; | |
1388 } | |
1389 } | |
1390 | |
1391 double G1CollectorPolicy::max_sum (double* data1, | |
1392 double* data2) { | |
1393 double ret = data1[0] + data2[0]; | |
1394 | |
1395 if (ParallelGCThreads > 0) { | |
1396 for (uint i = 1; i < ParallelGCThreads; ++i) { | |
1397 double data = data1[i] + data2[i]; | |
1398 if (data > ret) | |
1399 ret = data; | |
1400 } | |
1401 } | |
1402 return ret; | |
1403 } | |
1404 | |
1405 // Anything below that is considered to be zero | |
1406 #define MIN_TIMER_GRANULARITY 0.0000001 | |
1407 | |
677 | 1408 void G1CollectorPolicy::record_collection_pause_end(bool abandoned) { |
342 | 1409 double end_time_sec = os::elapsedTime(); |
1410 double elapsed_ms = _last_pause_time_ms; | |
1411 bool parallel = ParallelGCThreads > 0; | |
1412 double evac_ms = (end_time_sec - _cur_G1_strong_roots_end_sec) * 1000.0; | |
1413 size_t rs_size = | |
1414 _cur_collection_pause_used_regions_at_start - collection_set_size(); | |
1415 size_t cur_used_bytes = _g1->used(); | |
1416 assert(cur_used_bytes == _g1->recalculate_used(), "It should!"); | |
1417 bool last_pause_included_initial_mark = false; | |
595
3698e8f47799
6804746: G1: guarantee(variance() > -1.0,"variance should be >= 0") (due to evacuation failure)
tonyp
parents:
547
diff
changeset
|
1418 bool update_stats = !abandoned && !_g1->evacuation_failed(); |
342 | 1419 |
1420 #ifndef PRODUCT | |
1421 if (G1YoungSurvRateVerbose) { | |
1422 gclog_or_tty->print_cr(""); | |
1423 _short_lived_surv_rate_group->print(); | |
1424 // do that for any other surv rate groups too | |
1425 } | |
1426 #endif // PRODUCT | |
1427 | |
1428 checkpoint_conc_overhead(); | |
1429 | |
1430 if (in_young_gc_mode()) { | |
1431 last_pause_included_initial_mark = _should_initiate_conc_mark; | |
1432 if (last_pause_included_initial_mark) | |
1433 record_concurrent_mark_init_end_pre(0.0); | |
1434 | |
1435 size_t min_used_targ = | |
1436 (_g1->capacity() / 100) * (G1SteadyStateUsed - G1SteadyStateUsedDelta); | |
1437 | |
1438 if (cur_used_bytes > min_used_targ) { | |
1439 if (cur_used_bytes <= _prev_collection_pause_used_at_end_bytes) { | |
1440 } else if (!_g1->mark_in_progress() && !_last_full_young_gc) { | |
1441 _should_initiate_conc_mark = true; | |
1442 } | |
1443 } | |
1444 | |
1445 _prev_collection_pause_used_at_end_bytes = cur_used_bytes; | |
1446 } | |
1447 | |
1448 _mmu_tracker->add_pause(end_time_sec - elapsed_ms/1000.0, | |
1449 end_time_sec, false); | |
1450 | |
1451 guarantee(_cur_collection_pause_used_regions_at_start >= | |
1452 collection_set_size(), | |
1453 "Negative RS size?"); | |
1454 | |
1455 // This assert is exempted when we're doing parallel collection pauses, | |
1456 // because the fragmentation caused by the parallel GC allocation buffers | |
1457 // can lead to more memory being used during collection than was used | |
1458 // before. Best leave this out until the fragmentation problem is fixed. | |
1459 // Pauses in which evacuation failed can also lead to negative | |
1460 // collections, since no space is reclaimed from a region containing an | |
1461 // object whose evacuation failed. | |
1462 // Further, we're now always doing parallel collection. But I'm still | |
1463 // leaving this here as a placeholder for a more precise assertion later. | |
1464 // (DLD, 10/05.) | |
1465 assert((true || parallel) // Always using GC LABs now. | |
1466 || _g1->evacuation_failed() | |
1467 || _cur_collection_pause_used_at_start_bytes >= cur_used_bytes, | |
1468 "Negative collection"); | |
1469 | |
1470 size_t freed_bytes = | |
1471 _cur_collection_pause_used_at_start_bytes - cur_used_bytes; | |
1472 size_t surviving_bytes = _collection_set_bytes_used_before - freed_bytes; | |
1473 double survival_fraction = | |
1474 (double)surviving_bytes/ | |
1475 (double)_collection_set_bytes_used_before; | |
1476 | |
1477 _n_pauses++; | |
1478 | |
595
3698e8f47799
6804746: G1: guarantee(variance() > -1.0,"variance should be >= 0") (due to evacuation failure)
tonyp
parents:
547
diff
changeset
|
1479 if (update_stats) { |
342 | 1480 _recent_CH_strong_roots_times_ms->add(_cur_CH_strong_roots_dur_ms); |
1481 _recent_G1_strong_roots_times_ms->add(_cur_G1_strong_roots_dur_ms); | |
1482 _recent_evac_times_ms->add(evac_ms); | |
1483 _recent_pause_times_ms->add(elapsed_ms); | |
1484 | |
1485 _recent_rs_sizes->add(rs_size); | |
1486 | |
1487 // We exempt parallel collection from this check because Alloc Buffer | |
1488 // fragmentation can produce negative collections. Same with evac | |
1489 // failure. | |
1490 // Further, we're now always doing parallel collection. But I'm still | |
1491 // leaving this here as a placeholder for a more precise assertion later. | |
1492 // (DLD, 10/05. | |
1493 assert((true || parallel) | |
1494 || _g1->evacuation_failed() | |
1495 || surviving_bytes <= _collection_set_bytes_used_before, | |
1496 "Or else negative collection!"); | |
1497 _recent_CS_bytes_used_before->add(_collection_set_bytes_used_before); | |
1498 _recent_CS_bytes_surviving->add(surviving_bytes); | |
1499 | |
1500 // this is where we update the allocation rate of the application | |
1501 double app_time_ms = | |
1502 (_cur_collection_start_sec * 1000.0 - _prev_collection_pause_end_ms); | |
1503 if (app_time_ms < MIN_TIMER_GRANULARITY) { | |
1504 // This usually happens due to the timer not having the required | |
1505 // granularity. Some Linuxes are the usual culprits. | |
1506 // We'll just set it to something (arbitrarily) small. | |
1507 app_time_ms = 1.0; | |
1508 } | |
1509 size_t regions_allocated = | |
1510 (_region_num_young - _prev_region_num_young) + | |
1511 (_region_num_tenured - _prev_region_num_tenured); | |
1512 double alloc_rate_ms = (double) regions_allocated / app_time_ms; | |
1513 _alloc_rate_ms_seq->add(alloc_rate_ms); | |
1514 _prev_region_num_young = _region_num_young; | |
1515 _prev_region_num_tenured = _region_num_tenured; | |
1516 | |
1517 double interval_ms = | |
1518 (end_time_sec - _recent_prev_end_times_for_all_gcs_sec->oldest()) * 1000.0; | |
1519 update_recent_gc_times(end_time_sec, elapsed_ms); | |
1520 _recent_avg_pause_time_ratio = _recent_gc_times_ms->sum()/interval_ms; | |
1521 assert(recent_avg_pause_time_ratio() < 1.00, "All GC?"); | |
1522 } | |
1523 | |
1524 if (G1PolicyVerbose > 1) { | |
1525 gclog_or_tty->print_cr(" Recording collection pause(%d)", _n_pauses); | |
1526 } | |
1527 | |
1528 PauseSummary* summary; | |
677 | 1529 if (abandoned) { |
1530 summary = _abandoned_summary; | |
1531 } else { | |
1532 summary = _summary; | |
342 | 1533 } |
1534 | |
1535 double ext_root_scan_time = avg_value(_par_last_ext_root_scan_times_ms); | |
1536 double mark_stack_scan_time = avg_value(_par_last_mark_stack_scan_times_ms); | |
1537 double scan_only_time = avg_value(_par_last_scan_only_times_ms); | |
1538 double scan_only_regions_scanned = | |
1539 sum_of_values(_par_last_scan_only_regions_scanned); | |
1540 double update_rs_time = avg_value(_par_last_update_rs_times_ms); | |
1541 double update_rs_processed_buffers = | |
1542 sum_of_values(_par_last_update_rs_processed_buffers); | |
1543 double scan_rs_time = avg_value(_par_last_scan_rs_times_ms); | |
1544 double obj_copy_time = avg_value(_par_last_obj_copy_times_ms); | |
1545 double termination_time = avg_value(_par_last_termination_times_ms); | |
1546 | |
648
2314b7336582
6820321: G1: Error: guarantee(check_nums(total, n, parts), "all seq lengths should match")
tonyp
parents:
640
diff
changeset
|
1547 double parallel_other_time = _cur_collection_par_time_ms - |
2314b7336582
6820321: G1: Error: guarantee(check_nums(total, n, parts), "all seq lengths should match")
tonyp
parents:
640
diff
changeset
|
1548 (update_rs_time + ext_root_scan_time + mark_stack_scan_time + |
2314b7336582
6820321: G1: Error: guarantee(check_nums(total, n, parts), "all seq lengths should match")
tonyp
parents:
640
diff
changeset
|
1549 scan_only_time + scan_rs_time + obj_copy_time + termination_time); |
595
3698e8f47799
6804746: G1: guarantee(variance() > -1.0,"variance should be >= 0") (due to evacuation failure)
tonyp
parents:
547
diff
changeset
|
1550 if (update_stats) { |
342 | 1551 MainBodySummary* body_summary = summary->main_body_summary(); |
1552 guarantee(body_summary != NULL, "should not be null!"); | |
1553 | |
1554 if (_satb_drain_time_set) | |
1555 body_summary->record_satb_drain_time_ms(_cur_satb_drain_time_ms); | |
1556 else | |
1557 body_summary->record_satb_drain_time_ms(0.0); | |
1558 body_summary->record_ext_root_scan_time_ms(ext_root_scan_time); | |
1559 body_summary->record_mark_stack_scan_time_ms(mark_stack_scan_time); | |
1560 body_summary->record_scan_only_time_ms(scan_only_time); | |
1561 body_summary->record_update_rs_time_ms(update_rs_time); | |
1562 body_summary->record_scan_rs_time_ms(scan_rs_time); | |
1563 body_summary->record_obj_copy_time_ms(obj_copy_time); | |
1564 if (parallel) { | |
1565 body_summary->record_parallel_time_ms(_cur_collection_par_time_ms); | |
1566 body_summary->record_clear_ct_time_ms(_cur_clear_ct_time_ms); | |
1567 body_summary->record_termination_time_ms(termination_time); | |
1568 body_summary->record_parallel_other_time_ms(parallel_other_time); | |
1569 } | |
1570 body_summary->record_mark_closure_time_ms(_mark_closure_time_ms); | |
1571 } | |
1572 | |
1573 if (G1PolicyVerbose > 1) { | |
1574 gclog_or_tty->print_cr(" ET: %10.6f ms (avg: %10.6f ms)\n" | |
1575 " CH Strong: %10.6f ms (avg: %10.6f ms)\n" | |
1576 " G1 Strong: %10.6f ms (avg: %10.6f ms)\n" | |
1577 " Evac: %10.6f ms (avg: %10.6f ms)\n" | |
1578 " ET-RS: %10.6f ms (avg: %10.6f ms)\n" | |
1579 " |RS|: " SIZE_FORMAT, | |
1580 elapsed_ms, recent_avg_time_for_pauses_ms(), | |
1581 _cur_CH_strong_roots_dur_ms, recent_avg_time_for_CH_strong_ms(), | |
1582 _cur_G1_strong_roots_dur_ms, recent_avg_time_for_G1_strong_ms(), | |
1583 evac_ms, recent_avg_time_for_evac_ms(), | |
1584 scan_rs_time, | |
1585 recent_avg_time_for_pauses_ms() - | |
1586 recent_avg_time_for_G1_strong_ms(), | |
1587 rs_size); | |
1588 | |
1589 gclog_or_tty->print_cr(" Used at start: " SIZE_FORMAT"K" | |
1590 " At end " SIZE_FORMAT "K\n" | |
1591 " garbage : " SIZE_FORMAT "K" | |
1592 " of " SIZE_FORMAT "K\n" | |
1593 " survival : %6.2f%% (%6.2f%% avg)", | |
1594 _cur_collection_pause_used_at_start_bytes/K, | |
1595 _g1->used()/K, freed_bytes/K, | |
1596 _collection_set_bytes_used_before/K, | |
1597 survival_fraction*100.0, | |
1598 recent_avg_survival_fraction()*100.0); | |
1599 gclog_or_tty->print_cr(" Recent %% gc pause time: %6.2f", | |
1600 recent_avg_pause_time_ratio() * 100.0); | |
1601 } | |
1602 | |
1603 double other_time_ms = elapsed_ms; | |
1604 | |
1605 if (!abandoned) { | |
1606 if (_satb_drain_time_set) | |
1607 other_time_ms -= _cur_satb_drain_time_ms; | |
1608 | |
1609 if (parallel) | |
1610 other_time_ms -= _cur_collection_par_time_ms + _cur_clear_ct_time_ms; | |
1611 else | |
1612 other_time_ms -= | |
1613 update_rs_time + | |
1614 ext_root_scan_time + mark_stack_scan_time + scan_only_time + | |
1615 scan_rs_time + obj_copy_time; | |
1616 } | |
1617 | |
1618 if (PrintGCDetails) { | |
1619 gclog_or_tty->print_cr("%s%s, %1.8lf secs]", | |
677 | 1620 abandoned ? " (abandoned)" : "", |
342 | 1621 (last_pause_included_initial_mark) ? " (initial-mark)" : "", |
1622 elapsed_ms / 1000.0); | |
1623 | |
1624 if (!abandoned) { | |
677 | 1625 if (_satb_drain_time_set) { |
342 | 1626 print_stats(1, "SATB Drain Time", _cur_satb_drain_time_ms); |
677 | 1627 } |
1628 if (_last_satb_drain_processed_buffers >= 0) { | |
342 | 1629 print_stats(2, "Processed Buffers", _last_satb_drain_processed_buffers); |
677 | 1630 } |
1631 if (parallel) { | |
1632 print_stats(1, "Parallel Time", _cur_collection_par_time_ms); | |
1633 print_par_stats(2, "Update RS (Start)", _par_last_update_rs_start_times_ms, false); | |
1634 print_par_stats(2, "Update RS", _par_last_update_rs_times_ms); | |
794 | 1635 print_par_buffers(3, "Processed Buffers", |
1636 _par_last_update_rs_processed_buffers, true); | |
342 | 1637 print_par_stats(2, "Ext Root Scanning", _par_last_ext_root_scan_times_ms); |
1638 print_par_stats(2, "Mark Stack Scanning", _par_last_mark_stack_scan_times_ms); | |
1639 print_par_stats(2, "Scan-Only Scanning", _par_last_scan_only_times_ms); | |
1640 print_par_buffers(3, "Scan-Only Regions", | |
1641 _par_last_scan_only_regions_scanned, true); | |
1642 print_par_stats(2, "Scan RS", _par_last_scan_rs_times_ms); | |
1643 print_par_stats(2, "Object Copy", _par_last_obj_copy_times_ms); | |
1644 print_par_stats(2, "Termination", _par_last_termination_times_ms); | |
1645 print_stats(2, "Other", parallel_other_time); | |
1646 print_stats(1, "Clear CT", _cur_clear_ct_time_ms); | |
677 | 1647 } else { |
1648 print_stats(1, "Update RS", update_rs_time); | |
794 | 1649 print_stats(2, "Processed Buffers", |
1650 (int)update_rs_processed_buffers); | |
342 | 1651 print_stats(1, "Ext Root Scanning", ext_root_scan_time); |
1652 print_stats(1, "Mark Stack Scanning", mark_stack_scan_time); | |
1653 print_stats(1, "Scan-Only Scanning", scan_only_time); | |
1654 print_stats(1, "Scan RS", scan_rs_time); | |
1655 print_stats(1, "Object Copying", obj_copy_time); | |
1656 } | |
1657 } | |
890
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
1658 #ifndef PRODUCT |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
1659 print_stats(1, "Cur Clear CC", _cur_clear_cc_time_ms); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
1660 print_stats(1, "Cum Clear CC", _cum_clear_cc_time_ms); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
1661 print_stats(1, "Min Clear CC", _min_clear_cc_time_ms); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
1662 print_stats(1, "Max Clear CC", _max_clear_cc_time_ms); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
1663 if (_num_cc_clears > 0) { |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
1664 print_stats(1, "Avg Clear CC", _cum_clear_cc_time_ms / ((double)_num_cc_clears)); |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
1665 } |
6cb8e9df7174
6819077: G1: first GC thread coming late into the GC.
johnc
parents:
845
diff
changeset
|
1666 #endif |
342 | 1667 print_stats(1, "Other", other_time_ms); |
1668 for (int i = 0; i < _aux_num; ++i) { | |
1669 if (_cur_aux_times_set[i]) { | |
1670 char buffer[96]; | |
1671 sprintf(buffer, "Aux%d", i); | |
1672 print_stats(1, buffer, _cur_aux_times_ms[i]); | |
1673 } | |
1674 } | |
1675 } | |
1676 if (PrintGCDetails) | |
1677 gclog_or_tty->print(" ["); | |
1678 if (PrintGC || PrintGCDetails) | |
1679 _g1->print_size_transition(gclog_or_tty, | |
1680 _cur_collection_pause_used_at_start_bytes, | |
1681 _g1->used(), _g1->capacity()); | |
1682 if (PrintGCDetails) | |
1683 gclog_or_tty->print_cr("]"); | |
1684 | |
1685 _all_pause_times_ms->add(elapsed_ms); | |
648
2314b7336582
6820321: G1: Error: guarantee(check_nums(total, n, parts), "all seq lengths should match")
tonyp
parents:
640
diff
changeset
|
1686 if (update_stats) { |
2314b7336582
6820321: G1: Error: guarantee(check_nums(total, n, parts), "all seq lengths should match")
tonyp
parents:
640
diff
changeset
|
1687 summary->record_total_time_ms(elapsed_ms); |
2314b7336582
6820321: G1: Error: guarantee(check_nums(total, n, parts), "all seq lengths should match")
tonyp
parents:
640
diff
changeset
|
1688 summary->record_other_time_ms(other_time_ms); |
2314b7336582
6820321: G1: Error: guarantee(check_nums(total, n, parts), "all seq lengths should match")
tonyp
parents:
640
diff
changeset
|
1689 } |
342 | 1690 for (int i = 0; i < _aux_num; ++i) |
1691 if (_cur_aux_times_set[i]) | |
1692 _all_aux_times_ms[i].add(_cur_aux_times_ms[i]); | |
1693 | |
1694 // Reset marks-between-pauses counter. | |
1695 _n_marks_since_last_pause = 0; | |
1696 | |
1697 // Update the efficiency-since-mark vars. | |
1698 double proc_ms = elapsed_ms * (double) _parallel_gc_threads; | |
1699 if (elapsed_ms < MIN_TIMER_GRANULARITY) { | |
1700 // This usually happens due to the timer not having the required | |
1701 // granularity. Some Linuxes are the usual culprits. | |
1702 // We'll just set it to something (arbitrarily) small. | |
1703 proc_ms = 1.0; | |
1704 } | |
1705 double cur_efficiency = (double) freed_bytes / proc_ms; | |
1706 | |
1707 bool new_in_marking_window = _in_marking_window; | |
1708 bool new_in_marking_window_im = false; | |
1709 if (_should_initiate_conc_mark) { | |
1710 new_in_marking_window = true; | |
1711 new_in_marking_window_im = true; | |
1712 } | |
1713 | |
1714 if (in_young_gc_mode()) { | |
1715 if (_last_full_young_gc) { | |
1716 set_full_young_gcs(false); | |
1717 _last_full_young_gc = false; | |
1718 } | |
1719 | |
1720 if ( !_last_young_gc_full ) { | |
1721 if ( _should_revert_to_full_young_gcs || | |
1722 _known_garbage_ratio < 0.05 || | |
1723 (adaptive_young_list_length() && | |
1724 (get_gc_eff_factor() * cur_efficiency < predict_young_gc_eff())) ) { | |
1725 set_full_young_gcs(true); | |
1726 } | |
1727 } | |
1728 _should_revert_to_full_young_gcs = false; | |
1729 | |
1730 if (_last_young_gc_full && !_during_marking) | |
1731 _young_gc_eff_seq->add(cur_efficiency); | |
1732 } | |
1733 | |
1734 _short_lived_surv_rate_group->start_adding_regions(); | |
1735 // do that for any other surv rate groupsx | |
1736 | |
1737 // <NEW PREDICTION> | |
1738 | |
677 | 1739 if (update_stats) { |
342 | 1740 double pause_time_ms = elapsed_ms; |
1741 | |
1742 size_t diff = 0; | |
1743 if (_max_pending_cards >= _pending_cards) | |
1744 diff = _max_pending_cards - _pending_cards; | |
1745 _pending_card_diff_seq->add((double) diff); | |
1746 | |
1747 double cost_per_card_ms = 0.0; | |
1748 if (_pending_cards > 0) { | |
1749 cost_per_card_ms = update_rs_time / (double) _pending_cards; | |
1750 _cost_per_card_ms_seq->add(cost_per_card_ms); | |
1751 } | |
1752 | |
1753 double cost_per_scan_only_region_ms = 0.0; | |
1754 if (scan_only_regions_scanned > 0.0) { | |
1755 cost_per_scan_only_region_ms = | |
1756 scan_only_time / scan_only_regions_scanned; | |
1757 if (_in_marking_window_im) | |
1758 _cost_per_scan_only_region_ms_during_cm_seq->add(cost_per_scan_only_region_ms); | |
1759 else | |
1760 _cost_per_scan_only_region_ms_seq->add(cost_per_scan_only_region_ms); | |
1761 } | |
1762 | |
1763 size_t cards_scanned = _g1->cards_scanned(); | |
1764 | |
1765 double cost_per_entry_ms = 0.0; | |
1766 if (cards_scanned > 10) { | |
1767 cost_per_entry_ms = scan_rs_time / (double) cards_scanned; | |
1768 if (_last_young_gc_full) | |
1769 _cost_per_entry_ms_seq->add(cost_per_entry_ms); | |
1770 else | |
1771 _partially_young_cost_per_entry_ms_seq->add(cost_per_entry_ms); | |
1772 } | |
1773 | |
1774 if (_max_rs_lengths > 0) { | |
1775 double cards_per_entry_ratio = | |
1776 (double) cards_scanned / (double) _max_rs_lengths; | |
1777 if (_last_young_gc_full) | |
1778 _fully_young_cards_per_entry_ratio_seq->add(cards_per_entry_ratio); | |
1779 else | |
1780 _partially_young_cards_per_entry_ratio_seq->add(cards_per_entry_ratio); | |
1781 } | |
1782 | |
1783 size_t rs_length_diff = _max_rs_lengths - _recorded_rs_lengths; | |
1784 if (rs_length_diff >= 0) | |
1785 _rs_length_diff_seq->add((double) rs_length_diff); | |
1786 | |
1787 size_t copied_bytes = surviving_bytes; | |
1788 double cost_per_byte_ms = 0.0; | |
1789 if (copied_bytes > 0) { | |
1790 cost_per_byte_ms = obj_copy_time / (double) copied_bytes; | |
1791 if (_in_marking_window) | |
1792 _cost_per_byte_ms_during_cm_seq->add(cost_per_byte_ms); | |
1793 else | |
1794 _cost_per_byte_ms_seq->add(cost_per_byte_ms); | |
1795 } | |
1796 | |
1797 double all_other_time_ms = pause_time_ms - | |
1798 (update_rs_time + scan_only_time + scan_rs_time + obj_copy_time + | |
1799 _mark_closure_time_ms + termination_time); | |
1800 | |
1801 double young_other_time_ms = 0.0; | |
1802 if (_recorded_young_regions > 0) { | |
1803 young_other_time_ms = | |
1804 _recorded_young_cset_choice_time_ms + | |
1805 _recorded_young_free_cset_time_ms; | |
1806 _young_other_cost_per_region_ms_seq->add(young_other_time_ms / | |
1807 (double) _recorded_young_regions); | |
1808 } | |
1809 double non_young_other_time_ms = 0.0; | |
1810 if (_recorded_non_young_regions > 0) { | |
1811 non_young_other_time_ms = | |
1812 _recorded_non_young_cset_choice_time_ms + | |
1813 _recorded_non_young_free_cset_time_ms; | |
1814 | |
1815 _non_young_other_cost_per_region_ms_seq->add(non_young_other_time_ms / | |
1816 (double) _recorded_non_young_regions); | |
1817 } | |
1818 | |
1819 double constant_other_time_ms = all_other_time_ms - | |
1820 (young_other_time_ms + non_young_other_time_ms); | |
1821 _constant_other_time_ms_seq->add(constant_other_time_ms); | |
1822 | |
1823 double survival_ratio = 0.0; | |
1824 if (_bytes_in_collection_set_before_gc > 0) { | |
1825 survival_ratio = (double) bytes_in_to_space_during_gc() / | |
1826 (double) _bytes_in_collection_set_before_gc; | |
1827 } | |
1828 | |
1829 _pending_cards_seq->add((double) _pending_cards); | |
1830 _scanned_cards_seq->add((double) cards_scanned); | |
1831 _rs_lengths_seq->add((double) _max_rs_lengths); | |
1832 | |
1833 double expensive_region_limit_ms = | |
751 | 1834 (double) MaxGCPauseMillis - predict_constant_other_time_ms(); |
342 | 1835 if (expensive_region_limit_ms < 0.0) { |
1836 // this means that the other time was predicted to be longer than | |
1837 // than the max pause time | |
751 | 1838 expensive_region_limit_ms = (double) MaxGCPauseMillis; |
342 | 1839 } |
1840 _expensive_region_limit_ms = expensive_region_limit_ms; | |
1841 | |
1842 if (PREDICTIONS_VERBOSE) { | |
1843 gclog_or_tty->print_cr(""); | |
1844 gclog_or_tty->print_cr("PREDICTIONS %1.4lf %d " | |
1845 "REGIONS %d %d %d %d " | |
1846 "PENDING_CARDS %d %d " | |
1847 "CARDS_SCANNED %d %d " | |
1848 "RS_LENGTHS %d %d " | |
1849 "SCAN_ONLY_SCAN %1.6lf %1.6lf " | |
1850 "RS_UPDATE %1.6lf %1.6lf RS_SCAN %1.6lf %1.6lf " | |
1851 "SURVIVAL_RATIO %1.6lf %1.6lf " | |
1852 "OBJECT_COPY %1.6lf %1.6lf OTHER_CONSTANT %1.6lf %1.6lf " | |
1853 "OTHER_YOUNG %1.6lf %1.6lf " | |
1854 "OTHER_NON_YOUNG %1.6lf %1.6lf " | |
1855 "VTIME_DIFF %1.6lf TERMINATION %1.6lf " | |
1856 "ELAPSED %1.6lf %1.6lf ", | |
1857 _cur_collection_start_sec, | |
1858 (!_last_young_gc_full) ? 2 : | |
1859 (last_pause_included_initial_mark) ? 1 : 0, | |
1860 _recorded_region_num, | |
1861 _recorded_young_regions, | |
1862 _recorded_scan_only_regions, | |
1863 _recorded_non_young_regions, | |
1864 _predicted_pending_cards, _pending_cards, | |
1865 _predicted_cards_scanned, cards_scanned, | |
1866 _predicted_rs_lengths, _max_rs_lengths, | |
1867 _predicted_scan_only_scan_time_ms, scan_only_time, | |
1868 _predicted_rs_update_time_ms, update_rs_time, | |
1869 _predicted_rs_scan_time_ms, scan_rs_time, | |
1870 _predicted_survival_ratio, survival_ratio, | |
1871 _predicted_object_copy_time_ms, obj_copy_time, | |
1872 _predicted_constant_other_time_ms, constant_other_time_ms, | |
1873 _predicted_young_other_time_ms, young_other_time_ms, | |
1874 _predicted_non_young_other_time_ms, | |
1875 non_young_other_time_ms, | |
1876 _vtime_diff_ms, termination_time, | |
1877 _predicted_pause_time_ms, elapsed_ms); | |
1878 } | |
1879 | |
1880 if (G1PolicyVerbose > 0) { | |
1881 gclog_or_tty->print_cr("Pause Time, predicted: %1.4lfms (predicted %s), actual: %1.4lfms", | |
1882 _predicted_pause_time_ms, | |
1883 (_within_target) ? "within" : "outside", | |
1884 elapsed_ms); | |
1885 } | |
1886 | |
1887 } | |
1888 | |
1889 _in_marking_window = new_in_marking_window; | |
1890 _in_marking_window_im = new_in_marking_window_im; | |
1891 _free_regions_at_end_of_collection = _g1->free_regions(); | |
1892 _scan_only_regions_at_end_of_collection = _g1->young_list_length(); | |
1893 calculate_young_list_min_length(); | |
1894 calculate_young_list_target_config(); | |
1895 | |
1896 // </NEW PREDICTION> | |
1897 | |
1898 _target_pause_time_ms = -1.0; | |
1899 } | |
1900 | |
1901 // <NEW PREDICTION> | |
1902 | |
1903 double | |
1904 G1CollectorPolicy:: | |
1905 predict_young_collection_elapsed_time_ms(size_t adjustment) { | |
1906 guarantee( adjustment == 0 || adjustment == 1, "invariant" ); | |
1907 | |
1908 G1CollectedHeap* g1h = G1CollectedHeap::heap(); | |
1909 size_t young_num = g1h->young_list_length(); | |
1910 if (young_num == 0) | |
1911 return 0.0; | |
1912 | |
1913 young_num += adjustment; | |
1914 size_t pending_cards = predict_pending_cards(); | |
1915 size_t rs_lengths = g1h->young_list_sampled_rs_lengths() + | |
1916 predict_rs_length_diff(); | |
1917 size_t card_num; | |
1918 if (full_young_gcs()) | |
1919 card_num = predict_young_card_num(rs_lengths); | |
1920 else | |
1921 card_num = predict_non_young_card_num(rs_lengths); | |
1922 size_t young_byte_size = young_num * HeapRegion::GrainBytes; | |
1923 double accum_yg_surv_rate = | |
1924 _short_lived_surv_rate_group->accum_surv_rate(adjustment); | |
1925 | |
1926 size_t bytes_to_copy = | |
1927 (size_t) (accum_yg_surv_rate * (double) HeapRegion::GrainBytes); | |
1928 | |
1929 return | |
1930 predict_rs_update_time_ms(pending_cards) + | |
1931 predict_rs_scan_time_ms(card_num) + | |
1932 predict_object_copy_time_ms(bytes_to_copy) + | |
1933 predict_young_other_time_ms(young_num) + | |
1934 predict_constant_other_time_ms(); | |
1935 } | |
1936 | |
1937 double | |
1938 G1CollectorPolicy::predict_base_elapsed_time_ms(size_t pending_cards) { | |
1939 size_t rs_length = predict_rs_length_diff(); | |
1940 size_t card_num; | |
1941 if (full_young_gcs()) | |
1942 card_num = predict_young_card_num(rs_length); | |
1943 else | |
1944 card_num = predict_non_young_card_num(rs_length); | |
1945 return predict_base_elapsed_time_ms(pending_cards, card_num); | |
1946 } | |
1947 | |
1948 double | |
1949 G1CollectorPolicy::predict_base_elapsed_time_ms(size_t pending_cards, | |
1950 size_t scanned_cards) { | |
1951 return | |
1952 predict_rs_update_time_ms(pending_cards) + | |
1953 predict_rs_scan_time_ms(scanned_cards) + | |
1954 predict_constant_other_time_ms(); | |
1955 } | |
1956 | |
1957 double | |
1958 G1CollectorPolicy::predict_region_elapsed_time_ms(HeapRegion* hr, | |
1959 bool young) { | |
1960 size_t rs_length = hr->rem_set()->occupied(); | |
1961 size_t card_num; | |
1962 if (full_young_gcs()) | |
1963 card_num = predict_young_card_num(rs_length); | |
1964 else | |
1965 card_num = predict_non_young_card_num(rs_length); | |
1966 size_t bytes_to_copy = predict_bytes_to_copy(hr); | |
1967 | |
1968 double region_elapsed_time_ms = | |
1969 predict_rs_scan_time_ms(card_num) + | |
1970 predict_object_copy_time_ms(bytes_to_copy); | |
1971 | |
1972 if (young) | |
1973 region_elapsed_time_ms += predict_young_other_time_ms(1); | |
1974 else | |
1975 region_elapsed_time_ms += predict_non_young_other_time_ms(1); | |
1976 | |
1977 return region_elapsed_time_ms; | |
1978 } | |
1979 | |
1980 size_t | |
1981 G1CollectorPolicy::predict_bytes_to_copy(HeapRegion* hr) { | |
1982 size_t bytes_to_copy; | |
1983 if (hr->is_marked()) | |
1984 bytes_to_copy = hr->max_live_bytes(); | |
1985 else { | |
1986 guarantee( hr->is_young() && hr->age_in_surv_rate_group() != -1, | |
1987 "invariant" ); | |
1988 int age = hr->age_in_surv_rate_group(); | |
545 | 1989 double yg_surv_rate = predict_yg_surv_rate(age, hr->surv_rate_group()); |
342 | 1990 bytes_to_copy = (size_t) ((double) hr->used() * yg_surv_rate); |
1991 } | |
1992 | |
1993 return bytes_to_copy; | |
1994 } | |
1995 | |
1996 void | |
1997 G1CollectorPolicy::start_recording_regions() { | |
1998 _recorded_rs_lengths = 0; | |
1999 _recorded_scan_only_regions = 0; | |
2000 _recorded_young_regions = 0; | |
2001 _recorded_non_young_regions = 0; | |
2002 | |
2003 #if PREDICTIONS_VERBOSE | |
2004 _predicted_rs_lengths = 0; | |
2005 _predicted_cards_scanned = 0; | |
2006 | |
2007 _recorded_marked_bytes = 0; | |
2008 _recorded_young_bytes = 0; | |
2009 _predicted_bytes_to_copy = 0; | |
2010 #endif // PREDICTIONS_VERBOSE | |
2011 } | |
2012 | |
2013 void | |
2014 G1CollectorPolicy::record_cset_region(HeapRegion* hr, bool young) { | |
2015 if (young) { | |
2016 ++_recorded_young_regions; | |
2017 } else { | |
2018 ++_recorded_non_young_regions; | |
2019 } | |
2020 #if PREDICTIONS_VERBOSE | |
2021 if (young) { | |
545 | 2022 _recorded_young_bytes += hr->used(); |
342 | 2023 } else { |
2024 _recorded_marked_bytes += hr->max_live_bytes(); | |
2025 } | |
2026 _predicted_bytes_to_copy += predict_bytes_to_copy(hr); | |
2027 #endif // PREDICTIONS_VERBOSE | |
2028 | |
2029 size_t rs_length = hr->rem_set()->occupied(); | |
2030 _recorded_rs_lengths += rs_length; | |
2031 } | |
2032 | |
2033 void | |
2034 G1CollectorPolicy::record_scan_only_regions(size_t scan_only_length) { | |
2035 _recorded_scan_only_regions = scan_only_length; | |
2036 } | |
2037 | |
2038 void | |
2039 G1CollectorPolicy::end_recording_regions() { | |
2040 #if PREDICTIONS_VERBOSE | |
2041 _predicted_pending_cards = predict_pending_cards(); | |
2042 _predicted_rs_lengths = _recorded_rs_lengths + predict_rs_length_diff(); | |
2043 if (full_young_gcs()) | |
2044 _predicted_cards_scanned += predict_young_card_num(_predicted_rs_lengths); | |
2045 else | |
2046 _predicted_cards_scanned += | |
2047 predict_non_young_card_num(_predicted_rs_lengths); | |
2048 _recorded_region_num = _recorded_young_regions + _recorded_non_young_regions; | |
2049 | |
2050 _predicted_scan_only_scan_time_ms = | |
2051 predict_scan_only_time_ms(_recorded_scan_only_regions); | |
2052 _predicted_rs_update_time_ms = | |
2053 predict_rs_update_time_ms(_g1->pending_card_num()); | |
2054 _predicted_rs_scan_time_ms = | |
2055 predict_rs_scan_time_ms(_predicted_cards_scanned); | |
2056 _predicted_object_copy_time_ms = | |
2057 predict_object_copy_time_ms(_predicted_bytes_to_copy); | |
2058 _predicted_constant_other_time_ms = | |
2059 predict_constant_other_time_ms(); | |
2060 _predicted_young_other_time_ms = | |
2061 predict_young_other_time_ms(_recorded_young_regions); | |
2062 _predicted_non_young_other_time_ms = | |
2063 predict_non_young_other_time_ms(_recorded_non_young_regions); | |
2064 | |
2065 _predicted_pause_time_ms = | |
2066 _predicted_scan_only_scan_time_ms + | |
2067 _predicted_rs_update_time_ms + | |
2068 _predicted_rs_scan_time_ms + | |
2069 _predicted_object_copy_time_ms + | |
2070 _predicted_constant_other_time_ms + | |
2071 _predicted_young_other_time_ms + | |
2072 _predicted_non_young_other_time_ms; | |
2073 #endif // PREDICTIONS_VERBOSE | |
2074 } | |
2075 | |
2076 void G1CollectorPolicy::check_if_region_is_too_expensive(double | |
2077 predicted_time_ms) { | |
2078 // I don't think we need to do this when in young GC mode since | |
2079 // marking will be initiated next time we hit the soft limit anyway... | |
2080 if (predicted_time_ms > _expensive_region_limit_ms) { | |
2081 if (!in_young_gc_mode()) { | |
2082 set_full_young_gcs(true); | |
2083 _should_initiate_conc_mark = true; | |
2084 } else | |
2085 // no point in doing another partial one | |
2086 _should_revert_to_full_young_gcs = true; | |
2087 } | |
2088 } | |
2089 | |
2090 // </NEW PREDICTION> | |
2091 | |
2092 | |
2093 void G1CollectorPolicy::update_recent_gc_times(double end_time_sec, | |
2094 double elapsed_ms) { | |
2095 _recent_gc_times_ms->add(elapsed_ms); | |
2096 _recent_prev_end_times_for_all_gcs_sec->add(end_time_sec); | |
2097 _prev_collection_pause_end_ms = end_time_sec * 1000.0; | |
2098 } | |
2099 | |
2100 double G1CollectorPolicy::recent_avg_time_for_pauses_ms() { | |
751 | 2101 if (_recent_pause_times_ms->num() == 0) return (double) MaxGCPauseMillis; |
342 | 2102 else return _recent_pause_times_ms->avg(); |
2103 } | |
2104 | |
2105 double G1CollectorPolicy::recent_avg_time_for_CH_strong_ms() { | |
2106 if (_recent_CH_strong_roots_times_ms->num() == 0) | |
751 | 2107 return (double)MaxGCPauseMillis/3.0; |
342 | 2108 else return _recent_CH_strong_roots_times_ms->avg(); |
2109 } | |
2110 | |
2111 double G1CollectorPolicy::recent_avg_time_for_G1_strong_ms() { | |
2112 if (_recent_G1_strong_roots_times_ms->num() == 0) | |
751 | 2113 return (double)MaxGCPauseMillis/3.0; |
342 | 2114 else return _recent_G1_strong_roots_times_ms->avg(); |
2115 } | |
2116 | |
2117 double G1CollectorPolicy::recent_avg_time_for_evac_ms() { | |
751 | 2118 if (_recent_evac_times_ms->num() == 0) return (double)MaxGCPauseMillis/3.0; |
342 | 2119 else return _recent_evac_times_ms->avg(); |
2120 } | |
2121 | |
2122 int G1CollectorPolicy::number_of_recent_gcs() { | |
2123 assert(_recent_CH_strong_roots_times_ms->num() == | |
2124 _recent_G1_strong_roots_times_ms->num(), "Sequence out of sync"); | |
2125 assert(_recent_G1_strong_roots_times_ms->num() == | |
2126 _recent_evac_times_ms->num(), "Sequence out of sync"); | |
2127 assert(_recent_evac_times_ms->num() == | |
2128 _recent_pause_times_ms->num(), "Sequence out of sync"); | |
2129 assert(_recent_pause_times_ms->num() == | |
2130 _recent_CS_bytes_used_before->num(), "Sequence out of sync"); | |
2131 assert(_recent_CS_bytes_used_before->num() == | |
2132 _recent_CS_bytes_surviving->num(), "Sequence out of sync"); | |
2133 return _recent_pause_times_ms->num(); | |
2134 } | |
2135 | |
2136 double G1CollectorPolicy::recent_avg_survival_fraction() { | |
2137 return recent_avg_survival_fraction_work(_recent_CS_bytes_surviving, | |
2138 _recent_CS_bytes_used_before); | |
2139 } | |
2140 | |
2141 double G1CollectorPolicy::last_survival_fraction() { | |
2142 return last_survival_fraction_work(_recent_CS_bytes_surviving, | |
2143 _recent_CS_bytes_used_before); | |
2144 } | |
2145 | |
2146 double | |
2147 G1CollectorPolicy::recent_avg_survival_fraction_work(TruncatedSeq* surviving, | |
2148 TruncatedSeq* before) { | |
2149 assert(surviving->num() == before->num(), "Sequence out of sync"); | |
2150 if (before->sum() > 0.0) { | |
2151 double recent_survival_rate = surviving->sum() / before->sum(); | |
2152 // We exempt parallel collection from this check because Alloc Buffer | |
2153 // fragmentation can produce negative collections. | |
2154 // Further, we're now always doing parallel collection. But I'm still | |
2155 // leaving this here as a placeholder for a more precise assertion later. | |
2156 // (DLD, 10/05.) | |
2157 assert((true || ParallelGCThreads > 0) || | |
2158 _g1->evacuation_failed() || | |
2159 recent_survival_rate <= 1.0, "Or bad frac"); | |
2160 return recent_survival_rate; | |
2161 } else { | |
2162 return 1.0; // Be conservative. | |
2163 } | |
2164 } | |
2165 | |
2166 double | |
2167 G1CollectorPolicy::last_survival_fraction_work(TruncatedSeq* surviving, | |
2168 TruncatedSeq* before) { | |
2169 assert(surviving->num() == before->num(), "Sequence out of sync"); | |
2170 if (surviving->num() > 0 && before->last() > 0.0) { | |
2171 double last_survival_rate = surviving->last() / before->last(); | |
2172 // We exempt parallel collection from this check because Alloc Buffer | |
2173 // fragmentation can produce negative collections. | |
2174 // Further, we're now always doing parallel collection. But I'm still | |
2175 // leaving this here as a placeholder for a more precise assertion later. | |
2176 // (DLD, 10/05.) | |
2177 assert((true || ParallelGCThreads > 0) || | |
2178 last_survival_rate <= 1.0, "Or bad frac"); | |
2179 return last_survival_rate; | |
2180 } else { | |
2181 return 1.0; | |
2182 } | |
2183 } | |
2184 | |
2185 static const int survival_min_obs = 5; | |
2186 static double survival_min_obs_limits[] = { 0.9, 0.7, 0.5, 0.3, 0.1 }; | |
2187 static const double min_survival_rate = 0.1; | |
2188 | |
2189 double | |
2190 G1CollectorPolicy::conservative_avg_survival_fraction_work(double avg, | |
2191 double latest) { | |
2192 double res = avg; | |
2193 if (number_of_recent_gcs() < survival_min_obs) { | |
2194 res = MAX2(res, survival_min_obs_limits[number_of_recent_gcs()]); | |
2195 } | |
2196 res = MAX2(res, latest); | |
2197 res = MAX2(res, min_survival_rate); | |
2198 // In the parallel case, LAB fragmentation can produce "negative | |
2199 // collections"; so can evac failure. Cap at 1.0 | |
2200 res = MIN2(res, 1.0); | |
2201 return res; | |
2202 } | |
2203 | |
2204 size_t G1CollectorPolicy::expansion_amount() { | |
751 | 2205 if ((int)(recent_avg_pause_time_ratio() * 100.0) > G1GCPercent) { |
2206 // We will double the existing space, or take | |
2207 // G1ExpandByPercentOfAvailable % of the available expansion | |
2208 // space, whichever is smaller, bounded below by a minimum | |
2209 // expansion (unless that's all that's left.) | |
342 | 2210 const size_t min_expand_bytes = 1*M; |
2211 size_t reserved_bytes = _g1->g1_reserved_obj_bytes(); | |
2212 size_t committed_bytes = _g1->capacity(); | |
2213 size_t uncommitted_bytes = reserved_bytes - committed_bytes; | |
2214 size_t expand_bytes; | |
2215 size_t expand_bytes_via_pct = | |
751 | 2216 uncommitted_bytes * G1ExpandByPercentOfAvailable / 100; |
342 | 2217 expand_bytes = MIN2(expand_bytes_via_pct, committed_bytes); |
2218 expand_bytes = MAX2(expand_bytes, min_expand_bytes); | |
2219 expand_bytes = MIN2(expand_bytes, uncommitted_bytes); | |
2220 if (G1PolicyVerbose > 1) { | |
2221 gclog_or_tty->print("Decided to expand: ratio = %5.2f, " | |
2222 "committed = %d%s, uncommited = %d%s, via pct = %d%s.\n" | |
2223 " Answer = %d.\n", | |
2224 recent_avg_pause_time_ratio(), | |
2225 byte_size_in_proper_unit(committed_bytes), | |
2226 proper_unit_for_byte_size(committed_bytes), | |
2227 byte_size_in_proper_unit(uncommitted_bytes), | |
2228 proper_unit_for_byte_size(uncommitted_bytes), | |
2229 byte_size_in_proper_unit(expand_bytes_via_pct), | |
2230 proper_unit_for_byte_size(expand_bytes_via_pct), | |
2231 byte_size_in_proper_unit(expand_bytes), | |
2232 proper_unit_for_byte_size(expand_bytes)); | |
2233 } | |
2234 return expand_bytes; | |
2235 } else { | |
2236 return 0; | |
2237 } | |
2238 } | |
2239 | |
2240 void G1CollectorPolicy::note_start_of_mark_thread() { | |
2241 _mark_thread_startup_sec = os::elapsedTime(); | |
2242 } | |
2243 | |
2244 class CountCSClosure: public HeapRegionClosure { | |
2245 G1CollectorPolicy* _g1_policy; | |
2246 public: | |
2247 CountCSClosure(G1CollectorPolicy* g1_policy) : | |
2248 _g1_policy(g1_policy) {} | |
2249 bool doHeapRegion(HeapRegion* r) { | |
2250 _g1_policy->_bytes_in_collection_set_before_gc += r->used(); | |
2251 return false; | |
2252 } | |
2253 }; | |
2254 | |
2255 void G1CollectorPolicy::count_CS_bytes_used() { | |
2256 CountCSClosure cs_closure(this); | |
2257 _g1->collection_set_iterate(&cs_closure); | |
2258 } | |
2259 | |
2260 static void print_indent(int level) { | |
2261 for (int j = 0; j < level+1; ++j) | |
2262 gclog_or_tty->print(" "); | |
2263 } | |
2264 | |
2265 void G1CollectorPolicy::print_summary (int level, | |
2266 const char* str, | |
2267 NumberSeq* seq) const { | |
2268 double sum = seq->sum(); | |
2269 print_indent(level); | |
2270 gclog_or_tty->print_cr("%-24s = %8.2lf s (avg = %8.2lf ms)", | |
2271 str, sum / 1000.0, seq->avg()); | |
2272 } | |
2273 | |
2274 void G1CollectorPolicy::print_summary_sd (int level, | |
2275 const char* str, | |
2276 NumberSeq* seq) const { | |
2277 print_summary(level, str, seq); | |
2278 print_indent(level + 5); | |
2279 gclog_or_tty->print_cr("(num = %5d, std dev = %8.2lf ms, max = %8.2lf ms)", | |
2280 seq->num(), seq->sd(), seq->maximum()); | |
2281 } | |
2282 | |
2283 void G1CollectorPolicy::check_other_times(int level, | |
2284 NumberSeq* other_times_ms, | |
2285 NumberSeq* calc_other_times_ms) const { | |
2286 bool should_print = false; | |
2287 | |
2288 double max_sum = MAX2(fabs(other_times_ms->sum()), | |
2289 fabs(calc_other_times_ms->sum())); | |
2290 double min_sum = MIN2(fabs(other_times_ms->sum()), | |
2291 fabs(calc_other_times_ms->sum())); | |
2292 double sum_ratio = max_sum / min_sum; | |
2293 if (sum_ratio > 1.1) { | |
2294 should_print = true; | |
2295 print_indent(level + 1); | |
2296 gclog_or_tty->print_cr("## CALCULATED OTHER SUM DOESN'T MATCH RECORDED ###"); | |
2297 } | |
2298 | |
2299 double max_avg = MAX2(fabs(other_times_ms->avg()), | |
2300 fabs(calc_other_times_ms->avg())); | |
2301 double min_avg = MIN2(fabs(other_times_ms->avg()), | |
2302 fabs(calc_other_times_ms->avg())); | |
2303 double avg_ratio = max_avg / min_avg; | |
2304 if (avg_ratio > 1.1) { | |
2305 should_print = true; | |
2306 print_indent(level + 1); | |
2307 gclog_or_tty->print_cr("## CALCULATED OTHER AVG DOESN'T MATCH RECORDED ###"); | |
2308 } | |
2309 | |
2310 if (other_times_ms->sum() < -0.01) { | |
2311 print_indent(level + 1); | |
2312 gclog_or_tty->print_cr("## RECORDED OTHER SUM IS NEGATIVE ###"); | |
2313 } | |
2314 | |
2315 if (other_times_ms->avg() < -0.01) { | |
2316 print_indent(level + 1); | |
2317 gclog_or_tty->print_cr("## RECORDED OTHER AVG IS NEGATIVE ###"); | |
2318 } | |
2319 | |
2320 if (calc_other_times_ms->sum() < -0.01) { | |
2321 should_print = true; | |
2322 print_indent(level + 1); | |
2323 gclog_or_tty->print_cr("## CALCULATED OTHER SUM IS NEGATIVE ###"); | |
2324 } | |
2325 | |
2326 if (calc_other_times_ms->avg() < -0.01) { | |
2327 should_print = true; | |
2328 print_indent(level + 1); | |
2329 gclog_or_tty->print_cr("## CALCULATED OTHER AVG IS NEGATIVE ###"); | |
2330 } | |
2331 | |
2332 if (should_print) | |
2333 print_summary(level, "Other(Calc)", calc_other_times_ms); | |
2334 } | |
2335 | |
2336 void G1CollectorPolicy::print_summary(PauseSummary* summary) const { | |
2337 bool parallel = ParallelGCThreads > 0; | |
2338 MainBodySummary* body_summary = summary->main_body_summary(); | |
2339 if (summary->get_total_seq()->num() > 0) { | |
677 | 2340 print_summary_sd(0, "Evacuation Pauses", summary->get_total_seq()); |
342 | 2341 if (body_summary != NULL) { |
2342 print_summary(1, "SATB Drain", body_summary->get_satb_drain_seq()); | |
2343 if (parallel) { | |
2344 print_summary(1, "Parallel Time", body_summary->get_parallel_seq()); | |
2345 print_summary(2, "Update RS", body_summary->get_update_rs_seq()); | |
2346 print_summary(2, "Ext Root Scanning", | |
2347 body_summary->get_ext_root_scan_seq()); | |
2348 print_summary(2, "Mark Stack Scanning", | |
2349 body_summary->get_mark_stack_scan_seq()); | |
2350 print_summary(2, "Scan-Only Scanning", | |
2351 body_summary->get_scan_only_seq()); | |
2352 print_summary(2, "Scan RS", body_summary->get_scan_rs_seq()); | |
2353 print_summary(2, "Object Copy", body_summary->get_obj_copy_seq()); | |
2354 print_summary(2, "Termination", body_summary->get_termination_seq()); | |
2355 print_summary(2, "Other", body_summary->get_parallel_other_seq()); | |
2356 { | |
2357 NumberSeq* other_parts[] = { | |
2358 body_summary->get_update_rs_seq(), | |
2359 body_summary->get_ext_root_scan_seq(), | |
2360 body_summary->get_mark_stack_scan_seq(), | |
2361 body_summary->get_scan_only_seq(), | |
2362 body_summary->get_scan_rs_seq(), | |
2363 body_summary->get_obj_copy_seq(), | |
2364 body_summary->get_termination_seq() | |
2365 }; | |
2366 NumberSeq calc_other_times_ms(body_summary->get_parallel_seq(), | |
2367 7, other_parts); | |
2368 check_other_times(2, body_summary->get_parallel_other_seq(), | |
2369 &calc_other_times_ms); | |
2370 } | |
2371 print_summary(1, "Mark Closure", body_summary->get_mark_closure_seq()); | |
2372 print_summary(1, "Clear CT", body_summary->get_clear_ct_seq()); | |
2373 } else { | |
2374 print_summary(1, "Update RS", body_summary->get_update_rs_seq()); | |
2375 print_summary(1, "Ext Root Scanning", | |
2376 body_summary->get_ext_root_scan_seq()); | |
2377 print_summary(1, "Mark Stack Scanning", | |
2378 body_summary->get_mark_stack_scan_seq()); | |
2379 print_summary(1, "Scan-Only Scanning", | |
2380 body_summary->get_scan_only_seq()); | |
2381 print_summary(1, "Scan RS", body_summary->get_scan_rs_seq()); | |
2382 print_summary(1, "Object Copy", body_summary->get_obj_copy_seq()); | |
2383 } | |
2384 } | |
2385 print_summary(1, "Other", summary->get_other_seq()); | |
2386 { | |
2387 NumberSeq calc_other_times_ms; | |
2388 if (body_summary != NULL) { | |
2389 // not abandoned | |
2390 if (parallel) { | |
2391 // parallel | |
2392 NumberSeq* other_parts[] = { | |
2393 body_summary->get_satb_drain_seq(), | |
2394 body_summary->get_parallel_seq(), | |
2395 body_summary->get_clear_ct_seq() | |
2396 }; | |
677 | 2397 calc_other_times_ms = NumberSeq(summary->get_total_seq(), |
2398 3, other_parts); | |
342 | 2399 } else { |
2400 // serial | |
2401 NumberSeq* other_parts[] = { | |
2402 body_summary->get_satb_drain_seq(), | |
2403 body_summary->get_update_rs_seq(), | |
2404 body_summary->get_ext_root_scan_seq(), | |
2405 body_summary->get_mark_stack_scan_seq(), | |
2406 body_summary->get_scan_only_seq(), | |
2407 body_summary->get_scan_rs_seq(), | |
2408 body_summary->get_obj_copy_seq() | |
2409 }; | |
2410 calc_other_times_ms = NumberSeq(summary->get_total_seq(), | |
677 | 2411 7, other_parts); |
342 | 2412 } |
2413 } else { | |
2414 // abandoned | |
677 | 2415 calc_other_times_ms = NumberSeq(); |
342 | 2416 } |
2417 check_other_times(1, summary->get_other_seq(), &calc_other_times_ms); | |
2418 } | |
2419 } else { | |
2420 print_indent(0); | |
2421 gclog_or_tty->print_cr("none"); | |
2422 } | |
2423 gclog_or_tty->print_cr(""); | |
2424 } | |
2425 | |
2426 void | |
677 | 2427 G1CollectorPolicy::print_abandoned_summary(PauseSummary* summary) const { |
342 | 2428 bool printed = false; |
677 | 2429 if (summary->get_total_seq()->num() > 0) { |
342 | 2430 printed = true; |
677 | 2431 print_summary(summary); |
342 | 2432 } |
2433 if (!printed) { | |
2434 print_indent(0); | |
2435 gclog_or_tty->print_cr("none"); | |
2436 gclog_or_tty->print_cr(""); | |
2437 } | |
2438 } | |
2439 | |
2440 void G1CollectorPolicy::print_tracing_info() const { | |
2441 if (TraceGen0Time) { | |
2442 gclog_or_tty->print_cr("ALL PAUSES"); | |
2443 print_summary_sd(0, "Total", _all_pause_times_ms); | |
2444 gclog_or_tty->print_cr(""); | |
2445 gclog_or_tty->print_cr(""); | |
2446 gclog_or_tty->print_cr(" Full Young GC Pauses: %8d", _full_young_pause_num); | |
2447 gclog_or_tty->print_cr(" Partial Young GC Pauses: %8d", _partial_young_pause_num); | |
2448 gclog_or_tty->print_cr(""); | |
2449 | |
677 | 2450 gclog_or_tty->print_cr("EVACUATION PAUSES"); |
2451 print_summary(_summary); | |
342 | 2452 |
2453 gclog_or_tty->print_cr("ABANDONED PAUSES"); | |
677 | 2454 print_abandoned_summary(_abandoned_summary); |
342 | 2455 |
2456 gclog_or_tty->print_cr("MISC"); | |
2457 print_summary_sd(0, "Stop World", _all_stop_world_times_ms); | |
2458 print_summary_sd(0, "Yields", _all_yield_times_ms); | |
2459 for (int i = 0; i < _aux_num; ++i) { | |
2460 if (_all_aux_times_ms[i].num() > 0) { | |
2461 char buffer[96]; | |
2462 sprintf(buffer, "Aux%d", i); | |
2463 print_summary_sd(0, buffer, &_all_aux_times_ms[i]); | |
2464 } | |
2465 } | |
2466 | |
2467 size_t all_region_num = _region_num_young + _region_num_tenured; | |
2468 gclog_or_tty->print_cr(" New Regions %8d, Young %8d (%6.2lf%%), " | |
2469 "Tenured %8d (%6.2lf%%)", | |
2470 all_region_num, | |
2471 _region_num_young, | |
2472 (double) _region_num_young / (double) all_region_num * 100.0, | |
2473 _region_num_tenured, | |
2474 (double) _region_num_tenured / (double) all_region_num * 100.0); | |
2475 } | |
2476 if (TraceGen1Time) { | |
2477 if (_all_full_gc_times_ms->num() > 0) { | |
2478 gclog_or_tty->print("\n%4d full_gcs: total time = %8.2f s", | |
2479 _all_full_gc_times_ms->num(), | |
2480 _all_full_gc_times_ms->sum() / 1000.0); | |
2481 gclog_or_tty->print_cr(" (avg = %8.2fms).", _all_full_gc_times_ms->avg()); | |
2482 gclog_or_tty->print_cr(" [std. dev = %8.2f ms, max = %8.2f ms]", | |
2483 _all_full_gc_times_ms->sd(), | |
2484 _all_full_gc_times_ms->maximum()); | |
2485 } | |
2486 } | |
2487 } | |
2488 | |
2489 void G1CollectorPolicy::print_yg_surv_rate_info() const { | |
2490 #ifndef PRODUCT | |
2491 _short_lived_surv_rate_group->print_surv_rate_summary(); | |
2492 // add this call for any other surv rate groups | |
2493 #endif // PRODUCT | |
2494 } | |
2495 | |
2496 bool | |
2497 G1CollectorPolicy::should_add_next_region_to_young_list() { | |
2498 assert(in_young_gc_mode(), "should be in young GC mode"); | |
2499 bool ret; | |
2500 size_t young_list_length = _g1->young_list_length(); | |
545 | 2501 size_t young_list_max_length = _young_list_target_length; |
2502 if (G1FixedEdenSize) { | |
2503 young_list_max_length -= _max_survivor_regions; | |
2504 } | |
2505 if (young_list_length < young_list_max_length) { | |
342 | 2506 ret = true; |
2507 ++_region_num_young; | |
2508 } else { | |
2509 ret = false; | |
2510 ++_region_num_tenured; | |
2511 } | |
2512 | |
2513 return ret; | |
2514 } | |
2515 | |
2516 #ifndef PRODUCT | |
2517 // for debugging, bit of a hack... | |
2518 static char* | |
2519 region_num_to_mbs(int length) { | |
2520 static char buffer[64]; | |
2521 double bytes = (double) (length * HeapRegion::GrainBytes); | |
2522 double mbs = bytes / (double) (1024 * 1024); | |
2523 sprintf(buffer, "%7.2lfMB", mbs); | |
2524 return buffer; | |
2525 } | |
2526 #endif // PRODUCT | |
2527 | |
2528 void | |
2529 G1CollectorPolicy::checkpoint_conc_overhead() { | |
2530 double conc_overhead = 0.0; | |
2531 if (G1AccountConcurrentOverhead) | |
2532 conc_overhead = COTracker::totalPredConcOverhead(); | |
2533 _mmu_tracker->update_conc_overhead(conc_overhead); | |
2534 #if 0 | |
2535 gclog_or_tty->print(" CO %1.4lf TARGET %1.4lf", | |
2536 conc_overhead, _mmu_tracker->max_gc_time()); | |
2537 #endif | |
2538 } | |
2539 | |
2540 | |
545 | 2541 size_t G1CollectorPolicy::max_regions(int purpose) { |
342 | 2542 switch (purpose) { |
2543 case GCAllocForSurvived: | |
545 | 2544 return _max_survivor_regions; |
342 | 2545 case GCAllocForTenured: |
545 | 2546 return REGIONS_UNLIMITED; |
342 | 2547 default: |
545 | 2548 ShouldNotReachHere(); |
2549 return REGIONS_UNLIMITED; | |
342 | 2550 }; |
2551 } | |
2552 | |
545 | 2553 // Calculates survivor space parameters. |
2554 void G1CollectorPolicy::calculate_survivors_policy() | |
2555 { | |
751 | 2556 if (!G1UseSurvivorSpaces) { |
545 | 2557 return; |
2558 } | |
2559 if (G1FixedSurvivorSpaceSize == 0) { | |
2560 _max_survivor_regions = _young_list_target_length / SurvivorRatio; | |
2561 } else { | |
547
1e458753107d
6802413: G1: G1FixedSurvivorSpaceSize should be converted into regions in calculate_survivors_policy()
apetrusenko
parents:
545
diff
changeset
|
2562 _max_survivor_regions = G1FixedSurvivorSpaceSize / HeapRegion::GrainBytes; |
545 | 2563 } |
2564 | |
2565 if (G1FixedTenuringThreshold) { | |
2566 _tenuring_threshold = MaxTenuringThreshold; | |
2567 } else { | |
2568 _tenuring_threshold = _survivors_age_table.compute_tenuring_threshold( | |
2569 HeapRegion::GrainWords * _max_survivor_regions); | |
2570 } | |
2571 } | |
2572 | |
342 | 2573 bool |
2574 G1CollectorPolicy_BestRegionsFirst::should_do_collection_pause(size_t | |
2575 word_size) { | |
2576 assert(_g1->regions_accounted_for(), "Region leakage!"); | |
2577 // Initiate a pause when we reach the steady-state "used" target. | |
2578 size_t used_hard = (_g1->capacity() / 100) * G1SteadyStateUsed; | |
2579 size_t used_soft = | |
2580 MAX2((_g1->capacity() / 100) * (G1SteadyStateUsed - G1SteadyStateUsedDelta), | |
2581 used_hard/2); | |
2582 size_t used = _g1->used(); | |
2583 | |
2584 double max_pause_time_ms = _mmu_tracker->max_gc_time() * 1000.0; | |
2585 | |
2586 size_t young_list_length = _g1->young_list_length(); | |
545 | 2587 size_t young_list_max_length = _young_list_target_length; |
2588 if (G1FixedEdenSize) { | |
2589 young_list_max_length -= _max_survivor_regions; | |
2590 } | |
2591 bool reached_target_length = young_list_length >= young_list_max_length; | |
342 | 2592 |
2593 if (in_young_gc_mode()) { | |
2594 if (reached_target_length) { | |
2595 assert( young_list_length > 0 && _g1->young_list_length() > 0, | |
2596 "invariant" ); | |
2597 _target_pause_time_ms = max_pause_time_ms; | |
2598 return true; | |
2599 } | |
2600 } else { | |
2601 guarantee( false, "should not reach here" ); | |
2602 } | |
2603 | |
2604 return false; | |
2605 } | |
2606 | |
2607 #ifndef PRODUCT | |
2608 class HRSortIndexIsOKClosure: public HeapRegionClosure { | |
2609 CollectionSetChooser* _chooser; | |
2610 public: | |
2611 HRSortIndexIsOKClosure(CollectionSetChooser* chooser) : | |
2612 _chooser(chooser) {} | |
2613 | |
2614 bool doHeapRegion(HeapRegion* r) { | |
2615 if (!r->continuesHumongous()) { | |
2616 assert(_chooser->regionProperlyOrdered(r), "Ought to be."); | |
2617 } | |
2618 return false; | |
2619 } | |
2620 }; | |
2621 | |
2622 bool G1CollectorPolicy_BestRegionsFirst::assertMarkedBytesDataOK() { | |
2623 HRSortIndexIsOKClosure cl(_collectionSetChooser); | |
2624 _g1->heap_region_iterate(&cl); | |
2625 return true; | |
2626 } | |
2627 #endif | |
2628 | |
2629 void | |
2630 G1CollectorPolicy_BestRegionsFirst:: | |
2631 record_collection_pause_start(double start_time_sec, size_t start_used) { | |
2632 G1CollectorPolicy::record_collection_pause_start(start_time_sec, start_used); | |
2633 } | |
2634 | |
2635 class NextNonCSElemFinder: public HeapRegionClosure { | |
2636 HeapRegion* _res; | |
2637 public: | |
2638 NextNonCSElemFinder(): _res(NULL) {} | |
2639 bool doHeapRegion(HeapRegion* r) { | |
2640 if (!r->in_collection_set()) { | |
2641 _res = r; | |
2642 return true; | |
2643 } else { | |
2644 return false; | |
2645 } | |
2646 } | |
2647 HeapRegion* res() { return _res; } | |
2648 }; | |
2649 | |
2650 class KnownGarbageClosure: public HeapRegionClosure { | |
2651 CollectionSetChooser* _hrSorted; | |
2652 | |
2653 public: | |
2654 KnownGarbageClosure(CollectionSetChooser* hrSorted) : | |
2655 _hrSorted(hrSorted) | |
2656 {} | |
2657 | |
2658 bool doHeapRegion(HeapRegion* r) { | |
2659 // We only include humongous regions in collection | |
2660 // sets when concurrent mark shows that their contained object is | |
2661 // unreachable. | |
2662 | |
2663 // Do we have any marking information for this region? | |
2664 if (r->is_marked()) { | |
2665 // We don't include humongous regions in collection | |
2666 // sets because we collect them immediately at the end of a marking | |
2667 // cycle. We also don't include young regions because we *must* | |
2668 // include them in the next collection pause. | |
2669 if (!r->isHumongous() && !r->is_young()) { | |
2670 _hrSorted->addMarkedHeapRegion(r); | |
2671 } | |
2672 } | |
2673 return false; | |
2674 } | |
2675 }; | |
2676 | |
2677 class ParKnownGarbageHRClosure: public HeapRegionClosure { | |
2678 CollectionSetChooser* _hrSorted; | |
2679 jint _marked_regions_added; | |
2680 jint _chunk_size; | |
2681 jint _cur_chunk_idx; | |
2682 jint _cur_chunk_end; // Cur chunk [_cur_chunk_idx, _cur_chunk_end) | |
2683 int _worker; | |
2684 int _invokes; | |
2685 | |
2686 void get_new_chunk() { | |
2687 _cur_chunk_idx = _hrSorted->getParMarkedHeapRegionChunk(_chunk_size); | |
2688 _cur_chunk_end = _cur_chunk_idx + _chunk_size; | |
2689 } | |
2690 void add_region(HeapRegion* r) { | |
2691 if (_cur_chunk_idx == _cur_chunk_end) { | |
2692 get_new_chunk(); | |
2693 } | |
2694 assert(_cur_chunk_idx < _cur_chunk_end, "postcondition"); | |
2695 _hrSorted->setMarkedHeapRegion(_cur_chunk_idx, r); | |
2696 _marked_regions_added++; | |
2697 _cur_chunk_idx++; | |
2698 } | |
2699 | |
2700 public: | |
2701 ParKnownGarbageHRClosure(CollectionSetChooser* hrSorted, | |
2702 jint chunk_size, | |
2703 int worker) : | |
2704 _hrSorted(hrSorted), _chunk_size(chunk_size), _worker(worker), | |
2705 _marked_regions_added(0), _cur_chunk_idx(0), _cur_chunk_end(0), | |
2706 _invokes(0) | |
2707 {} | |
2708 | |
2709 bool doHeapRegion(HeapRegion* r) { | |
2710 // We only include humongous regions in collection | |
2711 // sets when concurrent mark shows that their contained object is | |
2712 // unreachable. | |
2713 _invokes++; | |
2714 | |
2715 // Do we have any marking information for this region? | |
2716 if (r->is_marked()) { | |
2717 // We don't include humongous regions in collection | |
2718 // sets because we collect them immediately at the end of a marking | |
2719 // cycle. | |
2720 // We also do not include young regions in collection sets | |
2721 if (!r->isHumongous() && !r->is_young()) { | |
2722 add_region(r); | |
2723 } | |
2724 } | |
2725 return false; | |
2726 } | |
2727 jint marked_regions_added() { return _marked_regions_added; } | |
2728 int invokes() { return _invokes; } | |
2729 }; | |
2730 | |
2731 class ParKnownGarbageTask: public AbstractGangTask { | |
2732 CollectionSetChooser* _hrSorted; | |
2733 jint _chunk_size; | |
2734 G1CollectedHeap* _g1; | |
2735 public: | |
2736 ParKnownGarbageTask(CollectionSetChooser* hrSorted, jint chunk_size) : | |
2737 AbstractGangTask("ParKnownGarbageTask"), | |
2738 _hrSorted(hrSorted), _chunk_size(chunk_size), | |
2739 _g1(G1CollectedHeap::heap()) | |
2740 {} | |
2741 | |
2742 void work(int i) { | |
2743 ParKnownGarbageHRClosure parKnownGarbageCl(_hrSorted, _chunk_size, i); | |
2744 // Back to zero for the claim value. | |
355 | 2745 _g1->heap_region_par_iterate_chunked(&parKnownGarbageCl, i, |
2746 HeapRegion::InitialClaimValue); | |
342 | 2747 jint regions_added = parKnownGarbageCl.marked_regions_added(); |
2748 _hrSorted->incNumMarkedHeapRegions(regions_added); | |
2749 if (G1PrintParCleanupStats) { | |
2750 gclog_or_tty->print(" Thread %d called %d times, added %d regions to list.\n", | |
2751 i, parKnownGarbageCl.invokes(), regions_added); | |
2752 } | |
2753 } | |
2754 }; | |
2755 | |
2756 void | |
2757 G1CollectorPolicy_BestRegionsFirst:: | |
2758 record_concurrent_mark_cleanup_end(size_t freed_bytes, | |
2759 size_t max_live_bytes) { | |
2760 double start; | |
2761 if (G1PrintParCleanupStats) start = os::elapsedTime(); | |
2762 record_concurrent_mark_cleanup_end_work1(freed_bytes, max_live_bytes); | |
2763 | |
2764 _collectionSetChooser->clearMarkedHeapRegions(); | |
2765 double clear_marked_end; | |
2766 if (G1PrintParCleanupStats) { | |
2767 clear_marked_end = os::elapsedTime(); | |
2768 gclog_or_tty->print_cr(" clear marked regions + work1: %8.3f ms.", | |
2769 (clear_marked_end - start)*1000.0); | |
2770 } | |
2771 if (ParallelGCThreads > 0) { | |
2772 const size_t OverpartitionFactor = 4; | |
2773 const size_t MinChunkSize = 8; | |
2774 const size_t ChunkSize = | |
2775 MAX2(_g1->n_regions() / (ParallelGCThreads * OverpartitionFactor), | |
2776 MinChunkSize); | |
2777 _collectionSetChooser->prepareForAddMarkedHeapRegionsPar(_g1->n_regions(), | |
2778 ChunkSize); | |
2779 ParKnownGarbageTask parKnownGarbageTask(_collectionSetChooser, | |
2780 (int) ChunkSize); | |
2781 _g1->workers()->run_task(&parKnownGarbageTask); | |
355 | 2782 |
2783 assert(_g1->check_heap_region_claim_values(HeapRegion::InitialClaimValue), | |
2784 "sanity check"); | |
342 | 2785 } else { |
2786 KnownGarbageClosure knownGarbagecl(_collectionSetChooser); | |
2787 _g1->heap_region_iterate(&knownGarbagecl); | |
2788 } | |
2789 double known_garbage_end; | |
2790 if (G1PrintParCleanupStats) { | |
2791 known_garbage_end = os::elapsedTime(); | |
2792 gclog_or_tty->print_cr(" compute known garbage: %8.3f ms.", | |
2793 (known_garbage_end - clear_marked_end)*1000.0); | |
2794 } | |
2795 _collectionSetChooser->sortMarkedHeapRegions(); | |
2796 double sort_end; | |
2797 if (G1PrintParCleanupStats) { | |
2798 sort_end = os::elapsedTime(); | |
2799 gclog_or_tty->print_cr(" sorting: %8.3f ms.", | |
2800 (sort_end - known_garbage_end)*1000.0); | |
2801 } | |
2802 | |
2803 record_concurrent_mark_cleanup_end_work2(); | |
2804 double work2_end; | |
2805 if (G1PrintParCleanupStats) { | |
2806 work2_end = os::elapsedTime(); | |
2807 gclog_or_tty->print_cr(" work2: %8.3f ms.", | |
2808 (work2_end - sort_end)*1000.0); | |
2809 } | |
2810 } | |
2811 | |
2812 // Add the heap region to the collection set and return the conservative | |
2813 // estimate of the number of live bytes. | |
2814 void G1CollectorPolicy:: | |
2815 add_to_collection_set(HeapRegion* hr) { | |
751 | 2816 if (G1PrintRegions) { |
342 | 2817 gclog_or_tty->print_cr("added region to cset %d:["PTR_FORMAT", "PTR_FORMAT"], " |
2818 "top "PTR_FORMAT", young %s", | |
2819 hr->hrs_index(), hr->bottom(), hr->end(), | |
2820 hr->top(), (hr->is_young()) ? "YES" : "NO"); | |
2821 } | |
2822 | |
2823 if (_g1->mark_in_progress()) | |
2824 _g1->concurrent_mark()->registerCSetRegion(hr); | |
2825 | |
2826 assert(!hr->in_collection_set(), | |
2827 "should not already be in the CSet"); | |
2828 hr->set_in_collection_set(true); | |
2829 hr->set_next_in_collection_set(_collection_set); | |
2830 _collection_set = hr; | |
2831 _collection_set_size++; | |
2832 _collection_set_bytes_used_before += hr->used(); | |
526 | 2833 _g1->register_region_with_in_cset_fast_test(hr); |
342 | 2834 } |
2835 | |
2836 void | |
2837 G1CollectorPolicy_BestRegionsFirst:: | |
677 | 2838 choose_collection_set() { |
342 | 2839 double non_young_start_time_sec; |
2840 start_recording_regions(); | |
2841 | |
677 | 2842 guarantee(_target_pause_time_ms > -1.0, |
2843 "_target_pause_time_ms should have been set!"); | |
2844 assert(_collection_set == NULL, "Precondition"); | |
342 | 2845 |
2846 double base_time_ms = predict_base_elapsed_time_ms(_pending_cards); | |
2847 double predicted_pause_time_ms = base_time_ms; | |
2848 | |
2849 double target_time_ms = _target_pause_time_ms; | |
2850 double time_remaining_ms = target_time_ms - base_time_ms; | |
2851 | |
2852 // the 10% and 50% values are arbitrary... | |
2853 if (time_remaining_ms < 0.10*target_time_ms) { | |
2854 time_remaining_ms = 0.50 * target_time_ms; | |
2855 _within_target = false; | |
2856 } else { | |
2857 _within_target = true; | |
2858 } | |
2859 | |
2860 // We figure out the number of bytes available for future to-space. | |
2861 // For new regions without marking information, we must assume the | |
2862 // worst-case of complete survival. If we have marking information for a | |
2863 // region, we can bound the amount of live data. We can add a number of | |
2864 // such regions, as long as the sum of the live data bounds does not | |
2865 // exceed the available evacuation space. | |
2866 size_t max_live_bytes = _g1->free_regions() * HeapRegion::GrainBytes; | |
2867 | |
2868 size_t expansion_bytes = | |
2869 _g1->expansion_regions() * HeapRegion::GrainBytes; | |
2870 | |
677 | 2871 _collection_set_bytes_used_before = 0; |
2872 _collection_set_size = 0; | |
342 | 2873 |
2874 // Adjust for expansion and slop. | |
2875 max_live_bytes = max_live_bytes + expansion_bytes; | |
2876 | |
677 | 2877 assert(_g1->regions_accounted_for(), "Region leakage!"); |
342 | 2878 |
2879 HeapRegion* hr; | |
2880 if (in_young_gc_mode()) { | |
2881 double young_start_time_sec = os::elapsedTime(); | |
2882 | |
2883 if (G1PolicyVerbose > 0) { | |
2884 gclog_or_tty->print_cr("Adding %d young regions to the CSet", | |
2885 _g1->young_list_length()); | |
2886 } | |
2887 _young_cset_length = 0; | |
2888 _last_young_gc_full = full_young_gcs() ? true : false; | |
2889 if (_last_young_gc_full) | |
2890 ++_full_young_pause_num; | |
2891 else | |
2892 ++_partial_young_pause_num; | |
2893 hr = _g1->pop_region_from_young_list(); | |
2894 while (hr != NULL) { | |
2895 | |
2896 assert( hr->young_index_in_cset() == -1, "invariant" ); | |
2897 assert( hr->age_in_surv_rate_group() != -1, "invariant" ); | |
2898 hr->set_young_index_in_cset((int) _young_cset_length); | |
2899 | |
2900 ++_young_cset_length; | |
2901 double predicted_time_ms = predict_region_elapsed_time_ms(hr, true); | |
2902 time_remaining_ms -= predicted_time_ms; | |
2903 predicted_pause_time_ms += predicted_time_ms; | |
677 | 2904 assert(!hr->in_collection_set(), "invariant"); |
2905 add_to_collection_set(hr); | |
2906 record_cset_region(hr, true); | |
342 | 2907 max_live_bytes -= MIN2(hr->max_live_bytes(), max_live_bytes); |
2908 if (G1PolicyVerbose > 0) { | |
2909 gclog_or_tty->print_cr(" Added [" PTR_FORMAT ", " PTR_FORMAT") to CS.", | |
2910 hr->bottom(), hr->end()); | |
2911 gclog_or_tty->print_cr(" (" SIZE_FORMAT " KB left in heap.)", | |
2912 max_live_bytes/K); | |
2913 } | |
2914 hr = _g1->pop_region_from_young_list(); | |
2915 } | |
2916 | |
2917 record_scan_only_regions(_g1->young_list_scan_only_length()); | |
2918 | |
2919 double young_end_time_sec = os::elapsedTime(); | |
2920 _recorded_young_cset_choice_time_ms = | |
2921 (young_end_time_sec - young_start_time_sec) * 1000.0; | |
2922 | |
2923 non_young_start_time_sec = os::elapsedTime(); | |
2924 | |
2925 if (_young_cset_length > 0 && _last_young_gc_full) { | |
2926 // don't bother adding more regions... | |
2927 goto choose_collection_set_end; | |
2928 } | |
2929 } | |
2930 | |
2931 if (!in_young_gc_mode() || !full_young_gcs()) { | |
2932 bool should_continue = true; | |
2933 NumberSeq seq; | |
2934 double avg_prediction = 100000000000000000.0; // something very large | |
2935 do { | |
2936 hr = _collectionSetChooser->getNextMarkedRegion(time_remaining_ms, | |
2937 avg_prediction); | |
677 | 2938 if (hr != NULL) { |
342 | 2939 double predicted_time_ms = predict_region_elapsed_time_ms(hr, false); |
2940 time_remaining_ms -= predicted_time_ms; | |
2941 predicted_pause_time_ms += predicted_time_ms; | |
2942 add_to_collection_set(hr); | |
2943 record_cset_region(hr, false); | |
2944 max_live_bytes -= MIN2(hr->max_live_bytes(), max_live_bytes); | |
2945 if (G1PolicyVerbose > 0) { | |
2946 gclog_or_tty->print_cr(" (" SIZE_FORMAT " KB left in heap.)", | |
2947 max_live_bytes/K); | |
2948 } | |
2949 seq.add(predicted_time_ms); | |
2950 avg_prediction = seq.avg() + seq.sd(); | |
2951 } | |
2952 should_continue = | |
2953 ( hr != NULL) && | |
2954 ( (adaptive_young_list_length()) ? time_remaining_ms > 0.0 | |
2955 : _collection_set_size < _young_list_fixed_length ); | |
2956 } while (should_continue); | |
2957 | |
2958 if (!adaptive_young_list_length() && | |
2959 _collection_set_size < _young_list_fixed_length) | |
2960 _should_revert_to_full_young_gcs = true; | |
2961 } | |
2962 | |
2963 choose_collection_set_end: | |
2964 count_CS_bytes_used(); | |
2965 | |
2966 end_recording_regions(); | |
2967 | |
2968 double non_young_end_time_sec = os::elapsedTime(); | |
2969 _recorded_non_young_cset_choice_time_ms = | |
2970 (non_young_end_time_sec - non_young_start_time_sec) * 1000.0; | |
2971 } | |
2972 | |
2973 void G1CollectorPolicy_BestRegionsFirst::record_full_collection_end() { | |
2974 G1CollectorPolicy::record_full_collection_end(); | |
2975 _collectionSetChooser->updateAfterFullCollection(); | |
2976 } | |
2977 | |
2978 void G1CollectorPolicy_BestRegionsFirst:: | |
2979 expand_if_possible(size_t numRegions) { | |
2980 size_t expansion_bytes = numRegions * HeapRegion::GrainBytes; | |
2981 _g1->expand(expansion_bytes); | |
2982 } | |
2983 | |
2984 void G1CollectorPolicy_BestRegionsFirst:: | |
677 | 2985 record_collection_pause_end(bool abandoned) { |
2986 G1CollectorPolicy::record_collection_pause_end(abandoned); | |
342 | 2987 assert(assertMarkedBytesDataOK(), "Marked regions not OK at pause end."); |
2988 } | |
2989 | |
2990 // Local Variables: *** | |
2991 // c-indentation-style: gnu *** | |
2992 // End: *** |