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