g1CollectorPolicy.cpp revision 2748
342N/A/*
2037N/A * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
342N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
342N/A *
342N/A * This code is free software; you can redistribute it and/or modify it
342N/A * under the terms of the GNU General Public License version 2 only, as
342N/A * published by the Free Software Foundation.
342N/A *
342N/A * This code is distributed in the hope that it will be useful, but WITHOUT
342N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
342N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
342N/A * version 2 for more details (a copy is included in the LICENSE file that
342N/A * accompanied this code).
342N/A *
342N/A * You should have received a copy of the GNU General Public License version
342N/A * 2 along with this work; if not, write to the Free Software Foundation,
342N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
342N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
342N/A *
342N/A */
342N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "gc_implementation/g1/concurrentG1Refine.hpp"
1879N/A#include "gc_implementation/g1/concurrentMark.hpp"
1879N/A#include "gc_implementation/g1/concurrentMarkThread.inline.hpp"
1879N/A#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
1879N/A#include "gc_implementation/g1/g1CollectorPolicy.hpp"
2748N/A#include "gc_implementation/g1/g1ErgoVerbose.hpp"
1879N/A#include "gc_implementation/g1/heapRegionRemSet.hpp"
1879N/A#include "gc_implementation/shared/gcPolicyCounters.hpp"
1879N/A#include "runtime/arguments.hpp"
1879N/A#include "runtime/java.hpp"
1879N/A#include "runtime/mutexLocker.hpp"
1879N/A#include "utilities/debug.hpp"
342N/A
342N/A#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/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
2210N/A// Help class for avoiding interleaved logging
2210N/Aclass LineBuffer: public StackObj {
2210N/A
2210N/Aprivate:
2210N/A static const int BUFFER_LEN = 1024;
2210N/A static const int INDENT_CHARS = 3;
2210N/A char _buffer[BUFFER_LEN];
2210N/A int _indent_level;
2210N/A int _cur;
2210N/A
2210N/A void vappend(const char* format, va_list ap) {
2210N/A int res = vsnprintf(&_buffer[_cur], BUFFER_LEN - _cur, format, ap);
2210N/A if (res != -1) {
2210N/A _cur += res;
2210N/A } else {
2210N/A DEBUG_ONLY(warning("buffer too small in LineBuffer");)
2210N/A _buffer[BUFFER_LEN -1] = 0;
2210N/A _cur = BUFFER_LEN; // vsnprintf above should not add to _buffer if we are called again
2210N/A }
2210N/A }
2210N/A
2210N/Apublic:
2210N/A explicit LineBuffer(int indent_level): _indent_level(indent_level), _cur(0) {
2210N/A for (; (_cur < BUFFER_LEN && _cur < (_indent_level * INDENT_CHARS)); _cur++) {
2210N/A _buffer[_cur] = ' ';
2210N/A }
2210N/A }
2210N/A
2210N/A#ifndef PRODUCT
2210N/A ~LineBuffer() {
2210N/A assert(_cur == _indent_level * INDENT_CHARS, "pending data in buffer - append_and_print_cr() not called?");
2210N/A }
2210N/A#endif
2210N/A
2210N/A void append(const char* format, ...) {
2210N/A va_list ap;
2210N/A va_start(ap, format);
2210N/A vappend(format, ap);
2210N/A va_end(ap);
2210N/A }
2210N/A
2210N/A void append_and_print_cr(const char* format, ...) {
2210N/A va_list ap;
2210N/A va_start(ap, format);
2210N/A vappend(format, ap);
2210N/A va_end(ap);
2210N/A gclog_or_tty->print_cr("%s", _buffer);
2210N/A _cur = _indent_level * INDENT_CHARS;
2210N/A }
2210N/A};
2210N/A
342N/AG1CollectorPolicy::G1CollectorPolicy() :
1753N/A _parallel_gc_threads(G1CollectedHeap::use_parallel_gc_threads()
2648N/A ? ParallelGCThreads : 1),
1753N/A
342N/A _n_pauses(0),
2648N/A _recent_rs_scan_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()),
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_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 _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 _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 _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
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),
1359N/A _initiate_conc_mark_if_possible(false),
1359N/A _during_initial_mark_pause(false),
342N/A _should_revert_to_full_young_gcs(false),
342N/A _last_full_young_gc(false),
342N/A
2589N/A _eden_bytes_before_gc(0),
2589N/A _survivor_bytes_before_gc(0),
2589N/A _capacity_before_gc(0),
2589N/A
342N/A _prev_collection_pause_used_at_end_bytes(0),
342N/A
342N/A _collection_set(NULL),
1394N/A _collection_set_size(0),
1394N/A _collection_set_bytes_used_before(0),
1394N/A
1394N/A // Incremental CSet attributes
1394N/A _inc_cset_build_state(Inactive),
1394N/A _inc_cset_head(NULL),
1394N/A _inc_cset_tail(NULL),
1394N/A _inc_cset_size(0),
1394N/A _inc_cset_young_index(0),
1394N/A _inc_cset_bytes_used_before(0),
1394N/A _inc_cset_max_finger(NULL),
1394N/A _inc_cset_recorded_young_bytes(0),
1394N/A _inc_cset_recorded_rs_lengths(0),
1394N/A _inc_cset_predicted_elapsed_time_ms(0.0),
1394N/A _inc_cset_predicted_bytes_to_copy(0),
1394N/A
342N/A#ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away
342N/A#pragma warning( disable:4355 ) // 'this' : used in base member initializer list
342N/A#endif // _MSC_VER
342N/A
342N/A _short_lived_surv_rate_group(new SurvRateGroup(this, "Short Lived",
342N/A G1YoungSurvRateNumRegionsSummary)),
342N/A _survivor_surv_rate_group(new SurvRateGroup(this, "Survivor",
545N/A G1YoungSurvRateNumRegionsSummary)),
342N/A // add here any more surv rate groups
545N/A _recorded_survivor_regions(0),
545N/A _recorded_survivor_head(NULL),
545N/A _recorded_survivor_tail(NULL),
1356N/A _survivors_age_table(true),
1356N/A
2748N/A _gc_overhead_perc(0.0) {
2748N/A
942N/A // Set up the region size and associated fields. Given that the
942N/A // policy is created before the heap, we have to set this up here,
942N/A // so it's done as soon as possible.
942N/A HeapRegion::setup_heap_region_size(Arguments::min_heap_size());
1261N/A HeapRegionRemSet::setup_remset_size();
942N/A
2748N/A G1ErgoVerbose::initialize();
2748N/A if (PrintAdaptiveSizePolicy) {
2748N/A // Currently, we only use a single switch for all the heuristics.
2748N/A G1ErgoVerbose::set_enabled(true);
2748N/A // Given that we don't currently have a verboseness level
2748N/A // parameter, we'll hardcode this to high. This can be easily
2748N/A // changed in the future.
2748N/A G1ErgoVerbose::set_level(ErgoHigh);
2748N/A } else {
2748N/A G1ErgoVerbose::set_enabled(false);
2748N/A }
2748N/A
1391N/A // Verify PLAB sizes
1391N/A const uint region_size = HeapRegion::GrainWords;
1391N/A if (YoungPLABSize > region_size || OldPLABSize > region_size) {
1391N/A char buffer[128];
1391N/A jio_snprintf(buffer, sizeof(buffer), "%sPLABSize should be at most %u",
1391N/A OldPLABSize > region_size ? "Old" : "Young", region_size);
1391N/A vm_exit_during_initialization(buffer);
1391N/A }
1391N/A
342N/A _recent_prev_end_times_for_all_gcs_sec->add(os::elapsedTime());
342N/A _prev_collection_pause_end_ms = os::elapsedTime() * 1000.0;
342N/A
1531N/A _par_last_gc_worker_start_times_ms = new double[_parallel_gc_threads];
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
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_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];
1531N/A _par_last_termination_attempts = new double[_parallel_gc_threads];
1531N/A _par_last_gc_worker_end_times_ms = new double[_parallel_gc_threads];
2277N/A _par_last_gc_worker_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 _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
1530N/A // Below, we might need to calculate the pause time target based on
1530N/A // the pause interval. When we do so we are going to give G1 maximum
1530N/A // flexibility and allow it to do pauses when it needs to. So, we'll
1530N/A // arrange that the pause interval to be pause time target + 1 to
1530N/A // ensure that a) the pause time target is maximized with respect to
1530N/A // the pause interval and b) we maintain the invariant that pause
1530N/A // time target < pause interval. If the user does not want this
1530N/A // maximum flexibility, they will have to set the pause interval
1530N/A // explicitly.
1530N/A
1530N/A // First make sure that, if either parameter is set, its value is
1530N/A // reasonable.
1530N/A if (!FLAG_IS_DEFAULT(MaxGCPauseMillis)) {
1530N/A if (MaxGCPauseMillis < 1) {
1530N/A vm_exit_during_initialization("MaxGCPauseMillis should be "
1530N/A "greater than 0");
1530N/A }
1530N/A }
1530N/A if (!FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
1530N/A if (GCPauseIntervalMillis < 1) {
1530N/A vm_exit_during_initialization("GCPauseIntervalMillis should be "
1530N/A "greater than 0");
1530N/A }
1530N/A }
1530N/A
1530N/A // Then, if the pause time target parameter was not set, set it to
1530N/A // the default value.
1530N/A if (FLAG_IS_DEFAULT(MaxGCPauseMillis)) {
1530N/A if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
1530N/A // The default pause time target in G1 is 200ms
1530N/A FLAG_SET_DEFAULT(MaxGCPauseMillis, 200);
1530N/A } else {
1530N/A // We do not allow the pause interval to be set without the
1530N/A // pause time target
1530N/A vm_exit_during_initialization("GCPauseIntervalMillis cannot be set "
1530N/A "without setting MaxGCPauseMillis");
1530N/A }
1530N/A }
1530N/A
1530N/A // Then, if the interval parameter was not set, set it according to
1530N/A // the pause time target (this will also deal with the case when the
1530N/A // pause time target is the default value).
1530N/A if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
1530N/A FLAG_SET_DEFAULT(GCPauseIntervalMillis, MaxGCPauseMillis + 1);
1530N/A }
1530N/A
1530N/A // Finally, make sure that the two parameters are consistent.
1530N/A if (MaxGCPauseMillis >= GCPauseIntervalMillis) {
1530N/A char buffer[256];
1530N/A jio_snprintf(buffer, 256,
1530N/A "MaxGCPauseMillis (%u) should be less than "
1530N/A "GCPauseIntervalMillis (%u)",
1530N/A MaxGCPauseMillis, GCPauseIntervalMillis);
1530N/A vm_exit_during_initialization(buffer);
1530N/A }
1530N/A
751N/A double max_gc_time = (double) MaxGCPauseMillis / 1000.0;
1530N/A double time_slice = (double) GCPauseIntervalMillis / 1000.0;
342N/A _mmu_tracker = new G1MMUTrackerQueue(time_slice, max_gc_time);
751N/A _sigma = (double) G1ConfidencePercent / 100.0;
342N/A
342N/A // start conservatively (around 50ms is about right)
342N/A _concurrent_mark_remark_times_ms->add(0.05);
342N/A _concurrent_mark_cleanup_times_ms->add(0.20);
342N/A _tenuring_threshold = MaxTenuringThreshold;
2696N/A // _max_survivor_regions will be calculated by
2696N/A // calculate_young_list_target_length() during initialization.
2696N/A _max_survivor_regions = 0;
545N/A
1356N/A assert(GCTimeRatio > 0,
1356N/A "we should have set it to a default value set_g1_gc_flags() "
1356N/A "if a user set it to 0");
1356N/A _gc_overhead_perc = 100.0 * (1.0 / (1.0 + GCTimeRatio));
1356N/A
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
2695N/A G1YoungGenSizer sizer;
2695N/A size_t initial_region_num = sizer.initial_young_region_num();
2695N/A
2695N/A if (UseAdaptiveSizePolicy) {
2695N/A set_adaptive_young_list_length(true);
2695N/A _young_list_fixed_length = 0;
1394N/A } else {
2695N/A set_adaptive_young_list_length(false);
2695N/A _young_list_fixed_length = initial_region_num;
342N/A }
2695N/A _free_regions_at_end_of_collection = _g1->free_regions();
2695N/A calculate_young_list_min_length();
2695N/A guarantee( _young_list_min_length == 0, "invariant, not enough info" );
2695N/A calculate_young_list_target_length();
1394N/A
1394N/A // We may immediately start allocating regions and placing them on the
1394N/A // collection set list. Initialize the per-collection set info
1394N/A start_incremental_cset_building();
342N/A}
342N/A
545N/A// Create the jstat counters for the policy.
545N/Avoid G1CollectorPolicy::initialize_gc_policy_counters()
545N/A{
2695N/A _gc_policy_counters = new GCPolicyCounters("GarbageFirst", 1, 3);
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();
1880N/A size_t min_regions = (size_t) ceil(alloc_rate_ms * when_ms);
1880N/A size_t current_region_num = _g1->young_list()->length();
342N/A _young_list_min_length = min_regions + current_region_num;
342N/A }
342N/A}
342N/A
1394N/Avoid G1CollectorPolicy::calculate_young_list_target_length() {
342N/A if (adaptive_young_list_length()) {
342N/A size_t rs_lengths = (size_t) get_new_prediction(_rs_lengths_seq);
1394N/A calculate_young_list_target_length(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 }
1880N/A
1880N/A // Make sure we allow the application to allocate at least one
1880N/A // region before we need to do a collection again.
1880N/A size_t min_length = _g1->young_list()->length() + 1;
1880N/A _young_list_target_length = MAX2(_young_list_target_length, min_length);
1898N/A calculate_max_gc_locker_expansion();
545N/A calculate_survivors_policy();
342N/A}
342N/A
1394N/Avoid G1CollectorPolicy::calculate_young_list_target_length(size_t rs_lengths) {
342N/A guarantee( adaptive_young_list_length(), "pre-condition" );
1394N/A guarantee( !_in_marking_window || !_last_full_young_gc, "invariant" );
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 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();
1394N/A size_t scanned_cards = predict_young_card_num(adj_rs_lengths);
545N/A double base_time_ms = predict_base_elapsed_time_ms(pending_cards, scanned_cards)
545N/A + survivor_regions_evac_time;
1394N/A
342N/A // the result
342N/A size_t final_young_length = 0;
1394N/A
1394N/A size_t init_free_regions =
1394N/A MAX2((size_t)0, _free_regions_at_end_of_collection - reserve_regions);
1394N/A
1394N/A // if we're still under the pause target...
1394N/A if (base_time_ms <= target_pause_time_ms) {
1394N/A // We make sure that the shortest young length that makes sense
1394N/A // fits within the target pause time.
1394N/A size_t min_young_length = 1;
1394N/A
1394N/A if (predict_will_fit(min_young_length, base_time_ms,
1394N/A init_free_regions, target_pause_time_ms)) {
1394N/A // The shortest young length will fit within the target pause time;
1394N/A // we'll now check whether the absolute maximum number of young
1394N/A // regions will fit in the target pause time. If not, we'll do
1394N/A // a binary search between min_young_length and max_young_length
1394N/A size_t abs_max_young_length = _free_regions_at_end_of_collection - 1;
1394N/A size_t max_young_length = abs_max_young_length;
1394N/A
1394N/A if (max_young_length > min_young_length) {
1394N/A // Let's check if the initial max young length will fit within the
1394N/A // target pause. If so then there is no need to search for a maximal
1394N/A // young length - we'll return the initial maximum
1394N/A
1394N/A if (predict_will_fit(max_young_length, base_time_ms,
1394N/A init_free_regions, target_pause_time_ms)) {
1394N/A // The maximum young length will satisfy the target pause time.
1394N/A // We are done so set min young length to this maximum length.
1394N/A // The code after the loop will then set final_young_length using
1394N/A // the value cached in the minimum length.
1394N/A min_young_length = max_young_length;
1394N/A } else {
1394N/A // The maximum possible number of young regions will not fit within
1394N/A // the target pause time so let's search....
342N/A
342N/A size_t diff = (max_young_length - min_young_length) / 2;
1394N/A max_young_length = min_young_length + diff;
1394N/A
1394N/A while (max_young_length > min_young_length) {
1394N/A if (predict_will_fit(max_young_length, base_time_ms,
1394N/A init_free_regions, target_pause_time_ms)) {
1394N/A
1394N/A // The current max young length will fit within the target
1394N/A // pause time. Note we do not exit the loop here. By setting
1394N/A // min = max, and then increasing the max below means that
1394N/A // we will continue searching for an upper bound in the
1394N/A // range [max..max+diff]
1394N/A min_young_length = max_young_length;
1394N/A }
1394N/A diff = (max_young_length - min_young_length) / 2;
1394N/A max_young_length = min_young_length + diff;
342N/A }
1394N/A // the above loop found a maximal young length that will fit
1394N/A // within the target pause time.
342N/A }
1394N/A assert(min_young_length <= abs_max_young_length, "just checking");
342N/A }
1394N/A final_young_length = min_young_length;
342N/A }
342N/A }
1394N/A // and we're done!
342N/A
342N/A // we should have at least one region in the target young length
545N/A _young_list_target_length =
1880N/A final_young_length + _recorded_survivor_regions;
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
1394N/A#ifdef TRACE_CALC_YOUNG_LENGTH
342N/A // leave this in for debugging, just in case
1394N/A gclog_or_tty->print_cr("target = %1.1lf ms, young = " SIZE_FORMAT ", "
1394N/A "elapsed %1.2lf ms, (%s%s) " SIZE_FORMAT SIZE_FORMAT,
342N/A target_pause_time_ms,
1394N/A _young_list_target_length
342N/A elapsed_time_ms,
342N/A full_young_gcs() ? "full" : "partial",
1359N/A during_initial_mark_pause() ? " i-m" : "",
545N/A _in_marking_window,
545N/A _in_marking_window_im);
1394N/A#endif // TRACE_CALC_YOUNG_LENGTH
342N/A
342N/A if (_young_list_target_length < _young_list_min_length) {
1394N/A // bummer; this means that, if we do a pause when the maximal
1394N/A // length 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
1394N/A#ifdef TRACE_CALC_YOUNG_LENGTH
342N/A // leave this in for debugging, just in case
342N/A gclog_or_tty->print_cr("adjusted target length from "
1394N/A SIZE_FORMAT " to " SIZE_FORMAT,
1394N/A _young_list_target_length, _young_list_min_length);
1394N/A#endif // TRACE_CALC_YOUNG_LENGTH
1394N/A
1394N/A _young_list_target_length = _young_list_min_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
1394N/A#ifdef TRACE_CALC_YOUNG_LENGTH
342N/A // leave this in for debugging, just in case
342N/A gclog_or_tty->print_cr("(partial) setting target to " SIZE_FORMAT
1394N/A _young_list_min_length);
1394N/A#endif // TRACE_CALC_YOUNG_LENGTH
1394N/A // we'll do the pause as soon as possible by choosing the minimum
1880N/A _young_list_target_length = _young_list_min_length;
342N/A }
342N/A
342N/A _rs_lengths_prediction = rs_lengths;
342N/A}
342N/A
1394N/A// This is used by: calculate_young_list_target_length(rs_length). It
1394N/A// returns true iff:
1394N/A// the predicted pause time for the given young list will not overflow
1394N/A// the target pause time
1394N/A// and:
1394N/A// the predicted amount of surviving data will not overflow the
1394N/A// the amount of free space available for survivor regions.
1394N/A//
342N/Abool
1394N/AG1CollectorPolicy::predict_will_fit(size_t young_length,
1394N/A double base_time_ms,
1394N/A size_t init_free_regions,
1394N/A double target_pause_time_ms) {
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 double accum_surv_rate =
342N/A accum_yg_surv_rate_pred((int)(young_length - 1)) - accum_surv_rate_adj;
1394N/A
342N/A size_t bytes_to_copy =
342N/A (size_t) (accum_surv_rate * (double) HeapRegion::GrainBytes);
1394N/A
342N/A double copy_time_ms = predict_object_copy_time_ms(bytes_to_copy);
1394N/A
342N/A double young_other_time_ms =
1394N/A predict_young_other_time_ms(young_length);
1394N/A
342N/A double pause_time_ms =
1394N/A base_time_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 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 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
1394N/A size_t rs_lengths = _g1->young_list()->sampled_rs_lengths();
342N/A if (rs_lengths > _rs_lengths_prediction) {
342N/A // add 10% to avoid having to recalculate often
342N/A size_t rs_lengths_prediction = rs_lengths * 1100 / 1000;
1394N/A calculate_young_list_target_length(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() {
1394N/A HeapRegion* head = _g1->young_list()->first_region();
342N/A return
342N/A verify_young_ages(head, _short_lived_surv_rate_group);
342N/A // also call verify_young_ages on any additional surv rate groups
342N/A}
342N/A
342N/Abool
342N/AG1CollectorPolicy::verify_young_ages(HeapRegion* head,
342N/A SurvRateGroup *surv_rate_group) {
342N/A guarantee( surv_rate_group != NULL, "pre-condition" );
342N/A
342N/A const char* name = surv_rate_group->name();
342N/A bool ret = true;
342N/A int prev_age = -1;
342N/A
342N/A for (HeapRegion* curr = head;
342N/A curr != NULL;
342N/A curr = curr->get_next_young_region()) {
342N/A SurvRateGroup* group = curr->surv_rate_group();
342N/A if (group == NULL && !curr->is_survivor()) {
342N/A gclog_or_tty->print_cr("## %s: encountered NULL surv_rate_group", name);
342N/A ret = false;
342N/A }
342N/A
342N/A if (surv_rate_group == group) {
342N/A int age = curr->age_in_surv_rate_group();
342N/A
342N/A if (age < 0) {
342N/A gclog_or_tty->print_cr("## %s: encountered negative age", name);
342N/A ret = false;
342N/A }
342N/A
342N/A if (age <= prev_age) {
342N/A gclog_or_tty->print_cr("## %s: region ages are not strictly increasing "
342N/A "(%d, %d)", name, age, prev_age);
342N/A ret = false;
342N/A }
342N/A prev_age = age;
342N/A }
342N/A }
342N/A
342N/A return ret;
342N/A}
342N/A#endif // PRODUCT
342N/A
342N/Avoid G1CollectorPolicy::record_full_collection_start() {
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;
1359N/A clear_initiate_conc_mark_if_possible();
1359N/A clear_during_initial_mark_pause();
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->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();
545N/A // Reset survivors SurvRateGroup.
545N/A _survivor_surv_rate_group->reset();
342N/A calculate_young_list_min_length();
1394N/A calculate_young_list_target_length();
1880N/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");
2695N/A gclog_or_tty->print(" (%s)", full_young_gcs() ? "young" : "partial");
342N/A }
342N/A
1880N/A assert(_g1->used() == _g1->recalculate_used(),
1880N/A err_msg("sanity, used: "SIZE_FORMAT" recalculate_used: "SIZE_FORMAT,
1880N/A _g1->used(), _g1->recalculate_used()));
342N/A
342N/A double s_w_t_ms = (start_time_sec - _stop_world_start) * 1000.0;
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_collection_set_before_gc = 0;
2655N/A _bytes_copied_during_gc = 0;
342N/A
2589N/A YoungList* young_list = _g1->young_list();
2589N/A _eden_bytes_before_gc = young_list->eden_used_bytes();
2589N/A _survivor_bytes_before_gc = young_list->survivor_used_bytes();
2589N/A _capacity_before_gc = _g1->capacity();
2589N/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) {
1531N/A _par_last_gc_worker_start_times_ms[i] = -1234.0;
1531N/A _par_last_ext_root_scan_times_ms[i] = -1234.0;
1531N/A _par_last_mark_stack_scan_times_ms[i] = -1234.0;
1531N/A _par_last_update_rs_times_ms[i] = -1234.0;
1531N/A _par_last_update_rs_processed_buffers[i] = -1234.0;
1531N/A _par_last_scan_rs_times_ms[i] = -1234.0;
1531N/A _par_last_obj_copy_times_ms[i] = -1234.0;
1531N/A _par_last_termination_times_ms[i] = -1234.0;
1531N/A _par_last_termination_attempts[i] = -1234.0;
1531N/A _par_last_gc_worker_end_times_ms[i] = -1234.0;
2277N/A _par_last_gc_worker_times_ms[i] = -1234.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
2695N/A _last_young_gc_full = false;
342N/A
342N/A // do that for any other surv rate groups
342N/A _short_lived_surv_rate_group->stop_adding_regions();
1282N/A _survivors_age_table.clear();
545N/A
342N/A assert( verify_young_ages(), "region age verification" );
342N/A}
342N/A
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
2695N/Avoid G1CollectorPolicy::record_concurrent_mark_init_end(double
342N/A mark_init_elapsed_time_ms) {
342N/A _during_marking = true;
1359N/A assert(!initiate_conc_mark_if_possible(), "we should have cleared it by now");
1359N/A clear_during_initial_mark_pause();
342N/A _cur_mark_stop_world_time_ms = mark_init_elapsed_time_ms;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_mark_remark_start() {
342N/A _mark_remark_start_sec = os::elapsedTime();
342N/A _during_marking = false;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_mark_remark_end() {
342N/A double end_time_sec = os::elapsedTime();
342N/A double elapsed_time_ms = (end_time_sec - _mark_remark_start_sec)*1000.0;
342N/A _concurrent_mark_remark_times_ms->add(elapsed_time_ms);
342N/A _cur_mark_stop_world_time_ms += elapsed_time_ms;
342N/A _prev_collection_pause_end_ms += elapsed_time_ms;
342N/A
342N/A _mmu_tracker->add_pause(_mark_remark_start_sec, end_time_sec, true);
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_mark_cleanup_start() {
342N/A _mark_cleanup_start_sec = os::elapsedTime();
342N/A}
342N/A
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) {
2748N/A if (_n_marks < 2) {
2748N/A _n_marks++;
2748N/A }
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 _n_pauses_at_mark_end = _n_pauses;
342N/A _n_marks_since_last_pause++;
342N/A}
342N/A
342N/Avoid
342N/AG1CollectorPolicy::record_concurrent_mark_cleanup_completed() {
2695N/A _should_revert_to_full_young_gcs = false;
2695N/A _last_full_young_gc = true;
2695N/A _in_marking_window = false;
2695N/A if (adaptive_young_list_length())
2695N/A calculate_young_list_target_length();
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/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
1531N/Avoid G1CollectorPolicy::print_par_stats(int level,
1531N/A const char* str,
2277N/A double* data) {
342N/A double min = data[0], max = data[0];
342N/A double total = 0.0;
2210N/A LineBuffer buf(level);
2210N/A buf.append("[%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;
2210N/A buf.append(" %3.1lf", val);
342N/A }
2277N/A buf.append_and_print_cr("");
2277N/A double avg = total / (double) ParallelGCThreads;
2277N/A buf.append_and_print_cr(" Avg: %5.1lf, Min: %5.1lf, Max: %5.1lf, Diff: %5.1lf]",
2277N/A avg, min, max, max - min);
342N/A}
342N/A
1531N/Avoid G1CollectorPolicy::print_par_sizes(int level,
1531N/A const char* str,
2277N/A double* data) {
342N/A double min = data[0], max = data[0];
342N/A double total = 0.0;
2210N/A LineBuffer buf(level);
2210N/A buf.append("[%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;
2210N/A buf.append(" %d", (int) val);
342N/A }
2277N/A buf.append_and_print_cr("");
2277N/A double avg = total / (double) ParallelGCThreads;
2277N/A buf.append_and_print_cr(" Sum: %d, Avg: %d, Min: %d, Max: %d, Diff: %d]",
2277N/A (int)total, (int)avg, (int)min, (int)max, (int)max - (int)min);
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::print_stats (int level,
342N/A const char* str,
342N/A double value) {
2210N/A LineBuffer(level).append_and_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) {
2210N/A LineBuffer(level).append_and_print_cr("[%s: %d]", str, value);
342N/A}
342N/A
342N/Adouble G1CollectorPolicy::avg_value (double* data) {
1753N/A if (G1CollectedHeap::use_parallel_gc_threads()) {
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) {
1753N/A if (G1CollectedHeap::use_parallel_gc_threads()) {
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) {
1753N/A if (G1CollectedHeap::use_parallel_gc_threads()) {
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
1753N/A if (G1CollectedHeap::use_parallel_gc_threads()) {
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
1627N/Avoid G1CollectorPolicy::record_collection_pause_end() {
342N/A double end_time_sec = os::elapsedTime();
342N/A double elapsed_ms = _last_pause_time_ms;
1753N/A bool parallel = G1CollectedHeap::use_parallel_gc_threads();
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;
1627N/A bool update_stats = !_g1->evacuation_failed();
342N/A
342N/A#ifndef PRODUCT
342N/A if (G1YoungSurvRateVerbose) {
342N/A gclog_or_tty->print_cr("");
342N/A _short_lived_surv_rate_group->print();
342N/A // do that for any other surv rate groups too
342N/A }
342N/A#endif // PRODUCT
342N/A
2695N/A last_pause_included_initial_mark = during_initial_mark_pause();
2695N/A if (last_pause_included_initial_mark)
2695N/A record_concurrent_mark_init_end(0.0);
2695N/A
2748N/A size_t marking_initiating_used_threshold =
2695N/A (_g1->capacity() / 100) * InitiatingHeapOccupancyPercent;
2695N/A
2695N/A if (!_g1->mark_in_progress() && !_last_full_young_gc) {
2695N/A assert(!last_pause_included_initial_mark, "invariant");
2748N/A if (cur_used_bytes > marking_initiating_used_threshold) {
2748N/A if (cur_used_bytes > _prev_collection_pause_used_at_end_bytes) {
1359N/A assert(!during_initial_mark_pause(), "we should not see this here");
1359N/A
2748N/A ergo_verbose3(ErgoConcCycles,
2748N/A "request concurrent cycle initiation",
2748N/A ergo_format_reason("occupancy higher than threshold")
2748N/A ergo_format_byte("occupancy")
2748N/A ergo_format_byte_perc("threshold"),
2748N/A cur_used_bytes,
2748N/A marking_initiating_used_threshold,
2748N/A (double) InitiatingHeapOccupancyPercent);
2748N/A
1359N/A // Note: this might have already been set, if during the last
1359N/A // pause we decided to start a cycle but at the beginning of
1359N/A // this pause we decided to postpone it. That's OK.
1359N/A set_initiate_conc_mark_if_possible();
2748N/A } else {
2748N/A ergo_verbose2(ErgoConcCycles,
2748N/A "do not request concurrent cycle initiation",
2748N/A ergo_format_reason("occupancy lower than previous occupancy")
2748N/A ergo_format_byte("occupancy")
2748N/A ergo_format_byte("previous occupancy"),
2748N/A cur_used_bytes,
2748N/A _prev_collection_pause_used_at_end_bytes);
2748N/A }
342N/A }
342N/A }
342N/A
2695N/A _prev_collection_pause_used_at_end_bytes = cur_used_bytes;
2695N/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;
1394N/A
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
2648N/A double ext_root_scan_time = avg_value(_par_last_ext_root_scan_times_ms);
2648N/A double mark_stack_scan_time = avg_value(_par_last_mark_stack_scan_times_ms);
2648N/A double update_rs_time = avg_value(_par_last_update_rs_times_ms);
2648N/A double update_rs_processed_buffers =
2648N/A sum_of_values(_par_last_update_rs_processed_buffers);
2648N/A double scan_rs_time = avg_value(_par_last_scan_rs_times_ms);
2648N/A double obj_copy_time = avg_value(_par_last_obj_copy_times_ms);
2648N/A double termination_time = avg_value(_par_last_termination_times_ms);
2648N/A
2648N/A double parallel_known_time = update_rs_time +
2648N/A ext_root_scan_time +
2648N/A mark_stack_scan_time +
2648N/A scan_rs_time +
2648N/A obj_copy_time +
2648N/A termination_time;
2648N/A
2648N/A double parallel_other_time = _cur_collection_par_time_ms - parallel_known_time;
2648N/A
2648N/A PauseSummary* summary = _summary;
2648N/A
595N/A if (update_stats) {
2648N/A _recent_rs_scan_times_ms->add(scan_rs_time);
342N/A _recent_pause_times_ms->add(elapsed_ms);
342N/A _recent_rs_sizes->add(rs_size);
342N/A
2648N/A MainBodySummary* body_summary = summary->main_body_summary();
2648N/A guarantee(body_summary != NULL, "should not be null!");
2648N/A
2648N/A if (_satb_drain_time_set)
2648N/A body_summary->record_satb_drain_time_ms(_cur_satb_drain_time_ms);
2648N/A else
2648N/A body_summary->record_satb_drain_time_ms(0.0);
2648N/A
2648N/A body_summary->record_ext_root_scan_time_ms(ext_root_scan_time);
2648N/A body_summary->record_mark_stack_scan_time_ms(mark_stack_scan_time);
2648N/A body_summary->record_update_rs_time_ms(update_rs_time);
2648N/A body_summary->record_scan_rs_time_ms(scan_rs_time);
2648N/A body_summary->record_obj_copy_time_ms(obj_copy_time);
2648N/A if (parallel) {
2648N/A body_summary->record_parallel_time_ms(_cur_collection_par_time_ms);
2648N/A body_summary->record_clear_ct_time_ms(_cur_clear_ct_time_ms);
2648N/A body_summary->record_termination_time_ms(termination_time);
2648N/A body_summary->record_parallel_other_time_ms(parallel_other_time);
2648N/A }
2648N/A body_summary->record_mark_closure_time_ms(_mark_closure_time_ms);
2648N/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 if (G1PolicyVerbose > 1) {
342N/A gclog_or_tty->print_cr(" ET: %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(),
2648N/A scan_rs_time, recent_avg_time_for_rs_scan_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
1627N/A if (_satb_drain_time_set) {
1627N/A other_time_ms -= _cur_satb_drain_time_ms;
1627N/A }
1627N/A
1627N/A if (parallel) {
1627N/A other_time_ms -= _cur_collection_par_time_ms + _cur_clear_ct_time_ms;
1627N/A } else {
1627N/A other_time_ms -=
1627N/A update_rs_time +
1627N/A ext_root_scan_time + mark_stack_scan_time +
1627N/A scan_rs_time + obj_copy_time;
342N/A }
342N/A
342N/A if (PrintGCDetails) {
1627N/A gclog_or_tty->print_cr("%s, %1.8lf secs]",
342N/A (last_pause_included_initial_mark) ? " (initial-mark)" : "",
342N/A elapsed_ms / 1000.0);
342N/A
1627N/A if (_satb_drain_time_set) {
1627N/A print_stats(1, "SATB Drain Time", _cur_satb_drain_time_ms);
1627N/A }
1627N/A if (_last_satb_drain_processed_buffers >= 0) {
1627N/A print_stats(2, "Processed Buffers", _last_satb_drain_processed_buffers);
1627N/A }
1627N/A if (parallel) {
1627N/A print_stats(1, "Parallel Time", _cur_collection_par_time_ms);
2277N/A print_par_stats(2, "GC Worker Start Time", _par_last_gc_worker_start_times_ms);
1627N/A print_par_stats(2, "Update RS", _par_last_update_rs_times_ms);
2277N/A print_par_sizes(3, "Processed Buffers", _par_last_update_rs_processed_buffers);
2277N/A print_par_stats(2, "Ext Root Scanning", _par_last_ext_root_scan_times_ms);
2277N/A print_par_stats(2, "Mark Stack Scanning", _par_last_mark_stack_scan_times_ms);
1627N/A print_par_stats(2, "Scan RS", _par_last_scan_rs_times_ms);
1627N/A print_par_stats(2, "Object Copy", _par_last_obj_copy_times_ms);
1627N/A print_par_stats(2, "Termination", _par_last_termination_times_ms);
2277N/A print_par_sizes(3, "Termination Attempts", _par_last_termination_attempts);
2277N/A print_par_stats(2, "GC Worker End Time", _par_last_gc_worker_end_times_ms);
2277N/A
2277N/A for (int i = 0; i < _parallel_gc_threads; i++) {
2277N/A _par_last_gc_worker_times_ms[i] = _par_last_gc_worker_end_times_ms[i] - _par_last_gc_worker_start_times_ms[i];
2277N/A }
2277N/A print_par_stats(2, "GC Worker Times", _par_last_gc_worker_times_ms);
2277N/A
2648N/A print_stats(2, "Parallel Other", parallel_other_time);
1627N/A print_stats(1, "Clear CT", _cur_clear_ct_time_ms);
1627N/A } else {
1627N/A print_stats(1, "Update RS", update_rs_time);
1627N/A print_stats(2, "Processed Buffers",
1627N/A (int)update_rs_processed_buffers);
1627N/A print_stats(1, "Ext Root Scanning", ext_root_scan_time);
1627N/A print_stats(1, "Mark Stack Scanning", mark_stack_scan_time);
1627N/A print_stats(1, "Scan RS", scan_rs_time);
1627N/A print_stats(1, "Object Copying", obj_copy_time);
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);
1394N/A print_stats(2, "Choose CSet", _recorded_young_cset_choice_time_ms);
1394N/A
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
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;
1359N/A if (during_initial_mark_pause()) {
342N/A new_in_marking_window = true;
342N/A new_in_marking_window_im = true;
342N/A }
342N/A
2695N/A if (_last_full_young_gc) {
2748N/A ergo_verbose2(ErgoPartiallyYoungGCs,
2748N/A "start partially-young GCs",
2748N/A ergo_format_byte_perc("known garbage"),
2748N/A _known_garbage_bytes, _known_garbage_ratio * 100.0);
2695N/A set_full_young_gcs(false);
2695N/A _last_full_young_gc = false;
2695N/A }
2695N/A
2695N/A if ( !_last_young_gc_full ) {
2748N/A if (_should_revert_to_full_young_gcs) {
2748N/A ergo_verbose2(ErgoPartiallyYoungGCs,
2748N/A "end partially-young GCs",
2748N/A ergo_format_reason("partially-young GCs end requested")
2748N/A ergo_format_byte_perc("known garbage"),
2748N/A _known_garbage_bytes, _known_garbage_ratio * 100.0);
2748N/A set_full_young_gcs(true);
2748N/A } else if (_known_garbage_ratio < 0.05) {
2748N/A ergo_verbose3(ErgoPartiallyYoungGCs,
2748N/A "end partially-young GCs",
2748N/A ergo_format_reason("known garbage percent lower than threshold")
2748N/A ergo_format_byte_perc("known garbage")
2748N/A ergo_format_perc("threshold"),
2748N/A _known_garbage_bytes, _known_garbage_ratio * 100.0,
2748N/A 0.05 * 100.0);
2748N/A set_full_young_gcs(true);
2748N/A } else if (adaptive_young_list_length() &&
2748N/A (get_gc_eff_factor() * cur_efficiency < predict_young_gc_eff())) {
2748N/A ergo_verbose5(ErgoPartiallyYoungGCs,
2748N/A "end partially-young GCs",
2748N/A ergo_format_reason("current GC efficiency lower than "
2748N/A "predicted fully-young GC efficiency")
2748N/A ergo_format_double("GC efficiency factor")
2748N/A ergo_format_double("current GC efficiency")
2748N/A ergo_format_double("predicted fully-young GC efficiency")
2748N/A ergo_format_byte_perc("known garbage"),
2748N/A get_gc_eff_factor(), cur_efficiency,
2748N/A predict_young_gc_eff(),
2748N/A _known_garbage_bytes, _known_garbage_ratio * 100.0);
2748N/A set_full_young_gcs(true);
342N/A }
2695N/A }
2695N/A _should_revert_to_full_young_gcs = false;
2695N/A
2695N/A if (_last_young_gc_full && !_during_marking) {
2695N/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 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 -
1394N/A (update_rs_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) {
2655N/A survival_ratio = (double) _bytes_copied_during_gc /
2655N/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 "
1394N/A "REGIONS %d %d %d "
342N/A "PENDING_CARDS %d %d "
342N/A "CARDS_SCANNED %d %d "
342N/A "RS_LENGTHS %d %d "
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_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_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 calculate_young_list_min_length();
1394N/A calculate_young_list_target_length();
342N/A
1111N/A // Note that _mmu_tracker->max_gc_time() returns the time in seconds.
1282N/A double update_rs_time_goal_ms = _mmu_tracker->max_gc_time() * MILLIUNITS * G1RSetUpdatingPauseTimePercent / 100.0;
1111N/A adjust_concurrent_refinement(update_rs_time, update_rs_processed_buffers, update_rs_time_goal_ms);
342N/A // </NEW PREDICTION>
342N/A}
342N/A
2589N/A#define EXT_SIZE_FORMAT "%d%s"
2589N/A#define EXT_SIZE_PARAMS(bytes) \
2589N/A byte_size_in_proper_unit((bytes)), \
2589N/A proper_unit_for_byte_size((bytes))
2589N/A
2589N/Avoid G1CollectorPolicy::print_heap_transition() {
2589N/A if (PrintGCDetails) {
2589N/A YoungList* young_list = _g1->young_list();
2589N/A size_t eden_bytes = young_list->eden_used_bytes();
2589N/A size_t survivor_bytes = young_list->survivor_used_bytes();
2589N/A size_t used_before_gc = _cur_collection_pause_used_at_start_bytes;
2589N/A size_t used = _g1->used();
2589N/A size_t capacity = _g1->capacity();
2589N/A
2589N/A gclog_or_tty->print_cr(
2589N/A " [Eden: "EXT_SIZE_FORMAT"->"EXT_SIZE_FORMAT" "
2589N/A "Survivors: "EXT_SIZE_FORMAT"->"EXT_SIZE_FORMAT" "
2589N/A "Heap: "EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")->"
2589N/A EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")]",
2589N/A EXT_SIZE_PARAMS(_eden_bytes_before_gc),
2589N/A EXT_SIZE_PARAMS(eden_bytes),
2589N/A EXT_SIZE_PARAMS(_survivor_bytes_before_gc),
2589N/A EXT_SIZE_PARAMS(survivor_bytes),
2589N/A EXT_SIZE_PARAMS(used_before_gc),
2589N/A EXT_SIZE_PARAMS(_capacity_before_gc),
2589N/A EXT_SIZE_PARAMS(used),
2589N/A EXT_SIZE_PARAMS(capacity));
2589N/A } else if (PrintGC) {
2589N/A _g1->print_size_transition(gclog_or_tty,
2589N/A _cur_collection_pause_used_at_start_bytes,
2589N/A _g1->used(), _g1->capacity());
2589N/A }
2589N/A}
2589N/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();
1394N/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();
1394N/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_young_regions = 0;
342N/A _recorded_non_young_regions = 0;
342N/A
342N/A#if PREDICTIONS_VERBOSE
342N/A _recorded_marked_bytes = 0;
342N/A _recorded_young_bytes = 0;
342N/A _predicted_bytes_to_copy = 0;
1394N/A _predicted_rs_lengths = 0;
1394N/A _predicted_cards_scanned = 0;
342N/A#endif // PREDICTIONS_VERBOSE
342N/A}
342N/A
342N/Avoid
1394N/AG1CollectorPolicy::record_cset_region_info(HeapRegion* hr, bool young) {
342N/A#if PREDICTIONS_VERBOSE
1394N/A if (!young) {
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
1394N/AG1CollectorPolicy::record_non_young_cset_region(HeapRegion* hr) {
1394N/A assert(!hr->is_young(), "should not call this");
1394N/A ++_recorded_non_young_regions;
1394N/A record_cset_region_info(hr, false);
1394N/A}
1394N/A
1394N/Avoid
1394N/AG1CollectorPolicy::set_recorded_young_regions(size_t n_regions) {
1394N/A _recorded_young_regions = n_regions;
1394N/A}
1394N/A
1394N/Avoid G1CollectorPolicy::set_recorded_young_bytes(size_t bytes) {
1394N/A#if PREDICTIONS_VERBOSE
1394N/A _recorded_young_bytes = bytes;
1394N/A#endif // PREDICTIONS_VERBOSE
1394N/A}
1394N/A
1394N/Avoid G1CollectorPolicy::set_recorded_rs_lengths(size_t rs_lengths) {
1394N/A _recorded_rs_lengths = rs_lengths;
1394N/A}
1394N/A
1394N/Avoid G1CollectorPolicy::set_predicted_bytes_to_copy(size_t bytes) {
1394N/A _predicted_bytes_to_copy = bytes;
342N/A}
342N/A
342N/Avoid
342N/AG1CollectorPolicy::end_recording_regions() {
1394N/A // The _predicted_pause_time_ms field is referenced in code
1394N/A // not under PREDICTIONS_VERBOSE. Let's initialize it.
1394N/A _predicted_pause_time_ms = -1.0;
1394N/A
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_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_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) {
2748N/A ergo_verbose2(ErgoPartiallyYoungGCs,
2748N/A "request partially-young GCs end",
2748N/A ergo_format_reason("predicted region time higher than threshold")
2748N/A ergo_format_ms("predicted region time")
2748N/A ergo_format_ms("threshold"),
2748N/A predicted_time_ms, _expensive_region_limit_ms);
2695N/A // no point in doing another partial one
2695N/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() {
2648N/A if (_recent_pause_times_ms->num() == 0) {
2648N/A return (double) MaxGCPauseMillis;
2648N/A }
2648N/A return _recent_pause_times_ms->avg();
342N/A}
342N/A
2648N/Adouble G1CollectorPolicy::recent_avg_time_for_rs_scan_ms() {
2648N/A if (_recent_rs_scan_times_ms->num() == 0) {
751N/A return (double)MaxGCPauseMillis/3.0;
2648N/A }
2648N/A return _recent_rs_scan_times_ms->avg();
342N/A}
342N/A
342N/Aint G1CollectorPolicy::number_of_recent_gcs() {
2648N/A assert(_recent_rs_scan_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");
2648N/A
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.)
1753N/A assert((true || G1CollectedHeap::use_parallel_gc_threads()) ||
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.)
1753N/A assert((true || G1CollectedHeap::use_parallel_gc_threads()) ||
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() {
2748N/A double recent_gc_overhead = recent_avg_pause_time_ratio() * 100.0;
2748N/A double threshold = _gc_overhead_perc;
2748N/A if (recent_gc_overhead > threshold) {
751N/A // We will double the existing space, or take
751N/A // G1ExpandByPercentOfAvailable % of the available expansion
751N/A // space, whichever is smaller, bounded below by a minimum
751N/A // expansion (unless that's all that's left.)
342N/A const size_t min_expand_bytes = 1*M;
2069N/A size_t reserved_bytes = _g1->max_capacity();
342N/A size_t committed_bytes = _g1->capacity();
342N/A size_t uncommitted_bytes = reserved_bytes - committed_bytes;
342N/A size_t expand_bytes;
342N/A size_t expand_bytes_via_pct =
751N/A uncommitted_bytes * G1ExpandByPercentOfAvailable / 100;
342N/A expand_bytes = MIN2(expand_bytes_via_pct, committed_bytes);
342N/A expand_bytes = MAX2(expand_bytes, min_expand_bytes);
342N/A expand_bytes = MIN2(expand_bytes, uncommitted_bytes);
2748N/A
2748N/A ergo_verbose5(ErgoHeapSizing,
2748N/A "attempt heap expansion",
2748N/A ergo_format_reason("recent GC overhead higher than "
2748N/A "threshold after GC")
2748N/A ergo_format_perc("recent GC overhead")
2748N/A ergo_format_perc("threshold")
2748N/A ergo_format_byte("uncommitted")
2748N/A ergo_format_byte_perc("calculated expansion amount"),
2748N/A recent_gc_overhead, threshold,
2748N/A uncommitted_bytes,
2748N/A expand_bytes_via_pct, (double) G1ExpandByPercentOfAvailable);
2748N/A
342N/A return expand_bytes;
342N/A } else {
342N/A return 0;
342N/A }
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::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/Avoid G1CollectorPolicy::print_summary (int level,
342N/A const char* str,
342N/A NumberSeq* seq) const {
342N/A double sum = seq->sum();
2210N/A LineBuffer(level + 1).append_and_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);
2210N/A LineBuffer(level + 6).append_and_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;
2210N/A LineBuffer buf(level + 2);
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;
2210N/A buf.append_and_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;
2210N/A buf.append_and_print_cr("## CALCULATED OTHER AVG DOESN'T MATCH RECORDED ###");
342N/A }
342N/A
342N/A if (other_times_ms->sum() < -0.01) {
2210N/A buf.append_and_print_cr("## RECORDED OTHER SUM IS NEGATIVE ###");
342N/A }
342N/A
342N/A if (other_times_ms->avg() < -0.01) {
2210N/A buf.append_and_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;
2210N/A buf.append_and_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;
2210N/A buf.append_and_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 {
1753N/A bool parallel = G1CollectedHeap::use_parallel_gc_threads();
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 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_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(),
1699N/A 6, 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 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 {
1699N/A if (body_summary != NULL) {
1699N/A NumberSeq calc_other_times_ms;
1699N/A if (parallel) {
1699N/A // parallel
1699N/A NumberSeq* other_parts[] = {
1699N/A body_summary->get_satb_drain_seq(),
1699N/A body_summary->get_parallel_seq(),
1699N/A body_summary->get_clear_ct_seq()
1699N/A };
1699N/A calc_other_times_ms = NumberSeq(summary->get_total_seq(),
1699N/A 3, other_parts);
1699N/A } else {
1699N/A // serial
1699N/A NumberSeq* other_parts[] = {
1699N/A body_summary->get_satb_drain_seq(),
1699N/A body_summary->get_update_rs_seq(),
1699N/A body_summary->get_ext_root_scan_seq(),
1699N/A body_summary->get_mark_stack_scan_seq(),
1699N/A body_summary->get_scan_rs_seq(),
1699N/A body_summary->get_obj_copy_seq()
1699N/A };
1699N/A calc_other_times_ms = NumberSeq(summary->get_total_seq(),
1699N/A 6, other_parts);
1699N/A }
1699N/A check_other_times(1, summary->get_other_seq(), &calc_other_times_ms);
342N/A }
342N/A }
342N/A } else {
2210N/A LineBuffer(1).append_and_print_cr("none");
342N/A }
2210N/A LineBuffer(0).append_and_print_cr("");
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("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
2748N/Avoid G1CollectorPolicy::update_region_num(bool young) {
1880N/A if (young) {
342N/A ++_region_num_young;
342N/A } else {
342N/A ++_region_num_tenured;
342N/A }
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
1898N/Avoid G1CollectorPolicy::calculate_max_gc_locker_expansion() {
1898N/A size_t expansion_region_num = 0;
1898N/A if (GCLockerEdenExpansionPercent > 0) {
1898N/A double perc = (double) GCLockerEdenExpansionPercent / 100.0;
1898N/A double expansion_region_num_d = perc * (double) _young_list_target_length;
1898N/A // We use ceiling so that if expansion_region_num_d is > 0.0 (but
1898N/A // less than 1.0) we'll get 1.
1898N/A expansion_region_num = (size_t) ceil(expansion_region_num_d);
1898N/A } else {
1898N/A assert(expansion_region_num == 0, "sanity");
1898N/A }
1898N/A _young_list_max_length = _young_list_target_length + expansion_region_num;
1898N/A assert(_young_list_target_length <= _young_list_max_length, "post-condition");
1898N/A}
1898N/A
545N/A// Calculates survivor space parameters.
545N/Avoid G1CollectorPolicy::calculate_survivors_policy()
545N/A{
2696N/A _max_survivor_regions = _young_list_target_length / SurvivorRatio;
2696N/A _tenuring_threshold = _survivors_age_table.compute_tenuring_threshold(
545N/A HeapRegion::GrainWords * _max_survivor_regions);
545N/A}
545N/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
2748N/Abool G1CollectorPolicy::force_initial_mark_if_outside_cycle(
2748N/A GCCause::Cause gc_cause) {
1576N/A bool during_cycle = _g1->concurrent_mark()->cmThread()->during_cycle();
1576N/A if (!during_cycle) {
2748N/A ergo_verbose1(ErgoConcCycles,
2748N/A "request concurrent cycle initiation",
2748N/A ergo_format_reason("requested by GC cause")
2748N/A ergo_format_str("GC cause"),
2748N/A GCCause::to_string(gc_cause));
1576N/A set_initiate_conc_mark_if_possible();
1576N/A return true;
1576N/A } else {
2748N/A ergo_verbose1(ErgoConcCycles,
2748N/A "do not request concurrent cycle initiation",
2748N/A ergo_format_reason("concurrent cycle already in progress")
2748N/A ergo_format_str("GC cause"),
2748N/A GCCause::to_string(gc_cause));
1576N/A return false;
1576N/A }
1576N/A}
1576N/A
342N/Avoid
1359N/AG1CollectorPolicy::decide_on_conc_mark_initiation() {
1359N/A // We are about to decide on whether this pause will be an
1359N/A // initial-mark pause.
1359N/A
1359N/A // First, during_initial_mark_pause() should not be already set. We
1359N/A // will set it here if we have to. However, it should be cleared by
1359N/A // the end of the pause (it's only set for the duration of an
1359N/A // initial-mark pause).
1359N/A assert(!during_initial_mark_pause(), "pre-condition");
1359N/A
1359N/A if (initiate_conc_mark_if_possible()) {
1359N/A // We had noticed on a previous pause that the heap occupancy has
1359N/A // gone over the initiating threshold and we should start a
1359N/A // concurrent marking cycle. So we might initiate one.
1359N/A
1359N/A bool during_cycle = _g1->concurrent_mark()->cmThread()->during_cycle();
1359N/A if (!during_cycle) {
1359N/A // The concurrent marking thread is not "during a cycle", i.e.,
1359N/A // it has completed the last one. So we can go ahead and
1359N/A // initiate a new cycle.
1359N/A
1359N/A set_during_initial_mark_pause();
1359N/A
1359N/A // And we can now clear initiate_conc_mark_if_possible() as
1359N/A // we've already acted on it.
1359N/A clear_initiate_conc_mark_if_possible();
2748N/A
2748N/A ergo_verbose0(ErgoConcCycles,
2748N/A "initiate concurrent cycle",
2748N/A ergo_format_reason("concurrent cycle initiation requested"));
1359N/A } else {
1359N/A // The concurrent marking thread is still finishing up the
1359N/A // previous cycle. If we start one right now the two cycles
1359N/A // overlap. In particular, the concurrent marking thread might
1359N/A // be in the process of clearing the next marking bitmap (which
1359N/A // we will use for the next cycle if we start one). Starting a
1359N/A // cycle now will be bad given that parts of the marking
1359N/A // information might get cleared by the marking thread. And we
1359N/A // cannot wait for the marking thread to finish the cycle as it
1359N/A // periodically yields while clearing the next marking bitmap
1359N/A // and, if it's in a yield point, it's waiting for us to
1359N/A // finish. So, at this point we will not start a cycle and we'll
1359N/A // let the concurrent marking thread complete the last one.
2748N/A ergo_verbose0(ErgoConcCycles,
2748N/A "do not initiate concurrent cycle",
2748N/A ergo_format_reason("concurrent cycle already in progress"));
1359N/A }
1359N/A }
1359N/A}
1359N/A
1359N/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 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) {
2210N/A gclog_or_tty->print_cr(" Thread %d called %d times, added %d regions to list.",
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 }
1753N/A if (G1CollectedHeap::use_parallel_gc_threads()) {
342N/A const size_t OverpartitionFactor = 4;
1491N/A const size_t MinWorkUnit = 8;
1491N/A const size_t WorkUnit =
342N/A MAX2(_g1->n_regions() / (ParallelGCThreads * OverpartitionFactor),
1491N/A MinWorkUnit);
342N/A _collectionSetChooser->prepareForAddMarkedHeapRegionsPar(_g1->n_regions(),
1491N/A WorkUnit);
342N/A ParKnownGarbageTask parKnownGarbageTask(_collectionSetChooser,
1491N/A (int) WorkUnit);
342N/A _g1->workers()->run_task(&parKnownGarbageTask);
355N/A
355N/A assert(_g1->check_heap_region_claim_values(HeapRegion::InitialClaimValue),
355N/A "sanity check");
342N/A } else {
342N/A KnownGarbageClosure knownGarbagecl(_collectionSetChooser);
342N/A _g1->heap_region_iterate(&knownGarbagecl);
342N/A }
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
1394N/A// Add the heap region at the head of the non-incremental collection set
342N/Avoid G1CollectorPolicy::
342N/Aadd_to_collection_set(HeapRegion* hr) {
1394N/A assert(_inc_cset_build_state == Active, "Precondition");
1394N/A assert(!hr->is_young(), "non-incremental add of young region");
1394N/A
342N/A if (_g1->mark_in_progress())
342N/A _g1->concurrent_mark()->registerCSetRegion(hr);
342N/A
1394N/A assert(!hr->in_collection_set(), "should not already be in the CSet");
342N/A hr->set_in_collection_set(true);
342N/A hr->set_next_in_collection_set(_collection_set);
342N/A _collection_set = hr;
342N/A _collection_set_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
1394N/A// Initialize the per-collection-set information
1394N/Avoid G1CollectorPolicy::start_incremental_cset_building() {
1394N/A assert(_inc_cset_build_state == Inactive, "Precondition");
1394N/A
1394N/A _inc_cset_head = NULL;
1394N/A _inc_cset_tail = NULL;
1394N/A _inc_cset_size = 0;
1394N/A _inc_cset_bytes_used_before = 0;
1394N/A
2695N/A _inc_cset_young_index = 0;
1394N/A
1394N/A _inc_cset_max_finger = 0;
1394N/A _inc_cset_recorded_young_bytes = 0;
1394N/A _inc_cset_recorded_rs_lengths = 0;
1394N/A _inc_cset_predicted_elapsed_time_ms = 0;
1394N/A _inc_cset_predicted_bytes_to_copy = 0;
1394N/A _inc_cset_build_state = Active;
1394N/A}
1394N/A
1394N/Avoid G1CollectorPolicy::add_to_incremental_cset_info(HeapRegion* hr, size_t rs_length) {
1394N/A // This routine is used when:
1394N/A // * adding survivor regions to the incremental cset at the end of an
1394N/A // evacuation pause,
1394N/A // * adding the current allocation region to the incremental cset
1394N/A // when it is retired, and
1394N/A // * updating existing policy information for a region in the
1394N/A // incremental cset via young list RSet sampling.
1394N/A // Therefore this routine may be called at a safepoint by the
1394N/A // VM thread, or in-between safepoints by mutator threads (when
1394N/A // retiring the current allocation region) or a concurrent
1394N/A // refine thread (RSet sampling).
1394N/A
1394N/A double region_elapsed_time_ms = predict_region_elapsed_time_ms(hr, true);
1394N/A size_t used_bytes = hr->used();
1394N/A
1394N/A _inc_cset_recorded_rs_lengths += rs_length;
1394N/A _inc_cset_predicted_elapsed_time_ms += region_elapsed_time_ms;
1394N/A
1394N/A _inc_cset_bytes_used_before += used_bytes;
1394N/A
1394N/A // Cache the values we have added to the aggregated informtion
1394N/A // in the heap region in case we have to remove this region from
1394N/A // the incremental collection set, or it is updated by the
1394N/A // rset sampling code
1394N/A hr->set_recorded_rs_length(rs_length);
1394N/A hr->set_predicted_elapsed_time_ms(region_elapsed_time_ms);
1394N/A
1394N/A#if PREDICTIONS_VERBOSE
1394N/A size_t bytes_to_copy = predict_bytes_to_copy(hr);
1394N/A _inc_cset_predicted_bytes_to_copy += bytes_to_copy;
1394N/A
1394N/A // Record the number of bytes used in this region
1394N/A _inc_cset_recorded_young_bytes += used_bytes;
1394N/A
1394N/A // Cache the values we have added to the aggregated informtion
1394N/A // in the heap region in case we have to remove this region from
1394N/A // the incremental collection set, or it is updated by the
1394N/A // rset sampling code
1394N/A hr->set_predicted_bytes_to_copy(bytes_to_copy);
1394N/A#endif // PREDICTIONS_VERBOSE
1394N/A}
1394N/A
1394N/Avoid G1CollectorPolicy::remove_from_incremental_cset_info(HeapRegion* hr) {
1394N/A // This routine is currently only called as part of the updating of
1394N/A // existing policy information for regions in the incremental cset that
1394N/A // is performed by the concurrent refine thread(s) as part of young list
1394N/A // RSet sampling. Therefore we should not be at a safepoint.
1394N/A
1394N/A assert(!SafepointSynchronize::is_at_safepoint(), "should not be at safepoint");
1394N/A assert(hr->is_young(), "it should be");
1394N/A
1394N/A size_t used_bytes = hr->used();
1394N/A size_t old_rs_length = hr->recorded_rs_length();
1394N/A double old_elapsed_time_ms = hr->predicted_elapsed_time_ms();
1394N/A
1394N/A // Subtract the old recorded/predicted policy information for
1394N/A // the given heap region from the collection set info.
1394N/A _inc_cset_recorded_rs_lengths -= old_rs_length;
1394N/A _inc_cset_predicted_elapsed_time_ms -= old_elapsed_time_ms;
1394N/A
1394N/A _inc_cset_bytes_used_before -= used_bytes;
1394N/A
1394N/A // Clear the values cached in the heap region
1394N/A hr->set_recorded_rs_length(0);
1394N/A hr->set_predicted_elapsed_time_ms(0);
1394N/A
1394N/A#if PREDICTIONS_VERBOSE
1394N/A size_t old_predicted_bytes_to_copy = hr->predicted_bytes_to_copy();
1394N/A _inc_cset_predicted_bytes_to_copy -= old_predicted_bytes_to_copy;
1394N/A
1394N/A // Subtract the number of bytes used in this region
1394N/A _inc_cset_recorded_young_bytes -= used_bytes;
1394N/A
1394N/A // Clear the values cached in the heap region
1394N/A hr->set_predicted_bytes_to_copy(0);
1394N/A#endif // PREDICTIONS_VERBOSE
1394N/A}
1394N/A
1394N/Avoid G1CollectorPolicy::update_incremental_cset_info(HeapRegion* hr, size_t new_rs_length) {
1394N/A // Update the collection set information that is dependent on the new RS length
1394N/A assert(hr->is_young(), "Precondition");
1394N/A
1394N/A remove_from_incremental_cset_info(hr);
1394N/A add_to_incremental_cset_info(hr, new_rs_length);
1394N/A}
1394N/A
1394N/Avoid G1CollectorPolicy::add_region_to_incremental_cset_common(HeapRegion* hr) {
1394N/A assert( hr->is_young(), "invariant");
1394N/A assert( hr->young_index_in_cset() == -1, "invariant" );
1394N/A assert(_inc_cset_build_state == Active, "Precondition");
1394N/A
1394N/A // We need to clear and set the cached recorded/cached collection set
1394N/A // information in the heap region here (before the region gets added
1394N/A // to the collection set). An individual heap region's cached values
1394N/A // are calculated, aggregated with the policy collection set info,
1394N/A // and cached in the heap region here (initially) and (subsequently)
1394N/A // by the Young List sampling code.
1394N/A
1394N/A size_t rs_length = hr->rem_set()->occupied();
1394N/A add_to_incremental_cset_info(hr, rs_length);
1394N/A
1394N/A HeapWord* hr_end = hr->end();
1394N/A _inc_cset_max_finger = MAX2(_inc_cset_max_finger, hr_end);
1394N/A
1394N/A assert(!hr->in_collection_set(), "invariant");
1394N/A hr->set_in_collection_set(true);
1394N/A assert( hr->next_in_collection_set() == NULL, "invariant");
1394N/A
1394N/A _inc_cset_size++;
1394N/A _g1->register_region_with_in_cset_fast_test(hr);
1394N/A
1394N/A hr->set_young_index_in_cset((int) _inc_cset_young_index);
1394N/A ++_inc_cset_young_index;
1394N/A}
1394N/A
1394N/A// Add the region at the RHS of the incremental cset
1394N/Avoid G1CollectorPolicy::add_region_to_incremental_cset_rhs(HeapRegion* hr) {
1394N/A // We should only ever be appending survivors at the end of a pause
1394N/A assert( hr->is_survivor(), "Logic");
1394N/A
1394N/A // Do the 'common' stuff
1394N/A add_region_to_incremental_cset_common(hr);
1394N/A
1394N/A // Now add the region at the right hand side
1394N/A if (_inc_cset_tail == NULL) {
1394N/A assert(_inc_cset_head == NULL, "invariant");
1394N/A _inc_cset_head = hr;
1394N/A } else {
1394N/A _inc_cset_tail->set_next_in_collection_set(hr);
1394N/A }
1394N/A _inc_cset_tail = hr;
1394N/A}
1394N/A
1394N/A// Add the region to the LHS of the incremental cset
1394N/Avoid G1CollectorPolicy::add_region_to_incremental_cset_lhs(HeapRegion* hr) {
1394N/A // Survivors should be added to the RHS at the end of a pause
1394N/A assert(!hr->is_survivor(), "Logic");
1394N/A
1394N/A // Do the 'common' stuff
1394N/A add_region_to_incremental_cset_common(hr);
1394N/A
1394N/A // Add the region at the left hand side
1394N/A hr->set_next_in_collection_set(_inc_cset_head);
1394N/A if (_inc_cset_head == NULL) {
1394N/A assert(_inc_cset_tail == NULL, "Invariant");
1394N/A _inc_cset_tail = hr;
1394N/A }
1394N/A _inc_cset_head = hr;
1394N/A}
1394N/A
1394N/A#ifndef PRODUCT
1394N/Avoid G1CollectorPolicy::print_collection_set(HeapRegion* list_head, outputStream* st) {
1394N/A assert(list_head == inc_cset_head() || list_head == collection_set(), "must be");
1394N/A
1394N/A st->print_cr("\nCollection_set:");
1394N/A HeapRegion* csr = list_head;
1394N/A while (csr != NULL) {
1394N/A HeapRegion* next = csr->next_in_collection_set();
1394N/A assert(csr->in_collection_set(), "bad CS");
1394N/A st->print_cr(" [%08x-%08x], t: %08x, P: %08x, N: %08x, C: %08x, "
1394N/A "age: %4d, y: %d, surv: %d",
1394N/A csr->bottom(), csr->end(),
1394N/A csr->top(),
1394N/A csr->prev_top_at_mark_start(),
1394N/A csr->next_top_at_mark_start(),
1394N/A csr->top_at_conc_mark_count(),
1394N/A csr->age_in_surv_rate_group_cond(),
1394N/A csr->is_young(),
1394N/A csr->is_survivor());
1394N/A csr = next;
1394N/A }
1394N/A}
1394N/A#endif // !PRODUCT
1394N/A
1627N/Avoid
1576N/AG1CollectorPolicy_BestRegionsFirst::choose_collection_set(
1576N/A double target_pause_time_ms) {
1394N/A // Set this here - in case we're not doing young collections.
1394N/A double non_young_start_time_sec = os::elapsedTime();
1394N/A
2748N/A YoungList* young_list = _g1->young_list();
2748N/A
342N/A start_recording_regions();
342N/A
1576N/A guarantee(target_pause_time_ms > 0.0,
1576N/A err_msg("target_pause_time_ms = %1.6lf should be positive",
1576N/A target_pause_time_ms));
1576N/A guarantee(_collection_set == NULL, "Precondition");
342N/A
342N/A double base_time_ms = predict_base_elapsed_time_ms(_pending_cards);
342N/A double predicted_pause_time_ms = base_time_ms;
342N/A
1576N/A double time_remaining_ms = target_pause_time_ms - base_time_ms;
342N/A
2748N/A ergo_verbose3(ErgoCSetConstruction | ErgoHigh,
2748N/A "start choosing CSet",
2748N/A ergo_format_ms("predicted base time")
2748N/A ergo_format_ms("remaining time")
2748N/A ergo_format_ms("target pause time"),
2748N/A base_time_ms, time_remaining_ms, target_pause_time_ms);
2748N/A
342N/A // the 10% and 50% values are arbitrary...
2748N/A double threshold = 0.10 * target_pause_time_ms;
2748N/A if (time_remaining_ms < threshold) {
2748N/A double prev_time_remaining_ms = time_remaining_ms;
1576N/A time_remaining_ms = 0.50 * target_pause_time_ms;
342N/A _within_target = false;
2748N/A ergo_verbose3(ErgoCSetConstruction,
2748N/A "adjust remaining time",
2748N/A ergo_format_reason("remaining time lower than threshold")
2748N/A ergo_format_ms("remaining time")
2748N/A ergo_format_ms("threshold")
2748N/A ergo_format_ms("adjusted remaining time"),
2748N/A prev_time_remaining_ms, threshold, time_remaining_ms);
342N/A } else {
342N/A _within_target = true;
342N/A }
342N/A
2748N/A size_t expansion_bytes = _g1->expansion_regions() * HeapRegion::GrainBytes;
2748N/A
2748N/A HeapRegion* hr;
2748N/A double young_start_time_sec = os::elapsedTime();
342N/A
677N/A _collection_set_bytes_used_before = 0;
677N/A _collection_set_size = 0;
2695N/A _young_cset_length = 0;
2695N/A _last_young_gc_full = full_young_gcs() ? true : false;
2695N/A
2748N/A if (_last_young_gc_full) {
2695N/A ++_full_young_pause_num;
2748N/A } else {
2695N/A ++_partial_young_pause_num;
2748N/A }
2695N/A
2695N/A // The young list is laid with the survivor regions from the previous
2695N/A // pause are appended to the RHS of the young list, i.e.
2695N/A // [Newly Young Regions ++ Survivors from last pause].
2695N/A
2748N/A size_t survivor_region_num = young_list->survivor_length();
2748N/A size_t eden_region_num = young_list->length() - survivor_region_num;
2748N/A size_t old_region_num = 0;
2748N/A hr = young_list->first_survivor_region();
2695N/A while (hr != NULL) {
2695N/A assert(hr->is_survivor(), "badly formed young list");
2695N/A hr->set_young();
2695N/A hr = hr->get_next_young_region();
2695N/A }
2695N/A
2748N/A // Clear the fields that point to the survivor list - they are all young now.
2748N/A young_list->clear_survivors();
2695N/A
2695N/A if (_g1->mark_in_progress())
2695N/A _g1->concurrent_mark()->register_collection_set_finger(_inc_cset_max_finger);
2695N/A
2695N/A _young_cset_length = _inc_cset_young_index;
2695N/A _collection_set = _inc_cset_head;
2695N/A _collection_set_size = _inc_cset_size;
2695N/A _collection_set_bytes_used_before = _inc_cset_bytes_used_before;
2695N/A time_remaining_ms -= _inc_cset_predicted_elapsed_time_ms;
2695N/A predicted_pause_time_ms += _inc_cset_predicted_elapsed_time_ms;
2695N/A
2748N/A ergo_verbose3(ErgoCSetConstruction | ErgoHigh,
2748N/A "add young regions to CSet",
2748N/A ergo_format_region("eden")
2748N/A ergo_format_region("survivors")
2748N/A ergo_format_ms("predicted young region time"),
2748N/A eden_region_num, survivor_region_num,
2748N/A _inc_cset_predicted_elapsed_time_ms);
2748N/A
2695N/A // The number of recorded young regions is the incremental
2695N/A // collection set's current size
2695N/A set_recorded_young_regions(_inc_cset_size);
2695N/A set_recorded_rs_lengths(_inc_cset_recorded_rs_lengths);
2695N/A set_recorded_young_bytes(_inc_cset_recorded_young_bytes);
1394N/A#if PREDICTIONS_VERBOSE
2695N/A set_predicted_bytes_to_copy(_inc_cset_predicted_bytes_to_copy);
1394N/A#endif // PREDICTIONS_VERBOSE
1394N/A
2748N/A assert(_inc_cset_size == young_list->length(), "Invariant");
2695N/A
2695N/A double young_end_time_sec = os::elapsedTime();
2695N/A _recorded_young_cset_choice_time_ms =
2695N/A (young_end_time_sec - young_start_time_sec) * 1000.0;
2695N/A
2695N/A // We are doing young collections so reset this.
2695N/A non_young_start_time_sec = young_end_time_sec;
2695N/A
2695N/A if (!full_young_gcs()) {
342N/A bool should_continue = true;
342N/A NumberSeq seq;
342N/A double avg_prediction = 100000000000000000.0; // something very large
1394N/A
2748N/A size_t prev_collection_set_size = _collection_set_size;
2748N/A double prev_predicted_pause_time_ms = predicted_pause_time_ms;
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);
1394N/A record_non_young_cset_region(hr);
342N/A seq.add(predicted_time_ms);
342N/A avg_prediction = seq.avg() + seq.sd();
342N/A }
2748N/A
2748N/A should_continue = true;
2748N/A if (hr == NULL) {
2748N/A // No need for an ergo verbose message here,
2748N/A // getNextMarkRegion() does this when it returns NULL.
2748N/A should_continue = false;
2748N/A } else {
2748N/A if (adaptive_young_list_length()) {
2748N/A if (time_remaining_ms < 0.0) {
2748N/A ergo_verbose1(ErgoCSetConstruction,
2748N/A "stop adding old regions to CSet",
2748N/A ergo_format_reason("remaining time is lower than 0")
2748N/A ergo_format_ms("remaining time"),
2748N/A time_remaining_ms);
2748N/A should_continue = false;
2748N/A }
2748N/A } else {
2748N/A if (_collection_set_size < _young_list_fixed_length) {
2748N/A ergo_verbose2(ErgoCSetConstruction,
2748N/A "stop adding old regions to CSet",
2748N/A ergo_format_reason("CSet length lower than target")
2748N/A ergo_format_region("CSet")
2748N/A ergo_format_region("young target"),
2748N/A _collection_set_size, _young_list_fixed_length);
2748N/A should_continue = false;
2748N/A }
2748N/A }
2748N/A }
342N/A } while (should_continue);
342N/A
342N/A if (!adaptive_young_list_length() &&
2748N/A _collection_set_size < _young_list_fixed_length) {
2748N/A ergo_verbose2(ErgoCSetConstruction,
2748N/A "request partially-young GCs end",
2748N/A ergo_format_reason("CSet length lower than target")
2748N/A ergo_format_region("CSet")
2748N/A ergo_format_region("young target"),
2748N/A _collection_set_size, _young_list_fixed_length);
342N/A _should_revert_to_full_young_gcs = true;
2748N/A }
2748N/A
2748N/A old_region_num = _collection_set_size - prev_collection_set_size;
2748N/A
2748N/A ergo_verbose2(ErgoCSetConstruction | ErgoHigh,
2748N/A "add old regions to CSet",
2748N/A ergo_format_region("old")
2748N/A ergo_format_ms("predicted old region time"),
2748N/A old_region_num,
2748N/A predicted_pause_time_ms - prev_predicted_pause_time_ms);
342N/A }
342N/A
1394N/A stop_incremental_cset_building();
1394N/A
342N/A count_CS_bytes_used();
342N/A
342N/A end_recording_regions();
342N/A
2748N/A ergo_verbose5(ErgoCSetConstruction,
2748N/A "finish choosing CSet",
2748N/A ergo_format_region("eden")
2748N/A ergo_format_region("survivors")
2748N/A ergo_format_region("old")
2748N/A ergo_format_ms("predicted pause time")
2748N/A ergo_format_ms("target pause time"),
2748N/A eden_region_num, survivor_region_num, old_region_num,
2748N/A predicted_pause_time_ms, target_pause_time_ms);
2748N/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::
1627N/Arecord_collection_pause_end() {
1627N/A G1CollectorPolicy::record_collection_pause_end();
342N/A assert(assertMarkedBytesDataOK(), "Marked regions not OK at pause end.");
342N/A}