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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_GC_G1_G1POLICY_HPP
26 #define SHARE_GC_G1_G1POLICY_HPP
27
28 #include "gc/g1/g1CollectorState.hpp"
29 #include "gc/g1/g1GCPhaseTimes.hpp"
30 #include "gc/g1/g1HeapRegionAttr.hpp"
31 #include "gc/g1/g1InitialMarkToMixedTimeTracker.hpp"
32 #include "gc/g1/g1MMUTracker.hpp"
33 #include "gc/g1/g1OldGenAllocationTracker.hpp"
34 #include "gc/g1/g1RemSetTrackingPolicy.hpp"
35 #include "gc/g1/g1Predictions.hpp"
36 #include "gc/g1/g1YoungGenSizer.hpp"
37 #include "gc/shared/gcCause.hpp"
38 #include "utilities/pair.hpp"
39
40 // A G1Policy makes policy decisions that determine the
41 // characteristics of the collector. Examples include:
42 // * choice of collection set.
43 // * when to collect.
44
45 class HeapRegion;
46 class G1CollectionSet;
47 class G1CollectionSetCandidates;
48 class G1CollectionSetChooser;
49 class G1IHOPControl;
50 class G1Analytics;
51 class G1SurvivorRegions;
90
91 double _reserve_factor;
92 // This will be set when the heap is expanded
93 // for the first time during initialization.
94 uint _reserve_regions;
95
96 G1YoungGenSizer* _young_gen_sizer;
97
98 uint _free_regions_at_end_of_collection;
99
100 size_t _rs_length;
101
102 size_t _rs_length_prediction;
103
104 size_t _pending_cards_at_gc_start;
105
106 // Tracking the allocation in the old generation between
107 // two GCs.
108 G1OldGenAllocationTracker _old_gen_alloc_tracker;
109
110 G1InitialMarkToMixedTimeTracker _initial_mark_to_mixed;
111
112 bool should_update_surv_rate_group_predictors() {
113 return collector_state()->in_young_only_phase() && !collector_state()->mark_or_rebuild_in_progress();
114 }
115
116 double logged_cards_processing_time() const;
117 public:
118 const G1Predictions& predictor() const { return _predictor; }
119 const G1Analytics* analytics() const { return const_cast<const G1Analytics*>(_analytics); }
120
121 G1RemSetTrackingPolicy* remset_tracker() { return &_remset_tracker; }
122
123 G1OldGenAllocationTracker* old_gen_alloc_tracker() { return &_old_gen_alloc_tracker; }
124
125 void set_region_eden(HeapRegion* hr) {
126 hr->set_eden();
127 hr->install_surv_rate_group(_eden_surv_rate_group);
128 }
129
130 void set_region_survivor(HeapRegion* hr) {
254 uint calc_max_old_cset_length() const;
255
256 // Returns the given amount of reclaimable bytes (that represents
257 // the amount of reclaimable space still to be collected) as a
258 // percentage of the current heap capacity.
259 double reclaimable_bytes_percent(size_t reclaimable_bytes) const;
260
261 jlong collection_pause_end_millis() { return _collection_pause_end_millis; }
262
263 private:
264 void clear_collection_set_candidates();
265 // Sets up marking if proper conditions are met.
266 void maybe_start_marking();
267
268 // The kind of STW pause.
269 enum PauseKind {
270 FullGC,
271 YoungOnlyGC,
272 MixedGC,
273 LastYoungGC,
274 InitialMarkGC,
275 Cleanup,
276 Remark
277 };
278
279 // Calculate PauseKind from internal state.
280 PauseKind young_gc_pause_kind() const;
281 // Record the given STW pause with the given start and end times (in s).
282 void record_pause(PauseKind kind, double start, double end);
283 // Indicate that we aborted marking before doing any mixed GCs.
284 void abort_time_to_mixed_tracking();
285
286 // Record and log stats before not-full collection.
287 void record_concurrent_refinement_stats();
288
289 public:
290
291 G1Policy(STWGCTimer* gc_timer);
292
293 virtual ~G1Policy();
294
295 static G1Policy* create_policy(STWGCTimer* gc_timer_stw);
296
297 G1CollectorState* collector_state() const;
298
347
348 // Calculate the number of optional regions from the given collection set candidates,
349 // the remaining time and the maximum number of these regions and return the number
350 // of actually selected regions in num_optional_regions.
351 void calculate_optional_collection_set_regions(G1CollectionSetCandidates* candidates,
352 uint const max_optional_regions,
353 double time_remaining_ms,
354 uint& num_optional_regions);
355
356 private:
357 // Set the state to start a concurrent marking cycle and clear
358 // _initiate_conc_mark_if_possible because it has now been
359 // acted on.
360 void initiate_conc_mark();
361
362 public:
363 // This sets the initiate_conc_mark_if_possible() flag to start a
364 // new cycle, as long as we are not already in one. It's best if it
365 // is called during a safepoint when the test whether a cycle is in
366 // progress or not is stable.
367 bool force_initial_mark_if_outside_cycle(GCCause::Cause gc_cause);
368
369 // This is called at the very beginning of an evacuation pause (it
370 // has to be the first thing that the pause does). If
371 // initiate_conc_mark_if_possible() is true, and the concurrent
372 // marking thread has completed its work during the previous cycle,
373 // it will set in_initial_mark_gc() to so that the pause does
374 // the initial-mark work and start a marking cycle.
375 void decide_on_conc_mark_initiation();
376
377 size_t young_list_target_length() const { return _young_list_target_length; }
378
379 bool should_allocate_mutator_region() const;
380
381 bool can_expand_young_list() const;
382
383 uint young_list_max_length() const {
384 return _young_list_max_length;
385 }
386
387 bool use_adaptive_young_list_length() const;
388
389 void transfer_survivors_to_cset(const G1SurvivorRegions* survivors);
390
391 private:
392 //
393 // Survivor regions policy.
394 //
|
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_GC_G1_G1POLICY_HPP
26 #define SHARE_GC_G1_G1POLICY_HPP
27
28 #include "gc/g1/g1CollectorState.hpp"
29 #include "gc/g1/g1ConcurrentStartToMixedTimeTracker.hpp"
30 #include "gc/g1/g1GCPhaseTimes.hpp"
31 #include "gc/g1/g1HeapRegionAttr.hpp"
32 #include "gc/g1/g1MMUTracker.hpp"
33 #include "gc/g1/g1OldGenAllocationTracker.hpp"
34 #include "gc/g1/g1RemSetTrackingPolicy.hpp"
35 #include "gc/g1/g1Predictions.hpp"
36 #include "gc/g1/g1YoungGenSizer.hpp"
37 #include "gc/shared/gcCause.hpp"
38 #include "utilities/pair.hpp"
39
40 // A G1Policy makes policy decisions that determine the
41 // characteristics of the collector. Examples include:
42 // * choice of collection set.
43 // * when to collect.
44
45 class HeapRegion;
46 class G1CollectionSet;
47 class G1CollectionSetCandidates;
48 class G1CollectionSetChooser;
49 class G1IHOPControl;
50 class G1Analytics;
51 class G1SurvivorRegions;
90
91 double _reserve_factor;
92 // This will be set when the heap is expanded
93 // for the first time during initialization.
94 uint _reserve_regions;
95
96 G1YoungGenSizer* _young_gen_sizer;
97
98 uint _free_regions_at_end_of_collection;
99
100 size_t _rs_length;
101
102 size_t _rs_length_prediction;
103
104 size_t _pending_cards_at_gc_start;
105
106 // Tracking the allocation in the old generation between
107 // two GCs.
108 G1OldGenAllocationTracker _old_gen_alloc_tracker;
109
110 G1ConcurrentStartToMixedTimeTracker _concurrent_start_to_mixed;
111
112 bool should_update_surv_rate_group_predictors() {
113 return collector_state()->in_young_only_phase() && !collector_state()->mark_or_rebuild_in_progress();
114 }
115
116 double logged_cards_processing_time() const;
117 public:
118 const G1Predictions& predictor() const { return _predictor; }
119 const G1Analytics* analytics() const { return const_cast<const G1Analytics*>(_analytics); }
120
121 G1RemSetTrackingPolicy* remset_tracker() { return &_remset_tracker; }
122
123 G1OldGenAllocationTracker* old_gen_alloc_tracker() { return &_old_gen_alloc_tracker; }
124
125 void set_region_eden(HeapRegion* hr) {
126 hr->set_eden();
127 hr->install_surv_rate_group(_eden_surv_rate_group);
128 }
129
130 void set_region_survivor(HeapRegion* hr) {
254 uint calc_max_old_cset_length() const;
255
256 // Returns the given amount of reclaimable bytes (that represents
257 // the amount of reclaimable space still to be collected) as a
258 // percentage of the current heap capacity.
259 double reclaimable_bytes_percent(size_t reclaimable_bytes) const;
260
261 jlong collection_pause_end_millis() { return _collection_pause_end_millis; }
262
263 private:
264 void clear_collection_set_candidates();
265 // Sets up marking if proper conditions are met.
266 void maybe_start_marking();
267
268 // The kind of STW pause.
269 enum PauseKind {
270 FullGC,
271 YoungOnlyGC,
272 MixedGC,
273 LastYoungGC,
274 ConcurrentStartGC,
275 Cleanup,
276 Remark
277 };
278
279 static bool is_young_only_pause(PauseKind kind);
280 static bool is_mixed_pause(PauseKind kind);
281 static bool is_last_young_pause(PauseKind kind);
282 static bool is_concurrent_start_pause(PauseKind kind);
283 // Calculate PauseKind from internal state.
284 PauseKind young_gc_pause_kind() const;
285 // Record the given STW pause with the given start and end times (in s).
286 void record_pause(PauseKind kind, double start, double end);
287 // Indicate that we aborted marking before doing any mixed GCs.
288 void abort_time_to_mixed_tracking();
289
290 // Record and log stats before not-full collection.
291 void record_concurrent_refinement_stats();
292
293 public:
294
295 G1Policy(STWGCTimer* gc_timer);
296
297 virtual ~G1Policy();
298
299 static G1Policy* create_policy(STWGCTimer* gc_timer_stw);
300
301 G1CollectorState* collector_state() const;
302
351
352 // Calculate the number of optional regions from the given collection set candidates,
353 // the remaining time and the maximum number of these regions and return the number
354 // of actually selected regions in num_optional_regions.
355 void calculate_optional_collection_set_regions(G1CollectionSetCandidates* candidates,
356 uint const max_optional_regions,
357 double time_remaining_ms,
358 uint& num_optional_regions);
359
360 private:
361 // Set the state to start a concurrent marking cycle and clear
362 // _initiate_conc_mark_if_possible because it has now been
363 // acted on.
364 void initiate_conc_mark();
365
366 public:
367 // This sets the initiate_conc_mark_if_possible() flag to start a
368 // new cycle, as long as we are not already in one. It's best if it
369 // is called during a safepoint when the test whether a cycle is in
370 // progress or not is stable.
371 bool force_concurrent_start_if_outside_cycle(GCCause::Cause gc_cause);
372
373 // This is called at the very beginning of an evacuation pause (it
374 // has to be the first thing that the pause does). If
375 // initiate_conc_mark_if_possible() is true, and the concurrent
376 // marking thread has completed its work during the previous cycle,
377 // it will set in_concurrent_start_gc() to so that the pause does
378 // the concurrent start work and start a marking cycle.
379 void decide_on_conc_mark_initiation();
380
381 size_t young_list_target_length() const { return _young_list_target_length; }
382
383 bool should_allocate_mutator_region() const;
384
385 bool can_expand_young_list() const;
386
387 uint young_list_max_length() const {
388 return _young_list_max_length;
389 }
390
391 bool use_adaptive_young_list_length() const;
392
393 void transfer_survivors_to_cset(const G1SurvivorRegions* survivors);
394
395 private:
396 //
397 // Survivor regions policy.
398 //
|