1 /*
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
265 // Then, if the interval parameter was not set, set it according to
266 // the pause time target (this will also deal with the case when the
267 // pause time target is the default value).
268 if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
269 FLAG_SET_DEFAULT(GCPauseIntervalMillis, MaxGCPauseMillis + 1);
270 }
271
272 // Finally, make sure that the two parameters are consistent.
273 if (MaxGCPauseMillis >= GCPauseIntervalMillis) {
274 char buffer[256];
275 jio_snprintf(buffer, 256,
276 "MaxGCPauseMillis (%u) should be less than "
277 "GCPauseIntervalMillis (%u)",
278 MaxGCPauseMillis, GCPauseIntervalMillis);
279 vm_exit_during_initialization(buffer);
280 }
281
282 double max_gc_time = (double) MaxGCPauseMillis / 1000.0;
283 double time_slice = (double) GCPauseIntervalMillis / 1000.0;
284 _mmu_tracker = new G1MMUTrackerQueue(time_slice, max_gc_time);
285
286 uintx confidence_perc = G1ConfidencePercent;
287 // Put an artificial ceiling on this so that it's not set to a silly value.
288 if (confidence_perc > 100) {
289 confidence_perc = 100;
290 warning("G1ConfidencePercent is set to a value that is too large, "
291 "it's been updated to %u", confidence_perc);
292 }
293 _sigma = (double) confidence_perc / 100.0;
294
295 // start conservatively (around 50ms is about right)
296 _concurrent_mark_remark_times_ms->add(0.05);
297 _concurrent_mark_cleanup_times_ms->add(0.20);
298 _tenuring_threshold = MaxTenuringThreshold;
299 // _max_survivor_regions will be calculated by
300 // update_young_list_target_length() during initialization.
301 _max_survivor_regions = 0;
302
303 assert(GCTimeRatio > 0,
304 "we should have set it to a default value set_g1_gc_flags() "
305 "if a user set it to 0");
306 _gc_overhead_perc = 100.0 * (1.0 / (1.0 + GCTimeRatio));
307
308 uintx reserve_perc = G1ReservePercent;
309 // Put an artificial ceiling on this so that it's not set to a silly value.
310 if (reserve_perc > 50) {
311 reserve_perc = 50;
312 warning("G1ReservePercent is set to a value that is too large, "
313 "it's been updated to %u", reserve_perc);
314 }
315 _reserve_factor = (double) reserve_perc / 100.0;
316 // This will be set when the heap is expanded
317 // for the first time during initialization.
318 _reserve_regions = 0;
319
320 _collectionSetChooser = new CollectionSetChooser();
321 }
322
323 void G1CollectorPolicy::initialize_alignments() {
324 _space_alignment = HeapRegion::GrainBytes;
325 size_t card_table_alignment = GenRemSet::max_alignment_constraint(GenRemSet::CardTable);
326 size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
327 _heap_alignment = MAX3(card_table_alignment, _space_alignment, page_size);
328 }
329
330 void G1CollectorPolicy::initialize_flags() {
331 if (G1HeapRegionSize != HeapRegion::GrainBytes) {
332 FLAG_SET_ERGO(uintx, G1HeapRegionSize, HeapRegion::GrainBytes);
333 }
334
335 if (SurvivorRatio < 1) {
336 vm_exit_during_initialization("Invalid survivor ratio specified");
337 }
338 CollectorPolicy::initialize_flags();
339 _young_gen_sizer = new G1YoungGenSizer(); // Must be after call to initialize_flags
340 }
341
342 void G1CollectorPolicy::post_heap_initialize() {
490
491 size_t free_bytes =
492 (base_free_regions - young_length) * HeapRegion::GrainBytes;
493 if ((2.0 * sigma()) * (double) bytes_to_copy > (double) free_bytes) {
494 // end condition 3: out-of-space (conservatively!)
495 return false;
496 }
497
498 // success!
499 return true;
500 }
501
502 void G1CollectorPolicy::record_new_heap_size(uint new_number_of_regions) {
503 // re-calculate the necessary reserve
504 double reserve_regions_d = (double) new_number_of_regions * _reserve_factor;
505 // We use ceiling so that if reserve_regions_d is > 0.0 (but
506 // smaller than 1.0) we'll get 1.
507 _reserve_regions = (uint) ceil(reserve_regions_d);
508
509 _young_gen_sizer->heap_size_changed(new_number_of_regions);
510 }
511
512 uint G1CollectorPolicy::calculate_young_list_desired_min_length(
513 uint base_min_length) {
514 uint desired_min_length = 0;
515 if (adaptive_young_list_length()) {
516 if (_alloc_rate_ms_seq->num() > 3) {
517 double now_sec = os::elapsedTime();
518 double when_ms = _mmu_tracker->when_max_gc_sec(now_sec) * 1000.0;
519 double alloc_rate_ms = predict_alloc_rate_ms();
520 desired_min_length = (uint) ceil(alloc_rate_ms * when_ms);
521 } else {
522 // otherwise we don't have enough info to make the prediction
523 }
524 }
525 desired_min_length += base_min_length;
526 // make sure we don't go below any user-defined minimum bound
527 return MAX2(_young_gen_sizer->min_desired_young_length(), desired_min_length);
528 }
529
1172 if (_collection_set_bytes_used_before > 0) {
1173 survival_ratio = (double) _bytes_copied_during_gc /
1174 (double) _collection_set_bytes_used_before;
1175 }
1176
1177 _pending_cards_seq->add((double) _pending_cards);
1178 _rs_lengths_seq->add((double) _max_rs_lengths);
1179 }
1180
1181 _in_marking_window = new_in_marking_window;
1182 _in_marking_window_im = new_in_marking_window_im;
1183 _free_regions_at_end_of_collection = _g1->num_free_regions();
1184 update_young_list_target_length();
1185
1186 // Note that _mmu_tracker->max_gc_time() returns the time in seconds.
1187 double update_rs_time_goal_ms = _mmu_tracker->max_gc_time() * MILLIUNITS * G1RSetUpdatingPauseTimePercent / 100.0;
1188 adjust_concurrent_refinement(phase_times()->average_time_ms(G1GCPhaseTimes::UpdateRS),
1189 phase_times()->sum_thread_work_items(G1GCPhaseTimes::UpdateRS), update_rs_time_goal_ms);
1190
1191 _collectionSetChooser->verify();
1192 }
1193
1194 #define EXT_SIZE_FORMAT "%.1f%s"
1195 #define EXT_SIZE_PARAMS(bytes) \
1196 byte_size_in_proper_unit((double)(bytes)), \
1197 proper_unit_for_byte_size((bytes))
1198
1199 void G1CollectorPolicy::record_heap_size_info_at_start(bool full) {
1200 YoungList* young_list = _g1->young_list();
1201 _eden_used_bytes_before_gc = young_list->eden_used_bytes();
1202 _survivor_used_bytes_before_gc = young_list->survivor_used_bytes();
1203 _heap_capacity_bytes_before_gc = _g1->capacity();
1204 _heap_used_bytes_before_gc = _g1->used();
1205 _cur_collection_pause_used_regions_at_start = _g1->num_used_regions();
1206
1207 _eden_capacity_bytes_before_gc =
1208 (_young_list_target_length * HeapRegion::GrainBytes) - _survivor_used_bytes_before_gc;
1209
1210 if (full) {
1211 _metaspace_used_bytes_before_gc = MetaspaceAux::used_bytes();
|
1 /*
2 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
265 // Then, if the interval parameter was not set, set it according to
266 // the pause time target (this will also deal with the case when the
267 // pause time target is the default value).
268 if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
269 FLAG_SET_DEFAULT(GCPauseIntervalMillis, MaxGCPauseMillis + 1);
270 }
271
272 // Finally, make sure that the two parameters are consistent.
273 if (MaxGCPauseMillis >= GCPauseIntervalMillis) {
274 char buffer[256];
275 jio_snprintf(buffer, 256,
276 "MaxGCPauseMillis (%u) should be less than "
277 "GCPauseIntervalMillis (%u)",
278 MaxGCPauseMillis, GCPauseIntervalMillis);
279 vm_exit_during_initialization(buffer);
280 }
281
282 double max_gc_time = (double) MaxGCPauseMillis / 1000.0;
283 double time_slice = (double) GCPauseIntervalMillis / 1000.0;
284 _mmu_tracker = new G1MMUTrackerQueue(time_slice, max_gc_time);
285 if (EnableJFR) {
286 _ihop_control = create_ihop_control();
287 }
288
289 uintx confidence_perc = G1ConfidencePercent;
290 // Put an artificial ceiling on this so that it's not set to a silly value.
291 if (confidence_perc > 100) {
292 confidence_perc = 100;
293 warning("G1ConfidencePercent is set to a value that is too large, "
294 "it's been updated to %u", confidence_perc);
295 }
296 _sigma = (double) confidence_perc / 100.0;
297
298 // start conservatively (around 50ms is about right)
299 _concurrent_mark_remark_times_ms->add(0.05);
300 _concurrent_mark_cleanup_times_ms->add(0.20);
301 _tenuring_threshold = MaxTenuringThreshold;
302 // _max_survivor_regions will be calculated by
303 // update_young_list_target_length() during initialization.
304 _max_survivor_regions = 0;
305
306 assert(GCTimeRatio > 0,
307 "we should have set it to a default value set_g1_gc_flags() "
308 "if a user set it to 0");
309 _gc_overhead_perc = 100.0 * (1.0 / (1.0 + GCTimeRatio));
310
311 uintx reserve_perc = G1ReservePercent;
312 // Put an artificial ceiling on this so that it's not set to a silly value.
313 if (reserve_perc > 50) {
314 reserve_perc = 50;
315 warning("G1ReservePercent is set to a value that is too large, "
316 "it's been updated to %u", reserve_perc);
317 }
318 _reserve_factor = (double) reserve_perc / 100.0;
319 // This will be set when the heap is expanded
320 // for the first time during initialization.
321 _reserve_regions = 0;
322
323 _collectionSetChooser = new CollectionSetChooser();
324 }
325
326 G1CollectorPolicy::~G1CollectorPolicy() {
327 if (EnableJFR) {
328 assert(_ihop_control != NULL, "sanity check");
329 delete _ihop_control;
330 }
331 }
332
333 void G1CollectorPolicy::initialize_alignments() {
334 _space_alignment = HeapRegion::GrainBytes;
335 size_t card_table_alignment = GenRemSet::max_alignment_constraint(GenRemSet::CardTable);
336 size_t page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
337 _heap_alignment = MAX3(card_table_alignment, _space_alignment, page_size);
338 }
339
340 void G1CollectorPolicy::initialize_flags() {
341 if (G1HeapRegionSize != HeapRegion::GrainBytes) {
342 FLAG_SET_ERGO(uintx, G1HeapRegionSize, HeapRegion::GrainBytes);
343 }
344
345 if (SurvivorRatio < 1) {
346 vm_exit_during_initialization("Invalid survivor ratio specified");
347 }
348 CollectorPolicy::initialize_flags();
349 _young_gen_sizer = new G1YoungGenSizer(); // Must be after call to initialize_flags
350 }
351
352 void G1CollectorPolicy::post_heap_initialize() {
500
501 size_t free_bytes =
502 (base_free_regions - young_length) * HeapRegion::GrainBytes;
503 if ((2.0 * sigma()) * (double) bytes_to_copy > (double) free_bytes) {
504 // end condition 3: out-of-space (conservatively!)
505 return false;
506 }
507
508 // success!
509 return true;
510 }
511
512 void G1CollectorPolicy::record_new_heap_size(uint new_number_of_regions) {
513 // re-calculate the necessary reserve
514 double reserve_regions_d = (double) new_number_of_regions * _reserve_factor;
515 // We use ceiling so that if reserve_regions_d is > 0.0 (but
516 // smaller than 1.0) we'll get 1.
517 _reserve_regions = (uint) ceil(reserve_regions_d);
518
519 _young_gen_sizer->heap_size_changed(new_number_of_regions);
520
521 if (EnableJFR) {
522 _ihop_control->update_target_occupancy(new_number_of_regions * HeapRegion::GrainBytes);
523 }
524 }
525
526 uint G1CollectorPolicy::calculate_young_list_desired_min_length(
527 uint base_min_length) {
528 uint desired_min_length = 0;
529 if (adaptive_young_list_length()) {
530 if (_alloc_rate_ms_seq->num() > 3) {
531 double now_sec = os::elapsedTime();
532 double when_ms = _mmu_tracker->when_max_gc_sec(now_sec) * 1000.0;
533 double alloc_rate_ms = predict_alloc_rate_ms();
534 desired_min_length = (uint) ceil(alloc_rate_ms * when_ms);
535 } else {
536 // otherwise we don't have enough info to make the prediction
537 }
538 }
539 desired_min_length += base_min_length;
540 // make sure we don't go below any user-defined minimum bound
541 return MAX2(_young_gen_sizer->min_desired_young_length(), desired_min_length);
542 }
543
1186 if (_collection_set_bytes_used_before > 0) {
1187 survival_ratio = (double) _bytes_copied_during_gc /
1188 (double) _collection_set_bytes_used_before;
1189 }
1190
1191 _pending_cards_seq->add((double) _pending_cards);
1192 _rs_lengths_seq->add((double) _max_rs_lengths);
1193 }
1194
1195 _in_marking_window = new_in_marking_window;
1196 _in_marking_window_im = new_in_marking_window_im;
1197 _free_regions_at_end_of_collection = _g1->num_free_regions();
1198 update_young_list_target_length();
1199
1200 // Note that _mmu_tracker->max_gc_time() returns the time in seconds.
1201 double update_rs_time_goal_ms = _mmu_tracker->max_gc_time() * MILLIUNITS * G1RSetUpdatingPauseTimePercent / 100.0;
1202 adjust_concurrent_refinement(phase_times()->average_time_ms(G1GCPhaseTimes::UpdateRS),
1203 phase_times()->sum_thread_work_items(G1GCPhaseTimes::UpdateRS), update_rs_time_goal_ms);
1204
1205 _collectionSetChooser->verify();
1206
1207 if (EnableJFR) {
1208 _ihop_control->send_trace_event(_g1->gc_tracer_stw());
1209 }
1210 }
1211
1212 G1IHOPControl* G1CollectorPolicy::create_ihop_control() {
1213 assert(EnableJFR, "sanity check");
1214 return new G1StaticIHOPControl(InitiatingHeapOccupancyPercent);
1215 }
1216
1217 #define EXT_SIZE_FORMAT "%.1f%s"
1218 #define EXT_SIZE_PARAMS(bytes) \
1219 byte_size_in_proper_unit((double)(bytes)), \
1220 proper_unit_for_byte_size((bytes))
1221
1222 void G1CollectorPolicy::record_heap_size_info_at_start(bool full) {
1223 YoungList* young_list = _g1->young_list();
1224 _eden_used_bytes_before_gc = young_list->eden_used_bytes();
1225 _survivor_used_bytes_before_gc = young_list->survivor_used_bytes();
1226 _heap_capacity_bytes_before_gc = _g1->capacity();
1227 _heap_used_bytes_before_gc = _g1->used();
1228 _cur_collection_pause_used_regions_at_start = _g1->num_used_regions();
1229
1230 _eden_capacity_bytes_before_gc =
1231 (_young_list_target_length * HeapRegion::GrainBytes) - _survivor_used_bytes_before_gc;
1232
1233 if (full) {
1234 _metaspace_used_bytes_before_gc = MetaspaceAux::used_bytes();
|