1140 G1UpdateRemSetTrackingBeforeRebuild cl(_g1h, this); |
1140 G1UpdateRemSetTrackingBeforeRebuild cl(_g1h, this); |
1141 _g1h->heap_region_iterate(&cl); |
1141 _g1h->heap_region_iterate(&cl); |
1142 log_debug(gc, remset, tracking)("Remembered Set Tracking update regions total %u, selected %u", |
1142 log_debug(gc, remset, tracking)("Remembered Set Tracking update regions total %u, selected %u", |
1143 _g1h->num_regions(), cl.num_selected_for_rebuild()); |
1143 _g1h->num_regions(), cl.num_selected_for_rebuild()); |
1144 } |
1144 } |
|
1145 { |
|
1146 GCTraceTime(Debug, gc, phases)("Reclaim Empty Regions"); |
|
1147 reclaim_empty_regions(); |
|
1148 } |
|
1149 |
|
1150 // Clean out dead classes |
|
1151 if (ClassUnloadingWithConcurrentMark) { |
|
1152 GCTraceTime(Debug, gc, phases)("Purge Metaspace"); |
|
1153 ClassLoaderDataGraph::purge(); |
|
1154 } |
|
1155 |
|
1156 compute_new_sizes(); |
1145 |
1157 |
1146 verify_during_pause(G1HeapVerifier::G1VerifyRemark, VerifyOption_G1UsePrevMarking, "Remark after"); |
1158 verify_during_pause(G1HeapVerifier::G1VerifyRemark, VerifyOption_G1UsePrevMarking, "Remark after"); |
1147 |
1159 |
1148 assert(!restart_for_overflow(), "sanity"); |
1160 assert(!restart_for_overflow(), "sanity"); |
1149 // Completely reset the marking state since marking completed |
1161 // Completely reset the marking state since marking completed |
1171 _remark_times.add((now - start) * 1000.0); |
1183 _remark_times.add((now - start) * 1000.0); |
1172 |
1184 |
1173 g1p->record_concurrent_mark_remark_end(); |
1185 g1p->record_concurrent_mark_remark_end(); |
1174 } |
1186 } |
1175 |
1187 |
1176 class G1CleanupTask : public AbstractGangTask { |
1188 class G1ReclaimEmptyRegionsTask : public AbstractGangTask { |
1177 // Per-region work during the Cleanup pause. |
1189 // Per-region work during the Cleanup pause. |
1178 class G1CleanupRegionsClosure : public HeapRegionClosure { |
1190 class G1ReclaimEmptyRegionsClosure : public HeapRegionClosure { |
1179 G1CollectedHeap* _g1h; |
1191 G1CollectedHeap* _g1h; |
1180 size_t _freed_bytes; |
1192 size_t _freed_bytes; |
1181 FreeRegionList* _local_cleanup_list; |
1193 FreeRegionList* _local_cleanup_list; |
1182 uint _old_regions_removed; |
1194 uint _old_regions_removed; |
1183 uint _humongous_regions_removed; |
1195 uint _humongous_regions_removed; |
1184 HRRSCleanupTask* _hrrs_cleanup_task; |
1196 HRRSCleanupTask* _hrrs_cleanup_task; |
1185 |
1197 |
1186 public: |
1198 public: |
1187 G1CleanupRegionsClosure(G1CollectedHeap* g1, |
1199 G1ReclaimEmptyRegionsClosure(G1CollectedHeap* g1, |
1188 FreeRegionList* local_cleanup_list, |
1200 FreeRegionList* local_cleanup_list, |
1189 HRRSCleanupTask* hrrs_cleanup_task) : |
1201 HRRSCleanupTask* hrrs_cleanup_task) : |
1190 _g1h(g1), |
1202 _g1h(g1), |
1191 _freed_bytes(0), |
1203 _freed_bytes(0), |
1192 _local_cleanup_list(local_cleanup_list), |
1204 _local_cleanup_list(local_cleanup_list), |
1193 _old_regions_removed(0), |
1205 _old_regions_removed(0), |
1194 _humongous_regions_removed(0), |
1206 _humongous_regions_removed(0), |
1223 G1CollectedHeap* _g1h; |
1235 G1CollectedHeap* _g1h; |
1224 FreeRegionList* _cleanup_list; |
1236 FreeRegionList* _cleanup_list; |
1225 HeapRegionClaimer _hrclaimer; |
1237 HeapRegionClaimer _hrclaimer; |
1226 |
1238 |
1227 public: |
1239 public: |
1228 G1CleanupTask(G1CollectedHeap* g1h, FreeRegionList* cleanup_list, uint n_workers) : |
1240 G1ReclaimEmptyRegionsTask(G1CollectedHeap* g1h, FreeRegionList* cleanup_list, uint n_workers) : |
1229 AbstractGangTask("G1 Cleanup"), |
1241 AbstractGangTask("G1 Cleanup"), |
1230 _g1h(g1h), |
1242 _g1h(g1h), |
1231 _cleanup_list(cleanup_list), |
1243 _cleanup_list(cleanup_list), |
1232 _hrclaimer(n_workers) { |
1244 _hrclaimer(n_workers) { |
1233 |
1245 |
1235 } |
1247 } |
1236 |
1248 |
1237 void work(uint worker_id) { |
1249 void work(uint worker_id) { |
1238 FreeRegionList local_cleanup_list("Local Cleanup List"); |
1250 FreeRegionList local_cleanup_list("Local Cleanup List"); |
1239 HRRSCleanupTask hrrs_cleanup_task; |
1251 HRRSCleanupTask hrrs_cleanup_task; |
1240 G1CleanupRegionsClosure cl(_g1h, |
1252 G1ReclaimEmptyRegionsClosure cl(_g1h, |
1241 &local_cleanup_list, |
1253 &local_cleanup_list, |
1242 &hrrs_cleanup_task); |
1254 &hrrs_cleanup_task); |
1243 _g1h->heap_region_par_iterate_from_worker_offset(&cl, &_hrclaimer, worker_id); |
1255 _g1h->heap_region_par_iterate_from_worker_offset(&cl, &_hrclaimer, worker_id); |
1244 assert(cl.is_complete(), "Shouldn't have aborted!"); |
1256 assert(cl.is_complete(), "Shouldn't have aborted!"); |
1245 |
1257 |
1246 // Now update the old/humongous region sets |
1258 // Now update the old/humongous region sets |
1247 _g1h->remove_from_old_sets(cl.old_regions_removed(), cl.humongous_regions_removed()); |
1259 _g1h->remove_from_old_sets(cl.old_regions_removed(), cl.humongous_regions_removed()); |
1259 |
1271 |
1260 void G1ConcurrentMark::reclaim_empty_regions() { |
1272 void G1ConcurrentMark::reclaim_empty_regions() { |
1261 WorkGang* workers = _g1h->workers(); |
1273 WorkGang* workers = _g1h->workers(); |
1262 FreeRegionList empty_regions_list("Empty Regions After Mark List"); |
1274 FreeRegionList empty_regions_list("Empty Regions After Mark List"); |
1263 |
1275 |
1264 G1CleanupTask cl(_g1h, &empty_regions_list, workers->active_workers()); |
1276 G1ReclaimEmptyRegionsTask cl(_g1h, &empty_regions_list, workers->active_workers()); |
1265 workers->run_task(&cl); |
1277 workers->run_task(&cl); |
1266 |
1278 |
1267 if (!empty_regions_list.is_empty()) { |
1279 if (!empty_regions_list.is_empty()) { |
1268 log_debug(gc)("Reclaimed %u empty regions", empty_regions_list.length()); |
1280 log_debug(gc)("Reclaimed %u empty regions", empty_regions_list.length()); |
1269 // Now print the empty regions list. |
1281 // Now print the empty regions list. |
1278 // And actually make them available. |
1290 // And actually make them available. |
1279 _g1h->prepend_to_freelist(&empty_regions_list); |
1291 _g1h->prepend_to_freelist(&empty_regions_list); |
1280 } |
1292 } |
1281 } |
1293 } |
1282 |
1294 |
|
1295 void G1ConcurrentMark::compute_new_sizes() { |
|
1296 MetaspaceGC::compute_new_size(); |
|
1297 |
|
1298 // Cleanup will have freed any regions completely full of garbage. |
|
1299 // Update the soft reference policy with the new heap occupancy. |
|
1300 Universe::update_heap_info_at_gc(); |
|
1301 |
|
1302 // We reclaimed old regions so we should calculate the sizes to make |
|
1303 // sure we update the old gen/space data. |
|
1304 _g1h->g1mm()->update_sizes(); |
|
1305 } |
|
1306 |
1283 void G1ConcurrentMark::cleanup() { |
1307 void G1ConcurrentMark::cleanup() { |
1284 assert_at_safepoint_on_vm_thread(); |
1308 assert_at_safepoint_on_vm_thread(); |
1285 |
1309 |
1286 // If a full collection has happened, we shouldn't do this. |
1310 // If a full collection has happened, we shouldn't do this. |
1287 if (has_aborted()) { |
1311 if (has_aborted()) { |
1303 |
1327 |
1304 if (log_is_enabled(Trace, gc, liveness)) { |
1328 if (log_is_enabled(Trace, gc, liveness)) { |
1305 G1PrintRegionLivenessInfoClosure cl("Post-Cleanup"); |
1329 G1PrintRegionLivenessInfoClosure cl("Post-Cleanup"); |
1306 _g1h->heap_region_iterate(&cl); |
1330 _g1h->heap_region_iterate(&cl); |
1307 } |
1331 } |
1308 |
|
1309 { |
|
1310 GCTraceTime(Debug, gc, phases)("Reclaim Empty Regions"); |
|
1311 reclaim_empty_regions(); |
|
1312 } |
|
1313 |
|
1314 // Cleanup will have freed any regions completely full of garbage. |
|
1315 // Update the soft reference policy with the new heap occupancy. |
|
1316 Universe::update_heap_info_at_gc(); |
|
1317 |
|
1318 // Clean out dead classes and update Metaspace sizes. |
|
1319 if (ClassUnloadingWithConcurrentMark) { |
|
1320 GCTraceTime(Debug, gc, phases)("Purge Metaspace"); |
|
1321 ClassLoaderDataGraph::purge(); |
|
1322 } |
|
1323 MetaspaceGC::compute_new_size(); |
|
1324 |
|
1325 // We reclaimed old regions so we should calculate the sizes to make |
|
1326 // sure we update the old gen/space data. |
|
1327 _g1h->g1mm()->update_sizes(); |
|
1328 |
1332 |
1329 verify_during_pause(G1HeapVerifier::G1VerifyCleanup, VerifyOption_G1UsePrevMarking, "Cleanup after"); |
1333 verify_during_pause(G1HeapVerifier::G1VerifyCleanup, VerifyOption_G1UsePrevMarking, "Cleanup after"); |
1330 |
1334 |
1331 // We need to make this be a "collection" so any collection pause that |
1335 // We need to make this be a "collection" so any collection pause that |
1332 // races with it goes around and waits for Cleanup to finish. |
1336 // races with it goes around and waits for Cleanup to finish. |