127 _predictor(predictor),
128 _marking_times_s(10, 0.95),
129 _allocation_rate_s(10, 0.95),
130 _last_unrestrained_young_size(0),
131 _heap_reserve_percent(heap_reserve_percent),
132 _heap_waste_percent(heap_waste_percent)
133 {
134 }
135
136 size_t G1AdaptiveIHOPControl::actual_target_threshold() const {
137 // The actual target threshold takes the heap reserve and the expected waste in
138 // free space into account.
139 // _heap_reserve is that part of the total heap capacity that is reserved for
140 // eventual promotion failure.
141 // _heap_waste is the amount of space will never be reclaimed in any
142 // heap, so can not be used for allocation during marking and must always be
143 // considered.
144
145 double safe_total_heap_percentage = MIN2((double)(_heap_reserve_percent + _heap_waste_percent), 100.0);
146
147 return MIN2(
148 G1CollectedHeap::heap()->max_capacity() * (100.0 - safe_total_heap_percentage) / 100.0,
149 _target_occupancy * (100.0 - _heap_waste_percent) / 100.0
150 );
151 }
152
153 bool G1AdaptiveIHOPControl::have_enough_data_for_prediction() const {
154 return ((size_t)_marking_times_s.num() >= G1AdaptiveIHOPNumInitialSamples) &&
155 ((size_t)_allocation_rate_s.num() >= G1AdaptiveIHOPNumInitialSamples);
156 }
157
158 size_t G1AdaptiveIHOPControl::get_conc_mark_start_threshold() {
159 if (have_enough_data_for_prediction()) {
160 double pred_marking_time = _predictor->get_new_prediction(&_marking_times_s);
161 double pred_promotion_rate = _predictor->get_new_prediction(&_allocation_rate_s);
162
163 size_t predicted_needed_bytes_during_marking =
164 (pred_marking_time * pred_promotion_rate +
165 _last_unrestrained_young_size); // In reality we would need the maximum size of the young gen during marking. This is a conservative estimate.
166
167 size_t internal_threshold = actual_target_threshold();
168 size_t predicted_initiating_threshold = predicted_needed_bytes_during_marking < internal_threshold ?
169 internal_threshold - predicted_needed_bytes_during_marking :
170 0;
171 return predicted_initiating_threshold;
172 } else {
173 // Use the initial value.
174 return _initial_ihop_percent * _target_occupancy / 100.0;
175 }
176 }
177
178 void G1AdaptiveIHOPControl::update_allocation_info(double allocation_time_s, size_t allocated_bytes, size_t additional_buffer_size) {
179 G1IHOPControl::update_allocation_info(allocation_time_s, allocated_bytes, additional_buffer_size);
180
181 double allocation_rate = (double) allocated_bytes / allocation_time_s;
182 _allocation_rate_s.add(allocation_rate);
183
184 _last_unrestrained_young_size = additional_buffer_size;
185 }
186
187 void G1AdaptiveIHOPControl::update_marking_length(double marking_length_s) {
188 assert(marking_length_s >= 0.0, "Marking length must be larger than zero but is %.3f", marking_length_s);
189 _marking_times_s.add(marking_length_s);
190 }
191
192 void G1AdaptiveIHOPControl::print() {
193 G1IHOPControl::print();
194 size_t actual_target = actual_target_threshold();
195 ergo_verbose6(ErgoIHOP,
196 "adaptive IHOP information",
197 ergo_format_reason("value update")
198 ergo_format_byte_perc("threshold")
|
127 _predictor(predictor),
128 _marking_times_s(10, 0.95),
129 _allocation_rate_s(10, 0.95),
130 _last_unrestrained_young_size(0),
131 _heap_reserve_percent(heap_reserve_percent),
132 _heap_waste_percent(heap_waste_percent)
133 {
134 }
135
136 size_t G1AdaptiveIHOPControl::actual_target_threshold() const {
137 // The actual target threshold takes the heap reserve and the expected waste in
138 // free space into account.
139 // _heap_reserve is that part of the total heap capacity that is reserved for
140 // eventual promotion failure.
141 // _heap_waste is the amount of space will never be reclaimed in any
142 // heap, so can not be used for allocation during marking and must always be
143 // considered.
144
145 double safe_total_heap_percentage = MIN2((double)(_heap_reserve_percent + _heap_waste_percent), 100.0);
146
147 return (size_t)MIN2(
148 (G1CollectedHeap::heap()->max_capacity() * (100.0 - safe_total_heap_percentage) / 100.0),
149 (_target_occupancy * (100.0 - (float)_heap_waste_percent) / 100.0)
150 );
151 }
152
153 bool G1AdaptiveIHOPControl::have_enough_data_for_prediction() const {
154 return ((size_t)_marking_times_s.num() >= G1AdaptiveIHOPNumInitialSamples) &&
155 ((size_t)_allocation_rate_s.num() >= G1AdaptiveIHOPNumInitialSamples);
156 }
157
158 size_t G1AdaptiveIHOPControl::get_conc_mark_start_threshold() {
159 if (have_enough_data_for_prediction()) {
160 double pred_marking_time = _predictor->get_new_prediction(&_marking_times_s);
161 double pred_promotion_rate = _predictor->get_new_prediction(&_allocation_rate_s);
162
163 size_t predicted_needed_bytes_during_marking =
164 ((size_t)(pred_marking_time * pred_promotion_rate) +
165 _last_unrestrained_young_size); // In reality we would need the maximum size of the young gen during marking. This is a conservative estimate.
166
167 size_t internal_threshold = actual_target_threshold();
168 size_t predicted_initiating_threshold = predicted_needed_bytes_during_marking < internal_threshold ?
169 internal_threshold - predicted_needed_bytes_during_marking :
170 0;
171 return predicted_initiating_threshold;
172 } else {
173 // Use the initial value.
174 return (size_t)(_initial_ihop_percent * _target_occupancy / 100.0);
175 }
176 }
177
178 void G1AdaptiveIHOPControl::update_allocation_info(double allocation_time_s, size_t allocated_bytes,
179 size_t additional_buffer_size) {
180 G1IHOPControl::update_allocation_info(allocation_time_s, allocated_bytes, additional_buffer_size);
181
182 double allocation_rate = (double) allocated_bytes / allocation_time_s;
183 _allocation_rate_s.add(allocation_rate);
184
185 _last_unrestrained_young_size = additional_buffer_size;
186 }
187
188 void G1AdaptiveIHOPControl::update_marking_length(double marking_length_s) {
189 assert(marking_length_s >= 0.0, "Marking length must be larger than zero but is %.3f", marking_length_s);
190 _marking_times_s.add(marking_length_s);
191 }
192
193 void G1AdaptiveIHOPControl::print() {
194 G1IHOPControl::print();
195 size_t actual_target = actual_target_threshold();
196 ergo_verbose6(ErgoIHOP,
197 "adaptive IHOP information",
198 ergo_format_reason("value update")
199 ergo_format_byte_perc("threshold")
|