8138969: G1CollectorPolicy should use const for applicable methods
Reviewed-by: mgerdin, jwilhelm
--- a/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp Wed Oct 07 01:03:24 2015 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectedHeap.hpp Wed Oct 07 15:06:52 2015 +0200
@@ -1054,6 +1054,7 @@
return CollectedHeap::G1CollectedHeap;
}
+ const G1CollectorState* collector_state() const { return &_collector_state; }
G1CollectorState* collector_state() { return &_collector_state; }
// The current policy object for the collector.
--- a/hotspot/src/share/vm/gc/g1/g1CollectorPolicy.cpp Wed Oct 07 01:03:24 2015 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectorPolicy.cpp Wed Oct 07 15:06:52 2015 +0200
@@ -315,6 +315,7 @@
}
}
+const G1CollectorState* G1CollectorPolicy::collector_state() const { return _g1->collector_state(); }
G1CollectorState* G1CollectorPolicy::collector_state() { return _g1->collector_state(); }
G1YoungGenSizer::G1YoungGenSizer() : _sizer_kind(SizerDefaults), _adaptive_size(true),
@@ -441,7 +442,7 @@
bool G1CollectorPolicy::predict_will_fit(uint young_length,
double base_time_ms,
uint base_free_regions,
- double target_pause_time_ms) {
+ double target_pause_time_ms) const {
if (young_length >= base_free_regions) {
// end condition 1: not enough space for the young regions
return false;
@@ -480,7 +481,7 @@
}
uint G1CollectorPolicy::calculate_young_list_desired_min_length(
- uint base_min_length) {
+ uint base_min_length) const {
uint desired_min_length = 0;
if (adaptive_young_list_length()) {
if (_alloc_rate_ms_seq->num() > 3) {
@@ -497,7 +498,7 @@
return MAX2(_young_gen_sizer->min_desired_young_length(), desired_min_length);
}
-uint G1CollectorPolicy::calculate_young_list_desired_max_length() {
+uint G1CollectorPolicy::calculate_young_list_desired_max_length() const {
// Here, we might want to also take into account any additional
// constraints (i.e., user-defined minimum bound). Currently, we
// effectively don't set this bound.
@@ -575,7 +576,7 @@
G1CollectorPolicy::calculate_young_list_target_length(size_t rs_lengths,
uint base_min_length,
uint desired_min_length,
- uint desired_max_length) {
+ uint desired_max_length) const {
assert(adaptive_young_list_length(), "pre-condition");
assert(collector_state()->gcs_are_young(), "only call this for young GCs");
@@ -675,7 +676,7 @@
return base_min_length + min_young_length;
}
-double G1CollectorPolicy::predict_survivor_regions_evac_time() {
+double G1CollectorPolicy::predict_survivor_regions_evac_time() const {
double survivor_regions_evac_time = 0.0;
for (HeapRegion * r = _recorded_survivor_head;
r != NULL && r != _recorded_survivor_tail->get_next_young_region();
@@ -1173,7 +1174,7 @@
}
}
-void G1CollectorPolicy::print_heap_transition(size_t bytes_before) {
+void G1CollectorPolicy::print_heap_transition(size_t bytes_before) const {
size_t bytes_after = _g1->used();
size_t capacity = _g1->capacity();
@@ -1186,11 +1187,11 @@
proper_unit_for_byte_size(capacity));
}
-void G1CollectorPolicy::print_heap_transition() {
+void G1CollectorPolicy::print_heap_transition() const {
print_heap_transition(_heap_used_bytes_before_gc);
}
-void G1CollectorPolicy::print_detailed_heap_transition(bool full) {
+void G1CollectorPolicy::print_detailed_heap_transition(bool full) const {
YoungList* young_list = _g1->young_list();
size_t eden_used_bytes_after_gc = young_list->eden_used_bytes();
@@ -1267,7 +1268,7 @@
double
G1CollectorPolicy::predict_base_elapsed_time_ms(size_t pending_cards,
- size_t scanned_cards) {
+ size_t scanned_cards) const {
return
predict_rs_update_time_ms(pending_cards) +
predict_rs_scan_time_ms(scanned_cards) +
@@ -1275,7 +1276,7 @@
}
double
-G1CollectorPolicy::predict_base_elapsed_time_ms(size_t pending_cards) {
+G1CollectorPolicy::predict_base_elapsed_time_ms(size_t pending_cards) const {
size_t rs_length = predict_rs_length_diff();
size_t card_num;
if (collector_state()->gcs_are_young()) {
@@ -1286,7 +1287,7 @@
return predict_base_elapsed_time_ms(pending_cards, card_num);
}
-size_t G1CollectorPolicy::predict_bytes_to_copy(HeapRegion* hr) {
+size_t G1CollectorPolicy::predict_bytes_to_copy(HeapRegion* hr) const {
size_t bytes_to_copy;
if (hr->is_marked())
bytes_to_copy = hr->max_live_bytes();
@@ -1301,7 +1302,7 @@
double
G1CollectorPolicy::predict_region_elapsed_time_ms(HeapRegion* hr,
- bool for_young_gc) {
+ bool for_young_gc) const {
size_t rs_length = hr->rem_set()->occupied();
size_t card_num;
@@ -1347,7 +1348,7 @@
_prev_collection_pause_end_ms = end_time_sec * 1000.0;
}
-size_t G1CollectorPolicy::expansion_amount() {
+size_t G1CollectorPolicy::expansion_amount() const {
double recent_gc_overhead = recent_avg_pause_time_ratio() * 100.0;
double threshold = _gc_overhead_perc;
if (recent_gc_overhead > threshold) {
@@ -1396,13 +1397,13 @@
#endif // PRODUCT
}
-bool G1CollectorPolicy::is_young_list_full() {
+bool G1CollectorPolicy::is_young_list_full() const {
uint young_list_length = _g1->young_list()->length();
uint young_list_target_length = _young_list_target_length;
return young_list_length >= young_list_target_length;
}
-bool G1CollectorPolicy::can_expand_young_list() {
+bool G1CollectorPolicy::can_expand_young_list() const {
uint young_list_length = _g1->young_list()->length();
uint young_list_max_length = _young_list_max_length;
return young_list_length < young_list_max_length;
@@ -1556,7 +1557,7 @@
}
};
-uint G1CollectorPolicy::calculate_parallel_work_chunk_size(uint n_workers, uint n_regions) {
+uint G1CollectorPolicy::calculate_parallel_work_chunk_size(uint n_workers, uint n_regions) const {
assert(n_workers > 0, "Active gc workers should be greater than 0");
const uint overpartition_factor = 4;
const uint min_chunk_size = MAX2(n_regions / n_workers, 1U);
@@ -1782,7 +1783,7 @@
}
#endif // !PRODUCT
-double G1CollectorPolicy::reclaimable_bytes_perc(size_t reclaimable_bytes) {
+double G1CollectorPolicy::reclaimable_bytes_perc(size_t reclaimable_bytes) const {
// Returns the given amount of reclaimable bytes (that represents
// the amount of reclaimable space still to be collected) as a
// percentage of the current heap capacity.
@@ -1791,7 +1792,7 @@
}
bool G1CollectorPolicy::next_gc_should_be_mixed(const char* true_action_str,
- const char* false_action_str) {
+ const char* false_action_str) const {
CollectionSetChooser* cset_chooser = _collectionSetChooser;
if (cset_chooser->is_empty()) {
ergo_verbose0(ErgoMixedGCs,
@@ -1829,7 +1830,7 @@
return true;
}
-uint G1CollectorPolicy::calc_min_old_cset_length() {
+uint G1CollectorPolicy::calc_min_old_cset_length() const {
// The min old CSet region bound is based on the maximum desired
// number of mixed GCs after a cycle. I.e., even if some old regions
// look expensive, we should add them to the CSet anyway to make
@@ -1850,13 +1851,13 @@
return (uint) result;
}
-uint G1CollectorPolicy::calc_max_old_cset_length() {
+uint G1CollectorPolicy::calc_max_old_cset_length() const {
// The max old CSet region bound is based on the threshold expressed
// as a percentage of the heap size. I.e., it should bound the
// number of old regions added to the CSet irrespective of how many
// of them are available.
- G1CollectedHeap* g1h = G1CollectedHeap::heap();
+ const G1CollectedHeap* g1h = G1CollectedHeap::heap();
const size_t region_num = g1h->num_regions();
const size_t perc = (size_t) G1OldCSetRegionThresholdPercent;
size_t result = region_num * perc / 100;
--- a/hotspot/src/share/vm/gc/g1/g1CollectorPolicy.hpp Wed Oct 07 01:03:24 2015 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectorPolicy.hpp Wed Oct 07 15:06:52 2015 +0200
@@ -155,7 +155,7 @@
uint max_desired_young_length() {
return _max_desired_young_length;
}
- bool adaptive_young_list_length() {
+ bool adaptive_young_list_length() const {
return _adaptive_size;
}
};
@@ -242,9 +242,9 @@
void init_cset_region_lengths(uint eden_cset_region_length,
uint survivor_cset_region_length);
- uint eden_cset_region_length() { return _eden_cset_region_length; }
- uint survivor_cset_region_length() { return _survivor_cset_region_length; }
- uint old_cset_region_length() { return _old_cset_region_length; }
+ uint eden_cset_region_length() const { return _eden_cset_region_length; }
+ uint survivor_cset_region_length() const { return _survivor_cset_region_length; }
+ uint old_cset_region_length() const { return _old_cset_region_length; }
uint _free_regions_at_end_of_collection;
@@ -254,13 +254,13 @@
size_t _rs_lengths_prediction;
- double sigma() { return _sigma; }
+ double sigma() const { return _sigma; }
// A function that prevents us putting too much stock in small sample
// sets. Returns a number between 2.0 and 1.0, depending on the number
// of samples. 5 or more samples yields one; fewer scales linearly from
// 2.0 at 1 sample to 1.0 at 5.
- double confidence_factor(int samples) {
+ double confidence_factor(int samples) const {
if (samples > 4) return 1.0;
else return 1.0 + sigma() * ((double)(5 - samples))/2.0;
}
@@ -303,7 +303,7 @@
bool verify_young_ages();
#endif // PRODUCT
- double get_new_prediction(TruncatedSeq* seq) {
+ double get_new_prediction(TruncatedSeq* seq) const {
return MAX2(seq->davg() + sigma() * seq->dsd(),
seq->davg() * confidence_factor(seq->num()));
}
@@ -312,27 +312,27 @@
_max_rs_lengths = rs_lengths;
}
- size_t predict_rs_length_diff() {
+ size_t predict_rs_length_diff() const {
return (size_t) get_new_prediction(_rs_length_diff_seq);
}
- double predict_alloc_rate_ms() {
+ double predict_alloc_rate_ms() const {
return get_new_prediction(_alloc_rate_ms_seq);
}
- double predict_cost_per_card_ms() {
+ double predict_cost_per_card_ms() const {
return get_new_prediction(_cost_per_card_ms_seq);
}
- double predict_rs_update_time_ms(size_t pending_cards) {
+ double predict_rs_update_time_ms(size_t pending_cards) const {
return (double) pending_cards * predict_cost_per_card_ms();
}
- double predict_young_cards_per_entry_ratio() {
+ double predict_young_cards_per_entry_ratio() const {
return get_new_prediction(_young_cards_per_entry_ratio_seq);
}
- double predict_mixed_cards_per_entry_ratio() {
+ double predict_mixed_cards_per_entry_ratio() const {
if (_mixed_cards_per_entry_ratio_seq->num() < 2) {
return predict_young_cards_per_entry_ratio();
} else {
@@ -340,17 +340,17 @@
}
}
- size_t predict_young_card_num(size_t rs_length) {
+ size_t predict_young_card_num(size_t rs_length) const {
return (size_t) ((double) rs_length *
predict_young_cards_per_entry_ratio());
}
- size_t predict_non_young_card_num(size_t rs_length) {
+ size_t predict_non_young_card_num(size_t rs_length) const {
return (size_t) ((double) rs_length *
predict_mixed_cards_per_entry_ratio());
}
- double predict_rs_scan_time_ms(size_t card_num) {
+ double predict_rs_scan_time_ms(size_t card_num) const {
if (collector_state()->gcs_are_young()) {
return (double) card_num * get_new_prediction(_cost_per_entry_ms_seq);
} else {
@@ -358,7 +358,7 @@
}
}
- double predict_mixed_rs_scan_time_ms(size_t card_num) {
+ double predict_mixed_rs_scan_time_ms(size_t card_num) const {
if (_mixed_cost_per_entry_ms_seq->num() < 3) {
return (double) card_num * get_new_prediction(_cost_per_entry_ms_seq);
} else {
@@ -367,7 +367,7 @@
}
}
- double predict_object_copy_time_ms_during_cm(size_t bytes_to_copy) {
+ double predict_object_copy_time_ms_during_cm(size_t bytes_to_copy) const {
if (_cost_per_byte_ms_during_cm_seq->num() < 3) {
return (1.1 * (double) bytes_to_copy) *
get_new_prediction(_cost_per_byte_ms_seq);
@@ -377,7 +377,7 @@
}
}
- double predict_object_copy_time_ms(size_t bytes_to_copy) {
+ double predict_object_copy_time_ms(size_t bytes_to_copy) const {
if (collector_state()->during_concurrent_mark()) {
return predict_object_copy_time_ms_during_cm(bytes_to_copy);
} else {
@@ -386,34 +386,34 @@
}
}
- double predict_constant_other_time_ms() {
+ double predict_constant_other_time_ms() const {
return get_new_prediction(_constant_other_time_ms_seq);
}
- double predict_young_other_time_ms(size_t young_num) {
+ double predict_young_other_time_ms(size_t young_num) const {
return (double) young_num *
get_new_prediction(_young_other_cost_per_region_ms_seq);
}
- double predict_non_young_other_time_ms(size_t non_young_num) {
+ double predict_non_young_other_time_ms(size_t non_young_num) const {
return (double) non_young_num *
get_new_prediction(_non_young_other_cost_per_region_ms_seq);
}
- double predict_base_elapsed_time_ms(size_t pending_cards);
+ double predict_base_elapsed_time_ms(size_t pending_cards) const;
double predict_base_elapsed_time_ms(size_t pending_cards,
- size_t scanned_cards);
- size_t predict_bytes_to_copy(HeapRegion* hr);
- double predict_region_elapsed_time_ms(HeapRegion* hr, bool for_young_gc);
+ size_t scanned_cards) const;
+ size_t predict_bytes_to_copy(HeapRegion* hr) const;
+ double predict_region_elapsed_time_ms(HeapRegion* hr, bool for_young_gc) const;
void set_recorded_rs_lengths(size_t rs_lengths);
- uint cset_region_length() { return young_cset_region_length() +
+ uint cset_region_length() const { return young_cset_region_length() +
old_cset_region_length(); }
- uint young_cset_region_length() { return eden_cset_region_length() +
+ uint young_cset_region_length() const { return eden_cset_region_length() +
survivor_cset_region_length(); }
- double predict_survivor_regions_evac_time();
+ double predict_survivor_regions_evac_time() const;
void cset_regions_freed() {
bool propagate = collector_state()->should_propagate();
@@ -426,21 +426,25 @@
return _mmu_tracker;
}
- double max_pause_time_ms() {
+ const G1MMUTracker* mmu_tracker() const {
+ return _mmu_tracker;
+ }
+
+ double max_pause_time_ms() const {
return _mmu_tracker->max_gc_time() * 1000.0;
}
- double predict_remark_time_ms() {
+ double predict_remark_time_ms() const {
return get_new_prediction(_concurrent_mark_remark_times_ms);
}
- double predict_cleanup_time_ms() {
+ double predict_cleanup_time_ms() const {
return get_new_prediction(_concurrent_mark_cleanup_times_ms);
}
// Returns an estimate of the survival rate of the region at yg-age
// "yg_age".
- double predict_yg_surv_rate(int age, SurvRateGroup* surv_rate_group) {
+ double predict_yg_surv_rate(int age, SurvRateGroup* surv_rate_group) const {
TruncatedSeq* seq = surv_rate_group->get_seq(age);
if (seq->num() == 0)
gclog_or_tty->print("BARF! age is %d", age);
@@ -451,11 +455,11 @@
return pred;
}
- double predict_yg_surv_rate(int age) {
+ double predict_yg_surv_rate(int age) const {
return predict_yg_surv_rate(age, _short_lived_surv_rate_group);
}
- double accum_yg_surv_rate_pred(int age) {
+ double accum_yg_surv_rate_pred(int age) const {
return _short_lived_surv_rate_group->accum_surv_rate_pred(age);
}
@@ -536,7 +540,7 @@
// The ratio of gc time to elapsed time, computed over recent pauses.
double _recent_avg_pause_time_ratio;
- double recent_avg_pause_time_ratio() {
+ double recent_avg_pause_time_ratio() const {
return _recent_avg_pause_time_ratio;
}
@@ -556,12 +560,12 @@
// Calculate and return the minimum desired young list target
// length. This is the minimum desired young list length according
// to the user's inputs.
- uint calculate_young_list_desired_min_length(uint base_min_length);
+ uint calculate_young_list_desired_min_length(uint base_min_length) const;
// Calculate and return the maximum desired young list target
// length. This is the maximum desired young list length according
// to the user's inputs.
- uint calculate_young_list_desired_max_length();
+ uint calculate_young_list_desired_max_length() const;
// Calculate and return the maximum young list target length that
// can fit into the pause time goal. The parameters are: rs_lengths
@@ -572,11 +576,11 @@
uint calculate_young_list_target_length(size_t rs_lengths,
uint base_min_length,
uint desired_min_length,
- uint desired_max_length);
+ uint desired_max_length) const;
// Calculate and return chunk size (in number of regions) for parallel
// concurrent mark cleanup.
- uint calculate_parallel_work_chunk_size(uint n_workers, uint n_regions);
+ uint calculate_parallel_work_chunk_size(uint n_workers, uint n_regions) const;
// Check whether a given young length (young_length) fits into the
// given target pause time and whether the prediction for the amount
@@ -584,19 +588,19 @@
// given free space (expressed by base_free_regions). It is used by
// calculate_young_list_target_length().
bool predict_will_fit(uint young_length, double base_time_ms,
- uint base_free_regions, double target_pause_time_ms);
+ uint base_free_regions, double target_pause_time_ms) const;
// Calculate the minimum number of old regions we'll add to the CSet
// during a mixed GC.
- uint calc_min_old_cset_length();
+ uint calc_min_old_cset_length() const;
// Calculate the maximum number of old regions we'll add to the CSet
// during a mixed GC.
- uint calc_max_old_cset_length();
+ uint calc_max_old_cset_length() const;
// Returns the given amount of uncollected reclaimable space
// as a percentage of the current heap capacity.
- double reclaimable_bytes_perc(size_t reclaimable_bytes);
+ double reclaimable_bytes_perc(size_t reclaimable_bytes) const;
public:
@@ -604,6 +608,7 @@
virtual G1CollectorPolicy* as_g1_policy() { return this; }
+ const G1CollectorState* collector_state() const;
G1CollectorState* collector_state();
G1GCPhaseTimes* phase_times() const { return _phase_times; }
@@ -658,9 +663,9 @@
// Print heap sizing transition (with less and more detail).
- void print_heap_transition(size_t bytes_before);
- void print_heap_transition();
- void print_detailed_heap_transition(bool full = false);
+ void print_heap_transition(size_t bytes_before) const;
+ void print_heap_transition() const;
+ void print_detailed_heap_transition(bool full = false) const;
void record_stop_world_start();
void record_concurrent_pause();
@@ -672,7 +677,7 @@
}
// The amount of space we copied during a GC.
- size_t bytes_copied_during_gc() {
+ size_t bytes_copied_during_gc() const {
return _bytes_copied_during_gc;
}
@@ -684,7 +689,7 @@
// next GC should be mixed. The two action strings are used
// in the ergo output when the method returns true or false.
bool next_gc_should_be_mixed(const char* true_action_str,
- const char* false_action_str);
+ const char* false_action_str) const;
// Choose a new collection set. Marks the chosen regions as being
// "in_collection_set", and links them together. The head and number of
@@ -764,7 +769,7 @@
// If an expansion would be appropriate, because recent GC overhead had
// exceeded the desired limit, return an amount to expand by.
- virtual size_t expansion_amount();
+ virtual size_t expansion_amount() const;
// Print tracing information.
void print_tracing_info() const;
@@ -783,15 +788,15 @@
size_t young_list_target_length() const { return _young_list_target_length; }
- bool is_young_list_full();
+ bool is_young_list_full() const;
- bool can_expand_young_list();
+ bool can_expand_young_list() const;
- uint young_list_max_length() {
+ uint young_list_max_length() const {
return _young_list_max_length;
}
- bool adaptive_young_list_length() {
+ bool adaptive_young_list_length() const {
return _young_gen_sizer->adaptive_young_list_length();
}
@@ -832,7 +837,7 @@
static const uint REGIONS_UNLIMITED = (uint) -1;
- uint max_regions(InCSetState dest) {
+ uint max_regions(InCSetState dest) const {
switch (dest.value()) {
case InCSetState::Young:
return _max_survivor_regions;
@@ -862,7 +867,7 @@
_recorded_survivor_tail = tail;
}
- uint recorded_survivor_regions() {
+ uint recorded_survivor_regions() const {
return _recorded_survivor_regions;
}
--- a/hotspot/src/share/vm/gc/g1/g1CollectorState.hpp Wed Oct 07 01:03:24 2015 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1CollectorState.hpp Wed Oct 07 15:06:52 2015 +0200
@@ -104,24 +104,24 @@
void set_full_collection(bool v) { _full_collection = v; }
// Getters
- bool gcs_are_young() { return _gcs_are_young; }
- bool last_gc_was_young() { return _last_gc_was_young; }
- bool last_young_gc() { return _last_young_gc; }
- bool during_initial_mark_pause() { return _during_initial_mark_pause; }
- bool initiate_conc_mark_if_possible() { return _initiate_conc_mark_if_possible; }
- bool during_marking() { return _during_marking; }
- bool mark_in_progress() { return _mark_in_progress; }
- bool in_marking_window() { return _in_marking_window; }
- bool in_marking_window_im() { return _in_marking_window_im; }
- bool concurrent_cycle_started() { return _concurrent_cycle_started; }
- bool full_collection() { return _full_collection; }
+ bool gcs_are_young() const { return _gcs_are_young; }
+ bool last_gc_was_young() const { return _last_gc_was_young; }
+ bool last_young_gc() const { return _last_young_gc; }
+ bool during_initial_mark_pause() const { return _during_initial_mark_pause; }
+ bool initiate_conc_mark_if_possible() const { return _initiate_conc_mark_if_possible; }
+ bool during_marking() const { return _during_marking; }
+ bool mark_in_progress() const { return _mark_in_progress; }
+ bool in_marking_window() const { return _in_marking_window; }
+ bool in_marking_window_im() const { return _in_marking_window_im; }
+ bool concurrent_cycle_started() const { return _concurrent_cycle_started; }
+ bool full_collection() const { return _full_collection; }
// Composite booleans (clients worry about flickering)
- bool during_concurrent_mark() {
+ bool during_concurrent_mark() const {
return (_in_marking_window && !_in_marking_window_im);
}
- bool should_propagate() { // XXX should have a more suitable state name or abstraction for this
+ bool should_propagate() const { // XXX should have a more suitable state name or abstraction for this
return (_last_young_gc && !_in_marking_window);
}
--- a/hotspot/src/share/vm/gc/g1/g1MMUTracker.hpp Wed Oct 07 01:03:24 2015 +0200
+++ b/hotspot/src/share/vm/gc/g1/g1MMUTracker.hpp Wed Oct 07 15:06:52 2015 +0200
@@ -46,7 +46,7 @@
virtual void add_pause(double start, double end) = 0;
virtual double when_sec(double current_time, double pause_time) = 0;
- double max_gc_time() {
+ double max_gc_time() const {
return _max_gc_time;
}