1243 assert(SafepointSynchronize::is_at_safepoint(),
1244 "world should be stopped");
1245
1246 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1247
1248 // If a full collection has happened, we shouldn't do this.
1249 if (has_aborted()) {
1250 g1h->set_marking_complete(); // So bitmap clearing isn't confused
1251 return;
1252 }
1253
1254 SvcGCMarker sgcm(SvcGCMarker::OTHER);
1255
1256 if (VerifyDuringGC) {
1257 HandleMark hm; // handle scope
1258 gclog_or_tty->print(" VerifyDuringGC:(before)");
1259 Universe::heap()->prepare_for_verify();
1260 Universe::verify(/* silent */ false,
1261 /* option */ VerifyOption_G1UsePrevMarking);
1262 }
1263
1264 G1CollectorPolicy* g1p = g1h->g1_policy();
1265 g1p->record_concurrent_mark_remark_start();
1266
1267 double start = os::elapsedTime();
1268
1269 checkpointRootsFinalWork();
1270
1271 double mark_work_end = os::elapsedTime();
1272
1273 weakRefsWork(clear_all_soft_refs);
1274
1275 if (has_overflown()) {
1276 // Oops. We overflowed. Restart concurrent marking.
1277 _restart_for_overflow = true;
1278 // Clear the marking state because we will be restarting
1279 // marking due to overflowing the global mark stack.
1280 reset_marking_state();
1281 if (G1TraceMarkStackOverflow) {
1282 gclog_or_tty->print_cr("\nRemark led to restart for overflow.");
1283 }
1284 } else {
1285 // Aggregate the per-task counting data that we have accumulated
1286 // while marking.
1287 aggregate_count_data();
1288
1289 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
1290 // We're done with marking.
1291 // This is the end of the marking cycle, we're expected all
1292 // threads to have SATB queues with active set to true.
1293 satb_mq_set.set_active_all_threads(false, /* new active value */
1294 true /* expected_active */);
1295
1296 if (VerifyDuringGC) {
1297 HandleMark hm; // handle scope
1298 gclog_or_tty->print(" VerifyDuringGC:(after)");
1299 Universe::heap()->prepare_for_verify();
1300 Universe::verify(/* silent */ false,
1301 /* option */ VerifyOption_G1UseNextMarking);
1302 }
1303 assert(!restart_for_overflow(), "sanity");
1304 // Completely reset the marking state since marking completed
1305 set_non_marking_state();
1306 }
1307
1308 // Expand the marking stack, if we have to and if we can.
1309 if (_markStack.should_expand()) {
1310 _markStack.expand();
1311 }
1312
1313 #if VERIFY_OBJS_PROCESSED
1314 _scan_obj_cl.objs_processed = 0;
1315 ThreadLocalObjQueue::objs_enqueued = 0;
1316 #endif
1317
1318 // Statistics
1319 double now = os::elapsedTime();
1320 _remark_mark_times.add((mark_work_end - start) * 1000.0);
1321 _remark_weak_ref_times.add((now - mark_work_end) * 1000.0);
1322 _remark_times.add((now - start) * 1000.0);
1937 assert(SafepointSynchronize::is_at_safepoint(),
1938 "world should be stopped");
1939 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1940
1941 // If a full collection has happened, we shouldn't do this.
1942 if (has_aborted()) {
1943 g1h->set_marking_complete(); // So bitmap clearing isn't confused
1944 return;
1945 }
1946
1947 HRSPhaseSetter x(HRSPhaseCleanup);
1948 g1h->verify_region_sets_optional();
1949
1950 if (VerifyDuringGC) {
1951 HandleMark hm; // handle scope
1952 gclog_or_tty->print(" VerifyDuringGC:(before)");
1953 Universe::heap()->prepare_for_verify();
1954 Universe::verify(/* silent */ false,
1955 /* option */ VerifyOption_G1UsePrevMarking);
1956 }
1957
1958 G1CollectorPolicy* g1p = G1CollectedHeap::heap()->g1_policy();
1959 g1p->record_concurrent_mark_cleanup_start();
1960
1961 double start = os::elapsedTime();
1962
1963 HeapRegionRemSet::reset_for_cleanup_tasks();
1964
1965 uint n_workers;
1966
1967 // Do counting once more with the world stopped for good measure.
1968 G1ParFinalCountTask g1_par_count_task(g1h, &_region_bm, &_card_bm);
1969
1970 if (G1CollectedHeap::use_parallel_gc_threads()) {
1971 assert(g1h->check_heap_region_claim_values(HeapRegion::InitialClaimValue),
1972 "sanity check");
1973
1974 g1h->set_par_threads();
1975 n_workers = g1h->n_par_threads();
1976 assert(g1h->n_par_threads() == n_workers,
2092
2093 // Clean up will have freed any regions completely full of garbage.
2094 // Update the soft reference policy with the new heap occupancy.
2095 Universe::update_heap_info_at_gc();
2096
2097 // We need to make this be a "collection" so any collection pause that
2098 // races with it goes around and waits for completeCleanup to finish.
2099 g1h->increment_total_collections();
2100
2101 // We reclaimed old regions so we should calculate the sizes to make
2102 // sure we update the old gen/space data.
2103 g1h->g1mm()->update_sizes();
2104
2105 if (VerifyDuringGC) {
2106 HandleMark hm; // handle scope
2107 gclog_or_tty->print(" VerifyDuringGC:(after)");
2108 Universe::heap()->prepare_for_verify();
2109 Universe::verify(/* silent */ false,
2110 /* option */ VerifyOption_G1UsePrevMarking);
2111 }
2112
2113 g1h->verify_region_sets_optional();
2114 }
2115
2116 void ConcurrentMark::completeCleanup() {
2117 if (has_aborted()) return;
2118
2119 G1CollectedHeap* g1h = G1CollectedHeap::heap();
2120
2121 _cleanup_list.verify_optional();
2122 FreeRegionList tmp_free_list("Tmp Free List");
2123
2124 if (G1ConcRegionFreeingVerbose) {
2125 gclog_or_tty->print_cr("G1ConcRegionFreeing [complete cleanup] : "
2126 "cleanup list has %u entries",
2127 _cleanup_list.length());
2128 }
2129
2130 // Noone else should be accessing the _cleanup_list at this point,
2131 // so it's not necessary to take any locks
3165
3166 memset(marked_bytes_array, 0, (size_t) max_regions * sizeof(size_t));
3167 task_card_bm->clear();
3168 }
3169 }
3170
3171 void ConcurrentMark::print_stats() {
3172 if (verbose_stats()) {
3173 gclog_or_tty->print_cr("---------------------------------------------------------------------");
3174 for (size_t i = 0; i < _active_tasks; ++i) {
3175 _tasks[i]->print_stats();
3176 gclog_or_tty->print_cr("---------------------------------------------------------------------");
3177 }
3178 }
3179 }
3180
3181 // abandon current marking iteration due to a Full GC
3182 void ConcurrentMark::abort() {
3183 // Clear all marks to force marking thread to do nothing
3184 _nextMarkBitMap->clearAll();
3185 // Clear the liveness counting data
3186 clear_all_count_data();
3187 // Empty mark stack
3188 reset_marking_state();
3189 for (uint i = 0; i < _max_worker_id; ++i) {
3190 _tasks[i]->clear_region_fields();
3191 }
3192 _has_aborted = true;
3193
3194 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
3195 satb_mq_set.abandon_partial_marking();
3196 // This can be called either during or outside marking, we'll read
3197 // the expected_active value from the SATB queue set.
3198 satb_mq_set.set_active_all_threads(
3199 false, /* new active value */
3200 satb_mq_set.is_active() /* expected_active */);
3201 }
3202
3203 static void print_ms_time_info(const char* prefix, const char* name,
3204 NumberSeq& ns) {
|
1243 assert(SafepointSynchronize::is_at_safepoint(),
1244 "world should be stopped");
1245
1246 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1247
1248 // If a full collection has happened, we shouldn't do this.
1249 if (has_aborted()) {
1250 g1h->set_marking_complete(); // So bitmap clearing isn't confused
1251 return;
1252 }
1253
1254 SvcGCMarker sgcm(SvcGCMarker::OTHER);
1255
1256 if (VerifyDuringGC) {
1257 HandleMark hm; // handle scope
1258 gclog_or_tty->print(" VerifyDuringGC:(before)");
1259 Universe::heap()->prepare_for_verify();
1260 Universe::verify(/* silent */ false,
1261 /* option */ VerifyOption_G1UsePrevMarking);
1262 }
1263 g1h->check_bitmaps("Remark Start");
1264
1265 G1CollectorPolicy* g1p = g1h->g1_policy();
1266 g1p->record_concurrent_mark_remark_start();
1267
1268 double start = os::elapsedTime();
1269
1270 checkpointRootsFinalWork();
1271
1272 double mark_work_end = os::elapsedTime();
1273
1274 weakRefsWork(clear_all_soft_refs);
1275
1276 if (has_overflown()) {
1277 // Oops. We overflowed. Restart concurrent marking.
1278 _restart_for_overflow = true;
1279 // Clear the marking state because we will be restarting
1280 // marking due to overflowing the global mark stack.
1281 reset_marking_state();
1282 if (G1TraceMarkStackOverflow) {
1283 gclog_or_tty->print_cr("\nRemark led to restart for overflow.");
1284 }
1285 } else {
1286 // Aggregate the per-task counting data that we have accumulated
1287 // while marking.
1288 aggregate_count_data();
1289
1290 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
1291 // We're done with marking.
1292 // This is the end of the marking cycle, we're expected all
1293 // threads to have SATB queues with active set to true.
1294 satb_mq_set.set_active_all_threads(false, /* new active value */
1295 true /* expected_active */);
1296
1297 if (VerifyDuringGC) {
1298 HandleMark hm; // handle scope
1299 gclog_or_tty->print(" VerifyDuringGC:(after)");
1300 Universe::heap()->prepare_for_verify();
1301 Universe::verify(/* silent */ false,
1302 /* option */ VerifyOption_G1UseNextMarking);
1303 }
1304 g1h->check_bitmaps("Remark End");
1305 assert(!restart_for_overflow(), "sanity");
1306 // Completely reset the marking state since marking completed
1307 set_non_marking_state();
1308 }
1309
1310 // Expand the marking stack, if we have to and if we can.
1311 if (_markStack.should_expand()) {
1312 _markStack.expand();
1313 }
1314
1315 #if VERIFY_OBJS_PROCESSED
1316 _scan_obj_cl.objs_processed = 0;
1317 ThreadLocalObjQueue::objs_enqueued = 0;
1318 #endif
1319
1320 // Statistics
1321 double now = os::elapsedTime();
1322 _remark_mark_times.add((mark_work_end - start) * 1000.0);
1323 _remark_weak_ref_times.add((now - mark_work_end) * 1000.0);
1324 _remark_times.add((now - start) * 1000.0);
1939 assert(SafepointSynchronize::is_at_safepoint(),
1940 "world should be stopped");
1941 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1942
1943 // If a full collection has happened, we shouldn't do this.
1944 if (has_aborted()) {
1945 g1h->set_marking_complete(); // So bitmap clearing isn't confused
1946 return;
1947 }
1948
1949 HRSPhaseSetter x(HRSPhaseCleanup);
1950 g1h->verify_region_sets_optional();
1951
1952 if (VerifyDuringGC) {
1953 HandleMark hm; // handle scope
1954 gclog_or_tty->print(" VerifyDuringGC:(before)");
1955 Universe::heap()->prepare_for_verify();
1956 Universe::verify(/* silent */ false,
1957 /* option */ VerifyOption_G1UsePrevMarking);
1958 }
1959 g1h->check_bitmaps("Cleanup Start");
1960
1961 G1CollectorPolicy* g1p = G1CollectedHeap::heap()->g1_policy();
1962 g1p->record_concurrent_mark_cleanup_start();
1963
1964 double start = os::elapsedTime();
1965
1966 HeapRegionRemSet::reset_for_cleanup_tasks();
1967
1968 uint n_workers;
1969
1970 // Do counting once more with the world stopped for good measure.
1971 G1ParFinalCountTask g1_par_count_task(g1h, &_region_bm, &_card_bm);
1972
1973 if (G1CollectedHeap::use_parallel_gc_threads()) {
1974 assert(g1h->check_heap_region_claim_values(HeapRegion::InitialClaimValue),
1975 "sanity check");
1976
1977 g1h->set_par_threads();
1978 n_workers = g1h->n_par_threads();
1979 assert(g1h->n_par_threads() == n_workers,
2095
2096 // Clean up will have freed any regions completely full of garbage.
2097 // Update the soft reference policy with the new heap occupancy.
2098 Universe::update_heap_info_at_gc();
2099
2100 // We need to make this be a "collection" so any collection pause that
2101 // races with it goes around and waits for completeCleanup to finish.
2102 g1h->increment_total_collections();
2103
2104 // We reclaimed old regions so we should calculate the sizes to make
2105 // sure we update the old gen/space data.
2106 g1h->g1mm()->update_sizes();
2107
2108 if (VerifyDuringGC) {
2109 HandleMark hm; // handle scope
2110 gclog_or_tty->print(" VerifyDuringGC:(after)");
2111 Universe::heap()->prepare_for_verify();
2112 Universe::verify(/* silent */ false,
2113 /* option */ VerifyOption_G1UsePrevMarking);
2114 }
2115 g1h->check_bitmaps("Cleanup End");
2116
2117 g1h->verify_region_sets_optional();
2118 }
2119
2120 void ConcurrentMark::completeCleanup() {
2121 if (has_aborted()) return;
2122
2123 G1CollectedHeap* g1h = G1CollectedHeap::heap();
2124
2125 _cleanup_list.verify_optional();
2126 FreeRegionList tmp_free_list("Tmp Free List");
2127
2128 if (G1ConcRegionFreeingVerbose) {
2129 gclog_or_tty->print_cr("G1ConcRegionFreeing [complete cleanup] : "
2130 "cleanup list has %u entries",
2131 _cleanup_list.length());
2132 }
2133
2134 // Noone else should be accessing the _cleanup_list at this point,
2135 // so it's not necessary to take any locks
3169
3170 memset(marked_bytes_array, 0, (size_t) max_regions * sizeof(size_t));
3171 task_card_bm->clear();
3172 }
3173 }
3174
3175 void ConcurrentMark::print_stats() {
3176 if (verbose_stats()) {
3177 gclog_or_tty->print_cr("---------------------------------------------------------------------");
3178 for (size_t i = 0; i < _active_tasks; ++i) {
3179 _tasks[i]->print_stats();
3180 gclog_or_tty->print_cr("---------------------------------------------------------------------");
3181 }
3182 }
3183 }
3184
3185 // abandon current marking iteration due to a Full GC
3186 void ConcurrentMark::abort() {
3187 // Clear all marks to force marking thread to do nothing
3188 _nextMarkBitMap->clearAll();
3189
3190 // Note we cannot clear the previous marking bitmap here
3191 // since VerifyDuringGC verifies the objects marked during
3192 // a full GC against the previous bitmap.
3193
3194 // Clear the liveness counting data
3195 clear_all_count_data();
3196 // Empty mark stack
3197 reset_marking_state();
3198 for (uint i = 0; i < _max_worker_id; ++i) {
3199 _tasks[i]->clear_region_fields();
3200 }
3201 _has_aborted = true;
3202
3203 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set();
3204 satb_mq_set.abandon_partial_marking();
3205 // This can be called either during or outside marking, we'll read
3206 // the expected_active value from the SATB queue set.
3207 satb_mq_set.set_active_all_threads(
3208 false, /* new active value */
3209 satb_mq_set.is_active() /* expected_active */);
3210 }
3211
3212 static void print_ms_time_info(const char* prefix, const char* name,
3213 NumberSeq& ns) {
|