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