27 #include "gc/g1/concurrentMark.hpp" |
27 #include "gc/g1/concurrentMark.hpp" |
28 #include "gc/g1/concurrentMarkThread.inline.hpp" |
28 #include "gc/g1/concurrentMarkThread.inline.hpp" |
29 #include "gc/g1/g1CollectedHeap.inline.hpp" |
29 #include "gc/g1/g1CollectedHeap.inline.hpp" |
30 #include "gc/g1/g1CollectorPolicy.hpp" |
30 #include "gc/g1/g1CollectorPolicy.hpp" |
31 #include "gc/g1/g1IHOPControl.hpp" |
31 #include "gc/g1/g1IHOPControl.hpp" |
32 #include "gc/g1/g1ErgoVerbose.hpp" |
|
33 #include "gc/g1/g1GCPhaseTimes.hpp" |
32 #include "gc/g1/g1GCPhaseTimes.hpp" |
34 #include "gc/g1/g1Log.hpp" |
|
35 #include "gc/g1/heapRegion.inline.hpp" |
33 #include "gc/g1/heapRegion.inline.hpp" |
36 #include "gc/g1/heapRegionRemSet.hpp" |
34 #include "gc/g1/heapRegionRemSet.hpp" |
37 #include "gc/shared/gcPolicyCounters.hpp" |
35 #include "gc/shared/gcPolicyCounters.hpp" |
38 #include "runtime/arguments.hpp" |
36 #include "runtime/arguments.hpp" |
39 #include "runtime/java.hpp" |
37 #include "runtime/java.hpp" |
119 _rs_lengths_prediction(0), |
117 _rs_lengths_prediction(0), |
120 _max_survivor_regions(0), |
118 _max_survivor_regions(0), |
121 |
119 |
122 _eden_used_bytes_before_gc(0), |
120 _eden_used_bytes_before_gc(0), |
123 _survivor_used_bytes_before_gc(0), |
121 _survivor_used_bytes_before_gc(0), |
|
122 _old_used_bytes_before_gc(0), |
|
123 _humongous_used_bytes_before_gc(0), |
124 _heap_used_bytes_before_gc(0), |
124 _heap_used_bytes_before_gc(0), |
125 _metaspace_used_bytes_before_gc(0), |
125 _metaspace_used_bytes_before_gc(0), |
126 _eden_capacity_bytes_before_gc(0), |
126 _eden_capacity_bytes_before_gc(0), |
127 _heap_capacity_bytes_before_gc(0), |
127 _heap_capacity_bytes_before_gc(0), |
128 |
128 |
174 // the region size on the heap size, but the heap size should be |
174 // the region size on the heap size, but the heap size should be |
175 // aligned with the region size. To get around this we use the |
175 // aligned with the region size. To get around this we use the |
176 // unaligned values for the heap. |
176 // unaligned values for the heap. |
177 HeapRegion::setup_heap_region_size(InitialHeapSize, MaxHeapSize); |
177 HeapRegion::setup_heap_region_size(InitialHeapSize, MaxHeapSize); |
178 HeapRegionRemSet::setup_remset_size(); |
178 HeapRegionRemSet::setup_remset_size(); |
179 |
|
180 G1ErgoVerbose::initialize(); |
|
181 if (PrintAdaptiveSizePolicy) { |
|
182 // Currently, we only use a single switch for all the heuristics. |
|
183 G1ErgoVerbose::set_enabled(true); |
|
184 // Given that we don't currently have a verboseness level |
|
185 // parameter, we'll hardcode this to high. This can be easily |
|
186 // changed in the future. |
|
187 G1ErgoVerbose::set_level(ErgoHigh); |
|
188 } else { |
|
189 G1ErgoVerbose::set_enabled(false); |
|
190 } |
|
191 |
179 |
192 _recent_prev_end_times_for_all_gcs_sec->add(os::elapsedTime()); |
180 _recent_prev_end_times_for_all_gcs_sec->add(os::elapsedTime()); |
193 _prev_collection_pause_end_ms = os::elapsedTime() * 1000.0; |
181 _prev_collection_pause_end_ms = os::elapsedTime() * 1000.0; |
194 clear_ratio_check_data(); |
182 clear_ratio_check_data(); |
195 |
183 |
789 for (HeapRegion* curr = head; |
777 for (HeapRegion* curr = head; |
790 curr != NULL; |
778 curr != NULL; |
791 curr = curr->get_next_young_region()) { |
779 curr = curr->get_next_young_region()) { |
792 SurvRateGroup* group = curr->surv_rate_group(); |
780 SurvRateGroup* group = curr->surv_rate_group(); |
793 if (group == NULL && !curr->is_survivor()) { |
781 if (group == NULL && !curr->is_survivor()) { |
794 gclog_or_tty->print_cr("## %s: encountered NULL surv_rate_group", name); |
782 log_info(gc, verify)("## %s: encountered NULL surv_rate_group", name); |
795 ret = false; |
783 ret = false; |
796 } |
784 } |
797 |
785 |
798 if (surv_rate_group == group) { |
786 if (surv_rate_group == group) { |
799 int age = curr->age_in_surv_rate_group(); |
787 int age = curr->age_in_surv_rate_group(); |
800 |
788 |
801 if (age < 0) { |
789 if (age < 0) { |
802 gclog_or_tty->print_cr("## %s: encountered negative age", name); |
790 log_info(gc, verify)("## %s: encountered negative age", name); |
803 ret = false; |
791 ret = false; |
804 } |
792 } |
805 |
793 |
806 if (age <= prev_age) { |
794 if (age <= prev_age) { |
807 gclog_or_tty->print_cr("## %s: region ages are not strictly increasing " |
795 log_info(gc, verify)("## %s: region ages are not strictly increasing (%d, %d)", name, age, prev_age); |
808 "(%d, %d)", name, age, prev_age); |
|
809 ret = false; |
796 ret = false; |
810 } |
797 } |
811 prev_age = age; |
798 prev_age = age; |
812 } |
799 } |
813 } |
800 } |
980 |
967 |
981 size_t cur_used_bytes = _g1->non_young_capacity_bytes(); |
968 size_t cur_used_bytes = _g1->non_young_capacity_bytes(); |
982 size_t alloc_byte_size = alloc_word_size * HeapWordSize; |
969 size_t alloc_byte_size = alloc_word_size * HeapWordSize; |
983 size_t marking_request_bytes = cur_used_bytes + alloc_byte_size; |
970 size_t marking_request_bytes = cur_used_bytes + alloc_byte_size; |
984 |
971 |
|
972 bool result = false; |
985 if (marking_request_bytes > marking_initiating_used_threshold) { |
973 if (marking_request_bytes > marking_initiating_used_threshold) { |
986 if (collector_state()->gcs_are_young() && !collector_state()->last_young_gc()) { |
974 result = collector_state()->gcs_are_young() && !collector_state()->last_young_gc(); |
987 ergo_verbose5(ErgoConcCycles, |
975 log_debug(gc, ergo, ihop)("%s occupancy: " SIZE_FORMAT "B allocation request: " SIZE_FORMAT "B threshold: " SIZE_FORMAT "B (%1.2f) source: %s", |
988 "request concurrent cycle initiation", |
976 result ? "Request concurrent cycle initiation (occupancy higher than threshold)" : "Do not request concurrent cycle initiation (still doing mixed collections)", |
989 ergo_format_reason("occupancy higher than threshold") |
977 cur_used_bytes, alloc_byte_size, marking_initiating_used_threshold, (double) marking_initiating_used_threshold / _g1->capacity() * 100, source); |
990 ergo_format_byte("occupancy") |
978 } |
991 ergo_format_byte("allocation request") |
979 |
992 ergo_format_byte_perc("threshold") |
980 return result; |
993 ergo_format_str("source"), |
|
994 cur_used_bytes, |
|
995 alloc_byte_size, |
|
996 marking_initiating_used_threshold, |
|
997 (double) marking_initiating_used_threshold / _g1->capacity() * 100, |
|
998 source); |
|
999 return true; |
|
1000 } else { |
|
1001 ergo_verbose5(ErgoConcCycles, |
|
1002 "do not request concurrent cycle initiation", |
|
1003 ergo_format_reason("still doing mixed collections") |
|
1004 ergo_format_byte("occupancy") |
|
1005 ergo_format_byte("allocation request") |
|
1006 ergo_format_byte_perc("threshold") |
|
1007 ergo_format_str("source"), |
|
1008 cur_used_bytes, |
|
1009 alloc_byte_size, |
|
1010 marking_initiating_used_threshold, |
|
1011 (double) InitiatingHeapOccupancyPercent, |
|
1012 source); |
|
1013 } |
|
1014 } |
|
1015 |
|
1016 return false; |
|
1017 } |
981 } |
1018 |
982 |
1019 // Anything below that is considered to be zero |
983 // Anything below that is considered to be zero |
1020 #define MIN_TIMER_GRANULARITY 0.0000001 |
984 #define MIN_TIMER_GRANULARITY 0.0000001 |
1021 |
985 |
1025 size_t cur_used_bytes = _g1->used(); |
989 size_t cur_used_bytes = _g1->used(); |
1026 assert(cur_used_bytes == _g1->recalculate_used(), "It should!"); |
990 assert(cur_used_bytes == _g1->recalculate_used(), "It should!"); |
1027 bool last_pause_included_initial_mark = false; |
991 bool last_pause_included_initial_mark = false; |
1028 bool update_stats = !_g1->evacuation_failed(); |
992 bool update_stats = !_g1->evacuation_failed(); |
1029 |
993 |
1030 #ifndef PRODUCT |
994 NOT_PRODUCT(_short_lived_surv_rate_group->print()); |
1031 if (G1YoungSurvRateVerbose) { |
|
1032 gclog_or_tty->cr(); |
|
1033 _short_lived_surv_rate_group->print(); |
|
1034 // do that for any other surv rate groups too |
|
1035 } |
|
1036 #endif // PRODUCT |
|
1037 |
995 |
1038 record_pause(young_gc_pause_kind(), end_time_sec - pause_time_ms / 1000.0, end_time_sec); |
996 record_pause(young_gc_pause_kind(), end_time_sec - pause_time_ms / 1000.0, end_time_sec); |
1039 |
997 |
1040 last_pause_included_initial_mark = collector_state()->during_initial_mark_pause(); |
998 last_pause_included_initial_mark = collector_state()->during_initial_mark_pause(); |
1041 if (last_pause_included_initial_mark) { |
999 if (last_pause_included_initial_mark) { |
1226 double update_rs_time_goal_ms = _mmu_tracker->max_gc_time() * MILLIUNITS * G1RSetUpdatingPauseTimePercent / 100.0; |
1184 double update_rs_time_goal_ms = _mmu_tracker->max_gc_time() * MILLIUNITS * G1RSetUpdatingPauseTimePercent / 100.0; |
1227 |
1185 |
1228 double scan_hcc_time_ms = average_time_ms(G1GCPhaseTimes::ScanHCC); |
1186 double scan_hcc_time_ms = average_time_ms(G1GCPhaseTimes::ScanHCC); |
1229 |
1187 |
1230 if (update_rs_time_goal_ms < scan_hcc_time_ms) { |
1188 if (update_rs_time_goal_ms < scan_hcc_time_ms) { |
1231 ergo_verbose2(ErgoTiming, |
1189 log_debug(gc, ergo, refine)("Adjust concurrent refinement thresholds (scanning the HCC expected to take longer than Update RS time goal)." |
1232 "adjust concurrent refinement thresholds", |
1190 "Update RS time goal: %1.2fms Scan HCC time: %1.2fms", |
1233 ergo_format_reason("Scanning the HCC expected to take longer than Update RS time goal") |
1191 update_rs_time_goal_ms, scan_hcc_time_ms); |
1234 ergo_format_ms("Update RS time goal") |
|
1235 ergo_format_ms("Scan HCC time"), |
|
1236 update_rs_time_goal_ms, |
|
1237 scan_hcc_time_ms); |
|
1238 |
1192 |
1239 update_rs_time_goal_ms = 0; |
1193 update_rs_time_goal_ms = 0; |
1240 } else { |
1194 } else { |
1241 update_rs_time_goal_ms -= scan_hcc_time_ms; |
1195 update_rs_time_goal_ms -= scan_hcc_time_ms; |
1242 } |
1196 } |
1310 void G1CollectorPolicy::record_heap_size_info_at_start(bool full) { |
1264 void G1CollectorPolicy::record_heap_size_info_at_start(bool full) { |
1311 YoungList* young_list = _g1->young_list(); |
1265 YoungList* young_list = _g1->young_list(); |
1312 _eden_used_bytes_before_gc = young_list->eden_used_bytes(); |
1266 _eden_used_bytes_before_gc = young_list->eden_used_bytes(); |
1313 _survivor_used_bytes_before_gc = young_list->survivor_used_bytes(); |
1267 _survivor_used_bytes_before_gc = young_list->survivor_used_bytes(); |
1314 _heap_capacity_bytes_before_gc = _g1->capacity(); |
1268 _heap_capacity_bytes_before_gc = _g1->capacity(); |
|
1269 _old_used_bytes_before_gc = _g1->old_regions_count() * HeapRegion::GrainBytes; |
|
1270 _humongous_used_bytes_before_gc = _g1->humongous_regions_count() * HeapRegion::GrainBytes; |
1315 _heap_used_bytes_before_gc = _g1->used(); |
1271 _heap_used_bytes_before_gc = _g1->used(); |
1316 |
1272 _eden_capacity_bytes_before_gc = (_young_list_target_length * HeapRegion::GrainBytes) - _survivor_used_bytes_before_gc; |
1317 _eden_capacity_bytes_before_gc = |
1273 _metaspace_used_bytes_before_gc = MetaspaceAux::used_bytes(); |
1318 (_young_list_target_length * HeapRegion::GrainBytes) - _survivor_used_bytes_before_gc; |
1274 } |
1319 |
1275 |
1320 if (full) { |
1276 void G1CollectorPolicy::print_detailed_heap_transition() const { |
1321 _metaspace_used_bytes_before_gc = MetaspaceAux::used_bytes(); |
|
1322 } |
|
1323 } |
|
1324 |
|
1325 void G1CollectorPolicy::print_heap_transition(size_t bytes_before) const { |
|
1326 size_t bytes_after = _g1->used(); |
|
1327 size_t capacity = _g1->capacity(); |
|
1328 |
|
1329 gclog_or_tty->print(" " SIZE_FORMAT "%s->" SIZE_FORMAT "%s(" SIZE_FORMAT "%s)", |
|
1330 byte_size_in_proper_unit(bytes_before), |
|
1331 proper_unit_for_byte_size(bytes_before), |
|
1332 byte_size_in_proper_unit(bytes_after), |
|
1333 proper_unit_for_byte_size(bytes_after), |
|
1334 byte_size_in_proper_unit(capacity), |
|
1335 proper_unit_for_byte_size(capacity)); |
|
1336 } |
|
1337 |
|
1338 void G1CollectorPolicy::print_heap_transition() const { |
|
1339 print_heap_transition(_heap_used_bytes_before_gc); |
|
1340 } |
|
1341 |
|
1342 void G1CollectorPolicy::print_detailed_heap_transition(bool full) const { |
|
1343 YoungList* young_list = _g1->young_list(); |
1277 YoungList* young_list = _g1->young_list(); |
1344 |
1278 |
1345 size_t eden_used_bytes_after_gc = young_list->eden_used_bytes(); |
1279 size_t eden_used_bytes_after_gc = young_list->eden_used_bytes(); |
1346 size_t survivor_used_bytes_after_gc = young_list->survivor_used_bytes(); |
1280 size_t survivor_used_bytes_after_gc = young_list->survivor_used_bytes(); |
1347 size_t heap_used_bytes_after_gc = _g1->used(); |
1281 size_t heap_used_bytes_after_gc = _g1->used(); |
|
1282 size_t old_used_bytes_after_gc = _g1->old_regions_count() * HeapRegion::GrainBytes; |
|
1283 size_t humongous_used_bytes_after_gc = _g1->humongous_regions_count() * HeapRegion::GrainBytes; |
1348 |
1284 |
1349 size_t heap_capacity_bytes_after_gc = _g1->capacity(); |
1285 size_t heap_capacity_bytes_after_gc = _g1->capacity(); |
1350 size_t eden_capacity_bytes_after_gc = |
1286 size_t eden_capacity_bytes_after_gc = |
1351 (_young_list_target_length * HeapRegion::GrainBytes) - survivor_used_bytes_after_gc; |
1287 (_young_list_target_length * HeapRegion::GrainBytes) - survivor_used_bytes_after_gc; |
1352 |
1288 size_t survivor_capacity_bytes_after_gc = _max_survivor_regions * HeapRegion::GrainBytes; |
1353 gclog_or_tty->print( |
1289 |
1354 " [Eden: " EXT_SIZE_FORMAT "(" EXT_SIZE_FORMAT ")->" EXT_SIZE_FORMAT "(" EXT_SIZE_FORMAT ") " |
1290 log_info(gc, heap)("Eden: " SIZE_FORMAT "K->" SIZE_FORMAT "K(" SIZE_FORMAT "K)", |
1355 "Survivors: " EXT_SIZE_FORMAT "->" EXT_SIZE_FORMAT " " |
1291 _eden_used_bytes_before_gc / K, eden_used_bytes_after_gc /K, eden_capacity_bytes_after_gc /K); |
1356 "Heap: " EXT_SIZE_FORMAT "(" EXT_SIZE_FORMAT ")->" |
1292 log_info(gc, heap)("Survivor: " SIZE_FORMAT "K->" SIZE_FORMAT "K(" SIZE_FORMAT "K)", |
1357 EXT_SIZE_FORMAT "(" EXT_SIZE_FORMAT ")]", |
1293 _survivor_used_bytes_before_gc / K, survivor_used_bytes_after_gc /K, survivor_capacity_bytes_after_gc /K); |
1358 EXT_SIZE_PARAMS(_eden_used_bytes_before_gc), |
1294 log_info(gc, heap)("Old: " SIZE_FORMAT "K->" SIZE_FORMAT "K", |
1359 EXT_SIZE_PARAMS(_eden_capacity_bytes_before_gc), |
1295 _old_used_bytes_before_gc / K, old_used_bytes_after_gc /K); |
1360 EXT_SIZE_PARAMS(eden_used_bytes_after_gc), |
1296 log_info(gc, heap)("Humongous: " SIZE_FORMAT "K->" SIZE_FORMAT "K", |
1361 EXT_SIZE_PARAMS(eden_capacity_bytes_after_gc), |
1297 _humongous_used_bytes_before_gc / K, humongous_used_bytes_after_gc /K); |
1362 EXT_SIZE_PARAMS(_survivor_used_bytes_before_gc), |
1298 |
1363 EXT_SIZE_PARAMS(survivor_used_bytes_after_gc), |
1299 MetaspaceAux::print_metaspace_change(_metaspace_used_bytes_before_gc); |
1364 EXT_SIZE_PARAMS(_heap_used_bytes_before_gc), |
|
1365 EXT_SIZE_PARAMS(_heap_capacity_bytes_before_gc), |
|
1366 EXT_SIZE_PARAMS(heap_used_bytes_after_gc), |
|
1367 EXT_SIZE_PARAMS(heap_capacity_bytes_after_gc)); |
|
1368 |
|
1369 if (full) { |
|
1370 MetaspaceAux::print_metaspace_change(_metaspace_used_bytes_before_gc); |
|
1371 } |
|
1372 |
|
1373 gclog_or_tty->cr(); |
|
1374 } |
1300 } |
1375 |
1301 |
1376 void G1CollectorPolicy::print_phases(double pause_time_sec) { |
1302 void G1CollectorPolicy::print_phases(double pause_time_sec) { |
1377 phase_times()->print(pause_time_sec); |
1303 phase_times()->print(pause_time_sec); |
1378 } |
1304 } |
1688 scale_factor = 1 + ((ratio_delta - StartScaleUpAt) / ScaleUpRange); |
1614 scale_factor = 1 + ((ratio_delta - StartScaleUpAt) / ScaleUpRange); |
1689 scale_factor = MIN2(scale_factor, MaxScaleUpFactor); |
1615 scale_factor = MIN2(scale_factor, MaxScaleUpFactor); |
1690 } |
1616 } |
1691 } |
1617 } |
1692 |
1618 |
1693 ergo_verbose5(ErgoHeapSizing, |
1619 log_debug(gc, ergo, heap)("Attempt heap expansion (recent GC overhead higher than threshold after GC) " |
1694 "attempt heap expansion", |
1620 "recent GC overhead: %1.2f %% threshold: %1.2f %% uncommitted: " SIZE_FORMAT "B base expansion amount and scale: " SIZE_FORMAT "B (%1.2f%%)", |
1695 ergo_format_reason("recent GC overhead higher than " |
1621 recent_gc_overhead, threshold, uncommitted_bytes, expand_bytes, scale_factor * 100); |
1696 "threshold after GC") |
|
1697 ergo_format_perc("recent GC overhead") |
|
1698 ergo_format_perc("current threshold") |
|
1699 ergo_format_byte("uncommitted") |
|
1700 ergo_format_byte_perc("base expansion amount and scale"), |
|
1701 recent_gc_overhead, threshold, |
|
1702 uncommitted_bytes, |
|
1703 expand_bytes, scale_factor * 100); |
|
1704 |
1622 |
1705 expand_bytes = static_cast<size_t>(expand_bytes * scale_factor); |
1623 expand_bytes = static_cast<size_t>(expand_bytes * scale_factor); |
1706 |
1624 |
1707 // Ensure the expansion size is at least the minimum growth amount |
1625 // Ensure the expansion size is at least the minimum growth amount |
1708 // and at most the remaining uncommitted byte size. |
1626 // and at most the remaining uncommitted byte size. |
1781 // We actually check whether we are marking here and not if we are in a |
1699 // We actually check whether we are marking here and not if we are in a |
1782 // reclamation phase. This means that we will schedule a concurrent mark |
1700 // reclamation phase. This means that we will schedule a concurrent mark |
1783 // even while we are still in the process of reclaiming memory. |
1701 // even while we are still in the process of reclaiming memory. |
1784 bool during_cycle = _g1->concurrent_mark()->cmThread()->during_cycle(); |
1702 bool during_cycle = _g1->concurrent_mark()->cmThread()->during_cycle(); |
1785 if (!during_cycle) { |
1703 if (!during_cycle) { |
1786 ergo_verbose1(ErgoConcCycles, |
1704 log_debug(gc, ergo)("Request concurrent cycle initiation (requested by GC cause). GC cause: %s", GCCause::to_string(gc_cause)); |
1787 "request concurrent cycle initiation", |
|
1788 ergo_format_reason("requested by GC cause") |
|
1789 ergo_format_str("GC cause"), |
|
1790 GCCause::to_string(gc_cause)); |
|
1791 collector_state()->set_initiate_conc_mark_if_possible(true); |
1705 collector_state()->set_initiate_conc_mark_if_possible(true); |
1792 return true; |
1706 return true; |
1793 } else { |
1707 } else { |
1794 ergo_verbose1(ErgoConcCycles, |
1708 log_debug(gc, ergo)("Do not request concurrent cycle initiation (concurrent cycle already in progress). GC cause: %s", GCCause::to_string(gc_cause)); |
1795 "do not request concurrent cycle initiation", |
|
1796 ergo_format_reason("concurrent cycle already in progress") |
|
1797 ergo_format_str("GC cause"), |
|
1798 GCCause::to_string(gc_cause)); |
|
1799 return false; |
1709 return false; |
1800 } |
1710 } |
1801 } |
1711 } |
1802 |
1712 |
1803 void G1CollectorPolicy::initiate_conc_mark() { |
1713 void G1CollectorPolicy::initiate_conc_mark() { |
1821 // concurrent marking cycle. So we might initiate one. |
1731 // concurrent marking cycle. So we might initiate one. |
1822 |
1732 |
1823 if (!about_to_start_mixed_phase() && collector_state()->gcs_are_young()) { |
1733 if (!about_to_start_mixed_phase() && collector_state()->gcs_are_young()) { |
1824 // Initiate a new initial mark if there is no marking or reclamation going on. |
1734 // Initiate a new initial mark if there is no marking or reclamation going on. |
1825 initiate_conc_mark(); |
1735 initiate_conc_mark(); |
1826 ergo_verbose0(ErgoConcCycles, |
1736 log_debug(gc, ergo)("Initiate concurrent cycle (concurrent cycle initiation requested)"); |
1827 "initiate concurrent cycle", |
|
1828 ergo_format_reason("concurrent cycle initiation requested")); |
|
1829 } else if (_g1->is_user_requested_concurrent_full_gc(_g1->gc_cause())) { |
1737 } else if (_g1->is_user_requested_concurrent_full_gc(_g1->gc_cause())) { |
1830 // Initiate a user requested initial mark. An initial mark must be young only |
1738 // Initiate a user requested initial mark. An initial mark must be young only |
1831 // GC, so the collector state must be updated to reflect this. |
1739 // GC, so the collector state must be updated to reflect this. |
1832 collector_state()->set_gcs_are_young(true); |
1740 collector_state()->set_gcs_are_young(true); |
1833 collector_state()->set_last_young_gc(false); |
1741 collector_state()->set_last_young_gc(false); |
1834 |
1742 |
1835 abort_time_to_mixed_tracking(); |
1743 abort_time_to_mixed_tracking(); |
1836 initiate_conc_mark(); |
1744 initiate_conc_mark(); |
1837 ergo_verbose0(ErgoConcCycles, |
1745 log_debug(gc, ergo)("Initiate concurrent cycle (user requested concurrent cycle)"); |
1838 "initiate concurrent cycle", |
|
1839 ergo_format_reason("user requested concurrent cycle")); |
|
1840 } else { |
1746 } else { |
1841 // The concurrent marking thread is still finishing up the |
1747 // The concurrent marking thread is still finishing up the |
1842 // previous cycle. If we start one right now the two cycles |
1748 // previous cycle. If we start one right now the two cycles |
1843 // overlap. In particular, the concurrent marking thread might |
1749 // overlap. In particular, the concurrent marking thread might |
1844 // be in the process of clearing the next marking bitmap (which |
1750 // be in the process of clearing the next marking bitmap (which |
1848 // cannot wait for the marking thread to finish the cycle as it |
1754 // cannot wait for the marking thread to finish the cycle as it |
1849 // periodically yields while clearing the next marking bitmap |
1755 // periodically yields while clearing the next marking bitmap |
1850 // and, if it's in a yield point, it's waiting for us to |
1756 // and, if it's in a yield point, it's waiting for us to |
1851 // finish. So, at this point we will not start a cycle and we'll |
1757 // finish. So, at this point we will not start a cycle and we'll |
1852 // let the concurrent marking thread complete the last one. |
1758 // let the concurrent marking thread complete the last one. |
1853 ergo_verbose0(ErgoConcCycles, |
1759 log_debug(gc, ergo)("Do not initiate concurrent cycle (concurrent cycle already in progress)"); |
1854 "do not initiate concurrent cycle", |
|
1855 ergo_format_reason("concurrent cycle already in progress")); |
|
1856 } |
1760 } |
1857 } |
1761 } |
1858 } |
1762 } |
1859 |
1763 |
1860 class ParKnownGarbageHRClosure: public HeapRegionClosure { |
1764 class ParKnownGarbageHRClosure: public HeapRegionClosure { |
2195 } |
2099 } |
2196 |
2100 |
2197 bool G1CollectorPolicy::next_gc_should_be_mixed(const char* true_action_str, |
2101 bool G1CollectorPolicy::next_gc_should_be_mixed(const char* true_action_str, |
2198 const char* false_action_str) const { |
2102 const char* false_action_str) const { |
2199 if (cset_chooser()->is_empty()) { |
2103 if (cset_chooser()->is_empty()) { |
2200 ergo_verbose0(ErgoMixedGCs, |
2104 log_debug(gc, ergo)("%s (candidate old regions not available)", false_action_str); |
2201 false_action_str, |
|
2202 ergo_format_reason("candidate old regions not available")); |
|
2203 return false; |
2105 return false; |
2204 } |
2106 } |
2205 |
2107 |
2206 // Is the amount of uncollected reclaimable space above G1HeapWastePercent? |
2108 // Is the amount of uncollected reclaimable space above G1HeapWastePercent? |
2207 size_t reclaimable_bytes = cset_chooser()->remaining_reclaimable_bytes(); |
2109 size_t reclaimable_bytes = cset_chooser()->remaining_reclaimable_bytes(); |
2208 double reclaimable_perc = reclaimable_bytes_perc(reclaimable_bytes); |
2110 double reclaimable_perc = reclaimable_bytes_perc(reclaimable_bytes); |
2209 double threshold = (double) G1HeapWastePercent; |
2111 double threshold = (double) G1HeapWastePercent; |
2210 if (reclaimable_perc <= threshold) { |
2112 if (reclaimable_perc <= threshold) { |
2211 ergo_verbose4(ErgoMixedGCs, |
2113 log_debug(gc, ergo)("%s (reclaimable percentage not over threshold). candidate old regions: %u reclaimable: " SIZE_FORMAT " (%1.2f) threshold: " UINTX_FORMAT, |
2212 false_action_str, |
2114 false_action_str, cset_chooser()->remaining_regions(), reclaimable_bytes, reclaimable_perc, G1HeapWastePercent); |
2213 ergo_format_reason("reclaimable percentage not over threshold") |
|
2214 ergo_format_region("candidate old regions") |
|
2215 ergo_format_byte_perc("reclaimable") |
|
2216 ergo_format_perc("threshold"), |
|
2217 cset_chooser()->remaining_regions(), |
|
2218 reclaimable_bytes, |
|
2219 reclaimable_perc, threshold); |
|
2220 return false; |
2115 return false; |
2221 } |
2116 } |
2222 |
2117 log_debug(gc, ergo)("%s (candidate old regions available). candidate old regions: %u reclaimable: " SIZE_FORMAT " (%1.2f) threshold: " UINTX_FORMAT, |
2223 ergo_verbose4(ErgoMixedGCs, |
2118 true_action_str, cset_chooser()->remaining_regions(), reclaimable_bytes, reclaimable_perc, G1HeapWastePercent); |
2224 true_action_str, |
|
2225 ergo_format_reason("candidate old regions available") |
|
2226 ergo_format_region("candidate old regions") |
|
2227 ergo_format_byte_perc("reclaimable") |
|
2228 ergo_format_perc("threshold"), |
|
2229 cset_chooser()->remaining_regions(), |
|
2230 reclaimable_bytes, |
|
2231 reclaimable_perc, threshold); |
|
2232 return true; |
2119 return true; |
2233 } |
2120 } |
2234 |
2121 |
2235 uint G1CollectorPolicy::calc_min_old_cset_length() const { |
2122 uint G1CollectorPolicy::calc_min_old_cset_length() const { |
2236 // The min old CSet region bound is based on the maximum desired |
2123 // The min old CSet region bound is based on the maximum desired |
2282 guarantee(_collection_set == NULL, "Precondition"); |
2169 guarantee(_collection_set == NULL, "Precondition"); |
2283 |
2170 |
2284 double base_time_ms = predict_base_elapsed_time_ms(_pending_cards); |
2171 double base_time_ms = predict_base_elapsed_time_ms(_pending_cards); |
2285 double time_remaining_ms = MAX2(target_pause_time_ms - base_time_ms, 0.0); |
2172 double time_remaining_ms = MAX2(target_pause_time_ms - base_time_ms, 0.0); |
2286 |
2173 |
2287 ergo_verbose4(ErgoCSetConstruction | ErgoHigh, |
2174 log_trace(gc, ergo, cset)("Start choosing CSet. pending cards: " SIZE_FORMAT " predicted base time: %1.2fms remaining time: %1.2fms target pause time: %1.2fms", |
2288 "start choosing CSet", |
2175 _pending_cards, base_time_ms, time_remaining_ms, target_pause_time_ms); |
2289 ergo_format_size("_pending_cards") |
|
2290 ergo_format_ms("predicted base time") |
|
2291 ergo_format_ms("remaining time") |
|
2292 ergo_format_ms("target pause time"), |
|
2293 _pending_cards, base_time_ms, time_remaining_ms, target_pause_time_ms); |
|
2294 |
2176 |
2295 collector_state()->set_last_gc_was_young(collector_state()->gcs_are_young()); |
2177 collector_state()->set_last_gc_was_young(collector_state()->gcs_are_young()); |
2296 |
2178 |
2297 if (collector_state()->last_gc_was_young()) { |
2179 if (collector_state()->last_gc_was_young()) { |
2298 _trace_young_gen_time_data.increment_young_collection_count(); |
2180 _trace_young_gen_time_data.increment_young_collection_count(); |
2324 |
2206 |
2325 _collection_set = _inc_cset_head; |
2207 _collection_set = _inc_cset_head; |
2326 _collection_set_bytes_used_before = _inc_cset_bytes_used_before; |
2208 _collection_set_bytes_used_before = _inc_cset_bytes_used_before; |
2327 time_remaining_ms = MAX2(time_remaining_ms - _inc_cset_predicted_elapsed_time_ms, 0.0); |
2209 time_remaining_ms = MAX2(time_remaining_ms - _inc_cset_predicted_elapsed_time_ms, 0.0); |
2328 |
2210 |
2329 ergo_verbose4(ErgoCSetConstruction | ErgoHigh, |
2211 log_trace(gc, ergo, cset)("Add young regions to CSet. eden: %u regions, survivors: %u regions, predicted young region time: %1.2fms, target pause time: %1.2fms", |
2330 "add young regions to CSet", |
2212 eden_region_length, survivor_region_length, _inc_cset_predicted_elapsed_time_ms, target_pause_time_ms); |
2331 ergo_format_region("eden") |
|
2332 ergo_format_region("survivors") |
|
2333 ergo_format_ms("predicted young region time") |
|
2334 ergo_format_ms("target pause time"), |
|
2335 eden_region_length, survivor_region_length, |
|
2336 _inc_cset_predicted_elapsed_time_ms, |
|
2337 target_pause_time_ms); |
|
2338 |
2213 |
2339 // The number of recorded young regions is the incremental |
2214 // The number of recorded young regions is the incremental |
2340 // collection set's current size |
2215 // collection set's current size |
2341 set_recorded_rs_lengths(_inc_cset_recorded_rs_lengths); |
2216 set_recorded_rs_lengths(_inc_cset_recorded_rs_lengths); |
2342 |
2217 |
2361 |
2236 |
2362 HeapRegion* hr = cset_chooser()->peek(); |
2237 HeapRegion* hr = cset_chooser()->peek(); |
2363 while (hr != NULL) { |
2238 while (hr != NULL) { |
2364 if (old_cset_region_length() >= max_old_cset_length) { |
2239 if (old_cset_region_length() >= max_old_cset_length) { |
2365 // Added maximum number of old regions to the CSet. |
2240 // Added maximum number of old regions to the CSet. |
2366 ergo_verbose2(ErgoCSetConstruction, |
2241 log_debug(gc, ergo, cset)("Finish adding old regions to CSet (old CSet region num reached max). old %u regions, max %u regions", |
2367 "finish adding old regions to CSet", |
2242 old_cset_region_length(), max_old_cset_length); |
2368 ergo_format_reason("old CSet region num reached max") |
|
2369 ergo_format_region("old") |
|
2370 ergo_format_region("max"), |
|
2371 old_cset_region_length(), max_old_cset_length); |
|
2372 break; |
2243 break; |
2373 } |
2244 } |
2374 |
2245 |
2375 |
2246 |
2376 // Stop adding regions if the remaining reclaimable space is |
2247 // Stop adding regions if the remaining reclaimable space is |
2380 double threshold = (double) G1HeapWastePercent; |
2251 double threshold = (double) G1HeapWastePercent; |
2381 if (reclaimable_perc <= threshold) { |
2252 if (reclaimable_perc <= threshold) { |
2382 // We've added enough old regions that the amount of uncollected |
2253 // We've added enough old regions that the amount of uncollected |
2383 // reclaimable space is at or below the waste threshold. Stop |
2254 // reclaimable space is at or below the waste threshold. Stop |
2384 // adding old regions to the CSet. |
2255 // adding old regions to the CSet. |
2385 ergo_verbose5(ErgoCSetConstruction, |
2256 log_debug(gc, ergo, cset)("Finish adding old regions to CSet (reclaimable percentage not over threshold). " |
2386 "finish adding old regions to CSet", |
2257 "old %u regions, max %u regions, reclaimable: " SIZE_FORMAT "B (%1.2f%%) threshold: " UINTX_FORMAT "%%", |
2387 ergo_format_reason("reclaimable percentage not over threshold") |
2258 old_cset_region_length(), max_old_cset_length, reclaimable_bytes, reclaimable_perc, G1HeapWastePercent); |
2388 ergo_format_region("old") |
|
2389 ergo_format_region("max") |
|
2390 ergo_format_byte_perc("reclaimable") |
|
2391 ergo_format_perc("threshold"), |
|
2392 old_cset_region_length(), |
|
2393 max_old_cset_length, |
|
2394 reclaimable_bytes, |
|
2395 reclaimable_perc, threshold); |
|
2396 break; |
2259 break; |
2397 } |
2260 } |
2398 |
2261 |
2399 double predicted_time_ms = predict_region_elapsed_time_ms(hr, collector_state()->gcs_are_young()); |
2262 double predicted_time_ms = predict_region_elapsed_time_ms(hr, collector_state()->gcs_are_young()); |
2400 if (check_time_remaining) { |
2263 if (check_time_remaining) { |
2402 // Too expensive for the current CSet. |
2265 // Too expensive for the current CSet. |
2403 |
2266 |
2404 if (old_cset_region_length() >= min_old_cset_length) { |
2267 if (old_cset_region_length() >= min_old_cset_length) { |
2405 // We have added the minimum number of old regions to the CSet, |
2268 // We have added the minimum number of old regions to the CSet, |
2406 // we are done with this CSet. |
2269 // we are done with this CSet. |
2407 ergo_verbose4(ErgoCSetConstruction, |
2270 log_debug(gc, ergo, cset)("Finish adding old regions to CSet (predicted time is too high). " |
2408 "finish adding old regions to CSet", |
2271 "predicted time: %1.2fms, remaining time: %1.2fms old %u regions, min %u regions", |
2409 ergo_format_reason("predicted time is too high") |
2272 predicted_time_ms, time_remaining_ms, old_cset_region_length(), min_old_cset_length); |
2410 ergo_format_ms("predicted time") |
|
2411 ergo_format_ms("remaining time") |
|
2412 ergo_format_region("old") |
|
2413 ergo_format_region("min"), |
|
2414 predicted_time_ms, time_remaining_ms, |
|
2415 old_cset_region_length(), min_old_cset_length); |
|
2416 break; |
2273 break; |
2417 } |
2274 } |
2418 |
2275 |
2419 // We'll add it anyway given that we haven't reached the |
2276 // We'll add it anyway given that we haven't reached the |
2420 // minimum number of old regions. |
2277 // minimum number of old regions. |
2422 } |
2279 } |
2423 } else { |
2280 } else { |
2424 if (old_cset_region_length() >= min_old_cset_length) { |
2281 if (old_cset_region_length() >= min_old_cset_length) { |
2425 // In the non-auto-tuning case, we'll finish adding regions |
2282 // In the non-auto-tuning case, we'll finish adding regions |
2426 // to the CSet if we reach the minimum. |
2283 // to the CSet if we reach the minimum. |
2427 ergo_verbose2(ErgoCSetConstruction, |
2284 |
2428 "finish adding old regions to CSet", |
2285 log_debug(gc, ergo, cset)("Finish adding old regions to CSet (old CSet region num reached min). old %u regions, min %u regions", |
2429 ergo_format_reason("old CSet region num reached min") |
2286 old_cset_region_length(), min_old_cset_length); |
2430 ergo_format_region("old") |
|
2431 ergo_format_region("min"), |
|
2432 old_cset_region_length(), min_old_cset_length); |
|
2433 break; |
2287 break; |
2434 } |
2288 } |
2435 } |
2289 } |
2436 |
2290 |
2437 // We will add this region to the CSet. |
2291 // We will add this region to the CSet. |
2442 add_old_region_to_cset(hr); |
2296 add_old_region_to_cset(hr); |
2443 |
2297 |
2444 hr = cset_chooser()->peek(); |
2298 hr = cset_chooser()->peek(); |
2445 } |
2299 } |
2446 if (hr == NULL) { |
2300 if (hr == NULL) { |
2447 ergo_verbose0(ErgoCSetConstruction, |
2301 log_debug(gc, ergo, cset)("Finish adding old regions to CSet (candidate old regions not available)"); |
2448 "finish adding old regions to CSet", |
|
2449 ergo_format_reason("candidate old regions not available")); |
|
2450 } |
2302 } |
2451 |
2303 |
2452 if (expensive_region_num > 0) { |
2304 if (expensive_region_num > 0) { |
2453 // We print the information once here at the end, predicated on |
2305 // We print the information once here at the end, predicated on |
2454 // whether we added any apparently expensive regions or not, to |
2306 // whether we added any apparently expensive regions or not, to |
2455 // avoid generating output per region. |
2307 // avoid generating output per region. |
2456 ergo_verbose4(ErgoCSetConstruction, |
2308 log_debug(gc, ergo, cset)("Added expensive regions to CSet (old CSet region num not reached min)." |
2457 "added expensive regions to CSet", |
2309 "old %u regions, expensive: %u regions, min %u regions, remaining time: %1.2fms", |
2458 ergo_format_reason("old CSet region num not reached min") |
2310 old_cset_region_length(), expensive_region_num, min_old_cset_length, time_remaining_ms); |
2459 ergo_format_region("old") |
|
2460 ergo_format_region("expensive") |
|
2461 ergo_format_region("min") |
|
2462 ergo_format_ms("remaining time"), |
|
2463 old_cset_region_length(), |
|
2464 expensive_region_num, |
|
2465 min_old_cset_length, |
|
2466 time_remaining_ms); |
|
2467 } |
2311 } |
2468 |
2312 |
2469 cset_chooser()->verify(); |
2313 cset_chooser()->verify(); |
2470 } |
2314 } |
2471 |
2315 |
2472 stop_incremental_cset_building(); |
2316 stop_incremental_cset_building(); |
2473 |
2317 |
2474 ergo_verbose3(ErgoCSetConstruction, |
2318 log_debug(gc, ergo, cset)("Finish choosing CSet. old %u regions, predicted old region time: %1.2fms, time remaining: %1.2f", |
2475 "finish choosing CSet", |
2319 old_cset_region_length(), predicted_old_time_ms, time_remaining_ms); |
2476 ergo_format_region("old") |
|
2477 ergo_format_ms("predicted old region time") |
|
2478 ergo_format_ms("time remaining"), |
|
2479 old_cset_region_length(), |
|
2480 predicted_old_time_ms, time_remaining_ms); |
|
2481 |
2320 |
2482 double non_young_end_time_sec = os::elapsedTime(); |
2321 double non_young_end_time_sec = os::elapsedTime(); |
2483 phase_times()->record_non_young_cset_choice_time_ms((non_young_end_time_sec - non_young_start_time_sec) * 1000.0); |
2322 phase_times()->record_non_young_cset_choice_time_ms((non_young_end_time_sec - non_young_start_time_sec) * 1000.0); |
2484 } |
2323 } |
2485 |
2324 |
2534 } |
2373 } |
2535 |
2374 |
2536 void TraceYoungGenTimeData::print_summary(const char* str, |
2375 void TraceYoungGenTimeData::print_summary(const char* str, |
2537 const NumberSeq* seq) const { |
2376 const NumberSeq* seq) const { |
2538 double sum = seq->sum(); |
2377 double sum = seq->sum(); |
2539 gclog_or_tty->print_cr("%-27s = %8.2lf s (avg = %8.2lf ms)", |
2378 tty->print_cr("%-27s = %8.2lf s (avg = %8.2lf ms)", |
2540 str, sum / 1000.0, seq->avg()); |
2379 str, sum / 1000.0, seq->avg()); |
2541 } |
2380 } |
2542 |
2381 |
2543 void TraceYoungGenTimeData::print_summary_sd(const char* str, |
2382 void TraceYoungGenTimeData::print_summary_sd(const char* str, |
2544 const NumberSeq* seq) const { |
2383 const NumberSeq* seq) const { |
2545 print_summary(str, seq); |
2384 print_summary(str, seq); |
2546 gclog_or_tty->print_cr("%45s = %5d, std dev = %8.2lf ms, max = %8.2lf ms)", |
2385 tty->print_cr("%45s = %5d, std dev = %8.2lf ms, max = %8.2lf ms)", |
2547 "(num", seq->num(), seq->sd(), seq->maximum()); |
2386 "(num", seq->num(), seq->sd(), seq->maximum()); |
2548 } |
2387 } |
2549 |
2388 |
2550 void TraceYoungGenTimeData::print() const { |
2389 void TraceYoungGenTimeData::print() const { |
2551 if (!TraceYoungGenTime) { |
2390 if (!TraceYoungGenTime) { |
2552 return; |
2391 return; |
2553 } |
2392 } |
2554 |
2393 |
2555 gclog_or_tty->print_cr("ALL PAUSES"); |
2394 tty->print_cr("ALL PAUSES"); |
2556 print_summary_sd(" Total", &_total); |
2395 print_summary_sd(" Total", &_total); |
2557 gclog_or_tty->cr(); |
2396 tty->cr(); |
2558 gclog_or_tty->cr(); |
2397 tty->cr(); |
2559 gclog_or_tty->print_cr(" Young GC Pauses: %8d", _young_pause_num); |
2398 tty->print_cr(" Young GC Pauses: %8d", _young_pause_num); |
2560 gclog_or_tty->print_cr(" Mixed GC Pauses: %8d", _mixed_pause_num); |
2399 tty->print_cr(" Mixed GC Pauses: %8d", _mixed_pause_num); |
2561 gclog_or_tty->cr(); |
2400 tty->cr(); |
2562 |
2401 |
2563 gclog_or_tty->print_cr("EVACUATION PAUSES"); |
2402 tty->print_cr("EVACUATION PAUSES"); |
2564 |
2403 |
2565 if (_young_pause_num == 0 && _mixed_pause_num == 0) { |
2404 if (_young_pause_num == 0 && _mixed_pause_num == 0) { |
2566 gclog_or_tty->print_cr("none"); |
2405 tty->print_cr("none"); |
2567 } else { |
2406 } else { |
2568 print_summary_sd(" Evacuation Pauses", &_total); |
2407 print_summary_sd(" Evacuation Pauses", &_total); |
2569 print_summary(" Root Region Scan Wait", &_root_region_scan_wait); |
2408 print_summary(" Root Region Scan Wait", &_root_region_scan_wait); |
2570 print_summary(" Parallel Time", &_parallel); |
2409 print_summary(" Parallel Time", &_parallel); |
2571 print_summary(" Ext Root Scanning", &_ext_root_scan); |
2410 print_summary(" Ext Root Scanning", &_ext_root_scan); |
2576 print_summary(" Termination", &_termination); |
2415 print_summary(" Termination", &_termination); |
2577 print_summary(" Parallel Other", &_parallel_other); |
2416 print_summary(" Parallel Other", &_parallel_other); |
2578 print_summary(" Clear CT", &_clear_ct); |
2417 print_summary(" Clear CT", &_clear_ct); |
2579 print_summary(" Other", &_other); |
2418 print_summary(" Other", &_other); |
2580 } |
2419 } |
2581 gclog_or_tty->cr(); |
2420 tty->cr(); |
2582 |
2421 |
2583 gclog_or_tty->print_cr("MISC"); |
2422 tty->print_cr("MISC"); |
2584 print_summary_sd(" Stop World", &_all_stop_world_times_ms); |
2423 print_summary_sd(" Stop World", &_all_stop_world_times_ms); |
2585 print_summary_sd(" Yields", &_all_yield_times_ms); |
2424 print_summary_sd(" Yields", &_all_yield_times_ms); |
2586 } |
2425 } |
2587 |
2426 |
2588 void TraceOldGenTimeData::record_full_collection(double full_gc_time_ms) { |
2427 void TraceOldGenTimeData::record_full_collection(double full_gc_time_ms) { |
2595 if (!TraceOldGenTime) { |
2434 if (!TraceOldGenTime) { |
2596 return; |
2435 return; |
2597 } |
2436 } |
2598 |
2437 |
2599 if (_all_full_gc_times.num() > 0) { |
2438 if (_all_full_gc_times.num() > 0) { |
2600 gclog_or_tty->print("\n%4d full_gcs: total time = %8.2f s", |
2439 tty->print("\n%4d full_gcs: total time = %8.2f s", |
2601 _all_full_gc_times.num(), |
2440 _all_full_gc_times.num(), |
2602 _all_full_gc_times.sum() / 1000.0); |
2441 _all_full_gc_times.sum() / 1000.0); |
2603 gclog_or_tty->print_cr(" (avg = %8.2fms).", _all_full_gc_times.avg()); |
2442 tty->print_cr(" (avg = %8.2fms).", _all_full_gc_times.avg()); |
2604 gclog_or_tty->print_cr(" [std. dev = %8.2f ms, max = %8.2f ms]", |
2443 tty->print_cr(" [std. dev = %8.2f ms, max = %8.2f ms]", |
2605 _all_full_gc_times.sd(), |
2444 _all_full_gc_times.sd(), |
2606 _all_full_gc_times.maximum()); |
2445 _all_full_gc_times.maximum()); |
2607 } |
2446 } |
2608 } |
2447 } |