457 // The easiest way to deal with the parsing of the NewSize /
458 // MaxNewSize / etc. parameteres is to re-use the code in the
459 // TwoGenerationCollectorPolicy class. This is similar to what
460 // ParallelScavenge does with its GenerationSizer class (see
461 // ParallelScavengeHeap::initialize()). We might change this in the
462 // future, but it's a good start.
463 class G1YoungGenSizer : public TwoGenerationCollectorPolicy {
464 private:
465 size_t size_to_region_num(size_t byte_size) {
466 return MAX2((size_t) 1, byte_size / HeapRegion::GrainBytes);
467 }
468
469 public:
470 G1YoungGenSizer() {
471 initialize_flags();
472 initialize_size_info();
473 }
474 size_t min_young_region_num() {
475 return size_to_region_num(_min_gen0_size);
476 }
477 size_t initial_young_region_num() {
478 return size_to_region_num(_initial_gen0_size);
479 }
480 size_t max_young_region_num() {
481 return size_to_region_num(_max_gen0_size);
482 }
483 };
484
485 void G1CollectorPolicy::update_young_list_size_using_newratio(size_t number_of_heap_regions) {
486 assert(number_of_heap_regions > 0, "Heap must be initialized");
487 size_t young_size = number_of_heap_regions / (NewRatio + 1);
488 _min_desired_young_length = young_size;
489 _max_desired_young_length = young_size;
490 }
491
492 void G1CollectorPolicy::init() {
493 // Set aside an initial future to_space.
494 _g1 = G1CollectedHeap::heap();
495
496 assert(Heap_lock->owned_by_self(), "Locking discipline.");
497
498 initialize_gc_policy_counters();
499
500 G1YoungGenSizer sizer;
501 size_t initial_region_num = sizer.initial_young_region_num();
502 _min_desired_young_length = sizer.min_young_region_num();
503 _max_desired_young_length = sizer.max_young_region_num();
504
505 if (FLAG_IS_CMDLINE(NewRatio)) {
506 if (FLAG_IS_CMDLINE(NewSize) || FLAG_IS_CMDLINE(MaxNewSize)) {
507 warning("-XX:NewSize and -XX:MaxNewSize override -XX:NewRatio");
508 } else {
509 // Treat NewRatio as a fixed size that is only recalculated when the heap size changes
510 update_young_list_size_using_newratio(_g1->n_regions());
511 _using_new_ratio_calculations = true;
512 }
513 }
514
515 // GenCollectorPolicy guarantees that min <= initial <= max.
516 // Asserting here just to state that we rely on this property.
517 assert(_min_desired_young_length <= _max_desired_young_length, "Invalid min/max young gen size values");
518 assert(initial_region_num <= _max_desired_young_length, "Initial young gen size too large");
519 assert(_min_desired_young_length <= initial_region_num, "Initial young gen size too small");
520
521 set_adaptive_young_list_length(_min_desired_young_length < _max_desired_young_length);
522 if (adaptive_young_list_length()) {
523 _young_list_fixed_length = 0;
524 } else {
525 _young_list_fixed_length = initial_region_num;
526 }
527 _free_regions_at_end_of_collection = _g1->free_regions();
528 update_young_list_target_length();
529 _prev_eden_capacity = _young_list_target_length * HeapRegion::GrainBytes;
530
531 // We may immediately start allocating regions and placing them on the
532 // collection set list. Initialize the per-collection set info
533 start_incremental_cset_building();
534 }
535
536 // Create the jstat counters for the policy.
537 void G1CollectorPolicy::initialize_gc_policy_counters() {
538 _gc_policy_counters = new GCPolicyCounters("GarbageFirst", 1, 3);
539 }
540
541 bool G1CollectorPolicy::predict_will_fit(size_t young_length,
542 double base_time_ms,
543 size_t base_free_regions,
544 double target_pause_time_ms) {
545 if (young_length >= base_free_regions) {
|
457 // The easiest way to deal with the parsing of the NewSize /
458 // MaxNewSize / etc. parameteres is to re-use the code in the
459 // TwoGenerationCollectorPolicy class. This is similar to what
460 // ParallelScavenge does with its GenerationSizer class (see
461 // ParallelScavengeHeap::initialize()). We might change this in the
462 // future, but it's a good start.
463 class G1YoungGenSizer : public TwoGenerationCollectorPolicy {
464 private:
465 size_t size_to_region_num(size_t byte_size) {
466 return MAX2((size_t) 1, byte_size / HeapRegion::GrainBytes);
467 }
468
469 public:
470 G1YoungGenSizer() {
471 initialize_flags();
472 initialize_size_info();
473 }
474 size_t min_young_region_num() {
475 return size_to_region_num(_min_gen0_size);
476 }
477 size_t max_young_region_num() {
478 return size_to_region_num(_max_gen0_size);
479 }
480 };
481
482 void G1CollectorPolicy::update_young_list_size_using_newratio(size_t number_of_heap_regions) {
483 assert(number_of_heap_regions > 0, "Heap must be initialized");
484 size_t young_size = number_of_heap_regions / (NewRatio + 1);
485 _min_desired_young_length = young_size;
486 _max_desired_young_length = young_size;
487 }
488
489 void G1CollectorPolicy::init() {
490 // Set aside an initial future to_space.
491 _g1 = G1CollectedHeap::heap();
492
493 assert(Heap_lock->owned_by_self(), "Locking discipline.");
494
495 initialize_gc_policy_counters();
496
497 G1YoungGenSizer sizer;
498 _min_desired_young_length = sizer.min_young_region_num();
499 _max_desired_young_length = sizer.max_young_region_num();
500
501 if (FLAG_IS_CMDLINE(NewRatio)) {
502 if (FLAG_IS_CMDLINE(NewSize) || FLAG_IS_CMDLINE(MaxNewSize)) {
503 warning("-XX:NewSize and -XX:MaxNewSize override -XX:NewRatio");
504 } else {
505 // Treat NewRatio as a fixed size that is only recalculated when the heap size changes
506 update_young_list_size_using_newratio(_g1->n_regions());
507 _using_new_ratio_calculations = true;
508 }
509 }
510
511 assert(_min_desired_young_length <= _max_desired_young_length, "Invalid min/max young gen size values");
512
513 set_adaptive_young_list_length(_min_desired_young_length < _max_desired_young_length);
514 if (adaptive_young_list_length()) {
515 _young_list_fixed_length = 0;
516 } else {
517 assert(_min_desired_young_length == _max_desired_young_length, "Min and max young size differ");
518 _young_list_fixed_length = _min_desired_young_length;
519 }
520 _free_regions_at_end_of_collection = _g1->free_regions();
521 update_young_list_target_length();
522 _prev_eden_capacity = _young_list_target_length * HeapRegion::GrainBytes;
523
524 // We may immediately start allocating regions and placing them on the
525 // collection set list. Initialize the per-collection set info
526 start_incremental_cset_building();
527 }
528
529 // Create the jstat counters for the policy.
530 void G1CollectorPolicy::initialize_gc_policy_counters() {
531 _gc_policy_counters = new GCPolicyCounters("GarbageFirst", 1, 3);
532 }
533
534 bool G1CollectorPolicy::predict_will_fit(size_t young_length,
535 double base_time_ms,
536 size_t base_free_regions,
537 double target_pause_time_ms) {
538 if (young_length >= base_free_regions) {
|