1164
1165 // Clear the marking state because we will be restarting
1166 // marking due to overflowing the global mark stack.
1167 reset_marking_for_restart();
1168 }
1169
1170 {
1171 GCTraceTime(Debug, gc, phases)("Report Object Count");
1172 report_object_count(mark_finished);
1173 }
1174
1175 // Statistics
1176 double now = os::elapsedTime();
1177 _remark_mark_times.add((mark_work_end - start) * 1000.0);
1178 _remark_weak_ref_times.add((now - mark_work_end) * 1000.0);
1179 _remark_times.add((now - start) * 1000.0);
1180
1181 g1p->record_concurrent_mark_remark_end();
1182 }
1183
1184 class G1CleanupTask : public AbstractGangTask {
1185 // Per-region work during the Cleanup pause.
1186 class G1CleanupRegionsClosure : public HeapRegionClosure {
1187 G1CollectedHeap* _g1h;
1188 size_t _freed_bytes;
1189 FreeRegionList* _local_cleanup_list;
1190 uint _old_regions_removed;
1191 uint _humongous_regions_removed;
1192 HRRSCleanupTask* _hrrs_cleanup_task;
1193
1194 public:
1195 G1CleanupRegionsClosure(G1CollectedHeap* g1,
1196 FreeRegionList* local_cleanup_list,
1197 HRRSCleanupTask* hrrs_cleanup_task) :
1198 _g1h(g1),
1199 _freed_bytes(0),
1200 _local_cleanup_list(local_cleanup_list),
1201 _old_regions_removed(0),
1202 _humongous_regions_removed(0),
1203 _hrrs_cleanup_task(hrrs_cleanup_task) { }
1204
1205 size_t freed_bytes() { return _freed_bytes; }
1206 const uint old_regions_removed() { return _old_regions_removed; }
1207 const uint humongous_regions_removed() { return _humongous_regions_removed; }
1208
1209 bool do_heap_region(HeapRegion *hr) {
1210 if (hr->used() > 0 && hr->max_live_bytes() == 0 && !hr->is_young() && !hr->is_archive()) {
1211 _freed_bytes += hr->used();
1212 hr->set_containing_set(NULL);
1213 if (hr->is_humongous()) {
1214 _humongous_regions_removed++;
1215 _g1h->free_humongous_region(hr, _local_cleanup_list);
1216 } else {
1217 _old_regions_removed++;
1218 _g1h->free_region(hr, _local_cleanup_list, false /* skip_remset */, false /* skip_hcc */, true /* locked */);
1219 }
1220 hr->clear_cardtable();
1221 _g1h->concurrent_mark()->clear_statistics_in_region(hr->hrm_index());
1222 log_trace(gc)("Reclaimed empty region %u (%s) bot " PTR_FORMAT, hr->hrm_index(), hr->get_short_type_str(), p2i(hr->bottom()));
1223 } else {
1224 hr->rem_set()->do_cleanup_work(_hrrs_cleanup_task);
1225 }
1226
1227 return false;
1228 }
1229 };
1230
1231 G1CollectedHeap* _g1h;
1232 FreeRegionList* _cleanup_list;
1233 HeapRegionClaimer _hrclaimer;
1234
1235 public:
1236 G1CleanupTask(G1CollectedHeap* g1h, FreeRegionList* cleanup_list, uint n_workers) :
1237 AbstractGangTask("G1 Cleanup"),
1238 _g1h(g1h),
1239 _cleanup_list(cleanup_list),
1240 _hrclaimer(n_workers) {
1241
1242 HeapRegionRemSet::reset_for_cleanup_tasks();
1243 }
1244
1245 void work(uint worker_id) {
1246 FreeRegionList local_cleanup_list("Local Cleanup List");
1247 HRRSCleanupTask hrrs_cleanup_task;
1248 G1CleanupRegionsClosure cl(_g1h,
1249 &local_cleanup_list,
1250 &hrrs_cleanup_task);
1251 _g1h->heap_region_par_iterate_from_worker_offset(&cl, &_hrclaimer, worker_id);
1252 assert(cl.is_complete(), "Shouldn't have aborted!");
1253
1254 // Now update the old/humongous region sets
1255 _g1h->remove_from_old_sets(cl.old_regions_removed(), cl.humongous_regions_removed());
1256 {
1257 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag);
1258 _g1h->decrement_summary_bytes(cl.freed_bytes());
1259
1260 _cleanup_list->add_ordered(&local_cleanup_list);
1261 assert(local_cleanup_list.is_empty(), "post-condition");
1262
1263 HeapRegionRemSet::finish_cleanup_task(&hrrs_cleanup_task);
1264 }
1265 }
1266 };
1267
1268 void G1ConcurrentMark::reclaim_empty_regions() {
1269 WorkGang* workers = _g1h->workers();
1270 FreeRegionList empty_regions_list("Empty Regions After Mark List");
1271
1272 G1CleanupTask cl(_g1h, &empty_regions_list, workers->active_workers());
1273 workers->run_task(&cl);
1274
1275 if (!empty_regions_list.is_empty()) {
1276 log_debug(gc)("Reclaimed %u empty regions", empty_regions_list.length());
1277 // Now print the empty regions list.
1278 G1HRPrinter* hrp = _g1h->hr_printer();
1279 if (hrp->is_active()) {
1280 FreeRegionListIterator iter(&empty_regions_list);
1281 while (iter.more_available()) {
1282 HeapRegion* hr = iter.get_next();
1283 hrp->cleanup(hr);
1284 }
1285 }
1286 // And actually make them available.
1287 _g1h->prepend_to_freelist(&empty_regions_list);
1288 }
1289 }
1290
1291 void G1ConcurrentMark::compute_new_sizes() {
1292 MetaspaceGC::compute_new_size();
|
1164
1165 // Clear the marking state because we will be restarting
1166 // marking due to overflowing the global mark stack.
1167 reset_marking_for_restart();
1168 }
1169
1170 {
1171 GCTraceTime(Debug, gc, phases)("Report Object Count");
1172 report_object_count(mark_finished);
1173 }
1174
1175 // Statistics
1176 double now = os::elapsedTime();
1177 _remark_mark_times.add((mark_work_end - start) * 1000.0);
1178 _remark_weak_ref_times.add((now - mark_work_end) * 1000.0);
1179 _remark_times.add((now - start) * 1000.0);
1180
1181 g1p->record_concurrent_mark_remark_end();
1182 }
1183
1184 class G1ReclaimEmptyRegionsTask : public AbstractGangTask {
1185 // Per-region work during the Cleanup pause.
1186 class G1ReclaimEmptyRegionsClosure : public HeapRegionClosure {
1187 G1CollectedHeap* _g1h;
1188 size_t _freed_bytes;
1189 FreeRegionList* _local_cleanup_list;
1190 uint _old_regions_removed;
1191 uint _humongous_regions_removed;
1192 HRRSCleanupTask* _hrrs_cleanup_task;
1193
1194 public:
1195 G1ReclaimEmptyRegionsClosure(G1CollectedHeap* g1,
1196 FreeRegionList* local_cleanup_list,
1197 HRRSCleanupTask* hrrs_cleanup_task) :
1198 _g1h(g1),
1199 _freed_bytes(0),
1200 _local_cleanup_list(local_cleanup_list),
1201 _old_regions_removed(0),
1202 _humongous_regions_removed(0),
1203 _hrrs_cleanup_task(hrrs_cleanup_task) { }
1204
1205 size_t freed_bytes() { return _freed_bytes; }
1206 const uint old_regions_removed() { return _old_regions_removed; }
1207 const uint humongous_regions_removed() { return _humongous_regions_removed; }
1208
1209 bool do_heap_region(HeapRegion *hr) {
1210 if (hr->used() > 0 && hr->max_live_bytes() == 0 && !hr->is_young() && !hr->is_archive()) {
1211 _freed_bytes += hr->used();
1212 hr->set_containing_set(NULL);
1213 if (hr->is_humongous()) {
1214 _humongous_regions_removed++;
1215 _g1h->free_humongous_region(hr, _local_cleanup_list);
1216 } else {
1217 _old_regions_removed++;
1218 _g1h->free_region(hr, _local_cleanup_list, false /* skip_remset */, false /* skip_hcc */, true /* locked */);
1219 }
1220 hr->clear_cardtable();
1221 _g1h->concurrent_mark()->clear_statistics_in_region(hr->hrm_index());
1222 log_trace(gc)("Reclaimed empty region %u (%s) bot " PTR_FORMAT, hr->hrm_index(), hr->get_short_type_str(), p2i(hr->bottom()));
1223 } else {
1224 hr->rem_set()->do_cleanup_work(_hrrs_cleanup_task);
1225 }
1226
1227 return false;
1228 }
1229 };
1230
1231 G1CollectedHeap* _g1h;
1232 FreeRegionList* _cleanup_list;
1233 HeapRegionClaimer _hrclaimer;
1234
1235 public:
1236 G1ReclaimEmptyRegionsTask(G1CollectedHeap* g1h, FreeRegionList* cleanup_list, uint n_workers) :
1237 AbstractGangTask("G1 Cleanup"),
1238 _g1h(g1h),
1239 _cleanup_list(cleanup_list),
1240 _hrclaimer(n_workers) {
1241
1242 HeapRegionRemSet::reset_for_cleanup_tasks();
1243 }
1244
1245 void work(uint worker_id) {
1246 FreeRegionList local_cleanup_list("Local Cleanup List");
1247 HRRSCleanupTask hrrs_cleanup_task;
1248 G1ReclaimEmptyRegionsClosure cl(_g1h,
1249 &local_cleanup_list,
1250 &hrrs_cleanup_task);
1251 _g1h->heap_region_par_iterate_from_worker_offset(&cl, &_hrclaimer, worker_id);
1252 assert(cl.is_complete(), "Shouldn't have aborted!");
1253
1254 // Now update the old/humongous region sets
1255 _g1h->remove_from_old_sets(cl.old_regions_removed(), cl.humongous_regions_removed());
1256 {
1257 MutexLockerEx x(ParGCRareEvent_lock, Mutex::_no_safepoint_check_flag);
1258 _g1h->decrement_summary_bytes(cl.freed_bytes());
1259
1260 _cleanup_list->add_ordered(&local_cleanup_list);
1261 assert(local_cleanup_list.is_empty(), "post-condition");
1262
1263 HeapRegionRemSet::finish_cleanup_task(&hrrs_cleanup_task);
1264 }
1265 }
1266 };
1267
1268 void G1ConcurrentMark::reclaim_empty_regions() {
1269 WorkGang* workers = _g1h->workers();
1270 FreeRegionList empty_regions_list("Empty Regions After Mark List");
1271
1272 G1ReclaimEmptyRegionsTask cl(_g1h, &empty_regions_list, workers->active_workers());
1273 workers->run_task(&cl);
1274
1275 if (!empty_regions_list.is_empty()) {
1276 log_debug(gc)("Reclaimed %u empty regions", empty_regions_list.length());
1277 // Now print the empty regions list.
1278 G1HRPrinter* hrp = _g1h->hr_printer();
1279 if (hrp->is_active()) {
1280 FreeRegionListIterator iter(&empty_regions_list);
1281 while (iter.more_available()) {
1282 HeapRegion* hr = iter.get_next();
1283 hrp->cleanup(hr);
1284 }
1285 }
1286 // And actually make them available.
1287 _g1h->prepend_to_freelist(&empty_regions_list);
1288 }
1289 }
1290
1291 void G1ConcurrentMark::compute_new_sizes() {
1292 MetaspaceGC::compute_new_size();
|