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#include "precompiled.hpp"
1879N/A#include "gc_implementation/g1/concurrentG1Refine.hpp"
1879N/A#include "gc_implementation/g1/concurrentMark.hpp"
1879N/A#include "gc_implementation/g1/concurrentMarkThread.inline.hpp"
1879N/A#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
1879N/A#include "gc_implementation/g1/g1CollectorPolicy.hpp"
2748N/A#include "gc_implementation/g1/g1ErgoVerbose.hpp"
3885N/A#include "gc_implementation/g1/g1GCPhaseTimes.hpp"
3678N/A#include "gc_implementation/g1/g1Log.hpp"
1879N/A#include "gc_implementation/g1/heapRegionRemSet.hpp"
1879N/A#include "gc_implementation/shared/gcPolicyCounters.hpp"
1879N/A#include "runtime/arguments.hpp"
1879N/A#include "runtime/java.hpp"
1879N/A#include "runtime/mutexLocker.hpp"
1879N/A#include "utilities/debug.hpp"
342N/A
342N/A// Different defaults for different number of GC threads
342N/A// They were chosen by running GCOld and SPECjbb on debris with different
342N/A// numbers of GC threads and choosing them based on the results
342N/A
342N/A// all the same
342N/Astatic double rs_length_diff_defaults[] = {
342N/A 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
342N/A};
342N/A
342N/Astatic double cost_per_card_ms_defaults[] = {
342N/A 0.01, 0.005, 0.005, 0.003, 0.003, 0.002, 0.002, 0.0015
342N/A};
342N/A
342N/A// all the same
2986N/Astatic double young_cards_per_entry_ratio_defaults[] = {
342N/A 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
342N/A};
342N/A
342N/Astatic double cost_per_entry_ms_defaults[] = {
342N/A 0.015, 0.01, 0.01, 0.008, 0.008, 0.0055, 0.0055, 0.005
342N/A};
342N/A
342N/Astatic double cost_per_byte_ms_defaults[] = {
342N/A 0.00006, 0.00003, 0.00003, 0.000015, 0.000015, 0.00001, 0.00001, 0.000009
342N/A};
342N/A
342N/A// these should be pretty consistent
342N/Astatic double constant_other_time_ms_defaults[] = {
342N/A 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0
342N/A};
342N/A
342N/A
342N/Astatic double young_other_cost_per_region_ms_defaults[] = {
342N/A 0.3, 0.2, 0.2, 0.15, 0.15, 0.12, 0.12, 0.1
342N/A};
342N/A
342N/Astatic double non_young_other_cost_per_region_ms_defaults[] = {
342N/A 1.0, 0.7, 0.7, 0.5, 0.5, 0.42, 0.42, 0.30
342N/A};
342N/A
342N/AG1CollectorPolicy::G1CollectorPolicy() :
1753N/A _parallel_gc_threads(G1CollectedHeap::use_parallel_gc_threads()
2648N/A ? ParallelGCThreads : 1),
1753N/A
342N/A _recent_gc_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A _stop_world_start(0.0),
342N/A
342N/A _concurrent_mark_remark_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A _concurrent_mark_cleanup_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A
342N/A _alloc_rate_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _prev_collection_pause_end_ms(0.0),
342N/A _rs_length_diff_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _cost_per_card_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
2986N/A _young_cards_per_entry_ratio_seq(new TruncatedSeq(TruncatedSeqLength)),
2986N/A _mixed_cards_per_entry_ratio_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _cost_per_entry_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
2986N/A _mixed_cost_per_entry_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _cost_per_byte_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _cost_per_byte_ms_during_cm_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _constant_other_time_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _young_other_cost_per_region_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _non_young_other_cost_per_region_ms_seq(
342N/A new TruncatedSeq(TruncatedSeqLength)),
342N/A
342N/A _pending_cards_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _rs_lengths_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A
751N/A _pause_time_target_ms((double) MaxGCPauseMillis),
342N/A
2986N/A _gcs_are_young(true),
342N/A
342N/A _during_marking(false),
342N/A _in_marking_window(false),
342N/A _in_marking_window_im(false),
342N/A
2986N/A _recent_prev_end_times_for_all_gcs_sec(
2986N/A new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A
342N/A _recent_avg_pause_time_ratio(0.0),
342N/A
1359N/A _initiate_conc_mark_if_possible(false),
1359N/A _during_initial_mark_pause(false),
2986N/A _last_young_gc(false),
2986N/A _last_gc_was_young(false),
342N/A
2589N/A _eden_bytes_before_gc(0),
2589N/A _survivor_bytes_before_gc(0),
2589N/A _capacity_before_gc(0),
2589N/A
2936N/A _eden_cset_region_length(0),
2936N/A _survivor_cset_region_length(0),
2936N/A _old_cset_region_length(0),
2936N/A
342N/A _collection_set(NULL),
1394N/A _collection_set_bytes_used_before(0),
1394N/A
1394N/A // Incremental CSet attributes
1394N/A _inc_cset_build_state(Inactive),
1394N/A _inc_cset_head(NULL),
1394N/A _inc_cset_tail(NULL),
1394N/A _inc_cset_bytes_used_before(0),
1394N/A _inc_cset_max_finger(NULL),
1394N/A _inc_cset_recorded_rs_lengths(0),
3007N/A _inc_cset_recorded_rs_lengths_diffs(0),
1394N/A _inc_cset_predicted_elapsed_time_ms(0.0),
3007N/A _inc_cset_predicted_elapsed_time_ms_diffs(0.0),
1394N/A
342N/A#ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away
342N/A#pragma warning( disable:4355 ) // 'this' : used in base member initializer list
342N/A#endif // _MSC_VER
342N/A
342N/A _short_lived_surv_rate_group(new SurvRateGroup(this, "Short Lived",
342N/A G1YoungSurvRateNumRegionsSummary)),
342N/A _survivor_surv_rate_group(new SurvRateGroup(this, "Survivor",
545N/A G1YoungSurvRateNumRegionsSummary)),
342N/A // add here any more surv rate groups
545N/A _recorded_survivor_regions(0),
545N/A _recorded_survivor_head(NULL),
545N/A _recorded_survivor_tail(NULL),
1356N/A _survivors_age_table(true),
1356N/A
2748N/A _gc_overhead_perc(0.0) {
2748N/A
942N/A // Set up the region size and associated fields. Given that the
942N/A // policy is created before the heap, we have to set this up here,
942N/A // so it's done as soon as possible.
942N/A HeapRegion::setup_heap_region_size(Arguments::min_heap_size());
1261N/A HeapRegionRemSet::setup_remset_size();
942N/A
2748N/A G1ErgoVerbose::initialize();
2748N/A if (PrintAdaptiveSizePolicy) {
2748N/A // Currently, we only use a single switch for all the heuristics.
2748N/A G1ErgoVerbose::set_enabled(true);
2748N/A // Given that we don't currently have a verboseness level
2748N/A // parameter, we'll hardcode this to high. This can be easily
2748N/A // changed in the future.
2748N/A G1ErgoVerbose::set_level(ErgoHigh);
2748N/A } else {
2748N/A G1ErgoVerbose::set_enabled(false);
2748N/A }
2748N/A
1391N/A // Verify PLAB sizes
2822N/A const size_t region_size = HeapRegion::GrainWords;
1391N/A if (YoungPLABSize > region_size || OldPLABSize > region_size) {
1391N/A char buffer[128];
2822N/A jio_snprintf(buffer, sizeof(buffer), "%sPLABSize should be at most "SIZE_FORMAT,
1391N/A OldPLABSize > region_size ? "Old" : "Young", region_size);
1391N/A vm_exit_during_initialization(buffer);
1391N/A }
1391N/A
342N/A _recent_prev_end_times_for_all_gcs_sec->add(os::elapsedTime());
342N/A _prev_collection_pause_end_ms = os::elapsedTime() * 1000.0;
342N/A
3885N/A _phase_times = new G1GCPhaseTimes(_parallel_gc_threads);
342N/A
3885N/A int index = MIN2(_parallel_gc_threads - 1, 7);
342N/A
342N/A _rs_length_diff_seq->add(rs_length_diff_defaults[index]);
342N/A _cost_per_card_ms_seq->add(cost_per_card_ms_defaults[index]);
2986N/A _young_cards_per_entry_ratio_seq->add(
2986N/A young_cards_per_entry_ratio_defaults[index]);
342N/A _cost_per_entry_ms_seq->add(cost_per_entry_ms_defaults[index]);
342N/A _cost_per_byte_ms_seq->add(cost_per_byte_ms_defaults[index]);
342N/A _constant_other_time_ms_seq->add(constant_other_time_ms_defaults[index]);
342N/A _young_other_cost_per_region_ms_seq->add(
342N/A young_other_cost_per_region_ms_defaults[index]);
342N/A _non_young_other_cost_per_region_ms_seq->add(
342N/A non_young_other_cost_per_region_ms_defaults[index]);
342N/A
1530N/A // Below, we might need to calculate the pause time target based on
1530N/A // the pause interval. When we do so we are going to give G1 maximum
1530N/A // flexibility and allow it to do pauses when it needs to. So, we'll
1530N/A // arrange that the pause interval to be pause time target + 1 to
1530N/A // ensure that a) the pause time target is maximized with respect to
1530N/A // the pause interval and b) we maintain the invariant that pause
1530N/A // time target < pause interval. If the user does not want this
1530N/A // maximum flexibility, they will have to set the pause interval
1530N/A // explicitly.
1530N/A
1530N/A // First make sure that, if either parameter is set, its value is
1530N/A // reasonable.
1530N/A if (!FLAG_IS_DEFAULT(MaxGCPauseMillis)) {
1530N/A if (MaxGCPauseMillis < 1) {
1530N/A vm_exit_during_initialization("MaxGCPauseMillis should be "
1530N/A "greater than 0");
1530N/A }
1530N/A }
1530N/A if (!FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
1530N/A if (GCPauseIntervalMillis < 1) {
1530N/A vm_exit_during_initialization("GCPauseIntervalMillis should be "
1530N/A "greater than 0");
1530N/A }
1530N/A }
1530N/A
1530N/A // Then, if the pause time target parameter was not set, set it to
1530N/A // the default value.
1530N/A if (FLAG_IS_DEFAULT(MaxGCPauseMillis)) {
1530N/A if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
1530N/A // The default pause time target in G1 is 200ms
1530N/A FLAG_SET_DEFAULT(MaxGCPauseMillis, 200);
1530N/A } else {
1530N/A // We do not allow the pause interval to be set without the
1530N/A // pause time target
1530N/A vm_exit_during_initialization("GCPauseIntervalMillis cannot be set "
1530N/A "without setting MaxGCPauseMillis");
1530N/A }
1530N/A }
1530N/A
1530N/A // Then, if the interval parameter was not set, set it according to
1530N/A // the pause time target (this will also deal with the case when the
1530N/A // pause time target is the default value).
1530N/A if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
1530N/A FLAG_SET_DEFAULT(GCPauseIntervalMillis, MaxGCPauseMillis + 1);
1530N/A }
1530N/A
1530N/A // Finally, make sure that the two parameters are consistent.
1530N/A if (MaxGCPauseMillis >= GCPauseIntervalMillis) {
1530N/A char buffer[256];
1530N/A jio_snprintf(buffer, 256,
1530N/A "MaxGCPauseMillis (%u) should be less than "
1530N/A "GCPauseIntervalMillis (%u)",
1530N/A MaxGCPauseMillis, GCPauseIntervalMillis);
1530N/A vm_exit_during_initialization(buffer);
1530N/A }
1530N/A
751N/A double max_gc_time = (double) MaxGCPauseMillis / 1000.0;
1530N/A double time_slice = (double) GCPauseIntervalMillis / 1000.0;
342N/A _mmu_tracker = new G1MMUTrackerQueue(time_slice, max_gc_time);
4249N/A
4249N/A uintx confidence_perc = G1ConfidencePercent;
4249N/A // Put an artificial ceiling on this so that it's not set to a silly value.
4249N/A if (confidence_perc > 100) {
4249N/A confidence_perc = 100;
4249N/A warning("G1ConfidencePercent is set to a value that is too large, "
4249N/A "it's been updated to %u", confidence_perc);
4249N/A }
4249N/A _sigma = (double) confidence_perc / 100.0;
342N/A
342N/A // start conservatively (around 50ms is about right)
342N/A _concurrent_mark_remark_times_ms->add(0.05);
342N/A _concurrent_mark_cleanup_times_ms->add(0.20);
342N/A _tenuring_threshold = MaxTenuringThreshold;
2696N/A // _max_survivor_regions will be calculated by
2753N/A // update_young_list_target_length() during initialization.
2696N/A _max_survivor_regions = 0;
545N/A
1356N/A assert(GCTimeRatio > 0,
1356N/A "we should have set it to a default value set_g1_gc_flags() "
1356N/A "if a user set it to 0");
1356N/A _gc_overhead_perc = 100.0 * (1.0 / (1.0 + GCTimeRatio));
1356N/A
2753N/A uintx reserve_perc = G1ReservePercent;
2753N/A // Put an artificial ceiling on this so that it's not set to a silly value.
2753N/A if (reserve_perc > 50) {
2753N/A reserve_perc = 50;
2753N/A warning("G1ReservePercent is set to a value that is too large, "
2753N/A "it's been updated to %u", reserve_perc);
2753N/A }
2753N/A _reserve_factor = (double) reserve_perc / 100.0;
2754N/A // This will be set when the heap is expanded
2753N/A // for the first time during initialization.
2753N/A _reserve_regions = 0;
2753N/A
342N/A initialize_all();
2849N/A _collectionSetChooser = new CollectionSetChooser();
3009N/A _young_gen_sizer = new G1YoungGenSizer(); // Must be after call to initialize_flags
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::initialize_flags() {
342N/A set_min_alignment(HeapRegion::GrainBytes);
4602N/A size_t card_table_alignment = GenRemSet::max_alignment_constraint(rem_set_name());
4602N/A set_max_alignment(MAX2(card_table_alignment, min_alignment()));
547N/A if (SurvivorRatio < 1) {
547N/A vm_exit_during_initialization("Invalid survivor ratio specified");
547N/A }
342N/A CollectorPolicy::initialize_flags();
342N/A}
342N/A
3009N/AG1YoungGenSizer::G1YoungGenSizer() : _sizer_kind(SizerDefaults), _adaptive_size(true) {
4195N/A assert(G1NewSizePercent <= G1MaxNewSizePercent, "Min larger than max");
4195N/A assert(G1NewSizePercent > 0 && G1NewSizePercent < 100, "Min out of bounds");
4195N/A assert(G1MaxNewSizePercent > 0 && G1MaxNewSizePercent < 100, "Max out of bounds");
3009N/A
3009N/A if (FLAG_IS_CMDLINE(NewRatio)) {
3009N/A if (FLAG_IS_CMDLINE(NewSize) || FLAG_IS_CMDLINE(MaxNewSize)) {
3009N/A warning("-XX:NewSize and -XX:MaxNewSize override -XX:NewRatio");
3009N/A } else {
3009N/A _sizer_kind = SizerNewRatio;
3009N/A _adaptive_size = false;
3009N/A return;
3009N/A }
2812N/A }
1285N/A
3009N/A if (FLAG_IS_CMDLINE(NewSize)) {
3681N/A _min_desired_young_length = MAX2((uint) (NewSize / HeapRegion::GrainBytes),
3681N/A 1U);
3009N/A if (FLAG_IS_CMDLINE(MaxNewSize)) {
3681N/A _max_desired_young_length =
3681N/A MAX2((uint) (MaxNewSize / HeapRegion::GrainBytes),
3681N/A 1U);
3009N/A _sizer_kind = SizerMaxAndNewSize;
3009N/A _adaptive_size = _min_desired_young_length == _max_desired_young_length;
3009N/A } else {
3009N/A _sizer_kind = SizerNewSizeOnly;
3009N/A }
3009N/A } else if (FLAG_IS_CMDLINE(MaxNewSize)) {
3681N/A _max_desired_young_length =
3681N/A MAX2((uint) (MaxNewSize / HeapRegion::GrainBytes),
3681N/A 1U);
3009N/A _sizer_kind = SizerMaxNewSizeOnly;
1285N/A }
3009N/A}
3009N/A
3681N/Auint G1YoungGenSizer::calculate_default_min_length(uint new_number_of_heap_regions) {
4195N/A uint default_value = (new_number_of_heap_regions * G1NewSizePercent) / 100;
3681N/A return MAX2(1U, default_value);
3009N/A}
3009N/A
3681N/Auint G1YoungGenSizer::calculate_default_max_length(uint new_number_of_heap_regions) {
4195N/A uint default_value = (new_number_of_heap_regions * G1MaxNewSizePercent) / 100;
3681N/A return MAX2(1U, default_value);
3009N/A}
3009N/A
3681N/Avoid G1YoungGenSizer::heap_size_changed(uint new_number_of_heap_regions) {
3009N/A assert(new_number_of_heap_regions > 0, "Heap must be initialized");
3009N/A
3009N/A switch (_sizer_kind) {
3009N/A case SizerDefaults:
3009N/A _min_desired_young_length = calculate_default_min_length(new_number_of_heap_regions);
3009N/A _max_desired_young_length = calculate_default_max_length(new_number_of_heap_regions);
3009N/A break;
3009N/A case SizerNewSizeOnly:
3009N/A _max_desired_young_length = calculate_default_max_length(new_number_of_heap_regions);
3009N/A _max_desired_young_length = MAX2(_min_desired_young_length, _max_desired_young_length);
3009N/A break;
3009N/A case SizerMaxNewSizeOnly:
3009N/A _min_desired_young_length = calculate_default_min_length(new_number_of_heap_regions);
3009N/A _min_desired_young_length = MIN2(_min_desired_young_length, _max_desired_young_length);
3009N/A break;
3009N/A case SizerMaxAndNewSize:
3009N/A // Do nothing. Values set on the command line, don't update them at runtime.
3009N/A break;
3009N/A case SizerNewRatio:
3009N/A _min_desired_young_length = new_number_of_heap_regions / (NewRatio + 1);
3009N/A _max_desired_young_length = _min_desired_young_length;
3009N/A break;
3009N/A default:
3009N/A ShouldNotReachHere();
1285N/A }
3009N/A
3009N/A assert(_min_desired_young_length <= _max_desired_young_length, "Invalid min/max young gen size values");
2754N/A}
2754N/A
342N/Avoid G1CollectorPolicy::init() {
342N/A // Set aside an initial future to_space.
342N/A _g1 = G1CollectedHeap::heap();
342N/A
342N/A assert(Heap_lock->owned_by_self(), "Locking discipline.");
342N/A
545N/A initialize_gc_policy_counters();
545N/A
2754N/A if (adaptive_young_list_length()) {
2695N/A _young_list_fixed_length = 0;
1394N/A } else {
3009N/A _young_list_fixed_length = _young_gen_sizer->min_desired_young_length();
342N/A }
2695N/A _free_regions_at_end_of_collection = _g1->free_regions();
2753N/A update_young_list_target_length();
1394N/A
1394N/A // We may immediately start allocating regions and placing them on the
1394N/A // collection set list. Initialize the per-collection set info
1394N/A start_incremental_cset_building();
342N/A}
342N/A
545N/A// Create the jstat counters for the policy.
2753N/Avoid G1CollectorPolicy::initialize_gc_policy_counters() {
2695N/A _gc_policy_counters = new GCPolicyCounters("GarbageFirst", 1, 3);
545N/A}
545N/A
3681N/Abool G1CollectorPolicy::predict_will_fit(uint young_length,
2753N/A double base_time_ms,
3681N/A uint base_free_regions,
2753N/A double target_pause_time_ms) {
2753N/A if (young_length >= base_free_regions) {
342N/A // end condition 1: not enough space for the young regions
342N/A return false;
2753N/A }
2753N/A
3681N/A double accum_surv_rate = accum_yg_surv_rate_pred((int) young_length - 1);
342N/A size_t bytes_to_copy =
2753N/A (size_t) (accum_surv_rate * (double) HeapRegion::GrainBytes);
342N/A double copy_time_ms = predict_object_copy_time_ms(bytes_to_copy);
2753N/A double young_other_time_ms = predict_young_other_time_ms(young_length);
2753N/A double pause_time_ms = base_time_ms + copy_time_ms + young_other_time_ms;
2753N/A if (pause_time_ms > target_pause_time_ms) {
2753N/A // end condition 2: prediction is over the target pause time
342N/A return false;
2753N/A }
342N/A
342N/A size_t free_bytes =
3681N/A (base_free_regions - young_length) * HeapRegion::GrainBytes;
2753N/A if ((2.0 * sigma()) * (double) bytes_to_copy > (double) free_bytes) {
2753N/A // end condition 3: out-of-space (conservatively!)
342N/A return false;
2753N/A }
342N/A
342N/A // success!
342N/A return true;
342N/A}
342N/A
3681N/Avoid G1CollectorPolicy::record_new_heap_size(uint new_number_of_regions) {
2754N/A // re-calculate the necessary reserve
2754N/A double reserve_regions_d = (double) new_number_of_regions * _reserve_factor;
2753N/A // We use ceiling so that if reserve_regions_d is > 0.0 (but
2753N/A // smaller than 1.0) we'll get 1.
3681N/A _reserve_regions = (uint) ceil(reserve_regions_d);
2754N/A
3009N/A _young_gen_sizer->heap_size_changed(new_number_of_regions);
2753N/A}
2753N/A
3681N/Auint G1CollectorPolicy::calculate_young_list_desired_min_length(
3681N/A uint base_min_length) {
3681N/A uint desired_min_length = 0;
2753N/A if (adaptive_young_list_length()) {
2753N/A if (_alloc_rate_ms_seq->num() > 3) {
2753N/A double now_sec = os::elapsedTime();
2753N/A double when_ms = _mmu_tracker->when_max_gc_sec(now_sec) * 1000.0;
2753N/A double alloc_rate_ms = predict_alloc_rate_ms();
3681N/A desired_min_length = (uint) ceil(alloc_rate_ms * when_ms);
2753N/A } else {
2753N/A // otherwise we don't have enough info to make the prediction
2753N/A }
2753N/A }
2754N/A desired_min_length += base_min_length;
2754N/A // make sure we don't go below any user-defined minimum bound
3009N/A return MAX2(_young_gen_sizer->min_desired_young_length(), desired_min_length);
2753N/A}
2753N/A
3681N/Auint G1CollectorPolicy::calculate_young_list_desired_max_length() {
2753N/A // Here, we might want to also take into account any additional
2753N/A // constraints (i.e., user-defined minimum bound). Currently, we
2753N/A // effectively don't set this bound.
3009N/A return _young_gen_sizer->max_desired_young_length();
2753N/A}
2753N/A
2753N/Avoid G1CollectorPolicy::update_young_list_target_length(size_t rs_lengths) {
2753N/A if (rs_lengths == (size_t) -1) {
2753N/A // if it's set to the default value (-1), we should predict it;
2753N/A // otherwise, use the given value.
2753N/A rs_lengths = (size_t) get_new_prediction(_rs_lengths_seq);
2753N/A }
2753N/A
2753N/A // Calculate the absolute and desired min bounds.
2753N/A
2753N/A // This is how many young regions we already have (currently: the survivors).
3681N/A uint base_min_length = recorded_survivor_regions();
2753N/A // This is the absolute minimum young length, which ensures that we
2753N/A // can allocate one eden region in the worst-case.
3681N/A uint absolute_min_length = base_min_length + 1;
3681N/A uint desired_min_length =
2753N/A calculate_young_list_desired_min_length(base_min_length);
2753N/A if (desired_min_length < absolute_min_length) {
2753N/A desired_min_length = absolute_min_length;
2753N/A }
2753N/A
2753N/A // Calculate the absolute and desired max bounds.
2753N/A
2753N/A // We will try our best not to "eat" into the reserve.
3681N/A uint absolute_max_length = 0;
2753N/A if (_free_regions_at_end_of_collection > _reserve_regions) {
2753N/A absolute_max_length = _free_regions_at_end_of_collection - _reserve_regions;
2753N/A }
3681N/A uint desired_max_length = calculate_young_list_desired_max_length();
2753N/A if (desired_max_length > absolute_max_length) {
2753N/A desired_max_length = absolute_max_length;
2753N/A }
2753N/A
3681N/A uint young_list_target_length = 0;
2753N/A if (adaptive_young_list_length()) {
2986N/A if (gcs_are_young()) {
2753N/A young_list_target_length =
2753N/A calculate_young_list_target_length(rs_lengths,
2753N/A base_min_length,
2753N/A desired_min_length,
2753N/A desired_max_length);
2753N/A _rs_lengths_prediction = rs_lengths;
2753N/A } else {
2753N/A // Don't calculate anything and let the code below bound it to
2753N/A // the desired_min_length, i.e., do the next GC as soon as
2753N/A // possible to maximize how many old regions we can add to it.
2753N/A }
2753N/A } else {
3201N/A // The user asked for a fixed young gen so we'll fix the young gen
3201N/A // whether the next GC is young or mixed.
3201N/A young_list_target_length = _young_list_fixed_length;
2753N/A }
2753N/A
2753N/A // Make sure we don't go over the desired max length, nor under the
2753N/A // desired min length. In case they clash, desired_min_length wins
2753N/A // which is why that test is second.
2753N/A if (young_list_target_length > desired_max_length) {
2753N/A young_list_target_length = desired_max_length;
2753N/A }
2753N/A if (young_list_target_length < desired_min_length) {
2753N/A young_list_target_length = desired_min_length;
2753N/A }
2753N/A
2753N/A assert(young_list_target_length > recorded_survivor_regions(),
2753N/A "we should be able to allocate at least one eden region");
2753N/A assert(young_list_target_length >= absolute_min_length, "post-condition");
2753N/A _young_list_target_length = young_list_target_length;
2753N/A
2753N/A update_max_gc_locker_expansion();
2753N/A}
2753N/A
3681N/Auint
2753N/AG1CollectorPolicy::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 assert(adaptive_young_list_length(), "pre-condition");
2986N/A assert(gcs_are_young(), "only call this for young GCs");
2753N/A
2753N/A // In case some edge-condition makes the desired max length too small...
2753N/A if (desired_max_length <= desired_min_length) {
2753N/A return desired_min_length;
2753N/A }
2753N/A
2753N/A // We'll adjust min_young_length and max_young_length not to include
2753N/A // the already allocated young regions (i.e., so they reflect the
2753N/A // min and max eden regions we'll allocate). The base_min_length
2753N/A // will be reflected in the predictions by the
2753N/A // survivor_regions_evac_time prediction.
2753N/A assert(desired_min_length > base_min_length, "invariant");
3681N/A uint min_young_length = desired_min_length - base_min_length;
2753N/A assert(desired_max_length > base_min_length, "invariant");
3681N/A uint max_young_length = desired_max_length - base_min_length;
2753N/A
2753N/A double target_pause_time_ms = _mmu_tracker->max_gc_time() * 1000.0;
2753N/A double survivor_regions_evac_time = predict_survivor_regions_evac_time();
2753N/A size_t pending_cards = (size_t) get_new_prediction(_pending_cards_seq);
2753N/A size_t adj_rs_lengths = rs_lengths + predict_rs_length_diff();
2753N/A size_t scanned_cards = predict_young_card_num(adj_rs_lengths);
2753N/A double base_time_ms =
2753N/A predict_base_elapsed_time_ms(pending_cards, scanned_cards) +
2753N/A survivor_regions_evac_time;
3681N/A uint available_free_regions = _free_regions_at_end_of_collection;
3681N/A uint base_free_regions = 0;
2753N/A if (available_free_regions > _reserve_regions) {
2753N/A base_free_regions = available_free_regions - _reserve_regions;
2753N/A }
2753N/A
2753N/A // Here, we will make sure that the shortest young length that
2753N/A // makes sense fits within the target pause time.
2753N/A
2753N/A if (predict_will_fit(min_young_length, base_time_ms,
2753N/A base_free_regions, target_pause_time_ms)) {
2753N/A // The shortest young length will fit into the target pause time;
2753N/A // we'll now check whether the absolute maximum number of young
2753N/A // regions will fit in the target pause time. If not, we'll do
2753N/A // a binary search between min_young_length and max_young_length.
2753N/A if (predict_will_fit(max_young_length, base_time_ms,
2753N/A base_free_regions, target_pause_time_ms)) {
2753N/A // The maximum young length will fit into the target pause time.
2753N/A // We are done so set min young length to the maximum length (as
2753N/A // the result is assumed to be returned in min_young_length).
2753N/A min_young_length = max_young_length;
2753N/A } else {
2753N/A // The maximum possible number of young regions will not fit within
2753N/A // the target pause time so we'll search for the optimal
2753N/A // length. The loop invariants are:
2753N/A //
2753N/A // min_young_length < max_young_length
2753N/A // min_young_length is known to fit into the target pause time
2753N/A // max_young_length is known not to fit into the target pause time
2753N/A //
2753N/A // Going into the loop we know the above hold as we've just
2753N/A // checked them. Every time around the loop we check whether
2753N/A // the middle value between min_young_length and
2753N/A // max_young_length fits into the target pause time. If it
2753N/A // does, it becomes the new min. If it doesn't, it becomes
2753N/A // the new max. This way we maintain the loop invariants.
2753N/A
2753N/A assert(min_young_length < max_young_length, "invariant");
3681N/A uint diff = (max_young_length - min_young_length) / 2;
2753N/A while (diff > 0) {
3681N/A uint young_length = min_young_length + diff;
2753N/A if (predict_will_fit(young_length, base_time_ms,
2753N/A base_free_regions, target_pause_time_ms)) {
2753N/A min_young_length = young_length;
2753N/A } else {
2753N/A max_young_length = young_length;
2753N/A }
2753N/A assert(min_young_length < max_young_length, "invariant");
2753N/A diff = (max_young_length - min_young_length) / 2;
2753N/A }
2753N/A // The results is min_young_length which, according to the
2753N/A // loop invariants, should fit within the target pause time.
2753N/A
2753N/A // These are the post-conditions of the binary search above:
2753N/A assert(min_young_length < max_young_length,
2753N/A "otherwise we should have discovered that max_young_length "
2753N/A "fits into the pause target and not done the binary search");
2753N/A assert(predict_will_fit(min_young_length, base_time_ms,
2753N/A base_free_regions, target_pause_time_ms),
2753N/A "min_young_length, the result of the binary search, should "
2753N/A "fit into the pause target");
2753N/A assert(!predict_will_fit(min_young_length + 1, base_time_ms,
2753N/A base_free_regions, target_pause_time_ms),
2753N/A "min_young_length, the result of the binary search, should be "
2753N/A "optimal, so no larger length should fit into the pause target");
2753N/A }
2753N/A } else {
2753N/A // Even the minimum length doesn't fit into the pause time
2753N/A // target, return it as the result nevertheless.
2753N/A }
2753N/A return base_min_length + min_young_length;
2753N/A}
2753N/A
545N/Adouble G1CollectorPolicy::predict_survivor_regions_evac_time() {
545N/A double survivor_regions_evac_time = 0.0;
545N/A for (HeapRegion * r = _recorded_survivor_head;
545N/A r != NULL && r != _recorded_survivor_tail->get_next_young_region();
545N/A r = r->get_next_young_region()) {
3961N/A survivor_regions_evac_time += predict_region_elapsed_time_ms(r, gcs_are_young());
545N/A }
545N/A return survivor_regions_evac_time;
545N/A}
545N/A
2753N/Avoid G1CollectorPolicy::revise_young_list_target_length_if_necessary() {
342N/A guarantee( adaptive_young_list_length(), "should not call this otherwise" );
342N/A
1394N/A size_t rs_lengths = _g1->young_list()->sampled_rs_lengths();
342N/A if (rs_lengths > _rs_lengths_prediction) {
342N/A // add 10% to avoid having to recalculate often
342N/A size_t rs_lengths_prediction = rs_lengths * 1100 / 1000;
2753N/A update_young_list_target_length(rs_lengths_prediction);
342N/A }
342N/A}
342N/A
2753N/A
2753N/A
342N/AHeapWord* G1CollectorPolicy::mem_allocate_work(size_t size,
342N/A bool is_tlab,
342N/A bool* gc_overhead_limit_was_exceeded) {
342N/A guarantee(false, "Not using this policy feature yet.");
342N/A return NULL;
342N/A}
342N/A
342N/A// This method controls how a collector handles one or more
342N/A// of its generations being fully allocated.
342N/AHeapWord* G1CollectorPolicy::satisfy_failed_allocation(size_t size,
342N/A bool is_tlab) {
342N/A guarantee(false, "Not using this policy feature yet.");
342N/A return NULL;
342N/A}
342N/A
342N/A
342N/A#ifndef PRODUCT
342N/Abool G1CollectorPolicy::verify_young_ages() {
1394N/A HeapRegion* head = _g1->young_list()->first_region();
342N/A return
342N/A verify_young_ages(head, _short_lived_surv_rate_group);
342N/A // also call verify_young_ages on any additional surv rate groups
342N/A}
342N/A
342N/Abool
342N/AG1CollectorPolicy::verify_young_ages(HeapRegion* head,
342N/A SurvRateGroup *surv_rate_group) {
342N/A guarantee( surv_rate_group != NULL, "pre-condition" );
342N/A
342N/A const char* name = surv_rate_group->name();
342N/A bool ret = true;
342N/A int prev_age = -1;
342N/A
342N/A for (HeapRegion* curr = head;
342N/A curr != NULL;
342N/A curr = curr->get_next_young_region()) {
342N/A SurvRateGroup* group = curr->surv_rate_group();
342N/A if (group == NULL && !curr->is_survivor()) {
342N/A gclog_or_tty->print_cr("## %s: encountered NULL surv_rate_group", name);
342N/A ret = false;
342N/A }
342N/A
342N/A if (surv_rate_group == group) {
342N/A int age = curr->age_in_surv_rate_group();
342N/A
342N/A if (age < 0) {
342N/A gclog_or_tty->print_cr("## %s: encountered negative age", name);
342N/A ret = false;
342N/A }
342N/A
342N/A if (age <= prev_age) {
342N/A gclog_or_tty->print_cr("## %s: region ages are not strictly increasing "
342N/A "(%d, %d)", name, age, prev_age);
342N/A ret = false;
342N/A }
342N/A prev_age = age;
342N/A }
342N/A }
342N/A
342N/A return ret;
342N/A}
342N/A#endif // PRODUCT
342N/A
342N/Avoid G1CollectorPolicy::record_full_collection_start() {
3885N/A _full_collection_start_sec = os::elapsedTime();
4485N/A record_heap_size_info_at_start();
342N/A // Release the future to-space so that it is available for compaction into.
342N/A _g1->set_full_collection();
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_full_collection_end() {
342N/A // Consider this like a collection pause for the purposes of allocation
342N/A // since last pause.
342N/A double end_sec = os::elapsedTime();
3885N/A double full_gc_time_sec = end_sec - _full_collection_start_sec;
342N/A double full_gc_time_ms = full_gc_time_sec * 1000.0;
342N/A
3776N/A _trace_gen1_time_data.record_full_collection(full_gc_time_ms);
342N/A
595N/A update_recent_gc_times(end_sec, full_gc_time_ms);
342N/A
342N/A _g1->clear_full_collection();
342N/A
2986N/A // "Nuke" the heuristics that control the young/mixed GC
2986N/A // transitions and make sure we start with young GCs after the Full GC.
2986N/A set_gcs_are_young(true);
2986N/A _last_young_gc = false;
1359N/A clear_initiate_conc_mark_if_possible();
1359N/A clear_during_initial_mark_pause();
342N/A _in_marking_window = false;
342N/A _in_marking_window_im = false;
342N/A
342N/A _short_lived_surv_rate_group->start_adding_regions();
342N/A // also call this on any additional surv rate groups
342N/A
545N/A record_survivor_regions(0, NULL, NULL);
545N/A
342N/A _free_regions_at_end_of_collection = _g1->free_regions();
545N/A // Reset survivors SurvRateGroup.
545N/A _survivor_surv_rate_group->reset();
2753N/A update_young_list_target_length();
3682N/A _collectionSetChooser->clear();
1880N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_stop_world_start() {
342N/A _stop_world_start = os::elapsedTime();
342N/A}
342N/A
4485N/Avoid G1CollectorPolicy::record_collection_pause_start(double start_time_sec) {
3120N/A // We only need to do this here as the policy will only be applied
3120N/A // to the GC we're about to start. so, no point is calculating this
3120N/A // every time we calculate / recalculate the target young length.
3120N/A update_survivors_policy();
2753N/A
1880N/A assert(_g1->used() == _g1->recalculate_used(),
1880N/A err_msg("sanity, used: "SIZE_FORMAT" recalculate_used: "SIZE_FORMAT,
1880N/A _g1->used(), _g1->recalculate_used()));
342N/A
342N/A double s_w_t_ms = (start_time_sec - _stop_world_start) * 1000.0;
3776N/A _trace_gen0_time_data.record_start_collection(s_w_t_ms);
342N/A _stop_world_start = 0.0;
342N/A
4485N/A record_heap_size_info_at_start();
4485N/A
3978N/A phase_times()->record_cur_collection_start_sec(start_time_sec);
342N/A _pending_cards = _g1->pending_card_num();
342N/A
3961N/A _collection_set_bytes_used_before = 0;
2655N/A _bytes_copied_during_gc = 0;
342N/A
2986N/A _last_gc_was_young = false;
342N/A
342N/A // do that for any other surv rate groups
342N/A _short_lived_surv_rate_group->stop_adding_regions();
1282N/A _survivors_age_table.clear();
545N/A
342N/A assert( verify_young_ages(), "region age verification" );
342N/A}
342N/A
2695N/Avoid G1CollectorPolicy::record_concurrent_mark_init_end(double
342N/A mark_init_elapsed_time_ms) {
342N/A _during_marking = true;
1359N/A assert(!initiate_conc_mark_if_possible(), "we should have cleared it by now");
1359N/A clear_during_initial_mark_pause();
342N/A _cur_mark_stop_world_time_ms = mark_init_elapsed_time_ms;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_mark_remark_start() {
342N/A _mark_remark_start_sec = os::elapsedTime();
342N/A _during_marking = false;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_mark_remark_end() {
342N/A double end_time_sec = os::elapsedTime();
342N/A double elapsed_time_ms = (end_time_sec - _mark_remark_start_sec)*1000.0;
342N/A _concurrent_mark_remark_times_ms->add(elapsed_time_ms);
342N/A _cur_mark_stop_world_time_ms += elapsed_time_ms;
342N/A _prev_collection_pause_end_ms += elapsed_time_ms;
342N/A
342N/A _mmu_tracker->add_pause(_mark_remark_start_sec, end_time_sec, true);
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_mark_cleanup_start() {
342N/A _mark_cleanup_start_sec = os::elapsedTime();
342N/A}
342N/A
2849N/Avoid G1CollectorPolicy::record_concurrent_mark_cleanup_completed() {
2986N/A _last_young_gc = true;
2695N/A _in_marking_window = false;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_pause() {
342N/A if (_stop_world_start > 0.0) {
342N/A double yield_ms = (os::elapsedTime() - _stop_world_start) * 1000.0;
3776N/A _trace_gen0_time_data.record_yield_time(yield_ms);
342N/A }
342N/A}
342N/A
3117N/Abool G1CollectorPolicy::need_to_start_conc_mark(const char* source, size_t alloc_word_size) {
3117N/A if (_g1->concurrent_mark()->cmThread()->during_cycle()) {
3112N/A return false;
3112N/A }
3112N/A
3112N/A size_t marking_initiating_used_threshold =
3112N/A (_g1->capacity() / 100) * InitiatingHeapOccupancyPercent;
3112N/A size_t cur_used_bytes = _g1->non_young_capacity_bytes();
3117N/A size_t alloc_byte_size = alloc_word_size * HeapWordSize;
3117N/A
3117N/A if ((cur_used_bytes + alloc_byte_size) > marking_initiating_used_threshold) {
3112N/A if (gcs_are_young()) {
3117N/A ergo_verbose5(ErgoConcCycles,
3112N/A "request concurrent cycle initiation",
3112N/A ergo_format_reason("occupancy higher than threshold")
3112N/A ergo_format_byte("occupancy")
3117N/A ergo_format_byte("allocation request")
3112N/A ergo_format_byte_perc("threshold")
3112N/A ergo_format_str("source"),
3112N/A cur_used_bytes,
3117N/A alloc_byte_size,
3112N/A marking_initiating_used_threshold,
3112N/A (double) InitiatingHeapOccupancyPercent,
3112N/A source);
3112N/A return true;
3112N/A } else {
3117N/A ergo_verbose5(ErgoConcCycles,
3112N/A "do not request concurrent cycle initiation",
3112N/A ergo_format_reason("still doing mixed collections")
3112N/A ergo_format_byte("occupancy")
3117N/A ergo_format_byte("allocation request")
3112N/A ergo_format_byte_perc("threshold")
3112N/A ergo_format_str("source"),
3112N/A cur_used_bytes,
3117N/A alloc_byte_size,
3112N/A marking_initiating_used_threshold,
3112N/A (double) InitiatingHeapOccupancyPercent,
3112N/A source);
3112N/A }
3112N/A }
3112N/A
3112N/A return false;
3112N/A}
3112N/A
342N/A// Anything below that is considered to be zero
342N/A#define MIN_TIMER_GRANULARITY 0.0000001
342N/A
4362N/Avoid G1CollectorPolicy::record_collection_pause_end(double pause_time_ms, EvacuationInfo& evacuation_info) {
342N/A double end_time_sec = os::elapsedTime();
2936N/A assert(_cur_collection_pause_used_regions_at_start >= cset_region_length(),
2936N/A "otherwise, the subtraction below does not make sense");
342N/A size_t rs_size =
2936N/A _cur_collection_pause_used_regions_at_start - cset_region_length();
342N/A size_t cur_used_bytes = _g1->used();
342N/A assert(cur_used_bytes == _g1->recalculate_used(), "It should!");
342N/A bool last_pause_included_initial_mark = false;
1627N/A bool update_stats = !_g1->evacuation_failed();
342N/A
342N/A#ifndef PRODUCT
342N/A if (G1YoungSurvRateVerbose) {
342N/A gclog_or_tty->print_cr("");
342N/A _short_lived_surv_rate_group->print();
342N/A // do that for any other surv rate groups too
342N/A }
342N/A#endif // PRODUCT
342N/A
2695N/A last_pause_included_initial_mark = during_initial_mark_pause();
3112N/A if (last_pause_included_initial_mark) {
2695N/A record_concurrent_mark_init_end(0.0);
3201N/A } else if (!_last_young_gc && need_to_start_conc_mark("end of GC")) {
3112N/A // Note: this might have already been set, if during the last
3112N/A // pause we decided to start a cycle but at the beginning of
3112N/A // this pause we decided to postpone it. That's OK.
3112N/A set_initiate_conc_mark_if_possible();
3112N/A }
2695N/A
3885N/A _mmu_tracker->add_pause(end_time_sec - pause_time_ms/1000.0,
342N/A end_time_sec, false);
342N/A
342N/A size_t freed_bytes =
342N/A _cur_collection_pause_used_at_start_bytes - cur_used_bytes;
342N/A size_t surviving_bytes = _collection_set_bytes_used_before - freed_bytes;
1394N/A
342N/A double survival_fraction =
342N/A (double)surviving_bytes/
342N/A (double)_collection_set_bytes_used_before;
342N/A
4362N/A evacuation_info.set_collectionset_used_before(_collection_set_bytes_used_before);
4362N/A evacuation_info.set_bytes_copied(_bytes_copied_during_gc);
4362N/A
595N/A if (update_stats) {
3885N/A _trace_gen0_time_data.record_end_collection(pause_time_ms, phase_times());
342N/A // this is where we update the allocation rate of the application
342N/A double app_time_ms =
3978N/A (phase_times()->cur_collection_start_sec() * 1000.0 - _prev_collection_pause_end_ms);
342N/A if (app_time_ms < MIN_TIMER_GRANULARITY) {
342N/A // This usually happens due to the timer not having the required
342N/A // granularity. Some Linuxes are the usual culprits.
342N/A // We'll just set it to something (arbitrarily) small.
342N/A app_time_ms = 1.0;
342N/A }
2936N/A // We maintain the invariant that all objects allocated by mutator
2936N/A // threads will be allocated out of eden regions. So, we can use
2936N/A // the eden region number allocated since the previous GC to
2936N/A // calculate the application's allocate rate. The only exception
2936N/A // to that is humongous objects that are allocated separately. But
2936N/A // given that humongous object allocations do not really affect
2936N/A // either the pause's duration nor when the next pause will take
2936N/A // place we can safely ignore them here.
3681N/A uint regions_allocated = eden_cset_region_length();
342N/A double alloc_rate_ms = (double) regions_allocated / app_time_ms;
342N/A _alloc_rate_ms_seq->add(alloc_rate_ms);
342N/A
342N/A double interval_ms =
342N/A (end_time_sec - _recent_prev_end_times_for_all_gcs_sec->oldest()) * 1000.0;
3885N/A update_recent_gc_times(end_time_sec, pause_time_ms);
342N/A _recent_avg_pause_time_ratio = _recent_gc_times_ms->sum()/interval_ms;
1086N/A if (recent_avg_pause_time_ratio() < 0.0 ||
1086N/A (recent_avg_pause_time_ratio() - 1.0 > 0.0)) {
1086N/A#ifndef PRODUCT
1086N/A // Dump info to allow post-facto debugging
1086N/A gclog_or_tty->print_cr("recent_avg_pause_time_ratio() out of bounds");
1086N/A gclog_or_tty->print_cr("-------------------------------------------");
1086N/A gclog_or_tty->print_cr("Recent GC Times (ms):");
1086N/A _recent_gc_times_ms->dump();
1086N/A gclog_or_tty->print_cr("(End Time=%3.3f) Recent GC End Times (s):", end_time_sec);
1086N/A _recent_prev_end_times_for_all_gcs_sec->dump();
1086N/A gclog_or_tty->print_cr("GC = %3.3f, Interval = %3.3f, Ratio = %3.3f",
1086N/A _recent_gc_times_ms->sum(), interval_ms, recent_avg_pause_time_ratio());
1087N/A // In debug mode, terminate the JVM if the user wants to debug at this point.
1087N/A assert(!G1FailOnFPError, "Debugging data for CR 6898948 has been dumped above");
1087N/A#endif // !PRODUCT
1087N/A // Clip ratio between 0.0 and 1.0, and continue. This will be fixed in
1087N/A // CR 6902692 by redoing the manner in which the ratio is incrementally computed.
1086N/A if (_recent_avg_pause_time_ratio < 0.0) {
1086N/A _recent_avg_pause_time_ratio = 0.0;
1086N/A } else {
1086N/A assert(_recent_avg_pause_time_ratio - 1.0 > 0.0, "Ctl-point invariant");
1086N/A _recent_avg_pause_time_ratio = 1.0;
1086N/A }
1086N/A }
342N/A }
342N/A bool new_in_marking_window = _in_marking_window;
342N/A bool new_in_marking_window_im = false;
1359N/A if (during_initial_mark_pause()) {
342N/A new_in_marking_window = true;
342N/A new_in_marking_window_im = true;
342N/A }
342N/A
2986N/A if (_last_young_gc) {
3201N/A // This is supposed to to be the "last young GC" before we start
3201N/A // doing mixed GCs. Here we decide whether to start mixed GCs or not.
3201N/A
2818N/A if (!last_pause_included_initial_mark) {
3201N/A if (next_gc_should_be_mixed("start mixed GCs",
3201N/A "do not start mixed GCs")) {
3201N/A set_gcs_are_young(false);
3201N/A }
2818N/A } else {
2986N/A ergo_verbose0(ErgoMixedGCs,
2986N/A "do not start mixed GCs",
2818N/A ergo_format_reason("concurrent cycle is about to start"));
2818N/A }
2986N/A _last_young_gc = false;
2695N/A }
2695N/A
2986N/A if (!_last_gc_was_young) {
3201N/A // This is a mixed GC. Here we decide whether to continue doing
3201N/A // mixed GCs or not.
3201N/A
3201N/A if (!next_gc_should_be_mixed("continue mixed GCs",
3201N/A "do not continue mixed GCs")) {
2986N/A set_gcs_are_young(true);
342N/A }
2695N/A }
2986N/A
342N/A _short_lived_surv_rate_group->start_adding_regions();
342N/A // do that for any other surv rate groupsx
342N/A
677N/A if (update_stats) {
342N/A double cost_per_card_ms = 0.0;
342N/A if (_pending_cards > 0) {
3978N/A cost_per_card_ms = phase_times()->average_last_update_rs_time() / (double) _pending_cards;
342N/A _cost_per_card_ms_seq->add(cost_per_card_ms);
342N/A }
342N/A
342N/A size_t cards_scanned = _g1->cards_scanned();
342N/A
342N/A double cost_per_entry_ms = 0.0;
342N/A if (cards_scanned > 10) {
3978N/A cost_per_entry_ms = phase_times()->average_last_scan_rs_time() / (double) cards_scanned;
2986N/A if (_last_gc_was_young) {
342N/A _cost_per_entry_ms_seq->add(cost_per_entry_ms);
2986N/A } else {
2986N/A _mixed_cost_per_entry_ms_seq->add(cost_per_entry_ms);
2986N/A }
342N/A }
342N/A
342N/A if (_max_rs_lengths > 0) {
342N/A double cards_per_entry_ratio =
342N/A (double) cards_scanned / (double) _max_rs_lengths;
2986N/A if (_last_gc_was_young) {
2986N/A _young_cards_per_entry_ratio_seq->add(cards_per_entry_ratio);
2986N/A } else {
2986N/A _mixed_cards_per_entry_ratio_seq->add(cards_per_entry_ratio);
2986N/A }
342N/A }
342N/A
3007N/A // This is defensive. For a while _max_rs_lengths could get
3007N/A // smaller than _recorded_rs_lengths which was causing
3007N/A // rs_length_diff to get very large and mess up the RSet length
3007N/A // predictions. The reason was unsafe concurrent updates to the
3007N/A // _inc_cset_recorded_rs_lengths field which the code below guards
3007N/A // against (see CR 7118202). This bug has now been fixed (see CR
3007N/A // 7119027). However, I'm still worried that
3007N/A // _inc_cset_recorded_rs_lengths might still end up somewhat
3007N/A // inaccurate. The concurrent refinement thread calculates an
3007N/A // RSet's length concurrently with other CR threads updating it
3007N/A // which might cause it to calculate the length incorrectly (if,
3007N/A // say, it's in mid-coarsening). So I'll leave in the defensive
3007N/A // conditional below just in case.
2973N/A size_t rs_length_diff = 0;
2973N/A if (_max_rs_lengths > _recorded_rs_lengths) {
2973N/A rs_length_diff = _max_rs_lengths - _recorded_rs_lengths;
2973N/A }
2973N/A _rs_length_diff_seq->add((double) rs_length_diff);
342N/A
342N/A size_t copied_bytes = surviving_bytes;
342N/A double cost_per_byte_ms = 0.0;
342N/A if (copied_bytes > 0) {
3978N/A cost_per_byte_ms = phase_times()->average_last_obj_copy_time() / (double) copied_bytes;
2986N/A if (_in_marking_window) {
342N/A _cost_per_byte_ms_during_cm_seq->add(cost_per_byte_ms);
2986N/A } else {
342N/A _cost_per_byte_ms_seq->add(cost_per_byte_ms);
2986N/A }
342N/A }
342N/A
342N/A double all_other_time_ms = pause_time_ms -
3978N/A (phase_times()->average_last_update_rs_time() + phase_times()->average_last_scan_rs_time()
3978N/A + phase_times()->average_last_obj_copy_time() + phase_times()->average_last_termination_time());
342N/A
342N/A double young_other_time_ms = 0.0;
2936N/A if (young_cset_region_length() > 0) {
342N/A young_other_time_ms =
3978N/A phase_times()->young_cset_choice_time_ms() +
3978N/A phase_times()->young_free_cset_time_ms();
342N/A _young_other_cost_per_region_ms_seq->add(young_other_time_ms /
2936N/A (double) young_cset_region_length());
342N/A }
342N/A double non_young_other_time_ms = 0.0;
2936N/A if (old_cset_region_length() > 0) {
342N/A non_young_other_time_ms =
3978N/A phase_times()->non_young_cset_choice_time_ms() +
3978N/A phase_times()->non_young_free_cset_time_ms();
342N/A
342N/A _non_young_other_cost_per_region_ms_seq->add(non_young_other_time_ms /
2936N/A (double) old_cset_region_length());
342N/A }
342N/A
342N/A double constant_other_time_ms = all_other_time_ms -
342N/A (young_other_time_ms + non_young_other_time_ms);
342N/A _constant_other_time_ms_seq->add(constant_other_time_ms);
342N/A
342N/A double survival_ratio = 0.0;
3961N/A if (_collection_set_bytes_used_before > 0) {
2655N/A survival_ratio = (double) _bytes_copied_during_gc /
3961N/A (double) _collection_set_bytes_used_before;
342N/A }
342N/A
342N/A _pending_cards_seq->add((double) _pending_cards);
342N/A _rs_lengths_seq->add((double) _max_rs_lengths);
342N/A }
342N/A
342N/A _in_marking_window = new_in_marking_window;
342N/A _in_marking_window_im = new_in_marking_window_im;
342N/A _free_regions_at_end_of_collection = _g1->free_regions();
2753N/A update_young_list_target_length();
342N/A
1111N/A // Note that _mmu_tracker->max_gc_time() returns the time in seconds.
1282N/A double update_rs_time_goal_ms = _mmu_tracker->max_gc_time() * MILLIUNITS * G1RSetUpdatingPauseTimePercent / 100.0;
3978N/A adjust_concurrent_refinement(phase_times()->average_last_update_rs_time(),
3978N/A phase_times()->sum_last_update_rs_processed_buffers(), update_rs_time_goal_ms);
2849N/A
3682N/A _collectionSetChooser->verify();
342N/A}
342N/A
3728N/A#define EXT_SIZE_FORMAT "%.1f%s"
2589N/A#define EXT_SIZE_PARAMS(bytes) \
3728N/A byte_size_in_proper_unit((double)(bytes)), \
2589N/A proper_unit_for_byte_size((bytes))
2589N/A
4485N/Avoid G1CollectorPolicy::record_heap_size_info_at_start() {
4485N/A YoungList* young_list = _g1->young_list();
4485N/A _eden_bytes_before_gc = young_list->eden_used_bytes();
4485N/A _survivor_bytes_before_gc = young_list->survivor_used_bytes();
4485N/A _capacity_before_gc = _g1->capacity();
4485N/A
4485N/A _cur_collection_pause_used_at_start_bytes = _g1->used();
4485N/A _cur_collection_pause_used_regions_at_start = _g1->used_regions();
4485N/A
4485N/A size_t eden_capacity_before_gc =
4485N/A (_young_list_target_length * HeapRegion::GrainBytes) - _survivor_bytes_before_gc;
4485N/A
4485N/A _prev_eden_capacity = eden_capacity_before_gc;
4485N/A}
4485N/A
2589N/Avoid G1CollectorPolicy::print_heap_transition() {
3978N/A _g1->print_size_transition(gclog_or_tty,
3978N/A _cur_collection_pause_used_at_start_bytes, _g1->used(), _g1->capacity());
3978N/A}
3978N/A
3978N/Avoid G1CollectorPolicy::print_detailed_heap_transition() {
2589N/A YoungList* young_list = _g1->young_list();
2589N/A size_t eden_bytes = young_list->eden_used_bytes();
2589N/A size_t survivor_bytes = young_list->survivor_used_bytes();
2589N/A size_t used_before_gc = _cur_collection_pause_used_at_start_bytes;
2589N/A size_t used = _g1->used();
2589N/A size_t capacity = _g1->capacity();
2754N/A size_t eden_capacity =
2754N/A (_young_list_target_length * HeapRegion::GrainBytes) - survivor_bytes;
2589N/A
2589N/A gclog_or_tty->print_cr(
2754N/A " [Eden: "EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")->"EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT") "
2754N/A "Survivors: "EXT_SIZE_FORMAT"->"EXT_SIZE_FORMAT" "
2754N/A "Heap: "EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")->"
2754N/A EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")]",
2754N/A EXT_SIZE_PARAMS(_eden_bytes_before_gc),
2754N/A EXT_SIZE_PARAMS(_prev_eden_capacity),
2754N/A EXT_SIZE_PARAMS(eden_bytes),
2754N/A EXT_SIZE_PARAMS(eden_capacity),
2754N/A EXT_SIZE_PARAMS(_survivor_bytes_before_gc),
2754N/A EXT_SIZE_PARAMS(survivor_bytes),
2754N/A EXT_SIZE_PARAMS(used_before_gc),
2754N/A EXT_SIZE_PARAMS(_capacity_before_gc),
2754N/A EXT_SIZE_PARAMS(used),
2754N/A EXT_SIZE_PARAMS(capacity));
2589N/A}
2589N/A
1111N/Avoid G1CollectorPolicy::adjust_concurrent_refinement(double update_rs_time,
1111N/A double update_rs_processed_buffers,
1111N/A double goal_ms) {
1111N/A DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
1111N/A ConcurrentG1Refine *cg1r = G1CollectedHeap::heap()->concurrent_g1_refine();
1111N/A
1282N/A if (G1UseAdaptiveConcRefinement) {
1111N/A const int k_gy = 3, k_gr = 6;
1111N/A const double inc_k = 1.1, dec_k = 0.9;
1111N/A
1111N/A int g = cg1r->green_zone();
1111N/A if (update_rs_time > goal_ms) {
1111N/A g = (int)(g * dec_k); // Can become 0, that's OK. That would mean a mutator-only processing.
1111N/A } else {
1111N/A if (update_rs_time < goal_ms && update_rs_processed_buffers > g) {
1111N/A g = (int)MAX2(g * inc_k, g + 1.0);
1111N/A }
1111N/A }
1111N/A // Change the refinement threads params
1111N/A cg1r->set_green_zone(g);
1111N/A cg1r->set_yellow_zone(g * k_gy);
1111N/A cg1r->set_red_zone(g * k_gr);
1111N/A cg1r->reinitialize_threads();
1111N/A
1111N/A int processing_threshold_delta = MAX2((int)(cg1r->green_zone() * sigma()), 1);
1111N/A int processing_threshold = MIN2(cg1r->green_zone() + processing_threshold_delta,
1111N/A cg1r->yellow_zone());
1111N/A // Change the barrier params
1111N/A dcqs.set_process_completed_threshold(processing_threshold);
1111N/A dcqs.set_max_completed_queue(cg1r->red_zone());
1111N/A }
1111N/A
1111N/A int curr_queue_size = dcqs.completed_buffers_num();
1111N/A if (curr_queue_size >= cg1r->yellow_zone()) {
1111N/A dcqs.set_completed_queue_padding(curr_queue_size);
1111N/A } else {
1111N/A dcqs.set_completed_queue_padding(0);
1111N/A }
1111N/A dcqs.notify_if_necessary();
1111N/A}
1111N/A
342N/Adouble
342N/AG1CollectorPolicy::predict_base_elapsed_time_ms(size_t pending_cards,
342N/A size_t scanned_cards) {
342N/A return
342N/A predict_rs_update_time_ms(pending_cards) +
342N/A predict_rs_scan_time_ms(scanned_cards) +
342N/A predict_constant_other_time_ms();
342N/A}
342N/A
342N/Adouble
3961N/AG1CollectorPolicy::predict_base_elapsed_time_ms(size_t pending_cards) {
3961N/A size_t rs_length = predict_rs_length_diff();
342N/A size_t card_num;
2986N/A if (gcs_are_young()) {
342N/A card_num = predict_young_card_num(rs_length);
2986N/A } else {
342N/A card_num = predict_non_young_card_num(rs_length);
2986N/A }
3961N/A return predict_base_elapsed_time_ms(pending_cards, card_num);
342N/A}
342N/A
3681N/Asize_t G1CollectorPolicy::predict_bytes_to_copy(HeapRegion* hr) {
342N/A size_t bytes_to_copy;
342N/A if (hr->is_marked())
342N/A bytes_to_copy = hr->max_live_bytes();
342N/A else {
3201N/A assert(hr->is_young() && hr->age_in_surv_rate_group() != -1, "invariant");
342N/A int age = hr->age_in_surv_rate_group();
545N/A double yg_surv_rate = predict_yg_surv_rate(age, hr->surv_rate_group());
342N/A bytes_to_copy = (size_t) ((double) hr->used() * yg_surv_rate);
342N/A }
342N/A return bytes_to_copy;
342N/A}
342N/A
3961N/Adouble
3961N/AG1CollectorPolicy::predict_region_elapsed_time_ms(HeapRegion* hr,
3961N/A bool for_young_gc) {
3961N/A size_t rs_length = hr->rem_set()->occupied();
3961N/A size_t card_num;
3961N/A
3961N/A // Predicting the number of cards is based on which type of GC
3961N/A // we're predicting for.
3961N/A if (for_young_gc) {
3961N/A card_num = predict_young_card_num(rs_length);
3961N/A } else {
3961N/A card_num = predict_non_young_card_num(rs_length);
3961N/A }
3961N/A size_t bytes_to_copy = predict_bytes_to_copy(hr);
3961N/A
3961N/A double region_elapsed_time_ms =
3961N/A predict_rs_scan_time_ms(card_num) +
3961N/A predict_object_copy_time_ms(bytes_to_copy);
3961N/A
3961N/A // The prediction of the "other" time for this region is based
3961N/A // upon the region type and NOT the GC type.
3961N/A if (hr->is_young()) {
3961N/A region_elapsed_time_ms += predict_young_other_time_ms(1);
3961N/A } else {
3961N/A region_elapsed_time_ms += predict_non_young_other_time_ms(1);
3961N/A }
3961N/A return region_elapsed_time_ms;
3961N/A}
3961N/A
342N/Avoid
3681N/AG1CollectorPolicy::init_cset_region_lengths(uint eden_cset_region_length,
3681N/A uint survivor_cset_region_length) {
2936N/A _eden_cset_region_length = eden_cset_region_length;
2936N/A _survivor_cset_region_length = survivor_cset_region_length;
2936N/A _old_cset_region_length = 0;
1394N/A}
1394N/A
1394N/Avoid G1CollectorPolicy::set_recorded_rs_lengths(size_t rs_lengths) {
1394N/A _recorded_rs_lengths = rs_lengths;
1394N/A}
1394N/A
342N/Avoid G1CollectorPolicy::update_recent_gc_times(double end_time_sec,
342N/A double elapsed_ms) {
342N/A _recent_gc_times_ms->add(elapsed_ms);
342N/A _recent_prev_end_times_for_all_gcs_sec->add(end_time_sec);
342N/A _prev_collection_pause_end_ms = end_time_sec * 1000.0;
342N/A}
342N/A
342N/Asize_t G1CollectorPolicy::expansion_amount() {
2748N/A double recent_gc_overhead = recent_avg_pause_time_ratio() * 100.0;
2748N/A double threshold = _gc_overhead_perc;
2748N/A if (recent_gc_overhead > threshold) {
751N/A // We will double the existing space, or take
751N/A // G1ExpandByPercentOfAvailable % of the available expansion
751N/A // space, whichever is smaller, bounded below by a minimum
751N/A // expansion (unless that's all that's left.)
342N/A const size_t min_expand_bytes = 1*M;
2069N/A size_t reserved_bytes = _g1->max_capacity();
342N/A size_t committed_bytes = _g1->capacity();
342N/A size_t uncommitted_bytes = reserved_bytes - committed_bytes;
342N/A size_t expand_bytes;
342N/A size_t expand_bytes_via_pct =
751N/A uncommitted_bytes * G1ExpandByPercentOfAvailable / 100;
342N/A expand_bytes = MIN2(expand_bytes_via_pct, committed_bytes);
342N/A expand_bytes = MAX2(expand_bytes, min_expand_bytes);
342N/A expand_bytes = MIN2(expand_bytes, uncommitted_bytes);
2748N/A
2748N/A ergo_verbose5(ErgoHeapSizing,
2748N/A "attempt heap expansion",
2748N/A ergo_format_reason("recent GC overhead higher than "
2748N/A "threshold after GC")
2748N/A ergo_format_perc("recent GC overhead")
2748N/A ergo_format_perc("threshold")
2748N/A ergo_format_byte("uncommitted")
2748N/A ergo_format_byte_perc("calculated expansion amount"),
2748N/A recent_gc_overhead, threshold,
2748N/A uncommitted_bytes,
2748N/A expand_bytes_via_pct, (double) G1ExpandByPercentOfAvailable);
2748N/A
342N/A return expand_bytes;
342N/A } else {
342N/A return 0;
342N/A }
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::print_tracing_info() const {
3776N/A _trace_gen0_time_data.print();
3776N/A _trace_gen1_time_data.print();
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::print_yg_surv_rate_info() const {
342N/A#ifndef PRODUCT
342N/A _short_lived_surv_rate_group->print_surv_rate_summary();
342N/A // add this call for any other surv rate groups
342N/A#endif // PRODUCT
342N/A}
342N/A
342N/A#ifndef PRODUCT
342N/A// for debugging, bit of a hack...
342N/Astatic char*
342N/Aregion_num_to_mbs(int length) {
342N/A static char buffer[64];
342N/A double bytes = (double) (length * HeapRegion::GrainBytes);
342N/A double mbs = bytes / (double) (1024 * 1024);
342N/A sprintf(buffer, "%7.2lfMB", mbs);
342N/A return buffer;
342N/A}
342N/A#endif // PRODUCT
342N/A
3681N/Auint G1CollectorPolicy::max_regions(int purpose) {
342N/A switch (purpose) {
342N/A case GCAllocForSurvived:
545N/A return _max_survivor_regions;
342N/A case GCAllocForTenured:
545N/A return REGIONS_UNLIMITED;
342N/A default:
545N/A ShouldNotReachHere();
545N/A return REGIONS_UNLIMITED;
342N/A };
342N/A}
342N/A
2753N/Avoid G1CollectorPolicy::update_max_gc_locker_expansion() {
3681N/A uint expansion_region_num = 0;
1898N/A if (GCLockerEdenExpansionPercent > 0) {
1898N/A double perc = (double) GCLockerEdenExpansionPercent / 100.0;
1898N/A double expansion_region_num_d = perc * (double) _young_list_target_length;
1898N/A // We use ceiling so that if expansion_region_num_d is > 0.0 (but
1898N/A // less than 1.0) we'll get 1.
3681N/A expansion_region_num = (uint) ceil(expansion_region_num_d);
1898N/A } else {
1898N/A assert(expansion_region_num == 0, "sanity");
1898N/A }
1898N/A _young_list_max_length = _young_list_target_length + expansion_region_num;
1898N/A assert(_young_list_target_length <= _young_list_max_length, "post-condition");
1898N/A}
1898N/A
545N/A// Calculates survivor space parameters.
2753N/Avoid G1CollectorPolicy::update_survivors_policy() {
2753N/A double max_survivor_regions_d =
2753N/A (double) _young_list_target_length / (double) SurvivorRatio;
2753N/A // We use ceiling so that if max_survivor_regions_d is > 0.0 (but
2753N/A // smaller than 1.0) we'll get 1.
3681N/A _max_survivor_regions = (uint) ceil(max_survivor_regions_d);
2753N/A
2696N/A _tenuring_threshold = _survivors_age_table.compute_tenuring_threshold(
545N/A HeapRegion::GrainWords * _max_survivor_regions);
545N/A}
545N/A
2748N/Abool G1CollectorPolicy::force_initial_mark_if_outside_cycle(
2748N/A GCCause::Cause gc_cause) {
1576N/A bool during_cycle = _g1->concurrent_mark()->cmThread()->during_cycle();
1576N/A if (!during_cycle) {
2748N/A ergo_verbose1(ErgoConcCycles,
2748N/A "request concurrent cycle initiation",
2748N/A ergo_format_reason("requested by GC cause")
2748N/A ergo_format_str("GC cause"),
2748N/A GCCause::to_string(gc_cause));
1576N/A set_initiate_conc_mark_if_possible();
1576N/A return true;
1576N/A } else {
2748N/A ergo_verbose1(ErgoConcCycles,
2748N/A "do not request concurrent cycle initiation",
2748N/A ergo_format_reason("concurrent cycle already in progress")
2748N/A ergo_format_str("GC cause"),
2748N/A GCCause::to_string(gc_cause));
1576N/A return false;
1576N/A }
1576N/A}
1576N/A
342N/Avoid
1359N/AG1CollectorPolicy::decide_on_conc_mark_initiation() {
1359N/A // We are about to decide on whether this pause will be an
1359N/A // initial-mark pause.
1359N/A
1359N/A // First, during_initial_mark_pause() should not be already set. We
1359N/A // will set it here if we have to. However, it should be cleared by
1359N/A // the end of the pause (it's only set for the duration of an
1359N/A // initial-mark pause).
1359N/A assert(!during_initial_mark_pause(), "pre-condition");
1359N/A
1359N/A if (initiate_conc_mark_if_possible()) {
1359N/A // We had noticed on a previous pause that the heap occupancy has
1359N/A // gone over the initiating threshold and we should start a
1359N/A // concurrent marking cycle. So we might initiate one.
1359N/A
1359N/A bool during_cycle = _g1->concurrent_mark()->cmThread()->during_cycle();
1359N/A if (!during_cycle) {
1359N/A // The concurrent marking thread is not "during a cycle", i.e.,
1359N/A // it has completed the last one. So we can go ahead and
1359N/A // initiate a new cycle.
1359N/A
1359N/A set_during_initial_mark_pause();
2986N/A // We do not allow mixed GCs during marking.
2986N/A if (!gcs_are_young()) {
2986N/A set_gcs_are_young(true);
2986N/A ergo_verbose0(ErgoMixedGCs,
2986N/A "end mixed GCs",
2818N/A ergo_format_reason("concurrent cycle is about to start"));
2818N/A }
1359N/A
1359N/A // And we can now clear initiate_conc_mark_if_possible() as
1359N/A // we've already acted on it.
1359N/A clear_initiate_conc_mark_if_possible();
2748N/A
2748N/A ergo_verbose0(ErgoConcCycles,
2748N/A "initiate concurrent cycle",
2748N/A ergo_format_reason("concurrent cycle initiation requested"));
1359N/A } else {
1359N/A // The concurrent marking thread is still finishing up the
1359N/A // previous cycle. If we start one right now the two cycles
1359N/A // overlap. In particular, the concurrent marking thread might
1359N/A // be in the process of clearing the next marking bitmap (which
1359N/A // we will use for the next cycle if we start one). Starting a
1359N/A // cycle now will be bad given that parts of the marking
1359N/A // information might get cleared by the marking thread. And we
1359N/A // cannot wait for the marking thread to finish the cycle as it
1359N/A // periodically yields while clearing the next marking bitmap
1359N/A // and, if it's in a yield point, it's waiting for us to
1359N/A // finish. So, at this point we will not start a cycle and we'll
1359N/A // let the concurrent marking thread complete the last one.
2748N/A ergo_verbose0(ErgoConcCycles,
2748N/A "do not initiate concurrent cycle",
2748N/A ergo_format_reason("concurrent cycle already in progress"));
1359N/A }
1359N/A }
1359N/A}
1359N/A
342N/Aclass KnownGarbageClosure: public HeapRegionClosure {
3201N/A G1CollectedHeap* _g1h;
342N/A CollectionSetChooser* _hrSorted;
342N/A
342N/Apublic:
342N/A KnownGarbageClosure(CollectionSetChooser* hrSorted) :
3201N/A _g1h(G1CollectedHeap::heap()), _hrSorted(hrSorted) { }
342N/A
342N/A bool doHeapRegion(HeapRegion* r) {
342N/A // We only include humongous regions in collection
342N/A // sets when concurrent mark shows that their contained object is
342N/A // unreachable.
342N/A
342N/A // Do we have any marking information for this region?
342N/A if (r->is_marked()) {
3201N/A // We will skip any region that's currently used as an old GC
3201N/A // alloc region (we should not consider those for collection
3201N/A // before we fill them up).
3682N/A if (_hrSorted->should_add(r) && !_g1h->is_old_gc_alloc_region(r)) {
3682N/A _hrSorted->add_region(r);
342N/A }
342N/A }
342N/A return false;
342N/A }
342N/A};
342N/A
342N/Aclass ParKnownGarbageHRClosure: public HeapRegionClosure {
3201N/A G1CollectedHeap* _g1h;
3920N/A CSetChooserParUpdater _cset_updater;
342N/A
342N/Apublic:
342N/A ParKnownGarbageHRClosure(CollectionSetChooser* hrSorted,
3682N/A uint chunk_size) :
3920N/A _g1h(G1CollectedHeap::heap()),
3920N/A _cset_updater(hrSorted, true /* parallel */, chunk_size) { }
342N/A
342N/A bool doHeapRegion(HeapRegion* r) {
342N/A // Do we have any marking information for this region?
342N/A if (r->is_marked()) {
3201N/A // We will skip any region that's currently used as an old GC
3201N/A // alloc region (we should not consider those for collection
3201N/A // before we fill them up).
3920N/A if (_cset_updater.should_add(r) && !_g1h->is_old_gc_alloc_region(r)) {
3920N/A _cset_updater.add_region(r);
342N/A }
342N/A }
342N/A return false;
342N/A }
342N/A};
342N/A
342N/Aclass ParKnownGarbageTask: public AbstractGangTask {
342N/A CollectionSetChooser* _hrSorted;
3682N/A uint _chunk_size;
342N/A G1CollectedHeap* _g1;
342N/Apublic:
3682N/A ParKnownGarbageTask(CollectionSetChooser* hrSorted, uint chunk_size) :
342N/A AbstractGangTask("ParKnownGarbageTask"),
342N/A _hrSorted(hrSorted), _chunk_size(chunk_size),
3201N/A _g1(G1CollectedHeap::heap()) { }
342N/A
3008N/A void work(uint worker_id) {
3682N/A ParKnownGarbageHRClosure parKnownGarbageCl(_hrSorted, _chunk_size);
3682N/A
342N/A // Back to zero for the claim value.
3008N/A _g1->heap_region_par_iterate_chunked(&parKnownGarbageCl, worker_id,
2941N/A _g1->workers()->active_workers(),
355N/A HeapRegion::InitialClaimValue);
342N/A }
342N/A};
342N/A
342N/Avoid
2941N/AG1CollectorPolicy::record_concurrent_mark_cleanup_end(int no_of_gc_threads) {
3682N/A _collectionSetChooser->clear();
2849N/A
3681N/A uint region_num = _g1->n_regions();
1753N/A if (G1CollectedHeap::use_parallel_gc_threads()) {
3681N/A const uint OverpartitionFactor = 4;
3681N/A uint WorkUnit;
2941N/A // The use of MinChunkSize = 8 in the original code
2941N/A // causes some assertion failures when the total number of
2941N/A // region is less than 8. The code here tries to fix that.
2941N/A // Should the original code also be fixed?
2941N/A if (no_of_gc_threads > 0) {
3681N/A const uint MinWorkUnit = MAX2(region_num / no_of_gc_threads, 1U);
3681N/A WorkUnit = MAX2(region_num / (no_of_gc_threads * OverpartitionFactor),
3681N/A MinWorkUnit);
2941N/A } else {
2941N/A assert(no_of_gc_threads > 0,
2941N/A "The active gc workers should be greater than 0");
2941N/A // In a product build do something reasonable to avoid a crash.
3681N/A const uint MinWorkUnit = MAX2(region_num / (uint) ParallelGCThreads, 1U);
2941N/A WorkUnit =
3681N/A MAX2(region_num / (uint) (ParallelGCThreads * OverpartitionFactor),
2941N/A MinWorkUnit);
2941N/A }
3682N/A _collectionSetChooser->prepare_for_par_region_addition(_g1->n_regions(),
3682N/A WorkUnit);
342N/A ParKnownGarbageTask parKnownGarbageTask(_collectionSetChooser,
1491N/A (int) WorkUnit);
342N/A _g1->workers()->run_task(&parKnownGarbageTask);
355N/A
355N/A assert(_g1->check_heap_region_claim_values(HeapRegion::InitialClaimValue),
355N/A "sanity check");
342N/A } else {
342N/A KnownGarbageClosure knownGarbagecl(_collectionSetChooser);
342N/A _g1->heap_region_iterate(&knownGarbagecl);
342N/A }
2849N/A
3682N/A _collectionSetChooser->sort_regions();
3682N/A
2849N/A double end_sec = os::elapsedTime();
2849N/A double elapsed_time_ms = (end_sec - _mark_cleanup_start_sec) * 1000.0;
2849N/A _concurrent_mark_cleanup_times_ms->add(elapsed_time_ms);
2849N/A _cur_mark_stop_world_time_ms += elapsed_time_ms;
2849N/A _prev_collection_pause_end_ms += elapsed_time_ms;
2849N/A _mmu_tracker->add_pause(_mark_cleanup_start_sec, end_sec, true);
342N/A}
342N/A
1394N/A// Add the heap region at the head of the non-incremental collection set
2936N/Avoid G1CollectorPolicy::add_old_region_to_cset(HeapRegion* hr) {
1394N/A assert(_inc_cset_build_state == Active, "Precondition");
1394N/A assert(!hr->is_young(), "non-incremental add of young region");
1394N/A
1394N/A assert(!hr->in_collection_set(), "should not already be in the CSet");
342N/A hr->set_in_collection_set(true);
342N/A hr->set_next_in_collection_set(_collection_set);
342N/A _collection_set = hr;
342N/A _collection_set_bytes_used_before += hr->used();
526N/A _g1->register_region_with_in_cset_fast_test(hr);
2936N/A size_t rs_length = hr->rem_set()->occupied();
2936N/A _recorded_rs_lengths += rs_length;
2936N/A _old_cset_region_length += 1;
342N/A}
342N/A
1394N/A// Initialize the per-collection-set information
1394N/Avoid G1CollectorPolicy::start_incremental_cset_building() {
1394N/A assert(_inc_cset_build_state == Inactive, "Precondition");
1394N/A
1394N/A _inc_cset_head = NULL;
1394N/A _inc_cset_tail = NULL;
1394N/A _inc_cset_bytes_used_before = 0;
1394N/A
1394N/A _inc_cset_max_finger = 0;
1394N/A _inc_cset_recorded_rs_lengths = 0;
3007N/A _inc_cset_recorded_rs_lengths_diffs = 0;
3007N/A _inc_cset_predicted_elapsed_time_ms = 0.0;
3007N/A _inc_cset_predicted_elapsed_time_ms_diffs = 0.0;
1394N/A _inc_cset_build_state = Active;
1394N/A}
1394N/A
3007N/Avoid G1CollectorPolicy::finalize_incremental_cset_building() {
3007N/A assert(_inc_cset_build_state == Active, "Precondition");
3007N/A assert(SafepointSynchronize::is_at_safepoint(), "should be at a safepoint");
3007N/A
3007N/A // The two "main" fields, _inc_cset_recorded_rs_lengths and
3007N/A // _inc_cset_predicted_elapsed_time_ms, are updated by the thread
3007N/A // that adds a new region to the CSet. Further updates by the
3007N/A // concurrent refinement thread that samples the young RSet lengths
3007N/A // are accumulated in the *_diffs fields. Here we add the diffs to
3007N/A // the "main" fields.
3007N/A
3007N/A if (_inc_cset_recorded_rs_lengths_diffs >= 0) {
3007N/A _inc_cset_recorded_rs_lengths += _inc_cset_recorded_rs_lengths_diffs;
3007N/A } else {
3007N/A // This is defensive. The diff should in theory be always positive
3007N/A // as RSets can only grow between GCs. However, given that we
3007N/A // sample their size concurrently with other threads updating them
3007N/A // it's possible that we might get the wrong size back, which
3007N/A // could make the calculations somewhat inaccurate.
3007N/A size_t diffs = (size_t) (-_inc_cset_recorded_rs_lengths_diffs);
3007N/A if (_inc_cset_recorded_rs_lengths >= diffs) {
3007N/A _inc_cset_recorded_rs_lengths -= diffs;
3007N/A } else {
3007N/A _inc_cset_recorded_rs_lengths = 0;
3007N/A }
3007N/A }
3007N/A _inc_cset_predicted_elapsed_time_ms +=
3007N/A _inc_cset_predicted_elapsed_time_ms_diffs;
3007N/A
3007N/A _inc_cset_recorded_rs_lengths_diffs = 0;
3007N/A _inc_cset_predicted_elapsed_time_ms_diffs = 0.0;
3007N/A}
3007N/A
1394N/Avoid G1CollectorPolicy::add_to_incremental_cset_info(HeapRegion* hr, size_t rs_length) {
1394N/A // This routine is used when:
1394N/A // * adding survivor regions to the incremental cset at the end of an
1394N/A // evacuation pause,
1394N/A // * adding the current allocation region to the incremental cset
1394N/A // when it is retired, and
1394N/A // * updating existing policy information for a region in the
1394N/A // incremental cset via young list RSet sampling.
1394N/A // Therefore this routine may be called at a safepoint by the
1394N/A // VM thread, or in-between safepoints by mutator threads (when
1394N/A // retiring the current allocation region) or a concurrent
1394N/A // refine thread (RSet sampling).
1394N/A
3961N/A double region_elapsed_time_ms = predict_region_elapsed_time_ms(hr, gcs_are_young());
1394N/A size_t used_bytes = hr->used();
1394N/A _inc_cset_recorded_rs_lengths += rs_length;
1394N/A _inc_cset_predicted_elapsed_time_ms += region_elapsed_time_ms;
1394N/A _inc_cset_bytes_used_before += used_bytes;
1394N/A
1394N/A // Cache the values we have added to the aggregated informtion
1394N/A // in the heap region in case we have to remove this region from
1394N/A // the incremental collection set, or it is updated by the
1394N/A // rset sampling code
1394N/A hr->set_recorded_rs_length(rs_length);
1394N/A hr->set_predicted_elapsed_time_ms(region_elapsed_time_ms);
1394N/A}
1394N/A
3007N/Avoid G1CollectorPolicy::update_incremental_cset_info(HeapRegion* hr,
3007N/A size_t new_rs_length) {
3007N/A // Update the CSet information that is dependent on the new RS length
3007N/A assert(hr->is_young(), "Precondition");
3007N/A assert(!SafepointSynchronize::is_at_safepoint(),
3007N/A "should not be at a safepoint");
3007N/A
3007N/A // We could have updated _inc_cset_recorded_rs_lengths and
3007N/A // _inc_cset_predicted_elapsed_time_ms directly but we'd need to do
3007N/A // that atomically, as this code is executed by a concurrent
3007N/A // refinement thread, potentially concurrently with a mutator thread
3007N/A // allocating a new region and also updating the same fields. To
3007N/A // avoid the atomic operations we accumulate these updates on two
3007N/A // separate fields (*_diffs) and we'll just add them to the "main"
3007N/A // fields at the start of a GC.
3007N/A
3007N/A ssize_t old_rs_length = (ssize_t) hr->recorded_rs_length();
3007N/A ssize_t rs_lengths_diff = (ssize_t) new_rs_length - old_rs_length;
3007N/A _inc_cset_recorded_rs_lengths_diffs += rs_lengths_diff;
3007N/A
1394N/A double old_elapsed_time_ms = hr->predicted_elapsed_time_ms();
3961N/A double new_region_elapsed_time_ms = predict_region_elapsed_time_ms(hr, gcs_are_young());
3007N/A double elapsed_ms_diff = new_region_elapsed_time_ms - old_elapsed_time_ms;
3007N/A _inc_cset_predicted_elapsed_time_ms_diffs += elapsed_ms_diff;
3007N/A
3007N/A hr->set_recorded_rs_length(new_rs_length);
3007N/A hr->set_predicted_elapsed_time_ms(new_region_elapsed_time_ms);
1394N/A}
1394N/A
1394N/Avoid G1CollectorPolicy::add_region_to_incremental_cset_common(HeapRegion* hr) {
2936N/A assert(hr->is_young(), "invariant");
2936N/A assert(hr->young_index_in_cset() > -1, "should have already been set");
1394N/A assert(_inc_cset_build_state == Active, "Precondition");
1394N/A
1394N/A // We need to clear and set the cached recorded/cached collection set
1394N/A // information in the heap region here (before the region gets added
1394N/A // to the collection set). An individual heap region's cached values
1394N/A // are calculated, aggregated with the policy collection set info,
1394N/A // and cached in the heap region here (initially) and (subsequently)
1394N/A // by the Young List sampling code.
1394N/A
1394N/A size_t rs_length = hr->rem_set()->occupied();
1394N/A add_to_incremental_cset_info(hr, rs_length);
1394N/A
1394N/A HeapWord* hr_end = hr->end();
1394N/A _inc_cset_max_finger = MAX2(_inc_cset_max_finger, hr_end);
1394N/A
1394N/A assert(!hr->in_collection_set(), "invariant");
1394N/A hr->set_in_collection_set(true);
1394N/A assert( hr->next_in_collection_set() == NULL, "invariant");
1394N/A
1394N/A _g1->register_region_with_in_cset_fast_test(hr);
1394N/A}
1394N/A
1394N/A// Add the region at the RHS of the incremental cset
1394N/Avoid G1CollectorPolicy::add_region_to_incremental_cset_rhs(HeapRegion* hr) {
1394N/A // We should only ever be appending survivors at the end of a pause
1394N/A assert( hr->is_survivor(), "Logic");
1394N/A
1394N/A // Do the 'common' stuff
1394N/A add_region_to_incremental_cset_common(hr);
1394N/A
1394N/A // Now add the region at the right hand side
1394N/A if (_inc_cset_tail == NULL) {
1394N/A assert(_inc_cset_head == NULL, "invariant");
1394N/A _inc_cset_head = hr;
1394N/A } else {
1394N/A _inc_cset_tail->set_next_in_collection_set(hr);
1394N/A }
1394N/A _inc_cset_tail = hr;
1394N/A}
1394N/A
1394N/A// Add the region to the LHS of the incremental cset
1394N/Avoid G1CollectorPolicy::add_region_to_incremental_cset_lhs(HeapRegion* hr) {
1394N/A // Survivors should be added to the RHS at the end of a pause
1394N/A assert(!hr->is_survivor(), "Logic");
1394N/A
1394N/A // Do the 'common' stuff
1394N/A add_region_to_incremental_cset_common(hr);
1394N/A
1394N/A // Add the region at the left hand side
1394N/A hr->set_next_in_collection_set(_inc_cset_head);
1394N/A if (_inc_cset_head == NULL) {
1394N/A assert(_inc_cset_tail == NULL, "Invariant");
1394N/A _inc_cset_tail = hr;
1394N/A }
1394N/A _inc_cset_head = hr;
1394N/A}
1394N/A
1394N/A#ifndef PRODUCT
1394N/Avoid G1CollectorPolicy::print_collection_set(HeapRegion* list_head, outputStream* st) {
1394N/A assert(list_head == inc_cset_head() || list_head == collection_set(), "must be");
1394N/A
1394N/A st->print_cr("\nCollection_set:");
1394N/A HeapRegion* csr = list_head;
1394N/A while (csr != NULL) {
1394N/A HeapRegion* next = csr->next_in_collection_set();
1394N/A assert(csr->in_collection_set(), "bad CS");
3696N/A st->print_cr(" "HR_FORMAT", P: "PTR_FORMAT "N: "PTR_FORMAT", age: %4d",
3696N/A HR_FORMAT_PARAMS(csr),
3696N/A csr->prev_top_at_mark_start(), csr->next_top_at_mark_start(),
3696N/A csr->age_in_surv_rate_group_cond());
1394N/A csr = next;
1394N/A }
1394N/A}
1394N/A#endif // !PRODUCT
1394N/A
4461N/Adouble G1CollectorPolicy::reclaimable_bytes_perc(size_t reclaimable_bytes) {
4461N/A // Returns the given amount of reclaimable bytes (that represents
4461N/A // the amount of reclaimable space still to be collected) as a
4461N/A // percentage of the current heap capacity.
4461N/A size_t capacity_bytes = _g1->capacity();
4461N/A return (double) reclaimable_bytes * 100.0 / (double) capacity_bytes;
4461N/A}
4461N/A
3201N/Abool G1CollectorPolicy::next_gc_should_be_mixed(const char* true_action_str,
3201N/A const char* false_action_str) {
3201N/A CollectionSetChooser* cset_chooser = _collectionSetChooser;
3682N/A if (cset_chooser->is_empty()) {
3201N/A ergo_verbose0(ErgoMixedGCs,
3201N/A false_action_str,
3201N/A ergo_format_reason("candidate old regions not available"));
3201N/A return false;
3201N/A }
4461N/A
4461N/A // Is the amount of uncollected reclaimable space above G1HeapWastePercent?
3682N/A size_t reclaimable_bytes = cset_chooser->remaining_reclaimable_bytes();
4461N/A double reclaimable_perc = reclaimable_bytes_perc(reclaimable_bytes);
3635N/A double threshold = (double) G1HeapWastePercent;
4461N/A if (reclaimable_perc <= threshold) {
3201N/A ergo_verbose4(ErgoMixedGCs,
3201N/A false_action_str,
4461N/A ergo_format_reason("reclaimable percentage not over threshold")
3201N/A ergo_format_region("candidate old regions")
3201N/A ergo_format_byte_perc("reclaimable")
3201N/A ergo_format_perc("threshold"),
3682N/A cset_chooser->remaining_regions(),
4461N/A reclaimable_bytes,
4461N/A reclaimable_perc, threshold);
3201N/A return false;
3201N/A }
3201N/A
3201N/A ergo_verbose4(ErgoMixedGCs,
3201N/A true_action_str,
3201N/A ergo_format_reason("candidate old regions available")
3201N/A ergo_format_region("candidate old regions")
3201N/A ergo_format_byte_perc("reclaimable")
3201N/A ergo_format_perc("threshold"),
3682N/A cset_chooser->remaining_regions(),
4461N/A reclaimable_bytes,
4461N/A reclaimable_perc, threshold);
3201N/A return true;
3201N/A}
3201N/A
4461N/Auint G1CollectorPolicy::calc_min_old_cset_length() {
4461N/A // The min old CSet region bound is based on the maximum desired
4461N/A // number of mixed GCs after a cycle. I.e., even if some old regions
4461N/A // look expensive, we should add them to the CSet anyway to make
4461N/A // sure we go through the available old regions in no more than the
4461N/A // maximum desired number of mixed GCs.
4461N/A //
4461N/A // The calculation is based on the number of marked regions we added
4461N/A // to the CSet chooser in the first place, not how many remain, so
4461N/A // that the result is the same during all mixed GCs that follow a cycle.
4461N/A
4461N/A const size_t region_num = (size_t) _collectionSetChooser->length();
4461N/A const size_t gc_num = (size_t) MAX2(G1MixedGCCountTarget, (uintx) 1);
4461N/A size_t result = region_num / gc_num;
4461N/A // emulate ceiling
4461N/A if (result * gc_num < region_num) {
4461N/A result += 1;
4461N/A }
4461N/A return (uint) result;
4461N/A}
4461N/A
4461N/Auint G1CollectorPolicy::calc_max_old_cset_length() {
4461N/A // The max old CSet region bound is based on the threshold expressed
4461N/A // as a percentage of the heap size. I.e., it should bound the
4461N/A // number of old regions added to the CSet irrespective of how many
4461N/A // of them are available.
4461N/A
4461N/A G1CollectedHeap* g1h = G1CollectedHeap::heap();
4461N/A const size_t region_num = g1h->n_regions();
4461N/A const size_t perc = (size_t) G1OldCSetRegionThresholdPercent;
4461N/A size_t result = region_num * perc / 100;
4461N/A // emulate ceiling
4461N/A if (100 * result < region_num * perc) {
4461N/A result += 1;
4461N/A }
4461N/A return (uint) result;
4461N/A}
4461N/A
4362N/Avoid G1CollectorPolicy::finalize_cset(double target_pause_time_ms, EvacuationInfo& evacuation_info) {
3961N/A double young_start_time_sec = os::elapsedTime();
1394N/A
2748N/A YoungList* young_list = _g1->young_list();
3007N/A finalize_incremental_cset_building();
2748N/A
1576N/A guarantee(target_pause_time_ms > 0.0,
1576N/A err_msg("target_pause_time_ms = %1.6lf should be positive",
1576N/A target_pause_time_ms));
1576N/A guarantee(_collection_set == NULL, "Precondition");
342N/A
342N/A double base_time_ms = predict_base_elapsed_time_ms(_pending_cards);
342N/A double predicted_pause_time_ms = base_time_ms;
4461N/A double time_remaining_ms = MAX2(target_pause_time_ms - base_time_ms, 0.0);
342N/A
3961N/A ergo_verbose4(ErgoCSetConstruction | ErgoHigh,
2748N/A "start choosing CSet",
3961N/A ergo_format_size("_pending_cards")
2748N/A ergo_format_ms("predicted base time")
2748N/A ergo_format_ms("remaining time")
2748N/A ergo_format_ms("target pause time"),
3961N/A _pending_cards, base_time_ms, time_remaining_ms, target_pause_time_ms);
2748N/A
2986N/A _last_gc_was_young = gcs_are_young() ? true : false;
2986N/A
2986N/A if (_last_gc_was_young) {
3776N/A _trace_gen0_time_data.increment_young_collection_count();
2748N/A } else {
3776N/A _trace_gen0_time_data.increment_mixed_collection_count();
2748N/A }
2695N/A
2695N/A // The young list is laid with the survivor regions from the previous
2695N/A // pause are appended to the RHS of the young list, i.e.
2695N/A // [Newly Young Regions ++ Survivors from last pause].
2695N/A
3681N/A uint survivor_region_length = young_list->survivor_length();
3681N/A uint eden_region_length = young_list->length() - survivor_region_length;
2936N/A init_cset_region_lengths(eden_region_length, survivor_region_length);
3961N/A
3961N/A HeapRegion* hr = young_list->first_survivor_region();
2695N/A while (hr != NULL) {
2695N/A assert(hr->is_survivor(), "badly formed young list");
2695N/A hr->set_young();
2695N/A hr = hr->get_next_young_region();
2695N/A }
2695N/A
2748N/A // Clear the fields that point to the survivor list - they are all young now.
2748N/A young_list->clear_survivors();
2695N/A
2695N/A _collection_set = _inc_cset_head;
2695N/A _collection_set_bytes_used_before = _inc_cset_bytes_used_before;
4461N/A time_remaining_ms = MAX2(time_remaining_ms - _inc_cset_predicted_elapsed_time_ms, 0.0);
2695N/A predicted_pause_time_ms += _inc_cset_predicted_elapsed_time_ms;
2695N/A
2748N/A ergo_verbose3(ErgoCSetConstruction | ErgoHigh,
2748N/A "add young regions to CSet",
2748N/A ergo_format_region("eden")
2748N/A ergo_format_region("survivors")
2748N/A ergo_format_ms("predicted young region time"),
2936N/A eden_region_length, survivor_region_length,
2748N/A _inc_cset_predicted_elapsed_time_ms);
2748N/A
2695N/A // The number of recorded young regions is the incremental
2695N/A // collection set's current size
2695N/A set_recorded_rs_lengths(_inc_cset_recorded_rs_lengths);
2695N/A
2695N/A double young_end_time_sec = os::elapsedTime();
3978N/A phase_times()->record_young_cset_choice_time_ms((young_end_time_sec - young_start_time_sec) * 1000.0);
2695N/A
3961N/A // Set the start of the non-young choice time.
3961N/A double non_young_start_time_sec = young_end_time_sec;
2695N/A
2986N/A if (!gcs_are_young()) {
3201N/A CollectionSetChooser* cset_chooser = _collectionSetChooser;
3682N/A cset_chooser->verify();
4461N/A const uint min_old_cset_length = calc_min_old_cset_length();
4461N/A const uint max_old_cset_length = calc_max_old_cset_length();
3681N/A
3681N/A uint expensive_region_num = 0;
3201N/A bool check_time_remaining = adaptive_young_list_length();
3961N/A
3201N/A HeapRegion* hr = cset_chooser->peek();
3201N/A while (hr != NULL) {
3201N/A if (old_cset_region_length() >= max_old_cset_length) {
3201N/A // Added maximum number of old regions to the CSet.
3201N/A ergo_verbose2(ErgoCSetConstruction,
3201N/A "finish adding old regions to CSet",
3201N/A ergo_format_reason("old CSet region num reached max")
3201N/A ergo_format_region("old")
3201N/A ergo_format_region("max"),
3201N/A old_cset_region_length(), max_old_cset_length);
3201N/A break;
342N/A }
2748N/A
4461N/A
4461N/A // Stop adding regions if the remaining reclaimable space is
4461N/A // not above G1HeapWastePercent.
4461N/A size_t reclaimable_bytes = cset_chooser->remaining_reclaimable_bytes();
4461N/A double reclaimable_perc = reclaimable_bytes_perc(reclaimable_bytes);
4461N/A double threshold = (double) G1HeapWastePercent;
4461N/A if (reclaimable_perc <= threshold) {
4461N/A // We've added enough old regions that the amount of uncollected
4461N/A // reclaimable space is at or below the waste threshold. Stop
4461N/A // adding old regions to the CSet.
4461N/A ergo_verbose5(ErgoCSetConstruction,
4461N/A "finish adding old regions to CSet",
4461N/A ergo_format_reason("reclaimable percentage not over threshold")
4461N/A ergo_format_region("old")
4461N/A ergo_format_region("max")
4461N/A ergo_format_byte_perc("reclaimable")
4461N/A ergo_format_perc("threshold"),
4461N/A old_cset_region_length(),
4461N/A max_old_cset_length,
4461N/A reclaimable_bytes,
4461N/A reclaimable_perc, threshold);
4461N/A break;
4461N/A }
4461N/A
3961N/A double predicted_time_ms = predict_region_elapsed_time_ms(hr, gcs_are_young());
3201N/A if (check_time_remaining) {
3201N/A if (predicted_time_ms > time_remaining_ms) {
3201N/A // Too expensive for the current CSet.
3201N/A
3201N/A if (old_cset_region_length() >= min_old_cset_length) {
3201N/A // We have added the minimum number of old regions to the CSet,
3201N/A // we are done with this CSet.
3201N/A ergo_verbose4(ErgoCSetConstruction,
3201N/A "finish adding old regions to CSet",
3201N/A ergo_format_reason("predicted time is too high")
3201N/A ergo_format_ms("predicted time")
3201N/A ergo_format_ms("remaining time")
3201N/A ergo_format_region("old")
3201N/A ergo_format_region("min"),
3201N/A predicted_time_ms, time_remaining_ms,
3201N/A old_cset_region_length(), min_old_cset_length);
3201N/A break;
3201N/A }
3201N/A
3201N/A // We'll add it anyway given that we haven't reached the
3201N/A // minimum number of old regions.
3201N/A expensive_region_num += 1;
3201N/A }
2748N/A } else {
3201N/A if (old_cset_region_length() >= min_old_cset_length) {
3201N/A // In the non-auto-tuning case, we'll finish adding regions
3201N/A // to the CSet if we reach the minimum.
3201N/A ergo_verbose2(ErgoCSetConstruction,
3201N/A "finish adding old regions to CSet",
3201N/A ergo_format_reason("old CSet region num reached min")
3201N/A ergo_format_region("old")
3201N/A ergo_format_region("min"),
3201N/A old_cset_region_length(), min_old_cset_length);
3201N/A break;
2748N/A }
2748N/A }
3201N/A
3201N/A // We will add this region to the CSet.
4461N/A time_remaining_ms = MAX2(time_remaining_ms - predicted_time_ms, 0.0);
3201N/A predicted_pause_time_ms += predicted_time_ms;
3201N/A cset_chooser->remove_and_move_to_next(hr);
3201N/A _g1->old_set_remove(hr);
3201N/A add_old_region_to_cset(hr);
3201N/A
3201N/A hr = cset_chooser->peek();
3201N/A }
3201N/A if (hr == NULL) {
3201N/A ergo_verbose0(ErgoCSetConstruction,
3201N/A "finish adding old regions to CSet",
3201N/A ergo_format_reason("candidate old regions not available"));
2748N/A }
2748N/A
3201N/A if (expensive_region_num > 0) {
3201N/A // We print the information once here at the end, predicated on
3201N/A // whether we added any apparently expensive regions or not, to
3201N/A // avoid generating output per region.
3201N/A ergo_verbose4(ErgoCSetConstruction,
3201N/A "added expensive regions to CSet",
3201N/A ergo_format_reason("old CSet region num not reached min")
3201N/A ergo_format_region("old")
3201N/A ergo_format_region("expensive")
3201N/A ergo_format_region("min")
3201N/A ergo_format_ms("remaining time"),
3201N/A old_cset_region_length(),
3201N/A expensive_region_num,
3201N/A min_old_cset_length,
3201N/A time_remaining_ms);
3201N/A }
3201N/A
3682N/A cset_chooser->verify();
342N/A }
342N/A
1394N/A stop_incremental_cset_building();
1394N/A
2748N/A ergo_verbose5(ErgoCSetConstruction,
2748N/A "finish choosing CSet",
2748N/A ergo_format_region("eden")
2748N/A ergo_format_region("survivors")
2748N/A ergo_format_region("old")
2748N/A ergo_format_ms("predicted pause time")
2748N/A ergo_format_ms("target pause time"),
2936N/A eden_region_length, survivor_region_length,
2936N/A old_cset_region_length(),
2748N/A predicted_pause_time_ms, target_pause_time_ms);
2748N/A
342N/A double non_young_end_time_sec = os::elapsedTime();
3978N/A phase_times()->record_non_young_cset_choice_time_ms((non_young_end_time_sec - non_young_start_time_sec) * 1000.0);
4362N/A evacuation_info.set_collectionset_regions(cset_region_length());
342N/A}
3776N/A
3776N/Avoid TraceGen0TimeData::record_start_collection(double time_to_stop_the_world_ms) {
3776N/A if(TraceGen0Time) {
3776N/A _all_stop_world_times_ms.add(time_to_stop_the_world_ms);
3776N/A }
3776N/A}
3776N/A
3776N/Avoid TraceGen0TimeData::record_yield_time(double yield_time_ms) {
3776N/A if(TraceGen0Time) {
3776N/A _all_yield_times_ms.add(yield_time_ms);
3776N/A }
3776N/A}
3776N/A
3885N/Avoid TraceGen0TimeData::record_end_collection(double pause_time_ms, G1GCPhaseTimes* phase_times) {
3776N/A if(TraceGen0Time) {
3885N/A _total.add(pause_time_ms);
3885N/A _other.add(pause_time_ms - phase_times->accounted_time_ms());
3978N/A _root_region_scan_wait.add(phase_times->root_region_scan_wait_time_ms());
3978N/A _parallel.add(phase_times->cur_collection_par_time_ms());
3978N/A _ext_root_scan.add(phase_times->average_last_ext_root_scan_time());
3978N/A _satb_filtering.add(phase_times->average_last_satb_filtering_times_ms());
3978N/A _update_rs.add(phase_times->average_last_update_rs_time());
3978N/A _scan_rs.add(phase_times->average_last_scan_rs_time());
3978N/A _obj_copy.add(phase_times->average_last_obj_copy_time());
3978N/A _termination.add(phase_times->average_last_termination_time());
3885N/A
3978N/A double parallel_known_time = phase_times->average_last_ext_root_scan_time() +
3978N/A phase_times->average_last_satb_filtering_times_ms() +
3978N/A phase_times->average_last_update_rs_time() +
3978N/A phase_times->average_last_scan_rs_time() +
3978N/A phase_times->average_last_obj_copy_time() +
3978N/A + phase_times->average_last_termination_time();
3885N/A
3978N/A double parallel_other_time = phase_times->cur_collection_par_time_ms() - parallel_known_time;
3885N/A _parallel_other.add(parallel_other_time);
3978N/A _clear_ct.add(phase_times->cur_clear_ct_time_ms());
3776N/A }
3776N/A}
3776N/A
3776N/Avoid TraceGen0TimeData::increment_young_collection_count() {
3776N/A if(TraceGen0Time) {
3776N/A ++_young_pause_num;
3776N/A }
3776N/A}
3776N/A
3776N/Avoid TraceGen0TimeData::increment_mixed_collection_count() {
3776N/A if(TraceGen0Time) {
3776N/A ++_mixed_pause_num;
3776N/A }
3776N/A}
3776N/A
3885N/Avoid TraceGen0TimeData::print_summary(const char* str,
3776N/A const NumberSeq* seq) const {
3776N/A double sum = seq->sum();
3885N/A gclog_or_tty->print_cr("%-27s = %8.2lf s (avg = %8.2lf ms)",
3776N/A str, sum / 1000.0, seq->avg());
3776N/A}
3776N/A
3885N/Avoid TraceGen0TimeData::print_summary_sd(const char* str,
3776N/A const NumberSeq* seq) const {
3885N/A print_summary(str, seq);
3885N/A gclog_or_tty->print_cr("%+45s = %5d, std dev = %8.2lf ms, max = %8.2lf ms)",
3885N/A "(num", seq->num(), seq->sd(), seq->maximum());
3776N/A}
3776N/A
3776N/Avoid TraceGen0TimeData::print() const {
3776N/A if (!TraceGen0Time) {
3776N/A return;
3776N/A }
3776N/A
3776N/A gclog_or_tty->print_cr("ALL PAUSES");
3885N/A print_summary_sd(" Total", &_total);
3776N/A gclog_or_tty->print_cr("");
3776N/A gclog_or_tty->print_cr("");
3776N/A gclog_or_tty->print_cr(" Young GC Pauses: %8d", _young_pause_num);
3776N/A gclog_or_tty->print_cr(" Mixed GC Pauses: %8d", _mixed_pause_num);
3776N/A gclog_or_tty->print_cr("");
3776N/A
3776N/A gclog_or_tty->print_cr("EVACUATION PAUSES");
3776N/A
3776N/A if (_young_pause_num == 0 && _mixed_pause_num == 0) {
3776N/A gclog_or_tty->print_cr("none");
3776N/A } else {
3885N/A print_summary_sd(" Evacuation Pauses", &_total);
3885N/A print_summary(" Root Region Scan Wait", &_root_region_scan_wait);
3885N/A print_summary(" Parallel Time", &_parallel);
3885N/A print_summary(" Ext Root Scanning", &_ext_root_scan);
3885N/A print_summary(" SATB Filtering", &_satb_filtering);
3885N/A print_summary(" Update RS", &_update_rs);
3885N/A print_summary(" Scan RS", &_scan_rs);
3885N/A print_summary(" Object Copy", &_obj_copy);
3885N/A print_summary(" Termination", &_termination);
3885N/A print_summary(" Parallel Other", &_parallel_other);
3885N/A print_summary(" Clear CT", &_clear_ct);
3885N/A print_summary(" Other", &_other);
3776N/A }
3776N/A gclog_or_tty->print_cr("");
3776N/A
3776N/A gclog_or_tty->print_cr("MISC");
3885N/A print_summary_sd(" Stop World", &_all_stop_world_times_ms);
3885N/A print_summary_sd(" Yields", &_all_yield_times_ms);
3776N/A}
3776N/A
3776N/Avoid TraceGen1TimeData::record_full_collection(double full_gc_time_ms) {
3776N/A if (TraceGen1Time) {
3776N/A _all_full_gc_times.add(full_gc_time_ms);
3776N/A }
3776N/A}
3776N/A
3776N/Avoid TraceGen1TimeData::print() const {
3776N/A if (!TraceGen1Time) {
3776N/A return;
3776N/A }
3776N/A
3776N/A if (_all_full_gc_times.num() > 0) {
3776N/A gclog_or_tty->print("\n%4d full_gcs: total time = %8.2f s",
3776N/A _all_full_gc_times.num(),
3776N/A _all_full_gc_times.sum() / 1000.0);
3776N/A gclog_or_tty->print_cr(" (avg = %8.2fms).", _all_full_gc_times.avg());
3776N/A gclog_or_tty->print_cr(" [std. dev = %8.2f ms, max = %8.2f ms]",
3776N/A _all_full_gc_times.sd(),
3776N/A _all_full_gc_times.maximum());
3776N/A }
3776N/A}