src/share/vm/memory/collectorPolicy.cpp

Print this page




 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 
 387   // Adjust NewSize and OldSize or MaxHeapSize to match each other
 388   if (NewSize + OldSize > MaxHeapSize) {
 389     if (_max_heap_size_cmdline) {
 390       // Somebody has set a maximum heap size with the intention that we should not
 391       // exceed it. Adjust New/OldSize as necessary.
 392       uintx calculated_size = NewSize + OldSize;
 393       double shrink_factor = (double) MaxHeapSize / calculated_size;
 394       uintx smaller_new_size = align_size_down((uintx)(NewSize * shrink_factor), _gen_alignment);
 395       FLAG_SET_ERGO(uintx, NewSize, MAX2(young_gen_size_lower_bound(), smaller_new_size));
 396       _initial_young_size = NewSize;
 397 
 398       // OldSize is already aligned because above we aligned MaxHeapSize to
 399       // _heap_alignment, and we just made sure that NewSize is aligned to
 400       // _gen_alignment. In initialize_flags() we verified that _heap_alignment
 401       // is a multiple of _gen_alignment.
 402       FLAG_SET_ERGO(uintx, OldSize, MaxHeapSize - NewSize);
 403     } else {
 404       FLAG_SET_ERGO(uintx, MaxHeapSize, align_size_up(NewSize + OldSize, _heap_alignment));
 405       _max_heap_byte_size = MaxHeapSize;
 406     }
 407   }
 408 
 409   // Update NewSize, if possible, to avoid sizing the young gen too 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_young_size
 415       // might not have been set yet.


 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   _initial_young_size = NewSize;
 448   _max_young_size = MaxNewSize;
 449   _initial_old_size = OldSize;
 450 
 451   // Determine maximum size of the young generation.
 452 
 453   if (FLAG_IS_DEFAULT(MaxNewSize)) {
 454     _max_young_size = scale_by_NewRatio_aligned(_max_heap_byte_size);
 455     // Bound the maximum size by NewSize below (since it historically
 456     // would have been NewSize and because the NewRatio calculation could
 457     // yield a size that is too small) and bound it by MaxNewSize above.
 458     // Ergonomics plays here by previously calculating the desired
 459     // NewSize and MaxNewSize.
 460     _max_young_size = MIN2(MAX2(_max_young_size, _initial_young_size), MaxNewSize);
 461   }
 462 
 463   // Given the maximum young size, determine the initial and
 464   // minimum young sizes.
 465 
 466   if (_max_heap_byte_size == _initial_heap_byte_size) {
 467     // The maximum and initial heap sizes are the same so the generation's
 468     // initial size must be the same as it maximum size. Use NewSize as the
 469     // size if set on command line.
 470     _max_young_size = FLAG_IS_CMDLINE(NewSize) ? NewSize : _max_young_size;
 471     _initial_young_size = _max_young_size;
 472 
 473     // Also update the minimum size if min == initial == max.
 474     if (_max_heap_byte_size == _min_heap_byte_size) {
 475       _min_young_size = _max_young_size;
 476     }
 477   } else {
 478     if (FLAG_IS_CMDLINE(NewSize)) {
 479       // If NewSize is set on the command line, we should use it as
 480       // the initial size, but make sure it is within the heap bounds.
 481       _initial_young_size =
 482         MIN2(_max_young_size, bound_minus_alignment(NewSize, _initial_heap_byte_size));
 483       _min_young_size = bound_minus_alignment(_initial_young_size, _min_heap_byte_size);
 484     } else {
 485       // For the case where NewSize is not set on the command line, use
 486       // NewRatio to size the initial generation size. Use the current
 487       // NewSize as the floor, because if NewRatio is overly large, the resulting
 488       // size can be too small.
 489       _initial_young_size =
 490         MIN2(_max_young_size, MAX2(scale_by_NewRatio_aligned(_initial_heap_byte_size), NewSize));
 491     }
 492   }
 493 
 494   if (PrintGCDetails && Verbose) {
 495     gclog_or_tty->print_cr("1: Minimum young " SIZE_FORMAT "  Initial young "
 496       SIZE_FORMAT "  Maximum young " SIZE_FORMAT,
 497       _min_young_size, _initial_young_size, _max_young_size);
 498   }
 499 
 500   // At this point the minimum, initial and maximum sizes
 501   // of the overall heap and of the young generation have been determined.
 502   // The maximum old size can be determined from the maximum young
 503   // and maximum heap size since no explicit flags exist
 504   // for setting the old generation maximum.
 505   _max_old_size = MAX2(_max_heap_byte_size - _max_young_size, _gen_alignment);
 506 
 507   // If no explicit command line flag has been set for the
 508   // old generation size, use what is left.
 509   if (!FLAG_IS_CMDLINE(OldSize)) {
 510     // The user has not specified any value but the ergonomics




 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 
 387   // Adjust NewSize and OldSize or MaxHeapSize to match each other
 388   if (NewSize + OldSize > MaxHeapSize) {
 389     if (_max_heap_size_cmdline) {
 390       // Somebody has set a maximum heap size with the intention that we should not
 391       // exceed it. Adjust New/OldSize as necessary.
 392       uintx calculated_size = NewSize + OldSize;
 393       double shrink_factor = (double) MaxHeapSize / calculated_size;
 394       uintx smaller_new_size = align_size_down((uintx)(NewSize * shrink_factor), _gen_alignment);
 395       FLAG_SET_ERGO(uintx, NewSize, MAX2(young_gen_size_lower_bound(), (size_t)smaller_new_size));
 396       _initial_young_size = NewSize;
 397 
 398       // OldSize is already aligned because above we aligned MaxHeapSize to
 399       // _heap_alignment, and we just made sure that NewSize is aligned to
 400       // _gen_alignment. In initialize_flags() we verified that _heap_alignment
 401       // is a multiple of _gen_alignment.
 402       FLAG_SET_ERGO(uintx, OldSize, MaxHeapSize - NewSize);
 403     } else {
 404       FLAG_SET_ERGO(uintx, MaxHeapSize, align_size_up(NewSize + OldSize, _heap_alignment));
 405       _max_heap_byte_size = MaxHeapSize;
 406     }
 407   }
 408 
 409   // Update NewSize, if possible, to avoid sizing the young gen too 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_young_size
 415       // might not have been set yet.


 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   _initial_young_size = NewSize;
 448   _max_young_size = MaxNewSize;
 449   _initial_old_size = OldSize;
 450 
 451   // Determine maximum size of the young generation.
 452 
 453   if (FLAG_IS_DEFAULT(MaxNewSize)) {
 454     _max_young_size = scale_by_NewRatio_aligned(_max_heap_byte_size);
 455     // Bound the maximum size by NewSize below (since it historically
 456     // would have been NewSize and because the NewRatio calculation could
 457     // yield a size that is too small) and bound it by MaxNewSize above.
 458     // Ergonomics plays here by previously calculating the desired
 459     // NewSize and MaxNewSize.
 460     _max_young_size = MIN2(MAX2(_max_young_size, _initial_young_size), (size_t)MaxNewSize);
 461   }
 462 
 463   // Given the maximum young size, determine the initial and
 464   // minimum young sizes.
 465 
 466   if (_max_heap_byte_size == _initial_heap_byte_size) {
 467     // The maximum and initial heap sizes are the same so the generation's
 468     // initial size must be the same as it maximum size. Use NewSize as the
 469     // size if set on command line.
 470     _max_young_size = FLAG_IS_CMDLINE(NewSize) ? NewSize : _max_young_size;
 471     _initial_young_size = _max_young_size;
 472 
 473     // Also update the minimum size if min == initial == max.
 474     if (_max_heap_byte_size == _min_heap_byte_size) {
 475       _min_young_size = _max_young_size;
 476     }
 477   } else {
 478     if (FLAG_IS_CMDLINE(NewSize)) {
 479       // If NewSize is set on the command line, we should use it as
 480       // the initial size, but make sure it is within the heap bounds.
 481       _initial_young_size =
 482         MIN2(_max_young_size, bound_minus_alignment(NewSize, _initial_heap_byte_size));
 483       _min_young_size = bound_minus_alignment(_initial_young_size, _min_heap_byte_size);
 484     } else {
 485       // For the case where NewSize is not set on the command line, use
 486       // NewRatio to size the initial generation size. Use the current
 487       // NewSize as the floor, because if NewRatio is overly large, the resulting
 488       // size can be too small.
 489       _initial_young_size =
 490         MIN2(_max_young_size, MAX2(scale_by_NewRatio_aligned(_initial_heap_byte_size), (size_t)NewSize));
 491     }
 492   }
 493 
 494   if (PrintGCDetails && Verbose) {
 495     gclog_or_tty->print_cr("1: Minimum young " SIZE_FORMAT "  Initial young "
 496       SIZE_FORMAT "  Maximum young " SIZE_FORMAT,
 497       _min_young_size, _initial_young_size, _max_young_size);
 498   }
 499 
 500   // At this point the minimum, initial and maximum sizes
 501   // of the overall heap and of the young generation have been determined.
 502   // The maximum old size can be determined from the maximum young
 503   // and maximum heap size since no explicit flags exist
 504   // for setting the old generation maximum.
 505   _max_old_size = MAX2(_max_heap_byte_size - _max_young_size, _gen_alignment);
 506 
 507   // If no explicit command line flag has been set for the
 508   // old generation size, use what is left.
 509   if (!FLAG_IS_CMDLINE(OldSize)) {
 510     // The user has not specified any value but the ergonomics