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_gen0_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 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.
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.
464 max_new_size = MIN2(MAX2(max_new_size, NewSize), MaxNewSize);
465 }
466 assert(max_new_size > 0, "All paths should set max_new_size");
467
468 // Given the maximum gen0 size, determine the initial and
469 // minimum gen0 sizes.
470
471 if (_max_heap_byte_size == _initial_heap_byte_size) {
472 // The maxium and initial heap sizes are the same so the generation's
473 // initial size must be the same as it maximum size. Use NewSize as the
474 // size if set on command line.
475 size_t fixed_young_size = FLAG_IS_CMDLINE(NewSize) ? NewSize : max_new_size;
476
477 _initial_gen0_size = fixed_young_size;
478 _max_gen0_size = fixed_young_size;
479
480 // Also update the minimum size if min == initial == max.
481 if (_max_heap_byte_size == _min_heap_byte_size) {
482 _min_gen0_size = fixed_young_size;
483 }
484 } else {
485 size_t desired_new_size = 0;
486 if (FLAG_IS_CMDLINE(NewSize)) {
487 // If NewSize is set on the command line, we should use it as
488 // the initial size, but make sure it is within the heap bounds.
489 desired_new_size =
490 MIN2(max_new_size, bound_minus_alignment(NewSize, _initial_heap_byte_size));
491 _min_gen0_size = bound_minus_alignment(desired_new_size, _min_heap_byte_size);
492 } else {
493 // For the case where NewSize is not set on the command line, use
494 // NewRatio to size the initial generation size. Use the current
495 // NewSize as the floor, because if NewRatio is overly large, the resulting
496 // size can be too small.
497 desired_new_size =
498 MIN2(max_new_size, MAX2(scale_by_NewRatio_aligned(_initial_heap_byte_size), NewSize));
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
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 {
539 // OldSize has been explicitly set on the command line. Use it
540 // for the initial size but make sure the minimum allow a young
541 // generation to fit as well.
542 // If the user has explicitly set an OldSize that is inconsistent
543 // with other command line flags, issue a warning.
544 // The generation minimums and the overall heap minimum should
545 // be within one generation alignment.
546 if (OldSize > _max_gen1_size) {
547 warning("Inconsistency between maximum heap size and maximum "
548 "generation sizes: using maximum heap = " SIZE_FORMAT
549 " -XX:OldSize flag is being ignored",
550 _max_heap_byte_size);
551 FLAG_SET_ERGO(uintx, OldSize, _max_gen1_size);
552 }
553
554 _min_gen1_size = MIN2(OldSize, _min_heap_byte_size - _min_gen0_size);
555 _initial_gen1_size = OldSize;
556 }
557
558 // The initial generation sizes should match the initial heap size,
559 // if not issue a warning and resize the generations. This behavior
560 // differs from JDK8 where the generation sizes have higher priority
561 // than the initial heap size.
562 if ((_initial_gen1_size + _initial_gen0_size) != _initial_heap_byte_size) {
563 warning("Inconsistency between generation sizes and heap size, resizing "
564 "the generations to fit the heap.");
565
566 size_t desired_gen0_size = _initial_heap_byte_size - _initial_gen1_size;
567 if (_initial_heap_byte_size < _initial_gen1_size) {
568 // Old want all memory, use minimum for young and rest for old
569 _initial_gen0_size = _min_gen0_size;
570 _initial_gen1_size = _initial_heap_byte_size - _min_gen0_size;
571 } else if (desired_gen0_size > _max_gen0_size) {
572 // Need to increase both young and old generation
573 _initial_gen0_size = _max_gen0_size;
574 _initial_gen1_size = _initial_heap_byte_size - _max_gen0_size;
|
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_gen0_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 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.
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.
464 max_new_size = MIN2(MAX2(max_new_size, (size_t)NewSize), (size_t)MaxNewSize);
465 }
466 assert(max_new_size > 0, "All paths should set max_new_size");
467
468 // Given the maximum gen0 size, determine the initial and
469 // minimum gen0 sizes.
470
471 if (_max_heap_byte_size == _initial_heap_byte_size) {
472 // The maxium and initial heap sizes are the same so the generation's
473 // initial size must be the same as it maximum size. Use NewSize as the
474 // size if set on command line.
475 size_t fixed_young_size = FLAG_IS_CMDLINE(NewSize) ? NewSize : max_new_size;
476
477 _initial_gen0_size = fixed_young_size;
478 _max_gen0_size = fixed_young_size;
479
480 // Also update the minimum size if min == initial == max.
481 if (_max_heap_byte_size == _min_heap_byte_size) {
482 _min_gen0_size = fixed_young_size;
483 }
484 } else {
485 size_t desired_new_size = 0;
486 if (FLAG_IS_CMDLINE(NewSize)) {
487 // If NewSize is set on the command line, we should use it as
488 // the initial size, but make sure it is within the heap bounds.
489 desired_new_size =
490 MIN2(max_new_size, bound_minus_alignment(NewSize, _initial_heap_byte_size));
491 _min_gen0_size = bound_minus_alignment(desired_new_size, _min_heap_byte_size);
492 } else {
493 // For the case where NewSize is not set on the command line, use
494 // NewRatio to size the initial generation size. Use the current
495 // NewSize as the floor, because if NewRatio is overly large, the resulting
496 // size can be too small.
497 desired_new_size =
498 MIN2(max_new_size, MAX2(scale_by_NewRatio_aligned(_initial_heap_byte_size), (size_t)NewSize));
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
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 {
539 // OldSize has been explicitly set on the command line. Use it
540 // for the initial size but make sure the minimum allow a young
541 // generation to fit as well.
542 // If the user has explicitly set an OldSize that is inconsistent
543 // with other command line flags, issue a warning.
544 // The generation minimums and the overall heap minimum should
545 // be within one generation alignment.
546 if (OldSize > _max_gen1_size) {
547 warning("Inconsistency between maximum heap size and maximum "
548 "generation sizes: using maximum heap = " SIZE_FORMAT
549 " -XX:OldSize flag is being ignored",
550 _max_heap_byte_size);
551 FLAG_SET_ERGO(uintx, OldSize, _max_gen1_size);
552 }
553
554 _min_gen1_size = MIN2((size_t)OldSize, _min_heap_byte_size - _min_gen0_size);
555 _initial_gen1_size = OldSize;
556 }
557
558 // The initial generation sizes should match the initial heap size,
559 // if not issue a warning and resize the generations. This behavior
560 // differs from JDK8 where the generation sizes have higher priority
561 // than the initial heap size.
562 if ((_initial_gen1_size + _initial_gen0_size) != _initial_heap_byte_size) {
563 warning("Inconsistency between generation sizes and heap size, resizing "
564 "the generations to fit the heap.");
565
566 size_t desired_gen0_size = _initial_heap_byte_size - _initial_gen1_size;
567 if (_initial_heap_byte_size < _initial_gen1_size) {
568 // Old want all memory, use minimum for young and rest for old
569 _initial_gen0_size = _min_gen0_size;
570 _initial_gen1_size = _initial_heap_byte_size - _min_gen0_size;
571 } else if (desired_gen0_size > _max_gen0_size) {
572 // Need to increase both young and old generation
573 _initial_gen0_size = _max_gen0_size;
574 _initial_gen1_size = _initial_heap_byte_size - _max_gen0_size;
|