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