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