99 // the heap size changes, the limits for the young gen size will be
100 // recalculated.
101 //
102 // If only -XX:NewSize is set we should use the specified value as the
103 // minimum size for young gen. Still using G1MaxNewSizePercent of the
104 // heap as maximum.
105 //
106 // If only -XX:MaxNewSize is set we should use the specified value as the
107 // maximum size for young gen. Still using G1NewSizePercent of the heap
108 // as minimum.
109 //
110 // If -XX:NewSize and -XX:MaxNewSize are both specified we use these values.
111 // No updates when the heap size changes. There is a special case when
112 // NewSize==MaxNewSize. This is interpreted as "fixed" and will use a
113 // different heuristic for calculating the collection set when we do mixed
114 // collection.
115 //
116 // If only -XX:NewRatio is set we should use the specified ratio of the heap
117 // as both min and max. This will be interpreted as "fixed" just like the
118 // NewSize==MaxNewSize case above. But we will update the min and max
119 // everytime the heap size changes.
120 //
121 // NewSize and MaxNewSize override NewRatio. So, NewRatio is ignored if it is
122 // combined with either NewSize or MaxNewSize. (A warning message is printed.)
123 class G1YoungGenSizer : public CHeapObj<mtGC> {
124 private:
125 enum SizerKind {
126 SizerDefaults,
127 SizerNewSizeOnly,
128 SizerMaxNewSizeOnly,
129 SizerMaxAndNewSize,
130 SizerNewRatio
131 };
132 SizerKind _sizer_kind;
133 uint _min_desired_young_length;
134 uint _max_desired_young_length;
135 bool _adaptive_size;
136 uint calculate_default_min_length(uint new_number_of_heap_regions);
137 uint calculate_default_max_length(uint new_number_of_heap_regions);
138
139 // Update the given values for minimum and maximum young gen length in regions
506 HeapRegion* _inc_cset_head;
507
508 // The tail of the incrementally built collection set.
509 HeapRegion* _inc_cset_tail;
510
511 // The number of bytes in the incrementally built collection set.
512 // Used to set _collection_set_bytes_used_before at the start of
513 // an evacuation pause.
514 size_t _inc_cset_bytes_used_before;
515
516 // Used to record the highest end of heap region in collection set
517 HeapWord* _inc_cset_max_finger;
518
519 // The RSet lengths recorded for regions in the CSet. It is updated
520 // by the thread that adds a new region to the CSet. We assume that
521 // only one thread can be allocating a new CSet region (currently,
522 // it does so after taking the Heap_lock) hence no need to
523 // synchronize updates to this field.
524 size_t _inc_cset_recorded_rs_lengths;
525
526 // A concurrent refinement thread periodcially samples the young
527 // region RSets and needs to update _inc_cset_recorded_rs_lengths as
528 // the RSets grow. Instead of having to syncronize updates to that
529 // field we accumulate them in this field and add it to
530 // _inc_cset_recorded_rs_lengths_diffs at the start of a GC.
531 ssize_t _inc_cset_recorded_rs_lengths_diffs;
532
533 // The predicted elapsed time it will take to collect the regions in
534 // the CSet. This is updated by the thread that adds a new region to
535 // the CSet. See the comment for _inc_cset_recorded_rs_lengths about
536 // MT-safety assumptions.
537 double _inc_cset_predicted_elapsed_time_ms;
538
539 // See the comment for _inc_cset_recorded_rs_lengths_diffs.
540 double _inc_cset_predicted_elapsed_time_ms_diffs;
541
542 // Stash a pointer to the g1 heap.
543 G1CollectedHeap* _g1;
544
545 G1GCPhaseTimes* _phase_times;
546
547 // The ratio of gc time to elapsed time, computed over recent pauses.
548 double _recent_avg_pause_time_ratio;
587 // Update the young list target length either by setting it to the
588 // desired fixed value or by calculating it using G1's pause
589 // prediction model. If no rs_lengths parameter is passed, predict
590 // the RS lengths using the prediction model, otherwise use the
591 // given rs_lengths as the prediction.
592 void update_young_list_target_length(size_t rs_lengths = (size_t) -1);
593
594 // Calculate and return the minimum desired young list target
595 // length. This is the minimum desired young list length according
596 // to the user's inputs.
597 uint calculate_young_list_desired_min_length(uint base_min_length);
598
599 // Calculate and return the maximum desired young list target
600 // length. This is the maximum desired young list length according
601 // to the user's inputs.
602 uint calculate_young_list_desired_max_length();
603
604 // Calculate and return the maximum young list target length that
605 // can fit into the pause time goal. The parameters are: rs_lengths
606 // represent the prediction of how large the young RSet lengths will
607 // be, base_min_length is the alreay existing number of regions in
608 // the young list, min_length and max_length are the desired min and
609 // max young list length according to the user's inputs.
610 uint calculate_young_list_target_length(size_t rs_lengths,
611 uint base_min_length,
612 uint desired_min_length,
613 uint desired_max_length);
614
615 // Check whether a given young length (young_length) fits into the
616 // given target pause time and whether the prediction for the amount
617 // of objects to be copied for the given length will fit into the
618 // given free space (expressed by base_free_regions). It is used by
619 // calculate_young_list_target_length().
620 bool predict_will_fit(uint young_length, double base_time_ms,
621 uint base_free_regions, double target_pause_time_ms);
622
623 // Calculate the minimum number of old regions we'll add to the CSet
624 // during a mixed GC.
625 uint calc_min_old_cset_length();
626
627 // Calculate the maximum number of old regions we'll add to the CSet
|
99 // the heap size changes, the limits for the young gen size will be
100 // recalculated.
101 //
102 // If only -XX:NewSize is set we should use the specified value as the
103 // minimum size for young gen. Still using G1MaxNewSizePercent of the
104 // heap as maximum.
105 //
106 // If only -XX:MaxNewSize is set we should use the specified value as the
107 // maximum size for young gen. Still using G1NewSizePercent of the heap
108 // as minimum.
109 //
110 // If -XX:NewSize and -XX:MaxNewSize are both specified we use these values.
111 // No updates when the heap size changes. There is a special case when
112 // NewSize==MaxNewSize. This is interpreted as "fixed" and will use a
113 // different heuristic for calculating the collection set when we do mixed
114 // collection.
115 //
116 // If only -XX:NewRatio is set we should use the specified ratio of the heap
117 // as both min and max. This will be interpreted as "fixed" just like the
118 // NewSize==MaxNewSize case above. But we will update the min and max
119 // every time the heap size changes.
120 //
121 // NewSize and MaxNewSize override NewRatio. So, NewRatio is ignored if it is
122 // combined with either NewSize or MaxNewSize. (A warning message is printed.)
123 class G1YoungGenSizer : public CHeapObj<mtGC> {
124 private:
125 enum SizerKind {
126 SizerDefaults,
127 SizerNewSizeOnly,
128 SizerMaxNewSizeOnly,
129 SizerMaxAndNewSize,
130 SizerNewRatio
131 };
132 SizerKind _sizer_kind;
133 uint _min_desired_young_length;
134 uint _max_desired_young_length;
135 bool _adaptive_size;
136 uint calculate_default_min_length(uint new_number_of_heap_regions);
137 uint calculate_default_max_length(uint new_number_of_heap_regions);
138
139 // Update the given values for minimum and maximum young gen length in regions
506 HeapRegion* _inc_cset_head;
507
508 // The tail of the incrementally built collection set.
509 HeapRegion* _inc_cset_tail;
510
511 // The number of bytes in the incrementally built collection set.
512 // Used to set _collection_set_bytes_used_before at the start of
513 // an evacuation pause.
514 size_t _inc_cset_bytes_used_before;
515
516 // Used to record the highest end of heap region in collection set
517 HeapWord* _inc_cset_max_finger;
518
519 // The RSet lengths recorded for regions in the CSet. It is updated
520 // by the thread that adds a new region to the CSet. We assume that
521 // only one thread can be allocating a new CSet region (currently,
522 // it does so after taking the Heap_lock) hence no need to
523 // synchronize updates to this field.
524 size_t _inc_cset_recorded_rs_lengths;
525
526 // A concurrent refinement thread periodically samples the young
527 // region RSets and needs to update _inc_cset_recorded_rs_lengths as
528 // the RSets grow. Instead of having to synchronize updates to that
529 // field we accumulate them in this field and add it to
530 // _inc_cset_recorded_rs_lengths_diffs at the start of a GC.
531 ssize_t _inc_cset_recorded_rs_lengths_diffs;
532
533 // The predicted elapsed time it will take to collect the regions in
534 // the CSet. This is updated by the thread that adds a new region to
535 // the CSet. See the comment for _inc_cset_recorded_rs_lengths about
536 // MT-safety assumptions.
537 double _inc_cset_predicted_elapsed_time_ms;
538
539 // See the comment for _inc_cset_recorded_rs_lengths_diffs.
540 double _inc_cset_predicted_elapsed_time_ms_diffs;
541
542 // Stash a pointer to the g1 heap.
543 G1CollectedHeap* _g1;
544
545 G1GCPhaseTimes* _phase_times;
546
547 // The ratio of gc time to elapsed time, computed over recent pauses.
548 double _recent_avg_pause_time_ratio;
587 // Update the young list target length either by setting it to the
588 // desired fixed value or by calculating it using G1's pause
589 // prediction model. If no rs_lengths parameter is passed, predict
590 // the RS lengths using the prediction model, otherwise use the
591 // given rs_lengths as the prediction.
592 void update_young_list_target_length(size_t rs_lengths = (size_t) -1);
593
594 // Calculate and return the minimum desired young list target
595 // length. This is the minimum desired young list length according
596 // to the user's inputs.
597 uint calculate_young_list_desired_min_length(uint base_min_length);
598
599 // Calculate and return the maximum desired young list target
600 // length. This is the maximum desired young list length according
601 // to the user's inputs.
602 uint calculate_young_list_desired_max_length();
603
604 // Calculate and return the maximum young list target length that
605 // can fit into the pause time goal. The parameters are: rs_lengths
606 // represent the prediction of how large the young RSet lengths will
607 // be, base_min_length is the already existing number of regions in
608 // the young list, min_length and max_length are the desired min and
609 // max young list length according to the user's inputs.
610 uint calculate_young_list_target_length(size_t rs_lengths,
611 uint base_min_length,
612 uint desired_min_length,
613 uint desired_max_length);
614
615 // Check whether a given young length (young_length) fits into the
616 // given target pause time and whether the prediction for the amount
617 // of objects to be copied for the given length will fit into the
618 // given free space (expressed by base_free_regions). It is used by
619 // calculate_young_list_target_length().
620 bool predict_will_fit(uint young_length, double base_time_ms,
621 uint base_free_regions, double target_pause_time_ms);
622
623 // Calculate the minimum number of old regions we'll add to the CSet
624 // during a mixed GC.
625 uint calc_min_old_cset_length();
626
627 // Calculate the maximum number of old regions we'll add to the CSet
|