src/share/vm/memory/collectorPolicy.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/memory

src/share/vm/memory/collectorPolicy.cpp

Print this page
rev 6345 : 8027643: Merge GenCollectorPolicy and TwoGenerationCollectorPolicy
Summary: Merged the two calsses GenCollectorPolicy and TwoGenerationCollectorPolicy
Reviewed-by:


 183   // Parallel GC does its own alignment of the generations to avoid requiring a
 184   // large page (256M on some platforms) for the permanent generation.  The
 185   // other collectors should also be updated to do their own alignment and then
 186   // this use of lcm() should be removed.
 187   if (UseLargePages && !UseParallelGC) {
 188       // In presence of large pages we have to make sure that our
 189       // alignment is large page aware
 190       alignment = lcm(os::large_page_size(), alignment);
 191   }
 192 
 193   return alignment;
 194 }
 195 
 196 // GenCollectorPolicy methods
 197 
 198 GenCollectorPolicy::GenCollectorPolicy() :
 199     _min_gen0_size(0),
 200     _initial_gen0_size(0),
 201     _max_gen0_size(0),
 202     _gen_alignment(0),



 203     _generations(NULL)
 204 {}
 205 
 206 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
 207   return align_size_down_bounded(base_size / (NewRatio + 1), _gen_alignment);
 208 }
 209 
 210 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size,
 211                                                  size_t maximum_size) {
 212   size_t max_minus = maximum_size - _gen_alignment;
 213   return desired_size < max_minus ? desired_size : max_minus;
 214 }
 215 
 216 
 217 void GenCollectorPolicy::initialize_size_policy(size_t init_eden_size,
 218                                                 size_t init_promo_size,
 219                                                 size_t init_survivor_size) {
 220   const double max_gc_pause_sec = ((double) MaxGCPauseMillis) / 1000.0;
 221   _size_policy = new AdaptiveSizePolicy(init_eden_size,
 222                                         init_promo_size,
 223                                         init_survivor_size,
 224                                         max_gc_pause_sec,
 225                                         GCTimeRatio);
 226 }
 227 
 228 size_t GenCollectorPolicy::young_gen_size_lower_bound() {
 229   // The young generation must be aligned and have room for eden + two survivors
 230   return align_size_up(3 * _space_alignment, _gen_alignment);
 231 }
 232 
 233 #ifdef ASSERT
 234 void GenCollectorPolicy::assert_flags() {
 235   CollectorPolicy::assert_flags();
 236   assert(NewSize >= _min_gen0_size, "Ergonomics decided on a too small young gen size");
 237   assert(NewSize <= MaxNewSize, "Ergonomics decided on incompatible initial and maximum young gen sizes");
 238   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young gen and heap sizes");
 239   assert(NewSize % _gen_alignment == 0, "NewSize alignment");
 240   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize % _gen_alignment == 0, "MaxNewSize alignment");
 241 }
 242 
 243 void TwoGenerationCollectorPolicy::assert_flags() {
 244   GenCollectorPolicy::assert_flags();
 245   assert(OldSize + NewSize <= MaxHeapSize, "Ergonomics decided on incompatible generation and heap sizes");
 246   assert(OldSize % _gen_alignment == 0, "OldSize alignment");
 247 }
 248 
 249 void GenCollectorPolicy::assert_size_info() {
 250   CollectorPolicy::assert_size_info();
 251   // GenCollectorPolicy::initialize_size_info may update the MaxNewSize
 252   assert(MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young and heap sizes");
 253   assert(NewSize == _initial_gen0_size, "Discrepancy between NewSize flag and local storage");
 254   assert(MaxNewSize == _max_gen0_size, "Discrepancy between MaxNewSize flag and local storage");

 255   assert(_min_gen0_size <= _initial_gen0_size, "Ergonomics decided on incompatible minimum and initial young gen sizes");
 256   assert(_initial_gen0_size <= _max_gen0_size, "Ergonomics decided on incompatible initial and maximum young gen sizes");
 257   assert(_min_gen0_size % _gen_alignment == 0, "_min_gen0_size alignment");
 258   assert(_initial_gen0_size % _gen_alignment == 0, "_initial_gen0_size alignment");
 259   assert(_max_gen0_size % _gen_alignment == 0, "_max_gen0_size alignment");
 260   assert(_min_gen0_size <= bound_minus_alignment(_min_gen0_size, _min_heap_byte_size),
 261       "Ergonomics made minimum young generation larger than minimum heap");
 262   assert(_initial_gen0_size <=  bound_minus_alignment(_initial_gen0_size, _initial_heap_byte_size),
 263       "Ergonomics made initial young generation larger than initial heap");
 264   assert(_max_gen0_size <= bound_minus_alignment(_max_gen0_size, _max_heap_byte_size),
 265       "Ergonomics made maximum young generation lager than maximum heap");
 266 }
 267 
 268 void TwoGenerationCollectorPolicy::assert_size_info() {
 269   GenCollectorPolicy::assert_size_info();
 270   assert(OldSize == _initial_gen1_size, "Discrepancy between OldSize flag and local storage");
 271   assert(_min_gen1_size <= _initial_gen1_size, "Ergonomics decided on incompatible minimum and initial old gen sizes");
 272   assert(_initial_gen1_size <= _max_gen1_size, "Ergonomics decided on incompatible initial and maximum old gen sizes");
 273   assert(_max_gen1_size % _gen_alignment == 0, "_max_gen1_size alignment");
 274   assert(_initial_gen1_size % _gen_alignment == 0, "_initial_gen1_size alignment");
 275   assert(_max_heap_byte_size <= (_max_gen0_size + _max_gen1_size), "Total maximum heap sizes must be sum of generation maximum sizes");
 276   assert(_min_gen0_size + _min_gen1_size <= _min_heap_byte_size, "Minimum generation sizes exceed minimum heap size");
 277   assert(_initial_gen0_size + _initial_gen1_size == _initial_heap_byte_size, "Initial generation sizes should match initial heap size");
 278   assert(_max_gen0_size + _max_gen1_size == _max_heap_byte_size, "Maximum generation sizes should match maximum heap size");
 279 }
 280 #endif // ASSERT
 281 
 282 void GenCollectorPolicy::initialize_flags() {
 283   CollectorPolicy::initialize_flags();
 284 
 285   assert(_gen_alignment != 0, "Generation alignment not set up properly");
 286   assert(_heap_alignment >= _gen_alignment,
 287          err_msg("heap_alignment: " SIZE_FORMAT " less than gen_alignment: " SIZE_FORMAT,
 288                  _heap_alignment, _gen_alignment));
 289   assert(_gen_alignment % _space_alignment == 0,
 290          err_msg("gen_alignment: " SIZE_FORMAT " not aligned by space_alignment: " SIZE_FORMAT,


 352     }
 353     _max_gen0_size = MaxNewSize;
 354   }
 355 
 356   if (NewSize > MaxNewSize) {
 357     // At this point this should only happen if the user specifies a large NewSize and/or
 358     // a small (but not too small) 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     FLAG_SET_ERGO(uintx, MaxNewSize, NewSize);
 365     _max_gen0_size = MaxNewSize;
 366   }
 367 
 368   if (SurvivorRatio < 1 || NewRatio < 1) {
 369     vm_exit_during_initialization("Invalid young gen ratio specified");
 370   }
 371 
 372   DEBUG_ONLY(GenCollectorPolicy::assert_flags();)
 373 }
 374 
 375 void TwoGenerationCollectorPolicy::initialize_flags() {
 376   GenCollectorPolicy::initialize_flags();
 377 
 378   if (!is_size_aligned(OldSize, _gen_alignment)) {
 379     // Setting OldSize directly to preserve information about the possible
 380     // setting of OldSize on the command line.
 381     OldSize = align_size_down(OldSize, _gen_alignment);
 382   }
 383 
 384   if (FLAG_IS_CMDLINE(OldSize) && FLAG_IS_DEFAULT(MaxHeapSize)) {
 385     // NewRatio will be used later to set the young generation size so we use
 386     // it to calculate how big the heap should be based on the requested OldSize
 387     // and NewRatio.
 388     assert(NewRatio > 0, "NewRatio should have been set up earlier");
 389     size_t calculated_heapsize = (OldSize / NewRatio) * (NewRatio + 1);
 390 
 391     calculated_heapsize = align_size_up(calculated_heapsize, _heap_alignment);
 392     FLAG_SET_ERGO(uintx, MaxHeapSize, calculated_heapsize);
 393     _max_heap_byte_size = MaxHeapSize;
 394     FLAG_SET_ERGO(uintx, InitialHeapSize, calculated_heapsize);
 395     _initial_heap_byte_size = InitialHeapSize;
 396   }
 397 


 416       _max_heap_byte_size = MaxHeapSize;
 417     }
 418   }
 419 
 420   // Update NewSize, if possible, to avoid sizing gen0 to small when only
 421   // OldSize is set on the command line.
 422   if (FLAG_IS_CMDLINE(OldSize) && !FLAG_IS_CMDLINE(NewSize)) {
 423     if (OldSize < _initial_heap_byte_size) {
 424       size_t new_size = _initial_heap_byte_size - OldSize;
 425       // Need to compare against the flag value for max since _max_gen0_size
 426       // might not have been set yet.
 427       if (new_size >= _min_gen0_size && new_size <= MaxNewSize) {
 428         FLAG_SET_ERGO(uintx, NewSize, new_size);
 429         _initial_gen0_size = NewSize;
 430       }
 431     }
 432   }
 433 
 434   always_do_update_barrier = UseConcMarkSweepGC;
 435 
 436   DEBUG_ONLY(TwoGenerationCollectorPolicy::assert_flags();)
 437 }
 438 
 439 // Values set on the command line win over any ergonomically
 440 // set command line parameters.
 441 // Ergonomic choice of parameters are done before this
 442 // method is called.  Values for command line parameters such as NewSize
 443 // and MaxNewSize feed those ergonomic choices into this method.
 444 // This method makes the final generation sizings consistent with
 445 // themselves and with overall heap sizings.
 446 // In the absence of explicitly set command line flags, policies
 447 // such as the use of NewRatio are used to size the generation.







 448 void GenCollectorPolicy::initialize_size_info() {
 449   CollectorPolicy::initialize_size_info();
 450 
 451   // _space_alignment is used for alignment within a generation.
 452   // There is additional alignment done down stream for some
 453   // collectors that sometimes causes unwanted rounding up of
 454   // generations sizes.
 455 
 456   // Determine maximum size of gen0
 457 
 458   size_t max_new_size = 0;
 459   if (!FLAG_IS_DEFAULT(MaxNewSize)) {
 460     max_new_size = MaxNewSize;
 461   } else {
 462     max_new_size = scale_by_NewRatio_aligned(_max_heap_byte_size);
 463     // Bound the maximum size by NewSize below (since it historically
 464     // would have been NewSize and because the NewRatio calculation could
 465     // yield a size that is too small) and bound it by MaxNewSize above.
 466     // Ergonomics plays here by previously calculating the desired
 467     // NewSize and MaxNewSize.


 503     }
 504     _initial_gen0_size = desired_new_size;
 505     _max_gen0_size = max_new_size;
 506   }
 507 
 508   // Write back to flags if necessary.
 509   if (NewSize != _initial_gen0_size) {
 510     FLAG_SET_ERGO(uintx, NewSize, _initial_gen0_size);
 511   }
 512 
 513   if (MaxNewSize != _max_gen0_size) {
 514     FLAG_SET_ERGO(uintx, MaxNewSize, _max_gen0_size);
 515   }
 516 
 517   if (PrintGCDetails && Verbose) {
 518     gclog_or_tty->print_cr("1: Minimum gen0 " SIZE_FORMAT "  Initial gen0 "
 519       SIZE_FORMAT "  Maximum gen0 " SIZE_FORMAT,
 520       _min_gen0_size, _initial_gen0_size, _max_gen0_size);
 521   }
 522 
 523   DEBUG_ONLY(GenCollectorPolicy::assert_size_info();)
 524 }
 525 
 526 // Minimum sizes of the generations may be different than
 527 // the initial sizes.  An inconsistency is permitted here
 528 // in the total size that can be specified explicitly by
 529 // command line specification of OldSize and NewSize and
 530 // also a command line specification of -Xms.  Issue a warning
 531 // but allow the values to pass.
 532 
 533 void TwoGenerationCollectorPolicy::initialize_size_info() {
 534   GenCollectorPolicy::initialize_size_info();
 535 
 536   // At this point the minimum, initial and maximum sizes
 537   // of the overall heap and of gen0 have been determined.
 538   // The maximum gen1 size can be determined from the maximum gen0
 539   // and maximum heap size since no explicit flags exist
 540   // for setting the gen1 maximum.
 541   _max_gen1_size = MAX2(_max_heap_byte_size - _max_gen0_size, _gen_alignment);
 542 
 543   // If no explicit command line flag has been set for the
 544   // gen1 size, use what is left for gen1
 545   if (!FLAG_IS_CMDLINE(OldSize)) {
 546     // The user has not specified any value but the ergonomics
 547     // may have chosen a value (which may or may not be consistent
 548     // with the overall heap size).  In either case make
 549     // the minimum, maximum and initial sizes consistent
 550     // with the gen0 sizes and the overall heap sizes.
 551     _min_gen1_size = _gen_alignment;
 552     _initial_gen1_size = MIN2(_max_gen1_size, MAX2(_initial_heap_byte_size - _initial_gen0_size, _min_gen1_size));
 553     // _max_gen1_size has already been made consistent above
 554     FLAG_SET_ERGO(uintx, OldSize, _initial_gen1_size);
 555   } else {


 608 
 609   // Write back to flags if necessary
 610   if (NewSize != _initial_gen0_size) {
 611     FLAG_SET_ERGO(uintx, NewSize, _initial_gen0_size);
 612   }
 613 
 614   if (MaxNewSize != _max_gen0_size) {
 615     FLAG_SET_ERGO(uintx, MaxNewSize, _max_gen0_size);
 616   }
 617 
 618   if (OldSize != _initial_gen1_size) {
 619     FLAG_SET_ERGO(uintx, OldSize, _initial_gen1_size);
 620   }
 621 
 622   if (PrintGCDetails && Verbose) {
 623     gclog_or_tty->print_cr("Minimum gen1 " SIZE_FORMAT "  Initial gen1 "
 624       SIZE_FORMAT "  Maximum gen1 " SIZE_FORMAT,
 625       _min_gen1_size, _initial_gen1_size, _max_gen1_size);
 626   }
 627 
 628   DEBUG_ONLY(TwoGenerationCollectorPolicy::assert_size_info();)
 629 }
 630 
 631 HeapWord* GenCollectorPolicy::mem_allocate_work(size_t size,
 632                                         bool is_tlab,
 633                                         bool* gc_overhead_limit_was_exceeded) {
 634   GenCollectedHeap *gch = GenCollectedHeap::heap();
 635 
 636   debug_only(gch->check_for_valid_allocation_state());
 637   assert(gch->no_gc_in_progress(), "Allocation during gc not allowed");
 638 
 639   // In general gc_overhead_limit_was_exceeded should be false so
 640   // set it so here and reset it to true only if the gc time
 641   // limit is being exceeded as checked below.
 642   *gc_overhead_limit_was_exceeded = false;
 643 
 644   HeapWord* result = NULL;
 645 
 646   // Loop until the allocation is satisfied, or unsatisfied after GC.
 647   for (int try_count = 1, gclocker_stalled_count = 0; /* return or throw */; try_count += 1) {
 648     HandleMark hm; // Discard any handles allocated in each iteration.




 183   // Parallel GC does its own alignment of the generations to avoid requiring a
 184   // large page (256M on some platforms) for the permanent generation.  The
 185   // other collectors should also be updated to do their own alignment and then
 186   // this use of lcm() should be removed.
 187   if (UseLargePages && !UseParallelGC) {
 188       // In presence of large pages we have to make sure that our
 189       // alignment is large page aware
 190       alignment = lcm(os::large_page_size(), alignment);
 191   }
 192 
 193   return alignment;
 194 }
 195 
 196 // GenCollectorPolicy methods
 197 
 198 GenCollectorPolicy::GenCollectorPolicy() :
 199     _min_gen0_size(0),
 200     _initial_gen0_size(0),
 201     _max_gen0_size(0),
 202     _gen_alignment(0),
 203     _min_gen1_size(0),
 204     _initial_gen1_size(0),
 205     _max_gen1_size(0),
 206     _generations(NULL)
 207 {}
 208 
 209 size_t GenCollectorPolicy::scale_by_NewRatio_aligned(size_t base_size) {
 210   return align_size_down_bounded(base_size / (NewRatio + 1), _gen_alignment);
 211 }
 212 
 213 size_t GenCollectorPolicy::bound_minus_alignment(size_t desired_size,
 214                                                  size_t maximum_size) {
 215   size_t max_minus = maximum_size - _gen_alignment;
 216   return desired_size < max_minus ? desired_size : max_minus;
 217 }
 218 
 219 
 220 void GenCollectorPolicy::initialize_size_policy(size_t init_eden_size,
 221                                                 size_t init_promo_size,
 222                                                 size_t init_survivor_size) {
 223   const double max_gc_pause_sec = ((double) MaxGCPauseMillis) / 1000.0;
 224   _size_policy = new AdaptiveSizePolicy(init_eden_size,
 225                                         init_promo_size,
 226                                         init_survivor_size,
 227                                         max_gc_pause_sec,
 228                                         GCTimeRatio);
 229 }
 230 
 231 size_t GenCollectorPolicy::young_gen_size_lower_bound() {
 232   // The young generation must be aligned and have room for eden + two survivors
 233   return align_size_up(3 * _space_alignment, _gen_alignment);
 234 }
 235 
 236 #ifdef ASSERT
 237 void GenCollectorPolicy::assert_flags() {
 238   CollectorPolicy::assert_flags();
 239   assert(NewSize >= _min_gen0_size, "Ergonomics decided on a too small young gen size");
 240   assert(NewSize <= MaxNewSize, "Ergonomics decided on incompatible initial and maximum young gen sizes");
 241   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young gen and heap sizes");
 242   assert(NewSize % _gen_alignment == 0, "NewSize alignment");
 243   assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize % _gen_alignment == 0, "MaxNewSize alignment");




 244   assert(OldSize + NewSize <= MaxHeapSize, "Ergonomics decided on incompatible generation and heap sizes");
 245   assert(OldSize % _gen_alignment == 0, "OldSize alignment");
 246 }
 247 
 248 void GenCollectorPolicy::assert_size_info() {
 249   CollectorPolicy::assert_size_info();
 250   // GenCollectorPolicy::initialize_size_info may update the MaxNewSize
 251   assert(MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young and heap sizes");
 252   assert(NewSize == _initial_gen0_size, "Discrepancy between NewSize flag and local storage");
 253   assert(MaxNewSize == _max_gen0_size, "Discrepancy between MaxNewSize flag and local storage");
 254   assert(OldSize == _initial_gen1_size, "Discrepancy between OldSize flag and local storage");
 255   assert(_min_gen0_size <= _initial_gen0_size, "Ergonomics decided on incompatible minimum and initial young gen sizes");
 256   assert(_initial_gen0_size <= _max_gen0_size, "Ergonomics decided on incompatible initial and maximum young gen sizes");
 257   assert(_min_gen0_size % _gen_alignment == 0, "_min_gen0_size alignment");
 258   assert(_initial_gen0_size % _gen_alignment == 0, "_initial_gen0_size alignment");
 259   assert(_max_gen0_size % _gen_alignment == 0, "_max_gen0_size alignment");
 260   assert(_min_gen0_size <= bound_minus_alignment(_min_gen0_size, _min_heap_byte_size),
 261       "Ergonomics made minimum young generation larger than minimum heap");
 262   assert(_initial_gen0_size <=  bound_minus_alignment(_initial_gen0_size, _initial_heap_byte_size),
 263       "Ergonomics made initial young generation larger than initial heap");
 264   assert(_max_gen0_size <= bound_minus_alignment(_max_gen0_size, _max_heap_byte_size),
 265       "Ergonomics made maximum young generation lager than maximum heap");





 266   assert(_min_gen1_size <= _initial_gen1_size, "Ergonomics decided on incompatible minimum and initial old gen sizes");
 267   assert(_initial_gen1_size <= _max_gen1_size, "Ergonomics decided on incompatible initial and maximum old gen sizes");
 268   assert(_max_gen1_size % _gen_alignment == 0, "_max_gen1_size alignment");
 269   assert(_initial_gen1_size % _gen_alignment == 0, "_initial_gen1_size alignment");
 270   assert(_max_heap_byte_size <= (_max_gen0_size + _max_gen1_size), "Total maximum heap sizes must be sum of generation maximum sizes");
 271   assert(_min_gen0_size + _min_gen1_size <= _min_heap_byte_size, "Minimum generation sizes exceed minimum heap size");
 272   assert(_initial_gen0_size + _initial_gen1_size == _initial_heap_byte_size, "Initial generation sizes should match initial heap size");
 273   assert(_max_gen0_size + _max_gen1_size == _max_heap_byte_size, "Maximum generation sizes should match maximum heap size");
 274 }
 275 #endif // ASSERT
 276 
 277 void GenCollectorPolicy::initialize_flags() {
 278   CollectorPolicy::initialize_flags();
 279 
 280   assert(_gen_alignment != 0, "Generation alignment not set up properly");
 281   assert(_heap_alignment >= _gen_alignment,
 282          err_msg("heap_alignment: " SIZE_FORMAT " less than gen_alignment: " SIZE_FORMAT,
 283                  _heap_alignment, _gen_alignment));
 284   assert(_gen_alignment % _space_alignment == 0,
 285          err_msg("gen_alignment: " SIZE_FORMAT " not aligned by space_alignment: " SIZE_FORMAT,


 347     }
 348     _max_gen0_size = MaxNewSize;
 349   }
 350 
 351   if (NewSize > MaxNewSize) {
 352     // At this point this should only happen if the user specifies a large NewSize and/or
 353     // a small (but not too small) MaxNewSize.
 354     if (FLAG_IS_CMDLINE(MaxNewSize)) {
 355       warning("NewSize (" SIZE_FORMAT "k) is greater than the MaxNewSize (" SIZE_FORMAT "k). "
 356               "A new max generation size of " SIZE_FORMAT "k will be used.",
 357               NewSize/K, MaxNewSize/K, NewSize/K);
 358     }
 359     FLAG_SET_ERGO(uintx, MaxNewSize, NewSize);
 360     _max_gen0_size = MaxNewSize;
 361   }
 362 
 363   if (SurvivorRatio < 1 || NewRatio < 1) {
 364     vm_exit_during_initialization("Invalid young gen ratio specified");
 365   }
 366 






 367   if (!is_size_aligned(OldSize, _gen_alignment)) {
 368     // Setting OldSize directly to preserve information about the possible
 369     // setting of OldSize on the command line.
 370     OldSize = align_size_down(OldSize, _gen_alignment);
 371   }
 372 
 373   if (FLAG_IS_CMDLINE(OldSize) && FLAG_IS_DEFAULT(MaxHeapSize)) {
 374     // NewRatio will be used later to set the young generation size so we use
 375     // it to calculate how big the heap should be based on the requested OldSize
 376     // and NewRatio.
 377     assert(NewRatio > 0, "NewRatio should have been set up earlier");
 378     size_t calculated_heapsize = (OldSize / NewRatio) * (NewRatio + 1);
 379 
 380     calculated_heapsize = align_size_up(calculated_heapsize, _heap_alignment);
 381     FLAG_SET_ERGO(uintx, MaxHeapSize, calculated_heapsize);
 382     _max_heap_byte_size = MaxHeapSize;
 383     FLAG_SET_ERGO(uintx, InitialHeapSize, calculated_heapsize);
 384     _initial_heap_byte_size = InitialHeapSize;
 385   }
 386 


 405       _max_heap_byte_size = MaxHeapSize;
 406     }
 407   }
 408 
 409   // Update NewSize, if possible, to avoid sizing gen0 to small when only
 410   // OldSize is set on the command line.
 411   if (FLAG_IS_CMDLINE(OldSize) && !FLAG_IS_CMDLINE(NewSize)) {
 412     if (OldSize < _initial_heap_byte_size) {
 413       size_t new_size = _initial_heap_byte_size - OldSize;
 414       // Need to compare against the flag value for max since _max_gen0_size
 415       // might not have been set yet.
 416       if (new_size >= _min_gen0_size && new_size <= MaxNewSize) {
 417         FLAG_SET_ERGO(uintx, NewSize, new_size);
 418         _initial_gen0_size = NewSize;
 419       }
 420     }
 421   }
 422 
 423   always_do_update_barrier = UseConcMarkSweepGC;
 424 
 425   DEBUG_ONLY(GenCollectorPolicy::assert_flags();)
 426 }
 427 
 428 // Values set on the command line win over any ergonomically
 429 // set command line parameters.
 430 // Ergonomic choice of parameters are done before this
 431 // method is called.  Values for command line parameters such as NewSize
 432 // and MaxNewSize feed those ergonomic choices into this method.
 433 // This method makes the final generation sizings consistent with
 434 // themselves and with overall heap sizings.
 435 // In the absence of explicitly set command line flags, policies
 436 // such as the use of NewRatio are used to size the generation.
 437 
 438 // Minimum sizes of the generations may be different than
 439 // the initial sizes.  An inconsistency is permitted here
 440 // in the total size that can be specified explicitly by
 441 // command line specification of OldSize and NewSize and
 442 // also a command line specification of -Xms.  Issue a warning
 443 // but allow the values to pass.
 444 void GenCollectorPolicy::initialize_size_info() {
 445   CollectorPolicy::initialize_size_info();
 446 
 447   // _space_alignment is used for alignment within a generation.
 448   // There is additional alignment done down stream for some
 449   // collectors that sometimes causes unwanted rounding up of
 450   // generations sizes.
 451 
 452   // Determine maximum size of gen0
 453 
 454   size_t max_new_size = 0;
 455   if (!FLAG_IS_DEFAULT(MaxNewSize)) {
 456     max_new_size = MaxNewSize;
 457   } else {
 458     max_new_size = scale_by_NewRatio_aligned(_max_heap_byte_size);
 459     // Bound the maximum size by NewSize below (since it historically
 460     // would have been NewSize and because the NewRatio calculation could
 461     // yield a size that is too small) and bound it by MaxNewSize above.
 462     // Ergonomics plays here by previously calculating the desired
 463     // NewSize and MaxNewSize.


 499     }
 500     _initial_gen0_size = desired_new_size;
 501     _max_gen0_size = max_new_size;
 502   }
 503 
 504   // Write back to flags if necessary.
 505   if (NewSize != _initial_gen0_size) {
 506     FLAG_SET_ERGO(uintx, NewSize, _initial_gen0_size);
 507   }
 508 
 509   if (MaxNewSize != _max_gen0_size) {
 510     FLAG_SET_ERGO(uintx, MaxNewSize, _max_gen0_size);
 511   }
 512 
 513   if (PrintGCDetails && Verbose) {
 514     gclog_or_tty->print_cr("1: Minimum gen0 " SIZE_FORMAT "  Initial gen0 "
 515       SIZE_FORMAT "  Maximum gen0 " SIZE_FORMAT,
 516       _min_gen0_size, _initial_gen0_size, _max_gen0_size);
 517   }
 518 













 519   // At this point the minimum, initial and maximum sizes
 520   // of the overall heap and of gen0 have been determined.
 521   // The maximum gen1 size can be determined from the maximum gen0
 522   // and maximum heap size since no explicit flags exist
 523   // for setting the gen1 maximum.
 524   _max_gen1_size = MAX2(_max_heap_byte_size - _max_gen0_size, _gen_alignment);
 525 
 526   // If no explicit command line flag has been set for the
 527   // gen1 size, use what is left for gen1
 528   if (!FLAG_IS_CMDLINE(OldSize)) {
 529     // The user has not specified any value but the ergonomics
 530     // may have chosen a value (which may or may not be consistent
 531     // with the overall heap size).  In either case make
 532     // the minimum, maximum and initial sizes consistent
 533     // with the gen0 sizes and the overall heap sizes.
 534     _min_gen1_size = _gen_alignment;
 535     _initial_gen1_size = MIN2(_max_gen1_size, MAX2(_initial_heap_byte_size - _initial_gen0_size, _min_gen1_size));
 536     // _max_gen1_size has already been made consistent above
 537     FLAG_SET_ERGO(uintx, OldSize, _initial_gen1_size);
 538   } else {


 591 
 592   // Write back to flags if necessary
 593   if (NewSize != _initial_gen0_size) {
 594     FLAG_SET_ERGO(uintx, NewSize, _initial_gen0_size);
 595   }
 596 
 597   if (MaxNewSize != _max_gen0_size) {
 598     FLAG_SET_ERGO(uintx, MaxNewSize, _max_gen0_size);
 599   }
 600 
 601   if (OldSize != _initial_gen1_size) {
 602     FLAG_SET_ERGO(uintx, OldSize, _initial_gen1_size);
 603   }
 604 
 605   if (PrintGCDetails && Verbose) {
 606     gclog_or_tty->print_cr("Minimum gen1 " SIZE_FORMAT "  Initial gen1 "
 607       SIZE_FORMAT "  Maximum gen1 " SIZE_FORMAT,
 608       _min_gen1_size, _initial_gen1_size, _max_gen1_size);
 609   }
 610 
 611   DEBUG_ONLY(GenCollectorPolicy::assert_size_info();)
 612 }
 613 
 614 HeapWord* GenCollectorPolicy::mem_allocate_work(size_t size,
 615                                         bool is_tlab,
 616                                         bool* gc_overhead_limit_was_exceeded) {
 617   GenCollectedHeap *gch = GenCollectedHeap::heap();
 618 
 619   debug_only(gch->check_for_valid_allocation_state());
 620   assert(gch->no_gc_in_progress(), "Allocation during gc not allowed");
 621 
 622   // In general gc_overhead_limit_was_exceeded should be false so
 623   // set it so here and reset it to true only if the gc time
 624   // limit is being exceeded as checked below.
 625   *gc_overhead_limit_was_exceeded = false;
 626 
 627   HeapWord* result = NULL;
 628 
 629   // Loop until the allocation is satisfied, or unsatisfied after GC.
 630   for (int try_count = 1, gclocker_stalled_count = 0; /* return or throw */; try_count += 1) {
 631     HandleMark hm; // Discard any handles allocated in each iteration.


src/share/vm/memory/collectorPolicy.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File