342N/A/*
4485N/A * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
342N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
342N/A *
342N/A * This code is free software; you can redistribute it and/or modify it
342N/A * under the terms of the GNU General Public License version 2 only, as
342N/A * published by the Free Software Foundation.
342N/A *
342N/A * This code is distributed in the hope that it will be useful, but WITHOUT
342N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
342N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
342N/A * version 2 for more details (a copy is included in the LICENSE file that
342N/A * accompanied this code).
342N/A *
342N/A * You should have received a copy of the GNU General Public License version
342N/A * 2 along with this work; if not, write to the Free Software Foundation,
342N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
342N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
342N/A *
342N/A */
342N/A
1879N/A#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTORPOLICY_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTORPOLICY_HPP
1879N/A
1879N/A#include "gc_implementation/g1/collectionSetChooser.hpp"
1879N/A#include "gc_implementation/g1/g1MMUTracker.hpp"
1879N/A#include "memory/collectorPolicy.hpp"
1879N/A
342N/A// A G1CollectorPolicy makes policy decisions that determine the
342N/A// characteristics of the collector. Examples include:
342N/A// * choice of collection set.
342N/A// * when to collect.
342N/A
342N/Aclass HeapRegion;
342N/Aclass CollectionSetChooser;
3885N/Aclass G1GCPhaseTimes;
342N/A
3776N/A// TraceGen0Time collects data on _both_ young and mixed evacuation pauses
3776N/A// (the latter may contain non-young regions - i.e. regions that are
3776N/A// technically in Gen1) while TraceGen1Time collects data about full GCs.
3863N/Aclass TraceGen0TimeData : public CHeapObj<mtGC> {
3776N/A private:
3776N/A unsigned _young_pause_num;
3776N/A unsigned _mixed_pause_num;
3776N/A
3776N/A NumberSeq _all_stop_world_times_ms;
3776N/A NumberSeq _all_yield_times_ms;
342N/A
3776N/A NumberSeq _total;
3776N/A NumberSeq _other;
3776N/A NumberSeq _root_region_scan_wait;
3776N/A NumberSeq _parallel;
3776N/A NumberSeq _ext_root_scan;
3776N/A NumberSeq _satb_filtering;
3776N/A NumberSeq _update_rs;
3776N/A NumberSeq _scan_rs;
3776N/A NumberSeq _obj_copy;
3776N/A NumberSeq _termination;
3776N/A NumberSeq _parallel_other;
3776N/A NumberSeq _clear_ct;
342N/A
3885N/A void print_summary(const char* str, const NumberSeq* seq) const;
3885N/A void print_summary_sd(const char* str, const NumberSeq* seq) const;
342N/A
342N/Apublic:
3776N/A TraceGen0TimeData() : _young_pause_num(0), _mixed_pause_num(0) {};
3776N/A void record_start_collection(double time_to_stop_the_world_ms);
3776N/A void record_yield_time(double yield_time_ms);
3885N/A void record_end_collection(double pause_time_ms, G1GCPhaseTimes* phase_times);
3776N/A void increment_young_collection_count();
3776N/A void increment_mixed_collection_count();
3776N/A void print() const;
342N/A};
342N/A
3863N/Aclass TraceGen1TimeData : public CHeapObj<mtGC> {
3776N/A private:
3776N/A NumberSeq _all_full_gc_times;
342N/A
3776N/A public:
3776N/A void record_full_collection(double full_gc_time_ms);
3776N/A void print() const;
342N/A};
342N/A
3009N/A// There are three command line options related to the young gen size:
3009N/A// NewSize, MaxNewSize and NewRatio (There is also -Xmn, but that is
3009N/A// just a short form for NewSize==MaxNewSize). G1 will use its internal
3009N/A// heuristics to calculate the actual young gen size, so these options
3009N/A// basically only limit the range within which G1 can pick a young gen
3009N/A// size. Also, these are general options taking byte sizes. G1 will
3009N/A// internally work with a number of regions instead. So, some rounding
3009N/A// will occur.
3009N/A//
3009N/A// If nothing related to the the young gen size is set on the command
4195N/A// line we should allow the young gen to be between G1NewSizePercent
4195N/A// and G1MaxNewSizePercent of the heap size. This means that every time
4195N/A// the heap size changes, the limits for the young gen size will be
4195N/A// recalculated.
3009N/A//
3009N/A// If only -XX:NewSize is set we should use the specified value as the
4195N/A// minimum size for young gen. Still using G1MaxNewSizePercent of the
4195N/A// heap as maximum.
3009N/A//
3009N/A// If only -XX:MaxNewSize is set we should use the specified value as the
4195N/A// maximum size for young gen. Still using G1NewSizePercent of the heap
4195N/A// as minimum.
3009N/A//
3009N/A// If -XX:NewSize and -XX:MaxNewSize are both specified we use these values.
3009N/A// No updates when the heap size changes. There is a special case when
3009N/A// NewSize==MaxNewSize. This is interpreted as "fixed" and will use a
3009N/A// different heuristic for calculating the collection set when we do mixed
3009N/A// collection.
3009N/A//
3009N/A// If only -XX:NewRatio is set we should use the specified ratio of the heap
3009N/A// as both min and max. This will be interpreted as "fixed" just like the
3009N/A// NewSize==MaxNewSize case above. But we will update the min and max
3009N/A// everytime the heap size changes.
3009N/A//
3009N/A// NewSize and MaxNewSize override NewRatio. So, NewRatio is ignored if it is
3009N/A// combined with either NewSize or MaxNewSize. (A warning message is printed.)
3863N/Aclass G1YoungGenSizer : public CHeapObj<mtGC> {
3009N/Aprivate:
3009N/A enum SizerKind {
3009N/A SizerDefaults,
3009N/A SizerNewSizeOnly,
3009N/A SizerMaxNewSizeOnly,
3009N/A SizerMaxAndNewSize,
3009N/A SizerNewRatio
3009N/A };
3009N/A SizerKind _sizer_kind;
3681N/A uint _min_desired_young_length;
3681N/A uint _max_desired_young_length;
3009N/A bool _adaptive_size;
3681N/A uint calculate_default_min_length(uint new_number_of_heap_regions);
3681N/A uint calculate_default_max_length(uint new_number_of_heap_regions);
3009N/A
3009N/Apublic:
3009N/A G1YoungGenSizer();
3681N/A void heap_size_changed(uint new_number_of_heap_regions);
3681N/A uint min_desired_young_length() {
3009N/A return _min_desired_young_length;
3009N/A }
3681N/A uint max_desired_young_length() {
3009N/A return _max_desired_young_length;
3009N/A }
3009N/A bool adaptive_young_list_length() {
3009N/A return _adaptive_size;
3009N/A }
3009N/A};
3009N/A
342N/Aclass G1CollectorPolicy: public CollectorPolicy {
2849N/Aprivate:
342N/A // either equal to the number of parallel threads, if ParallelGCThreads
342N/A // has been set, or 1 otherwise
342N/A int _parallel_gc_threads;
342N/A
2941N/A // The number of GC threads currently active.
2941N/A uintx _no_of_gc_threads;
2941N/A
342N/A enum SomePrivateConstants {
942N/A NumPrevPausesForHeuristics = 10
342N/A };
342N/A
342N/A G1MMUTracker* _mmu_tracker;
342N/A
342N/A void initialize_flags();
342N/A
342N/A void initialize_all() {
342N/A initialize_flags();
342N/A initialize_size_info();
342N/A initialize_perm_generation(PermGen::MarkSweepCompact);
342N/A }
342N/A
2849N/A CollectionSetChooser* _collectionSetChooser;
342N/A
3885N/A double _full_collection_start_sec;
342N/A size_t _cur_collection_pause_used_at_start_bytes;
3681N/A uint _cur_collection_pause_used_regions_at_start;
890N/A
342N/A // These exclude marking times.
342N/A TruncatedSeq* _recent_gc_times_ms;
342N/A
342N/A TruncatedSeq* _concurrent_mark_remark_times_ms;
342N/A TruncatedSeq* _concurrent_mark_cleanup_times_ms;
342N/A
3776N/A TraceGen0TimeData _trace_gen0_time_data;
3776N/A TraceGen1TimeData _trace_gen1_time_data;
342N/A
342N/A double _stop_world_start;
342N/A
2986N/A // indicates whether we are in young or mixed GC mode
2986N/A bool _gcs_are_young;
342N/A
3681N/A uint _young_list_target_length;
3681N/A uint _young_list_fixed_length;
2754N/A size_t _prev_eden_capacity; // used for logging
342N/A
1898N/A // The max number of regions we can extend the eden by while the GC
1898N/A // locker is active. This should be >= _young_list_target_length;
3681N/A uint _young_list_max_length;
1898N/A
2986N/A bool _last_gc_was_young;
342N/A
342N/A bool _during_marking;
342N/A bool _in_marking_window;
342N/A bool _in_marking_window_im;
342N/A
342N/A SurvRateGroup* _short_lived_surv_rate_group;
342N/A SurvRateGroup* _survivor_surv_rate_group;
342N/A // add here any more surv rate groups
342N/A
1356N/A double _gc_overhead_perc;
1356N/A
2753N/A double _reserve_factor;
3681N/A uint _reserve_regions;
2753N/A
342N/A bool during_marking() {
342N/A return _during_marking;
342N/A }
342N/A
342N/Aprivate:
342N/A enum PredictionConstants {
342N/A TruncatedSeqLength = 10
342N/A };
342N/A
342N/A TruncatedSeq* _alloc_rate_ms_seq;
342N/A double _prev_collection_pause_end_ms;
342N/A
342N/A TruncatedSeq* _rs_length_diff_seq;
342N/A TruncatedSeq* _cost_per_card_ms_seq;
2986N/A TruncatedSeq* _young_cards_per_entry_ratio_seq;
2986N/A TruncatedSeq* _mixed_cards_per_entry_ratio_seq;
342N/A TruncatedSeq* _cost_per_entry_ms_seq;
2986N/A TruncatedSeq* _mixed_cost_per_entry_ms_seq;
342N/A TruncatedSeq* _cost_per_byte_ms_seq;
342N/A TruncatedSeq* _constant_other_time_ms_seq;
342N/A TruncatedSeq* _young_other_cost_per_region_ms_seq;
342N/A TruncatedSeq* _non_young_other_cost_per_region_ms_seq;
342N/A
342N/A TruncatedSeq* _pending_cards_seq;
342N/A TruncatedSeq* _rs_lengths_seq;
342N/A
342N/A TruncatedSeq* _cost_per_byte_ms_during_cm_seq;
342N/A
3009N/A G1YoungGenSizer* _young_gen_sizer;
2754N/A
3681N/A uint _eden_cset_region_length;
3681N/A uint _survivor_cset_region_length;
3681N/A uint _old_cset_region_length;
2936N/A
3681N/A void init_cset_region_lengths(uint eden_cset_region_length,
3681N/A uint survivor_cset_region_length);
2936N/A
3681N/A uint eden_cset_region_length() { return _eden_cset_region_length; }
3681N/A uint survivor_cset_region_length() { return _survivor_cset_region_length; }
3681N/A uint old_cset_region_length() { return _old_cset_region_length; }
342N/A
3681N/A uint _free_regions_at_end_of_collection;
342N/A
342N/A size_t _recorded_rs_lengths;
342N/A size_t _max_rs_lengths;
342N/A double _sigma;
342N/A
342N/A size_t _rs_lengths_prediction;
342N/A
3201N/A double sigma() { return _sigma; }
342N/A
342N/A // A function that prevents us putting too much stock in small sample
342N/A // sets. Returns a number between 2.0 and 1.0, depending on the number
342N/A // of samples. 5 or more samples yields one; fewer scales linearly from
342N/A // 2.0 at 1 sample to 1.0 at 5.
342N/A double confidence_factor(int samples) {
342N/A if (samples > 4) return 1.0;
342N/A else return 1.0 + sigma() * ((double)(5 - samples))/2.0;
342N/A }
342N/A
342N/A double get_new_neg_prediction(TruncatedSeq* seq) {
342N/A return seq->davg() - sigma() * seq->dsd();
342N/A }
342N/A
342N/A#ifndef PRODUCT
342N/A bool verify_young_ages(HeapRegion* head, SurvRateGroup *surv_rate_group);
342N/A#endif // PRODUCT
342N/A
1111N/A void adjust_concurrent_refinement(double update_rs_time,
1111N/A double update_rs_processed_buffers,
1111N/A double goal_ms);
1111N/A
2941N/A uintx no_of_gc_threads() { return _no_of_gc_threads; }
2941N/A void set_no_of_gc_threads(uintx v) { _no_of_gc_threads = v; }
2941N/A
342N/A double _pause_time_target_ms;
3885N/A
342N/A size_t _pending_cards;
342N/A
342N/Apublic:
2941N/A // Accessors
342N/A
2936N/A void set_region_eden(HeapRegion* hr, int young_index_in_cset) {
2936N/A hr->set_young();
342N/A hr->install_surv_rate_group(_short_lived_surv_rate_group);
2936N/A hr->set_young_index_in_cset(young_index_in_cset);
342N/A }
342N/A
2936N/A void set_region_survivor(HeapRegion* hr, int young_index_in_cset) {
2936N/A assert(hr->is_young() && hr->is_survivor(), "pre-condition");
342N/A hr->install_surv_rate_group(_survivor_surv_rate_group);
2936N/A hr->set_young_index_in_cset(young_index_in_cset);
342N/A }
342N/A
342N/A#ifndef PRODUCT
342N/A bool verify_young_ages();
342N/A#endif // PRODUCT
342N/A
342N/A double get_new_prediction(TruncatedSeq* seq) {
342N/A return MAX2(seq->davg() + sigma() * seq->dsd(),
342N/A seq->davg() * confidence_factor(seq->num()));
342N/A }
342N/A
342N/A void record_max_rs_lengths(size_t rs_lengths) {
342N/A _max_rs_lengths = rs_lengths;
342N/A }
342N/A
342N/A size_t predict_rs_length_diff() {
342N/A return (size_t) get_new_prediction(_rs_length_diff_seq);
342N/A }
342N/A
342N/A double predict_alloc_rate_ms() {
342N/A return get_new_prediction(_alloc_rate_ms_seq);
342N/A }
342N/A
342N/A double predict_cost_per_card_ms() {
342N/A return get_new_prediction(_cost_per_card_ms_seq);
342N/A }
342N/A
342N/A double predict_rs_update_time_ms(size_t pending_cards) {
342N/A return (double) pending_cards * predict_cost_per_card_ms();
342N/A }
342N/A
2986N/A double predict_young_cards_per_entry_ratio() {
2986N/A return get_new_prediction(_young_cards_per_entry_ratio_seq);
342N/A }
342N/A
2986N/A double predict_mixed_cards_per_entry_ratio() {
2986N/A if (_mixed_cards_per_entry_ratio_seq->num() < 2) {
2986N/A return predict_young_cards_per_entry_ratio();
2986N/A } else {
2986N/A return get_new_prediction(_mixed_cards_per_entry_ratio_seq);
2986N/A }
342N/A }
342N/A
342N/A size_t predict_young_card_num(size_t rs_length) {
342N/A return (size_t) ((double) rs_length *
2986N/A predict_young_cards_per_entry_ratio());
342N/A }
342N/A
342N/A size_t predict_non_young_card_num(size_t rs_length) {
342N/A return (size_t) ((double) rs_length *
2986N/A predict_mixed_cards_per_entry_ratio());
342N/A }
342N/A
342N/A double predict_rs_scan_time_ms(size_t card_num) {
2986N/A if (gcs_are_young()) {
342N/A return (double) card_num * get_new_prediction(_cost_per_entry_ms_seq);
2986N/A } else {
2986N/A return predict_mixed_rs_scan_time_ms(card_num);
2986N/A }
342N/A }
342N/A
2986N/A double predict_mixed_rs_scan_time_ms(size_t card_num) {
2986N/A if (_mixed_cost_per_entry_ms_seq->num() < 3) {
342N/A return (double) card_num * get_new_prediction(_cost_per_entry_ms_seq);
2986N/A } else {
2986N/A return (double) (card_num *
2986N/A get_new_prediction(_mixed_cost_per_entry_ms_seq));
2986N/A }
342N/A }
342N/A
342N/A double predict_object_copy_time_ms_during_cm(size_t bytes_to_copy) {
2986N/A if (_cost_per_byte_ms_during_cm_seq->num() < 3) {
2986N/A return (1.1 * (double) bytes_to_copy) *
2986N/A get_new_prediction(_cost_per_byte_ms_seq);
2986N/A } else {
342N/A return (double) bytes_to_copy *
2986N/A get_new_prediction(_cost_per_byte_ms_during_cm_seq);
2986N/A }
342N/A }
342N/A
342N/A double predict_object_copy_time_ms(size_t bytes_to_copy) {
2986N/A if (_in_marking_window && !_in_marking_window_im) {
342N/A return predict_object_copy_time_ms_during_cm(bytes_to_copy);
2986N/A } else {
342N/A return (double) bytes_to_copy *
2986N/A get_new_prediction(_cost_per_byte_ms_seq);
2986N/A }
342N/A }
342N/A
342N/A double predict_constant_other_time_ms() {
342N/A return get_new_prediction(_constant_other_time_ms_seq);
342N/A }
342N/A
342N/A double predict_young_other_time_ms(size_t young_num) {
2986N/A return (double) young_num *
2986N/A get_new_prediction(_young_other_cost_per_region_ms_seq);
342N/A }
342N/A
342N/A double predict_non_young_other_time_ms(size_t non_young_num) {
2986N/A return (double) non_young_num *
2986N/A get_new_prediction(_non_young_other_cost_per_region_ms_seq);
342N/A }
342N/A
342N/A double predict_base_elapsed_time_ms(size_t pending_cards);
342N/A double predict_base_elapsed_time_ms(size_t pending_cards,
342N/A size_t scanned_cards);
342N/A size_t predict_bytes_to_copy(HeapRegion* hr);
3961N/A double predict_region_elapsed_time_ms(HeapRegion* hr, bool for_young_gc);
342N/A
2936N/A void set_recorded_rs_lengths(size_t rs_lengths);
1394N/A
3681N/A uint cset_region_length() { return young_cset_region_length() +
3681N/A old_cset_region_length(); }
3681N/A uint young_cset_region_length() { return eden_cset_region_length() +
3681N/A survivor_cset_region_length(); }
342N/A
545N/A double predict_survivor_regions_evac_time();
545N/A
342N/A void cset_regions_freed() {
2986N/A bool propagate = _last_gc_was_young && !_in_marking_window;
342N/A _short_lived_surv_rate_group->all_surviving_words_recorded(propagate);
342N/A _survivor_surv_rate_group->all_surviving_words_recorded(propagate);
342N/A // also call it on any more surv rate groups
342N/A }
342N/A
342N/A G1MMUTracker* mmu_tracker() {
342N/A return _mmu_tracker;
342N/A }
342N/A
1576N/A double max_pause_time_ms() {
1576N/A return _mmu_tracker->max_gc_time() * 1000.0;
1576N/A }
1576N/A
342N/A double predict_remark_time_ms() {
342N/A return get_new_prediction(_concurrent_mark_remark_times_ms);
342N/A }
342N/A
342N/A double predict_cleanup_time_ms() {
342N/A return get_new_prediction(_concurrent_mark_cleanup_times_ms);
342N/A }
342N/A
342N/A // Returns an estimate of the survival rate of the region at yg-age
342N/A // "yg_age".
545N/A double predict_yg_surv_rate(int age, SurvRateGroup* surv_rate_group) {
545N/A TruncatedSeq* seq = surv_rate_group->get_seq(age);
342N/A if (seq->num() == 0)
342N/A gclog_or_tty->print("BARF! age is %d", age);
342N/A guarantee( seq->num() > 0, "invariant" );
342N/A double pred = get_new_prediction(seq);
342N/A if (pred > 1.0)
342N/A pred = 1.0;
342N/A return pred;
342N/A }
342N/A
545N/A double predict_yg_surv_rate(int age) {
545N/A return predict_yg_surv_rate(age, _short_lived_surv_rate_group);
545N/A }
545N/A
342N/A double accum_yg_surv_rate_pred(int age) {
342N/A return _short_lived_surv_rate_group->accum_surv_rate_pred(age);
342N/A }
342N/A
2849N/Aprivate:
342N/A // Statistics kept per GC stoppage, pause or full.
342N/A TruncatedSeq* _recent_prev_end_times_for_all_gcs_sec;
342N/A
342N/A // Add a new GC of the given duration and end time to the record.
342N/A void update_recent_gc_times(double end_time_sec, double elapsed_ms);
342N/A
342N/A // The head of the list (via "next_in_collection_set()") representing the
1394N/A // current collection set. Set from the incrementally built collection
1394N/A // set at the start of the pause.
342N/A HeapRegion* _collection_set;
1394N/A
1394N/A // The number of bytes in the collection set before the pause. Set from
1394N/A // the incrementally built collection set at the start of an evacuation
3961N/A // pause, and incremented in finalize_cset() when adding old regions
3961N/A // (if any) to the collection set.
342N/A size_t _collection_set_bytes_used_before;
342N/A
3961N/A // The number of bytes copied during the GC.
3961N/A size_t _bytes_copied_during_gc;
3961N/A
1394N/A // The associated information that is maintained while the incremental
1394N/A // collection set is being built with young regions. Used to populate
1394N/A // the recorded info for the evacuation pause.
1394N/A
1394N/A enum CSetBuildType {
1394N/A Active, // We are actively building the collection set
1394N/A Inactive // We are not actively building the collection set
1394N/A };
1394N/A
1394N/A CSetBuildType _inc_cset_build_state;
1394N/A
1394N/A // The head of the incrementally built collection set.
1394N/A HeapRegion* _inc_cset_head;
1394N/A
1394N/A // The tail of the incrementally built collection set.
1394N/A HeapRegion* _inc_cset_tail;
1394N/A
1394N/A // The number of bytes in the incrementally built collection set.
1394N/A // Used to set _collection_set_bytes_used_before at the start of
1394N/A // an evacuation pause.
1394N/A size_t _inc_cset_bytes_used_before;
1394N/A
1394N/A // Used to record the highest end of heap region in collection set
1394N/A HeapWord* _inc_cset_max_finger;
1394N/A
3007N/A // The RSet lengths recorded for regions in the CSet. It is updated
3007N/A // by the thread that adds a new region to the CSet. We assume that
3007N/A // only one thread can be allocating a new CSet region (currently,
3007N/A // it does so after taking the Heap_lock) hence no need to
3007N/A // synchronize updates to this field.
1394N/A size_t _inc_cset_recorded_rs_lengths;
1394N/A
3007N/A // A concurrent refinement thread periodcially samples the young
3007N/A // region RSets and needs to update _inc_cset_recorded_rs_lengths as
3007N/A // the RSets grow. Instead of having to syncronize updates to that
3007N/A // field we accumulate them in this field and add it to
3007N/A // _inc_cset_recorded_rs_lengths_diffs at the start of a GC.
3007N/A ssize_t _inc_cset_recorded_rs_lengths_diffs;
3007N/A
3007N/A // The predicted elapsed time it will take to collect the regions in
3007N/A // the CSet. This is updated by the thread that adds a new region to
3007N/A // the CSet. See the comment for _inc_cset_recorded_rs_lengths about
3007N/A // MT-safety assumptions.
1394N/A double _inc_cset_predicted_elapsed_time_ms;
1394N/A
3007N/A // See the comment for _inc_cset_recorded_rs_lengths_diffs.
3007N/A double _inc_cset_predicted_elapsed_time_ms_diffs;
3007N/A
342N/A // Stash a pointer to the g1 heap.
342N/A G1CollectedHeap* _g1;
342N/A
3885N/A G1GCPhaseTimes* _phase_times;
3885N/A
342N/A // The ratio of gc time to elapsed time, computed over recent pauses.
342N/A double _recent_avg_pause_time_ratio;
342N/A
342N/A double recent_avg_pause_time_ratio() {
342N/A return _recent_avg_pause_time_ratio;
342N/A }
342N/A
1359N/A // At the end of a pause we check the heap occupancy and we decide
1359N/A // whether we will start a marking cycle during the next pause. If
1359N/A // we decide that we want to do that, we will set this parameter to
1359N/A // true. So, this parameter will stay true between the end of a
1359N/A // pause and the beginning of a subsequent pause (not necessarily
1359N/A // the next one, see the comments on the next field) when we decide
1359N/A // that we will indeed start a marking cycle and do the initial-mark
1359N/A // work.
1359N/A volatile bool _initiate_conc_mark_if_possible;
342N/A
1359N/A // If initiate_conc_mark_if_possible() is set at the beginning of a
1359N/A // pause, it is a suggestion that the pause should start a marking
1359N/A // cycle by doing the initial-mark work. However, it is possible
1359N/A // that the concurrent marking thread is still finishing up the
1359N/A // previous marking cycle (e.g., clearing the next marking
1359N/A // bitmap). If that is the case we cannot start a new cycle and
1359N/A // we'll have to wait for the concurrent marking thread to finish
1359N/A // what it is doing. In this case we will postpone the marking cycle
1359N/A // initiation decision for the next pause. When we eventually decide
1359N/A // to start a cycle, we will set _during_initial_mark_pause which
1359N/A // will stay true until the end of the initial-mark pause and it's
1359N/A // the condition that indicates that a pause is doing the
1359N/A // initial-mark work.
1359N/A volatile bool _during_initial_mark_pause;
1359N/A
2986N/A bool _last_young_gc;
342N/A
342N/A // This set of variables tracks the collector efficiency, in order to
342N/A // determine whether we should initiate a new marking.
342N/A double _cur_mark_stop_world_time_ms;
342N/A double _mark_remark_start_sec;
342N/A double _mark_cleanup_start_sec;
342N/A
2753N/A // Update the young list target length either by setting it to the
2753N/A // desired fixed value or by calculating it using G1's pause
2753N/A // prediction model. If no rs_lengths parameter is passed, predict
2753N/A // the RS lengths using the prediction model, otherwise use the
2753N/A // given rs_lengths as the prediction.
2753N/A void update_young_list_target_length(size_t rs_lengths = (size_t) -1);
2753N/A
2753N/A // Calculate and return the minimum desired young list target
2753N/A // length. This is the minimum desired young list length according
2753N/A // to the user's inputs.
3681N/A uint calculate_young_list_desired_min_length(uint base_min_length);
2753N/A
2753N/A // Calculate and return the maximum desired young list target
2753N/A // length. This is the maximum desired young list length according
2753N/A // to the user's inputs.
3681N/A uint calculate_young_list_desired_max_length();
2753N/A
2753N/A // Calculate and return the maximum young list target length that
2753N/A // can fit into the pause time goal. The parameters are: rs_lengths
2753N/A // represent the prediction of how large the young RSet lengths will
2753N/A // be, base_min_length is the alreay existing number of regions in
2753N/A // the young list, min_length and max_length are the desired min and
2753N/A // max young list length according to the user's inputs.
3681N/A uint calculate_young_list_target_length(size_t rs_lengths,
3681N/A uint base_min_length,
3681N/A uint desired_min_length,
3681N/A uint desired_max_length);
2753N/A
2753N/A // Check whether a given young length (young_length) fits into the
2753N/A // given target pause time and whether the prediction for the amount
2753N/A // of objects to be copied for the given length will fit into the
2753N/A // given free space (expressed by base_free_regions). It is used by
2753N/A // calculate_young_list_target_length().
3681N/A bool predict_will_fit(uint young_length, double base_time_ms,
3681N/A uint base_free_regions, double target_pause_time_ms);
342N/A
4461N/A // Calculate the minimum number of old regions we'll add to the CSet
4461N/A // during a mixed GC.
4461N/A uint calc_min_old_cset_length();
4461N/A
4461N/A // Calculate the maximum number of old regions we'll add to the CSet
4461N/A // during a mixed GC.
4461N/A uint calc_max_old_cset_length();
4461N/A
4461N/A // Returns the given amount of uncollected reclaimable space
4461N/A // as a percentage of the current heap capacity.
4461N/A double reclaimable_bytes_perc(size_t reclaimable_bytes);
4461N/A
342N/Apublic:
342N/A
342N/A G1CollectorPolicy();
342N/A
342N/A virtual G1CollectorPolicy* as_g1_policy() { return this; }
342N/A
342N/A virtual CollectorPolicy::Name kind() {
342N/A return CollectorPolicy::G1CollectorPolicyKind;
342N/A }
342N/A
3885N/A G1GCPhaseTimes* phase_times() const { return _phase_times; }
3885N/A
2753N/A // Check the current value of the young list RSet lengths and
2753N/A // compare it against the last prediction. If the current value is
2753N/A // higher, recalculate the young list target length prediction.
2753N/A void revise_young_list_target_length_if_necessary();
342N/A
2754N/A // This should be called after the heap is resized.
3681N/A void record_new_heap_size(uint new_number_of_regions);
2753N/A
2849N/A void init();
342N/A
545N/A // Create jstat counters for the policy.
545N/A virtual void initialize_gc_policy_counters();
545N/A
342N/A virtual HeapWord* mem_allocate_work(size_t size,
342N/A bool is_tlab,
342N/A bool* gc_overhead_limit_was_exceeded);
342N/A
342N/A // This method controls how a collector handles one or more
342N/A // of its generations being fully allocated.
342N/A virtual HeapWord* satisfy_failed_allocation(size_t size,
342N/A bool is_tlab);
342N/A
342N/A BarrierSet::Name barrier_set_name() { return BarrierSet::G1SATBCTLogging; }
342N/A
342N/A GenRemSet::Name rem_set_name() { return GenRemSet::CardTable; }
342N/A
3117N/A bool need_to_start_conc_mark(const char* source, size_t alloc_word_size = 0);
3112N/A
4485N/A // Record the start and end of an evacuation pause.
4485N/A void record_collection_pause_start(double start_time_sec);
4485N/A void record_collection_pause_end(double pause_time_ms, EvacuationInfo& evacuation_info);
342N/A
4485N/A // Record the start and end of a full collection.
4485N/A void record_full_collection_start();
4485N/A void record_full_collection_end();
342N/A
342N/A // Must currently be called while the world is stopped.
4485N/A void record_concurrent_mark_init_end(double mark_init_elapsed_time_ms);
342N/A
4485N/A // Record start and end of remark.
2849N/A void record_concurrent_mark_remark_start();
2849N/A void record_concurrent_mark_remark_end();
342N/A
4485N/A // Record start, end, and completion of cleanup.
2849N/A void record_concurrent_mark_cleanup_start();
2941N/A void record_concurrent_mark_cleanup_end(int no_of_gc_threads);
2849N/A void record_concurrent_mark_cleanup_completed();
342N/A
4485N/A // Records the information about the heap size for reporting in
4485N/A // print_detailed_heap_transition
4485N/A void record_heap_size_info_at_start();
342N/A
4485N/A // Print heap sizing transition (with less and more detail).
2589N/A void print_heap_transition();
3978N/A void print_detailed_heap_transition();
342N/A
4485N/A void record_stop_world_start();
4485N/A void record_concurrent_pause();
342N/A
2655N/A // Record how much space we copied during a GC. This is typically
2655N/A // called when a GC alloc region is being retired.
2655N/A void record_bytes_copied_during_gc(size_t bytes) {
2655N/A _bytes_copied_during_gc += bytes;
2655N/A }
2655N/A
2655N/A // The amount of space we copied during a GC.
2655N/A size_t bytes_copied_during_gc() {
2655N/A return _bytes_copied_during_gc;
2655N/A }
342N/A
3643N/A // Determine whether there are candidate regions so that the
3643N/A // next GC should be mixed. The two action strings are used
3643N/A // in the ergo output when the method returns true or false.
3201N/A bool next_gc_should_be_mixed(const char* true_action_str,
3201N/A const char* false_action_str);
3201N/A
342N/A // Choose a new collection set. Marks the chosen regions as being
342N/A // "in_collection_set", and links them together. The head and number of
342N/A // the collection set are available via access methods.
4362N/A void finalize_cset(double target_pause_time_ms, EvacuationInfo& evacuation_info);
342N/A
342N/A // The head of the list (via "next_in_collection_set()") representing the
342N/A // current collection set.
342N/A HeapRegion* collection_set() { return _collection_set; }
342N/A
1394N/A void clear_collection_set() { _collection_set = NULL; }
1394N/A
2936N/A // Add old region "hr" to the CSet.
2936N/A void add_old_region_to_cset(HeapRegion* hr);
342N/A
1394N/A // Incremental CSet Support
1394N/A
1394N/A // The head of the incrementally built collection set.
1394N/A HeapRegion* inc_cset_head() { return _inc_cset_head; }
1394N/A
1394N/A // The tail of the incrementally built collection set.
1394N/A HeapRegion* inc_set_tail() { return _inc_cset_tail; }
1394N/A
1394N/A // Initialize incremental collection set info.
1394N/A void start_incremental_cset_building();
1394N/A
3007N/A // Perform any final calculations on the incremental CSet fields
3007N/A // before we can use them.
3007N/A void finalize_incremental_cset_building();
3007N/A
1394N/A void clear_incremental_cset() {
1394N/A _inc_cset_head = NULL;
1394N/A _inc_cset_tail = NULL;
1394N/A }
1394N/A
1394N/A // Stop adding regions to the incremental collection set
1394N/A void stop_incremental_cset_building() { _inc_cset_build_state = Inactive; }
1394N/A
3007N/A // Add information about hr to the aggregated information for the
3007N/A // incrementally built collection set.
1394N/A void add_to_incremental_cset_info(HeapRegion* hr, size_t rs_length);
1394N/A
1394N/A // Update information about hr in the aggregated information for
1394N/A // the incrementally built collection set.
1394N/A void update_incremental_cset_info(HeapRegion* hr, size_t new_rs_length);
1394N/A
1394N/Aprivate:
1394N/A // Update the incremental cset information when adding a region
1394N/A // (should not be called directly).
1394N/A void add_region_to_incremental_cset_common(HeapRegion* hr);
1394N/A
1394N/Apublic:
1394N/A // Add hr to the LHS of the incremental collection set.
1394N/A void add_region_to_incremental_cset_lhs(HeapRegion* hr);
1394N/A
1394N/A // Add hr to the RHS of the incremental collection set.
1394N/A void add_region_to_incremental_cset_rhs(HeapRegion* hr);
1394N/A
1394N/A#ifndef PRODUCT
1394N/A void print_collection_set(HeapRegion* list_head, outputStream* st);
1394N/A#endif // !PRODUCT
1394N/A
1359N/A bool initiate_conc_mark_if_possible() { return _initiate_conc_mark_if_possible; }
1359N/A void set_initiate_conc_mark_if_possible() { _initiate_conc_mark_if_possible = true; }
1359N/A void clear_initiate_conc_mark_if_possible() { _initiate_conc_mark_if_possible = false; }
1359N/A
1359N/A bool during_initial_mark_pause() { return _during_initial_mark_pause; }
1359N/A void set_during_initial_mark_pause() { _during_initial_mark_pause = true; }
1359N/A void clear_during_initial_mark_pause(){ _during_initial_mark_pause = false; }
1359N/A
1576N/A // This sets the initiate_conc_mark_if_possible() flag to start a
1576N/A // new cycle, as long as we are not already in one. It's best if it
1576N/A // is called during a safepoint when the test whether a cycle is in
1576N/A // progress or not is stable.
2748N/A bool force_initial_mark_if_outside_cycle(GCCause::Cause gc_cause);
1576N/A
1359N/A // This is called at the very beginning of an evacuation pause (it
1359N/A // has to be the first thing that the pause does). If
1359N/A // initiate_conc_mark_if_possible() is true, and the concurrent
1359N/A // marking thread has completed its work during the previous cycle,
1359N/A // it will set during_initial_mark_pause() to so that the pause does
1359N/A // the initial-mark work and start a marking cycle.
1359N/A void decide_on_conc_mark_initiation();
342N/A
342N/A // If an expansion would be appropriate, because recent GC overhead had
342N/A // exceeded the desired limit, return an amount to expand by.
2849N/A size_t expansion_amount();
342N/A
342N/A // Print tracing information.
342N/A void print_tracing_info() const;
342N/A
342N/A // Print stats on young survival ratio
342N/A void print_yg_surv_rate_info() const;
342N/A
545N/A void finished_recalculating_age_indexes(bool is_survivors) {
545N/A if (is_survivors) {
545N/A _survivor_surv_rate_group->finished_recalculating_age_indexes();
545N/A } else {
545N/A _short_lived_surv_rate_group->finished_recalculating_age_indexes();
545N/A }
342N/A // do that for any other surv rate groups
342N/A }
342N/A
1880N/A bool is_young_list_full() {
3681N/A uint young_list_length = _g1->young_list()->length();
3681N/A uint young_list_target_length = _young_list_target_length;
1898N/A return young_list_length >= young_list_target_length;
1898N/A }
1898N/A
1898N/A bool can_expand_young_list() {
3681N/A uint young_list_length = _g1->young_list()->length();
3681N/A uint young_list_max_length = _young_list_max_length;
1898N/A return young_list_length < young_list_max_length;
1898N/A }
1880N/A
3681N/A uint young_list_max_length() {
2816N/A return _young_list_max_length;
2816N/A }
2816N/A
2986N/A bool gcs_are_young() {
2986N/A return _gcs_are_young;
342N/A }
2986N/A void set_gcs_are_young(bool gcs_are_young) {
2986N/A _gcs_are_young = gcs_are_young;
342N/A }
342N/A
342N/A bool adaptive_young_list_length() {
3009N/A return _young_gen_sizer->adaptive_young_list_length();
342N/A }
342N/A
2849N/Aprivate:
342N/A //
342N/A // Survivor regions policy.
342N/A //
342N/A
342N/A // Current tenuring threshold, set to 0 if the collector reaches the
342N/A // maximum amount of suvivors regions.
342N/A int _tenuring_threshold;
342N/A
545N/A // The limit on the number of regions allocated for survivors.
3681N/A uint _max_survivor_regions;
545N/A
2589N/A // For reporting purposes.
2589N/A size_t _eden_bytes_before_gc;
2589N/A size_t _survivor_bytes_before_gc;
2589N/A size_t _capacity_before_gc;
2589N/A
545N/A // The amount of survor regions after a collection.
3681N/A uint _recorded_survivor_regions;
545N/A // List of survivor regions.
545N/A HeapRegion* _recorded_survivor_head;
545N/A HeapRegion* _recorded_survivor_tail;
545N/A
545N/A ageTable _survivors_age_table;
545N/A
342N/Apublic:
4355N/A uint tenuring_threshold() const { return _tenuring_threshold; }
342N/A
342N/A inline GCAllocPurpose
342N/A evacuation_destination(HeapRegion* src_region, int age, size_t word_sz) {
342N/A if (age < _tenuring_threshold && src_region->is_young()) {
342N/A return GCAllocForSurvived;
342N/A } else {
342N/A return GCAllocForTenured;
342N/A }
342N/A }
342N/A
342N/A inline bool track_object_age(GCAllocPurpose purpose) {
342N/A return purpose == GCAllocForSurvived;
342N/A }
342N/A
3681N/A static const uint REGIONS_UNLIMITED = (uint) -1;
545N/A
3681N/A uint max_regions(int purpose);
342N/A
342N/A // The limit on regions for a particular purpose is reached.
342N/A void note_alloc_region_limit_reached(int purpose) {
342N/A if (purpose == GCAllocForSurvived) {
342N/A _tenuring_threshold = 0;
342N/A }
342N/A }
342N/A
342N/A void note_start_adding_survivor_regions() {
342N/A _survivor_surv_rate_group->start_adding_regions();
342N/A }
342N/A
342N/A void note_stop_adding_survivor_regions() {
342N/A _survivor_surv_rate_group->stop_adding_regions();
342N/A }
545N/A
3681N/A void record_survivor_regions(uint regions,
545N/A HeapRegion* head,
545N/A HeapRegion* tail) {
545N/A _recorded_survivor_regions = regions;
545N/A _recorded_survivor_head = head;
545N/A _recorded_survivor_tail = tail;
545N/A }
545N/A
3681N/A uint recorded_survivor_regions() {
838N/A return _recorded_survivor_regions;
838N/A }
838N/A
3681N/A void record_thread_age_table(ageTable* age_table) {
545N/A _survivors_age_table.merge_par(age_table);
545N/A }
545N/A
2753N/A void update_max_gc_locker_expansion();
1898N/A
545N/A // Calculates survivor space parameters.
2753N/A void update_survivors_policy();
545N/A
342N/A};
342N/A
342N/A// This should move to some place more general...
342N/A
342N/A// If we have "n" measurements, and we've kept track of their "sum" and the
342N/A// "sum_of_squares" of the measurements, this returns the variance of the
342N/A// sequence.
342N/Ainline double variance(int n, double sum_of_squares, double sum) {
342N/A double n_d = (double)n;
342N/A double avg = sum/n_d;
342N/A return (sum_of_squares - 2.0 * avg * sum + n_d * avg * avg) / n_d;
342N/A}
342N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1COLLECTORPOLICY_HPP