389 }
390
391 assert(_min_desired_young_length <= _max_desired_young_length, "Invalid min/max young gen size values");
392 }
393
394 void G1CollectorPolicy::init() {
395 // Set aside an initial future to_space.
396 _g1 = G1CollectedHeap::heap();
397
398 assert(Heap_lock->owned_by_self(), "Locking discipline.");
399
400 initialize_gc_policy_counters();
401
402 if (adaptive_young_list_length()) {
403 _young_list_fixed_length = 0;
404 } else {
405 _young_list_fixed_length = _young_gen_sizer->min_desired_young_length();
406 }
407 _free_regions_at_end_of_collection = _g1->free_regions();
408 update_young_list_target_length();
409 _prev_eden_capacity = _young_list_target_length * HeapRegion::GrainBytes;
410
411 // We may immediately start allocating regions and placing them on the
412 // collection set list. Initialize the per-collection set info
413 start_incremental_cset_building();
414 }
415
416 // Create the jstat counters for the policy.
417 void G1CollectorPolicy::initialize_gc_policy_counters() {
418 _gc_policy_counters = new GCPolicyCounters("GarbageFirst", 1, 3);
419 }
420
421 bool G1CollectorPolicy::predict_will_fit(uint young_length,
422 double base_time_ms,
423 uint base_free_regions,
424 double target_pause_time_ms) {
425 if (young_length >= base_free_regions) {
426 // end condition 1: not enough space for the young regions
427 return false;
428 }
429
729 if (age < 0) {
730 gclog_or_tty->print_cr("## %s: encountered negative age", name);
731 ret = false;
732 }
733
734 if (age <= prev_age) {
735 gclog_or_tty->print_cr("## %s: region ages are not strictly increasing "
736 "(%d, %d)", name, age, prev_age);
737 ret = false;
738 }
739 prev_age = age;
740 }
741 }
742
743 return ret;
744 }
745 #endif // PRODUCT
746
747 void G1CollectorPolicy::record_full_collection_start() {
748 _full_collection_start_sec = os::elapsedTime();
749 // Release the future to-space so that it is available for compaction into.
750 _g1->set_full_collection();
751 }
752
753 void G1CollectorPolicy::record_full_collection_end() {
754 // Consider this like a collection pause for the purposes of allocation
755 // since last pause.
756 double end_sec = os::elapsedTime();
757 double full_gc_time_sec = end_sec - _full_collection_start_sec;
758 double full_gc_time_ms = full_gc_time_sec * 1000.0;
759
760 _trace_gen1_time_data.record_full_collection(full_gc_time_ms);
761
762 update_recent_gc_times(end_sec, full_gc_time_ms);
763
764 _g1->clear_full_collection();
765
766 // "Nuke" the heuristics that control the young/mixed GC
767 // transitions and make sure we start with young GCs after the Full GC.
768 set_gcs_are_young(true);
771 clear_during_initial_mark_pause();
772 _in_marking_window = false;
773 _in_marking_window_im = false;
774
775 _short_lived_surv_rate_group->start_adding_regions();
776 // also call this on any additional surv rate groups
777
778 record_survivor_regions(0, NULL, NULL);
779
780 _free_regions_at_end_of_collection = _g1->free_regions();
781 // Reset survivors SurvRateGroup.
782 _survivor_surv_rate_group->reset();
783 update_young_list_target_length();
784 _collectionSetChooser->clear();
785 }
786
787 void G1CollectorPolicy::record_stop_world_start() {
788 _stop_world_start = os::elapsedTime();
789 }
790
791 void G1CollectorPolicy::record_collection_pause_start(double start_time_sec,
792 size_t start_used) {
793 // We only need to do this here as the policy will only be applied
794 // to the GC we're about to start. so, no point is calculating this
795 // every time we calculate / recalculate the target young length.
796 update_survivors_policy();
797
798 assert(_g1->used() == _g1->recalculate_used(),
799 err_msg("sanity, used: "SIZE_FORMAT" recalculate_used: "SIZE_FORMAT,
800 _g1->used(), _g1->recalculate_used()));
801
802 double s_w_t_ms = (start_time_sec - _stop_world_start) * 1000.0;
803 _trace_gen0_time_data.record_start_collection(s_w_t_ms);
804 _stop_world_start = 0.0;
805
806 phase_times()->record_cur_collection_start_sec(start_time_sec);
807 _cur_collection_pause_used_at_start_bytes = start_used;
808 _cur_collection_pause_used_regions_at_start = _g1->used_regions();
809 _pending_cards = _g1->pending_card_num();
810
811 _collection_set_bytes_used_before = 0;
812 _bytes_copied_during_gc = 0;
813
814 YoungList* young_list = _g1->young_list();
815 _eden_bytes_before_gc = young_list->eden_used_bytes();
816 _survivor_bytes_before_gc = young_list->survivor_used_bytes();
817 _capacity_before_gc = _g1->capacity();
818
819 _last_gc_was_young = false;
820
821 // do that for any other surv rate groups
822 _short_lived_surv_rate_group->stop_adding_regions();
823 _survivors_age_table.clear();
824
825 assert( verify_young_ages(), "region age verification" );
826 }
827
828 void G1CollectorPolicy::record_concurrent_mark_init_end(double
829 mark_init_elapsed_time_ms) {
830 _during_marking = true;
831 assert(!initiate_conc_mark_if_possible(), "we should have cleared it by now");
832 clear_during_initial_mark_pause();
833 _cur_mark_stop_world_time_ms = mark_init_elapsed_time_ms;
834 }
835
836 void G1CollectorPolicy::record_concurrent_mark_remark_start() {
837 _mark_remark_start_sec = os::elapsedTime();
838 _during_marking = false;
1136 }
1137
1138 _in_marking_window = new_in_marking_window;
1139 _in_marking_window_im = new_in_marking_window_im;
1140 _free_regions_at_end_of_collection = _g1->free_regions();
1141 update_young_list_target_length();
1142
1143 // Note that _mmu_tracker->max_gc_time() returns the time in seconds.
1144 double update_rs_time_goal_ms = _mmu_tracker->max_gc_time() * MILLIUNITS * G1RSetUpdatingPauseTimePercent / 100.0;
1145 adjust_concurrent_refinement(phase_times()->average_last_update_rs_time(),
1146 phase_times()->sum_last_update_rs_processed_buffers(), update_rs_time_goal_ms);
1147
1148 _collectionSetChooser->verify();
1149 }
1150
1151 #define EXT_SIZE_FORMAT "%.1f%s"
1152 #define EXT_SIZE_PARAMS(bytes) \
1153 byte_size_in_proper_unit((double)(bytes)), \
1154 proper_unit_for_byte_size((bytes))
1155
1156 void G1CollectorPolicy::print_heap_transition() {
1157 _g1->print_size_transition(gclog_or_tty,
1158 _cur_collection_pause_used_at_start_bytes, _g1->used(), _g1->capacity());
1159 }
1160
1161 void G1CollectorPolicy::print_detailed_heap_transition() {
1162 YoungList* young_list = _g1->young_list();
1163 size_t eden_bytes = young_list->eden_used_bytes();
1164 size_t survivor_bytes = young_list->survivor_used_bytes();
1165 size_t used_before_gc = _cur_collection_pause_used_at_start_bytes;
1166 size_t used = _g1->used();
1167 size_t capacity = _g1->capacity();
1168 size_t eden_capacity =
1169 (_young_list_target_length * HeapRegion::GrainBytes) - survivor_bytes;
1170
1171 gclog_or_tty->print_cr(
1172 " [Eden: "EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")->"EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT") "
1173 "Survivors: "EXT_SIZE_FORMAT"->"EXT_SIZE_FORMAT" "
1174 "Heap: "EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")->"
1175 EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")]",
1176 EXT_SIZE_PARAMS(_eden_bytes_before_gc),
1177 EXT_SIZE_PARAMS(_prev_eden_capacity),
1178 EXT_SIZE_PARAMS(eden_bytes),
1179 EXT_SIZE_PARAMS(eden_capacity),
1180 EXT_SIZE_PARAMS(_survivor_bytes_before_gc),
1181 EXT_SIZE_PARAMS(survivor_bytes),
1182 EXT_SIZE_PARAMS(used_before_gc),
1183 EXT_SIZE_PARAMS(_capacity_before_gc),
1184 EXT_SIZE_PARAMS(used),
1185 EXT_SIZE_PARAMS(capacity));
1186
1187 _prev_eden_capacity = eden_capacity;
1188 }
1189
1190 void G1CollectorPolicy::adjust_concurrent_refinement(double update_rs_time,
1191 double update_rs_processed_buffers,
1192 double goal_ms) {
1193 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
1194 ConcurrentG1Refine *cg1r = G1CollectedHeap::heap()->concurrent_g1_refine();
1195
1196 if (G1UseAdaptiveConcRefinement) {
1197 const int k_gy = 3, k_gr = 6;
1198 const double inc_k = 1.1, dec_k = 0.9;
1199
1200 int g = cg1r->green_zone();
1201 if (update_rs_time > goal_ms) {
1202 g = (int)(g * dec_k); // Can become 0, that's OK. That would mean a mutator-only processing.
1203 } else {
1204 if (update_rs_time < goal_ms && update_rs_processed_buffers > g) {
1205 g = (int)MAX2(g * inc_k, g + 1.0);
1206 }
1207 }
|
389 }
390
391 assert(_min_desired_young_length <= _max_desired_young_length, "Invalid min/max young gen size values");
392 }
393
394 void G1CollectorPolicy::init() {
395 // Set aside an initial future to_space.
396 _g1 = G1CollectedHeap::heap();
397
398 assert(Heap_lock->owned_by_self(), "Locking discipline.");
399
400 initialize_gc_policy_counters();
401
402 if (adaptive_young_list_length()) {
403 _young_list_fixed_length = 0;
404 } else {
405 _young_list_fixed_length = _young_gen_sizer->min_desired_young_length();
406 }
407 _free_regions_at_end_of_collection = _g1->free_regions();
408 update_young_list_target_length();
409
410 // We may immediately start allocating regions and placing them on the
411 // collection set list. Initialize the per-collection set info
412 start_incremental_cset_building();
413 }
414
415 // Create the jstat counters for the policy.
416 void G1CollectorPolicy::initialize_gc_policy_counters() {
417 _gc_policy_counters = new GCPolicyCounters("GarbageFirst", 1, 3);
418 }
419
420 bool G1CollectorPolicy::predict_will_fit(uint young_length,
421 double base_time_ms,
422 uint base_free_regions,
423 double target_pause_time_ms) {
424 if (young_length >= base_free_regions) {
425 // end condition 1: not enough space for the young regions
426 return false;
427 }
428
728 if (age < 0) {
729 gclog_or_tty->print_cr("## %s: encountered negative age", name);
730 ret = false;
731 }
732
733 if (age <= prev_age) {
734 gclog_or_tty->print_cr("## %s: region ages are not strictly increasing "
735 "(%d, %d)", name, age, prev_age);
736 ret = false;
737 }
738 prev_age = age;
739 }
740 }
741
742 return ret;
743 }
744 #endif // PRODUCT
745
746 void G1CollectorPolicy::record_full_collection_start() {
747 _full_collection_start_sec = os::elapsedTime();
748 record_heap_size_info_at_start();
749 // Release the future to-space so that it is available for compaction into.
750 _g1->set_full_collection();
751 }
752
753 void G1CollectorPolicy::record_full_collection_end() {
754 // Consider this like a collection pause for the purposes of allocation
755 // since last pause.
756 double end_sec = os::elapsedTime();
757 double full_gc_time_sec = end_sec - _full_collection_start_sec;
758 double full_gc_time_ms = full_gc_time_sec * 1000.0;
759
760 _trace_gen1_time_data.record_full_collection(full_gc_time_ms);
761
762 update_recent_gc_times(end_sec, full_gc_time_ms);
763
764 _g1->clear_full_collection();
765
766 // "Nuke" the heuristics that control the young/mixed GC
767 // transitions and make sure we start with young GCs after the Full GC.
768 set_gcs_are_young(true);
771 clear_during_initial_mark_pause();
772 _in_marking_window = false;
773 _in_marking_window_im = false;
774
775 _short_lived_surv_rate_group->start_adding_regions();
776 // also call this on any additional surv rate groups
777
778 record_survivor_regions(0, NULL, NULL);
779
780 _free_regions_at_end_of_collection = _g1->free_regions();
781 // Reset survivors SurvRateGroup.
782 _survivor_surv_rate_group->reset();
783 update_young_list_target_length();
784 _collectionSetChooser->clear();
785 }
786
787 void G1CollectorPolicy::record_stop_world_start() {
788 _stop_world_start = os::elapsedTime();
789 }
790
791 void G1CollectorPolicy::record_collection_pause_start(double start_time_sec) {
792 // We only need to do this here as the policy will only be applied
793 // to the GC we're about to start. so, no point is calculating this
794 // every time we calculate / recalculate the target young length.
795 update_survivors_policy();
796
797 assert(_g1->used() == _g1->recalculate_used(),
798 err_msg("sanity, used: "SIZE_FORMAT" recalculate_used: "SIZE_FORMAT,
799 _g1->used(), _g1->recalculate_used()));
800
801 double s_w_t_ms = (start_time_sec - _stop_world_start) * 1000.0;
802 _trace_gen0_time_data.record_start_collection(s_w_t_ms);
803 _stop_world_start = 0.0;
804
805 record_heap_size_info_at_start();
806
807 phase_times()->record_cur_collection_start_sec(start_time_sec);
808 _pending_cards = _g1->pending_card_num();
809
810 _collection_set_bytes_used_before = 0;
811 _bytes_copied_during_gc = 0;
812
813 _last_gc_was_young = false;
814
815 // do that for any other surv rate groups
816 _short_lived_surv_rate_group->stop_adding_regions();
817 _survivors_age_table.clear();
818
819 assert( verify_young_ages(), "region age verification" );
820 }
821
822 void G1CollectorPolicy::record_concurrent_mark_init_end(double
823 mark_init_elapsed_time_ms) {
824 _during_marking = true;
825 assert(!initiate_conc_mark_if_possible(), "we should have cleared it by now");
826 clear_during_initial_mark_pause();
827 _cur_mark_stop_world_time_ms = mark_init_elapsed_time_ms;
828 }
829
830 void G1CollectorPolicy::record_concurrent_mark_remark_start() {
831 _mark_remark_start_sec = os::elapsedTime();
832 _during_marking = false;
1130 }
1131
1132 _in_marking_window = new_in_marking_window;
1133 _in_marking_window_im = new_in_marking_window_im;
1134 _free_regions_at_end_of_collection = _g1->free_regions();
1135 update_young_list_target_length();
1136
1137 // Note that _mmu_tracker->max_gc_time() returns the time in seconds.
1138 double update_rs_time_goal_ms = _mmu_tracker->max_gc_time() * MILLIUNITS * G1RSetUpdatingPauseTimePercent / 100.0;
1139 adjust_concurrent_refinement(phase_times()->average_last_update_rs_time(),
1140 phase_times()->sum_last_update_rs_processed_buffers(), update_rs_time_goal_ms);
1141
1142 _collectionSetChooser->verify();
1143 }
1144
1145 #define EXT_SIZE_FORMAT "%.1f%s"
1146 #define EXT_SIZE_PARAMS(bytes) \
1147 byte_size_in_proper_unit((double)(bytes)), \
1148 proper_unit_for_byte_size((bytes))
1149
1150 void G1CollectorPolicy::record_heap_size_info_at_start() {
1151 YoungList* young_list = _g1->young_list();
1152 _eden_bytes_before_gc = young_list->eden_used_bytes();
1153 _survivor_bytes_before_gc = young_list->survivor_used_bytes();
1154 _capacity_before_gc = _g1->capacity();
1155
1156 _cur_collection_pause_used_at_start_bytes = _g1->used();
1157 _cur_collection_pause_used_regions_at_start = _g1->used_regions();
1158
1159 size_t eden_capacity_before_gc =
1160 (_young_list_target_length * HeapRegion::GrainBytes) - _survivor_bytes_before_gc;
1161
1162 _prev_eden_capacity = eden_capacity_before_gc;
1163 }
1164
1165 void G1CollectorPolicy::print_heap_transition() {
1166 _g1->print_size_transition(gclog_or_tty,
1167 _cur_collection_pause_used_at_start_bytes, _g1->used(), _g1->capacity());
1168 }
1169
1170 void G1CollectorPolicy::print_detailed_heap_transition() {
1171 YoungList* young_list = _g1->young_list();
1172 size_t eden_bytes = young_list->eden_used_bytes();
1173 size_t survivor_bytes = young_list->survivor_used_bytes();
1174 size_t used_before_gc = _cur_collection_pause_used_at_start_bytes;
1175 size_t used = _g1->used();
1176 size_t capacity = _g1->capacity();
1177 size_t eden_capacity =
1178 (_young_list_target_length * HeapRegion::GrainBytes) - survivor_bytes;
1179
1180 gclog_or_tty->print_cr(
1181 " [Eden: "EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")->"EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT") "
1182 "Survivors: "EXT_SIZE_FORMAT"->"EXT_SIZE_FORMAT" "
1183 "Heap: "EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")->"
1184 EXT_SIZE_FORMAT"("EXT_SIZE_FORMAT")]",
1185 EXT_SIZE_PARAMS(_eden_bytes_before_gc),
1186 EXT_SIZE_PARAMS(_prev_eden_capacity),
1187 EXT_SIZE_PARAMS(eden_bytes),
1188 EXT_SIZE_PARAMS(eden_capacity),
1189 EXT_SIZE_PARAMS(_survivor_bytes_before_gc),
1190 EXT_SIZE_PARAMS(survivor_bytes),
1191 EXT_SIZE_PARAMS(used_before_gc),
1192 EXT_SIZE_PARAMS(_capacity_before_gc),
1193 EXT_SIZE_PARAMS(used),
1194 EXT_SIZE_PARAMS(capacity));
1195 }
1196
1197 void G1CollectorPolicy::adjust_concurrent_refinement(double update_rs_time,
1198 double update_rs_processed_buffers,
1199 double goal_ms) {
1200 DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set();
1201 ConcurrentG1Refine *cg1r = G1CollectedHeap::heap()->concurrent_g1_refine();
1202
1203 if (G1UseAdaptiveConcRefinement) {
1204 const int k_gy = 3, k_gr = 6;
1205 const double inc_k = 1.1, dec_k = 0.9;
1206
1207 int g = cg1r->green_zone();
1208 if (update_rs_time > goal_ms) {
1209 g = (int)(g * dec_k); // Can become 0, that's OK. That would mean a mutator-only processing.
1210 } else {
1211 if (update_rs_time < goal_ms && update_rs_processed_buffers > g) {
1212 g = (int)MAX2(g * inc_k, g + 1.0);
1213 }
1214 }
|