src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef __clang_major__
aoqi@0 26 #define ATTRIBUTE_PRINTF(x,y) // FIXME, formats are a mess.
aoqi@0 27 #endif
aoqi@0 28
aoqi@0 29 #include "precompiled.hpp"
aoqi@0 30 #include "gc_implementation/g1/concurrentG1Refine.hpp"
aoqi@0 31 #include "gc_implementation/g1/concurrentMark.hpp"
aoqi@0 32 #include "gc_implementation/g1/concurrentMarkThread.inline.hpp"
aoqi@0 33 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
aoqi@0 34 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
aoqi@0 35 #include "gc_implementation/g1/g1ErgoVerbose.hpp"
aoqi@0 36 #include "gc_implementation/g1/g1GCPhaseTimes.hpp"
aoqi@0 37 #include "gc_implementation/g1/g1Log.hpp"
aoqi@0 38 #include "gc_implementation/g1/heapRegionRemSet.hpp"
aoqi@0 39 #include "gc_implementation/shared/gcPolicyCounters.hpp"
aoqi@0 40 #include "runtime/arguments.hpp"
aoqi@0 41 #include "runtime/java.hpp"
aoqi@0 42 #include "runtime/mutexLocker.hpp"
aoqi@0 43 #include "utilities/debug.hpp"
aoqi@0 44
aoqi@0 45 // Different defaults for different number of GC threads
aoqi@0 46 // They were chosen by running GCOld and SPECjbb on debris with different
aoqi@0 47 // numbers of GC threads and choosing them based on the results
aoqi@0 48
aoqi@0 49 // all the same
aoqi@0 50 static double rs_length_diff_defaults[] = {
aoqi@0 51 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
aoqi@0 52 };
aoqi@0 53
aoqi@0 54 static double cost_per_card_ms_defaults[] = {
aoqi@0 55 0.01, 0.005, 0.005, 0.003, 0.003, 0.002, 0.002, 0.0015
aoqi@0 56 };
aoqi@0 57
aoqi@0 58 // all the same
aoqi@0 59 static double young_cards_per_entry_ratio_defaults[] = {
aoqi@0 60 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
aoqi@0 61 };
aoqi@0 62
aoqi@0 63 static double cost_per_entry_ms_defaults[] = {
aoqi@0 64 0.015, 0.01, 0.01, 0.008, 0.008, 0.0055, 0.0055, 0.005
aoqi@0 65 };
aoqi@0 66
aoqi@0 67 static double cost_per_byte_ms_defaults[] = {
aoqi@0 68 0.00006, 0.00003, 0.00003, 0.000015, 0.000015, 0.00001, 0.00001, 0.000009
aoqi@0 69 };
aoqi@0 70
aoqi@0 71 // these should be pretty consistent
aoqi@0 72 static double constant_other_time_ms_defaults[] = {
aoqi@0 73 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0
aoqi@0 74 };
aoqi@0 75
aoqi@0 76
aoqi@0 77 static double young_other_cost_per_region_ms_defaults[] = {
aoqi@0 78 0.3, 0.2, 0.2, 0.15, 0.15, 0.12, 0.12, 0.1
aoqi@0 79 };
aoqi@0 80
aoqi@0 81 static double non_young_other_cost_per_region_ms_defaults[] = {
aoqi@0 82 1.0, 0.7, 0.7, 0.5, 0.5, 0.42, 0.42, 0.30
aoqi@0 83 };
aoqi@0 84
aoqi@0 85 G1CollectorPolicy::G1CollectorPolicy() :
aoqi@0 86 _parallel_gc_threads(G1CollectedHeap::use_parallel_gc_threads()
aoqi@0 87 ? ParallelGCThreads : 1),
aoqi@0 88
aoqi@0 89 _recent_gc_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
aoqi@0 90 _stop_world_start(0.0),
aoqi@0 91
aoqi@0 92 _concurrent_mark_remark_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
aoqi@0 93 _concurrent_mark_cleanup_times_ms(new TruncatedSeq(NumPrevPausesForHeuristics)),
aoqi@0 94
aoqi@0 95 _alloc_rate_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 96 _prev_collection_pause_end_ms(0.0),
aoqi@0 97 _rs_length_diff_seq(new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 98 _cost_per_card_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 99 _young_cards_per_entry_ratio_seq(new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 100 _mixed_cards_per_entry_ratio_seq(new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 101 _cost_per_entry_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 102 _mixed_cost_per_entry_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 103 _cost_per_byte_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 104 _cost_per_byte_ms_during_cm_seq(new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 105 _constant_other_time_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 106 _young_other_cost_per_region_ms_seq(new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 107 _non_young_other_cost_per_region_ms_seq(
aoqi@0 108 new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 109
aoqi@0 110 _pending_cards_seq(new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 111 _rs_lengths_seq(new TruncatedSeq(TruncatedSeqLength)),
aoqi@0 112
aoqi@0 113 _pause_time_target_ms((double) MaxGCPauseMillis),
aoqi@0 114
aoqi@0 115 _gcs_are_young(true),
aoqi@0 116
aoqi@0 117 _during_marking(false),
aoqi@0 118 _in_marking_window(false),
aoqi@0 119 _in_marking_window_im(false),
aoqi@0 120
aoqi@0 121 _recent_prev_end_times_for_all_gcs_sec(
aoqi@0 122 new TruncatedSeq(NumPrevPausesForHeuristics)),
aoqi@0 123
aoqi@0 124 _recent_avg_pause_time_ratio(0.0),
aoqi@0 125
aoqi@0 126 _initiate_conc_mark_if_possible(false),
aoqi@0 127 _during_initial_mark_pause(false),
aoqi@0 128 _last_young_gc(false),
aoqi@0 129 _last_gc_was_young(false),
aoqi@0 130
aoqi@0 131 _eden_used_bytes_before_gc(0),
aoqi@0 132 _survivor_used_bytes_before_gc(0),
aoqi@0 133 _heap_used_bytes_before_gc(0),
aoqi@0 134 _metaspace_used_bytes_before_gc(0),
aoqi@0 135 _eden_capacity_bytes_before_gc(0),
aoqi@0 136 _heap_capacity_bytes_before_gc(0),
aoqi@0 137
aoqi@0 138 _eden_cset_region_length(0),
aoqi@0 139 _survivor_cset_region_length(0),
aoqi@0 140 _old_cset_region_length(0),
aoqi@0 141
aoqi@0 142 _collection_set(NULL),
aoqi@0 143 _collection_set_bytes_used_before(0),
aoqi@0 144
aoqi@0 145 // Incremental CSet attributes
aoqi@0 146 _inc_cset_build_state(Inactive),
aoqi@0 147 _inc_cset_head(NULL),
aoqi@0 148 _inc_cset_tail(NULL),
aoqi@0 149 _inc_cset_bytes_used_before(0),
aoqi@0 150 _inc_cset_max_finger(NULL),
aoqi@0 151 _inc_cset_recorded_rs_lengths(0),
aoqi@0 152 _inc_cset_recorded_rs_lengths_diffs(0),
aoqi@0 153 _inc_cset_predicted_elapsed_time_ms(0.0),
aoqi@0 154 _inc_cset_predicted_elapsed_time_ms_diffs(0.0),
aoqi@0 155
aoqi@0 156 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away
aoqi@0 157 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list
aoqi@0 158 #endif // _MSC_VER
aoqi@0 159
aoqi@0 160 _short_lived_surv_rate_group(new SurvRateGroup(this, "Short Lived",
aoqi@0 161 G1YoungSurvRateNumRegionsSummary)),
aoqi@0 162 _survivor_surv_rate_group(new SurvRateGroup(this, "Survivor",
aoqi@0 163 G1YoungSurvRateNumRegionsSummary)),
aoqi@0 164 // add here any more surv rate groups
aoqi@0 165 _recorded_survivor_regions(0),
aoqi@0 166 _recorded_survivor_head(NULL),
aoqi@0 167 _recorded_survivor_tail(NULL),
aoqi@0 168 _survivors_age_table(true),
aoqi@0 169
aoqi@0 170 _gc_overhead_perc(0.0) {
aoqi@0 171
aoqi@0 172 // Set up the region size and associated fields. Given that the
aoqi@0 173 // policy is created before the heap, we have to set this up here,
aoqi@0 174 // so it's done as soon as possible.
aoqi@0 175
aoqi@0 176 // It would have been natural to pass initial_heap_byte_size() and
aoqi@0 177 // max_heap_byte_size() to setup_heap_region_size() but those have
aoqi@0 178 // not been set up at this point since they should be aligned with
aoqi@0 179 // the region size. So, there is a circular dependency here. We base
aoqi@0 180 // the region size on the heap size, but the heap size should be
aoqi@0 181 // aligned with the region size. To get around this we use the
aoqi@0 182 // unaligned values for the heap.
aoqi@0 183 HeapRegion::setup_heap_region_size(InitialHeapSize, MaxHeapSize);
aoqi@0 184 HeapRegionRemSet::setup_remset_size();
aoqi@0 185
aoqi@0 186 G1ErgoVerbose::initialize();
aoqi@0 187 if (PrintAdaptiveSizePolicy) {
aoqi@0 188 // Currently, we only use a single switch for all the heuristics.
aoqi@0 189 G1ErgoVerbose::set_enabled(true);
aoqi@0 190 // Given that we don't currently have a verboseness level
aoqi@0 191 // parameter, we'll hardcode this to high. This can be easily
aoqi@0 192 // changed in the future.
aoqi@0 193 G1ErgoVerbose::set_level(ErgoHigh);
aoqi@0 194 } else {
aoqi@0 195 G1ErgoVerbose::set_enabled(false);
aoqi@0 196 }
aoqi@0 197
aoqi@0 198 // Verify PLAB sizes
aoqi@0 199 const size_t region_size = HeapRegion::GrainWords;
aoqi@0 200 if (YoungPLABSize > region_size || OldPLABSize > region_size) {
aoqi@0 201 char buffer[128];
aoqi@0 202 jio_snprintf(buffer, sizeof(buffer), "%sPLABSize should be at most "SIZE_FORMAT,
aoqi@0 203 OldPLABSize > region_size ? "Old" : "Young", region_size);
aoqi@0 204 vm_exit_during_initialization(buffer);
aoqi@0 205 }
aoqi@0 206
aoqi@0 207 _recent_prev_end_times_for_all_gcs_sec->add(os::elapsedTime());
aoqi@0 208 _prev_collection_pause_end_ms = os::elapsedTime() * 1000.0;
aoqi@0 209
aoqi@0 210 _phase_times = new G1GCPhaseTimes(_parallel_gc_threads);
aoqi@0 211
aoqi@0 212 int index = MIN2(_parallel_gc_threads - 1, 7);
aoqi@0 213
aoqi@0 214 _rs_length_diff_seq->add(rs_length_diff_defaults[index]);
aoqi@0 215 _cost_per_card_ms_seq->add(cost_per_card_ms_defaults[index]);
aoqi@0 216 _young_cards_per_entry_ratio_seq->add(
aoqi@0 217 young_cards_per_entry_ratio_defaults[index]);
aoqi@0 218 _cost_per_entry_ms_seq->add(cost_per_entry_ms_defaults[index]);
aoqi@0 219 _cost_per_byte_ms_seq->add(cost_per_byte_ms_defaults[index]);
aoqi@0 220 _constant_other_time_ms_seq->add(constant_other_time_ms_defaults[index]);
aoqi@0 221 _young_other_cost_per_region_ms_seq->add(
aoqi@0 222 young_other_cost_per_region_ms_defaults[index]);
aoqi@0 223 _non_young_other_cost_per_region_ms_seq->add(
aoqi@0 224 non_young_other_cost_per_region_ms_defaults[index]);
aoqi@0 225
aoqi@0 226 // Below, we might need to calculate the pause time target based on
aoqi@0 227 // the pause interval. When we do so we are going to give G1 maximum
aoqi@0 228 // flexibility and allow it to do pauses when it needs to. So, we'll
aoqi@0 229 // arrange that the pause interval to be pause time target + 1 to
aoqi@0 230 // ensure that a) the pause time target is maximized with respect to
aoqi@0 231 // the pause interval and b) we maintain the invariant that pause
aoqi@0 232 // time target < pause interval. If the user does not want this
aoqi@0 233 // maximum flexibility, they will have to set the pause interval
aoqi@0 234 // explicitly.
aoqi@0 235
aoqi@0 236 // First make sure that, if either parameter is set, its value is
aoqi@0 237 // reasonable.
aoqi@0 238 if (!FLAG_IS_DEFAULT(MaxGCPauseMillis)) {
aoqi@0 239 if (MaxGCPauseMillis < 1) {
aoqi@0 240 vm_exit_during_initialization("MaxGCPauseMillis should be "
aoqi@0 241 "greater than 0");
aoqi@0 242 }
aoqi@0 243 }
aoqi@0 244 if (!FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
aoqi@0 245 if (GCPauseIntervalMillis < 1) {
aoqi@0 246 vm_exit_during_initialization("GCPauseIntervalMillis should be "
aoqi@0 247 "greater than 0");
aoqi@0 248 }
aoqi@0 249 }
aoqi@0 250
aoqi@0 251 // Then, if the pause time target parameter was not set, set it to
aoqi@0 252 // the default value.
aoqi@0 253 if (FLAG_IS_DEFAULT(MaxGCPauseMillis)) {
aoqi@0 254 if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
aoqi@0 255 // The default pause time target in G1 is 200ms
aoqi@0 256 FLAG_SET_DEFAULT(MaxGCPauseMillis, 200);
aoqi@0 257 } else {
aoqi@0 258 // We do not allow the pause interval to be set without the
aoqi@0 259 // pause time target
aoqi@0 260 vm_exit_during_initialization("GCPauseIntervalMillis cannot be set "
aoqi@0 261 "without setting MaxGCPauseMillis");
aoqi@0 262 }
aoqi@0 263 }
aoqi@0 264
aoqi@0 265 // Then, if the interval parameter was not set, set it according to
aoqi@0 266 // the pause time target (this will also deal with the case when the
aoqi@0 267 // pause time target is the default value).
aoqi@0 268 if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
aoqi@0 269 FLAG_SET_DEFAULT(GCPauseIntervalMillis, MaxGCPauseMillis + 1);
aoqi@0 270 }
aoqi@0 271
aoqi@0 272 // Finally, make sure that the two parameters are consistent.
aoqi@0 273 if (MaxGCPauseMillis >= GCPauseIntervalMillis) {
aoqi@0 274 char buffer[256];
aoqi@0 275 jio_snprintf(buffer, 256,
aoqi@0 276 "MaxGCPauseMillis (%u) should be less than "
aoqi@0 277 "GCPauseIntervalMillis (%u)",
aoqi@0 278 MaxGCPauseMillis, GCPauseIntervalMillis);
aoqi@0 279 vm_exit_during_initialization(buffer);
aoqi@0 280 }
aoqi@0 281
aoqi@0 282 double max_gc_time = (double) MaxGCPauseMillis / 1000.0;
aoqi@0 283 double time_slice = (double) GCPauseIntervalMillis / 1000.0;
aoqi@0 284 _mmu_tracker = new G1MMUTrackerQueue(time_slice, max_gc_time);
aoqi@0 285
aoqi@0 286 uintx confidence_perc = G1ConfidencePercent;
aoqi@0 287 // Put an artificial ceiling on this so that it's not set to a silly value.
aoqi@0 288 if (confidence_perc > 100) {
aoqi@0 289 confidence_perc = 100;
aoqi@0 290 warning("G1ConfidencePercent is set to a value that is too large, "
aoqi@0 291 "it's been updated to %u", confidence_perc);
aoqi@0 292 }
aoqi@0 293 _sigma = (double) confidence_perc / 100.0;
aoqi@0 294
aoqi@0 295 // start conservatively (around 50ms is about right)
aoqi@0 296 _concurrent_mark_remark_times_ms->add(0.05);
aoqi@0 297 _concurrent_mark_cleanup_times_ms->add(0.20);
aoqi@0 298 _tenuring_threshold = MaxTenuringThreshold;
aoqi@0 299 // _max_survivor_regions will be calculated by
aoqi@0 300 // update_young_list_target_length() during initialization.
aoqi@0 301 _max_survivor_regions = 0;
aoqi@0 302
aoqi@0 303 assert(GCTimeRatio > 0,
aoqi@0 304 "we should have set it to a default value set_g1_gc_flags() "
aoqi@0 305 "if a user set it to 0");
aoqi@0 306 _gc_overhead_perc = 100.0 * (1.0 / (1.0 + GCTimeRatio));
aoqi@0 307
aoqi@0 308 uintx reserve_perc = G1ReservePercent;
aoqi@0 309 // Put an artificial ceiling on this so that it's not set to a silly value.
aoqi@0 310 if (reserve_perc > 50) {
aoqi@0 311 reserve_perc = 50;
aoqi@0 312 warning("G1ReservePercent is set to a value that is too large, "
aoqi@0 313 "it's been updated to %u", reserve_perc);
aoqi@0 314 }
aoqi@0 315 _reserve_factor = (double) reserve_perc / 100.0;
aoqi@0 316 // This will be set when the heap is expanded
aoqi@0 317 // for the first time during initialization.
aoqi@0 318 _reserve_regions = 0;
aoqi@0 319
aoqi@0 320 _collectionSetChooser = new CollectionSetChooser();
aoqi@0 321 }
aoqi@0 322
aoqi@0 323 void G1CollectorPolicy::initialize_alignments() {
aoqi@0 324 _space_alignment = HeapRegion::GrainBytes;
aoqi@0 325 size_t card_table_alignment = GenRemSet::max_alignment_constraint(GenRemSet::CardTable);
aoqi@0 326 size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
aoqi@0 327 _heap_alignment = MAX3(card_table_alignment, _space_alignment, page_size);
aoqi@0 328 }
aoqi@0 329
aoqi@0 330 void G1CollectorPolicy::initialize_flags() {
aoqi@0 331 if (G1HeapRegionSize != HeapRegion::GrainBytes) {
aoqi@0 332 FLAG_SET_ERGO(uintx, G1HeapRegionSize, HeapRegion::GrainBytes);
aoqi@0 333 }
aoqi@0 334
aoqi@0 335 if (SurvivorRatio < 1) {
aoqi@0 336 vm_exit_during_initialization("Invalid survivor ratio specified");
aoqi@0 337 }
aoqi@0 338 CollectorPolicy::initialize_flags();
aoqi@0 339 _young_gen_sizer = new G1YoungGenSizer(); // Must be after call to initialize_flags
aoqi@0 340 }
aoqi@0 341
aoqi@0 342 void G1CollectorPolicy::post_heap_initialize() {
aoqi@0 343 uintx max_regions = G1CollectedHeap::heap()->max_regions();
aoqi@0 344 size_t max_young_size = (size_t)_young_gen_sizer->max_young_length(max_regions) * HeapRegion::GrainBytes;
aoqi@0 345 if (max_young_size != MaxNewSize) {
aoqi@0 346 FLAG_SET_ERGO(uintx, MaxNewSize, max_young_size);
aoqi@0 347 }
aoqi@0 348 }
aoqi@0 349
aoqi@0 350 G1YoungGenSizer::G1YoungGenSizer() : _sizer_kind(SizerDefaults), _adaptive_size(true),
aoqi@0 351 _min_desired_young_length(0), _max_desired_young_length(0) {
aoqi@0 352 if (FLAG_IS_CMDLINE(NewRatio)) {
aoqi@0 353 if (FLAG_IS_CMDLINE(NewSize) || FLAG_IS_CMDLINE(MaxNewSize)) {
aoqi@0 354 warning("-XX:NewSize and -XX:MaxNewSize override -XX:NewRatio");
aoqi@0 355 } else {
aoqi@0 356 _sizer_kind = SizerNewRatio;
aoqi@0 357 _adaptive_size = false;
aoqi@0 358 return;
aoqi@0 359 }
aoqi@0 360 }
aoqi@0 361
aoqi@0 362 if (NewSize > MaxNewSize) {
aoqi@0 363 if (FLAG_IS_CMDLINE(MaxNewSize)) {
aoqi@0 364 warning("NewSize (" SIZE_FORMAT "k) is greater than the MaxNewSize (" SIZE_FORMAT "k). "
aoqi@0 365 "A new max generation size of " SIZE_FORMAT "k will be used.",
aoqi@0 366 NewSize/K, MaxNewSize/K, NewSize/K);
aoqi@0 367 }
aoqi@0 368 MaxNewSize = NewSize;
aoqi@0 369 }
aoqi@0 370
aoqi@0 371 if (FLAG_IS_CMDLINE(NewSize)) {
aoqi@0 372 _min_desired_young_length = MAX2((uint) (NewSize / HeapRegion::GrainBytes),
aoqi@0 373 1U);
aoqi@0 374 if (FLAG_IS_CMDLINE(MaxNewSize)) {
aoqi@0 375 _max_desired_young_length =
aoqi@0 376 MAX2((uint) (MaxNewSize / HeapRegion::GrainBytes),
aoqi@0 377 1U);
aoqi@0 378 _sizer_kind = SizerMaxAndNewSize;
aoqi@0 379 _adaptive_size = _min_desired_young_length == _max_desired_young_length;
aoqi@0 380 } else {
aoqi@0 381 _sizer_kind = SizerNewSizeOnly;
aoqi@0 382 }
aoqi@0 383 } else if (FLAG_IS_CMDLINE(MaxNewSize)) {
aoqi@0 384 _max_desired_young_length =
aoqi@0 385 MAX2((uint) (MaxNewSize / HeapRegion::GrainBytes),
aoqi@0 386 1U);
aoqi@0 387 _sizer_kind = SizerMaxNewSizeOnly;
aoqi@0 388 }
aoqi@0 389 }
aoqi@0 390
aoqi@0 391 uint G1YoungGenSizer::calculate_default_min_length(uint new_number_of_heap_regions) {
aoqi@0 392 uint default_value = (new_number_of_heap_regions * G1NewSizePercent) / 100;
aoqi@0 393 return MAX2(1U, default_value);
aoqi@0 394 }
aoqi@0 395
aoqi@0 396 uint G1YoungGenSizer::calculate_default_max_length(uint new_number_of_heap_regions) {
aoqi@0 397 uint default_value = (new_number_of_heap_regions * G1MaxNewSizePercent) / 100;
aoqi@0 398 return MAX2(1U, default_value);
aoqi@0 399 }
aoqi@0 400
aoqi@0 401 void G1YoungGenSizer::recalculate_min_max_young_length(uint number_of_heap_regions, uint* min_young_length, uint* max_young_length) {
aoqi@0 402 assert(number_of_heap_regions > 0, "Heap must be initialized");
aoqi@0 403
aoqi@0 404 switch (_sizer_kind) {
aoqi@0 405 case SizerDefaults:
aoqi@0 406 *min_young_length = calculate_default_min_length(number_of_heap_regions);
aoqi@0 407 *max_young_length = calculate_default_max_length(number_of_heap_regions);
aoqi@0 408 break;
aoqi@0 409 case SizerNewSizeOnly:
aoqi@0 410 *max_young_length = calculate_default_max_length(number_of_heap_regions);
aoqi@0 411 *max_young_length = MAX2(*min_young_length, *max_young_length);
aoqi@0 412 break;
aoqi@0 413 case SizerMaxNewSizeOnly:
aoqi@0 414 *min_young_length = calculate_default_min_length(number_of_heap_regions);
aoqi@0 415 *min_young_length = MIN2(*min_young_length, *max_young_length);
aoqi@0 416 break;
aoqi@0 417 case SizerMaxAndNewSize:
aoqi@0 418 // Do nothing. Values set on the command line, don't update them at runtime.
aoqi@0 419 break;
aoqi@0 420 case SizerNewRatio:
aoqi@0 421 *min_young_length = number_of_heap_regions / (NewRatio + 1);
aoqi@0 422 *max_young_length = *min_young_length;
aoqi@0 423 break;
aoqi@0 424 default:
aoqi@0 425 ShouldNotReachHere();
aoqi@0 426 }
aoqi@0 427
aoqi@0 428 assert(*min_young_length <= *max_young_length, "Invalid min/max young gen size values");
aoqi@0 429 }
aoqi@0 430
aoqi@0 431 uint G1YoungGenSizer::max_young_length(uint number_of_heap_regions) {
aoqi@0 432 // We need to pass the desired values because recalculation may not update these
aoqi@0 433 // values in some cases.
aoqi@0 434 uint temp = _min_desired_young_length;
aoqi@0 435 uint result = _max_desired_young_length;
aoqi@0 436 recalculate_min_max_young_length(number_of_heap_regions, &temp, &result);
aoqi@0 437 return result;
aoqi@0 438 }
aoqi@0 439
aoqi@0 440 void G1YoungGenSizer::heap_size_changed(uint new_number_of_heap_regions) {
aoqi@0 441 recalculate_min_max_young_length(new_number_of_heap_regions, &_min_desired_young_length,
aoqi@0 442 &_max_desired_young_length);
aoqi@0 443 }
aoqi@0 444
aoqi@0 445 void G1CollectorPolicy::init() {
aoqi@0 446 // Set aside an initial future to_space.
aoqi@0 447 _g1 = G1CollectedHeap::heap();
aoqi@0 448
aoqi@0 449 assert(Heap_lock->owned_by_self(), "Locking discipline.");
aoqi@0 450
aoqi@0 451 initialize_gc_policy_counters();
aoqi@0 452
aoqi@0 453 if (adaptive_young_list_length()) {
aoqi@0 454 _young_list_fixed_length = 0;
aoqi@0 455 } else {
aoqi@0 456 _young_list_fixed_length = _young_gen_sizer->min_desired_young_length();
aoqi@0 457 }
aoqi@0 458 _free_regions_at_end_of_collection = _g1->free_regions();
aoqi@0 459 update_young_list_target_length();
aoqi@0 460
aoqi@0 461 // We may immediately start allocating regions and placing them on the
aoqi@0 462 // collection set list. Initialize the per-collection set info
aoqi@0 463 start_incremental_cset_building();
aoqi@0 464 }
aoqi@0 465
aoqi@0 466 // Create the jstat counters for the policy.
aoqi@0 467 void G1CollectorPolicy::initialize_gc_policy_counters() {
aoqi@0 468 _gc_policy_counters = new GCPolicyCounters("GarbageFirst", 1, 3);
aoqi@0 469 }
aoqi@0 470
aoqi@0 471 bool G1CollectorPolicy::predict_will_fit(uint young_length,
aoqi@0 472 double base_time_ms,
aoqi@0 473 uint base_free_regions,
aoqi@0 474 double target_pause_time_ms) {
aoqi@0 475 if (young_length >= base_free_regions) {
aoqi@0 476 // end condition 1: not enough space for the young regions
aoqi@0 477 return false;
aoqi@0 478 }
aoqi@0 479
aoqi@0 480 double accum_surv_rate = accum_yg_surv_rate_pred((int) young_length - 1);
aoqi@0 481 size_t bytes_to_copy =
aoqi@0 482 (size_t) (accum_surv_rate * (double) HeapRegion::GrainBytes);
aoqi@0 483 double copy_time_ms = predict_object_copy_time_ms(bytes_to_copy);
aoqi@0 484 double young_other_time_ms = predict_young_other_time_ms(young_length);
aoqi@0 485 double pause_time_ms = base_time_ms + copy_time_ms + young_other_time_ms;
aoqi@0 486 if (pause_time_ms > target_pause_time_ms) {
aoqi@0 487 // end condition 2: prediction is over the target pause time
aoqi@0 488 return false;
aoqi@0 489 }
aoqi@0 490
aoqi@0 491 size_t free_bytes =
aoqi@0 492 (base_free_regions - young_length) * HeapRegion::GrainBytes;
aoqi@0 493 if ((2.0 * sigma()) * (double) bytes_to_copy > (double) free_bytes) {
aoqi@0 494 // end condition 3: out-of-space (conservatively!)
aoqi@0 495 return false;
aoqi@0 496 }
aoqi@0 497
aoqi@0 498 // success!
aoqi@0 499 return true;
aoqi@0 500 }
aoqi@0 501
aoqi@0 502 void G1CollectorPolicy::record_new_heap_size(uint new_number_of_regions) {
aoqi@0 503 // re-calculate the necessary reserve
aoqi@0 504 double reserve_regions_d = (double) new_number_of_regions * _reserve_factor;
aoqi@0 505 // We use ceiling so that if reserve_regions_d is > 0.0 (but
aoqi@0 506 // smaller than 1.0) we'll get 1.
aoqi@0 507 _reserve_regions = (uint) ceil(reserve_regions_d);
aoqi@0 508
aoqi@0 509 _young_gen_sizer->heap_size_changed(new_number_of_regions);
aoqi@0 510 }
aoqi@0 511
aoqi@0 512 uint G1CollectorPolicy::calculate_young_list_desired_min_length(
aoqi@0 513 uint base_min_length) {
aoqi@0 514 uint desired_min_length = 0;
aoqi@0 515 if (adaptive_young_list_length()) {
aoqi@0 516 if (_alloc_rate_ms_seq->num() > 3) {
aoqi@0 517 double now_sec = os::elapsedTime();
aoqi@0 518 double when_ms = _mmu_tracker->when_max_gc_sec(now_sec) * 1000.0;
aoqi@0 519 double alloc_rate_ms = predict_alloc_rate_ms();
aoqi@0 520 desired_min_length = (uint) ceil(alloc_rate_ms * when_ms);
aoqi@0 521 } else {
aoqi@0 522 // otherwise we don't have enough info to make the prediction
aoqi@0 523 }
aoqi@0 524 }
aoqi@0 525 desired_min_length += base_min_length;
aoqi@0 526 // make sure we don't go below any user-defined minimum bound
aoqi@0 527 return MAX2(_young_gen_sizer->min_desired_young_length(), desired_min_length);
aoqi@0 528 }
aoqi@0 529
aoqi@0 530 uint G1CollectorPolicy::calculate_young_list_desired_max_length() {
aoqi@0 531 // Here, we might want to also take into account any additional
aoqi@0 532 // constraints (i.e., user-defined minimum bound). Currently, we
aoqi@0 533 // effectively don't set this bound.
aoqi@0 534 return _young_gen_sizer->max_desired_young_length();
aoqi@0 535 }
aoqi@0 536
aoqi@0 537 void G1CollectorPolicy::update_young_list_target_length(size_t rs_lengths) {
aoqi@0 538 if (rs_lengths == (size_t) -1) {
aoqi@0 539 // if it's set to the default value (-1), we should predict it;
aoqi@0 540 // otherwise, use the given value.
aoqi@0 541 rs_lengths = (size_t) get_new_prediction(_rs_lengths_seq);
aoqi@0 542 }
aoqi@0 543
aoqi@0 544 // Calculate the absolute and desired min bounds.
aoqi@0 545
aoqi@0 546 // This is how many young regions we already have (currently: the survivors).
aoqi@0 547 uint base_min_length = recorded_survivor_regions();
aoqi@0 548 // This is the absolute minimum young length, which ensures that we
aoqi@0 549 // can allocate one eden region in the worst-case.
aoqi@0 550 uint absolute_min_length = base_min_length + 1;
aoqi@0 551 uint desired_min_length =
aoqi@0 552 calculate_young_list_desired_min_length(base_min_length);
aoqi@0 553 if (desired_min_length < absolute_min_length) {
aoqi@0 554 desired_min_length = absolute_min_length;
aoqi@0 555 }
aoqi@0 556
aoqi@0 557 // Calculate the absolute and desired max bounds.
aoqi@0 558
aoqi@0 559 // We will try our best not to "eat" into the reserve.
aoqi@0 560 uint absolute_max_length = 0;
aoqi@0 561 if (_free_regions_at_end_of_collection > _reserve_regions) {
aoqi@0 562 absolute_max_length = _free_regions_at_end_of_collection - _reserve_regions;
aoqi@0 563 }
aoqi@0 564 uint desired_max_length = calculate_young_list_desired_max_length();
aoqi@0 565 if (desired_max_length > absolute_max_length) {
aoqi@0 566 desired_max_length = absolute_max_length;
aoqi@0 567 }
aoqi@0 568
aoqi@0 569 uint young_list_target_length = 0;
aoqi@0 570 if (adaptive_young_list_length()) {
aoqi@0 571 if (gcs_are_young()) {
aoqi@0 572 young_list_target_length =
aoqi@0 573 calculate_young_list_target_length(rs_lengths,
aoqi@0 574 base_min_length,
aoqi@0 575 desired_min_length,
aoqi@0 576 desired_max_length);
aoqi@0 577 _rs_lengths_prediction = rs_lengths;
aoqi@0 578 } else {
aoqi@0 579 // Don't calculate anything and let the code below bound it to
aoqi@0 580 // the desired_min_length, i.e., do the next GC as soon as
aoqi@0 581 // possible to maximize how many old regions we can add to it.
aoqi@0 582 }
aoqi@0 583 } else {
aoqi@0 584 // The user asked for a fixed young gen so we'll fix the young gen
aoqi@0 585 // whether the next GC is young or mixed.
aoqi@0 586 young_list_target_length = _young_list_fixed_length;
aoqi@0 587 }
aoqi@0 588
aoqi@0 589 // Make sure we don't go over the desired max length, nor under the
aoqi@0 590 // desired min length. In case they clash, desired_min_length wins
aoqi@0 591 // which is why that test is second.
aoqi@0 592 if (young_list_target_length > desired_max_length) {
aoqi@0 593 young_list_target_length = desired_max_length;
aoqi@0 594 }
aoqi@0 595 if (young_list_target_length < desired_min_length) {
aoqi@0 596 young_list_target_length = desired_min_length;
aoqi@0 597 }
aoqi@0 598
aoqi@0 599 assert(young_list_target_length > recorded_survivor_regions(),
aoqi@0 600 "we should be able to allocate at least one eden region");
aoqi@0 601 assert(young_list_target_length >= absolute_min_length, "post-condition");
aoqi@0 602 _young_list_target_length = young_list_target_length;
aoqi@0 603
aoqi@0 604 update_max_gc_locker_expansion();
aoqi@0 605 }
aoqi@0 606
aoqi@0 607 uint
aoqi@0 608 G1CollectorPolicy::calculate_young_list_target_length(size_t rs_lengths,
aoqi@0 609 uint base_min_length,
aoqi@0 610 uint desired_min_length,
aoqi@0 611 uint desired_max_length) {
aoqi@0 612 assert(adaptive_young_list_length(), "pre-condition");
aoqi@0 613 assert(gcs_are_young(), "only call this for young GCs");
aoqi@0 614
aoqi@0 615 // In case some edge-condition makes the desired max length too small...
aoqi@0 616 if (desired_max_length <= desired_min_length) {
aoqi@0 617 return desired_min_length;
aoqi@0 618 }
aoqi@0 619
aoqi@0 620 // We'll adjust min_young_length and max_young_length not to include
aoqi@0 621 // the already allocated young regions (i.e., so they reflect the
aoqi@0 622 // min and max eden regions we'll allocate). The base_min_length
aoqi@0 623 // will be reflected in the predictions by the
aoqi@0 624 // survivor_regions_evac_time prediction.
aoqi@0 625 assert(desired_min_length > base_min_length, "invariant");
aoqi@0 626 uint min_young_length = desired_min_length - base_min_length;
aoqi@0 627 assert(desired_max_length > base_min_length, "invariant");
aoqi@0 628 uint max_young_length = desired_max_length - base_min_length;
aoqi@0 629
aoqi@0 630 double target_pause_time_ms = _mmu_tracker->max_gc_time() * 1000.0;
aoqi@0 631 double survivor_regions_evac_time = predict_survivor_regions_evac_time();
aoqi@0 632 size_t pending_cards = (size_t) get_new_prediction(_pending_cards_seq);
aoqi@0 633 size_t adj_rs_lengths = rs_lengths + predict_rs_length_diff();
aoqi@0 634 size_t scanned_cards = predict_young_card_num(adj_rs_lengths);
aoqi@0 635 double base_time_ms =
aoqi@0 636 predict_base_elapsed_time_ms(pending_cards, scanned_cards) +
aoqi@0 637 survivor_regions_evac_time;
aoqi@0 638 uint available_free_regions = _free_regions_at_end_of_collection;
aoqi@0 639 uint base_free_regions = 0;
aoqi@0 640 if (available_free_regions > _reserve_regions) {
aoqi@0 641 base_free_regions = available_free_regions - _reserve_regions;
aoqi@0 642 }
aoqi@0 643
aoqi@0 644 // Here, we will make sure that the shortest young length that
aoqi@0 645 // makes sense fits within the target pause time.
aoqi@0 646
aoqi@0 647 if (predict_will_fit(min_young_length, base_time_ms,
aoqi@0 648 base_free_regions, target_pause_time_ms)) {
aoqi@0 649 // The shortest young length will fit into the target pause time;
aoqi@0 650 // we'll now check whether the absolute maximum number of young
aoqi@0 651 // regions will fit in the target pause time. If not, we'll do
aoqi@0 652 // a binary search between min_young_length and max_young_length.
aoqi@0 653 if (predict_will_fit(max_young_length, base_time_ms,
aoqi@0 654 base_free_regions, target_pause_time_ms)) {
aoqi@0 655 // The maximum young length will fit into the target pause time.
aoqi@0 656 // We are done so set min young length to the maximum length (as
aoqi@0 657 // the result is assumed to be returned in min_young_length).
aoqi@0 658 min_young_length = max_young_length;
aoqi@0 659 } else {
aoqi@0 660 // The maximum possible number of young regions will not fit within
aoqi@0 661 // the target pause time so we'll search for the optimal
aoqi@0 662 // length. The loop invariants are:
aoqi@0 663 //
aoqi@0 664 // min_young_length < max_young_length
aoqi@0 665 // min_young_length is known to fit into the target pause time
aoqi@0 666 // max_young_length is known not to fit into the target pause time
aoqi@0 667 //
aoqi@0 668 // Going into the loop we know the above hold as we've just
aoqi@0 669 // checked them. Every time around the loop we check whether
aoqi@0 670 // the middle value between min_young_length and
aoqi@0 671 // max_young_length fits into the target pause time. If it
aoqi@0 672 // does, it becomes the new min. If it doesn't, it becomes
aoqi@0 673 // the new max. This way we maintain the loop invariants.
aoqi@0 674
aoqi@0 675 assert(min_young_length < max_young_length, "invariant");
aoqi@0 676 uint diff = (max_young_length - min_young_length) / 2;
aoqi@0 677 while (diff > 0) {
aoqi@0 678 uint young_length = min_young_length + diff;
aoqi@0 679 if (predict_will_fit(young_length, base_time_ms,
aoqi@0 680 base_free_regions, target_pause_time_ms)) {
aoqi@0 681 min_young_length = young_length;
aoqi@0 682 } else {
aoqi@0 683 max_young_length = young_length;
aoqi@0 684 }
aoqi@0 685 assert(min_young_length < max_young_length, "invariant");
aoqi@0 686 diff = (max_young_length - min_young_length) / 2;
aoqi@0 687 }
aoqi@0 688 // The results is min_young_length which, according to the
aoqi@0 689 // loop invariants, should fit within the target pause time.
aoqi@0 690
aoqi@0 691 // These are the post-conditions of the binary search above:
aoqi@0 692 assert(min_young_length < max_young_length,
aoqi@0 693 "otherwise we should have discovered that max_young_length "
aoqi@0 694 "fits into the pause target and not done the binary search");
aoqi@0 695 assert(predict_will_fit(min_young_length, base_time_ms,
aoqi@0 696 base_free_regions, target_pause_time_ms),
aoqi@0 697 "min_young_length, the result of the binary search, should "
aoqi@0 698 "fit into the pause target");
aoqi@0 699 assert(!predict_will_fit(min_young_length + 1, base_time_ms,
aoqi@0 700 base_free_regions, target_pause_time_ms),
aoqi@0 701 "min_young_length, the result of the binary search, should be "
aoqi@0 702 "optimal, so no larger length should fit into the pause target");
aoqi@0 703 }
aoqi@0 704 } else {
aoqi@0 705 // Even the minimum length doesn't fit into the pause time
aoqi@0 706 // target, return it as the result nevertheless.
aoqi@0 707 }
aoqi@0 708 return base_min_length + min_young_length;
aoqi@0 709 }
aoqi@0 710
aoqi@0 711 double G1CollectorPolicy::predict_survivor_regions_evac_time() {
aoqi@0 712 double survivor_regions_evac_time = 0.0;
aoqi@0 713 for (HeapRegion * r = _recorded_survivor_head;
aoqi@0 714 r != NULL && r != _recorded_survivor_tail->get_next_young_region();
aoqi@0 715 r = r->get_next_young_region()) {
aoqi@0 716 survivor_regions_evac_time += predict_region_elapsed_time_ms(r, gcs_are_young());
aoqi@0 717 }
aoqi@0 718 return survivor_regions_evac_time;
aoqi@0 719 }
aoqi@0 720
aoqi@0 721 void G1CollectorPolicy::revise_young_list_target_length_if_necessary() {
aoqi@0 722 guarantee( adaptive_young_list_length(), "should not call this otherwise" );
aoqi@0 723
aoqi@0 724 size_t rs_lengths = _g1->young_list()->sampled_rs_lengths();
aoqi@0 725 if (rs_lengths > _rs_lengths_prediction) {
aoqi@0 726 // add 10% to avoid having to recalculate often
aoqi@0 727 size_t rs_lengths_prediction = rs_lengths * 1100 / 1000;
aoqi@0 728 update_young_list_target_length(rs_lengths_prediction);
aoqi@0 729 }
aoqi@0 730 }
aoqi@0 731
aoqi@0 732
aoqi@0 733
aoqi@0 734 HeapWord* G1CollectorPolicy::mem_allocate_work(size_t size,
aoqi@0 735 bool is_tlab,
aoqi@0 736 bool* gc_overhead_limit_was_exceeded) {
aoqi@0 737 guarantee(false, "Not using this policy feature yet.");
aoqi@0 738 return NULL;
aoqi@0 739 }
aoqi@0 740
aoqi@0 741 // This method controls how a collector handles one or more
aoqi@0 742 // of its generations being fully allocated.
aoqi@0 743 HeapWord* G1CollectorPolicy::satisfy_failed_allocation(size_t size,
aoqi@0 744 bool is_tlab) {
aoqi@0 745 guarantee(false, "Not using this policy feature yet.");
aoqi@0 746 return NULL;
aoqi@0 747 }
aoqi@0 748
aoqi@0 749
aoqi@0 750 #ifndef PRODUCT
aoqi@0 751 bool G1CollectorPolicy::verify_young_ages() {
aoqi@0 752 HeapRegion* head = _g1->young_list()->first_region();
aoqi@0 753 return
aoqi@0 754 verify_young_ages(head, _short_lived_surv_rate_group);
aoqi@0 755 // also call verify_young_ages on any additional surv rate groups
aoqi@0 756 }
aoqi@0 757
aoqi@0 758 bool
aoqi@0 759 G1CollectorPolicy::verify_young_ages(HeapRegion* head,
aoqi@0 760 SurvRateGroup *surv_rate_group) {
aoqi@0 761 guarantee( surv_rate_group != NULL, "pre-condition" );
aoqi@0 762
aoqi@0 763 const char* name = surv_rate_group->name();
aoqi@0 764 bool ret = true;
aoqi@0 765 int prev_age = -1;
aoqi@0 766
aoqi@0 767 for (HeapRegion* curr = head;
aoqi@0 768 curr != NULL;
aoqi@0 769 curr = curr->get_next_young_region()) {
aoqi@0 770 SurvRateGroup* group = curr->surv_rate_group();
aoqi@0 771 if (group == NULL && !curr->is_survivor()) {
aoqi@0 772 gclog_or_tty->print_cr("## %s: encountered NULL surv_rate_group", name);
aoqi@0 773 ret = false;
aoqi@0 774 }
aoqi@0 775
aoqi@0 776 if (surv_rate_group == group) {
aoqi@0 777 int age = curr->age_in_surv_rate_group();
aoqi@0 778
aoqi@0 779 if (age < 0) {
aoqi@0 780 gclog_or_tty->print_cr("## %s: encountered negative age", name);
aoqi@0 781 ret = false;
aoqi@0 782 }
aoqi@0 783
aoqi@0 784 if (age <= prev_age) {
aoqi@0 785 gclog_or_tty->print_cr("## %s: region ages are not strictly increasing "
aoqi@0 786 "(%d, %d)", name, age, prev_age);
aoqi@0 787 ret = false;
aoqi@0 788 }
aoqi@0 789 prev_age = age;
aoqi@0 790 }
aoqi@0 791 }
aoqi@0 792
aoqi@0 793 return ret;
aoqi@0 794 }
aoqi@0 795 #endif // PRODUCT
aoqi@0 796
aoqi@0 797 void G1CollectorPolicy::record_full_collection_start() {
aoqi@0 798 _full_collection_start_sec = os::elapsedTime();
aoqi@0 799 record_heap_size_info_at_start(true /* full */);
aoqi@0 800 // Release the future to-space so that it is available for compaction into.
aoqi@0 801 _g1->set_full_collection();
aoqi@0 802 }
aoqi@0 803
aoqi@0 804 void G1CollectorPolicy::record_full_collection_end() {
aoqi@0 805 // Consider this like a collection pause for the purposes of allocation
aoqi@0 806 // since last pause.
aoqi@0 807 double end_sec = os::elapsedTime();
aoqi@0 808 double full_gc_time_sec = end_sec - _full_collection_start_sec;
aoqi@0 809 double full_gc_time_ms = full_gc_time_sec * 1000.0;
aoqi@0 810
aoqi@0 811 _trace_gen1_time_data.record_full_collection(full_gc_time_ms);
aoqi@0 812
aoqi@0 813 update_recent_gc_times(end_sec, full_gc_time_ms);
aoqi@0 814
aoqi@0 815 _g1->clear_full_collection();
aoqi@0 816
aoqi@0 817 // "Nuke" the heuristics that control the young/mixed GC
aoqi@0 818 // transitions and make sure we start with young GCs after the Full GC.
aoqi@0 819 set_gcs_are_young(true);
aoqi@0 820 _last_young_gc = false;
aoqi@0 821 clear_initiate_conc_mark_if_possible();
aoqi@0 822 clear_during_initial_mark_pause();
aoqi@0 823 _in_marking_window = false;
aoqi@0 824 _in_marking_window_im = false;
aoqi@0 825
aoqi@0 826 _short_lived_surv_rate_group->start_adding_regions();
aoqi@0 827 // also call this on any additional surv rate groups
aoqi@0 828
aoqi@0 829 record_survivor_regions(0, NULL, NULL);
aoqi@0 830
aoqi@0 831 _free_regions_at_end_of_collection = _g1->free_regions();
aoqi@0 832 // Reset survivors SurvRateGroup.
aoqi@0 833 _survivor_surv_rate_group->reset();
aoqi@0 834 update_young_list_target_length();
aoqi@0 835 _collectionSetChooser->clear();
aoqi@0 836 }
aoqi@0 837
aoqi@0 838 void G1CollectorPolicy::record_stop_world_start() {
aoqi@0 839 _stop_world_start = os::elapsedTime();
aoqi@0 840 }
aoqi@0 841
aoqi@0 842 void G1CollectorPolicy::record_collection_pause_start(double start_time_sec) {
aoqi@0 843 // We only need to do this here as the policy will only be applied
aoqi@0 844 // to the GC we're about to start. so, no point is calculating this
aoqi@0 845 // every time we calculate / recalculate the target young length.
aoqi@0 846 update_survivors_policy();
aoqi@0 847
aoqi@0 848 assert(_g1->used() == _g1->recalculate_used(),
aoqi@0 849 err_msg("sanity, used: "SIZE_FORMAT" recalculate_used: "SIZE_FORMAT,
aoqi@0 850 _g1->used(), _g1->recalculate_used()));
aoqi@0 851
aoqi@0 852 double s_w_t_ms = (start_time_sec - _stop_world_start) * 1000.0;
aoqi@0 853 _trace_gen0_time_data.record_start_collection(s_w_t_ms);
aoqi@0 854 _stop_world_start = 0.0;
aoqi@0 855
aoqi@0 856 record_heap_size_info_at_start(false /* full */);
aoqi@0 857
aoqi@0 858 phase_times()->record_cur_collection_start_sec(start_time_sec);
aoqi@0 859 _pending_cards = _g1->pending_card_num();
aoqi@0 860
aoqi@0 861 _collection_set_bytes_used_before = 0;
aoqi@0 862 _bytes_copied_during_gc = 0;
aoqi@0 863
aoqi@0 864 _last_gc_was_young = false;
aoqi@0 865
aoqi@0 866 // do that for any other surv rate groups
aoqi@0 867 _short_lived_surv_rate_group->stop_adding_regions();
aoqi@0 868 _survivors_age_table.clear();
aoqi@0 869
aoqi@0 870 assert( verify_young_ages(), "region age verification" );
aoqi@0 871 }
aoqi@0 872
aoqi@0 873 void G1CollectorPolicy::record_concurrent_mark_init_end(double
aoqi@0 874 mark_init_elapsed_time_ms) {
aoqi@0 875 _during_marking = true;
aoqi@0 876 assert(!initiate_conc_mark_if_possible(), "we should have cleared it by now");
aoqi@0 877 clear_during_initial_mark_pause();
aoqi@0 878 _cur_mark_stop_world_time_ms = mark_init_elapsed_time_ms;
aoqi@0 879 }
aoqi@0 880
aoqi@0 881 void G1CollectorPolicy::record_concurrent_mark_remark_start() {
aoqi@0 882 _mark_remark_start_sec = os::elapsedTime();
aoqi@0 883 _during_marking = false;
aoqi@0 884 }
aoqi@0 885
aoqi@0 886 void G1CollectorPolicy::record_concurrent_mark_remark_end() {
aoqi@0 887 double end_time_sec = os::elapsedTime();
aoqi@0 888 double elapsed_time_ms = (end_time_sec - _mark_remark_start_sec)*1000.0;
aoqi@0 889 _concurrent_mark_remark_times_ms->add(elapsed_time_ms);
aoqi@0 890 _cur_mark_stop_world_time_ms += elapsed_time_ms;
aoqi@0 891 _prev_collection_pause_end_ms += elapsed_time_ms;
aoqi@0 892
aoqi@0 893 _mmu_tracker->add_pause(_mark_remark_start_sec, end_time_sec, true);
aoqi@0 894 }
aoqi@0 895
aoqi@0 896 void G1CollectorPolicy::record_concurrent_mark_cleanup_start() {
aoqi@0 897 _mark_cleanup_start_sec = os::elapsedTime();
aoqi@0 898 }
aoqi@0 899
aoqi@0 900 void G1CollectorPolicy::record_concurrent_mark_cleanup_completed() {
aoqi@0 901 _last_young_gc = true;
aoqi@0 902 _in_marking_window = false;
aoqi@0 903 }
aoqi@0 904
aoqi@0 905 void G1CollectorPolicy::record_concurrent_pause() {
aoqi@0 906 if (_stop_world_start > 0.0) {
aoqi@0 907 double yield_ms = (os::elapsedTime() - _stop_world_start) * 1000.0;
aoqi@0 908 _trace_gen0_time_data.record_yield_time(yield_ms);
aoqi@0 909 }
aoqi@0 910 }
aoqi@0 911
aoqi@0 912 bool G1CollectorPolicy::need_to_start_conc_mark(const char* source, size_t alloc_word_size) {
aoqi@0 913 if (_g1->concurrent_mark()->cmThread()->during_cycle()) {
aoqi@0 914 return false;
aoqi@0 915 }
aoqi@0 916
aoqi@0 917 size_t marking_initiating_used_threshold =
aoqi@0 918 (_g1->capacity() / 100) * InitiatingHeapOccupancyPercent;
aoqi@0 919 size_t cur_used_bytes = _g1->non_young_capacity_bytes();
aoqi@0 920 size_t alloc_byte_size = alloc_word_size * HeapWordSize;
aoqi@0 921
aoqi@0 922 if ((cur_used_bytes + alloc_byte_size) > marking_initiating_used_threshold) {
aoqi@0 923 if (gcs_are_young() && !_last_young_gc) {
aoqi@0 924 ergo_verbose5(ErgoConcCycles,
aoqi@0 925 "request concurrent cycle initiation",
aoqi@0 926 ergo_format_reason("occupancy higher than threshold")
aoqi@0 927 ergo_format_byte("occupancy")
aoqi@0 928 ergo_format_byte("allocation request")
aoqi@0 929 ergo_format_byte_perc("threshold")
aoqi@0 930 ergo_format_str("source"),
aoqi@0 931 cur_used_bytes,
aoqi@0 932 alloc_byte_size,
aoqi@0 933 marking_initiating_used_threshold,
aoqi@0 934 (double) InitiatingHeapOccupancyPercent,
aoqi@0 935 source);
aoqi@0 936 return true;
aoqi@0 937 } else {
aoqi@0 938 ergo_verbose5(ErgoConcCycles,
aoqi@0 939 "do not request concurrent cycle initiation",
aoqi@0 940 ergo_format_reason("still doing mixed collections")
aoqi@0 941 ergo_format_byte("occupancy")
aoqi@0 942 ergo_format_byte("allocation request")
aoqi@0 943 ergo_format_byte_perc("threshold")
aoqi@0 944 ergo_format_str("source"),
aoqi@0 945 cur_used_bytes,
aoqi@0 946 alloc_byte_size,
aoqi@0 947 marking_initiating_used_threshold,
aoqi@0 948 (double) InitiatingHeapOccupancyPercent,
aoqi@0 949 source);
aoqi@0 950 }
aoqi@0 951 }
aoqi@0 952
aoqi@0 953 return false;
aoqi@0 954 }
aoqi@0 955
aoqi@0 956 // Anything below that is considered to be zero
aoqi@0 957 #define MIN_TIMER_GRANULARITY 0.0000001
aoqi@0 958
aoqi@0 959 void G1CollectorPolicy::record_collection_pause_end(double pause_time_ms, EvacuationInfo& evacuation_info) {
aoqi@0 960 double end_time_sec = os::elapsedTime();
aoqi@0 961 assert(_cur_collection_pause_used_regions_at_start >= cset_region_length(),
aoqi@0 962 "otherwise, the subtraction below does not make sense");
aoqi@0 963 size_t rs_size =
aoqi@0 964 _cur_collection_pause_used_regions_at_start - cset_region_length();
aoqi@0 965 size_t cur_used_bytes = _g1->used();
aoqi@0 966 assert(cur_used_bytes == _g1->recalculate_used(), "It should!");
aoqi@0 967 bool last_pause_included_initial_mark = false;
aoqi@0 968 bool update_stats = !_g1->evacuation_failed();
aoqi@0 969
aoqi@0 970 #ifndef PRODUCT
aoqi@0 971 if (G1YoungSurvRateVerbose) {
aoqi@0 972 gclog_or_tty->cr();
aoqi@0 973 _short_lived_surv_rate_group->print();
aoqi@0 974 // do that for any other surv rate groups too
aoqi@0 975 }
aoqi@0 976 #endif // PRODUCT
aoqi@0 977
aoqi@0 978 last_pause_included_initial_mark = during_initial_mark_pause();
aoqi@0 979 if (last_pause_included_initial_mark) {
aoqi@0 980 record_concurrent_mark_init_end(0.0);
aoqi@0 981 } else if (need_to_start_conc_mark("end of GC")) {
aoqi@0 982 // Note: this might have already been set, if during the last
aoqi@0 983 // pause we decided to start a cycle but at the beginning of
aoqi@0 984 // this pause we decided to postpone it. That's OK.
aoqi@0 985 set_initiate_conc_mark_if_possible();
aoqi@0 986 }
aoqi@0 987
aoqi@0 988 _mmu_tracker->add_pause(end_time_sec - pause_time_ms/1000.0,
aoqi@0 989 end_time_sec, false);
aoqi@0 990
aoqi@0 991 evacuation_info.set_collectionset_used_before(_collection_set_bytes_used_before);
aoqi@0 992 evacuation_info.set_bytes_copied(_bytes_copied_during_gc);
aoqi@0 993
aoqi@0 994 if (update_stats) {
aoqi@0 995 _trace_gen0_time_data.record_end_collection(pause_time_ms, phase_times());
aoqi@0 996 // this is where we update the allocation rate of the application
aoqi@0 997 double app_time_ms =
aoqi@0 998 (phase_times()->cur_collection_start_sec() * 1000.0 - _prev_collection_pause_end_ms);
aoqi@0 999 if (app_time_ms < MIN_TIMER_GRANULARITY) {
aoqi@0 1000 // This usually happens due to the timer not having the required
aoqi@0 1001 // granularity. Some Linuxes are the usual culprits.
aoqi@0 1002 // We'll just set it to something (arbitrarily) small.
aoqi@0 1003 app_time_ms = 1.0;
aoqi@0 1004 }
aoqi@0 1005 // We maintain the invariant that all objects allocated by mutator
aoqi@0 1006 // threads will be allocated out of eden regions. So, we can use
aoqi@0 1007 // the eden region number allocated since the previous GC to
aoqi@0 1008 // calculate the application's allocate rate. The only exception
aoqi@0 1009 // to that is humongous objects that are allocated separately. But
aoqi@0 1010 // given that humongous object allocations do not really affect
aoqi@0 1011 // either the pause's duration nor when the next pause will take
aoqi@0 1012 // place we can safely ignore them here.
aoqi@0 1013 uint regions_allocated = eden_cset_region_length();
aoqi@0 1014 double alloc_rate_ms = (double) regions_allocated / app_time_ms;
aoqi@0 1015 _alloc_rate_ms_seq->add(alloc_rate_ms);
aoqi@0 1016
aoqi@0 1017 double interval_ms =
aoqi@0 1018 (end_time_sec - _recent_prev_end_times_for_all_gcs_sec->oldest()) * 1000.0;
aoqi@0 1019 update_recent_gc_times(end_time_sec, pause_time_ms);
aoqi@0 1020 _recent_avg_pause_time_ratio = _recent_gc_times_ms->sum()/interval_ms;
aoqi@0 1021 if (recent_avg_pause_time_ratio() < 0.0 ||
aoqi@0 1022 (recent_avg_pause_time_ratio() - 1.0 > 0.0)) {
aoqi@0 1023 #ifndef PRODUCT
aoqi@0 1024 // Dump info to allow post-facto debugging
aoqi@0 1025 gclog_or_tty->print_cr("recent_avg_pause_time_ratio() out of bounds");
aoqi@0 1026 gclog_or_tty->print_cr("-------------------------------------------");
aoqi@0 1027 gclog_or_tty->print_cr("Recent GC Times (ms):");
aoqi@0 1028 _recent_gc_times_ms->dump();
aoqi@0 1029 gclog_or_tty->print_cr("(End Time=%3.3f) Recent GC End Times (s):", end_time_sec);
aoqi@0 1030 _recent_prev_end_times_for_all_gcs_sec->dump();
aoqi@0 1031 gclog_or_tty->print_cr("GC = %3.3f, Interval = %3.3f, Ratio = %3.3f",
aoqi@0 1032 _recent_gc_times_ms->sum(), interval_ms, recent_avg_pause_time_ratio());
aoqi@0 1033 // In debug mode, terminate the JVM if the user wants to debug at this point.
aoqi@0 1034 assert(!G1FailOnFPError, "Debugging data for CR 6898948 has been dumped above");
aoqi@0 1035 #endif // !PRODUCT
aoqi@0 1036 // Clip ratio between 0.0 and 1.0, and continue. This will be fixed in
aoqi@0 1037 // CR 6902692 by redoing the manner in which the ratio is incrementally computed.
aoqi@0 1038 if (_recent_avg_pause_time_ratio < 0.0) {
aoqi@0 1039 _recent_avg_pause_time_ratio = 0.0;
aoqi@0 1040 } else {
aoqi@0 1041 assert(_recent_avg_pause_time_ratio - 1.0 > 0.0, "Ctl-point invariant");
aoqi@0 1042 _recent_avg_pause_time_ratio = 1.0;
aoqi@0 1043 }
aoqi@0 1044 }
aoqi@0 1045 }
aoqi@0 1046
aoqi@0 1047 bool new_in_marking_window = _in_marking_window;
aoqi@0 1048 bool new_in_marking_window_im = false;
aoqi@0 1049 if (during_initial_mark_pause()) {
aoqi@0 1050 new_in_marking_window = true;
aoqi@0 1051 new_in_marking_window_im = true;
aoqi@0 1052 }
aoqi@0 1053
aoqi@0 1054 if (_last_young_gc) {
aoqi@0 1055 // This is supposed to to be the "last young GC" before we start
aoqi@0 1056 // doing mixed GCs. Here we decide whether to start mixed GCs or not.
aoqi@0 1057
aoqi@0 1058 if (!last_pause_included_initial_mark) {
aoqi@0 1059 if (next_gc_should_be_mixed("start mixed GCs",
aoqi@0 1060 "do not start mixed GCs")) {
aoqi@0 1061 set_gcs_are_young(false);
aoqi@0 1062 }
aoqi@0 1063 } else {
aoqi@0 1064 ergo_verbose0(ErgoMixedGCs,
aoqi@0 1065 "do not start mixed GCs",
aoqi@0 1066 ergo_format_reason("concurrent cycle is about to start"));
aoqi@0 1067 }
aoqi@0 1068 _last_young_gc = false;
aoqi@0 1069 }
aoqi@0 1070
aoqi@0 1071 if (!_last_gc_was_young) {
aoqi@0 1072 // This is a mixed GC. Here we decide whether to continue doing
aoqi@0 1073 // mixed GCs or not.
aoqi@0 1074
aoqi@0 1075 if (!next_gc_should_be_mixed("continue mixed GCs",
aoqi@0 1076 "do not continue mixed GCs")) {
aoqi@0 1077 set_gcs_are_young(true);
aoqi@0 1078 }
aoqi@0 1079 }
aoqi@0 1080
aoqi@0 1081 _short_lived_surv_rate_group->start_adding_regions();
aoqi@0 1082 // do that for any other surv rate groupsx
aoqi@0 1083
aoqi@0 1084 if (update_stats) {
aoqi@0 1085 double cost_per_card_ms = 0.0;
aoqi@0 1086 if (_pending_cards > 0) {
aoqi@0 1087 cost_per_card_ms = phase_times()->average_last_update_rs_time() / (double) _pending_cards;
aoqi@0 1088 _cost_per_card_ms_seq->add(cost_per_card_ms);
aoqi@0 1089 }
aoqi@0 1090
aoqi@0 1091 size_t cards_scanned = _g1->cards_scanned();
aoqi@0 1092
aoqi@0 1093 double cost_per_entry_ms = 0.0;
aoqi@0 1094 if (cards_scanned > 10) {
aoqi@0 1095 cost_per_entry_ms = phase_times()->average_last_scan_rs_time() / (double) cards_scanned;
aoqi@0 1096 if (_last_gc_was_young) {
aoqi@0 1097 _cost_per_entry_ms_seq->add(cost_per_entry_ms);
aoqi@0 1098 } else {
aoqi@0 1099 _mixed_cost_per_entry_ms_seq->add(cost_per_entry_ms);
aoqi@0 1100 }
aoqi@0 1101 }
aoqi@0 1102
aoqi@0 1103 if (_max_rs_lengths > 0) {
aoqi@0 1104 double cards_per_entry_ratio =
aoqi@0 1105 (double) cards_scanned / (double) _max_rs_lengths;
aoqi@0 1106 if (_last_gc_was_young) {
aoqi@0 1107 _young_cards_per_entry_ratio_seq->add(cards_per_entry_ratio);
aoqi@0 1108 } else {
aoqi@0 1109 _mixed_cards_per_entry_ratio_seq->add(cards_per_entry_ratio);
aoqi@0 1110 }
aoqi@0 1111 }
aoqi@0 1112
aoqi@0 1113 // This is defensive. For a while _max_rs_lengths could get
aoqi@0 1114 // smaller than _recorded_rs_lengths which was causing
aoqi@0 1115 // rs_length_diff to get very large and mess up the RSet length
aoqi@0 1116 // predictions. The reason was unsafe concurrent updates to the
aoqi@0 1117 // _inc_cset_recorded_rs_lengths field which the code below guards
aoqi@0 1118 // against (see CR 7118202). This bug has now been fixed (see CR
aoqi@0 1119 // 7119027). However, I'm still worried that
aoqi@0 1120 // _inc_cset_recorded_rs_lengths might still end up somewhat
aoqi@0 1121 // inaccurate. The concurrent refinement thread calculates an
aoqi@0 1122 // RSet's length concurrently with other CR threads updating it
aoqi@0 1123 // which might cause it to calculate the length incorrectly (if,
aoqi@0 1124 // say, it's in mid-coarsening). So I'll leave in the defensive
aoqi@0 1125 // conditional below just in case.
aoqi@0 1126 size_t rs_length_diff = 0;
aoqi@0 1127 if (_max_rs_lengths > _recorded_rs_lengths) {
aoqi@0 1128 rs_length_diff = _max_rs_lengths - _recorded_rs_lengths;
aoqi@0 1129 }
aoqi@0 1130 _rs_length_diff_seq->add((double) rs_length_diff);
aoqi@0 1131
aoqi@0 1132 size_t freed_bytes = _heap_used_bytes_before_gc - cur_used_bytes;
aoqi@0 1133 size_t copied_bytes = _collection_set_bytes_used_before - freed_bytes;
aoqi@0 1134 double cost_per_byte_ms = 0.0;
aoqi@0 1135
aoqi@0 1136 if (copied_bytes > 0) {
aoqi@0 1137 cost_per_byte_ms = phase_times()->average_last_obj_copy_time() / (double) copied_bytes;
aoqi@0 1138 if (_in_marking_window) {
aoqi@0 1139 _cost_per_byte_ms_during_cm_seq->add(cost_per_byte_ms);
aoqi@0 1140 } else {
aoqi@0 1141 _cost_per_byte_ms_seq->add(cost_per_byte_ms);
aoqi@0 1142 }
aoqi@0 1143 }
aoqi@0 1144
aoqi@0 1145 double all_other_time_ms = pause_time_ms -
aoqi@0 1146 (phase_times()->average_last_update_rs_time() + phase_times()->average_last_scan_rs_time()
aoqi@0 1147 + phase_times()->average_last_obj_copy_time() + phase_times()->average_last_termination_time());
aoqi@0 1148
aoqi@0 1149 double young_other_time_ms = 0.0;
aoqi@0 1150 if (young_cset_region_length() > 0) {
aoqi@0 1151 young_other_time_ms =
aoqi@0 1152 phase_times()->young_cset_choice_time_ms() +
aoqi@0 1153 phase_times()->young_free_cset_time_ms();
aoqi@0 1154 _young_other_cost_per_region_ms_seq->add(young_other_time_ms /
aoqi@0 1155 (double) young_cset_region_length());
aoqi@0 1156 }
aoqi@0 1157 double non_young_other_time_ms = 0.0;
aoqi@0 1158 if (old_cset_region_length() > 0) {
aoqi@0 1159 non_young_other_time_ms =
aoqi@0 1160 phase_times()->non_young_cset_choice_time_ms() +
aoqi@0 1161 phase_times()->non_young_free_cset_time_ms();
aoqi@0 1162
aoqi@0 1163 _non_young_other_cost_per_region_ms_seq->add(non_young_other_time_ms /
aoqi@0 1164 (double) old_cset_region_length());
aoqi@0 1165 }
aoqi@0 1166
aoqi@0 1167 double constant_other_time_ms = all_other_time_ms -
aoqi@0 1168 (young_other_time_ms + non_young_other_time_ms);
aoqi@0 1169 _constant_other_time_ms_seq->add(constant_other_time_ms);
aoqi@0 1170
aoqi@0 1171 double survival_ratio = 0.0;
aoqi@0 1172 if (_collection_set_bytes_used_before > 0) {
aoqi@0 1173 survival_ratio = (double) _bytes_copied_during_gc /
aoqi@0 1174 (double) _collection_set_bytes_used_before;
aoqi@0 1175 }
aoqi@0 1176
aoqi@0 1177 _pending_cards_seq->add((double) _pending_cards);
aoqi@0 1178 _rs_lengths_seq->add((double) _max_rs_lengths);
aoqi@0 1179 }
aoqi@0 1180
aoqi@0 1181 _in_marking_window = new_in_marking_window;
aoqi@0 1182 _in_marking_window_im = new_in_marking_window_im;
aoqi@0 1183 _free_regions_at_end_of_collection = _g1->free_regions();
aoqi@0 1184 update_young_list_target_length();
aoqi@0 1185
aoqi@0 1186 // Note that _mmu_tracker->max_gc_time() returns the time in seconds.
aoqi@0 1187 double update_rs_time_goal_ms = _mmu_tracker->max_gc_time() * MILLIUNITS * G1RSetUpdatingPauseTimePercent / 100.0;
aoqi@0 1188 adjust_concurrent_refinement(phase_times()->average_last_update_rs_time(),
aoqi@0 1189 phase_times()->sum_last_update_rs_processed_buffers(), update_rs_time_goal_ms);
aoqi@0 1190
aoqi@0 1191 _collectionSetChooser->verify();
aoqi@0 1192 }
aoqi@0 1193
aoqi@0 1194 #define EXT_SIZE_FORMAT "%.1f%s"
aoqi@0 1195 #define EXT_SIZE_PARAMS(bytes) \
aoqi@0 1196 byte_size_in_proper_unit((double)(bytes)), \
aoqi@0 1197 proper_unit_for_byte_size((bytes))
aoqi@0 1198
aoqi@0 1199 void G1CollectorPolicy::record_heap_size_info_at_start(bool full) {
aoqi@0 1200 YoungList* young_list = _g1->young_list();
aoqi@0 1201 _eden_used_bytes_before_gc = young_list->eden_used_bytes();
aoqi@0 1202 _survivor_used_bytes_before_gc = young_list->survivor_used_bytes();
aoqi@0 1203 _heap_capacity_bytes_before_gc = _g1->capacity();
aoqi@0 1204 _heap_used_bytes_before_gc = _g1->used();
aoqi@0 1205 _cur_collection_pause_used_regions_at_start = _g1->used_regions();
aoqi@0 1206
aoqi@0 1207 _eden_capacity_bytes_before_gc =
aoqi@0 1208 (_young_list_target_length * HeapRegion::GrainBytes) - _survivor_used_bytes_before_gc;
aoqi@0 1209
aoqi@0 1210 if (full) {
aoqi@0 1211 _metaspace_used_bytes_before_gc = MetaspaceAux::used_bytes();
aoqi@0 1212 }
aoqi@0 1213 }
aoqi@0 1214
aoqi@0 1215 void G1CollectorPolicy::print_heap_transition() {
aoqi@0 1216 _g1->print_size_transition(gclog_or_tty,
aoqi@0 1217 _heap_used_bytes_before_gc,
aoqi@0 1218 _g1->used(),
aoqi@0 1219 _g1->capacity());
aoqi@0 1220 }
aoqi@0 1221
aoqi@0 1222 void G1CollectorPolicy::print_detailed_heap_transition(bool full) {
aoqi@0 1223 YoungList* young_list = _g1->young_list();
aoqi@0 1224
aoqi@0 1225 size_t eden_used_bytes_after_gc = young_list->eden_used_bytes();
aoqi@0 1226 size_t survivor_used_bytes_after_gc = young_list->survivor_used_bytes();
aoqi@0 1227 size_t heap_used_bytes_after_gc = _g1->used();
aoqi@0 1228
aoqi@0 1229 size_t heap_capacity_bytes_after_gc = _g1->capacity();
aoqi@0 1230 size_t eden_capacity_bytes_after_gc =
aoqi@0 1231 (_young_list_target_length * HeapRegion::GrainBytes) - survivor_used_bytes_after_gc;
aoqi@0 1232
aoqi@0 1233 gclog_or_tty->print(
aoqi@0 1234 " [Eden: "EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")->"EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT") "
aoqi@0 1235 "Survivors: "EXT_SIZE_FORMAT"->"EXT_SIZE_FORMAT" "
aoqi@0 1236 "Heap: "EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")->"
aoqi@0 1237 EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")]",
aoqi@0 1238 EXT_SIZE_PARAMS(_eden_used_bytes_before_gc),
aoqi@0 1239 EXT_SIZE_PARAMS(_eden_capacity_bytes_before_gc),
aoqi@0 1240 EXT_SIZE_PARAMS(eden_used_bytes_after_gc),
aoqi@0 1241 EXT_SIZE_PARAMS(eden_capacity_bytes_after_gc),
aoqi@0 1242 EXT_SIZE_PARAMS(_survivor_used_bytes_before_gc),
aoqi@0 1243 EXT_SIZE_PARAMS(survivor_used_bytes_after_gc),
aoqi@0 1244 EXT_SIZE_PARAMS(_heap_used_bytes_before_gc),
aoqi@0 1245 EXT_SIZE_PARAMS(_heap_capacity_bytes_before_gc),
aoqi@0 1246 EXT_SIZE_PARAMS(heap_used_bytes_after_gc),
aoqi@0 1247 EXT_SIZE_PARAMS(heap_capacity_bytes_after_gc));
aoqi@0 1248
aoqi@0 1249 if (full) {
aoqi@0 1250 MetaspaceAux::print_metaspace_change(_metaspace_used_bytes_before_gc);
aoqi@0 1251 }
aoqi@0 1252
aoqi@0 1253 gclog_or_tty->cr();
aoqi@0 1254 }
aoqi@0 1255
aoqi@0 1256 void G1CollectorPolicy::adjust_concurrent_refinement(double update_rs_time,
aoqi@0 1257 double update_rs_processed_buffers,
aoqi@0 1258 double goal_ms) {
aoqi@0 1259 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
aoqi@0 1260 ConcurrentG1Refine *cg1r = G1CollectedHeap::heap()->concurrent_g1_refine();
aoqi@0 1261
aoqi@0 1262 if (G1UseAdaptiveConcRefinement) {
aoqi@0 1263 const int k_gy = 3, k_gr = 6;
aoqi@0 1264 const double inc_k = 1.1, dec_k = 0.9;
aoqi@0 1265
aoqi@0 1266 int g = cg1r->green_zone();
aoqi@0 1267 if (update_rs_time > goal_ms) {
aoqi@0 1268 g = (int)(g * dec_k); // Can become 0, that's OK. That would mean a mutator-only processing.
aoqi@0 1269 } else {
aoqi@0 1270 if (update_rs_time < goal_ms && update_rs_processed_buffers > g) {
aoqi@0 1271 g = (int)MAX2(g * inc_k, g + 1.0);
aoqi@0 1272 }
aoqi@0 1273 }
aoqi@0 1274 // Change the refinement threads params
aoqi@0 1275 cg1r->set_green_zone(g);
aoqi@0 1276 cg1r->set_yellow_zone(g * k_gy);
aoqi@0 1277 cg1r->set_red_zone(g * k_gr);
aoqi@0 1278 cg1r->reinitialize_threads();
aoqi@0 1279
aoqi@0 1280 int processing_threshold_delta = MAX2((int)(cg1r->green_zone() * sigma()), 1);
aoqi@0 1281 int processing_threshold = MIN2(cg1r->green_zone() + processing_threshold_delta,
aoqi@0 1282 cg1r->yellow_zone());
aoqi@0 1283 // Change the barrier params
aoqi@0 1284 dcqs.set_process_completed_threshold(processing_threshold);
aoqi@0 1285 dcqs.set_max_completed_queue(cg1r->red_zone());
aoqi@0 1286 }
aoqi@0 1287
aoqi@0 1288 int curr_queue_size = dcqs.completed_buffers_num();
aoqi@0 1289 if (curr_queue_size >= cg1r->yellow_zone()) {
aoqi@0 1290 dcqs.set_completed_queue_padding(curr_queue_size);
aoqi@0 1291 } else {
aoqi@0 1292 dcqs.set_completed_queue_padding(0);
aoqi@0 1293 }
aoqi@0 1294 dcqs.notify_if_necessary();
aoqi@0 1295 }
aoqi@0 1296
aoqi@0 1297 double
aoqi@0 1298 G1CollectorPolicy::predict_base_elapsed_time_ms(size_t pending_cards,
aoqi@0 1299 size_t scanned_cards) {
aoqi@0 1300 return
aoqi@0 1301 predict_rs_update_time_ms(pending_cards) +
aoqi@0 1302 predict_rs_scan_time_ms(scanned_cards) +
aoqi@0 1303 predict_constant_other_time_ms();
aoqi@0 1304 }
aoqi@0 1305
aoqi@0 1306 double
aoqi@0 1307 G1CollectorPolicy::predict_base_elapsed_time_ms(size_t pending_cards) {
aoqi@0 1308 size_t rs_length = predict_rs_length_diff();
aoqi@0 1309 size_t card_num;
aoqi@0 1310 if (gcs_are_young()) {
aoqi@0 1311 card_num = predict_young_card_num(rs_length);
aoqi@0 1312 } else {
aoqi@0 1313 card_num = predict_non_young_card_num(rs_length);
aoqi@0 1314 }
aoqi@0 1315 return predict_base_elapsed_time_ms(pending_cards, card_num);
aoqi@0 1316 }
aoqi@0 1317
aoqi@0 1318 size_t G1CollectorPolicy::predict_bytes_to_copy(HeapRegion* hr) {
aoqi@0 1319 size_t bytes_to_copy;
aoqi@0 1320 if (hr->is_marked())
aoqi@0 1321 bytes_to_copy = hr->max_live_bytes();
aoqi@0 1322 else {
aoqi@0 1323 assert(hr->is_young() && hr->age_in_surv_rate_group() != -1, "invariant");
aoqi@0 1324 int age = hr->age_in_surv_rate_group();
aoqi@0 1325 double yg_surv_rate = predict_yg_surv_rate(age, hr->surv_rate_group());
aoqi@0 1326 bytes_to_copy = (size_t) ((double) hr->used() * yg_surv_rate);
aoqi@0 1327 }
aoqi@0 1328 return bytes_to_copy;
aoqi@0 1329 }
aoqi@0 1330
aoqi@0 1331 double
aoqi@0 1332 G1CollectorPolicy::predict_region_elapsed_time_ms(HeapRegion* hr,
aoqi@0 1333 bool for_young_gc) {
aoqi@0 1334 size_t rs_length = hr->rem_set()->occupied();
aoqi@0 1335 size_t card_num;
aoqi@0 1336
aoqi@0 1337 // Predicting the number of cards is based on which type of GC
aoqi@0 1338 // we're predicting for.
aoqi@0 1339 if (for_young_gc) {
aoqi@0 1340 card_num = predict_young_card_num(rs_length);
aoqi@0 1341 } else {
aoqi@0 1342 card_num = predict_non_young_card_num(rs_length);
aoqi@0 1343 }
aoqi@0 1344 size_t bytes_to_copy = predict_bytes_to_copy(hr);
aoqi@0 1345
aoqi@0 1346 double region_elapsed_time_ms =
aoqi@0 1347 predict_rs_scan_time_ms(card_num) +
aoqi@0 1348 predict_object_copy_time_ms(bytes_to_copy);
aoqi@0 1349
aoqi@0 1350 // The prediction of the "other" time for this region is based
aoqi@0 1351 // upon the region type and NOT the GC type.
aoqi@0 1352 if (hr->is_young()) {
aoqi@0 1353 region_elapsed_time_ms += predict_young_other_time_ms(1);
aoqi@0 1354 } else {
aoqi@0 1355 region_elapsed_time_ms += predict_non_young_other_time_ms(1);
aoqi@0 1356 }
aoqi@0 1357 return region_elapsed_time_ms;
aoqi@0 1358 }
aoqi@0 1359
aoqi@0 1360 void
aoqi@0 1361 G1CollectorPolicy::init_cset_region_lengths(uint eden_cset_region_length,
aoqi@0 1362 uint survivor_cset_region_length) {
aoqi@0 1363 _eden_cset_region_length = eden_cset_region_length;
aoqi@0 1364 _survivor_cset_region_length = survivor_cset_region_length;
aoqi@0 1365 _old_cset_region_length = 0;
aoqi@0 1366 }
aoqi@0 1367
aoqi@0 1368 void G1CollectorPolicy::set_recorded_rs_lengths(size_t rs_lengths) {
aoqi@0 1369 _recorded_rs_lengths = rs_lengths;
aoqi@0 1370 }
aoqi@0 1371
aoqi@0 1372 void G1CollectorPolicy::update_recent_gc_times(double end_time_sec,
aoqi@0 1373 double elapsed_ms) {
aoqi@0 1374 _recent_gc_times_ms->add(elapsed_ms);
aoqi@0 1375 _recent_prev_end_times_for_all_gcs_sec->add(end_time_sec);
aoqi@0 1376 _prev_collection_pause_end_ms = end_time_sec * 1000.0;
aoqi@0 1377 }
aoqi@0 1378
aoqi@0 1379 size_t G1CollectorPolicy::expansion_amount() {
aoqi@0 1380 double recent_gc_overhead = recent_avg_pause_time_ratio() * 100.0;
aoqi@0 1381 double threshold = _gc_overhead_perc;
aoqi@0 1382 if (recent_gc_overhead > threshold) {
aoqi@0 1383 // We will double the existing space, or take
aoqi@0 1384 // G1ExpandByPercentOfAvailable % of the available expansion
aoqi@0 1385 // space, whichever is smaller, bounded below by a minimum
aoqi@0 1386 // expansion (unless that's all that's left.)
aoqi@0 1387 const size_t min_expand_bytes = 1*M;
aoqi@0 1388 size_t reserved_bytes = _g1->max_capacity();
aoqi@0 1389 size_t committed_bytes = _g1->capacity();
aoqi@0 1390 size_t uncommitted_bytes = reserved_bytes - committed_bytes;
aoqi@0 1391 size_t expand_bytes;
aoqi@0 1392 size_t expand_bytes_via_pct =
aoqi@0 1393 uncommitted_bytes * G1ExpandByPercentOfAvailable / 100;
aoqi@0 1394 expand_bytes = MIN2(expand_bytes_via_pct, committed_bytes);
aoqi@0 1395 expand_bytes = MAX2(expand_bytes, min_expand_bytes);
aoqi@0 1396 expand_bytes = MIN2(expand_bytes, uncommitted_bytes);
aoqi@0 1397
aoqi@0 1398 ergo_verbose5(ErgoHeapSizing,
aoqi@0 1399 "attempt heap expansion",
aoqi@0 1400 ergo_format_reason("recent GC overhead higher than "
aoqi@0 1401 "threshold after GC")
aoqi@0 1402 ergo_format_perc("recent GC overhead")
aoqi@0 1403 ergo_format_perc("threshold")
aoqi@0 1404 ergo_format_byte("uncommitted")
aoqi@0 1405 ergo_format_byte_perc("calculated expansion amount"),
aoqi@0 1406 recent_gc_overhead, threshold,
aoqi@0 1407 uncommitted_bytes,
aoqi@0 1408 expand_bytes_via_pct, (double) G1ExpandByPercentOfAvailable);
aoqi@0 1409
aoqi@0 1410 return expand_bytes;
aoqi@0 1411 } else {
aoqi@0 1412 return 0;
aoqi@0 1413 }
aoqi@0 1414 }
aoqi@0 1415
aoqi@0 1416 void G1CollectorPolicy::print_tracing_info() const {
aoqi@0 1417 _trace_gen0_time_data.print();
aoqi@0 1418 _trace_gen1_time_data.print();
aoqi@0 1419 }
aoqi@0 1420
aoqi@0 1421 void G1CollectorPolicy::print_yg_surv_rate_info() const {
aoqi@0 1422 #ifndef PRODUCT
aoqi@0 1423 _short_lived_surv_rate_group->print_surv_rate_summary();
aoqi@0 1424 // add this call for any other surv rate groups
aoqi@0 1425 #endif // PRODUCT
aoqi@0 1426 }
aoqi@0 1427
aoqi@0 1428 uint G1CollectorPolicy::max_regions(int purpose) {
aoqi@0 1429 switch (purpose) {
aoqi@0 1430 case GCAllocForSurvived:
aoqi@0 1431 return _max_survivor_regions;
aoqi@0 1432 case GCAllocForTenured:
aoqi@0 1433 return REGIONS_UNLIMITED;
aoqi@0 1434 default:
aoqi@0 1435 ShouldNotReachHere();
aoqi@0 1436 return REGIONS_UNLIMITED;
aoqi@0 1437 };
aoqi@0 1438 }
aoqi@0 1439
aoqi@0 1440 void G1CollectorPolicy::update_max_gc_locker_expansion() {
aoqi@0 1441 uint expansion_region_num = 0;
aoqi@0 1442 if (GCLockerEdenExpansionPercent > 0) {
aoqi@0 1443 double perc = (double) GCLockerEdenExpansionPercent / 100.0;
aoqi@0 1444 double expansion_region_num_d = perc * (double) _young_list_target_length;
aoqi@0 1445 // We use ceiling so that if expansion_region_num_d is > 0.0 (but
aoqi@0 1446 // less than 1.0) we'll get 1.
aoqi@0 1447 expansion_region_num = (uint) ceil(expansion_region_num_d);
aoqi@0 1448 } else {
aoqi@0 1449 assert(expansion_region_num == 0, "sanity");
aoqi@0 1450 }
aoqi@0 1451 _young_list_max_length = _young_list_target_length + expansion_region_num;
aoqi@0 1452 assert(_young_list_target_length <= _young_list_max_length, "post-condition");
aoqi@0 1453 }
aoqi@0 1454
aoqi@0 1455 // Calculates survivor space parameters.
aoqi@0 1456 void G1CollectorPolicy::update_survivors_policy() {
aoqi@0 1457 double max_survivor_regions_d =
aoqi@0 1458 (double) _young_list_target_length / (double) SurvivorRatio;
aoqi@0 1459 // We use ceiling so that if max_survivor_regions_d is > 0.0 (but
aoqi@0 1460 // smaller than 1.0) we'll get 1.
aoqi@0 1461 _max_survivor_regions = (uint) ceil(max_survivor_regions_d);
aoqi@0 1462
aoqi@0 1463 _tenuring_threshold = _survivors_age_table.compute_tenuring_threshold(
aoqi@0 1464 HeapRegion::GrainWords * _max_survivor_regions);
aoqi@0 1465 }
aoqi@0 1466
aoqi@0 1467 bool G1CollectorPolicy::force_initial_mark_if_outside_cycle(
aoqi@0 1468 GCCause::Cause gc_cause) {
aoqi@0 1469 bool during_cycle = _g1->concurrent_mark()->cmThread()->during_cycle();
aoqi@0 1470 if (!during_cycle) {
aoqi@0 1471 ergo_verbose1(ErgoConcCycles,
aoqi@0 1472 "request concurrent cycle initiation",
aoqi@0 1473 ergo_format_reason("requested by GC cause")
aoqi@0 1474 ergo_format_str("GC cause"),
aoqi@0 1475 GCCause::to_string(gc_cause));
aoqi@0 1476 set_initiate_conc_mark_if_possible();
aoqi@0 1477 return true;
aoqi@0 1478 } else {
aoqi@0 1479 ergo_verbose1(ErgoConcCycles,
aoqi@0 1480 "do not request concurrent cycle initiation",
aoqi@0 1481 ergo_format_reason("concurrent cycle already in progress")
aoqi@0 1482 ergo_format_str("GC cause"),
aoqi@0 1483 GCCause::to_string(gc_cause));
aoqi@0 1484 return false;
aoqi@0 1485 }
aoqi@0 1486 }
aoqi@0 1487
aoqi@0 1488 void
aoqi@0 1489 G1CollectorPolicy::decide_on_conc_mark_initiation() {
aoqi@0 1490 // We are about to decide on whether this pause will be an
aoqi@0 1491 // initial-mark pause.
aoqi@0 1492
aoqi@0 1493 // First, during_initial_mark_pause() should not be already set. We
aoqi@0 1494 // will set it here if we have to. However, it should be cleared by
aoqi@0 1495 // the end of the pause (it's only set for the duration of an
aoqi@0 1496 // initial-mark pause).
aoqi@0 1497 assert(!during_initial_mark_pause(), "pre-condition");
aoqi@0 1498
aoqi@0 1499 if (initiate_conc_mark_if_possible()) {
aoqi@0 1500 // We had noticed on a previous pause that the heap occupancy has
aoqi@0 1501 // gone over the initiating threshold and we should start a
aoqi@0 1502 // concurrent marking cycle. So we might initiate one.
aoqi@0 1503
aoqi@0 1504 bool during_cycle = _g1->concurrent_mark()->cmThread()->during_cycle();
aoqi@0 1505 if (!during_cycle) {
aoqi@0 1506 // The concurrent marking thread is not "during a cycle", i.e.,
aoqi@0 1507 // it has completed the last one. So we can go ahead and
aoqi@0 1508 // initiate a new cycle.
aoqi@0 1509
aoqi@0 1510 set_during_initial_mark_pause();
aoqi@0 1511 // We do not allow mixed GCs during marking.
aoqi@0 1512 if (!gcs_are_young()) {
aoqi@0 1513 set_gcs_are_young(true);
aoqi@0 1514 ergo_verbose0(ErgoMixedGCs,
aoqi@0 1515 "end mixed GCs",
aoqi@0 1516 ergo_format_reason("concurrent cycle is about to start"));
aoqi@0 1517 }
aoqi@0 1518
aoqi@0 1519 // And we can now clear initiate_conc_mark_if_possible() as
aoqi@0 1520 // we've already acted on it.
aoqi@0 1521 clear_initiate_conc_mark_if_possible();
aoqi@0 1522
aoqi@0 1523 ergo_verbose0(ErgoConcCycles,
aoqi@0 1524 "initiate concurrent cycle",
aoqi@0 1525 ergo_format_reason("concurrent cycle initiation requested"));
aoqi@0 1526 } else {
aoqi@0 1527 // The concurrent marking thread is still finishing up the
aoqi@0 1528 // previous cycle. If we start one right now the two cycles
aoqi@0 1529 // overlap. In particular, the concurrent marking thread might
aoqi@0 1530 // be in the process of clearing the next marking bitmap (which
aoqi@0 1531 // we will use for the next cycle if we start one). Starting a
aoqi@0 1532 // cycle now will be bad given that parts of the marking
aoqi@0 1533 // information might get cleared by the marking thread. And we
aoqi@0 1534 // cannot wait for the marking thread to finish the cycle as it
aoqi@0 1535 // periodically yields while clearing the next marking bitmap
aoqi@0 1536 // and, if it's in a yield point, it's waiting for us to
aoqi@0 1537 // finish. So, at this point we will not start a cycle and we'll
aoqi@0 1538 // let the concurrent marking thread complete the last one.
aoqi@0 1539 ergo_verbose0(ErgoConcCycles,
aoqi@0 1540 "do not initiate concurrent cycle",
aoqi@0 1541 ergo_format_reason("concurrent cycle already in progress"));
aoqi@0 1542 }
aoqi@0 1543 }
aoqi@0 1544 }
aoqi@0 1545
aoqi@0 1546 class KnownGarbageClosure: public HeapRegionClosure {
aoqi@0 1547 G1CollectedHeap* _g1h;
aoqi@0 1548 CollectionSetChooser* _hrSorted;
aoqi@0 1549
aoqi@0 1550 public:
aoqi@0 1551 KnownGarbageClosure(CollectionSetChooser* hrSorted) :
aoqi@0 1552 _g1h(G1CollectedHeap::heap()), _hrSorted(hrSorted) { }
aoqi@0 1553
aoqi@0 1554 bool doHeapRegion(HeapRegion* r) {
aoqi@0 1555 // We only include humongous regions in collection
aoqi@0 1556 // sets when concurrent mark shows that their contained object is
aoqi@0 1557 // unreachable.
aoqi@0 1558
aoqi@0 1559 // Do we have any marking information for this region?
aoqi@0 1560 if (r->is_marked()) {
aoqi@0 1561 // We will skip any region that's currently used as an old GC
aoqi@0 1562 // alloc region (we should not consider those for collection
aoqi@0 1563 // before we fill them up).
aoqi@0 1564 if (_hrSorted->should_add(r) && !_g1h->is_old_gc_alloc_region(r)) {
aoqi@0 1565 _hrSorted->add_region(r);
aoqi@0 1566 }
aoqi@0 1567 }
aoqi@0 1568 return false;
aoqi@0 1569 }
aoqi@0 1570 };
aoqi@0 1571
aoqi@0 1572 class ParKnownGarbageHRClosure: public HeapRegionClosure {
aoqi@0 1573 G1CollectedHeap* _g1h;
aoqi@0 1574 CSetChooserParUpdater _cset_updater;
aoqi@0 1575
aoqi@0 1576 public:
aoqi@0 1577 ParKnownGarbageHRClosure(CollectionSetChooser* hrSorted,
aoqi@0 1578 uint chunk_size) :
aoqi@0 1579 _g1h(G1CollectedHeap::heap()),
aoqi@0 1580 _cset_updater(hrSorted, true /* parallel */, chunk_size) { }
aoqi@0 1581
aoqi@0 1582 bool doHeapRegion(HeapRegion* r) {
aoqi@0 1583 // Do we have any marking information for this region?
aoqi@0 1584 if (r->is_marked()) {
aoqi@0 1585 // We will skip any region that's currently used as an old GC
aoqi@0 1586 // alloc region (we should not consider those for collection
aoqi@0 1587 // before we fill them up).
aoqi@0 1588 if (_cset_updater.should_add(r) && !_g1h->is_old_gc_alloc_region(r)) {
aoqi@0 1589 _cset_updater.add_region(r);
aoqi@0 1590 }
aoqi@0 1591 }
aoqi@0 1592 return false;
aoqi@0 1593 }
aoqi@0 1594 };
aoqi@0 1595
aoqi@0 1596 class ParKnownGarbageTask: public AbstractGangTask {
aoqi@0 1597 CollectionSetChooser* _hrSorted;
aoqi@0 1598 uint _chunk_size;
aoqi@0 1599 G1CollectedHeap* _g1;
aoqi@0 1600 public:
aoqi@0 1601 ParKnownGarbageTask(CollectionSetChooser* hrSorted, uint chunk_size) :
aoqi@0 1602 AbstractGangTask("ParKnownGarbageTask"),
aoqi@0 1603 _hrSorted(hrSorted), _chunk_size(chunk_size),
aoqi@0 1604 _g1(G1CollectedHeap::heap()) { }
aoqi@0 1605
aoqi@0 1606 void work(uint worker_id) {
aoqi@0 1607 ParKnownGarbageHRClosure parKnownGarbageCl(_hrSorted, _chunk_size);
aoqi@0 1608
aoqi@0 1609 // Back to zero for the claim value.
aoqi@0 1610 _g1->heap_region_par_iterate_chunked(&parKnownGarbageCl, worker_id,
aoqi@0 1611 _g1->workers()->active_workers(),
aoqi@0 1612 HeapRegion::InitialClaimValue);
aoqi@0 1613 }
aoqi@0 1614 };
aoqi@0 1615
aoqi@0 1616 void
aoqi@0 1617 G1CollectorPolicy::record_concurrent_mark_cleanup_end(int no_of_gc_threads) {
aoqi@0 1618 _collectionSetChooser->clear();
aoqi@0 1619
aoqi@0 1620 uint region_num = _g1->n_regions();
aoqi@0 1621 if (G1CollectedHeap::use_parallel_gc_threads()) {
aoqi@0 1622 const uint OverpartitionFactor = 4;
aoqi@0 1623 uint WorkUnit;
aoqi@0 1624 // The use of MinChunkSize = 8 in the original code
aoqi@0 1625 // causes some assertion failures when the total number of
aoqi@0 1626 // region is less than 8. The code here tries to fix that.
aoqi@0 1627 // Should the original code also be fixed?
aoqi@0 1628 if (no_of_gc_threads > 0) {
aoqi@0 1629 const uint MinWorkUnit = MAX2(region_num / no_of_gc_threads, 1U);
aoqi@0 1630 WorkUnit = MAX2(region_num / (no_of_gc_threads * OverpartitionFactor),
aoqi@0 1631 MinWorkUnit);
aoqi@0 1632 } else {
aoqi@0 1633 assert(no_of_gc_threads > 0,
aoqi@0 1634 "The active gc workers should be greater than 0");
aoqi@0 1635 // In a product build do something reasonable to avoid a crash.
aoqi@0 1636 const uint MinWorkUnit = MAX2(region_num / (uint) ParallelGCThreads, 1U);
aoqi@0 1637 WorkUnit =
aoqi@0 1638 MAX2(region_num / (uint) (ParallelGCThreads * OverpartitionFactor),
aoqi@0 1639 MinWorkUnit);
aoqi@0 1640 }
aoqi@0 1641 _collectionSetChooser->prepare_for_par_region_addition(_g1->n_regions(),
aoqi@0 1642 WorkUnit);
aoqi@0 1643 ParKnownGarbageTask parKnownGarbageTask(_collectionSetChooser,
aoqi@0 1644 (int) WorkUnit);
aoqi@0 1645 _g1->workers()->run_task(&parKnownGarbageTask);
aoqi@0 1646
aoqi@0 1647 assert(_g1->check_heap_region_claim_values(HeapRegion::InitialClaimValue),
aoqi@0 1648 "sanity check");
aoqi@0 1649 } else {
aoqi@0 1650 KnownGarbageClosure knownGarbagecl(_collectionSetChooser);
aoqi@0 1651 _g1->heap_region_iterate(&knownGarbagecl);
aoqi@0 1652 }
aoqi@0 1653
aoqi@0 1654 _collectionSetChooser->sort_regions();
aoqi@0 1655
aoqi@0 1656 double end_sec = os::elapsedTime();
aoqi@0 1657 double elapsed_time_ms = (end_sec - _mark_cleanup_start_sec) * 1000.0;
aoqi@0 1658 _concurrent_mark_cleanup_times_ms->add(elapsed_time_ms);
aoqi@0 1659 _cur_mark_stop_world_time_ms += elapsed_time_ms;
aoqi@0 1660 _prev_collection_pause_end_ms += elapsed_time_ms;
aoqi@0 1661 _mmu_tracker->add_pause(_mark_cleanup_start_sec, end_sec, true);
aoqi@0 1662 }
aoqi@0 1663
aoqi@0 1664 // Add the heap region at the head of the non-incremental collection set
aoqi@0 1665 void G1CollectorPolicy::add_old_region_to_cset(HeapRegion* hr) {
aoqi@0 1666 assert(_inc_cset_build_state == Active, "Precondition");
aoqi@0 1667 assert(!hr->is_young(), "non-incremental add of young region");
aoqi@0 1668
aoqi@0 1669 assert(!hr->in_collection_set(), "should not already be in the CSet");
aoqi@0 1670 hr->set_in_collection_set(true);
aoqi@0 1671 hr->set_next_in_collection_set(_collection_set);
aoqi@0 1672 _collection_set = hr;
aoqi@0 1673 _collection_set_bytes_used_before += hr->used();
aoqi@0 1674 _g1->register_region_with_in_cset_fast_test(hr);
aoqi@0 1675 size_t rs_length = hr->rem_set()->occupied();
aoqi@0 1676 _recorded_rs_lengths += rs_length;
aoqi@0 1677 _old_cset_region_length += 1;
aoqi@0 1678 }
aoqi@0 1679
aoqi@0 1680 // Initialize the per-collection-set information
aoqi@0 1681 void G1CollectorPolicy::start_incremental_cset_building() {
aoqi@0 1682 assert(_inc_cset_build_state == Inactive, "Precondition");
aoqi@0 1683
aoqi@0 1684 _inc_cset_head = NULL;
aoqi@0 1685 _inc_cset_tail = NULL;
aoqi@0 1686 _inc_cset_bytes_used_before = 0;
aoqi@0 1687
aoqi@0 1688 _inc_cset_max_finger = 0;
aoqi@0 1689 _inc_cset_recorded_rs_lengths = 0;
aoqi@0 1690 _inc_cset_recorded_rs_lengths_diffs = 0;
aoqi@0 1691 _inc_cset_predicted_elapsed_time_ms = 0.0;
aoqi@0 1692 _inc_cset_predicted_elapsed_time_ms_diffs = 0.0;
aoqi@0 1693 _inc_cset_build_state = Active;
aoqi@0 1694 }
aoqi@0 1695
aoqi@0 1696 void G1CollectorPolicy::finalize_incremental_cset_building() {
aoqi@0 1697 assert(_inc_cset_build_state == Active, "Precondition");
aoqi@0 1698 assert(SafepointSynchronize::is_at_safepoint(), "should be at a safepoint");
aoqi@0 1699
aoqi@0 1700 // The two "main" fields, _inc_cset_recorded_rs_lengths and
aoqi@0 1701 // _inc_cset_predicted_elapsed_time_ms, are updated by the thread
aoqi@0 1702 // that adds a new region to the CSet. Further updates by the
aoqi@0 1703 // concurrent refinement thread that samples the young RSet lengths
aoqi@0 1704 // are accumulated in the *_diffs fields. Here we add the diffs to
aoqi@0 1705 // the "main" fields.
aoqi@0 1706
aoqi@0 1707 if (_inc_cset_recorded_rs_lengths_diffs >= 0) {
aoqi@0 1708 _inc_cset_recorded_rs_lengths += _inc_cset_recorded_rs_lengths_diffs;
aoqi@0 1709 } else {
aoqi@0 1710 // This is defensive. The diff should in theory be always positive
aoqi@0 1711 // as RSets can only grow between GCs. However, given that we
aoqi@0 1712 // sample their size concurrently with other threads updating them
aoqi@0 1713 // it's possible that we might get the wrong size back, which
aoqi@0 1714 // could make the calculations somewhat inaccurate.
aoqi@0 1715 size_t diffs = (size_t) (-_inc_cset_recorded_rs_lengths_diffs);
aoqi@0 1716 if (_inc_cset_recorded_rs_lengths >= diffs) {
aoqi@0 1717 _inc_cset_recorded_rs_lengths -= diffs;
aoqi@0 1718 } else {
aoqi@0 1719 _inc_cset_recorded_rs_lengths = 0;
aoqi@0 1720 }
aoqi@0 1721 }
aoqi@0 1722 _inc_cset_predicted_elapsed_time_ms +=
aoqi@0 1723 _inc_cset_predicted_elapsed_time_ms_diffs;
aoqi@0 1724
aoqi@0 1725 _inc_cset_recorded_rs_lengths_diffs = 0;
aoqi@0 1726 _inc_cset_predicted_elapsed_time_ms_diffs = 0.0;
aoqi@0 1727 }
aoqi@0 1728
aoqi@0 1729 void G1CollectorPolicy::add_to_incremental_cset_info(HeapRegion* hr, size_t rs_length) {
aoqi@0 1730 // This routine is used when:
aoqi@0 1731 // * adding survivor regions to the incremental cset at the end of an
aoqi@0 1732 // evacuation pause,
aoqi@0 1733 // * adding the current allocation region to the incremental cset
aoqi@0 1734 // when it is retired, and
aoqi@0 1735 // * updating existing policy information for a region in the
aoqi@0 1736 // incremental cset via young list RSet sampling.
aoqi@0 1737 // Therefore this routine may be called at a safepoint by the
aoqi@0 1738 // VM thread, or in-between safepoints by mutator threads (when
aoqi@0 1739 // retiring the current allocation region) or a concurrent
aoqi@0 1740 // refine thread (RSet sampling).
aoqi@0 1741
aoqi@0 1742 double region_elapsed_time_ms = predict_region_elapsed_time_ms(hr, gcs_are_young());
aoqi@0 1743 size_t used_bytes = hr->used();
aoqi@0 1744 _inc_cset_recorded_rs_lengths += rs_length;
aoqi@0 1745 _inc_cset_predicted_elapsed_time_ms += region_elapsed_time_ms;
aoqi@0 1746 _inc_cset_bytes_used_before += used_bytes;
aoqi@0 1747
aoqi@0 1748 // Cache the values we have added to the aggregated informtion
aoqi@0 1749 // in the heap region in case we have to remove this region from
aoqi@0 1750 // the incremental collection set, or it is updated by the
aoqi@0 1751 // rset sampling code
aoqi@0 1752 hr->set_recorded_rs_length(rs_length);
aoqi@0 1753 hr->set_predicted_elapsed_time_ms(region_elapsed_time_ms);
aoqi@0 1754 }
aoqi@0 1755
aoqi@0 1756 void G1CollectorPolicy::update_incremental_cset_info(HeapRegion* hr,
aoqi@0 1757 size_t new_rs_length) {
aoqi@0 1758 // Update the CSet information that is dependent on the new RS length
aoqi@0 1759 assert(hr->is_young(), "Precondition");
aoqi@0 1760 assert(!SafepointSynchronize::is_at_safepoint(),
aoqi@0 1761 "should not be at a safepoint");
aoqi@0 1762
aoqi@0 1763 // We could have updated _inc_cset_recorded_rs_lengths and
aoqi@0 1764 // _inc_cset_predicted_elapsed_time_ms directly but we'd need to do
aoqi@0 1765 // that atomically, as this code is executed by a concurrent
aoqi@0 1766 // refinement thread, potentially concurrently with a mutator thread
aoqi@0 1767 // allocating a new region and also updating the same fields. To
aoqi@0 1768 // avoid the atomic operations we accumulate these updates on two
aoqi@0 1769 // separate fields (*_diffs) and we'll just add them to the "main"
aoqi@0 1770 // fields at the start of a GC.
aoqi@0 1771
aoqi@0 1772 ssize_t old_rs_length = (ssize_t) hr->recorded_rs_length();
aoqi@0 1773 ssize_t rs_lengths_diff = (ssize_t) new_rs_length - old_rs_length;
aoqi@0 1774 _inc_cset_recorded_rs_lengths_diffs += rs_lengths_diff;
aoqi@0 1775
aoqi@0 1776 double old_elapsed_time_ms = hr->predicted_elapsed_time_ms();
aoqi@0 1777 double new_region_elapsed_time_ms = predict_region_elapsed_time_ms(hr, gcs_are_young());
aoqi@0 1778 double elapsed_ms_diff = new_region_elapsed_time_ms - old_elapsed_time_ms;
aoqi@0 1779 _inc_cset_predicted_elapsed_time_ms_diffs += elapsed_ms_diff;
aoqi@0 1780
aoqi@0 1781 hr->set_recorded_rs_length(new_rs_length);
aoqi@0 1782 hr->set_predicted_elapsed_time_ms(new_region_elapsed_time_ms);
aoqi@0 1783 }
aoqi@0 1784
aoqi@0 1785 void G1CollectorPolicy::add_region_to_incremental_cset_common(HeapRegion* hr) {
aoqi@0 1786 assert(hr->is_young(), "invariant");
aoqi@0 1787 assert(hr->young_index_in_cset() > -1, "should have already been set");
aoqi@0 1788 assert(_inc_cset_build_state == Active, "Precondition");
aoqi@0 1789
aoqi@0 1790 // We need to clear and set the cached recorded/cached collection set
aoqi@0 1791 // information in the heap region here (before the region gets added
aoqi@0 1792 // to the collection set). An individual heap region's cached values
aoqi@0 1793 // are calculated, aggregated with the policy collection set info,
aoqi@0 1794 // and cached in the heap region here (initially) and (subsequently)
aoqi@0 1795 // by the Young List sampling code.
aoqi@0 1796
aoqi@0 1797 size_t rs_length = hr->rem_set()->occupied();
aoqi@0 1798 add_to_incremental_cset_info(hr, rs_length);
aoqi@0 1799
aoqi@0 1800 HeapWord* hr_end = hr->end();
aoqi@0 1801 _inc_cset_max_finger = MAX2(_inc_cset_max_finger, hr_end);
aoqi@0 1802
aoqi@0 1803 assert(!hr->in_collection_set(), "invariant");
aoqi@0 1804 hr->set_in_collection_set(true);
aoqi@0 1805 assert( hr->next_in_collection_set() == NULL, "invariant");
aoqi@0 1806
aoqi@0 1807 _g1->register_region_with_in_cset_fast_test(hr);
aoqi@0 1808 }
aoqi@0 1809
aoqi@0 1810 // Add the region at the RHS of the incremental cset
aoqi@0 1811 void G1CollectorPolicy::add_region_to_incremental_cset_rhs(HeapRegion* hr) {
aoqi@0 1812 // We should only ever be appending survivors at the end of a pause
aoqi@0 1813 assert( hr->is_survivor(), "Logic");
aoqi@0 1814
aoqi@0 1815 // Do the 'common' stuff
aoqi@0 1816 add_region_to_incremental_cset_common(hr);
aoqi@0 1817
aoqi@0 1818 // Now add the region at the right hand side
aoqi@0 1819 if (_inc_cset_tail == NULL) {
aoqi@0 1820 assert(_inc_cset_head == NULL, "invariant");
aoqi@0 1821 _inc_cset_head = hr;
aoqi@0 1822 } else {
aoqi@0 1823 _inc_cset_tail->set_next_in_collection_set(hr);
aoqi@0 1824 }
aoqi@0 1825 _inc_cset_tail = hr;
aoqi@0 1826 }
aoqi@0 1827
aoqi@0 1828 // Add the region to the LHS of the incremental cset
aoqi@0 1829 void G1CollectorPolicy::add_region_to_incremental_cset_lhs(HeapRegion* hr) {
aoqi@0 1830 // Survivors should be added to the RHS at the end of a pause
aoqi@0 1831 assert(!hr->is_survivor(), "Logic");
aoqi@0 1832
aoqi@0 1833 // Do the 'common' stuff
aoqi@0 1834 add_region_to_incremental_cset_common(hr);
aoqi@0 1835
aoqi@0 1836 // Add the region at the left hand side
aoqi@0 1837 hr->set_next_in_collection_set(_inc_cset_head);
aoqi@0 1838 if (_inc_cset_head == NULL) {
aoqi@0 1839 assert(_inc_cset_tail == NULL, "Invariant");
aoqi@0 1840 _inc_cset_tail = hr;
aoqi@0 1841 }
aoqi@0 1842 _inc_cset_head = hr;
aoqi@0 1843 }
aoqi@0 1844
aoqi@0 1845 #ifndef PRODUCT
aoqi@0 1846 void G1CollectorPolicy::print_collection_set(HeapRegion* list_head, outputStream* st) {
aoqi@0 1847 assert(list_head == inc_cset_head() || list_head == collection_set(), "must be");
aoqi@0 1848
aoqi@0 1849 st->print_cr("\nCollection_set:");
aoqi@0 1850 HeapRegion* csr = list_head;
aoqi@0 1851 while (csr != NULL) {
aoqi@0 1852 HeapRegion* next = csr->next_in_collection_set();
aoqi@0 1853 assert(csr->in_collection_set(), "bad CS");
aoqi@0 1854 st->print_cr(" "HR_FORMAT", P: "PTR_FORMAT "N: "PTR_FORMAT", age: %4d",
aoqi@0 1855 HR_FORMAT_PARAMS(csr),
aoqi@0 1856 csr->prev_top_at_mark_start(), csr->next_top_at_mark_start(),
aoqi@0 1857 csr->age_in_surv_rate_group_cond());
aoqi@0 1858 csr = next;
aoqi@0 1859 }
aoqi@0 1860 }
aoqi@0 1861 #endif // !PRODUCT
aoqi@0 1862
aoqi@0 1863 double G1CollectorPolicy::reclaimable_bytes_perc(size_t reclaimable_bytes) {
aoqi@0 1864 // Returns the given amount of reclaimable bytes (that represents
aoqi@0 1865 // the amount of reclaimable space still to be collected) as a
aoqi@0 1866 // percentage of the current heap capacity.
aoqi@0 1867 size_t capacity_bytes = _g1->capacity();
aoqi@0 1868 return (double) reclaimable_bytes * 100.0 / (double) capacity_bytes;
aoqi@0 1869 }
aoqi@0 1870
aoqi@0 1871 bool G1CollectorPolicy::next_gc_should_be_mixed(const char* true_action_str,
aoqi@0 1872 const char* false_action_str) {
aoqi@0 1873 CollectionSetChooser* cset_chooser = _collectionSetChooser;
aoqi@0 1874 if (cset_chooser->is_empty()) {
aoqi@0 1875 ergo_verbose0(ErgoMixedGCs,
aoqi@0 1876 false_action_str,
aoqi@0 1877 ergo_format_reason("candidate old regions not available"));
aoqi@0 1878 return false;
aoqi@0 1879 }
aoqi@0 1880
aoqi@0 1881 // Is the amount of uncollected reclaimable space above G1HeapWastePercent?
aoqi@0 1882 size_t reclaimable_bytes = cset_chooser->remaining_reclaimable_bytes();
aoqi@0 1883 double reclaimable_perc = reclaimable_bytes_perc(reclaimable_bytes);
aoqi@0 1884 double threshold = (double) G1HeapWastePercent;
aoqi@0 1885 if (reclaimable_perc <= threshold) {
aoqi@0 1886 ergo_verbose4(ErgoMixedGCs,
aoqi@0 1887 false_action_str,
aoqi@0 1888 ergo_format_reason("reclaimable percentage not over threshold")
aoqi@0 1889 ergo_format_region("candidate old regions")
aoqi@0 1890 ergo_format_byte_perc("reclaimable")
aoqi@0 1891 ergo_format_perc("threshold"),
aoqi@0 1892 cset_chooser->remaining_regions(),
aoqi@0 1893 reclaimable_bytes,
aoqi@0 1894 reclaimable_perc, threshold);
aoqi@0 1895 return false;
aoqi@0 1896 }
aoqi@0 1897
aoqi@0 1898 ergo_verbose4(ErgoMixedGCs,
aoqi@0 1899 true_action_str,
aoqi@0 1900 ergo_format_reason("candidate old regions available")
aoqi@0 1901 ergo_format_region("candidate old regions")
aoqi@0 1902 ergo_format_byte_perc("reclaimable")
aoqi@0 1903 ergo_format_perc("threshold"),
aoqi@0 1904 cset_chooser->remaining_regions(),
aoqi@0 1905 reclaimable_bytes,
aoqi@0 1906 reclaimable_perc, threshold);
aoqi@0 1907 return true;
aoqi@0 1908 }
aoqi@0 1909
aoqi@0 1910 uint G1CollectorPolicy::calc_min_old_cset_length() {
aoqi@0 1911 // The min old CSet region bound is based on the maximum desired
aoqi@0 1912 // number of mixed GCs after a cycle. I.e., even if some old regions
aoqi@0 1913 // look expensive, we should add them to the CSet anyway to make
aoqi@0 1914 // sure we go through the available old regions in no more than the
aoqi@0 1915 // maximum desired number of mixed GCs.
aoqi@0 1916 //
aoqi@0 1917 // The calculation is based on the number of marked regions we added
aoqi@0 1918 // to the CSet chooser in the first place, not how many remain, so
aoqi@0 1919 // that the result is the same during all mixed GCs that follow a cycle.
aoqi@0 1920
aoqi@0 1921 const size_t region_num = (size_t) _collectionSetChooser->length();
aoqi@0 1922 const size_t gc_num = (size_t) MAX2(G1MixedGCCountTarget, (uintx) 1);
aoqi@0 1923 size_t result = region_num / gc_num;
aoqi@0 1924 // emulate ceiling
aoqi@0 1925 if (result * gc_num < region_num) {
aoqi@0 1926 result += 1;
aoqi@0 1927 }
aoqi@0 1928 return (uint) result;
aoqi@0 1929 }
aoqi@0 1930
aoqi@0 1931 uint G1CollectorPolicy::calc_max_old_cset_length() {
aoqi@0 1932 // The max old CSet region bound is based on the threshold expressed
aoqi@0 1933 // as a percentage of the heap size. I.e., it should bound the
aoqi@0 1934 // number of old regions added to the CSet irrespective of how many
aoqi@0 1935 // of them are available.
aoqi@0 1936
aoqi@0 1937 G1CollectedHeap* g1h = G1CollectedHeap::heap();
aoqi@0 1938 const size_t region_num = g1h->n_regions();
aoqi@0 1939 const size_t perc = (size_t) G1OldCSetRegionThresholdPercent;
aoqi@0 1940 size_t result = region_num * perc / 100;
aoqi@0 1941 // emulate ceiling
aoqi@0 1942 if (100 * result < region_num * perc) {
aoqi@0 1943 result += 1;
aoqi@0 1944 }
aoqi@0 1945 return (uint) result;
aoqi@0 1946 }
aoqi@0 1947
aoqi@0 1948
aoqi@0 1949 void G1CollectorPolicy::finalize_cset(double target_pause_time_ms, EvacuationInfo& evacuation_info) {
aoqi@0 1950 double young_start_time_sec = os::elapsedTime();
aoqi@0 1951
aoqi@0 1952 YoungList* young_list = _g1->young_list();
aoqi@0 1953 finalize_incremental_cset_building();
aoqi@0 1954
aoqi@0 1955 guarantee(target_pause_time_ms > 0.0,
aoqi@0 1956 err_msg("target_pause_time_ms = %1.6lf should be positive",
aoqi@0 1957 target_pause_time_ms));
aoqi@0 1958 guarantee(_collection_set == NULL, "Precondition");
aoqi@0 1959
aoqi@0 1960 double base_time_ms = predict_base_elapsed_time_ms(_pending_cards);
aoqi@0 1961 double predicted_pause_time_ms = base_time_ms;
aoqi@0 1962 double time_remaining_ms = MAX2(target_pause_time_ms - base_time_ms, 0.0);
aoqi@0 1963
aoqi@0 1964 ergo_verbose4(ErgoCSetConstruction | ErgoHigh,
aoqi@0 1965 "start choosing CSet",
aoqi@0 1966 ergo_format_size("_pending_cards")
aoqi@0 1967 ergo_format_ms("predicted base time")
aoqi@0 1968 ergo_format_ms("remaining time")
aoqi@0 1969 ergo_format_ms("target pause time"),
aoqi@0 1970 _pending_cards, base_time_ms, time_remaining_ms, target_pause_time_ms);
aoqi@0 1971
aoqi@0 1972 _last_gc_was_young = gcs_are_young() ? true : false;
aoqi@0 1973
aoqi@0 1974 if (_last_gc_was_young) {
aoqi@0 1975 _trace_gen0_time_data.increment_young_collection_count();
aoqi@0 1976 } else {
aoqi@0 1977 _trace_gen0_time_data.increment_mixed_collection_count();
aoqi@0 1978 }
aoqi@0 1979
aoqi@0 1980 // The young list is laid with the survivor regions from the previous
aoqi@0 1981 // pause are appended to the RHS of the young list, i.e.
aoqi@0 1982 // [Newly Young Regions ++ Survivors from last pause].
aoqi@0 1983
aoqi@0 1984 uint survivor_region_length = young_list->survivor_length();
aoqi@0 1985 uint eden_region_length = young_list->length() - survivor_region_length;
aoqi@0 1986 init_cset_region_lengths(eden_region_length, survivor_region_length);
aoqi@0 1987
aoqi@0 1988 HeapRegion* hr = young_list->first_survivor_region();
aoqi@0 1989 while (hr != NULL) {
aoqi@0 1990 assert(hr->is_survivor(), "badly formed young list");
aoqi@0 1991 hr->set_young();
aoqi@0 1992 hr = hr->get_next_young_region();
aoqi@0 1993 }
aoqi@0 1994
aoqi@0 1995 // Clear the fields that point to the survivor list - they are all young now.
aoqi@0 1996 young_list->clear_survivors();
aoqi@0 1997
aoqi@0 1998 _collection_set = _inc_cset_head;
aoqi@0 1999 _collection_set_bytes_used_before = _inc_cset_bytes_used_before;
aoqi@0 2000 time_remaining_ms = MAX2(time_remaining_ms - _inc_cset_predicted_elapsed_time_ms, 0.0);
aoqi@0 2001 predicted_pause_time_ms += _inc_cset_predicted_elapsed_time_ms;
aoqi@0 2002
aoqi@0 2003 ergo_verbose3(ErgoCSetConstruction | ErgoHigh,
aoqi@0 2004 "add young regions to CSet",
aoqi@0 2005 ergo_format_region("eden")
aoqi@0 2006 ergo_format_region("survivors")
aoqi@0 2007 ergo_format_ms("predicted young region time"),
aoqi@0 2008 eden_region_length, survivor_region_length,
aoqi@0 2009 _inc_cset_predicted_elapsed_time_ms);
aoqi@0 2010
aoqi@0 2011 // The number of recorded young regions is the incremental
aoqi@0 2012 // collection set's current size
aoqi@0 2013 set_recorded_rs_lengths(_inc_cset_recorded_rs_lengths);
aoqi@0 2014
aoqi@0 2015 double young_end_time_sec = os::elapsedTime();
aoqi@0 2016 phase_times()->record_young_cset_choice_time_ms((young_end_time_sec - young_start_time_sec) * 1000.0);
aoqi@0 2017
aoqi@0 2018 // Set the start of the non-young choice time.
aoqi@0 2019 double non_young_start_time_sec = young_end_time_sec;
aoqi@0 2020
aoqi@0 2021 if (!gcs_are_young()) {
aoqi@0 2022 CollectionSetChooser* cset_chooser = _collectionSetChooser;
aoqi@0 2023 cset_chooser->verify();
aoqi@0 2024 const uint min_old_cset_length = calc_min_old_cset_length();
aoqi@0 2025 const uint max_old_cset_length = calc_max_old_cset_length();
aoqi@0 2026
aoqi@0 2027 uint expensive_region_num = 0;
aoqi@0 2028 bool check_time_remaining = adaptive_young_list_length();
aoqi@0 2029
aoqi@0 2030 HeapRegion* hr = cset_chooser->peek();
aoqi@0 2031 while (hr != NULL) {
aoqi@0 2032 if (old_cset_region_length() >= max_old_cset_length) {
aoqi@0 2033 // Added maximum number of old regions to the CSet.
aoqi@0 2034 ergo_verbose2(ErgoCSetConstruction,
aoqi@0 2035 "finish adding old regions to CSet",
aoqi@0 2036 ergo_format_reason("old CSet region num reached max")
aoqi@0 2037 ergo_format_region("old")
aoqi@0 2038 ergo_format_region("max"),
aoqi@0 2039 old_cset_region_length(), max_old_cset_length);
aoqi@0 2040 break;
aoqi@0 2041 }
aoqi@0 2042
aoqi@0 2043
aoqi@0 2044 // Stop adding regions if the remaining reclaimable space is
aoqi@0 2045 // not above G1HeapWastePercent.
aoqi@0 2046 size_t reclaimable_bytes = cset_chooser->remaining_reclaimable_bytes();
aoqi@0 2047 double reclaimable_perc = reclaimable_bytes_perc(reclaimable_bytes);
aoqi@0 2048 double threshold = (double) G1HeapWastePercent;
aoqi@0 2049 if (reclaimable_perc <= threshold) {
aoqi@0 2050 // We've added enough old regions that the amount of uncollected
aoqi@0 2051 // reclaimable space is at or below the waste threshold. Stop
aoqi@0 2052 // adding old regions to the CSet.
aoqi@0 2053 ergo_verbose5(ErgoCSetConstruction,
aoqi@0 2054 "finish adding old regions to CSet",
aoqi@0 2055 ergo_format_reason("reclaimable percentage not over threshold")
aoqi@0 2056 ergo_format_region("old")
aoqi@0 2057 ergo_format_region("max")
aoqi@0 2058 ergo_format_byte_perc("reclaimable")
aoqi@0 2059 ergo_format_perc("threshold"),
aoqi@0 2060 old_cset_region_length(),
aoqi@0 2061 max_old_cset_length,
aoqi@0 2062 reclaimable_bytes,
aoqi@0 2063 reclaimable_perc, threshold);
aoqi@0 2064 break;
aoqi@0 2065 }
aoqi@0 2066
aoqi@0 2067 double predicted_time_ms = predict_region_elapsed_time_ms(hr, gcs_are_young());
aoqi@0 2068 if (check_time_remaining) {
aoqi@0 2069 if (predicted_time_ms > time_remaining_ms) {
aoqi@0 2070 // Too expensive for the current CSet.
aoqi@0 2071
aoqi@0 2072 if (old_cset_region_length() >= min_old_cset_length) {
aoqi@0 2073 // We have added the minimum number of old regions to the CSet,
aoqi@0 2074 // we are done with this CSet.
aoqi@0 2075 ergo_verbose4(ErgoCSetConstruction,
aoqi@0 2076 "finish adding old regions to CSet",
aoqi@0 2077 ergo_format_reason("predicted time is too high")
aoqi@0 2078 ergo_format_ms("predicted time")
aoqi@0 2079 ergo_format_ms("remaining time")
aoqi@0 2080 ergo_format_region("old")
aoqi@0 2081 ergo_format_region("min"),
aoqi@0 2082 predicted_time_ms, time_remaining_ms,
aoqi@0 2083 old_cset_region_length(), min_old_cset_length);
aoqi@0 2084 break;
aoqi@0 2085 }
aoqi@0 2086
aoqi@0 2087 // We'll add it anyway given that we haven't reached the
aoqi@0 2088 // minimum number of old regions.
aoqi@0 2089 expensive_region_num += 1;
aoqi@0 2090 }
aoqi@0 2091 } else {
aoqi@0 2092 if (old_cset_region_length() >= min_old_cset_length) {
aoqi@0 2093 // In the non-auto-tuning case, we'll finish adding regions
aoqi@0 2094 // to the CSet if we reach the minimum.
aoqi@0 2095 ergo_verbose2(ErgoCSetConstruction,
aoqi@0 2096 "finish adding old regions to CSet",
aoqi@0 2097 ergo_format_reason("old CSet region num reached min")
aoqi@0 2098 ergo_format_region("old")
aoqi@0 2099 ergo_format_region("min"),
aoqi@0 2100 old_cset_region_length(), min_old_cset_length);
aoqi@0 2101 break;
aoqi@0 2102 }
aoqi@0 2103 }
aoqi@0 2104
aoqi@0 2105 // We will add this region to the CSet.
aoqi@0 2106 time_remaining_ms = MAX2(time_remaining_ms - predicted_time_ms, 0.0);
aoqi@0 2107 predicted_pause_time_ms += predicted_time_ms;
aoqi@0 2108 cset_chooser->remove_and_move_to_next(hr);
aoqi@0 2109 _g1->old_set_remove(hr);
aoqi@0 2110 add_old_region_to_cset(hr);
aoqi@0 2111
aoqi@0 2112 hr = cset_chooser->peek();
aoqi@0 2113 }
aoqi@0 2114 if (hr == NULL) {
aoqi@0 2115 ergo_verbose0(ErgoCSetConstruction,
aoqi@0 2116 "finish adding old regions to CSet",
aoqi@0 2117 ergo_format_reason("candidate old regions not available"));
aoqi@0 2118 }
aoqi@0 2119
aoqi@0 2120 if (expensive_region_num > 0) {
aoqi@0 2121 // We print the information once here at the end, predicated on
aoqi@0 2122 // whether we added any apparently expensive regions or not, to
aoqi@0 2123 // avoid generating output per region.
aoqi@0 2124 ergo_verbose4(ErgoCSetConstruction,
aoqi@0 2125 "added expensive regions to CSet",
aoqi@0 2126 ergo_format_reason("old CSet region num not reached min")
aoqi@0 2127 ergo_format_region("old")
aoqi@0 2128 ergo_format_region("expensive")
aoqi@0 2129 ergo_format_region("min")
aoqi@0 2130 ergo_format_ms("remaining time"),
aoqi@0 2131 old_cset_region_length(),
aoqi@0 2132 expensive_region_num,
aoqi@0 2133 min_old_cset_length,
aoqi@0 2134 time_remaining_ms);
aoqi@0 2135 }
aoqi@0 2136
aoqi@0 2137 cset_chooser->verify();
aoqi@0 2138 }
aoqi@0 2139
aoqi@0 2140 stop_incremental_cset_building();
aoqi@0 2141
aoqi@0 2142 ergo_verbose5(ErgoCSetConstruction,
aoqi@0 2143 "finish choosing CSet",
aoqi@0 2144 ergo_format_region("eden")
aoqi@0 2145 ergo_format_region("survivors")
aoqi@0 2146 ergo_format_region("old")
aoqi@0 2147 ergo_format_ms("predicted pause time")
aoqi@0 2148 ergo_format_ms("target pause time"),
aoqi@0 2149 eden_region_length, survivor_region_length,
aoqi@0 2150 old_cset_region_length(),
aoqi@0 2151 predicted_pause_time_ms, target_pause_time_ms);
aoqi@0 2152
aoqi@0 2153 double non_young_end_time_sec = os::elapsedTime();
aoqi@0 2154 phase_times()->record_non_young_cset_choice_time_ms((non_young_end_time_sec - non_young_start_time_sec) * 1000.0);
aoqi@0 2155 evacuation_info.set_collectionset_regions(cset_region_length());
aoqi@0 2156 }
aoqi@0 2157
aoqi@0 2158 void TraceGen0TimeData::record_start_collection(double time_to_stop_the_world_ms) {
aoqi@0 2159 if(TraceGen0Time) {
aoqi@0 2160 _all_stop_world_times_ms.add(time_to_stop_the_world_ms);
aoqi@0 2161 }
aoqi@0 2162 }
aoqi@0 2163
aoqi@0 2164 void TraceGen0TimeData::record_yield_time(double yield_time_ms) {
aoqi@0 2165 if(TraceGen0Time) {
aoqi@0 2166 _all_yield_times_ms.add(yield_time_ms);
aoqi@0 2167 }
aoqi@0 2168 }
aoqi@0 2169
aoqi@0 2170 void TraceGen0TimeData::record_end_collection(double pause_time_ms, G1GCPhaseTimes* phase_times) {
aoqi@0 2171 if(TraceGen0Time) {
aoqi@0 2172 _total.add(pause_time_ms);
aoqi@0 2173 _other.add(pause_time_ms - phase_times->accounted_time_ms());
aoqi@0 2174 _root_region_scan_wait.add(phase_times->root_region_scan_wait_time_ms());
aoqi@0 2175 _parallel.add(phase_times->cur_collection_par_time_ms());
aoqi@0 2176 _ext_root_scan.add(phase_times->average_last_ext_root_scan_time());
aoqi@0 2177 _satb_filtering.add(phase_times->average_last_satb_filtering_times_ms());
aoqi@0 2178 _update_rs.add(phase_times->average_last_update_rs_time());
aoqi@0 2179 _scan_rs.add(phase_times->average_last_scan_rs_time());
aoqi@0 2180 _obj_copy.add(phase_times->average_last_obj_copy_time());
aoqi@0 2181 _termination.add(phase_times->average_last_termination_time());
aoqi@0 2182
aoqi@0 2183 double parallel_known_time = phase_times->average_last_ext_root_scan_time() +
aoqi@0 2184 phase_times->average_last_satb_filtering_times_ms() +
aoqi@0 2185 phase_times->average_last_update_rs_time() +
aoqi@0 2186 phase_times->average_last_scan_rs_time() +
aoqi@0 2187 phase_times->average_last_obj_copy_time() +
aoqi@0 2188 + phase_times->average_last_termination_time();
aoqi@0 2189
aoqi@0 2190 double parallel_other_time = phase_times->cur_collection_par_time_ms() - parallel_known_time;
aoqi@0 2191 _parallel_other.add(parallel_other_time);
aoqi@0 2192 _clear_ct.add(phase_times->cur_clear_ct_time_ms());
aoqi@0 2193 }
aoqi@0 2194 }
aoqi@0 2195
aoqi@0 2196 void TraceGen0TimeData::increment_young_collection_count() {
aoqi@0 2197 if(TraceGen0Time) {
aoqi@0 2198 ++_young_pause_num;
aoqi@0 2199 }
aoqi@0 2200 }
aoqi@0 2201
aoqi@0 2202 void TraceGen0TimeData::increment_mixed_collection_count() {
aoqi@0 2203 if(TraceGen0Time) {
aoqi@0 2204 ++_mixed_pause_num;
aoqi@0 2205 }
aoqi@0 2206 }
aoqi@0 2207
aoqi@0 2208 void TraceGen0TimeData::print_summary(const char* str,
aoqi@0 2209 const NumberSeq* seq) const {
aoqi@0 2210 double sum = seq->sum();
aoqi@0 2211 gclog_or_tty->print_cr("%-27s = %8.2lf s (avg = %8.2lf ms)",
aoqi@0 2212 str, sum / 1000.0, seq->avg());
aoqi@0 2213 }
aoqi@0 2214
aoqi@0 2215 void TraceGen0TimeData::print_summary_sd(const char* str,
aoqi@0 2216 const NumberSeq* seq) const {
aoqi@0 2217 print_summary(str, seq);
aoqi@0 2218 gclog_or_tty->print_cr("%+45s = %5d, std dev = %8.2lf ms, max = %8.2lf ms)",
aoqi@0 2219 "(num", seq->num(), seq->sd(), seq->maximum());
aoqi@0 2220 }
aoqi@0 2221
aoqi@0 2222 void TraceGen0TimeData::print() const {
aoqi@0 2223 if (!TraceGen0Time) {
aoqi@0 2224 return;
aoqi@0 2225 }
aoqi@0 2226
aoqi@0 2227 gclog_or_tty->print_cr("ALL PAUSES");
aoqi@0 2228 print_summary_sd(" Total", &_total);
aoqi@0 2229 gclog_or_tty->cr();
aoqi@0 2230 gclog_or_tty->cr();
aoqi@0 2231 gclog_or_tty->print_cr(" Young GC Pauses: %8d", _young_pause_num);
aoqi@0 2232 gclog_or_tty->print_cr(" Mixed GC Pauses: %8d", _mixed_pause_num);
aoqi@0 2233 gclog_or_tty->cr();
aoqi@0 2234
aoqi@0 2235 gclog_or_tty->print_cr("EVACUATION PAUSES");
aoqi@0 2236
aoqi@0 2237 if (_young_pause_num == 0 && _mixed_pause_num == 0) {
aoqi@0 2238 gclog_or_tty->print_cr("none");
aoqi@0 2239 } else {
aoqi@0 2240 print_summary_sd(" Evacuation Pauses", &_total);
aoqi@0 2241 print_summary(" Root Region Scan Wait", &_root_region_scan_wait);
aoqi@0 2242 print_summary(" Parallel Time", &_parallel);
aoqi@0 2243 print_summary(" Ext Root Scanning", &_ext_root_scan);
aoqi@0 2244 print_summary(" SATB Filtering", &_satb_filtering);
aoqi@0 2245 print_summary(" Update RS", &_update_rs);
aoqi@0 2246 print_summary(" Scan RS", &_scan_rs);
aoqi@0 2247 print_summary(" Object Copy", &_obj_copy);
aoqi@0 2248 print_summary(" Termination", &_termination);
aoqi@0 2249 print_summary(" Parallel Other", &_parallel_other);
aoqi@0 2250 print_summary(" Clear CT", &_clear_ct);
aoqi@0 2251 print_summary(" Other", &_other);
aoqi@0 2252 }
aoqi@0 2253 gclog_or_tty->cr();
aoqi@0 2254
aoqi@0 2255 gclog_or_tty->print_cr("MISC");
aoqi@0 2256 print_summary_sd(" Stop World", &_all_stop_world_times_ms);
aoqi@0 2257 print_summary_sd(" Yields", &_all_yield_times_ms);
aoqi@0 2258 }
aoqi@0 2259
aoqi@0 2260 void TraceGen1TimeData::record_full_collection(double full_gc_time_ms) {
aoqi@0 2261 if (TraceGen1Time) {
aoqi@0 2262 _all_full_gc_times.add(full_gc_time_ms);
aoqi@0 2263 }
aoqi@0 2264 }
aoqi@0 2265
aoqi@0 2266 void TraceGen1TimeData::print() const {
aoqi@0 2267 if (!TraceGen1Time) {
aoqi@0 2268 return;
aoqi@0 2269 }
aoqi@0 2270
aoqi@0 2271 if (_all_full_gc_times.num() > 0) {
aoqi@0 2272 gclog_or_tty->print("\n%4d full_gcs: total time = %8.2f s",
aoqi@0 2273 _all_full_gc_times.num(),
aoqi@0 2274 _all_full_gc_times.sum() / 1000.0);
aoqi@0 2275 gclog_or_tty->print_cr(" (avg = %8.2fms).", _all_full_gc_times.avg());
aoqi@0 2276 gclog_or_tty->print_cr(" [std. dev = %8.2f ms, max = %8.2f ms]",
aoqi@0 2277 _all_full_gc_times.sd(),
aoqi@0 2278 _all_full_gc_times.maximum());
aoqi@0 2279 }
aoqi@0 2280 }

mercurial