src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/gc_implementation/g1

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

Print this page




 296   // update_young_list_target_length() during initialization.
 297   _max_survivor_regions = 0;
 298 
 299   assert(GCTimeRatio > 0,
 300          "we should have set it to a default value set_g1_gc_flags() "
 301          "if a user set it to 0");
 302   _gc_overhead_perc = 100.0 * (1.0 / (1.0 + GCTimeRatio));
 303 
 304   uintx reserve_perc = G1ReservePercent;
 305   // Put an artificial ceiling on this so that it's not set to a silly value.
 306   if (reserve_perc > 50) {
 307     reserve_perc = 50;
 308     warning("G1ReservePercent is set to a value that is too large, "
 309             "it's been updated to %u", reserve_perc);
 310   }
 311   _reserve_factor = (double) reserve_perc / 100.0;
 312   // This will be set when the heap is expanded
 313   // for the first time during initialization.
 314   _reserve_regions = 0;
 315 
 316   initialize_all();
 317   _collectionSetChooser = new CollectionSetChooser();
 318   _young_gen_sizer = new G1YoungGenSizer(); // Must be after call to initialize_flags
 319 }
 320 
 321 void G1CollectorPolicy::initialize_flags() {
 322   _min_alignment = HeapRegion::GrainBytes;
 323   size_t card_table_alignment = GenRemSet::max_alignment_constraint(GenRemSet::CardTable);
 324   size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
 325   _max_alignment = MAX3(card_table_alignment, _min_alignment, page_size);







 326   if (SurvivorRatio < 1) {
 327     vm_exit_during_initialization("Invalid survivor ratio specified");
 328   }
 329   CollectorPolicy::initialize_flags();

 330 }
 331 
 332 G1YoungGenSizer::G1YoungGenSizer() : _sizer_kind(SizerDefaults), _adaptive_size(true) {
 333   assert(G1NewSizePercent <= G1MaxNewSizePercent, "Min larger than max");
 334   assert(G1NewSizePercent > 0 && G1NewSizePercent < 100, "Min out of bounds");
 335   assert(G1MaxNewSizePercent > 0 && G1MaxNewSizePercent < 100, "Max out of bounds");



 336 


 337   if (FLAG_IS_CMDLINE(NewRatio)) {
 338     if (FLAG_IS_CMDLINE(NewSize) || FLAG_IS_CMDLINE(MaxNewSize)) {
 339       warning("-XX:NewSize and -XX:MaxNewSize override -XX:NewRatio");
 340     } else {
 341       _sizer_kind = SizerNewRatio;
 342       _adaptive_size = false;
 343       return;
 344     }
 345   }
 346 
 347   if (FLAG_IS_CMDLINE(NewSize) && FLAG_IS_CMDLINE(MaxNewSize) && NewSize > MaxNewSize) {
 348     vm_exit_during_initialization("Initial young gen size set larger than the maximum young gen size");





 349   }
 350 
 351   if (FLAG_IS_CMDLINE(NewSize)) {
 352     _min_desired_young_length = MAX2((uint) (NewSize / HeapRegion::GrainBytes),
 353                                      1U);
 354     if (FLAG_IS_CMDLINE(MaxNewSize)) {
 355       _max_desired_young_length =
 356                              MAX2((uint) (MaxNewSize / HeapRegion::GrainBytes),
 357                                   1U);
 358       _sizer_kind = SizerMaxAndNewSize;
 359       _adaptive_size = _min_desired_young_length == _max_desired_young_length;
 360     } else {
 361       _sizer_kind = SizerNewSizeOnly;
 362     }
 363   } else if (FLAG_IS_CMDLINE(MaxNewSize)) {
 364     _max_desired_young_length =
 365                              MAX2((uint) (MaxNewSize / HeapRegion::GrainBytes),
 366                                   1U);
 367     _sizer_kind = SizerMaxNewSizeOnly;
 368   }
 369 }
 370 
 371 uint G1YoungGenSizer::calculate_default_min_length(uint new_number_of_heap_regions) {
 372   uint default_value = (new_number_of_heap_regions * G1NewSizePercent) / 100;
 373   return MAX2(1U, default_value);
 374 }
 375 
 376 uint G1YoungGenSizer::calculate_default_max_length(uint new_number_of_heap_regions) {
 377   uint default_value = (new_number_of_heap_regions * G1MaxNewSizePercent) / 100;
 378   return MAX2(1U, default_value);
 379 }
 380 
 381 void G1YoungGenSizer::heap_size_changed(uint new_number_of_heap_regions) {
 382   assert(new_number_of_heap_regions > 0, "Heap must be initialized");
 383 
 384   switch (_sizer_kind) {
 385     case SizerDefaults:
 386       _min_desired_young_length = calculate_default_min_length(new_number_of_heap_regions);
 387       _max_desired_young_length = calculate_default_max_length(new_number_of_heap_regions);
 388       break;
 389     case SizerNewSizeOnly:
 390       _max_desired_young_length = calculate_default_max_length(new_number_of_heap_regions);
 391       _max_desired_young_length = MAX2(_min_desired_young_length, _max_desired_young_length);
 392       break;
 393     case SizerMaxNewSizeOnly:
 394       _min_desired_young_length = calculate_default_min_length(new_number_of_heap_regions);
 395       _min_desired_young_length = MIN2(_min_desired_young_length, _max_desired_young_length);
 396       break;
 397     case SizerMaxAndNewSize:
 398       // Do nothing. Values set on the command line, don't update them at runtime.
 399       break;
 400     case SizerNewRatio:
 401       _min_desired_young_length = new_number_of_heap_regions / (NewRatio + 1);
 402       _max_desired_young_length = _min_desired_young_length;
 403       break;
 404     default:
 405       ShouldNotReachHere();
 406   }
 407 
 408   assert(_min_desired_young_length <= _max_desired_young_length, "Invalid min/max young gen size values");














 409 }
 410 
 411 void G1CollectorPolicy::init() {
 412   // Set aside an initial future to_space.
 413   _g1 = G1CollectedHeap::heap();
 414 
 415   assert(Heap_lock->owned_by_self(), "Locking discipline.");
 416 
 417   initialize_gc_policy_counters();
 418 
 419   if (adaptive_young_list_length()) {
 420     _young_list_fixed_length = 0;
 421   } else {
 422     _young_list_fixed_length = _young_gen_sizer->min_desired_young_length();
 423   }
 424   _free_regions_at_end_of_collection = _g1->free_regions();
 425   update_young_list_target_length();
 426 
 427   // We may immediately start allocating regions and placing them on the
 428   // collection set list. Initialize the per-collection set info




 296   // update_young_list_target_length() during initialization.
 297   _max_survivor_regions = 0;
 298 
 299   assert(GCTimeRatio > 0,
 300          "we should have set it to a default value set_g1_gc_flags() "
 301          "if a user set it to 0");
 302   _gc_overhead_perc = 100.0 * (1.0 / (1.0 + GCTimeRatio));
 303 
 304   uintx reserve_perc = G1ReservePercent;
 305   // Put an artificial ceiling on this so that it's not set to a silly value.
 306   if (reserve_perc > 50) {
 307     reserve_perc = 50;
 308     warning("G1ReservePercent is set to a value that is too large, "
 309             "it's been updated to %u", reserve_perc);
 310   }
 311   _reserve_factor = (double) reserve_perc / 100.0;
 312   // This will be set when the heap is expanded
 313   // for the first time during initialization.
 314   _reserve_regions = 0;
 315 

 316   _collectionSetChooser = new CollectionSetChooser();

 317 }
 318 
 319 void G1CollectorPolicy::initialize_alignments() {
 320   _space_alignment = HeapRegion::GrainBytes;
 321   size_t card_table_alignment = GenRemSet::max_alignment_constraint(GenRemSet::CardTable);
 322   size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
 323   _heap_alignment = MAX3(card_table_alignment, _space_alignment, page_size);
 324 }
 325 
 326 void G1CollectorPolicy::initialize_flags() {
 327   if (G1HeapRegionSize != HeapRegion::GrainBytes) {
 328     FLAG_SET_ERGO(uintx, G1HeapRegionSize, HeapRegion::GrainBytes);
 329   }
 330 
 331   if (SurvivorRatio < 1) {
 332     vm_exit_during_initialization("Invalid survivor ratio specified");
 333   }
 334   CollectorPolicy::initialize_flags();
 335   _young_gen_sizer = new G1YoungGenSizer(); // Must be after call to initialize_flags
 336 }
 337 
 338 void G1CollectorPolicy::post_heap_initialize() {
 339   uintx max_regions = G1CollectedHeap::heap()->max_regions();
 340   size_t max_young_size = (size_t)_young_gen_sizer->max_young_length(max_regions) * HeapRegion::GrainBytes;
 341   if (max_young_size != MaxNewSize) {
 342     FLAG_SET_ERGO(uintx, MaxNewSize, max_young_size);
 343   }
 344 }
 345 
 346 G1YoungGenSizer::G1YoungGenSizer() : _sizer_kind(SizerDefaults), _adaptive_size(true),
 347         _min_desired_young_length(0), _max_desired_young_length(0) {
 348   if (FLAG_IS_CMDLINE(NewRatio)) {
 349     if (FLAG_IS_CMDLINE(NewSize) || FLAG_IS_CMDLINE(MaxNewSize)) {
 350       warning("-XX:NewSize and -XX:MaxNewSize override -XX:NewRatio");
 351     } else {
 352       _sizer_kind = SizerNewRatio;
 353       _adaptive_size = false;
 354       return;
 355     }
 356   }
 357 
 358   if (NewSize > MaxNewSize) {
 359     if (FLAG_IS_CMDLINE(MaxNewSize)) {
 360       warning("NewSize (" SIZE_FORMAT "k) is greater than the MaxNewSize (" SIZE_FORMAT "k). "
 361               "A new max generation size of " SIZE_FORMAT "k will be used.",
 362               NewSize/K, MaxNewSize/K, NewSize/K);
 363     }
 364     MaxNewSize = NewSize;
 365   }
 366 
 367   if (FLAG_IS_CMDLINE(NewSize)) {
 368     _min_desired_young_length = MAX2((uint) (NewSize / HeapRegion::GrainBytes),
 369                                      1U);
 370     if (FLAG_IS_CMDLINE(MaxNewSize)) {
 371       _max_desired_young_length =
 372                              MAX2((uint) (MaxNewSize / HeapRegion::GrainBytes),
 373                                   1U);
 374       _sizer_kind = SizerMaxAndNewSize;
 375       _adaptive_size = _min_desired_young_length == _max_desired_young_length;
 376     } else {
 377       _sizer_kind = SizerNewSizeOnly;
 378     }
 379   } else if (FLAG_IS_CMDLINE(MaxNewSize)) {
 380     _max_desired_young_length =
 381                              MAX2((uint) (MaxNewSize / HeapRegion::GrainBytes),
 382                                   1U);
 383     _sizer_kind = SizerMaxNewSizeOnly;
 384   }
 385 }
 386 
 387 uint G1YoungGenSizer::calculate_default_min_length(uint new_number_of_heap_regions) {
 388   uint default_value = (new_number_of_heap_regions * G1NewSizePercent) / 100;
 389   return MAX2(1U, default_value);
 390 }
 391 
 392 uint G1YoungGenSizer::calculate_default_max_length(uint new_number_of_heap_regions) {
 393   uint default_value = (new_number_of_heap_regions * G1MaxNewSizePercent) / 100;
 394   return MAX2(1U, default_value);
 395 }
 396 
 397 void G1YoungGenSizer::recalculate_min_max_young_length(uint number_of_heap_regions, uint* min_young_length, uint* max_young_length) {
 398   assert(number_of_heap_regions > 0, "Heap must be initialized");
 399 
 400   switch (_sizer_kind) {
 401     case SizerDefaults:
 402       *min_young_length = calculate_default_min_length(number_of_heap_regions);
 403       *max_young_length = calculate_default_max_length(number_of_heap_regions);
 404       break;
 405     case SizerNewSizeOnly:
 406       *max_young_length = calculate_default_max_length(number_of_heap_regions);
 407       *max_young_length = MAX2(*min_young_length, *max_young_length);
 408       break;
 409     case SizerMaxNewSizeOnly:
 410       *min_young_length = calculate_default_min_length(number_of_heap_regions);
 411       *min_young_length = MIN2(*min_young_length, *max_young_length);
 412       break;
 413     case SizerMaxAndNewSize:
 414       // Do nothing. Values set on the command line, don't update them at runtime.
 415       break;
 416     case SizerNewRatio:
 417       *min_young_length = number_of_heap_regions / (NewRatio + 1);
 418       *max_young_length = *min_young_length;
 419       break;
 420     default:
 421       ShouldNotReachHere();
 422   }
 423 
 424   assert(*min_young_length <= *max_young_length, "Invalid min/max young gen size values");
 425 }
 426 
 427 uint G1YoungGenSizer::max_young_length(uint number_of_heap_regions) {
 428   // We need to pass the desired values because recalculation may not update these
 429   // values in some cases.
 430   uint temp = _min_desired_young_length;
 431   uint result = _max_desired_young_length;
 432   recalculate_min_max_young_length(number_of_heap_regions, &temp, &result);
 433   return result;
 434 }
 435 
 436 void G1YoungGenSizer::heap_size_changed(uint new_number_of_heap_regions) {
 437   recalculate_min_max_young_length(new_number_of_heap_regions, &_min_desired_young_length,
 438           &_max_desired_young_length);
 439 }
 440 
 441 void G1CollectorPolicy::init() {
 442   // Set aside an initial future to_space.
 443   _g1 = G1CollectedHeap::heap();
 444 
 445   assert(Heap_lock->owned_by_self(), "Locking discipline.");
 446 
 447   initialize_gc_policy_counters();
 448 
 449   if (adaptive_young_list_length()) {
 450     _young_list_fixed_length = 0;
 451   } else {
 452     _young_list_fixed_length = _young_gen_sizer->min_desired_young_length();
 453   }
 454   _free_regions_at_end_of_collection = _g1->free_regions();
 455   update_young_list_target_length();
 456 
 457   // We may immediately start allocating regions and placing them on the
 458   // collection set list. Initialize the per-collection set info


src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File