998 _concurrent_workers->run_task(&marking_task);
999 print_stats();
1000 }
1001
1002 void G1ConcurrentMark::checkpoint_roots_final(bool clear_all_soft_refs) {
1003 // world is stopped at this checkpoint
1004 assert(SafepointSynchronize::is_at_safepoint(),
1005 "world should be stopped");
1006
1007 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1008
1009 // If a full collection has happened, we shouldn't do this.
1010 if (has_aborted()) {
1011 g1h->collector_state()->set_mark_in_progress(false); // So bitmap clearing isn't confused
1012 return;
1013 }
1014
1015 SvcGCMarker sgcm(SvcGCMarker::OTHER);
1016
1017 if (VerifyDuringGC) {
1018 HandleMark hm; // handle scope
1019 g1h->prepare_for_verify();
1020 Universe::verify(VerifyOption_G1UsePrevMarking, "During GC (before)");
1021 }
1022 g1h->verifier()->check_bitmaps("Remark Start");
1023
1024 G1Policy* g1p = g1h->g1_policy();
1025 g1p->record_concurrent_mark_remark_start();
1026
1027 double start = os::elapsedTime();
1028
1029 checkpoint_roots_final_work();
1030
1031 double mark_work_end = os::elapsedTime();
1032
1033 weak_refs_work(clear_all_soft_refs);
1034
1035 if (has_overflown()) {
1036 // We overflowed. Restart concurrent marking.
1037 _restart_for_overflow = true;
1038
1039 // Verify the heap w.r.t. the previous marking bitmap.
1040 if (VerifyDuringGC) {
1041 HandleMark hm; // handle scope
1042 g1h->prepare_for_verify();
1043 Universe::verify(VerifyOption_G1UsePrevMarking, "During GC (overflow)");
1044 }
1045
1046 // Clear the marking state because we will be restarting
1047 // marking due to overflowing the global mark stack.
1048 reset_marking_state();
1049 } else {
1050 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
1051 // We're done with marking.
1052 // This is the end of the marking cycle, we're expected all
1053 // threads to have SATB queues with active set to true.
1054 satb_mq_set.set_active_all_threads(false, /* new active value */
1055 true /* expected_active */);
1056
1057 if (VerifyDuringGC) {
1058 HandleMark hm; // handle scope
1059 g1h->prepare_for_verify();
1060 Universe::verify(VerifyOption_G1UseNextMarking, "During GC (after)");
1061 }
1062 g1h->verifier()->check_bitmaps("Remark End");
1063 assert(!restart_for_overflow(), "sanity");
1064 // Completely reset the marking state since marking completed
1065 set_non_marking_state();
1066 }
1067
1068 // Statistics
1069 double now = os::elapsedTime();
1070 _remark_mark_times.add((mark_work_end - start) * 1000.0);
1071 _remark_weak_ref_times.add((now - mark_work_end) * 1000.0);
1072 _remark_times.add((now - start) * 1000.0);
1073
1074 g1p->record_concurrent_mark_remark_end();
1075
1076 G1CMIsAliveClosure is_alive(g1h);
1077 _gc_tracer_cm->report_object_count_after_gc(&is_alive);
1078 }
1079
1080 class G1NoteEndOfConcMarkClosure : public HeapRegionClosure {
1172 HeapRegionRemSet::finish_cleanup_task(&hrrs_cleanup_task);
1173 }
1174 }
1175 };
1176
1177 void G1ConcurrentMark::cleanup() {
1178 // world is stopped at this checkpoint
1179 assert(SafepointSynchronize::is_at_safepoint(),
1180 "world should be stopped");
1181 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1182
1183 // If a full collection has happened, we shouldn't do this.
1184 if (has_aborted()) {
1185 g1h->collector_state()->set_mark_in_progress(false); // So bitmap clearing isn't confused
1186 return;
1187 }
1188
1189 g1h->verifier()->verify_region_sets_optional();
1190
1191 if (VerifyDuringGC) {
1192 HandleMark hm; // handle scope
1193 g1h->prepare_for_verify();
1194 Universe::verify(VerifyOption_G1UsePrevMarking, "During GC (before)");
1195 }
1196 g1h->verifier()->check_bitmaps("Cleanup Start");
1197
1198 G1Policy* g1p = g1h->g1_policy();
1199 g1p->record_concurrent_mark_cleanup_start();
1200
1201 double start = os::elapsedTime();
1202
1203 HeapRegionRemSet::reset_for_cleanup_tasks();
1204
1205 {
1206 GCTraceTime(Debug, gc)("Finalize Live Data");
1207 finalize_live_data();
1208 }
1209
1210 if (VerifyDuringGC) {
1211 GCTraceTime(Debug, gc)("Verify Live Data");
1212 verify_live_data();
1213 }
1214
1246 // regions.
1247 if (G1ScrubRemSets) {
1248 double rs_scrub_start = os::elapsedTime();
1249 g1h->scrub_rem_set();
1250 _total_rs_scrub_time += (os::elapsedTime() - rs_scrub_start);
1251 }
1252
1253 // this will also free any regions totally full of garbage objects,
1254 // and sort the regions.
1255 g1h->g1_policy()->record_concurrent_mark_cleanup_end();
1256
1257 // Statistics.
1258 double end = os::elapsedTime();
1259 _cleanup_times.add((end - start) * 1000.0);
1260
1261 // Clean up will have freed any regions completely full of garbage.
1262 // Update the soft reference policy with the new heap occupancy.
1263 Universe::update_heap_info_at_gc();
1264
1265 if (VerifyDuringGC) {
1266 HandleMark hm; // handle scope
1267 g1h->prepare_for_verify();
1268 Universe::verify(VerifyOption_G1UsePrevMarking, "During GC (after)");
1269 }
1270
1271 g1h->verifier()->check_bitmaps("Cleanup End");
1272
1273 g1h->verifier()->verify_region_sets_optional();
1274
1275 // We need to make this be a "collection" so any collection pause that
1276 // races with it goes around and waits for completeCleanup to finish.
1277 g1h->increment_total_collections();
1278
1279 // Clean out dead classes and update Metaspace sizes.
1280 if (ClassUnloadingWithConcurrentMark) {
1281 ClassLoaderDataGraph::purge();
1282 }
1283 MetaspaceGC::compute_new_size();
1284
1285 // We reclaimed old regions so we should calculate the sizes to make
1286 // sure we update the old gen/space data.
1287 g1h->g1mm()->update_sizes();
1288 g1h->allocation_context_stats().update_after_mark();
|
998 _concurrent_workers->run_task(&marking_task);
999 print_stats();
1000 }
1001
1002 void G1ConcurrentMark::checkpoint_roots_final(bool clear_all_soft_refs) {
1003 // world is stopped at this checkpoint
1004 assert(SafepointSynchronize::is_at_safepoint(),
1005 "world should be stopped");
1006
1007 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1008
1009 // If a full collection has happened, we shouldn't do this.
1010 if (has_aborted()) {
1011 g1h->collector_state()->set_mark_in_progress(false); // So bitmap clearing isn't confused
1012 return;
1013 }
1014
1015 SvcGCMarker sgcm(SvcGCMarker::OTHER);
1016
1017 if (VerifyDuringGC) {
1018 g1h->verifier()->verify(G1HeapVerifier::G1VerifyRemark, VerifyOption_G1UsePrevMarking, "During GC (before)");
1019 }
1020 g1h->verifier()->check_bitmaps("Remark Start");
1021
1022 G1Policy* g1p = g1h->g1_policy();
1023 g1p->record_concurrent_mark_remark_start();
1024
1025 double start = os::elapsedTime();
1026
1027 checkpoint_roots_final_work();
1028
1029 double mark_work_end = os::elapsedTime();
1030
1031 weak_refs_work(clear_all_soft_refs);
1032
1033 if (has_overflown()) {
1034 // We overflowed. Restart concurrent marking.
1035 _restart_for_overflow = true;
1036
1037 // Verify the heap w.r.t. the previous marking bitmap.
1038 if (VerifyDuringGC) {
1039 g1h->verifier()->verify(G1HeapVerifier::G1VerifyRemark, VerifyOption_G1UsePrevMarking, "During GC (overflow)");
1040 }
1041
1042 // Clear the marking state because we will be restarting
1043 // marking due to overflowing the global mark stack.
1044 reset_marking_state();
1045 } else {
1046 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
1047 // We're done with marking.
1048 // This is the end of the marking cycle, we're expected all
1049 // threads to have SATB queues with active set to true.
1050 satb_mq_set.set_active_all_threads(false, /* new active value */
1051 true /* expected_active */);
1052
1053 if (VerifyDuringGC) {
1054 g1h->verifier()->verify(G1HeapVerifier::G1VerifyRemark, VerifyOption_G1UseNextMarking, "During GC (after)");
1055 }
1056 g1h->verifier()->check_bitmaps("Remark End");
1057 assert(!restart_for_overflow(), "sanity");
1058 // Completely reset the marking state since marking completed
1059 set_non_marking_state();
1060 }
1061
1062 // Statistics
1063 double now = os::elapsedTime();
1064 _remark_mark_times.add((mark_work_end - start) * 1000.0);
1065 _remark_weak_ref_times.add((now - mark_work_end) * 1000.0);
1066 _remark_times.add((now - start) * 1000.0);
1067
1068 g1p->record_concurrent_mark_remark_end();
1069
1070 G1CMIsAliveClosure is_alive(g1h);
1071 _gc_tracer_cm->report_object_count_after_gc(&is_alive);
1072 }
1073
1074 class G1NoteEndOfConcMarkClosure : public HeapRegionClosure {
1166 HeapRegionRemSet::finish_cleanup_task(&hrrs_cleanup_task);
1167 }
1168 }
1169 };
1170
1171 void G1ConcurrentMark::cleanup() {
1172 // world is stopped at this checkpoint
1173 assert(SafepointSynchronize::is_at_safepoint(),
1174 "world should be stopped");
1175 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1176
1177 // If a full collection has happened, we shouldn't do this.
1178 if (has_aborted()) {
1179 g1h->collector_state()->set_mark_in_progress(false); // So bitmap clearing isn't confused
1180 return;
1181 }
1182
1183 g1h->verifier()->verify_region_sets_optional();
1184
1185 if (VerifyDuringGC) {
1186 g1h->verifier()->verify(G1HeapVerifier::G1VerifyCleanup, VerifyOption_G1UsePrevMarking, "During GC (before)");
1187 }
1188 g1h->verifier()->check_bitmaps("Cleanup Start");
1189
1190 G1Policy* g1p = g1h->g1_policy();
1191 g1p->record_concurrent_mark_cleanup_start();
1192
1193 double start = os::elapsedTime();
1194
1195 HeapRegionRemSet::reset_for_cleanup_tasks();
1196
1197 {
1198 GCTraceTime(Debug, gc)("Finalize Live Data");
1199 finalize_live_data();
1200 }
1201
1202 if (VerifyDuringGC) {
1203 GCTraceTime(Debug, gc)("Verify Live Data");
1204 verify_live_data();
1205 }
1206
1238 // regions.
1239 if (G1ScrubRemSets) {
1240 double rs_scrub_start = os::elapsedTime();
1241 g1h->scrub_rem_set();
1242 _total_rs_scrub_time += (os::elapsedTime() - rs_scrub_start);
1243 }
1244
1245 // this will also free any regions totally full of garbage objects,
1246 // and sort the regions.
1247 g1h->g1_policy()->record_concurrent_mark_cleanup_end();
1248
1249 // Statistics.
1250 double end = os::elapsedTime();
1251 _cleanup_times.add((end - start) * 1000.0);
1252
1253 // Clean up will have freed any regions completely full of garbage.
1254 // Update the soft reference policy with the new heap occupancy.
1255 Universe::update_heap_info_at_gc();
1256
1257 if (VerifyDuringGC) {
1258 g1h->verifier()->verify(G1HeapVerifier::G1VerifyCleanup, VerifyOption_G1UsePrevMarking, "During GC (after)");
1259 }
1260
1261 g1h->verifier()->check_bitmaps("Cleanup End");
1262
1263 g1h->verifier()->verify_region_sets_optional();
1264
1265 // We need to make this be a "collection" so any collection pause that
1266 // races with it goes around and waits for completeCleanup to finish.
1267 g1h->increment_total_collections();
1268
1269 // Clean out dead classes and update Metaspace sizes.
1270 if (ClassUnloadingWithConcurrentMark) {
1271 ClassLoaderDataGraph::purge();
1272 }
1273 MetaspaceGC::compute_new_size();
1274
1275 // We reclaimed old regions so we should calculate the sizes to make
1276 // sure we update the old gen/space data.
1277 g1h->g1mm()->update_sizes();
1278 g1h->allocation_context_stats().update_after_mark();
|