g1CollectorPolicy.cpp revision 1356
342N/A/*
579N/A * Copyright 2001-2009 Sun Microsystems, Inc. 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 *
342N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
342N/A * CA 95054 USA or visit www.sun.com if you need additional information or
342N/A * have any questions.
342N/A *
342N/A */
342N/A
342N/A#include "incls/_precompiled.incl"
342N/A#include "incls/_g1CollectorPolicy.cpp.incl"
342N/A
342N/A#define PREDICTIONS_VERBOSE 0
342N/A
342N/A// <NEW PREDICTION>
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/Astatic double cost_per_scan_only_region_ms_defaults[] = {
342N/A 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
342N/A};
342N/A
342N/A// all the same
342N/Astatic double fully_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/A// </NEW PREDICTION>
342N/A
342N/AG1CollectorPolicy::G1CollectorPolicy() :
342N/A _parallel_gc_threads((ParallelGCThreads > 0) ? ParallelGCThreads : 1),
342N/A _n_pauses(0),
342N/A _recent_CH_strong_roots_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A _recent_G1_strong_roots_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A _recent_evac_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A _recent_pause_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A _recent_rs_sizes(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A _recent_gc_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A _all_pause_times_ms(new NumberSeq()),
342N/A _stop_world_start(0.0),
342N/A _all_stop_world_times_ms(new NumberSeq()),
342N/A _all_yield_times_ms(new NumberSeq()),
342N/A
342N/A _all_mod_union_times_ms(new NumberSeq()),
342N/A
677N/A _summary(new Summary()),
677N/A _abandoned_summary(new AbandonedSummary()),
342N/A
890N/A#ifndef PRODUCT
342N/A _cur_clear_ct_time_ms(0.0),
890N/A _min_clear_cc_time_ms(-1.0),
890N/A _max_clear_cc_time_ms(-1.0),
890N/A _cur_clear_cc_time_ms(0.0),
890N/A _cum_clear_cc_time_ms(0.0),
890N/A _num_cc_clears(0L),
890N/A#endif
342N/A
342N/A _region_num_young(0),
342N/A _region_num_tenured(0),
342N/A _prev_region_num_young(0),
342N/A _prev_region_num_tenured(0),
342N/A
342N/A _aux_num(10),
342N/A _all_aux_times_ms(new NumberSeq[_aux_num]),
342N/A _cur_aux_start_times_ms(new double[_aux_num]),
342N/A _cur_aux_times_ms(new double[_aux_num]),
342N/A _cur_aux_times_set(new bool[_aux_num]),
342N/A
342N/A _concurrent_mark_init_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A _concurrent_mark_remark_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A _concurrent_mark_cleanup_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A
342N/A // <NEW PREDICTION>
342N/A
342N/A _alloc_rate_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _prev_collection_pause_end_ms(0.0),
342N/A _pending_card_diff_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _rs_length_diff_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _cost_per_card_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _cost_per_scan_only_region_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _fully_young_cards_per_entry_ratio_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _partially_young_cards_per_entry_ratio_seq(
342N/A new TruncatedSeq(TruncatedSeqLength)),
342N/A _cost_per_entry_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _partially_young_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 _cost_per_scan_only_region_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 _scanned_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
342N/A // </NEW PREDICTION>
342N/A
342N/A _in_young_gc_mode(false),
342N/A _full_young_gcs(true),
342N/A _full_young_pause_num(0),
342N/A _partial_young_pause_num(0),
342N/A
342N/A _during_marking(false),
342N/A _in_marking_window(false),
342N/A _in_marking_window_im(false),
342N/A
342N/A _known_garbage_ratio(0.0),
342N/A _known_garbage_bytes(0),
342N/A
342N/A _young_gc_eff_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A _target_pause_time_ms(-1.0),
342N/A
342N/A _recent_prev_end_times_for_all_gcs_sec(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A
342N/A _recent_CS_bytes_used_before(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A _recent_CS_bytes_surviving(new TruncatedSeq(NumPrevPausesForHeuristics)),
342N/A
342N/A _recent_avg_pause_time_ratio(0.0),
342N/A _num_markings(0),
342N/A _n_marks(0),
342N/A _n_pauses_at_mark_end(0),
342N/A
342N/A _all_full_gc_times_ms(new NumberSeq()),
342N/A
342N/A // G1PausesBtwnConcMark defaults to -1
342N/A // so the hack is to do the cast QQQ FIXME
342N/A _pauses_btwn_concurrent_mark((size_t)G1PausesBtwnConcMark),
342N/A _n_marks_since_last_pause(0),
342N/A _conc_mark_initiated(false),
342N/A _should_initiate_conc_mark(false),
342N/A _should_revert_to_full_young_gcs(false),
342N/A _last_full_young_gc(false),
342N/A
342N/A _prev_collection_pause_used_at_end_bytes(0),
342N/A
342N/A _collection_set(NULL),
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
1356N/A _gc_overhead_perc(0.0)
545N/A
342N/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
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
342N/A _par_last_ext_root_scan_times_ms = new double[_parallel_gc_threads];
342N/A _par_last_mark_stack_scan_times_ms = new double[_parallel_gc_threads];
342N/A _par_last_scan_only_times_ms = new double[_parallel_gc_threads];
342N/A _par_last_scan_only_regions_scanned = new double[_parallel_gc_threads];
342N/A
342N/A _par_last_update_rs_start_times_ms = new double[_parallel_gc_threads];
342N/A _par_last_update_rs_times_ms = new double[_parallel_gc_threads];
342N/A _par_last_update_rs_processed_buffers = new double[_parallel_gc_threads];
342N/A
342N/A _par_last_scan_rs_start_times_ms = new double[_parallel_gc_threads];
342N/A _par_last_scan_rs_times_ms = new double[_parallel_gc_threads];
342N/A _par_last_scan_new_refs_times_ms = new double[_parallel_gc_threads];
342N/A
342N/A _par_last_obj_copy_times_ms = new double[_parallel_gc_threads];
342N/A
342N/A _par_last_termination_times_ms = new double[_parallel_gc_threads];
342N/A
342N/A // start conservatively
751N/A _expensive_region_limit_ms = 0.5 * (double) MaxGCPauseMillis;
342N/A
342N/A // <NEW PREDICTION>
342N/A
342N/A int index;
342N/A if (ParallelGCThreads == 0)
342N/A index = 0;
342N/A else if (ParallelGCThreads > 8)
342N/A index = 7;
342N/A else
342N/A index = ParallelGCThreads - 1;
342N/A
342N/A _pending_card_diff_seq->add(0.0);
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]);
342N/A _cost_per_scan_only_region_ms_seq->add(
342N/A cost_per_scan_only_region_ms_defaults[index]);
342N/A _fully_young_cards_per_entry_ratio_seq->add(
342N/A fully_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
342N/A // </NEW PREDICTION>
342N/A
751N/A double time_slice = (double) GCPauseIntervalMillis / 1000.0;
751N/A double max_gc_time = (double) MaxGCPauseMillis / 1000.0;
342N/A guarantee(max_gc_time < time_slice,
342N/A "Max GC time should not be greater than the time slice");
342N/A _mmu_tracker = new G1MMUTrackerQueue(time_slice, max_gc_time);
751N/A _sigma = (double) G1ConfidencePercent / 100.0;
342N/A
342N/A // start conservatively (around 50ms is about right)
342N/A _concurrent_mark_init_times_ms->add(0.05);
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;
342N/A
1282N/A // if G1FixedSurvivorSpaceSize is 0 which means the size is not
1282N/A // fixed, then _max_survivor_regions will be calculated at
1282N/A // calculate_young_list_target_config during initialization
1282N/A _max_survivor_regions = G1FixedSurvivorSpaceSize / HeapRegion::GrainBytes;
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
342N/A initialize_all();
342N/A}
342N/A
342N/A// Increment "i", mod "len"
342N/Astatic void inc_mod(int& i, int len) {
342N/A i++; if (i == len) i = 0;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::initialize_flags() {
342N/A set_min_alignment(HeapRegion::GrainBytes);
342N/A set_max_alignment(GenRemSet::max_alignment_constraint(rem_set_name()));
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
1285N/A// The easiest way to deal with the parsing of the NewSize /
1285N/A// MaxNewSize / etc. parameteres is to re-use the code in the
1285N/A// TwoGenerationCollectorPolicy class. This is similar to what
1285N/A// ParallelScavenge does with its GenerationSizer class (see
1285N/A// ParallelScavengeHeap::initialize()). We might change this in the
1285N/A// future, but it's a good start.
1285N/Aclass G1YoungGenSizer : public TwoGenerationCollectorPolicy {
1285N/A size_t size_to_region_num(size_t byte_size) {
1285N/A return MAX2((size_t) 1, byte_size / HeapRegion::GrainBytes);
1285N/A }
1285N/A
1285N/Apublic:
1285N/A G1YoungGenSizer() {
1285N/A initialize_flags();
1285N/A initialize_size_info();
1285N/A }
1285N/A
1285N/A size_t min_young_region_num() {
1285N/A return size_to_region_num(_min_gen0_size);
1285N/A }
1285N/A size_t initial_young_region_num() {
1285N/A return size_to_region_num(_initial_gen0_size);
1285N/A }
1285N/A size_t max_young_region_num() {
1285N/A return size_to_region_num(_max_gen0_size);
1285N/A }
1285N/A};
1285N/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
342N/A if (G1Gen) {
342N/A _in_young_gc_mode = true;
342N/A
1285N/A G1YoungGenSizer sizer;
1285N/A size_t initial_region_num = sizer.initial_young_region_num();
1285N/A
1285N/A if (UseAdaptiveSizePolicy) {
342N/A set_adaptive_young_list_length(true);
342N/A _young_list_fixed_length = 0;
342N/A } else {
342N/A set_adaptive_young_list_length(false);
1285N/A _young_list_fixed_length = initial_region_num;
342N/A }
342N/A _free_regions_at_end_of_collection = _g1->free_regions();
342N/A _scan_only_regions_at_end_of_collection = 0;
342N/A calculate_young_list_min_length();
342N/A guarantee( _young_list_min_length == 0, "invariant, not enough info" );
342N/A calculate_young_list_target_config();
342N/A } else {
342N/A _young_list_fixed_length = 0;
342N/A _in_young_gc_mode = false;
342N/A }
342N/A}
342N/A
545N/A// Create the jstat counters for the policy.
545N/Avoid G1CollectorPolicy::initialize_gc_policy_counters()
545N/A{
545N/A _gc_policy_counters = new GCPolicyCounters("GarbageFirst", 1, 2 + G1Gen);
545N/A}
545N/A
342N/Avoid G1CollectorPolicy::calculate_young_list_min_length() {
342N/A _young_list_min_length = 0;
342N/A
342N/A if (!adaptive_young_list_length())
342N/A return;
342N/A
342N/A if (_alloc_rate_ms_seq->num() > 3) {
342N/A double now_sec = os::elapsedTime();
342N/A double when_ms = _mmu_tracker->when_max_gc_sec(now_sec) * 1000.0;
342N/A double alloc_rate_ms = predict_alloc_rate_ms();
342N/A int min_regions = (int) ceil(alloc_rate_ms * when_ms);
342N/A int current_region_num = (int) _g1->young_list_length();
342N/A _young_list_min_length = min_regions + current_region_num;
342N/A }
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::calculate_young_list_target_config() {
342N/A if (adaptive_young_list_length()) {
342N/A size_t rs_lengths = (size_t) get_new_prediction(_rs_lengths_seq);
342N/A calculate_young_list_target_config(rs_lengths);
342N/A } else {
342N/A if (full_young_gcs())
342N/A _young_list_target_length = _young_list_fixed_length;
342N/A else
342N/A _young_list_target_length = _young_list_fixed_length / 2;
342N/A _young_list_target_length = MAX2(_young_list_target_length, (size_t)1);
342N/A size_t so_length = calculate_optimal_so_length(_young_list_target_length);
342N/A guarantee( so_length < _young_list_target_length, "invariant" );
342N/A _young_list_so_prefix_length = so_length;
342N/A }
545N/A calculate_survivors_policy();
342N/A}
342N/A
342N/A// This method calculate the optimal scan-only set for a fixed young
342N/A// gen size. I couldn't work out how to reuse the more elaborate one,
342N/A// i.e. calculate_young_list_target_config(rs_length), as the loops are
342N/A// fundamentally different (the other one finds a config for different
342N/A// S-O lengths, whereas here we need to do the opposite).
342N/Asize_t G1CollectorPolicy::calculate_optimal_so_length(
342N/A size_t young_list_length) {
342N/A if (!G1UseScanOnlyPrefix)
342N/A return 0;
342N/A
342N/A if (_all_pause_times_ms->num() < 3) {
342N/A // we won't use a scan-only set at the beginning to allow the rest
342N/A // of the predictors to warm up
342N/A return 0;
342N/A }
342N/A
342N/A if (_cost_per_scan_only_region_ms_seq->num() < 3) {
342N/A // then, we'll only set the S-O set to 1 for a little bit of time,
342N/A // to get enough information on the scanning cost
342N/A return 1;
342N/A }
342N/A
342N/A size_t pending_cards = (size_t) get_new_prediction(_pending_cards_seq);
342N/A size_t rs_lengths = (size_t) get_new_prediction(_rs_lengths_seq);
342N/A size_t adj_rs_lengths = rs_lengths + predict_rs_length_diff();
342N/A size_t scanned_cards;
342N/A if (full_young_gcs())
342N/A scanned_cards = predict_young_card_num(adj_rs_lengths);
342N/A else
342N/A scanned_cards = predict_non_young_card_num(adj_rs_lengths);
342N/A double base_time_ms = predict_base_elapsed_time_ms(pending_cards,
342N/A scanned_cards);
342N/A
342N/A size_t so_length = 0;
342N/A double max_gc_eff = 0.0;
342N/A for (size_t i = 0; i < young_list_length; ++i) {
342N/A double gc_eff = 0.0;
342N/A double pause_time_ms = 0.0;
342N/A predict_gc_eff(young_list_length, i, base_time_ms,
342N/A &gc_eff, &pause_time_ms);
342N/A if (gc_eff > max_gc_eff) {
342N/A max_gc_eff = gc_eff;
342N/A so_length = i;
342N/A }
342N/A }
342N/A
342N/A // set it to 95% of the optimal to make sure we sample the "area"
342N/A // around the optimal length to get up-to-date survival rate data
342N/A return so_length * 950 / 1000;
342N/A}
342N/A
342N/A// This is a really cool piece of code! It finds the best
342N/A// target configuration (young length / scan-only prefix length) so
342N/A// that GC efficiency is maximized and that we also meet a pause
342N/A// time. It's a triple nested loop. These loops are explained below
342N/A// from the inside-out :-)
342N/A//
342N/A// (a) The innermost loop will try to find the optimal young length
342N/A// for a fixed S-O length. It uses a binary search to speed up the
342N/A// process. We assume that, for a fixed S-O length, as we add more
342N/A// young regions to the CSet, the GC efficiency will only go up (I'll
342N/A// skip the proof). So, using a binary search to optimize this process
342N/A// makes perfect sense.
342N/A//
342N/A// (b) The middle loop will fix the S-O length before calling the
342N/A// innermost one. It will vary it between two parameters, increasing
342N/A// it by a given increment.
342N/A//
342N/A// (c) The outermost loop will call the middle loop three times.
342N/A// (1) The first time it will explore all possible S-O length values
342N/A// from 0 to as large as it can get, using a coarse increment (to
342N/A// quickly "home in" to where the optimal seems to be).
342N/A// (2) The second time it will explore the values around the optimal
342N/A// that was found by the first iteration using a fine increment.
342N/A// (3) Once the optimal config has been determined by the second
342N/A// iteration, we'll redo the calculation, but setting the S-O length
342N/A// to 95% of the optimal to make sure we sample the "area"
342N/A// around the optimal length to get up-to-date survival rate data
342N/A//
342N/A// Termination conditions for the iterations are several: the pause
342N/A// time is over the limit, we do not have enough to-space, etc.
342N/A
342N/Avoid G1CollectorPolicy::calculate_young_list_target_config(size_t rs_lengths) {
342N/A guarantee( adaptive_young_list_length(), "pre-condition" );
342N/A
342N/A double start_time_sec = os::elapsedTime();
1282N/A size_t min_reserve_perc = MAX2((size_t)2, (size_t)G1ReservePercent);
342N/A min_reserve_perc = MIN2((size_t) 50, min_reserve_perc);
342N/A size_t reserve_regions =
342N/A (size_t) ((double) min_reserve_perc * (double) _g1->n_regions() / 100.0);
342N/A
342N/A if (full_young_gcs() && _free_regions_at_end_of_collection > 0) {
342N/A // we are in fully-young mode and there are free regions in the heap
342N/A
545N/A double survivor_regions_evac_time =
545N/A predict_survivor_regions_evac_time();
545N/A
342N/A size_t min_so_length = 0;
342N/A size_t max_so_length = 0;
342N/A
342N/A if (G1UseScanOnlyPrefix) {
342N/A if (_all_pause_times_ms->num() < 3) {
342N/A // we won't use a scan-only set at the beginning to allow the rest
342N/A // of the predictors to warm up
342N/A min_so_length = 0;
342N/A max_so_length = 0;
342N/A } else if (_cost_per_scan_only_region_ms_seq->num() < 3) {
342N/A // then, we'll only set the S-O set to 1 for a little bit of time,
342N/A // to get enough information on the scanning cost
342N/A min_so_length = 1;
342N/A max_so_length = 1;
342N/A } else if (_in_marking_window || _last_full_young_gc) {
342N/A // no S-O prefix during a marking phase either, as at the end
342N/A // of the marking phase we'll have to use a very small young
342N/A // length target to fill up the rest of the CSet with
342N/A // non-young regions and, if we have lots of scan-only regions
342N/A // left-over, we will not be able to add any more non-young
342N/A // regions.
342N/A min_so_length = 0;
342N/A max_so_length = 0;
342N/A } else {
342N/A // this is the common case; we'll never reach the maximum, we
342N/A // one of the end conditions will fire well before that
342N/A // (hopefully!)
342N/A min_so_length = 0;
342N/A max_so_length = _free_regions_at_end_of_collection - 1;
342N/A }
342N/A } else {
342N/A // no S-O prefix, as the switch is not set, but we still need to
342N/A // do one iteration to calculate the best young target that
342N/A // meets the pause time; this way we reuse the same code instead
342N/A // of replicating it
342N/A min_so_length = 0;
342N/A max_so_length = 0;
342N/A }
342N/A
342N/A double target_pause_time_ms = _mmu_tracker->max_gc_time() * 1000.0;
342N/A size_t pending_cards = (size_t) get_new_prediction(_pending_cards_seq);
342N/A size_t adj_rs_lengths = rs_lengths + predict_rs_length_diff();
342N/A size_t scanned_cards;
342N/A if (full_young_gcs())
342N/A scanned_cards = predict_young_card_num(adj_rs_lengths);
342N/A else
342N/A scanned_cards = predict_non_young_card_num(adj_rs_lengths);
342N/A // calculate this once, so that we don't have to recalculate it in
342N/A // the innermost loop
545N/A double base_time_ms = predict_base_elapsed_time_ms(pending_cards, scanned_cards)
545N/A + survivor_regions_evac_time;
342N/A // the result
342N/A size_t final_young_length = 0;
342N/A size_t final_so_length = 0;
342N/A double final_gc_eff = 0.0;
342N/A // we'll also keep track of how many times we go into the inner loop
342N/A // this is for profiling reasons
342N/A size_t calculations = 0;
342N/A
342N/A // this determines which of the three iterations the outer loop is in
342N/A typedef enum {
342N/A pass_type_coarse,
342N/A pass_type_fine,
342N/A pass_type_final
342N/A } pass_type_t;
342N/A
342N/A // range of the outer loop's iteration
342N/A size_t from_so_length = min_so_length;
342N/A size_t to_so_length = max_so_length;
342N/A guarantee( from_so_length <= to_so_length, "invariant" );
342N/A
342N/A // this will keep the S-O length that's found by the second
342N/A // iteration of the outer loop; we'll keep it just in case the third
342N/A // iteration fails to find something
342N/A size_t fine_so_length = 0;
342N/A
342N/A // the increment step for the coarse (first) iteration
342N/A size_t so_coarse_increments = 5;
342N/A
342N/A // the common case, we'll start with the coarse iteration
342N/A pass_type_t pass = pass_type_coarse;
342N/A size_t so_length_incr = so_coarse_increments;
342N/A
342N/A if (from_so_length == to_so_length) {
342N/A // not point in doing the coarse iteration, we'll go directly into
342N/A // the fine one (we essentially trying to find the optimal young
342N/A // length for a fixed S-O length).
342N/A so_length_incr = 1;
342N/A pass = pass_type_final;
342N/A } else if (to_so_length - from_so_length < 3 * so_coarse_increments) {
342N/A // again, the range is too short so no point in foind the coarse
342N/A // iteration either
342N/A so_length_incr = 1;
342N/A pass = pass_type_fine;
342N/A }
342N/A
342N/A bool done = false;
342N/A // this is the outermost loop
342N/A while (!done) {
545N/A#ifdef TRACE_CALC_YOUNG_CONFIG
342N/A // leave this in for debugging, just in case
342N/A gclog_or_tty->print_cr("searching between " SIZE_FORMAT " and " SIZE_FORMAT
342N/A ", incr " SIZE_FORMAT ", pass %s",
342N/A from_so_length, to_so_length, so_length_incr,
342N/A (pass == pass_type_coarse) ? "coarse" :
342N/A (pass == pass_type_fine) ? "fine" : "final");
545N/A#endif // TRACE_CALC_YOUNG_CONFIG
342N/A
342N/A size_t so_length = from_so_length;
342N/A size_t init_free_regions =
342N/A MAX2((size_t)0,
342N/A _free_regions_at_end_of_collection +
342N/A _scan_only_regions_at_end_of_collection - reserve_regions);
342N/A
342N/A // this determines whether a configuration was found
342N/A bool gc_eff_set = false;
342N/A // this is the middle loop
342N/A while (so_length <= to_so_length) {
342N/A // base time, which excludes region-related time; again we
342N/A // calculate it once to avoid recalculating it in the
342N/A // innermost loop
342N/A double base_time_with_so_ms =
342N/A base_time_ms + predict_scan_only_time_ms(so_length);
342N/A // it's already over the pause target, go around
342N/A if (base_time_with_so_ms > target_pause_time_ms)
342N/A break;
342N/A
342N/A size_t starting_young_length = so_length+1;
342N/A
342N/A // we make sure that the short young length that makes sense
342N/A // (one more than the S-O length) is feasible
342N/A size_t min_young_length = starting_young_length;
342N/A double min_gc_eff;
342N/A bool min_ok;
342N/A ++calculations;
342N/A min_ok = predict_gc_eff(min_young_length, so_length,
342N/A base_time_with_so_ms,
342N/A init_free_regions, target_pause_time_ms,
342N/A &min_gc_eff);
342N/A
342N/A if (min_ok) {
342N/A // the shortest young length is indeed feasible; we'll know
342N/A // set up the max young length and we'll do a binary search
342N/A // between min_young_length and max_young_length
342N/A size_t max_young_length = _free_regions_at_end_of_collection - 1;
342N/A double max_gc_eff = 0.0;
342N/A bool max_ok = false;
342N/A
342N/A // the innermost loop! (finally!)
342N/A while (max_young_length > min_young_length) {
342N/A // we'll make sure that min_young_length is always at a
342N/A // feasible config
342N/A guarantee( min_ok, "invariant" );
342N/A
342N/A ++calculations;
342N/A max_ok = predict_gc_eff(max_young_length, so_length,
342N/A base_time_with_so_ms,
342N/A init_free_regions, target_pause_time_ms,
342N/A &max_gc_eff);
342N/A
342N/A size_t diff = (max_young_length - min_young_length) / 2;
342N/A if (max_ok) {
342N/A min_young_length = max_young_length;
342N/A min_gc_eff = max_gc_eff;
342N/A min_ok = true;
342N/A }
342N/A max_young_length = min_young_length + diff;
342N/A }
342N/A
342N/A // the innermost loop found a config
342N/A guarantee( min_ok, "invariant" );
342N/A if (min_gc_eff > final_gc_eff) {
342N/A // it's the best config so far, so we'll keep it
342N/A final_gc_eff = min_gc_eff;
342N/A final_young_length = min_young_length;
342N/A final_so_length = so_length;
342N/A gc_eff_set = true;
342N/A }
342N/A }
342N/A
342N/A // incremental the fixed S-O length and go around
342N/A so_length += so_length_incr;
342N/A }
342N/A
342N/A // this is the end of the outermost loop and we need to decide
342N/A // what to do during the next iteration
342N/A if (pass == pass_type_coarse) {
342N/A // we just did the coarse pass (first iteration)
342N/A
342N/A if (!gc_eff_set)
342N/A // we didn't find a feasible config so we'll just bail out; of
342N/A // course, it might be the case that we missed it; but I'd say
342N/A // it's a bit unlikely
342N/A done = true;
342N/A else {
342N/A // We did find a feasible config with optimal GC eff during
342N/A // the first pass. So the second pass we'll only consider the
342N/A // S-O lengths around that config with a fine increment.
342N/A
342N/A guarantee( so_length_incr == so_coarse_increments, "invariant" );
342N/A guarantee( final_so_length >= min_so_length, "invariant" );
342N/A
545N/A#ifdef TRACE_CALC_YOUNG_CONFIG
342N/A // leave this in for debugging, just in case
342N/A gclog_or_tty->print_cr(" coarse pass: SO length " SIZE_FORMAT,
342N/A final_so_length);
545N/A#endif // TRACE_CALC_YOUNG_CONFIG
342N/A
342N/A from_so_length =
342N/A (final_so_length - min_so_length > so_coarse_increments) ?
342N/A final_so_length - so_coarse_increments + 1 : min_so_length;
342N/A to_so_length =
342N/A (max_so_length - final_so_length > so_coarse_increments) ?
342N/A final_so_length + so_coarse_increments - 1 : max_so_length;
342N/A
342N/A pass = pass_type_fine;
342N/A so_length_incr = 1;
342N/A }
342N/A } else if (pass == pass_type_fine) {
342N/A // we just finished the second pass
342N/A
342N/A if (!gc_eff_set) {
342N/A // we didn't find a feasible config (yes, it's possible;
342N/A // notice that, sometimes, we go directly into the fine
342N/A // iteration and skip the coarse one) so we bail out
342N/A done = true;
342N/A } else {
342N/A // We did find a feasible config with optimal GC eff
342N/A guarantee( so_length_incr == 1, "invariant" );
342N/A
342N/A if (final_so_length == 0) {
342N/A // The config is of an empty S-O set, so we'll just bail out
342N/A done = true;
342N/A } else {
342N/A // we'll go around once more, setting the S-O length to 95%
342N/A // of the optimal
342N/A size_t new_so_length = 950 * final_so_length / 1000;
342N/A
545N/A#ifdef TRACE_CALC_YOUNG_CONFIG
342N/A // leave this in for debugging, just in case
342N/A gclog_or_tty->print_cr(" fine pass: SO length " SIZE_FORMAT
342N/A ", setting it to " SIZE_FORMAT,
342N/A final_so_length, new_so_length);
545N/A#endif // TRACE_CALC_YOUNG_CONFIG
342N/A
342N/A from_so_length = new_so_length;
342N/A to_so_length = new_so_length;
342N/A fine_so_length = final_so_length;
342N/A
342N/A pass = pass_type_final;
342N/A }
342N/A }
342N/A } else if (pass == pass_type_final) {
342N/A // we just finished the final (third) pass
342N/A
342N/A if (!gc_eff_set)
342N/A // we didn't find a feasible config, so we'll just use the one
342N/A // we found during the second pass, which we saved
342N/A final_so_length = fine_so_length;
342N/A
342N/A // and we're done!
342N/A done = true;
342N/A } else {
342N/A guarantee( false, "should never reach here" );
342N/A }
342N/A
342N/A // we now go around the outermost loop
342N/A }
342N/A
342N/A // we should have at least one region in the target young length
545N/A _young_list_target_length =
545N/A MAX2((size_t) 1, final_young_length + _recorded_survivor_regions);
342N/A if (final_so_length >= final_young_length)
342N/A // and we need to ensure that the S-O length is not greater than
342N/A // the target young length (this is being a bit careful)
342N/A final_so_length = 0;
342N/A _young_list_so_prefix_length = final_so_length;
342N/A guarantee( !_in_marking_window || !_last_full_young_gc ||
342N/A _young_list_so_prefix_length == 0, "invariant" );
342N/A
342N/A // let's keep an eye of how long we spend on this calculation
342N/A // right now, I assume that we'll print it when we need it; we
342N/A // should really adde it to the breakdown of a pause
342N/A double end_time_sec = os::elapsedTime();
342N/A double elapsed_time_ms = (end_time_sec - start_time_sec) * 1000.0;
342N/A
545N/A#ifdef TRACE_CALC_YOUNG_CONFIG
342N/A // leave this in for debugging, just in case
342N/A gclog_or_tty->print_cr("target = %1.1lf ms, young = " SIZE_FORMAT
342N/A ", SO = " SIZE_FORMAT ", "
342N/A "elapsed %1.2lf ms, calcs: " SIZE_FORMAT " (%s%s) "
342N/A SIZE_FORMAT SIZE_FORMAT,
342N/A target_pause_time_ms,
342N/A _young_list_target_length - _young_list_so_prefix_length,
342N/A _young_list_so_prefix_length,
342N/A elapsed_time_ms,
342N/A calculations,
342N/A full_young_gcs() ? "full" : "partial",
342N/A should_initiate_conc_mark() ? " i-m" : "",
545N/A _in_marking_window,
545N/A _in_marking_window_im);
545N/A#endif // TRACE_CALC_YOUNG_CONFIG
342N/A
342N/A if (_young_list_target_length < _young_list_min_length) {
342N/A // bummer; this means that, if we do a pause when the optimal
342N/A // config dictates, we'll violate the pause spacing target (the
342N/A // min length was calculate based on the application's current
342N/A // alloc rate);
342N/A
342N/A // so, we have to bite the bullet, and allocate the minimum
342N/A // number. We'll violate our target, but we just can't meet it.
342N/A
342N/A size_t so_length = 0;
342N/A // a note further up explains why we do not want an S-O length
342N/A // during marking
342N/A if (!_in_marking_window && !_last_full_young_gc)
342N/A // but we can still try to see whether we can find an optimal
342N/A // S-O length
342N/A so_length = calculate_optimal_so_length(_young_list_min_length);
342N/A
545N/A#ifdef TRACE_CALC_YOUNG_CONFIG
342N/A // leave this in for debugging, just in case
342N/A gclog_or_tty->print_cr("adjusted target length from "
342N/A SIZE_FORMAT " to " SIZE_FORMAT
342N/A ", SO " SIZE_FORMAT,
342N/A _young_list_target_length, _young_list_min_length,
342N/A so_length);
545N/A#endif // TRACE_CALC_YOUNG_CONFIG
342N/A
342N/A _young_list_target_length =
342N/A MAX2(_young_list_min_length, (size_t)1);
342N/A _young_list_so_prefix_length = so_length;
342N/A }
342N/A } else {
342N/A // we are in a partially-young mode or we've run out of regions (due
342N/A // to evacuation failure)
342N/A
545N/A#ifdef TRACE_CALC_YOUNG_CONFIG
342N/A // leave this in for debugging, just in case
342N/A gclog_or_tty->print_cr("(partial) setting target to " SIZE_FORMAT
342N/A ", SO " SIZE_FORMAT,
342N/A _young_list_min_length, 0);
545N/A#endif // TRACE_CALC_YOUNG_CONFIG
342N/A
342N/A // we'll do the pause as soon as possible and with no S-O prefix
342N/A // (see above for the reasons behind the latter)
342N/A _young_list_target_length =
342N/A MAX2(_young_list_min_length, (size_t) 1);
342N/A _young_list_so_prefix_length = 0;
342N/A }
342N/A
342N/A _rs_lengths_prediction = rs_lengths;
342N/A}
342N/A
342N/A// This is used by: calculate_optimal_so_length(length). It returns
342N/A// the GC eff and predicted pause time for a particular config
342N/Avoid
342N/AG1CollectorPolicy::predict_gc_eff(size_t young_length,
342N/A size_t so_length,
342N/A double base_time_ms,
342N/A double* ret_gc_eff,
342N/A double* ret_pause_time_ms) {
342N/A double so_time_ms = predict_scan_only_time_ms(so_length);
342N/A double accum_surv_rate_adj = 0.0;
342N/A if (so_length > 0)
342N/A accum_surv_rate_adj = accum_yg_surv_rate_pred((int)(so_length - 1));
342N/A double accum_surv_rate =
342N/A accum_yg_surv_rate_pred((int)(young_length - 1)) - accum_surv_rate_adj;
342N/A size_t bytes_to_copy =
342N/A (size_t) (accum_surv_rate * (double) HeapRegion::GrainBytes);
342N/A double copy_time_ms = predict_object_copy_time_ms(bytes_to_copy);
342N/A double young_other_time_ms =
342N/A predict_young_other_time_ms(young_length - so_length);
342N/A double pause_time_ms =
342N/A base_time_ms + so_time_ms + copy_time_ms + young_other_time_ms;
342N/A size_t reclaimed_bytes =
342N/A (young_length - so_length) * HeapRegion::GrainBytes - bytes_to_copy;
342N/A double gc_eff = (double) reclaimed_bytes / pause_time_ms;
342N/A
342N/A *ret_gc_eff = gc_eff;
342N/A *ret_pause_time_ms = pause_time_ms;
342N/A}
342N/A
342N/A// This is used by: calculate_young_list_target_config(rs_length). It
342N/A// returns the GC eff of a particular config. It returns false if that
342N/A// config violates any of the end conditions of the search in the
342N/A// calling method, or true upon success. The end conditions were put
342N/A// here since it's called twice and it was best not to replicate them
342N/A// in the caller. Also, passing the parameteres avoids having to
342N/A// recalculate them in the innermost loop.
342N/Abool
342N/AG1CollectorPolicy::predict_gc_eff(size_t young_length,
342N/A size_t so_length,
342N/A double base_time_with_so_ms,
342N/A size_t init_free_regions,
342N/A double target_pause_time_ms,
342N/A double* ret_gc_eff) {
342N/A *ret_gc_eff = 0.0;
342N/A
342N/A if (young_length >= init_free_regions)
342N/A // end condition 1: not enough space for the young regions
342N/A return false;
342N/A
342N/A double accum_surv_rate_adj = 0.0;
342N/A if (so_length > 0)
342N/A accum_surv_rate_adj = accum_yg_surv_rate_pred((int)(so_length - 1));
342N/A double accum_surv_rate =
342N/A accum_yg_surv_rate_pred((int)(young_length - 1)) - accum_surv_rate_adj;
342N/A size_t bytes_to_copy =
342N/A (size_t) (accum_surv_rate * (double) HeapRegion::GrainBytes);
342N/A double copy_time_ms = predict_object_copy_time_ms(bytes_to_copy);
342N/A double young_other_time_ms =
342N/A predict_young_other_time_ms(young_length - so_length);
342N/A double pause_time_ms =
342N/A base_time_with_so_ms + copy_time_ms + young_other_time_ms;
342N/A
342N/A if (pause_time_ms > target_pause_time_ms)
342N/A // end condition 2: over the target pause time
342N/A return false;
342N/A
342N/A size_t reclaimed_bytes =
342N/A (young_length - so_length) * HeapRegion::GrainBytes - bytes_to_copy;
342N/A size_t free_bytes =
342N/A (init_free_regions - young_length) * HeapRegion::GrainBytes;
342N/A
342N/A if ((2.0 + sigma()) * (double) bytes_to_copy > (double) free_bytes)
342N/A // end condition 3: out of to-space (conservatively)
342N/A return false;
342N/A
342N/A // success!
342N/A double gc_eff = (double) reclaimed_bytes / pause_time_ms;
342N/A *ret_gc_eff = gc_eff;
342N/A
342N/A return true;
342N/A}
342N/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()) {
545N/A survivor_regions_evac_time += predict_region_elapsed_time_ms(r, true);
545N/A }
545N/A return survivor_regions_evac_time;
545N/A}
545N/A
342N/Avoid G1CollectorPolicy::check_prediction_validity() {
342N/A guarantee( adaptive_young_list_length(), "should not call this otherwise" );
342N/A
342N/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;
342N/A calculate_young_list_target_config(rs_lengths_prediction);
342N/A }
342N/A}
342N/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() {
342N/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() {
342N/A _cur_collection_start_sec = os::elapsedTime();
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();
342N/A double full_gc_time_sec = end_sec - _cur_collection_start_sec;
342N/A double full_gc_time_ms = full_gc_time_sec * 1000.0;
342N/A
342N/A _all_full_gc_times_ms->add(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
342N/A // "Nuke" the heuristics that control the fully/partially young GC
342N/A // transitions and make sure we start with fully young GCs after the
342N/A // Full GC.
342N/A set_full_young_gcs(true);
342N/A _last_full_young_gc = false;
342N/A _should_revert_to_full_young_gcs = false;
342N/A _should_initiate_conc_mark = false;
342N/A _known_garbage_bytes = 0;
342N/A _known_garbage_ratio = 0.0;
342N/A _in_marking_window = false;
342N/A _in_marking_window_im = false;
342N/A
342N/A _short_lived_surv_rate_group->record_scan_only_prefix(0);
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 _prev_region_num_young = _region_num_young;
342N/A _prev_region_num_tenured = _region_num_tenured;
342N/A
342N/A _free_regions_at_end_of_collection = _g1->free_regions();
342N/A _scan_only_regions_at_end_of_collection = 0;
545N/A // Reset survivors SurvRateGroup.
545N/A _survivor_surv_rate_group->reset();
342N/A calculate_young_list_min_length();
342N/A calculate_young_list_target_config();
342N/A }
342N/A
342N/Avoid G1CollectorPolicy::record_before_bytes(size_t bytes) {
342N/A _bytes_in_to_space_before_gc += bytes;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_after_bytes(size_t bytes) {
342N/A _bytes_in_to_space_after_gc += bytes;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_stop_world_start() {
342N/A _stop_world_start = os::elapsedTime();
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_collection_pause_start(double start_time_sec,
342N/A size_t start_used) {
342N/A if (PrintGCDetails) {
342N/A gclog_or_tty->stamp(PrintGCTimeStamps);
342N/A gclog_or_tty->print("[GC pause");
342N/A if (in_young_gc_mode())
342N/A gclog_or_tty->print(" (%s)", full_young_gcs() ? "young" : "partial");
342N/A }
342N/A
342N/A assert(_g1->used_regions() == _g1->recalculate_used_regions(),
342N/A "sanity");
636N/A assert(_g1->used() == _g1->recalculate_used(), "sanity");
342N/A
342N/A double s_w_t_ms = (start_time_sec - _stop_world_start) * 1000.0;
342N/A _all_stop_world_times_ms->add(s_w_t_ms);
342N/A _stop_world_start = 0.0;
342N/A
342N/A _cur_collection_start_sec = start_time_sec;
342N/A _cur_collection_pause_used_at_start_bytes = start_used;
342N/A _cur_collection_pause_used_regions_at_start = _g1->used_regions();
342N/A _pending_cards = _g1->pending_card_num();
342N/A _max_pending_cards = _g1->max_pending_card_num();
342N/A
342N/A _bytes_in_to_space_before_gc = 0;
342N/A _bytes_in_to_space_after_gc = 0;
342N/A _bytes_in_collection_set_before_gc = 0;
342N/A
342N/A#ifdef DEBUG
342N/A // initialise these to something well known so that we can spot
342N/A // if they are not set properly
342N/A
342N/A for (int i = 0; i < _parallel_gc_threads; ++i) {
342N/A _par_last_ext_root_scan_times_ms[i] = -666.0;
342N/A _par_last_mark_stack_scan_times_ms[i] = -666.0;
342N/A _par_last_scan_only_times_ms[i] = -666.0;
342N/A _par_last_scan_only_regions_scanned[i] = -666.0;
342N/A _par_last_update_rs_start_times_ms[i] = -666.0;
342N/A _par_last_update_rs_times_ms[i] = -666.0;
342N/A _par_last_update_rs_processed_buffers[i] = -666.0;
342N/A _par_last_scan_rs_start_times_ms[i] = -666.0;
342N/A _par_last_scan_rs_times_ms[i] = -666.0;
342N/A _par_last_scan_new_refs_times_ms[i] = -666.0;
342N/A _par_last_obj_copy_times_ms[i] = -666.0;
342N/A _par_last_termination_times_ms[i] = -666.0;
342N/A }
342N/A#endif
342N/A
342N/A for (int i = 0; i < _aux_num; ++i) {
342N/A _cur_aux_times_ms[i] = 0.0;
342N/A _cur_aux_times_set[i] = false;
342N/A }
342N/A
342N/A _satb_drain_time_set = false;
342N/A _last_satb_drain_processed_buffers = -1;
342N/A
342N/A if (in_young_gc_mode())
342N/A _last_young_gc_full = false;
342N/A
342N/A
342N/A // do that for any other surv rate groups
342N/A _short_lived_surv_rate_group->stop_adding_regions();
342N/A size_t short_lived_so_length = _young_list_so_prefix_length;
342N/A _short_lived_surv_rate_group->record_scan_only_prefix(short_lived_so_length);
342N/A tag_scan_only(short_lived_so_length);
1282N/A _survivors_age_table.clear();
545N/A
342N/A assert( verify_young_ages(), "region age verification" );
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::tag_scan_only(size_t short_lived_scan_only_length) {
342N/A // done in a way that it can be extended for other surv rate groups too...
342N/A
342N/A HeapRegion* head = _g1->young_list_first_region();
342N/A bool finished_short_lived = (short_lived_scan_only_length == 0);
342N/A
342N/A if (finished_short_lived)
342N/A return;
342N/A
342N/A for (HeapRegion* curr = head;
342N/A curr != NULL;
342N/A curr = curr->get_next_young_region()) {
342N/A SurvRateGroup* surv_rate_group = curr->surv_rate_group();
342N/A int age = curr->age_in_surv_rate_group();
342N/A
342N/A if (surv_rate_group == _short_lived_surv_rate_group) {
342N/A if ((size_t)age < short_lived_scan_only_length)
342N/A curr->set_scan_only();
342N/A else
342N/A finished_short_lived = true;
342N/A }
342N/A
342N/A
342N/A if (finished_short_lived)
342N/A return;
342N/A }
342N/A
342N/A guarantee( false, "we should never reach here" );
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_mark_closure_time(double mark_closure_time_ms) {
342N/A _mark_closure_time_ms = mark_closure_time_ms;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_mark_init_start() {
342N/A _mark_init_start_sec = os::elapsedTime();
342N/A guarantee(!in_young_gc_mode(), "should not do be here in young GC mode");
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_mark_init_end_pre(double
342N/A mark_init_elapsed_time_ms) {
342N/A _during_marking = true;
342N/A _should_initiate_conc_mark = false;
342N/A _cur_mark_stop_world_time_ms = mark_init_elapsed_time_ms;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_mark_init_end() {
342N/A double end_time_sec = os::elapsedTime();
342N/A double elapsed_time_ms = (end_time_sec - _mark_init_start_sec) * 1000.0;
342N/A _concurrent_mark_init_times_ms->add(elapsed_time_ms);
342N/A record_concurrent_mark_init_end_pre(elapsed_time_ms);
342N/A
342N/A _mmu_tracker->add_pause(_mark_init_start_sec, end_time_sec, true);
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
342N/Avoid
342N/AG1CollectorPolicy::record_concurrent_mark_cleanup_end(size_t freed_bytes,
342N/A size_t max_live_bytes) {
342N/A record_concurrent_mark_cleanup_end_work1(freed_bytes, max_live_bytes);
342N/A record_concurrent_mark_cleanup_end_work2();
342N/A}
342N/A
342N/Avoid
342N/AG1CollectorPolicy::
342N/Arecord_concurrent_mark_cleanup_end_work1(size_t freed_bytes,
342N/A size_t max_live_bytes) {
342N/A if (_n_marks < 2) _n_marks++;
342N/A if (G1PolicyVerbose > 0)
342N/A gclog_or_tty->print_cr("At end of marking, max_live is " SIZE_FORMAT " MB "
342N/A " (of " SIZE_FORMAT " MB heap).",
342N/A max_live_bytes/M, _g1->capacity()/M);
342N/A}
342N/A
342N/A// The important thing about this is that it includes "os::elapsedTime".
342N/Avoid G1CollectorPolicy::record_concurrent_mark_cleanup_end_work2() {
342N/A double end_time_sec = os::elapsedTime();
342N/A double elapsed_time_ms = (end_time_sec - _mark_cleanup_start_sec)*1000.0;
342N/A _concurrent_mark_cleanup_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_cleanup_start_sec, end_time_sec, true);
342N/A
342N/A _num_markings++;
342N/A
342N/A // We did a marking, so reset the "since_last_mark" variables.
342N/A double considerConcMarkCost = 1.0;
342N/A // If there are available processors, concurrent activity is free...
342N/A if (Threads::number_of_non_daemon_threads() * 2 <
342N/A os::active_processor_count()) {
342N/A considerConcMarkCost = 0.0;
342N/A }
342N/A _n_pauses_at_mark_end = _n_pauses;
342N/A _n_marks_since_last_pause++;
342N/A _conc_mark_initiated = false;
342N/A}
342N/A
342N/Avoid
342N/AG1CollectorPolicy::record_concurrent_mark_cleanup_completed() {
342N/A if (in_young_gc_mode()) {
342N/A _should_revert_to_full_young_gcs = false;
342N/A _last_full_young_gc = true;
342N/A _in_marking_window = false;
342N/A if (adaptive_young_list_length())
342N/A calculate_young_list_target_config();
342N/A }
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;
342N/A _all_yield_times_ms->add(yield_ms);
342N/A }
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_pause_end() {
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_collection_pause_end_CH_strong_roots() {
342N/A _cur_CH_strong_roots_end_sec = os::elapsedTime();
342N/A _cur_CH_strong_roots_dur_ms =
342N/A (_cur_CH_strong_roots_end_sec - _cur_collection_start_sec) * 1000.0;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_collection_pause_end_G1_strong_roots() {
342N/A _cur_G1_strong_roots_end_sec = os::elapsedTime();
342N/A _cur_G1_strong_roots_dur_ms =
342N/A (_cur_G1_strong_roots_end_sec - _cur_CH_strong_roots_end_sec) * 1000.0;
342N/A}
342N/A
342N/Atemplate<class T>
342N/AT sum_of(T* sum_arr, int start, int n, int N) {
342N/A T sum = (T)0;
342N/A for (int i = 0; i < n; i++) {
342N/A int j = (start + i) % N;
342N/A sum += sum_arr[j];
342N/A }
342N/A return sum;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::print_par_stats (int level,
342N/A const char* str,
342N/A double* data,
342N/A bool summary) {
342N/A double min = data[0], max = data[0];
342N/A double total = 0.0;
342N/A int j;
342N/A for (j = 0; j < level; ++j)
342N/A gclog_or_tty->print(" ");
342N/A gclog_or_tty->print("[%s (ms):", str);
342N/A for (uint i = 0; i < ParallelGCThreads; ++i) {
342N/A double val = data[i];
342N/A if (val < min)
342N/A min = val;
342N/A if (val > max)
342N/A max = val;
342N/A total += val;
342N/A gclog_or_tty->print(" %3.1lf", val);
342N/A }
342N/A if (summary) {
342N/A gclog_or_tty->print_cr("");
342N/A double avg = total / (double) ParallelGCThreads;
342N/A gclog_or_tty->print(" ");
342N/A for (j = 0; j < level; ++j)
342N/A gclog_or_tty->print(" ");
342N/A gclog_or_tty->print("Avg: %5.1lf, Min: %5.1lf, Max: %5.1lf",
342N/A avg, min, max);
342N/A }
342N/A gclog_or_tty->print_cr("]");
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::print_par_buffers (int level,
342N/A const char* str,
342N/A double* data,
342N/A bool summary) {
342N/A double min = data[0], max = data[0];
342N/A double total = 0.0;
342N/A int j;
342N/A for (j = 0; j < level; ++j)
342N/A gclog_or_tty->print(" ");
342N/A gclog_or_tty->print("[%s :", str);
342N/A for (uint i = 0; i < ParallelGCThreads; ++i) {
342N/A double val = data[i];
342N/A if (val < min)
342N/A min = val;
342N/A if (val > max)
342N/A max = val;
342N/A total += val;
342N/A gclog_or_tty->print(" %d", (int) val);
342N/A }
342N/A if (summary) {
342N/A gclog_or_tty->print_cr("");
342N/A double avg = total / (double) ParallelGCThreads;
342N/A gclog_or_tty->print(" ");
342N/A for (j = 0; j < level; ++j)
342N/A gclog_or_tty->print(" ");
342N/A gclog_or_tty->print("Sum: %d, Avg: %d, Min: %d, Max: %d",
342N/A (int)total, (int)avg, (int)min, (int)max);
342N/A }
342N/A gclog_or_tty->print_cr("]");
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::print_stats (int level,
342N/A const char* str,
342N/A double value) {
342N/A for (int j = 0; j < level; ++j)
342N/A gclog_or_tty->print(" ");
342N/A gclog_or_tty->print_cr("[%s: %5.1lf ms]", str, value);
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::print_stats (int level,
342N/A const char* str,
342N/A int value) {
342N/A for (int j = 0; j < level; ++j)
342N/A gclog_or_tty->print(" ");
342N/A gclog_or_tty->print_cr("[%s: %d]", str, value);
342N/A}
342N/A
342N/Adouble G1CollectorPolicy::avg_value (double* data) {
342N/A if (ParallelGCThreads > 0) {
342N/A double ret = 0.0;
342N/A for (uint i = 0; i < ParallelGCThreads; ++i)
342N/A ret += data[i];
342N/A return ret / (double) ParallelGCThreads;
342N/A } else {
342N/A return data[0];
342N/A }
342N/A}
342N/A
342N/Adouble G1CollectorPolicy::max_value (double* data) {
342N/A if (ParallelGCThreads > 0) {
342N/A double ret = data[0];
342N/A for (uint i = 1; i < ParallelGCThreads; ++i)
342N/A if (data[i] > ret)
342N/A ret = data[i];
342N/A return ret;
342N/A } else {
342N/A return data[0];
342N/A }
342N/A}
342N/A
342N/Adouble G1CollectorPolicy::sum_of_values (double* data) {
342N/A if (ParallelGCThreads > 0) {
342N/A double sum = 0.0;
342N/A for (uint i = 0; i < ParallelGCThreads; i++)
342N/A sum += data[i];
342N/A return sum;
342N/A } else {
342N/A return data[0];
342N/A }
342N/A}
342N/A
342N/Adouble G1CollectorPolicy::max_sum (double* data1,
342N/A double* data2) {
342N/A double ret = data1[0] + data2[0];
342N/A
342N/A if (ParallelGCThreads > 0) {
342N/A for (uint i = 1; i < ParallelGCThreads; ++i) {
342N/A double data = data1[i] + data2[i];
342N/A if (data > ret)
342N/A ret = data;
342N/A }
342N/A }
342N/A return ret;
342N/A}
342N/A
342N/A// Anything below that is considered to be zero
342N/A#define MIN_TIMER_GRANULARITY 0.0000001
342N/A
677N/Avoid G1CollectorPolicy::record_collection_pause_end(bool abandoned) {
342N/A double end_time_sec = os::elapsedTime();
342N/A double elapsed_ms = _last_pause_time_ms;
342N/A bool parallel = ParallelGCThreads > 0;
342N/A double evac_ms = (end_time_sec - _cur_G1_strong_roots_end_sec) * 1000.0;
342N/A size_t rs_size =
342N/A _cur_collection_pause_used_regions_at_start - collection_set_size();
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;
595N/A bool update_stats = !abandoned && !_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
342N/A if (in_young_gc_mode()) {
342N/A last_pause_included_initial_mark = _should_initiate_conc_mark;
342N/A if (last_pause_included_initial_mark)
342N/A record_concurrent_mark_init_end_pre(0.0);
342N/A
342N/A size_t min_used_targ =
1283N/A (_g1->capacity() / 100) * InitiatingHeapOccupancyPercent;
342N/A
342N/A if (cur_used_bytes > min_used_targ) {
342N/A if (cur_used_bytes <= _prev_collection_pause_used_at_end_bytes) {
342N/A } else if (!_g1->mark_in_progress() && !_last_full_young_gc) {
342N/A _should_initiate_conc_mark = true;
342N/A }
342N/A }
342N/A
342N/A _prev_collection_pause_used_at_end_bytes = cur_used_bytes;
342N/A }
342N/A
342N/A _mmu_tracker->add_pause(end_time_sec - elapsed_ms/1000.0,
342N/A end_time_sec, false);
342N/A
342N/A guarantee(_cur_collection_pause_used_regions_at_start >=
342N/A collection_set_size(),
342N/A "Negative RS size?");
342N/A
342N/A // This assert is exempted when we're doing parallel collection pauses,
342N/A // because the fragmentation caused by the parallel GC allocation buffers
342N/A // can lead to more memory being used during collection than was used
342N/A // before. Best leave this out until the fragmentation problem is fixed.
342N/A // Pauses in which evacuation failed can also lead to negative
342N/A // collections, since no space is reclaimed from a region containing an
342N/A // object whose evacuation failed.
342N/A // Further, we're now always doing parallel collection. But I'm still
342N/A // leaving this here as a placeholder for a more precise assertion later.
342N/A // (DLD, 10/05.)
342N/A assert((true || parallel) // Always using GC LABs now.
342N/A || _g1->evacuation_failed()
342N/A || _cur_collection_pause_used_at_start_bytes >= cur_used_bytes,
342N/A "Negative collection");
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;
342N/A double survival_fraction =
342N/A (double)surviving_bytes/
342N/A (double)_collection_set_bytes_used_before;
342N/A
342N/A _n_pauses++;
342N/A
595N/A if (update_stats) {
342N/A _recent_CH_strong_roots_times_ms->add(_cur_CH_strong_roots_dur_ms);
342N/A _recent_G1_strong_roots_times_ms->add(_cur_G1_strong_roots_dur_ms);
342N/A _recent_evac_times_ms->add(evac_ms);
342N/A _recent_pause_times_ms->add(elapsed_ms);
342N/A
342N/A _recent_rs_sizes->add(rs_size);
342N/A
342N/A // We exempt parallel collection from this check because Alloc Buffer
342N/A // fragmentation can produce negative collections. Same with evac
342N/A // failure.
342N/A // Further, we're now always doing parallel collection. But I'm still
342N/A // leaving this here as a placeholder for a more precise assertion later.
342N/A // (DLD, 10/05.
342N/A assert((true || parallel)
342N/A || _g1->evacuation_failed()
342N/A || surviving_bytes <= _collection_set_bytes_used_before,
342N/A "Or else negative collection!");
342N/A _recent_CS_bytes_used_before->add(_collection_set_bytes_used_before);
342N/A _recent_CS_bytes_surviving->add(surviving_bytes);
342N/A
342N/A // this is where we update the allocation rate of the application
342N/A double app_time_ms =
342N/A (_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 }
342N/A size_t regions_allocated =
342N/A (_region_num_young - _prev_region_num_young) +
342N/A (_region_num_tenured - _prev_region_num_tenured);
342N/A double alloc_rate_ms = (double) regions_allocated / app_time_ms;
342N/A _alloc_rate_ms_seq->add(alloc_rate_ms);
342N/A _prev_region_num_young = _region_num_young;
342N/A _prev_region_num_tenured = _region_num_tenured;
342N/A
342N/A double interval_ms =
342N/A (end_time_sec - _recent_prev_end_times_for_all_gcs_sec->oldest()) * 1000.0;
342N/A update_recent_gc_times(end_time_sec, elapsed_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
342N/A if (G1PolicyVerbose > 1) {
342N/A gclog_or_tty->print_cr(" Recording collection pause(%d)", _n_pauses);
342N/A }
342N/A
342N/A PauseSummary* summary;
677N/A if (abandoned) {
677N/A summary = _abandoned_summary;
677N/A } else {
677N/A summary = _summary;
342N/A }
342N/A
342N/A double ext_root_scan_time = avg_value(_par_last_ext_root_scan_times_ms);
342N/A double mark_stack_scan_time = avg_value(_par_last_mark_stack_scan_times_ms);
342N/A double scan_only_time = avg_value(_par_last_scan_only_times_ms);
342N/A double scan_only_regions_scanned =
342N/A sum_of_values(_par_last_scan_only_regions_scanned);
342N/A double update_rs_time = avg_value(_par_last_update_rs_times_ms);
342N/A double update_rs_processed_buffers =
342N/A sum_of_values(_par_last_update_rs_processed_buffers);
342N/A double scan_rs_time = avg_value(_par_last_scan_rs_times_ms);
342N/A double obj_copy_time = avg_value(_par_last_obj_copy_times_ms);
342N/A double termination_time = avg_value(_par_last_termination_times_ms);
342N/A
648N/A double parallel_other_time = _cur_collection_par_time_ms -
648N/A (update_rs_time + ext_root_scan_time + mark_stack_scan_time +
648N/A scan_only_time + scan_rs_time + obj_copy_time + termination_time);
595N/A if (update_stats) {
342N/A MainBodySummary* body_summary = summary->main_body_summary();
342N/A guarantee(body_summary != NULL, "should not be null!");
342N/A
342N/A if (_satb_drain_time_set)
342N/A body_summary->record_satb_drain_time_ms(_cur_satb_drain_time_ms);
342N/A else
342N/A body_summary->record_satb_drain_time_ms(0.0);
342N/A body_summary->record_ext_root_scan_time_ms(ext_root_scan_time);
342N/A body_summary->record_mark_stack_scan_time_ms(mark_stack_scan_time);
342N/A body_summary->record_scan_only_time_ms(scan_only_time);
342N/A body_summary->record_update_rs_time_ms(update_rs_time);
342N/A body_summary->record_scan_rs_time_ms(scan_rs_time);
342N/A body_summary->record_obj_copy_time_ms(obj_copy_time);
342N/A if (parallel) {
342N/A body_summary->record_parallel_time_ms(_cur_collection_par_time_ms);
342N/A body_summary->record_clear_ct_time_ms(_cur_clear_ct_time_ms);
342N/A body_summary->record_termination_time_ms(termination_time);
342N/A body_summary->record_parallel_other_time_ms(parallel_other_time);
342N/A }
342N/A body_summary->record_mark_closure_time_ms(_mark_closure_time_ms);
342N/A }
342N/A
342N/A if (G1PolicyVerbose > 1) {
342N/A gclog_or_tty->print_cr(" ET: %10.6f ms (avg: %10.6f ms)\n"
342N/A " CH Strong: %10.6f ms (avg: %10.6f ms)\n"
342N/A " G1 Strong: %10.6f ms (avg: %10.6f ms)\n"
342N/A " Evac: %10.6f ms (avg: %10.6f ms)\n"
342N/A " ET-RS: %10.6f ms (avg: %10.6f ms)\n"
342N/A " |RS|: " SIZE_FORMAT,
342N/A elapsed_ms, recent_avg_time_for_pauses_ms(),
342N/A _cur_CH_strong_roots_dur_ms, recent_avg_time_for_CH_strong_ms(),
342N/A _cur_G1_strong_roots_dur_ms, recent_avg_time_for_G1_strong_ms(),
342N/A evac_ms, recent_avg_time_for_evac_ms(),
342N/A scan_rs_time,
342N/A recent_avg_time_for_pauses_ms() -
342N/A recent_avg_time_for_G1_strong_ms(),
342N/A rs_size);
342N/A
342N/A gclog_or_tty->print_cr(" Used at start: " SIZE_FORMAT"K"
342N/A " At end " SIZE_FORMAT "K\n"
342N/A " garbage : " SIZE_FORMAT "K"
342N/A " of " SIZE_FORMAT "K\n"
342N/A " survival : %6.2f%% (%6.2f%% avg)",
342N/A _cur_collection_pause_used_at_start_bytes/K,
342N/A _g1->used()/K, freed_bytes/K,
342N/A _collection_set_bytes_used_before/K,
342N/A survival_fraction*100.0,
342N/A recent_avg_survival_fraction()*100.0);
342N/A gclog_or_tty->print_cr(" Recent %% gc pause time: %6.2f",
342N/A recent_avg_pause_time_ratio() * 100.0);
342N/A }
342N/A
342N/A double other_time_ms = elapsed_ms;
342N/A
342N/A if (!abandoned) {
342N/A if (_satb_drain_time_set)
342N/A other_time_ms -= _cur_satb_drain_time_ms;
342N/A
342N/A if (parallel)
342N/A other_time_ms -= _cur_collection_par_time_ms + _cur_clear_ct_time_ms;
342N/A else
342N/A other_time_ms -=
342N/A update_rs_time +
342N/A ext_root_scan_time + mark_stack_scan_time + scan_only_time +
342N/A scan_rs_time + obj_copy_time;
342N/A }
342N/A
342N/A if (PrintGCDetails) {
342N/A gclog_or_tty->print_cr("%s%s, %1.8lf secs]",
677N/A abandoned ? " (abandoned)" : "",
342N/A (last_pause_included_initial_mark) ? " (initial-mark)" : "",
342N/A elapsed_ms / 1000.0);
342N/A
342N/A if (!abandoned) {
677N/A if (_satb_drain_time_set) {
342N/A print_stats(1, "SATB Drain Time", _cur_satb_drain_time_ms);
677N/A }
677N/A if (_last_satb_drain_processed_buffers >= 0) {
342N/A print_stats(2, "Processed Buffers", _last_satb_drain_processed_buffers);
677N/A }
677N/A if (parallel) {
677N/A print_stats(1, "Parallel Time", _cur_collection_par_time_ms);
677N/A print_par_stats(2, "Update RS (Start)", _par_last_update_rs_start_times_ms, false);
677N/A print_par_stats(2, "Update RS", _par_last_update_rs_times_ms);
794N/A print_par_buffers(3, "Processed Buffers",
794N/A _par_last_update_rs_processed_buffers, true);
342N/A print_par_stats(2, "Ext Root Scanning", _par_last_ext_root_scan_times_ms);
342N/A print_par_stats(2, "Mark Stack Scanning", _par_last_mark_stack_scan_times_ms);
342N/A print_par_stats(2, "Scan-Only Scanning", _par_last_scan_only_times_ms);
342N/A print_par_buffers(3, "Scan-Only Regions",
342N/A _par_last_scan_only_regions_scanned, true);
342N/A print_par_stats(2, "Scan RS", _par_last_scan_rs_times_ms);
342N/A print_par_stats(2, "Object Copy", _par_last_obj_copy_times_ms);
342N/A print_par_stats(2, "Termination", _par_last_termination_times_ms);
342N/A print_stats(2, "Other", parallel_other_time);
342N/A print_stats(1, "Clear CT", _cur_clear_ct_time_ms);
677N/A } else {
677N/A print_stats(1, "Update RS", update_rs_time);
794N/A print_stats(2, "Processed Buffers",
794N/A (int)update_rs_processed_buffers);
342N/A print_stats(1, "Ext Root Scanning", ext_root_scan_time);
342N/A print_stats(1, "Mark Stack Scanning", mark_stack_scan_time);
342N/A print_stats(1, "Scan-Only Scanning", scan_only_time);
342N/A print_stats(1, "Scan RS", scan_rs_time);
342N/A print_stats(1, "Object Copying", obj_copy_time);
342N/A }
342N/A }
890N/A#ifndef PRODUCT
890N/A print_stats(1, "Cur Clear CC", _cur_clear_cc_time_ms);
890N/A print_stats(1, "Cum Clear CC", _cum_clear_cc_time_ms);
890N/A print_stats(1, "Min Clear CC", _min_clear_cc_time_ms);
890N/A print_stats(1, "Max Clear CC", _max_clear_cc_time_ms);
890N/A if (_num_cc_clears > 0) {
890N/A print_stats(1, "Avg Clear CC", _cum_clear_cc_time_ms / ((double)_num_cc_clears));
890N/A }
890N/A#endif
342N/A print_stats(1, "Other", other_time_ms);
342N/A for (int i = 0; i < _aux_num; ++i) {
342N/A if (_cur_aux_times_set[i]) {
342N/A char buffer[96];
342N/A sprintf(buffer, "Aux%d", i);
342N/A print_stats(1, buffer, _cur_aux_times_ms[i]);
342N/A }
342N/A }
342N/A }
342N/A if (PrintGCDetails)
342N/A gclog_or_tty->print(" [");
342N/A if (PrintGC || PrintGCDetails)
342N/A _g1->print_size_transition(gclog_or_tty,
342N/A _cur_collection_pause_used_at_start_bytes,
342N/A _g1->used(), _g1->capacity());
342N/A if (PrintGCDetails)
342N/A gclog_or_tty->print_cr("]");
342N/A
342N/A _all_pause_times_ms->add(elapsed_ms);
648N/A if (update_stats) {
648N/A summary->record_total_time_ms(elapsed_ms);
648N/A summary->record_other_time_ms(other_time_ms);
648N/A }
342N/A for (int i = 0; i < _aux_num; ++i)
342N/A if (_cur_aux_times_set[i])
342N/A _all_aux_times_ms[i].add(_cur_aux_times_ms[i]);
342N/A
342N/A // Reset marks-between-pauses counter.
342N/A _n_marks_since_last_pause = 0;
342N/A
342N/A // Update the efficiency-since-mark vars.
342N/A double proc_ms = elapsed_ms * (double) _parallel_gc_threads;
342N/A if (elapsed_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 proc_ms = 1.0;
342N/A }
342N/A double cur_efficiency = (double) freed_bytes / proc_ms;
342N/A
342N/A bool new_in_marking_window = _in_marking_window;
342N/A bool new_in_marking_window_im = false;
342N/A if (_should_initiate_conc_mark) {
342N/A new_in_marking_window = true;
342N/A new_in_marking_window_im = true;
342N/A }
342N/A
342N/A if (in_young_gc_mode()) {
342N/A if (_last_full_young_gc) {
342N/A set_full_young_gcs(false);
342N/A _last_full_young_gc = false;
342N/A }
342N/A
342N/A if ( !_last_young_gc_full ) {
342N/A if ( _should_revert_to_full_young_gcs ||
342N/A _known_garbage_ratio < 0.05 ||
342N/A (adaptive_young_list_length() &&
342N/A (get_gc_eff_factor() * cur_efficiency < predict_young_gc_eff())) ) {
342N/A set_full_young_gcs(true);
342N/A }
342N/A }
342N/A _should_revert_to_full_young_gcs = false;
342N/A
342N/A if (_last_young_gc_full && !_during_marking)
342N/A _young_gc_eff_seq->add(cur_efficiency);
342N/A }
342N/A
342N/A _short_lived_surv_rate_group->start_adding_regions();
342N/A // do that for any other surv rate groupsx
342N/A
342N/A // <NEW PREDICTION>
342N/A
677N/A if (update_stats) {
342N/A double pause_time_ms = elapsed_ms;
342N/A
342N/A size_t diff = 0;
342N/A if (_max_pending_cards >= _pending_cards)
342N/A diff = _max_pending_cards - _pending_cards;
342N/A _pending_card_diff_seq->add((double) diff);
342N/A
342N/A double cost_per_card_ms = 0.0;
342N/A if (_pending_cards > 0) {
342N/A cost_per_card_ms = update_rs_time / (double) _pending_cards;
342N/A _cost_per_card_ms_seq->add(cost_per_card_ms);
342N/A }
342N/A
342N/A double cost_per_scan_only_region_ms = 0.0;
342N/A if (scan_only_regions_scanned > 0.0) {
342N/A cost_per_scan_only_region_ms =
342N/A scan_only_time / scan_only_regions_scanned;
342N/A if (_in_marking_window_im)
342N/A _cost_per_scan_only_region_ms_during_cm_seq->add(cost_per_scan_only_region_ms);
342N/A else
342N/A _cost_per_scan_only_region_ms_seq->add(cost_per_scan_only_region_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) {
342N/A cost_per_entry_ms = scan_rs_time / (double) cards_scanned;
342N/A if (_last_young_gc_full)
342N/A _cost_per_entry_ms_seq->add(cost_per_entry_ms);
342N/A else
342N/A _partially_young_cost_per_entry_ms_seq->add(cost_per_entry_ms);
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;
342N/A if (_last_young_gc_full)
342N/A _fully_young_cards_per_entry_ratio_seq->add(cards_per_entry_ratio);
342N/A else
342N/A _partially_young_cards_per_entry_ratio_seq->add(cards_per_entry_ratio);
342N/A }
342N/A
342N/A size_t rs_length_diff = _max_rs_lengths - _recorded_rs_lengths;
342N/A if (rs_length_diff >= 0)
342N/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) {
342N/A cost_per_byte_ms = obj_copy_time / (double) copied_bytes;
342N/A if (_in_marking_window)
342N/A _cost_per_byte_ms_during_cm_seq->add(cost_per_byte_ms);
342N/A else
342N/A _cost_per_byte_ms_seq->add(cost_per_byte_ms);
342N/A }
342N/A
342N/A double all_other_time_ms = pause_time_ms -
342N/A (update_rs_time + scan_only_time + scan_rs_time + obj_copy_time +
342N/A _mark_closure_time_ms + termination_time);
342N/A
342N/A double young_other_time_ms = 0.0;
342N/A if (_recorded_young_regions > 0) {
342N/A young_other_time_ms =
342N/A _recorded_young_cset_choice_time_ms +
342N/A _recorded_young_free_cset_time_ms;
342N/A _young_other_cost_per_region_ms_seq->add(young_other_time_ms /
342N/A (double) _recorded_young_regions);
342N/A }
342N/A double non_young_other_time_ms = 0.0;
342N/A if (_recorded_non_young_regions > 0) {
342N/A non_young_other_time_ms =
342N/A _recorded_non_young_cset_choice_time_ms +
342N/A _recorded_non_young_free_cset_time_ms;
342N/A
342N/A _non_young_other_cost_per_region_ms_seq->add(non_young_other_time_ms /
342N/A (double) _recorded_non_young_regions);
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;
342N/A if (_bytes_in_collection_set_before_gc > 0) {
342N/A survival_ratio = (double) bytes_in_to_space_during_gc() /
342N/A (double) _bytes_in_collection_set_before_gc;
342N/A }
342N/A
342N/A _pending_cards_seq->add((double) _pending_cards);
342N/A _scanned_cards_seq->add((double) cards_scanned);
342N/A _rs_lengths_seq->add((double) _max_rs_lengths);
342N/A
342N/A double expensive_region_limit_ms =
751N/A (double) MaxGCPauseMillis - predict_constant_other_time_ms();
342N/A if (expensive_region_limit_ms < 0.0) {
342N/A // this means that the other time was predicted to be longer than
342N/A // than the max pause time
751N/A expensive_region_limit_ms = (double) MaxGCPauseMillis;
342N/A }
342N/A _expensive_region_limit_ms = expensive_region_limit_ms;
342N/A
342N/A if (PREDICTIONS_VERBOSE) {
342N/A gclog_or_tty->print_cr("");
342N/A gclog_or_tty->print_cr("PREDICTIONS %1.4lf %d "
342N/A "REGIONS %d %d %d %d "
342N/A "PENDING_CARDS %d %d "
342N/A "CARDS_SCANNED %d %d "
342N/A "RS_LENGTHS %d %d "
342N/A "SCAN_ONLY_SCAN %1.6lf %1.6lf "
342N/A "RS_UPDATE %1.6lf %1.6lf RS_SCAN %1.6lf %1.6lf "
342N/A "SURVIVAL_RATIO %1.6lf %1.6lf "
342N/A "OBJECT_COPY %1.6lf %1.6lf OTHER_CONSTANT %1.6lf %1.6lf "
342N/A "OTHER_YOUNG %1.6lf %1.6lf "
342N/A "OTHER_NON_YOUNG %1.6lf %1.6lf "
342N/A "VTIME_DIFF %1.6lf TERMINATION %1.6lf "
342N/A "ELAPSED %1.6lf %1.6lf ",
342N/A _cur_collection_start_sec,
342N/A (!_last_young_gc_full) ? 2 :
342N/A (last_pause_included_initial_mark) ? 1 : 0,
342N/A _recorded_region_num,
342N/A _recorded_young_regions,
342N/A _recorded_scan_only_regions,
342N/A _recorded_non_young_regions,
342N/A _predicted_pending_cards, _pending_cards,
342N/A _predicted_cards_scanned, cards_scanned,
342N/A _predicted_rs_lengths, _max_rs_lengths,
342N/A _predicted_scan_only_scan_time_ms, scan_only_time,
342N/A _predicted_rs_update_time_ms, update_rs_time,
342N/A _predicted_rs_scan_time_ms, scan_rs_time,
342N/A _predicted_survival_ratio, survival_ratio,
342N/A _predicted_object_copy_time_ms, obj_copy_time,
342N/A _predicted_constant_other_time_ms, constant_other_time_ms,
342N/A _predicted_young_other_time_ms, young_other_time_ms,
342N/A _predicted_non_young_other_time_ms,
342N/A non_young_other_time_ms,
342N/A _vtime_diff_ms, termination_time,
342N/A _predicted_pause_time_ms, elapsed_ms);
342N/A }
342N/A
342N/A if (G1PolicyVerbose > 0) {
342N/A gclog_or_tty->print_cr("Pause Time, predicted: %1.4lfms (predicted %s), actual: %1.4lfms",
342N/A _predicted_pause_time_ms,
342N/A (_within_target) ? "within" : "outside",
342N/A elapsed_ms);
342N/A }
342N/A
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();
342N/A _scan_only_regions_at_end_of_collection = _g1->young_list_length();
342N/A calculate_young_list_min_length();
342N/A calculate_young_list_target_config();
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;
1111N/A adjust_concurrent_refinement(update_rs_time, update_rs_processed_buffers, update_rs_time_goal_ms);
1111N/A
342N/A // </NEW PREDICTION>
342N/A
342N/A _target_pause_time_ms = -1.0;
342N/A}
342N/A
342N/A// <NEW PREDICTION>
342N/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::
342N/Apredict_young_collection_elapsed_time_ms(size_t adjustment) {
342N/A guarantee( adjustment == 0 || adjustment == 1, "invariant" );
342N/A
342N/A G1CollectedHeap* g1h = G1CollectedHeap::heap();
342N/A size_t young_num = g1h->young_list_length();
342N/A if (young_num == 0)
342N/A return 0.0;
342N/A
342N/A young_num += adjustment;
342N/A size_t pending_cards = predict_pending_cards();
342N/A size_t rs_lengths = g1h->young_list_sampled_rs_lengths() +
342N/A predict_rs_length_diff();
342N/A size_t card_num;
342N/A if (full_young_gcs())
342N/A card_num = predict_young_card_num(rs_lengths);
342N/A else
342N/A card_num = predict_non_young_card_num(rs_lengths);
342N/A size_t young_byte_size = young_num * HeapRegion::GrainBytes;
342N/A double accum_yg_surv_rate =
342N/A _short_lived_surv_rate_group->accum_surv_rate(adjustment);
342N/A
342N/A size_t bytes_to_copy =
342N/A (size_t) (accum_yg_surv_rate * (double) HeapRegion::GrainBytes);
342N/A
342N/A return
342N/A predict_rs_update_time_ms(pending_cards) +
342N/A predict_rs_scan_time_ms(card_num) +
342N/A predict_object_copy_time_ms(bytes_to_copy) +
342N/A predict_young_other_time_ms(young_num) +
342N/A predict_constant_other_time_ms();
342N/A}
342N/A
342N/Adouble
342N/AG1CollectorPolicy::predict_base_elapsed_time_ms(size_t pending_cards) {
342N/A size_t rs_length = predict_rs_length_diff();
342N/A size_t card_num;
342N/A if (full_young_gcs())
342N/A card_num = predict_young_card_num(rs_length);
342N/A else
342N/A card_num = predict_non_young_card_num(rs_length);
342N/A return predict_base_elapsed_time_ms(pending_cards, card_num);
342N/A}
342N/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
342N/AG1CollectorPolicy::predict_region_elapsed_time_ms(HeapRegion* hr,
342N/A bool young) {
342N/A size_t rs_length = hr->rem_set()->occupied();
342N/A size_t card_num;
342N/A if (full_young_gcs())
342N/A card_num = predict_young_card_num(rs_length);
342N/A else
342N/A card_num = predict_non_young_card_num(rs_length);
342N/A size_t bytes_to_copy = predict_bytes_to_copy(hr);
342N/A
342N/A double region_elapsed_time_ms =
342N/A predict_rs_scan_time_ms(card_num) +
342N/A predict_object_copy_time_ms(bytes_to_copy);
342N/A
342N/A if (young)
342N/A region_elapsed_time_ms += predict_young_other_time_ms(1);
342N/A else
342N/A region_elapsed_time_ms += predict_non_young_other_time_ms(1);
342N/A
342N/A return region_elapsed_time_ms;
342N/A}
342N/A
342N/Asize_t
342N/AG1CollectorPolicy::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 {
342N/A guarantee( hr->is_young() && hr->age_in_surv_rate_group() != -1,
342N/A "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
342N/A return bytes_to_copy;
342N/A}
342N/A
342N/Avoid
342N/AG1CollectorPolicy::start_recording_regions() {
342N/A _recorded_rs_lengths = 0;
342N/A _recorded_scan_only_regions = 0;
342N/A _recorded_young_regions = 0;
342N/A _recorded_non_young_regions = 0;
342N/A
342N/A#if PREDICTIONS_VERBOSE
342N/A _predicted_rs_lengths = 0;
342N/A _predicted_cards_scanned = 0;
342N/A
342N/A _recorded_marked_bytes = 0;
342N/A _recorded_young_bytes = 0;
342N/A _predicted_bytes_to_copy = 0;
342N/A#endif // PREDICTIONS_VERBOSE
342N/A}
342N/A
342N/Avoid
342N/AG1CollectorPolicy::record_cset_region(HeapRegion* hr, bool young) {
342N/A if (young) {
342N/A ++_recorded_young_regions;
342N/A } else {
342N/A ++_recorded_non_young_regions;
342N/A }
342N/A#if PREDICTIONS_VERBOSE
342N/A if (young) {
545N/A _recorded_young_bytes += hr->used();
342N/A } else {
342N/A _recorded_marked_bytes += hr->max_live_bytes();
342N/A }
342N/A _predicted_bytes_to_copy += predict_bytes_to_copy(hr);
342N/A#endif // PREDICTIONS_VERBOSE
342N/A
342N/A size_t rs_length = hr->rem_set()->occupied();
342N/A _recorded_rs_lengths += rs_length;
342N/A}
342N/A
342N/Avoid
342N/AG1CollectorPolicy::record_scan_only_regions(size_t scan_only_length) {
342N/A _recorded_scan_only_regions = scan_only_length;
342N/A}
342N/A
342N/Avoid
342N/AG1CollectorPolicy::end_recording_regions() {
342N/A#if PREDICTIONS_VERBOSE
342N/A _predicted_pending_cards = predict_pending_cards();
342N/A _predicted_rs_lengths = _recorded_rs_lengths + predict_rs_length_diff();
342N/A if (full_young_gcs())
342N/A _predicted_cards_scanned += predict_young_card_num(_predicted_rs_lengths);
342N/A else
342N/A _predicted_cards_scanned +=
342N/A predict_non_young_card_num(_predicted_rs_lengths);
342N/A _recorded_region_num = _recorded_young_regions + _recorded_non_young_regions;
342N/A
342N/A _predicted_scan_only_scan_time_ms =
342N/A predict_scan_only_time_ms(_recorded_scan_only_regions);
342N/A _predicted_rs_update_time_ms =
342N/A predict_rs_update_time_ms(_g1->pending_card_num());
342N/A _predicted_rs_scan_time_ms =
342N/A predict_rs_scan_time_ms(_predicted_cards_scanned);
342N/A _predicted_object_copy_time_ms =
342N/A predict_object_copy_time_ms(_predicted_bytes_to_copy);
342N/A _predicted_constant_other_time_ms =
342N/A predict_constant_other_time_ms();
342N/A _predicted_young_other_time_ms =
342N/A predict_young_other_time_ms(_recorded_young_regions);
342N/A _predicted_non_young_other_time_ms =
342N/A predict_non_young_other_time_ms(_recorded_non_young_regions);
342N/A
342N/A _predicted_pause_time_ms =
342N/A _predicted_scan_only_scan_time_ms +
342N/A _predicted_rs_update_time_ms +
342N/A _predicted_rs_scan_time_ms +
342N/A _predicted_object_copy_time_ms +
342N/A _predicted_constant_other_time_ms +
342N/A _predicted_young_other_time_ms +
342N/A _predicted_non_young_other_time_ms;
342N/A#endif // PREDICTIONS_VERBOSE
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::check_if_region_is_too_expensive(double
342N/A predicted_time_ms) {
342N/A // I don't think we need to do this when in young GC mode since
342N/A // marking will be initiated next time we hit the soft limit anyway...
342N/A if (predicted_time_ms > _expensive_region_limit_ms) {
342N/A if (!in_young_gc_mode()) {
342N/A set_full_young_gcs(true);
342N/A _should_initiate_conc_mark = true;
342N/A } else
342N/A // no point in doing another partial one
342N/A _should_revert_to_full_young_gcs = true;
342N/A }
342N/A}
342N/A
342N/A// </NEW PREDICTION>
342N/A
342N/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/Adouble G1CollectorPolicy::recent_avg_time_for_pauses_ms() {
751N/A if (_recent_pause_times_ms->num() == 0) return (double) MaxGCPauseMillis;
342N/A else return _recent_pause_times_ms->avg();
342N/A}
342N/A
342N/Adouble G1CollectorPolicy::recent_avg_time_for_CH_strong_ms() {
342N/A if (_recent_CH_strong_roots_times_ms->num() == 0)
751N/A return (double)MaxGCPauseMillis/3.0;
342N/A else return _recent_CH_strong_roots_times_ms->avg();
342N/A}
342N/A
342N/Adouble G1CollectorPolicy::recent_avg_time_for_G1_strong_ms() {
342N/A if (_recent_G1_strong_roots_times_ms->num() == 0)
751N/A return (double)MaxGCPauseMillis/3.0;
342N/A else return _recent_G1_strong_roots_times_ms->avg();
342N/A}
342N/A
342N/Adouble G1CollectorPolicy::recent_avg_time_for_evac_ms() {
751N/A if (_recent_evac_times_ms->num() == 0) return (double)MaxGCPauseMillis/3.0;
342N/A else return _recent_evac_times_ms->avg();
342N/A}
342N/A
342N/Aint G1CollectorPolicy::number_of_recent_gcs() {
342N/A assert(_recent_CH_strong_roots_times_ms->num() ==
342N/A _recent_G1_strong_roots_times_ms->num(), "Sequence out of sync");
342N/A assert(_recent_G1_strong_roots_times_ms->num() ==
342N/A _recent_evac_times_ms->num(), "Sequence out of sync");
342N/A assert(_recent_evac_times_ms->num() ==
342N/A _recent_pause_times_ms->num(), "Sequence out of sync");
342N/A assert(_recent_pause_times_ms->num() ==
342N/A _recent_CS_bytes_used_before->num(), "Sequence out of sync");
342N/A assert(_recent_CS_bytes_used_before->num() ==
342N/A _recent_CS_bytes_surviving->num(), "Sequence out of sync");
342N/A return _recent_pause_times_ms->num();
342N/A}
342N/A
342N/Adouble G1CollectorPolicy::recent_avg_survival_fraction() {
342N/A return recent_avg_survival_fraction_work(_recent_CS_bytes_surviving,
342N/A _recent_CS_bytes_used_before);
342N/A}
342N/A
342N/Adouble G1CollectorPolicy::last_survival_fraction() {
342N/A return last_survival_fraction_work(_recent_CS_bytes_surviving,
342N/A _recent_CS_bytes_used_before);
342N/A}
342N/A
342N/Adouble
342N/AG1CollectorPolicy::recent_avg_survival_fraction_work(TruncatedSeq* surviving,
342N/A TruncatedSeq* before) {
342N/A assert(surviving->num() == before->num(), "Sequence out of sync");
342N/A if (before->sum() > 0.0) {
342N/A double recent_survival_rate = surviving->sum() / before->sum();
342N/A // We exempt parallel collection from this check because Alloc Buffer
342N/A // fragmentation can produce negative collections.
342N/A // Further, we're now always doing parallel collection. But I'm still
342N/A // leaving this here as a placeholder for a more precise assertion later.
342N/A // (DLD, 10/05.)
342N/A assert((true || ParallelGCThreads > 0) ||
342N/A _g1->evacuation_failed() ||
342N/A recent_survival_rate <= 1.0, "Or bad frac");
342N/A return recent_survival_rate;
342N/A } else {
342N/A return 1.0; // Be conservative.
342N/A }
342N/A}
342N/A
342N/Adouble
342N/AG1CollectorPolicy::last_survival_fraction_work(TruncatedSeq* surviving,
342N/A TruncatedSeq* before) {
342N/A assert(surviving->num() == before->num(), "Sequence out of sync");
342N/A if (surviving->num() > 0 && before->last() > 0.0) {
342N/A double last_survival_rate = surviving->last() / before->last();
342N/A // We exempt parallel collection from this check because Alloc Buffer
342N/A // fragmentation can produce negative collections.
342N/A // Further, we're now always doing parallel collection. But I'm still
342N/A // leaving this here as a placeholder for a more precise assertion later.
342N/A // (DLD, 10/05.)
342N/A assert((true || ParallelGCThreads > 0) ||
342N/A last_survival_rate <= 1.0, "Or bad frac");
342N/A return last_survival_rate;
342N/A } else {
342N/A return 1.0;
342N/A }
342N/A}
342N/A
342N/Astatic const int survival_min_obs = 5;
342N/Astatic double survival_min_obs_limits[] = { 0.9, 0.7, 0.5, 0.3, 0.1 };
342N/Astatic const double min_survival_rate = 0.1;
342N/A
342N/Adouble
342N/AG1CollectorPolicy::conservative_avg_survival_fraction_work(double avg,
342N/A double latest) {
342N/A double res = avg;
342N/A if (number_of_recent_gcs() < survival_min_obs) {
342N/A res = MAX2(res, survival_min_obs_limits[number_of_recent_gcs()]);
342N/A }
342N/A res = MAX2(res, latest);
342N/A res = MAX2(res, min_survival_rate);
342N/A // In the parallel case, LAB fragmentation can produce "negative
342N/A // collections"; so can evac failure. Cap at 1.0
342N/A res = MIN2(res, 1.0);
342N/A return res;
342N/A}
342N/A
342N/Asize_t G1CollectorPolicy::expansion_amount() {
1356N/A if ((recent_avg_pause_time_ratio() * 100.0) > _gc_overhead_perc) {
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;
342N/A size_t reserved_bytes = _g1->g1_reserved_obj_bytes();
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);
342N/A if (G1PolicyVerbose > 1) {
342N/A gclog_or_tty->print("Decided to expand: ratio = %5.2f, "
342N/A "committed = %d%s, uncommited = %d%s, via pct = %d%s.\n"
342N/A " Answer = %d.\n",
342N/A recent_avg_pause_time_ratio(),
342N/A byte_size_in_proper_unit(committed_bytes),
342N/A proper_unit_for_byte_size(committed_bytes),
342N/A byte_size_in_proper_unit(uncommitted_bytes),
342N/A proper_unit_for_byte_size(uncommitted_bytes),
342N/A byte_size_in_proper_unit(expand_bytes_via_pct),
342N/A proper_unit_for_byte_size(expand_bytes_via_pct),
342N/A byte_size_in_proper_unit(expand_bytes),
342N/A proper_unit_for_byte_size(expand_bytes));
342N/A }
342N/A return expand_bytes;
342N/A } else {
342N/A return 0;
342N/A }
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::note_start_of_mark_thread() {
342N/A _mark_thread_startup_sec = os::elapsedTime();
342N/A}
342N/A
342N/Aclass CountCSClosure: public HeapRegionClosure {
342N/A G1CollectorPolicy* _g1_policy;
342N/Apublic:
342N/A CountCSClosure(G1CollectorPolicy* g1_policy) :
342N/A _g1_policy(g1_policy) {}
342N/A bool doHeapRegion(HeapRegion* r) {
342N/A _g1_policy->_bytes_in_collection_set_before_gc += r->used();
342N/A return false;
342N/A }
342N/A};
342N/A
342N/Avoid G1CollectorPolicy::count_CS_bytes_used() {
342N/A CountCSClosure cs_closure(this);
342N/A _g1->collection_set_iterate(&cs_closure);
342N/A}
342N/A
342N/Astatic void print_indent(int level) {
342N/A for (int j = 0; j < level+1; ++j)
342N/A gclog_or_tty->print(" ");
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::print_summary (int level,
342N/A const char* str,
342N/A NumberSeq* seq) const {
342N/A double sum = seq->sum();
342N/A print_indent(level);
342N/A gclog_or_tty->print_cr("%-24s = %8.2lf s (avg = %8.2lf ms)",
342N/A str, sum / 1000.0, seq->avg());
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::print_summary_sd (int level,
342N/A const char* str,
342N/A NumberSeq* seq) const {
342N/A print_summary(level, str, seq);
342N/A print_indent(level + 5);
342N/A gclog_or_tty->print_cr("(num = %5d, std dev = %8.2lf ms, max = %8.2lf ms)",
342N/A seq->num(), seq->sd(), seq->maximum());
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::check_other_times(int level,
342N/A NumberSeq* other_times_ms,
342N/A NumberSeq* calc_other_times_ms) const {
342N/A bool should_print = false;
342N/A
342N/A double max_sum = MAX2(fabs(other_times_ms->sum()),
342N/A fabs(calc_other_times_ms->sum()));
342N/A double min_sum = MIN2(fabs(other_times_ms->sum()),
342N/A fabs(calc_other_times_ms->sum()));
342N/A double sum_ratio = max_sum / min_sum;
342N/A if (sum_ratio > 1.1) {
342N/A should_print = true;
342N/A print_indent(level + 1);
342N/A gclog_or_tty->print_cr("## CALCULATED OTHER SUM DOESN'T MATCH RECORDED ###");
342N/A }
342N/A
342N/A double max_avg = MAX2(fabs(other_times_ms->avg()),
342N/A fabs(calc_other_times_ms->avg()));
342N/A double min_avg = MIN2(fabs(other_times_ms->avg()),
342N/A fabs(calc_other_times_ms->avg()));
342N/A double avg_ratio = max_avg / min_avg;
342N/A if (avg_ratio > 1.1) {
342N/A should_print = true;
342N/A print_indent(level + 1);
342N/A gclog_or_tty->print_cr("## CALCULATED OTHER AVG DOESN'T MATCH RECORDED ###");
342N/A }
342N/A
342N/A if (other_times_ms->sum() < -0.01) {
342N/A print_indent(level + 1);
342N/A gclog_or_tty->print_cr("## RECORDED OTHER SUM IS NEGATIVE ###");
342N/A }
342N/A
342N/A if (other_times_ms->avg() < -0.01) {
342N/A print_indent(level + 1);
342N/A gclog_or_tty->print_cr("## RECORDED OTHER AVG IS NEGATIVE ###");
342N/A }
342N/A
342N/A if (calc_other_times_ms->sum() < -0.01) {
342N/A should_print = true;
342N/A print_indent(level + 1);
342N/A gclog_or_tty->print_cr("## CALCULATED OTHER SUM IS NEGATIVE ###");
342N/A }
342N/A
342N/A if (calc_other_times_ms->avg() < -0.01) {
342N/A should_print = true;
342N/A print_indent(level + 1);
342N/A gclog_or_tty->print_cr("## CALCULATED OTHER AVG IS NEGATIVE ###");
342N/A }
342N/A
342N/A if (should_print)
342N/A print_summary(level, "Other(Calc)", calc_other_times_ms);
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::print_summary(PauseSummary* summary) const {
342N/A bool parallel = ParallelGCThreads > 0;
342N/A MainBodySummary* body_summary = summary->main_body_summary();
342N/A if (summary->get_total_seq()->num() > 0) {
677N/A print_summary_sd(0, "Evacuation Pauses", summary->get_total_seq());
342N/A if (body_summary != NULL) {
342N/A print_summary(1, "SATB Drain", body_summary->get_satb_drain_seq());
342N/A if (parallel) {
342N/A print_summary(1, "Parallel Time", body_summary->get_parallel_seq());
342N/A print_summary(2, "Update RS", body_summary->get_update_rs_seq());
342N/A print_summary(2, "Ext Root Scanning",
342N/A body_summary->get_ext_root_scan_seq());
342N/A print_summary(2, "Mark Stack Scanning",
342N/A body_summary->get_mark_stack_scan_seq());
342N/A print_summary(2, "Scan-Only Scanning",
342N/A body_summary->get_scan_only_seq());
342N/A print_summary(2, "Scan RS", body_summary->get_scan_rs_seq());
342N/A print_summary(2, "Object Copy", body_summary->get_obj_copy_seq());
342N/A print_summary(2, "Termination", body_summary->get_termination_seq());
342N/A print_summary(2, "Other", body_summary->get_parallel_other_seq());
342N/A {
342N/A NumberSeq* other_parts[] = {
342N/A body_summary->get_update_rs_seq(),
342N/A body_summary->get_ext_root_scan_seq(),
342N/A body_summary->get_mark_stack_scan_seq(),
342N/A body_summary->get_scan_only_seq(),
342N/A body_summary->get_scan_rs_seq(),
342N/A body_summary->get_obj_copy_seq(),
342N/A body_summary->get_termination_seq()
342N/A };
342N/A NumberSeq calc_other_times_ms(body_summary->get_parallel_seq(),
342N/A 7, other_parts);
342N/A check_other_times(2, body_summary->get_parallel_other_seq(),
342N/A &calc_other_times_ms);
342N/A }
342N/A print_summary(1, "Mark Closure", body_summary->get_mark_closure_seq());
342N/A print_summary(1, "Clear CT", body_summary->get_clear_ct_seq());
342N/A } else {
342N/A print_summary(1, "Update RS", body_summary->get_update_rs_seq());
342N/A print_summary(1, "Ext Root Scanning",
342N/A body_summary->get_ext_root_scan_seq());
342N/A print_summary(1, "Mark Stack Scanning",
342N/A body_summary->get_mark_stack_scan_seq());
342N/A print_summary(1, "Scan-Only Scanning",
342N/A body_summary->get_scan_only_seq());
342N/A print_summary(1, "Scan RS", body_summary->get_scan_rs_seq());
342N/A print_summary(1, "Object Copy", body_summary->get_obj_copy_seq());
342N/A }
342N/A }
342N/A print_summary(1, "Other", summary->get_other_seq());
342N/A {
342N/A NumberSeq calc_other_times_ms;
342N/A if (body_summary != NULL) {
342N/A // not abandoned
342N/A if (parallel) {
342N/A // parallel
342N/A NumberSeq* other_parts[] = {
342N/A body_summary->get_satb_drain_seq(),
342N/A body_summary->get_parallel_seq(),
342N/A body_summary->get_clear_ct_seq()
342N/A };
677N/A calc_other_times_ms = NumberSeq(summary->get_total_seq(),
677N/A 3, other_parts);
342N/A } else {
342N/A // serial
342N/A NumberSeq* other_parts[] = {
342N/A body_summary->get_satb_drain_seq(),
342N/A body_summary->get_update_rs_seq(),
342N/A body_summary->get_ext_root_scan_seq(),
342N/A body_summary->get_mark_stack_scan_seq(),
342N/A body_summary->get_scan_only_seq(),
342N/A body_summary->get_scan_rs_seq(),
342N/A body_summary->get_obj_copy_seq()
342N/A };
342N/A calc_other_times_ms = NumberSeq(summary->get_total_seq(),
677N/A 7, other_parts);
342N/A }
342N/A } else {
342N/A // abandoned
677N/A calc_other_times_ms = NumberSeq();
342N/A }
342N/A check_other_times(1, summary->get_other_seq(), &calc_other_times_ms);
342N/A }
342N/A } else {
342N/A print_indent(0);
342N/A gclog_or_tty->print_cr("none");
342N/A }
342N/A gclog_or_tty->print_cr("");
342N/A}
342N/A
342N/Avoid
677N/AG1CollectorPolicy::print_abandoned_summary(PauseSummary* summary) const {
342N/A bool printed = false;
677N/A if (summary->get_total_seq()->num() > 0) {
342N/A printed = true;
677N/A print_summary(summary);
342N/A }
342N/A if (!printed) {
342N/A print_indent(0);
342N/A gclog_or_tty->print_cr("none");
342N/A gclog_or_tty->print_cr("");
342N/A }
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::print_tracing_info() const {
342N/A if (TraceGen0Time) {
342N/A gclog_or_tty->print_cr("ALL PAUSES");
342N/A print_summary_sd(0, "Total", _all_pause_times_ms);
342N/A gclog_or_tty->print_cr("");
342N/A gclog_or_tty->print_cr("");
342N/A gclog_or_tty->print_cr(" Full Young GC Pauses: %8d", _full_young_pause_num);
342N/A gclog_or_tty->print_cr(" Partial Young GC Pauses: %8d", _partial_young_pause_num);
342N/A gclog_or_tty->print_cr("");
342N/A
677N/A gclog_or_tty->print_cr("EVACUATION PAUSES");
677N/A print_summary(_summary);
342N/A
342N/A gclog_or_tty->print_cr("ABANDONED PAUSES");
677N/A print_abandoned_summary(_abandoned_summary);
342N/A
342N/A gclog_or_tty->print_cr("MISC");
342N/A print_summary_sd(0, "Stop World", _all_stop_world_times_ms);
342N/A print_summary_sd(0, "Yields", _all_yield_times_ms);
342N/A for (int i = 0; i < _aux_num; ++i) {
342N/A if (_all_aux_times_ms[i].num() > 0) {
342N/A char buffer[96];
342N/A sprintf(buffer, "Aux%d", i);
342N/A print_summary_sd(0, buffer, &_all_aux_times_ms[i]);
342N/A }
342N/A }
342N/A
342N/A size_t all_region_num = _region_num_young + _region_num_tenured;
342N/A gclog_or_tty->print_cr(" New Regions %8d, Young %8d (%6.2lf%%), "
342N/A "Tenured %8d (%6.2lf%%)",
342N/A all_region_num,
342N/A _region_num_young,
342N/A (double) _region_num_young / (double) all_region_num * 100.0,
342N/A _region_num_tenured,
342N/A (double) _region_num_tenured / (double) all_region_num * 100.0);
342N/A }
342N/A if (TraceGen1Time) {
342N/A if (_all_full_gc_times_ms->num() > 0) {
342N/A gclog_or_tty->print("\n%4d full_gcs: total time = %8.2f s",
342N/A _all_full_gc_times_ms->num(),
342N/A _all_full_gc_times_ms->sum() / 1000.0);
342N/A gclog_or_tty->print_cr(" (avg = %8.2fms).", _all_full_gc_times_ms->avg());
342N/A gclog_or_tty->print_cr(" [std. dev = %8.2f ms, max = %8.2f ms]",
342N/A _all_full_gc_times_ms->sd(),
342N/A _all_full_gc_times_ms->maximum());
342N/A }
342N/A }
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/Abool
342N/AG1CollectorPolicy::should_add_next_region_to_young_list() {
342N/A assert(in_young_gc_mode(), "should be in young GC mode");
342N/A bool ret;
342N/A size_t young_list_length = _g1->young_list_length();
545N/A size_t young_list_max_length = _young_list_target_length;
545N/A if (G1FixedEdenSize) {
545N/A young_list_max_length -= _max_survivor_regions;
545N/A }
545N/A if (young_list_length < young_list_max_length) {
342N/A ret = true;
342N/A ++_region_num_young;
342N/A } else {
342N/A ret = false;
342N/A ++_region_num_tenured;
342N/A }
342N/A
342N/A return ret;
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
545N/Asize_t 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
545N/A// Calculates survivor space parameters.
545N/Avoid G1CollectorPolicy::calculate_survivors_policy()
545N/A{
545N/A if (G1FixedSurvivorSpaceSize == 0) {
545N/A _max_survivor_regions = _young_list_target_length / SurvivorRatio;
545N/A } else {
547N/A _max_survivor_regions = G1FixedSurvivorSpaceSize / HeapRegion::GrainBytes;
545N/A }
545N/A
545N/A if (G1FixedTenuringThreshold) {
545N/A _tenuring_threshold = MaxTenuringThreshold;
545N/A } else {
545N/A _tenuring_threshold = _survivors_age_table.compute_tenuring_threshold(
545N/A HeapRegion::GrainWords * _max_survivor_regions);
545N/A }
545N/A}
545N/A
342N/Abool
342N/AG1CollectorPolicy_BestRegionsFirst::should_do_collection_pause(size_t
342N/A word_size) {
342N/A assert(_g1->regions_accounted_for(), "Region leakage!");
342N/A double max_pause_time_ms = _mmu_tracker->max_gc_time() * 1000.0;
342N/A
342N/A size_t young_list_length = _g1->young_list_length();
545N/A size_t young_list_max_length = _young_list_target_length;
545N/A if (G1FixedEdenSize) {
545N/A young_list_max_length -= _max_survivor_regions;
545N/A }
545N/A bool reached_target_length = young_list_length >= young_list_max_length;
342N/A
342N/A if (in_young_gc_mode()) {
342N/A if (reached_target_length) {
342N/A assert( young_list_length > 0 && _g1->young_list_length() > 0,
342N/A "invariant" );
342N/A _target_pause_time_ms = max_pause_time_ms;
342N/A return true;
342N/A }
342N/A } else {
342N/A guarantee( false, "should not reach here" );
342N/A }
342N/A
342N/A return false;
342N/A}
342N/A
342N/A#ifndef PRODUCT
342N/Aclass HRSortIndexIsOKClosure: public HeapRegionClosure {
342N/A CollectionSetChooser* _chooser;
342N/Apublic:
342N/A HRSortIndexIsOKClosure(CollectionSetChooser* chooser) :
342N/A _chooser(chooser) {}
342N/A
342N/A bool doHeapRegion(HeapRegion* r) {
342N/A if (!r->continuesHumongous()) {
342N/A assert(_chooser->regionProperlyOrdered(r), "Ought to be.");
342N/A }
342N/A return false;
342N/A }
342N/A};
342N/A
342N/Abool G1CollectorPolicy_BestRegionsFirst::assertMarkedBytesDataOK() {
342N/A HRSortIndexIsOKClosure cl(_collectionSetChooser);
342N/A _g1->heap_region_iterate(&cl);
342N/A return true;
342N/A}
342N/A#endif
342N/A
342N/Avoid
342N/AG1CollectorPolicy_BestRegionsFirst::
342N/Arecord_collection_pause_start(double start_time_sec, size_t start_used) {
342N/A G1CollectorPolicy::record_collection_pause_start(start_time_sec, start_used);
342N/A}
342N/A
342N/Aclass NextNonCSElemFinder: public HeapRegionClosure {
342N/A HeapRegion* _res;
342N/Apublic:
342N/A NextNonCSElemFinder(): _res(NULL) {}
342N/A bool doHeapRegion(HeapRegion* r) {
342N/A if (!r->in_collection_set()) {
342N/A _res = r;
342N/A return true;
342N/A } else {
342N/A return false;
342N/A }
342N/A }
342N/A HeapRegion* res() { return _res; }
342N/A};
342N/A
342N/Aclass KnownGarbageClosure: public HeapRegionClosure {
342N/A CollectionSetChooser* _hrSorted;
342N/A
342N/Apublic:
342N/A KnownGarbageClosure(CollectionSetChooser* hrSorted) :
342N/A _hrSorted(hrSorted)
342N/A {}
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()) {
342N/A // We don't include humongous regions in collection
342N/A // sets because we collect them immediately at the end of a marking
342N/A // cycle. We also don't include young regions because we *must*
342N/A // include them in the next collection pause.
342N/A if (!r->isHumongous() && !r->is_young()) {
342N/A _hrSorted->addMarkedHeapRegion(r);
342N/A }
342N/A }
342N/A return false;
342N/A }
342N/A};
342N/A
342N/Aclass ParKnownGarbageHRClosure: public HeapRegionClosure {
342N/A CollectionSetChooser* _hrSorted;
342N/A jint _marked_regions_added;
342N/A jint _chunk_size;
342N/A jint _cur_chunk_idx;
342N/A jint _cur_chunk_end; // Cur chunk [_cur_chunk_idx, _cur_chunk_end)
342N/A int _worker;
342N/A int _invokes;
342N/A
342N/A void get_new_chunk() {
342N/A _cur_chunk_idx = _hrSorted->getParMarkedHeapRegionChunk(_chunk_size);
342N/A _cur_chunk_end = _cur_chunk_idx + _chunk_size;
342N/A }
342N/A void add_region(HeapRegion* r) {
342N/A if (_cur_chunk_idx == _cur_chunk_end) {
342N/A get_new_chunk();
342N/A }
342N/A assert(_cur_chunk_idx < _cur_chunk_end, "postcondition");
342N/A _hrSorted->setMarkedHeapRegion(_cur_chunk_idx, r);
342N/A _marked_regions_added++;
342N/A _cur_chunk_idx++;
342N/A }
342N/A
342N/Apublic:
342N/A ParKnownGarbageHRClosure(CollectionSetChooser* hrSorted,
342N/A jint chunk_size,
342N/A int worker) :
342N/A _hrSorted(hrSorted), _chunk_size(chunk_size), _worker(worker),
342N/A _marked_regions_added(0), _cur_chunk_idx(0), _cur_chunk_end(0),
342N/A _invokes(0)
342N/A {}
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 _invokes++;
342N/A
342N/A // Do we have any marking information for this region?
342N/A if (r->is_marked()) {
342N/A // We don't include humongous regions in collection
342N/A // sets because we collect them immediately at the end of a marking
342N/A // cycle.
342N/A // We also do not include young regions in collection sets
342N/A if (!r->isHumongous() && !r->is_young()) {
342N/A add_region(r);
342N/A }
342N/A }
342N/A return false;
342N/A }
342N/A jint marked_regions_added() { return _marked_regions_added; }
342N/A int invokes() { return _invokes; }
342N/A};
342N/A
342N/Aclass ParKnownGarbageTask: public AbstractGangTask {
342N/A CollectionSetChooser* _hrSorted;
342N/A jint _chunk_size;
342N/A G1CollectedHeap* _g1;
342N/Apublic:
342N/A ParKnownGarbageTask(CollectionSetChooser* hrSorted, jint chunk_size) :
342N/A AbstractGangTask("ParKnownGarbageTask"),
342N/A _hrSorted(hrSorted), _chunk_size(chunk_size),
342N/A _g1(G1CollectedHeap::heap())
342N/A {}
342N/A
342N/A void work(int i) {
342N/A ParKnownGarbageHRClosure parKnownGarbageCl(_hrSorted, _chunk_size, i);
342N/A // Back to zero for the claim value.
355N/A _g1->heap_region_par_iterate_chunked(&parKnownGarbageCl, i,
355N/A HeapRegion::InitialClaimValue);
342N/A jint regions_added = parKnownGarbageCl.marked_regions_added();
342N/A _hrSorted->incNumMarkedHeapRegions(regions_added);
342N/A if (G1PrintParCleanupStats) {
342N/A gclog_or_tty->print(" Thread %d called %d times, added %d regions to list.\n",
342N/A i, parKnownGarbageCl.invokes(), regions_added);
342N/A }
342N/A }
342N/A};
342N/A
342N/Avoid
342N/AG1CollectorPolicy_BestRegionsFirst::
342N/Arecord_concurrent_mark_cleanup_end(size_t freed_bytes,
342N/A size_t max_live_bytes) {
342N/A double start;
342N/A if (G1PrintParCleanupStats) start = os::elapsedTime();
342N/A record_concurrent_mark_cleanup_end_work1(freed_bytes, max_live_bytes);
342N/A
342N/A _collectionSetChooser->clearMarkedHeapRegions();
342N/A double clear_marked_end;
342N/A if (G1PrintParCleanupStats) {
342N/A clear_marked_end = os::elapsedTime();
342N/A gclog_or_tty->print_cr(" clear marked regions + work1: %8.3f ms.",
342N/A (clear_marked_end - start)*1000.0);
342N/A }
342N/A if (ParallelGCThreads > 0) {
342N/A const size_t OverpartitionFactor = 4;
342N/A const size_t MinChunkSize = 8;
342N/A const size_t ChunkSize =
342N/A MAX2(_g1->n_regions() / (ParallelGCThreads * OverpartitionFactor),
342N/A MinChunkSize);
342N/A _collectionSetChooser->prepareForAddMarkedHeapRegionsPar(_g1->n_regions(),
342N/A ChunkSize);
342N/A ParKnownGarbageTask parKnownGarbageTask(_collectionSetChooser,
342N/A (int) ChunkSize);
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 }
342N/A double known_garbage_end;
342N/A if (G1PrintParCleanupStats) {
342N/A known_garbage_end = os::elapsedTime();
342N/A gclog_or_tty->print_cr(" compute known garbage: %8.3f ms.",
342N/A (known_garbage_end - clear_marked_end)*1000.0);
342N/A }
342N/A _collectionSetChooser->sortMarkedHeapRegions();
342N/A double sort_end;
342N/A if (G1PrintParCleanupStats) {
342N/A sort_end = os::elapsedTime();
342N/A gclog_or_tty->print_cr(" sorting: %8.3f ms.",
342N/A (sort_end - known_garbage_end)*1000.0);
342N/A }
342N/A
342N/A record_concurrent_mark_cleanup_end_work2();
342N/A double work2_end;
342N/A if (G1PrintParCleanupStats) {
342N/A work2_end = os::elapsedTime();
342N/A gclog_or_tty->print_cr(" work2: %8.3f ms.",
342N/A (work2_end - sort_end)*1000.0);
342N/A }
342N/A}
342N/A
342N/A// Add the heap region to the collection set and return the conservative
342N/A// estimate of the number of live bytes.
342N/Avoid G1CollectorPolicy::
342N/Aadd_to_collection_set(HeapRegion* hr) {
1282N/A if (G1PrintHeapRegions) {
342N/A gclog_or_tty->print_cr("added region to cset %d:["PTR_FORMAT", "PTR_FORMAT"], "
342N/A "top "PTR_FORMAT", young %s",
342N/A hr->hrs_index(), hr->bottom(), hr->end(),
342N/A hr->top(), (hr->is_young()) ? "YES" : "NO");
342N/A }
342N/A
342N/A if (_g1->mark_in_progress())
342N/A _g1->concurrent_mark()->registerCSetRegion(hr);
342N/A
342N/A assert(!hr->in_collection_set(),
342N/A "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_size++;
342N/A _collection_set_bytes_used_before += hr->used();
526N/A _g1->register_region_with_in_cset_fast_test(hr);
342N/A}
342N/A
342N/Avoid
342N/AG1CollectorPolicy_BestRegionsFirst::
677N/Achoose_collection_set() {
342N/A double non_young_start_time_sec;
342N/A start_recording_regions();
342N/A
1088N/A guarantee(_target_pause_time_ms > -1.0
1088N/A NOT_PRODUCT(|| Universe::heap()->gc_cause() == GCCause::_scavenge_alot),
677N/A "_target_pause_time_ms should have been set!");
1088N/A#ifndef PRODUCT
1088N/A if (_target_pause_time_ms <= -1.0) {
1088N/A assert(ScavengeALot && Universe::heap()->gc_cause() == GCCause::_scavenge_alot, "Error");
1088N/A _target_pause_time_ms = _mmu_tracker->max_gc_time() * 1000.0;
1088N/A }
1088N/A#endif
677N/A assert(_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;
342N/A
342N/A double target_time_ms = _target_pause_time_ms;
342N/A double time_remaining_ms = target_time_ms - base_time_ms;
342N/A
342N/A // the 10% and 50% values are arbitrary...
342N/A if (time_remaining_ms < 0.10*target_time_ms) {
342N/A time_remaining_ms = 0.50 * target_time_ms;
342N/A _within_target = false;
342N/A } else {
342N/A _within_target = true;
342N/A }
342N/A
342N/A // We figure out the number of bytes available for future to-space.
342N/A // For new regions without marking information, we must assume the
342N/A // worst-case of complete survival. If we have marking information for a
342N/A // region, we can bound the amount of live data. We can add a number of
342N/A // such regions, as long as the sum of the live data bounds does not
342N/A // exceed the available evacuation space.
342N/A size_t max_live_bytes = _g1->free_regions() * HeapRegion::GrainBytes;
342N/A
342N/A size_t expansion_bytes =
342N/A _g1->expansion_regions() * HeapRegion::GrainBytes;
342N/A
677N/A _collection_set_bytes_used_before = 0;
677N/A _collection_set_size = 0;
342N/A
342N/A // Adjust for expansion and slop.
342N/A max_live_bytes = max_live_bytes + expansion_bytes;
342N/A
677N/A assert(_g1->regions_accounted_for(), "Region leakage!");
342N/A
342N/A HeapRegion* hr;
342N/A if (in_young_gc_mode()) {
342N/A double young_start_time_sec = os::elapsedTime();
342N/A
342N/A if (G1PolicyVerbose > 0) {
342N/A gclog_or_tty->print_cr("Adding %d young regions to the CSet",
342N/A _g1->young_list_length());
342N/A }
342N/A _young_cset_length = 0;
342N/A _last_young_gc_full = full_young_gcs() ? true : false;
342N/A if (_last_young_gc_full)
342N/A ++_full_young_pause_num;
342N/A else
342N/A ++_partial_young_pause_num;
342N/A hr = _g1->pop_region_from_young_list();
342N/A while (hr != NULL) {
342N/A
342N/A assert( hr->young_index_in_cset() == -1, "invariant" );
342N/A assert( hr->age_in_surv_rate_group() != -1, "invariant" );
342N/A hr->set_young_index_in_cset((int) _young_cset_length);
342N/A
342N/A ++_young_cset_length;
342N/A double predicted_time_ms = predict_region_elapsed_time_ms(hr, true);
342N/A time_remaining_ms -= predicted_time_ms;
342N/A predicted_pause_time_ms += predicted_time_ms;
677N/A assert(!hr->in_collection_set(), "invariant");
677N/A add_to_collection_set(hr);
677N/A record_cset_region(hr, true);
342N/A max_live_bytes -= MIN2(hr->max_live_bytes(), max_live_bytes);
342N/A if (G1PolicyVerbose > 0) {
342N/A gclog_or_tty->print_cr(" Added [" PTR_FORMAT ", " PTR_FORMAT") to CS.",
342N/A hr->bottom(), hr->end());
342N/A gclog_or_tty->print_cr(" (" SIZE_FORMAT " KB left in heap.)",
342N/A max_live_bytes/K);
342N/A }
342N/A hr = _g1->pop_region_from_young_list();
342N/A }
342N/A
342N/A record_scan_only_regions(_g1->young_list_scan_only_length());
342N/A
342N/A double young_end_time_sec = os::elapsedTime();
342N/A _recorded_young_cset_choice_time_ms =
342N/A (young_end_time_sec - young_start_time_sec) * 1000.0;
342N/A
342N/A non_young_start_time_sec = os::elapsedTime();
342N/A
342N/A if (_young_cset_length > 0 && _last_young_gc_full) {
342N/A // don't bother adding more regions...
342N/A goto choose_collection_set_end;
342N/A }
342N/A }
342N/A
342N/A if (!in_young_gc_mode() || !full_young_gcs()) {
342N/A bool should_continue = true;
342N/A NumberSeq seq;
342N/A double avg_prediction = 100000000000000000.0; // something very large
342N/A do {
342N/A hr = _collectionSetChooser->getNextMarkedRegion(time_remaining_ms,
342N/A avg_prediction);
677N/A if (hr != NULL) {
342N/A double predicted_time_ms = predict_region_elapsed_time_ms(hr, false);
342N/A time_remaining_ms -= predicted_time_ms;
342N/A predicted_pause_time_ms += predicted_time_ms;
342N/A add_to_collection_set(hr);
342N/A record_cset_region(hr, false);
342N/A max_live_bytes -= MIN2(hr->max_live_bytes(), max_live_bytes);
342N/A if (G1PolicyVerbose > 0) {
342N/A gclog_or_tty->print_cr(" (" SIZE_FORMAT " KB left in heap.)",
342N/A max_live_bytes/K);
342N/A }
342N/A seq.add(predicted_time_ms);
342N/A avg_prediction = seq.avg() + seq.sd();
342N/A }
342N/A should_continue =
342N/A ( hr != NULL) &&
342N/A ( (adaptive_young_list_length()) ? time_remaining_ms > 0.0
342N/A : _collection_set_size < _young_list_fixed_length );
342N/A } while (should_continue);
342N/A
342N/A if (!adaptive_young_list_length() &&
342N/A _collection_set_size < _young_list_fixed_length)
342N/A _should_revert_to_full_young_gcs = true;
342N/A }
342N/A
342N/Achoose_collection_set_end:
342N/A count_CS_bytes_used();
342N/A
342N/A end_recording_regions();
342N/A
342N/A double non_young_end_time_sec = os::elapsedTime();
342N/A _recorded_non_young_cset_choice_time_ms =
342N/A (non_young_end_time_sec - non_young_start_time_sec) * 1000.0;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy_BestRegionsFirst::record_full_collection_end() {
342N/A G1CollectorPolicy::record_full_collection_end();
342N/A _collectionSetChooser->updateAfterFullCollection();
342N/A}
342N/A
342N/Avoid G1CollectorPolicy_BestRegionsFirst::
342N/Aexpand_if_possible(size_t numRegions) {
342N/A size_t expansion_bytes = numRegions * HeapRegion::GrainBytes;
342N/A _g1->expand(expansion_bytes);
342N/A}
342N/A
342N/Avoid G1CollectorPolicy_BestRegionsFirst::
677N/Arecord_collection_pause_end(bool abandoned) {
677N/A G1CollectorPolicy::record_collection_pause_end(abandoned);
342N/A assert(assertMarkedBytesDataOK(), "Marked regions not OK at pause end.");
342N/A}