g1CollectorPolicy.cpp revision 2973
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// 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
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 _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()),
2754N/A _using_new_ratio_calculations(false),
342N/A
677N/A _summary(new Summary()),
342N/A
2815N/A _cur_clear_ct_time_ms(0.0),
2943N/A _mark_closure_time_ms(0.0),
2815N/A
2815N/A _cur_ref_proc_time_ms(0.0),
2815N/A _cur_ref_enq_time_ms(0.0),
2815N/A
890N/A#ifndef PRODUCT
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 _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 _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 _rs_lengths_seq(new TruncatedSeq(TruncatedSeqLength)),
342N/A
751N/A _pause_time_target_ms((double) MaxGCPauseMillis),
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_avg_pause_time_ratio(0.0),
342N/A
342N/A _all_full_gc_times_ms(new NumberSeq()),
342N/A
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
2936N/A _eden_cset_region_length(0),
2936N/A _survivor_cset_region_length(0),
2936N/A _old_cset_region_length(0),
2936N/A
342N/A _collection_set(NULL),
1394N/A _collection_set_bytes_used_before(0),
1394N/A
1394N/A // Incremental CSet attributes
1394N/A _inc_cset_build_state(Inactive),
1394N/A _inc_cset_head(NULL),
1394N/A _inc_cset_tail(NULL),
1394N/A _inc_cset_bytes_used_before(0),
1394N/A _inc_cset_max_finger(NULL),
1394N/A _inc_cset_recorded_rs_lengths(0),
1394N/A _inc_cset_predicted_elapsed_time_ms(0.0),
1394N/A
342N/A#ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away
342N/A#pragma warning( disable:4355 ) // 'this' : used in base member initializer list
342N/A#endif // _MSC_VER
342N/A
342N/A _short_lived_surv_rate_group(new SurvRateGroup(this, "Short Lived",
342N/A G1YoungSurvRateNumRegionsSummary)),
342N/A _survivor_surv_rate_group(new SurvRateGroup(this, "Survivor",
545N/A G1YoungSurvRateNumRegionsSummary)),
342N/A // add here any more surv rate groups
545N/A _recorded_survivor_regions(0),
545N/A _recorded_survivor_head(NULL),
545N/A _recorded_survivor_tail(NULL),
1356N/A _survivors_age_table(true),
1356N/A
2748N/A _gc_overhead_perc(0.0) {
2748N/A
942N/A // Set up the region size and associated fields. Given that the
942N/A // policy is created before the heap, we have to set this up here,
942N/A // so it's done as soon as possible.
942N/A HeapRegion::setup_heap_region_size(Arguments::min_heap_size());
1261N/A HeapRegionRemSet::setup_remset_size();
942N/A
2748N/A G1ErgoVerbose::initialize();
2748N/A if (PrintAdaptiveSizePolicy) {
2748N/A // Currently, we only use a single switch for all the heuristics.
2748N/A G1ErgoVerbose::set_enabled(true);
2748N/A // Given that we don't currently have a verboseness level
2748N/A // parameter, we'll hardcode this to high. This can be easily
2748N/A // changed in the future.
2748N/A G1ErgoVerbose::set_level(ErgoHigh);
2748N/A } else {
2748N/A G1ErgoVerbose::set_enabled(false);
2748N/A }
2748N/A
1391N/A // Verify PLAB sizes
2822N/A const size_t region_size = HeapRegion::GrainWords;
1391N/A if (YoungPLABSize > region_size || OldPLABSize > region_size) {
1391N/A char buffer[128];
2822N/A jio_snprintf(buffer, sizeof(buffer), "%sPLABSize should be at most "SIZE_FORMAT,
1391N/A OldPLABSize > region_size ? "Old" : "Young", region_size);
1391N/A vm_exit_during_initialization(buffer);
1391N/A }
1391N/A
342N/A _recent_prev_end_times_for_all_gcs_sec->add(os::elapsedTime());
342N/A _prev_collection_pause_end_ms = os::elapsedTime() * 1000.0;
342N/A
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];
2861N/A _par_last_gc_worker_other_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 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
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
2753N/A // update_young_list_target_length() during initialization.
2696N/A _max_survivor_regions = 0;
545N/A
1356N/A assert(GCTimeRatio > 0,
1356N/A "we should have set it to a default value set_g1_gc_flags() "
1356N/A "if a user set it to 0");
1356N/A _gc_overhead_perc = 100.0 * (1.0 / (1.0 + GCTimeRatio));
1356N/A
2753N/A uintx reserve_perc = G1ReservePercent;
2753N/A // Put an artificial ceiling on this so that it's not set to a silly value.
2753N/A if (reserve_perc > 50) {
2753N/A reserve_perc = 50;
2753N/A warning("G1ReservePercent is set to a value that is too large, "
2753N/A "it's been updated to %u", reserve_perc);
2753N/A }
2753N/A _reserve_factor = (double) reserve_perc / 100.0;
2754N/A // This will be set when the heap is expanded
2753N/A // for the first time during initialization.
2753N/A _reserve_regions = 0;
2753N/A
342N/A initialize_all();
2849N/A _collectionSetChooser = new CollectionSetChooser();
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 {
2812N/Aprivate:
2812N/A size_t size_to_region_num(size_t byte_size) {
2812N/A return MAX2((size_t) 1, byte_size / HeapRegion::GrainBytes);
2812N/A }
1285N/A
1285N/Apublic:
1285N/A G1YoungGenSizer() {
1285N/A initialize_flags();
1285N/A initialize_size_info();
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
2754N/Avoid G1CollectorPolicy::update_young_list_size_using_newratio(size_t number_of_heap_regions) {
2754N/A assert(number_of_heap_regions > 0, "Heap must be initialized");
2754N/A size_t young_size = number_of_heap_regions / (NewRatio + 1);
2754N/A _min_desired_young_length = young_size;
2754N/A _max_desired_young_length = young_size;
2754N/A}
2754N/A
342N/Avoid G1CollectorPolicy::init() {
342N/A // Set aside an initial future to_space.
342N/A _g1 = G1CollectedHeap::heap();
342N/A
342N/A assert(Heap_lock->owned_by_self(), "Locking discipline.");
342N/A
545N/A initialize_gc_policy_counters();
545N/A
2695N/A G1YoungGenSizer sizer;
2754N/A _min_desired_young_length = sizer.min_young_region_num();
2754N/A _max_desired_young_length = sizer.max_young_region_num();
2754N/A
2754N/A if (FLAG_IS_CMDLINE(NewRatio)) {
2754N/A if (FLAG_IS_CMDLINE(NewSize) || FLAG_IS_CMDLINE(MaxNewSize)) {
2812N/A warning("-XX:NewSize and -XX:MaxNewSize override -XX:NewRatio");
2754N/A } else {
2754N/A // Treat NewRatio as a fixed size that is only recalculated when the heap size changes
2812N/A update_young_list_size_using_newratio(_g1->n_regions());
2754N/A _using_new_ratio_calculations = true;
2754N/A }
2754N/A }
2754N/A
2754N/A assert(_min_desired_young_length <= _max_desired_young_length, "Invalid min/max young gen size values");
2754N/A
2754N/A set_adaptive_young_list_length(_min_desired_young_length < _max_desired_young_length);
2754N/A if (adaptive_young_list_length()) {
2695N/A _young_list_fixed_length = 0;
1394N/A } else {
2863N/A assert(_min_desired_young_length == _max_desired_young_length, "Min and max young size differ");
2863N/A _young_list_fixed_length = _min_desired_young_length;
342N/A }
2695N/A _free_regions_at_end_of_collection = _g1->free_regions();
2753N/A update_young_list_target_length();
2754N/A _prev_eden_capacity = _young_list_target_length * HeapRegion::GrainBytes;
1394N/A
1394N/A // We may immediately start allocating regions and placing them on the
1394N/A // collection set list. Initialize the per-collection set info
1394N/A start_incremental_cset_building();
342N/A}
342N/A
545N/A// Create the jstat counters for the policy.
2753N/Avoid G1CollectorPolicy::initialize_gc_policy_counters() {
2695N/A _gc_policy_counters = new GCPolicyCounters("GarbageFirst", 1, 3);
545N/A}
545N/A
2753N/Abool G1CollectorPolicy::predict_will_fit(size_t young_length,
2753N/A double base_time_ms,
2753N/A size_t base_free_regions,
2753N/A double target_pause_time_ms) {
2753N/A if (young_length >= base_free_regions) {
342N/A // end condition 1: not enough space for the young regions
342N/A return false;
2753N/A }
2753N/A
2753N/A double accum_surv_rate = accum_yg_surv_rate_pred((int)(young_length - 1));
342N/A size_t bytes_to_copy =
2753N/A (size_t) (accum_surv_rate * (double) HeapRegion::GrainBytes);
342N/A double copy_time_ms = predict_object_copy_time_ms(bytes_to_copy);
2753N/A double young_other_time_ms = predict_young_other_time_ms(young_length);
2753N/A double pause_time_ms = base_time_ms + copy_time_ms + young_other_time_ms;
2753N/A if (pause_time_ms > target_pause_time_ms) {
2753N/A // end condition 2: prediction is over the target pause time
342N/A return false;
2753N/A }
342N/A
342N/A size_t free_bytes =
2753N/A (base_free_regions - young_length) * HeapRegion::GrainBytes;
2753N/A if ((2.0 * sigma()) * (double) bytes_to_copy > (double) free_bytes) {
2753N/A // end condition 3: out-of-space (conservatively!)
342N/A return false;
2753N/A }
342N/A
342N/A // success!
342N/A return true;
342N/A}
342N/A
2754N/Avoid G1CollectorPolicy::record_new_heap_size(size_t new_number_of_regions) {
2754N/A // re-calculate the necessary reserve
2754N/A double reserve_regions_d = (double) new_number_of_regions * _reserve_factor;
2753N/A // We use ceiling so that if reserve_regions_d is > 0.0 (but
2753N/A // smaller than 1.0) we'll get 1.
2753N/A _reserve_regions = (size_t) ceil(reserve_regions_d);
2754N/A
2754N/A if (_using_new_ratio_calculations) {
2754N/A // -XX:NewRatio was specified so we need to update the
2754N/A // young gen length when the heap size has changed.
2754N/A update_young_list_size_using_newratio(new_number_of_regions);
2754N/A }
2753N/A}
2753N/A
2753N/Asize_t G1CollectorPolicy::calculate_young_list_desired_min_length(
2753N/A size_t base_min_length) {
2753N/A size_t desired_min_length = 0;
2753N/A if (adaptive_young_list_length()) {
2753N/A if (_alloc_rate_ms_seq->num() > 3) {
2753N/A double now_sec = os::elapsedTime();
2753N/A double when_ms = _mmu_tracker->when_max_gc_sec(now_sec) * 1000.0;
2753N/A double alloc_rate_ms = predict_alloc_rate_ms();
2753N/A desired_min_length = (size_t) ceil(alloc_rate_ms * when_ms);
2753N/A } else {
2753N/A // otherwise we don't have enough info to make the prediction
2753N/A }
2753N/A }
2754N/A desired_min_length += base_min_length;
2754N/A // make sure we don't go below any user-defined minimum bound
2754N/A return MAX2(_min_desired_young_length, desired_min_length);
2753N/A}
2753N/A
2753N/Asize_t G1CollectorPolicy::calculate_young_list_desired_max_length() {
2753N/A // Here, we might want to also take into account any additional
2753N/A // constraints (i.e., user-defined minimum bound). Currently, we
2753N/A // effectively don't set this bound.
2754N/A return _max_desired_young_length;
2753N/A}
2753N/A
2753N/Avoid G1CollectorPolicy::update_young_list_target_length(size_t rs_lengths) {
2753N/A if (rs_lengths == (size_t) -1) {
2753N/A // if it's set to the default value (-1), we should predict it;
2753N/A // otherwise, use the given value.
2753N/A rs_lengths = (size_t) get_new_prediction(_rs_lengths_seq);
2753N/A }
2753N/A
2753N/A // Calculate the absolute and desired min bounds.
2753N/A
2753N/A // This is how many young regions we already have (currently: the survivors).
2753N/A size_t base_min_length = recorded_survivor_regions();
2753N/A // This is the absolute minimum young length, which ensures that we
2753N/A // can allocate one eden region in the worst-case.
2753N/A size_t absolute_min_length = base_min_length + 1;
2753N/A size_t desired_min_length =
2753N/A calculate_young_list_desired_min_length(base_min_length);
2753N/A if (desired_min_length < absolute_min_length) {
2753N/A desired_min_length = absolute_min_length;
2753N/A }
2753N/A
2753N/A // Calculate the absolute and desired max bounds.
2753N/A
2753N/A // We will try our best not to "eat" into the reserve.
2753N/A size_t absolute_max_length = 0;
2753N/A if (_free_regions_at_end_of_collection > _reserve_regions) {
2753N/A absolute_max_length = _free_regions_at_end_of_collection - _reserve_regions;
2753N/A }
2753N/A size_t desired_max_length = calculate_young_list_desired_max_length();
2753N/A if (desired_max_length > absolute_max_length) {
2753N/A desired_max_length = absolute_max_length;
2753N/A }
2753N/A
2753N/A size_t young_list_target_length = 0;
2753N/A if (adaptive_young_list_length()) {
2753N/A if (full_young_gcs()) {
2753N/A young_list_target_length =
2753N/A calculate_young_list_target_length(rs_lengths,
2753N/A base_min_length,
2753N/A desired_min_length,
2753N/A desired_max_length);
2753N/A _rs_lengths_prediction = rs_lengths;
2753N/A } else {
2753N/A // Don't calculate anything and let the code below bound it to
2753N/A // the desired_min_length, i.e., do the next GC as soon as
2753N/A // possible to maximize how many old regions we can add to it.
2753N/A }
2753N/A } else {
2753N/A if (full_young_gcs()) {
2753N/A young_list_target_length = _young_list_fixed_length;
2753N/A } else {
2753N/A // A bit arbitrary: during partially-young GCs we allocate half
2753N/A // the young regions to try to add old regions to the CSet.
2753N/A young_list_target_length = _young_list_fixed_length / 2;
2753N/A // We choose to accept that we might go under the desired min
2753N/A // length given that we intentionally ask for a smaller young gen.
2753N/A desired_min_length = absolute_min_length;
2753N/A }
2753N/A }
2753N/A
2753N/A // Make sure we don't go over the desired max length, nor under the
2753N/A // desired min length. In case they clash, desired_min_length wins
2753N/A // which is why that test is second.
2753N/A if (young_list_target_length > desired_max_length) {
2753N/A young_list_target_length = desired_max_length;
2753N/A }
2753N/A if (young_list_target_length < desired_min_length) {
2753N/A young_list_target_length = desired_min_length;
2753N/A }
2753N/A
2753N/A assert(young_list_target_length > recorded_survivor_regions(),
2753N/A "we should be able to allocate at least one eden region");
2753N/A assert(young_list_target_length >= absolute_min_length, "post-condition");
2753N/A _young_list_target_length = young_list_target_length;
2753N/A
2753N/A update_max_gc_locker_expansion();
2753N/A}
2753N/A
2753N/Asize_t
2753N/AG1CollectorPolicy::calculate_young_list_target_length(size_t rs_lengths,
2753N/A size_t base_min_length,
2753N/A size_t desired_min_length,
2753N/A size_t desired_max_length) {
2753N/A assert(adaptive_young_list_length(), "pre-condition");
2753N/A assert(full_young_gcs(), "only call this for fully-young GCs");
2753N/A
2753N/A // In case some edge-condition makes the desired max length too small...
2753N/A if (desired_max_length <= desired_min_length) {
2753N/A return desired_min_length;
2753N/A }
2753N/A
2753N/A // We'll adjust min_young_length and max_young_length not to include
2753N/A // the already allocated young regions (i.e., so they reflect the
2753N/A // min and max eden regions we'll allocate). The base_min_length
2753N/A // will be reflected in the predictions by the
2753N/A // survivor_regions_evac_time prediction.
2753N/A assert(desired_min_length > base_min_length, "invariant");
2753N/A size_t min_young_length = desired_min_length - base_min_length;
2753N/A assert(desired_max_length > base_min_length, "invariant");
2753N/A size_t max_young_length = desired_max_length - base_min_length;
2753N/A
2753N/A double target_pause_time_ms = _mmu_tracker->max_gc_time() * 1000.0;
2753N/A double survivor_regions_evac_time = predict_survivor_regions_evac_time();
2753N/A size_t pending_cards = (size_t) get_new_prediction(_pending_cards_seq);
2753N/A size_t adj_rs_lengths = rs_lengths + predict_rs_length_diff();
2753N/A size_t scanned_cards = predict_young_card_num(adj_rs_lengths);
2753N/A double base_time_ms =
2753N/A predict_base_elapsed_time_ms(pending_cards, scanned_cards) +
2753N/A survivor_regions_evac_time;
2753N/A size_t available_free_regions = _free_regions_at_end_of_collection;
2753N/A size_t base_free_regions = 0;
2753N/A if (available_free_regions > _reserve_regions) {
2753N/A base_free_regions = available_free_regions - _reserve_regions;
2753N/A }
2753N/A
2753N/A // Here, we will make sure that the shortest young length that
2753N/A // makes sense fits within the target pause time.
2753N/A
2753N/A if (predict_will_fit(min_young_length, base_time_ms,
2753N/A base_free_regions, target_pause_time_ms)) {
2753N/A // The shortest young length will fit into the target pause time;
2753N/A // we'll now check whether the absolute maximum number of young
2753N/A // regions will fit in the target pause time. If not, we'll do
2753N/A // a binary search between min_young_length and max_young_length.
2753N/A if (predict_will_fit(max_young_length, base_time_ms,
2753N/A base_free_regions, target_pause_time_ms)) {
2753N/A // The maximum young length will fit into the target pause time.
2753N/A // We are done so set min young length to the maximum length (as
2753N/A // the result is assumed to be returned in min_young_length).
2753N/A min_young_length = max_young_length;
2753N/A } else {
2753N/A // The maximum possible number of young regions will not fit within
2753N/A // the target pause time so we'll search for the optimal
2753N/A // length. The loop invariants are:
2753N/A //
2753N/A // min_young_length < max_young_length
2753N/A // min_young_length is known to fit into the target pause time
2753N/A // max_young_length is known not to fit into the target pause time
2753N/A //
2753N/A // Going into the loop we know the above hold as we've just
2753N/A // checked them. Every time around the loop we check whether
2753N/A // the middle value between min_young_length and
2753N/A // max_young_length fits into the target pause time. If it
2753N/A // does, it becomes the new min. If it doesn't, it becomes
2753N/A // the new max. This way we maintain the loop invariants.
2753N/A
2753N/A assert(min_young_length < max_young_length, "invariant");
2753N/A size_t diff = (max_young_length - min_young_length) / 2;
2753N/A while (diff > 0) {
2753N/A size_t young_length = min_young_length + diff;
2753N/A if (predict_will_fit(young_length, base_time_ms,
2753N/A base_free_regions, target_pause_time_ms)) {
2753N/A min_young_length = young_length;
2753N/A } else {
2753N/A max_young_length = young_length;
2753N/A }
2753N/A assert(min_young_length < max_young_length, "invariant");
2753N/A diff = (max_young_length - min_young_length) / 2;
2753N/A }
2753N/A // The results is min_young_length which, according to the
2753N/A // loop invariants, should fit within the target pause time.
2753N/A
2753N/A // These are the post-conditions of the binary search above:
2753N/A assert(min_young_length < max_young_length,
2753N/A "otherwise we should have discovered that max_young_length "
2753N/A "fits into the pause target and not done the binary search");
2753N/A assert(predict_will_fit(min_young_length, base_time_ms,
2753N/A base_free_regions, target_pause_time_ms),
2753N/A "min_young_length, the result of the binary search, should "
2753N/A "fit into the pause target");
2753N/A assert(!predict_will_fit(min_young_length + 1, base_time_ms,
2753N/A base_free_regions, target_pause_time_ms),
2753N/A "min_young_length, the result of the binary search, should be "
2753N/A "optimal, so no larger length should fit into the pause target");
2753N/A }
2753N/A } else {
2753N/A // Even the minimum length doesn't fit into the pause time
2753N/A // target, return it as the result nevertheless.
2753N/A }
2753N/A return base_min_length + min_young_length;
2753N/A}
2753N/A
545N/Adouble G1CollectorPolicy::predict_survivor_regions_evac_time() {
545N/A double survivor_regions_evac_time = 0.0;
545N/A for (HeapRegion * r = _recorded_survivor_head;
545N/A r != NULL && r != _recorded_survivor_tail->get_next_young_region();
545N/A r = r->get_next_young_region()) {
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
2753N/Avoid G1CollectorPolicy::revise_young_list_target_length_if_necessary() {
342N/A guarantee( adaptive_young_list_length(), "should not call this otherwise" );
342N/A
1394N/A size_t rs_lengths = _g1->young_list()->sampled_rs_lengths();
342N/A if (rs_lengths > _rs_lengths_prediction) {
342N/A // add 10% to avoid having to recalculate often
342N/A size_t rs_lengths_prediction = rs_lengths * 1100 / 1000;
2753N/A update_young_list_target_length(rs_lengths_prediction);
342N/A }
342N/A}
342N/A
2753N/A
2753N/A
342N/AHeapWord* G1CollectorPolicy::mem_allocate_work(size_t size,
342N/A bool is_tlab,
342N/A bool* gc_overhead_limit_was_exceeded) {
342N/A guarantee(false, "Not using this policy feature yet.");
342N/A return NULL;
342N/A}
342N/A
342N/A// This method controls how a collector handles one or more
342N/A// of its generations being fully allocated.
342N/AHeapWord* G1CollectorPolicy::satisfy_failed_allocation(size_t size,
342N/A bool is_tlab) {
342N/A guarantee(false, "Not using this policy feature yet.");
342N/A return NULL;
342N/A}
342N/A
342N/A
342N/A#ifndef PRODUCT
342N/Abool G1CollectorPolicy::verify_young_ages() {
1394N/A HeapRegion* head = _g1->young_list()->first_region();
342N/A return
342N/A verify_young_ages(head, _short_lived_surv_rate_group);
342N/A // also call verify_young_ages on any additional surv rate groups
342N/A}
342N/A
342N/Abool
342N/AG1CollectorPolicy::verify_young_ages(HeapRegion* head,
342N/A SurvRateGroup *surv_rate_group) {
342N/A guarantee( surv_rate_group != NULL, "pre-condition" );
342N/A
342N/A const char* name = surv_rate_group->name();
342N/A bool ret = true;
342N/A int prev_age = -1;
342N/A
342N/A for (HeapRegion* curr = head;
342N/A curr != NULL;
342N/A curr = curr->get_next_young_region()) {
342N/A SurvRateGroup* group = curr->surv_rate_group();
342N/A if (group == NULL && !curr->is_survivor()) {
342N/A gclog_or_tty->print_cr("## %s: encountered NULL surv_rate_group", name);
342N/A ret = false;
342N/A }
342N/A
342N/A if (surv_rate_group == group) {
342N/A int age = curr->age_in_surv_rate_group();
342N/A
342N/A if (age < 0) {
342N/A gclog_or_tty->print_cr("## %s: encountered negative age", name);
342N/A ret = false;
342N/A }
342N/A
342N/A if (age <= prev_age) {
342N/A gclog_or_tty->print_cr("## %s: region ages are not strictly increasing "
342N/A "(%d, %d)", name, age, prev_age);
342N/A ret = false;
342N/A }
342N/A prev_age = age;
342N/A }
342N/A }
342N/A
342N/A return ret;
342N/A}
342N/A#endif // PRODUCT
342N/A
342N/Avoid G1CollectorPolicy::record_full_collection_start() {
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 _free_regions_at_end_of_collection = _g1->free_regions();
545N/A // Reset survivors SurvRateGroup.
545N/A _survivor_surv_rate_group->reset();
2753N/A update_young_list_target_length();
2849N/A _collectionSetChooser->updateAfterFullCollection();
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
2753N/A // We only need to do this here as the policy will only be applied
2753N/A // to the GC we're about to start. so, no point is calculating this
2753N/A // every time we calculate / recalculate the target young length.
2753N/A update_survivors_policy();
2753N/A
1880N/A assert(_g1->used() == _g1->recalculate_used(),
1880N/A err_msg("sanity, used: "SIZE_FORMAT" recalculate_used: "SIZE_FORMAT,
1880N/A _g1->used(), _g1->recalculate_used()));
342N/A
342N/A double s_w_t_ms = (start_time_sec - _stop_world_start) * 1000.0;
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;
2861N/A _par_last_gc_worker_other_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
2942N/A // This is initialized to zero here and is set during
2861N/A // the evacuation pause if marking is in progress.
2861N/A _cur_satb_drain_time_ms = 0.0;
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
2695N/Avoid G1CollectorPolicy::record_concurrent_mark_init_end(double
342N/A mark_init_elapsed_time_ms) {
342N/A _during_marking = true;
1359N/A assert(!initiate_conc_mark_if_possible(), "we should have cleared it by now");
1359N/A clear_during_initial_mark_pause();
342N/A _cur_mark_stop_world_time_ms = mark_init_elapsed_time_ms;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_mark_remark_start() {
342N/A _mark_remark_start_sec = os::elapsedTime();
342N/A _during_marking = false;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_mark_remark_end() {
342N/A double end_time_sec = os::elapsedTime();
342N/A double elapsed_time_ms = (end_time_sec - _mark_remark_start_sec)*1000.0;
342N/A _concurrent_mark_remark_times_ms->add(elapsed_time_ms);
342N/A _cur_mark_stop_world_time_ms += elapsed_time_ms;
342N/A _prev_collection_pause_end_ms += elapsed_time_ms;
342N/A
342N/A _mmu_tracker->add_pause(_mark_remark_start_sec, end_time_sec, true);
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_mark_cleanup_start() {
342N/A _mark_cleanup_start_sec = os::elapsedTime();
342N/A}
342N/A
2849N/Avoid G1CollectorPolicy::record_concurrent_mark_cleanup_completed() {
2695N/A _should_revert_to_full_young_gcs = false;
2695N/A _last_full_young_gc = true;
2695N/A _in_marking_window = false;
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::record_concurrent_pause() {
342N/A if (_stop_world_start > 0.0) {
342N/A double yield_ms = (os::elapsedTime() - _stop_world_start) * 1000.0;
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);
2941N/A for (uint i = 0; i < no_of_gc_threads(); ++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("");
2941N/A double avg = total / (double) no_of_gc_threads();
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);
2941N/A for (uint i = 0; i < no_of_gc_threads(); ++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("");
2941N/A double avg = total / (double) no_of_gc_threads();
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
2861N/Avoid G1CollectorPolicy::print_stats(int level,
2861N/A const char* str,
2861N/A double value) {
2210N/A LineBuffer(level).append_and_print_cr("[%s: %5.1lf ms]", str, value);
342N/A}
342N/A
2861N/Avoid G1CollectorPolicy::print_stats(int level,
2861N/A const char* str,
2861N/A int value) {
2210N/A LineBuffer(level).append_and_print_cr("[%s: %d]", str, value);
342N/A}
342N/A
2861N/Adouble G1CollectorPolicy::avg_value(double* data) {
1753N/A if (G1CollectedHeap::use_parallel_gc_threads()) {
342N/A double ret = 0.0;
2941N/A for (uint i = 0; i < no_of_gc_threads(); ++i) {
342N/A ret += data[i];
2861N/A }
2941N/A return ret / (double) no_of_gc_threads();
342N/A } else {
342N/A return data[0];
342N/A }
342N/A}
342N/A
2861N/Adouble G1CollectorPolicy::max_value(double* data) {
1753N/A if (G1CollectedHeap::use_parallel_gc_threads()) {
342N/A double ret = data[0];
2941N/A for (uint i = 1; i < no_of_gc_threads(); ++i) {
2861N/A if (data[i] > ret) {
342N/A ret = data[i];
2861N/A }
2861N/A }
342N/A return ret;
342N/A } else {
342N/A return data[0];
342N/A }
342N/A}
342N/A
2861N/Adouble G1CollectorPolicy::sum_of_values(double* data) {
1753N/A if (G1CollectedHeap::use_parallel_gc_threads()) {
342N/A double sum = 0.0;
2941N/A for (uint i = 0; i < no_of_gc_threads(); i++) {
342N/A sum += data[i];
2861N/A }
342N/A return sum;
342N/A } else {
342N/A return data[0];
342N/A }
342N/A}
342N/A
2861N/Adouble G1CollectorPolicy::max_sum(double* data1, double* data2) {
342N/A double ret = data1[0] + data2[0];
342N/A
1753N/A if (G1CollectedHeap::use_parallel_gc_threads()) {
2941N/A for (uint i = 1; i < no_of_gc_threads(); ++i) {
342N/A double data = data1[i] + data2[i];
2861N/A if (data > ret) {
342N/A ret = data;
2861N/A }
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
2941N/Avoid G1CollectorPolicy::record_collection_pause_end(int no_of_gc_threads) {
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();
2936N/A assert(_cur_collection_pause_used_regions_at_start >= cset_region_length(),
2936N/A "otherwise, the subtraction below does not make sense");
342N/A size_t rs_size =
2936N/A _cur_collection_pause_used_regions_at_start - cset_region_length();
342N/A size_t cur_used_bytes = _g1->used();
342N/A assert(cur_used_bytes == _g1->recalculate_used(), "It should!");
342N/A bool last_pause_included_initial_mark = false;
1627N/A bool update_stats = !_g1->evacuation_failed();
2941N/A set_no_of_gc_threads(no_of_gc_threads);
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 // 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
2861N/A // These values are used to update the summary information that is
2861N/A // displayed when TraceGen0Time is enabled, and are output as part
2861N/A // of the PrintGCDetails output, in the non-parallel case.
2861N/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
2861N/A double known_time = ext_root_scan_time +
2861N/A mark_stack_scan_time +
2861N/A update_rs_time +
2861N/A scan_rs_time +
2861N/A obj_copy_time;
2861N/A
2861N/A double other_time_ms = elapsed_ms;
2861N/A
2861N/A // Subtract the SATB drain time. It's initialized to zero at the
2861N/A // start of the pause and is updated during the pause if marking
2861N/A // is in progress.
2861N/A other_time_ms -= _cur_satb_drain_time_ms;
2861N/A
2861N/A if (parallel) {
2861N/A other_time_ms -= _cur_collection_par_time_ms;
2861N/A } else {
2861N/A other_time_ms -= known_time;
2861N/A }
2861N/A
2861N/A // Subtract the time taken to clean the card table from the
2861N/A // current value of "other time"
2861N/A other_time_ms -= _cur_clear_ct_time_ms;
2861N/A
2943N/A // Subtract the time spent completing marking in the collection
2943N/A // set. Note if marking is not in progress during the pause
2943N/A // the value of _mark_closure_time_ms will be zero.
2943N/A other_time_ms -= _mark_closure_time_ms;
2943N/A
2861N/A // TraceGen0Time and TraceGen1Time summary info updating.
2861N/A _all_pause_times_ms->add(elapsed_ms);
2648N/A
595N/A if (update_stats) {
2861N/A _summary->record_total_time_ms(elapsed_ms);
2861N/A _summary->record_other_time_ms(other_time_ms);
2861N/A
2861N/A MainBodySummary* body_summary = _summary->main_body_summary();
2861N/A assert(body_summary != NULL, "should not be null!");
2861N/A
2861N/A // This will be non-zero iff marking is currently in progress (i.e.
2861N/A // _g1->mark_in_progress() == true) and the currrent pause was not
2861N/A // an initial mark pause. Since the body_summary items are NumberSeqs,
2861N/A // however, they have to be consistent and updated in lock-step with
2861N/A // each other. Therefore we unconditionally record the SATB drain
2861N/A // time - even if it's zero.
2861N/A body_summary->record_satb_drain_time_ms(_cur_satb_drain_time_ms);
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);
2861N/A
2648N/A if (parallel) {
2648N/A body_summary->record_parallel_time_ms(_cur_collection_par_time_ms);
2648N/A body_summary->record_termination_time_ms(termination_time);
2861N/A
2861N/A double parallel_known_time = known_time + termination_time;
2861N/A double parallel_other_time = _cur_collection_par_time_ms - parallel_known_time;
2648N/A body_summary->record_parallel_other_time_ms(parallel_other_time);
2648N/A }
2861N/A
2648N/A body_summary->record_mark_closure_time_ms(_mark_closure_time_ms);
2861N/A body_summary->record_clear_ct_time_ms(_cur_clear_ct_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!");
2861N/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 }
2936N/A // We maintain the invariant that all objects allocated by mutator
2936N/A // threads will be allocated out of eden regions. So, we can use
2936N/A // the eden region number allocated since the previous GC to
2936N/A // calculate the application's allocate rate. The only exception
2936N/A // to that is humongous objects that are allocated separately. But
2936N/A // given that humongous object allocations do not really affect
2936N/A // either the pause's duration nor when the next pause will take
2936N/A // place we can safely ignore them here.
2936N/A size_t regions_allocated = eden_cset_region_length();
342N/A double alloc_rate_ms = (double) regions_allocated / app_time_ms;
342N/A _alloc_rate_ms_seq->add(alloc_rate_ms);
342N/A
342N/A double interval_ms =
342N/A (end_time_sec - _recent_prev_end_times_for_all_gcs_sec->oldest()) * 1000.0;
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
2861N/A for (int i = 0; i < _aux_num; ++i) {
2861N/A if (_cur_aux_times_set[i]) {
2861N/A _all_aux_times_ms[i].add(_cur_aux_times_ms[i]);
2861N/A }
2861N/A }
2861N/A
2861N/A // PrintGCDetails output
342N/A if (PrintGCDetails) {
2861N/A bool print_marking_info =
2861N/A _g1->mark_in_progress() && !last_pause_included_initial_mark;
2861N/A
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
2861N/A if (print_marking_info) {
1627N/A print_stats(1, "SATB Drain Time", _cur_satb_drain_time_ms);
1627N/A }
2861N/A
1627N/A if (parallel) {
1627N/A print_stats(1, "Parallel Time", _cur_collection_par_time_ms);
2861N/A print_par_stats(2, "GC Worker Start", _par_last_gc_worker_start_times_ms);
2861N/A print_par_stats(2, "Ext Root Scanning", _par_last_ext_root_scan_times_ms);
2861N/A if (print_marking_info) {
2861N/A print_par_stats(2, "Mark Stack Scanning", _par_last_mark_stack_scan_times_ms);
2861N/A }
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);
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);
2861N/A print_par_stats(2, "GC Worker End", _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];
2861N/A
2861N/A double worker_known_time = _par_last_ext_root_scan_times_ms[i] +
2861N/A _par_last_mark_stack_scan_times_ms[i] +
2861N/A _par_last_update_rs_times_ms[i] +
2861N/A _par_last_scan_rs_times_ms[i] +
2861N/A _par_last_obj_copy_times_ms[i] +
2861N/A _par_last_termination_times_ms[i];
2861N/A
2861N/A _par_last_gc_worker_other_times_ms[i] = _cur_collection_par_time_ms - worker_known_time;
2277N/A }
2861N/A print_par_stats(2, "GC Worker", _par_last_gc_worker_times_ms);
2861N/A print_par_stats(2, "GC Worker Other", _par_last_gc_worker_other_times_ms);
1627N/A } else {
2861N/A print_stats(1, "Ext Root Scanning", ext_root_scan_time);
2861N/A if (print_marking_info) {
2861N/A print_stats(1, "Mark Stack Scanning", mark_stack_scan_time);
2861N/A }
1627N/A print_stats(1, "Update RS", update_rs_time);
2861N/A print_stats(2, "Processed Buffers", (int)update_rs_processed_buffers);
1627N/A print_stats(1, "Scan RS", scan_rs_time);
1627N/A print_stats(1, "Object Copying", obj_copy_time);
342N/A }
2943N/A if (print_marking_info) {
2943N/A print_stats(1, "Complete CSet Marking", _mark_closure_time_ms);
2943N/A }
2861N/A print_stats(1, "Clear CT", _cur_clear_ct_time_ms);
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);
2943N/A print_stats(2, "Choose CSet",
2943N/A (_recorded_young_cset_choice_time_ms +
2943N/A _recorded_non_young_cset_choice_time_ms));
2815N/A print_stats(2, "Ref Proc", _cur_ref_proc_time_ms);
2815N/A print_stats(2, "Ref Enq", _cur_ref_enq_time_ms);
2943N/A print_stats(2, "Free CSet",
2943N/A (_recorded_young_free_cset_time_ms +
2943N/A _recorded_non_young_free_cset_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 // 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) {
2818N/A if (!last_pause_included_initial_mark) {
2818N/A ergo_verbose2(ErgoPartiallyYoungGCs,
2818N/A "start partially-young GCs",
2818N/A ergo_format_byte_perc("known garbage"),
2818N/A _known_garbage_bytes, _known_garbage_ratio * 100.0);
2818N/A set_full_young_gcs(false);
2818N/A } else {
2818N/A ergo_verbose0(ErgoPartiallyYoungGCs,
2818N/A "do not start partially-young GCs",
2818N/A ergo_format_reason("concurrent cycle is about to start"));
2818N/A }
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
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
2973N/A // It turns out that, sometimes, _max_rs_lengths can get smaller
2973N/A // than _recorded_rs_lengths which causes rs_length_diff to get
2973N/A // very large and mess up the RSet length predictions. We'll be
2973N/A // defensive until we work out why this happens.
2973N/A size_t rs_length_diff = 0;
2973N/A if (_max_rs_lengths > _recorded_rs_lengths) {
2973N/A rs_length_diff = _max_rs_lengths - _recorded_rs_lengths;
2973N/A }
2973N/A _rs_length_diff_seq->add((double) rs_length_diff);
342N/A
342N/A size_t copied_bytes = surviving_bytes;
342N/A double cost_per_byte_ms = 0.0;
342N/A if (copied_bytes > 0) {
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;
2936N/A if (young_cset_region_length() > 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 /
2936N/A (double) young_cset_region_length());
342N/A }
342N/A double non_young_other_time_ms = 0.0;
2936N/A if (old_cset_region_length() > 0) {
342N/A non_young_other_time_ms =
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 /
2936N/A (double) old_cset_region_length());
342N/A }
342N/A
342N/A double constant_other_time_ms = all_other_time_ms -
342N/A (young_other_time_ms + non_young_other_time_ms);
342N/A _constant_other_time_ms_seq->add(constant_other_time_ms);
342N/A
342N/A double survival_ratio = 0.0;
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 _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
342N/A _in_marking_window = new_in_marking_window;
342N/A _in_marking_window_im = new_in_marking_window_im;
342N/A _free_regions_at_end_of_collection = _g1->free_regions();
2753N/A update_young_list_target_length();
342N/A
1111N/A // Note that _mmu_tracker->max_gc_time() returns the time in seconds.
1282N/A double update_rs_time_goal_ms = _mmu_tracker->max_gc_time() * MILLIUNITS * G1RSetUpdatingPauseTimePercent / 100.0;
1111N/A adjust_concurrent_refinement(update_rs_time, update_rs_processed_buffers, update_rs_time_goal_ms);
2849N/A
2849N/A assert(assertMarkedBytesDataOK(), "Marked regions not OK at pause end.");
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();
2754N/A size_t eden_capacity =
2754N/A (_young_list_target_length * HeapRegion::GrainBytes) - survivor_bytes;
2589N/A
2589N/A gclog_or_tty->print_cr(
2754N/A " [Eden: "EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")->"EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT") "
2754N/A "Survivors: "EXT_SIZE_FORMAT"->"EXT_SIZE_FORMAT" "
2754N/A "Heap: "EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")->"
2754N/A EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")]",
2754N/A EXT_SIZE_PARAMS(_eden_bytes_before_gc),
2754N/A EXT_SIZE_PARAMS(_prev_eden_capacity),
2754N/A EXT_SIZE_PARAMS(eden_bytes),
2754N/A EXT_SIZE_PARAMS(eden_capacity),
2754N/A EXT_SIZE_PARAMS(_survivor_bytes_before_gc),
2754N/A EXT_SIZE_PARAMS(survivor_bytes),
2754N/A EXT_SIZE_PARAMS(used_before_gc),
2754N/A EXT_SIZE_PARAMS(_capacity_before_gc),
2754N/A EXT_SIZE_PARAMS(used),
2754N/A EXT_SIZE_PARAMS(capacity));
2754N/A
2754N/A _prev_eden_capacity = eden_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
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
2936N/AG1CollectorPolicy::init_cset_region_lengths(size_t eden_cset_region_length,
2936N/A size_t survivor_cset_region_length) {
2936N/A _eden_cset_region_length = eden_cset_region_length;
2936N/A _survivor_cset_region_length = survivor_cset_region_length;
2936N/A _old_cset_region_length = 0;
1394N/A}
1394N/A
1394N/Avoid G1CollectorPolicy::set_recorded_rs_lengths(size_t rs_lengths) {
1394N/A _recorded_rs_lengths = rs_lengths;
1394N/A}
1394N/A
342N/Avoid G1CollectorPolicy::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/Avoid G1CollectorPolicy::update_recent_gc_times(double end_time_sec,
342N/A double elapsed_ms) {
342N/A _recent_gc_times_ms->add(elapsed_ms);
342N/A _recent_prev_end_times_for_all_gcs_sec->add(end_time_sec);
342N/A _prev_collection_pause_end_ms = end_time_sec * 1000.0;
342N/A}
342N/A
342N/Asize_t G1CollectorPolicy::expansion_amount() {
2748N/A double recent_gc_overhead = recent_avg_pause_time_ratio() * 100.0;
2748N/A double threshold = _gc_overhead_perc;
2748N/A if (recent_gc_overhead > threshold) {
751N/A // We will double the existing space, or take
751N/A // G1ExpandByPercentOfAvailable % of the available expansion
751N/A // space, whichever is smaller, bounded below by a minimum
751N/A // expansion (unless that's all that's left.)
342N/A const size_t min_expand_bytes = 1*M;
2069N/A size_t reserved_bytes = _g1->max_capacity();
342N/A size_t committed_bytes = _g1->capacity();
342N/A size_t uncommitted_bytes = reserved_bytes - committed_bytes;
342N/A size_t expand_bytes;
342N/A size_t expand_bytes_via_pct =
751N/A uncommitted_bytes * G1ExpandByPercentOfAvailable / 100;
342N/A expand_bytes = MIN2(expand_bytes_via_pct, committed_bytes);
342N/A expand_bytes = MAX2(expand_bytes, min_expand_bytes);
342N/A expand_bytes = MIN2(expand_bytes, uncommitted_bytes);
2748N/A
2748N/A ergo_verbose5(ErgoHeapSizing,
2748N/A "attempt heap expansion",
2748N/A ergo_format_reason("recent GC overhead higher than "
2748N/A "threshold after GC")
2748N/A ergo_format_perc("recent GC overhead")
2748N/A ergo_format_perc("threshold")
2748N/A ergo_format_byte("uncommitted")
2748N/A ergo_format_byte_perc("calculated expansion amount"),
2748N/A recent_gc_overhead, threshold,
2748N/A uncommitted_bytes,
2748N/A expand_bytes_via_pct, (double) G1ExpandByPercentOfAvailable);
2748N/A
342N/A return expand_bytes;
342N/A } else {
342N/A return 0;
342N/A }
342N/A}
342N/A
342N/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
2861N/Avoid G1CollectorPolicy::print_summary(int level,
2861N/A const char* str,
2861N/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
2861N/Avoid G1CollectorPolicy::print_summary_sd(int level,
2861N/A const char* str,
2861N/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());
2861N/A print_summary(2, "Ext Root Scanning", body_summary->get_ext_root_scan_seq());
2861N/A print_summary(2, "Mark Stack Scanning", body_summary->get_mark_stack_scan_seq());
342N/A print_summary(2, "Update RS", body_summary->get_update_rs_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());
2861N/A print_summary(2, "Parallel Other", body_summary->get_parallel_other_seq());
342N/A {
342N/A NumberSeq* other_parts[] = {
342N/A body_summary->get_ext_root_scan_seq(),
342N/A body_summary->get_mark_stack_scan_seq(),
2861N/A body_summary->get_update_rs_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 } else {
2861N/A print_summary(1, "Ext Root Scanning", body_summary->get_ext_root_scan_seq());
2861N/A print_summary(1, "Mark Stack Scanning", body_summary->get_mark_stack_scan_seq());
342N/A print_summary(1, "Update RS", body_summary->get_update_rs_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 }
2861N/A print_summary(1, "Mark Closure", body_summary->get_mark_closure_seq());
2861N/A print_summary(1, "Clear CT", body_summary->get_clear_ct_seq());
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 if (TraceGen1Time) {
342N/A if (_all_full_gc_times_ms->num() > 0) {
342N/A gclog_or_tty->print("\n%4d full_gcs: total time = %8.2f s",
342N/A _all_full_gc_times_ms->num(),
342N/A _all_full_gc_times_ms->sum() / 1000.0);
342N/A gclog_or_tty->print_cr(" (avg = %8.2fms).", _all_full_gc_times_ms->avg());
342N/A gclog_or_tty->print_cr(" [std. dev = %8.2f ms, max = %8.2f ms]",
342N/A _all_full_gc_times_ms->sd(),
342N/A _all_full_gc_times_ms->maximum());
342N/A }
342N/A }
342N/A}
342N/A
342N/Avoid G1CollectorPolicy::print_yg_surv_rate_info() const {
342N/A#ifndef PRODUCT
342N/A _short_lived_surv_rate_group->print_surv_rate_summary();
342N/A // add this call for any other surv rate groups
342N/A#endif // PRODUCT
342N/A}
342N/A
342N/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
2753N/Avoid G1CollectorPolicy::update_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.
2753N/Avoid G1CollectorPolicy::update_survivors_policy() {
2753N/A double max_survivor_regions_d =
2753N/A (double) _young_list_target_length / (double) SurvivorRatio;
2753N/A // We use ceiling so that if max_survivor_regions_d is > 0.0 (but
2753N/A // smaller than 1.0) we'll get 1.
2753N/A _max_survivor_regions = (size_t) ceil(max_survivor_regions_d);
2753N/A
2696N/A _tenuring_threshold = _survivors_age_table.compute_tenuring_threshold(
545N/A HeapRegion::GrainWords * _max_survivor_regions);
545N/A}
545N/A
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
2849N/Abool G1CollectorPolicy::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();
2818N/A // We do not allow non-full young GCs during marking.
2818N/A if (!full_young_gcs()) {
2818N/A set_full_young_gcs(true);
2818N/A ergo_verbose0(ErgoPartiallyYoungGCs,
2818N/A "end partially-young GCs",
2818N/A ergo_format_reason("concurrent cycle is about to start"));
2818N/A }
1359N/A
1359N/A // And we can now clear initiate_conc_mark_if_possible() as
1359N/A // we've already acted on it.
1359N/A clear_initiate_conc_mark_if_possible();
2748N/A
2748N/A ergo_verbose0(ErgoConcCycles,
2748N/A "initiate concurrent cycle",
2748N/A ergo_format_reason("concurrent cycle initiation requested"));
1359N/A } else {
1359N/A // The concurrent marking thread is still finishing up the
1359N/A // previous cycle. If we start one right now the two cycles
1359N/A // overlap. In particular, the concurrent marking thread might
1359N/A // be in the process of clearing the next marking bitmap (which
1359N/A // we will use for the next cycle if we start one). Starting a
1359N/A // cycle now will be bad given that parts of the marking
1359N/A // information might get cleared by the marking thread. And we
1359N/A // cannot wait for the marking thread to finish the cycle as it
1359N/A // periodically yields while clearing the next marking bitmap
1359N/A // and, if it's in a yield point, it's waiting for us to
1359N/A // finish. So, at this point we will not start a cycle and we'll
1359N/A // let the concurrent marking thread complete the last one.
2748N/A ergo_verbose0(ErgoConcCycles,
2748N/A "do not initiate concurrent cycle",
2748N/A ergo_format_reason("concurrent cycle already in progress"));
1359N/A }
1359N/A }
1359N/A}
1359N/A
342N/Aclass KnownGarbageClosure: public HeapRegionClosure {
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,
2941N/A _g1->workers()->active_workers(),
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
2941N/AG1CollectorPolicy::record_concurrent_mark_cleanup_end(int no_of_gc_threads) {
2849N/A double start_sec;
2849N/A if (G1PrintParCleanupStats) {
2849N/A start_sec = os::elapsedTime();
2849N/A }
342N/A
342N/A _collectionSetChooser->clearMarkedHeapRegions();
2849N/A double clear_marked_end_sec;
342N/A if (G1PrintParCleanupStats) {
2849N/A clear_marked_end_sec = os::elapsedTime();
2849N/A gclog_or_tty->print_cr(" clear marked regions: %8.3f ms.",
2849N/A (clear_marked_end_sec - start_sec) * 1000.0);
342N/A }
2849N/A
1753N/A if (G1CollectedHeap::use_parallel_gc_threads()) {
342N/A const size_t OverpartitionFactor = 4;
2941N/A size_t WorkUnit;
2941N/A // The use of MinChunkSize = 8 in the original code
2941N/A // causes some assertion failures when the total number of
2941N/A // region is less than 8. The code here tries to fix that.
2941N/A // Should the original code also be fixed?
2941N/A if (no_of_gc_threads > 0) {
2941N/A const size_t MinWorkUnit =
2941N/A MAX2(_g1->n_regions() / no_of_gc_threads, (size_t) 1U);
2941N/A WorkUnit =
2941N/A MAX2(_g1->n_regions() / (no_of_gc_threads * OverpartitionFactor),
2941N/A MinWorkUnit);
2941N/A } else {
2941N/A assert(no_of_gc_threads > 0,
2941N/A "The active gc workers should be greater than 0");
2941N/A // In a product build do something reasonable to avoid a crash.
2941N/A const size_t MinWorkUnit =
2941N/A MAX2(_g1->n_regions() / ParallelGCThreads, (size_t) 1U);
2941N/A WorkUnit =
2941N/A MAX2(_g1->n_regions() / (ParallelGCThreads * OverpartitionFactor),
2941N/A MinWorkUnit);
2941N/A }
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 }
2849N/A double known_garbage_end_sec;
342N/A if (G1PrintParCleanupStats) {
2849N/A known_garbage_end_sec = os::elapsedTime();
342N/A gclog_or_tty->print_cr(" compute known garbage: %8.3f ms.",
2849N/A (known_garbage_end_sec - clear_marked_end_sec) * 1000.0);
342N/A }
2849N/A
342N/A _collectionSetChooser->sortMarkedHeapRegions();
2849N/A double end_sec = os::elapsedTime();
342N/A if (G1PrintParCleanupStats) {
342N/A gclog_or_tty->print_cr(" sorting: %8.3f ms.",
2849N/A (end_sec - known_garbage_end_sec) * 1000.0);
342N/A }
342N/A
2849N/A double elapsed_time_ms = (end_sec - _mark_cleanup_start_sec) * 1000.0;
2849N/A _concurrent_mark_cleanup_times_ms->add(elapsed_time_ms);
2849N/A _cur_mark_stop_world_time_ms += elapsed_time_ms;
2849N/A _prev_collection_pause_end_ms += elapsed_time_ms;
2849N/A _mmu_tracker->add_pause(_mark_cleanup_start_sec, end_sec, true);
342N/A}
342N/A
1394N/A// Add the heap region at the head of the non-incremental collection set
2936N/Avoid G1CollectorPolicy::add_old_region_to_cset(HeapRegion* hr) {
1394N/A assert(_inc_cset_build_state == Active, "Precondition");
1394N/A assert(!hr->is_young(), "non-incremental add of young region");
1394N/A
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_bytes_used_before += hr->used();
526N/A _g1->register_region_with_in_cset_fast_test(hr);
2936N/A size_t rs_length = hr->rem_set()->occupied();
2936N/A _recorded_rs_lengths += rs_length;
2936N/A _old_cset_region_length += 1;
342N/A}
342N/A
1394N/A// Initialize the per-collection-set information
1394N/Avoid G1CollectorPolicy::start_incremental_cset_building() {
1394N/A assert(_inc_cset_build_state == Inactive, "Precondition");
1394N/A
1394N/A _inc_cset_head = NULL;
1394N/A _inc_cset_tail = NULL;
1394N/A _inc_cset_bytes_used_before = 0;
1394N/A
1394N/A _inc_cset_max_finger = 0;
1394N/A _inc_cset_recorded_rs_lengths = 0;
1394N/A _inc_cset_predicted_elapsed_time_ms = 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
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
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) {
2936N/A assert(hr->is_young(), "invariant");
2936N/A assert(hr->young_index_in_cset() > -1, "should have already been set");
1394N/A assert(_inc_cset_build_state == Active, "Precondition");
1394N/A
1394N/A // We need to clear and set the cached recorded/cached collection set
1394N/A // information in the heap region here (before the region gets added
1394N/A // to the collection set). An individual heap region's cached values
1394N/A // are calculated, aggregated with the policy collection set info,
1394N/A // and cached in the heap region here (initially) and (subsequently)
1394N/A // by the Young List sampling code.
1394N/A
1394N/A size_t rs_length = hr->rem_set()->occupied();
1394N/A add_to_incremental_cset_info(hr, rs_length);
1394N/A
1394N/A HeapWord* hr_end = hr->end();
1394N/A _inc_cset_max_finger = MAX2(_inc_cset_max_finger, hr_end);
1394N/A
1394N/A assert(!hr->in_collection_set(), "invariant");
1394N/A hr->set_in_collection_set(true);
1394N/A assert( hr->next_in_collection_set() == NULL, "invariant");
1394N/A
1394N/A _g1->register_region_with_in_cset_fast_test(hr);
1394N/A}
1394N/A
1394N/A// Add the region at the RHS of the incremental cset
1394N/Avoid G1CollectorPolicy::add_region_to_incremental_cset_rhs(HeapRegion* hr) {
1394N/A // We should only ever be appending survivors at the end of a pause
1394N/A assert( hr->is_survivor(), "Logic");
1394N/A
1394N/A // Do the 'common' stuff
1394N/A add_region_to_incremental_cset_common(hr);
1394N/A
1394N/A // Now add the region at the right hand side
1394N/A if (_inc_cset_tail == NULL) {
1394N/A assert(_inc_cset_head == NULL, "invariant");
1394N/A _inc_cset_head = hr;
1394N/A } else {
1394N/A _inc_cset_tail->set_next_in_collection_set(hr);
1394N/A }
1394N/A _inc_cset_tail = hr;
1394N/A}
1394N/A
1394N/A// Add the region to the LHS of the incremental cset
1394N/Avoid G1CollectorPolicy::add_region_to_incremental_cset_lhs(HeapRegion* hr) {
1394N/A // Survivors should be added to the RHS at the end of a pause
1394N/A assert(!hr->is_survivor(), "Logic");
1394N/A
1394N/A // Do the 'common' stuff
1394N/A add_region_to_incremental_cset_common(hr);
1394N/A
1394N/A // Add the region at the left hand side
1394N/A hr->set_next_in_collection_set(_inc_cset_head);
1394N/A if (_inc_cset_head == NULL) {
1394N/A assert(_inc_cset_tail == NULL, "Invariant");
1394N/A _inc_cset_tail = hr;
1394N/A }
1394N/A _inc_cset_head = hr;
1394N/A}
1394N/A
1394N/A#ifndef PRODUCT
1394N/Avoid G1CollectorPolicy::print_collection_set(HeapRegion* list_head, outputStream* st) {
1394N/A assert(list_head == inc_cset_head() || list_head == collection_set(), "must be");
1394N/A
1394N/A st->print_cr("\nCollection_set:");
1394N/A HeapRegion* csr = list_head;
1394N/A while (csr != NULL) {
1394N/A HeapRegion* next = csr->next_in_collection_set();
1394N/A assert(csr->in_collection_set(), "bad CS");
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
2849N/Avoid G1CollectorPolicy::choose_collection_set(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
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;
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 }
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;
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
2936N/A size_t survivor_region_length = young_list->survivor_length();
2936N/A size_t eden_region_length = young_list->length() - survivor_region_length;
2936N/A init_cset_region_lengths(eden_region_length, survivor_region_length);
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 _collection_set = _inc_cset_head;
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"),
2936N/A eden_region_length, survivor_region_length,
2748N/A _inc_cset_predicted_elapsed_time_ms);
2748N/A
2695N/A // The number of recorded young regions is the incremental
2695N/A // collection set's current size
2695N/A set_recorded_rs_lengths(_inc_cset_recorded_rs_lengths);
2695N/A
2695N/A double young_end_time_sec = os::elapsedTime();
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 double prev_predicted_pause_time_ms = predicted_pause_time_ms;
342N/A do {
2936N/A // Note that add_old_region_to_cset() increments the
2936N/A // _old_cset_region_length field and cset_region_length() returns the
2936N/A // sum of _eden_cset_region_length, _survivor_cset_region_length, and
2936N/A // _old_cset_region_length. So, as old regions are added to the
2936N/A // CSet, _old_cset_region_length will be incremented and
2936N/A // cset_region_length(), which is used below, will always reflect
2936N/A // the the total number of regions added up to this point to the CSet.
2936N/A
342N/A hr = _collectionSetChooser->getNextMarkedRegion(time_remaining_ms,
342N/A avg_prediction);
677N/A if (hr != NULL) {
2910N/A _g1->old_set_remove(hr);
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;
2936N/A add_old_region_to_cset(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 {
2936N/A if (cset_region_length() >= _young_list_fixed_length) {
2748N/A ergo_verbose2(ErgoCSetConstruction,
2748N/A "stop adding old regions to CSet",
2760N/A ergo_format_reason("CSet length reached target")
2748N/A ergo_format_region("CSet")
2748N/A ergo_format_region("young target"),
2936N/A cset_region_length(), _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() &&
2936N/A cset_region_length() < _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"),
2936N/A cset_region_length(), _young_list_fixed_length);
342N/A _should_revert_to_full_young_gcs = true;
2748N/A }
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"),
2936N/A old_cset_region_length(),
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
2748N/A ergo_verbose5(ErgoCSetConstruction,
2748N/A "finish choosing CSet",
2748N/A ergo_format_region("eden")
2748N/A ergo_format_region("survivors")
2748N/A ergo_format_region("old")
2748N/A ergo_format_ms("predicted pause time")
2748N/A ergo_format_ms("target pause time"),
2936N/A eden_region_length, survivor_region_length,
2936N/A old_cset_region_length(),
2748N/A predicted_pause_time_ms, target_pause_time_ms);
2748N/A
342N/A double non_young_end_time_sec = os::elapsedTime();
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}