1162 ConcurrentMark* _cm; 1163 1164 public: 1165 CMRootRegionScanTask(ConcurrentMark* cm) : 1166 AbstractGangTask("Root Region Scan"), _cm(cm) { } 1167 1168 void work(uint worker_id) { 1169 assert(Thread::current()->is_ConcurrentGC_thread(), 1170 "this should only be done by a conc GC thread"); 1171 1172 CMRootRegions* root_regions = _cm->root_regions(); 1173 HeapRegion* hr = root_regions->claim_next(); 1174 while (hr != NULL) { 1175 _cm->scanRootRegion(hr, worker_id); 1176 hr = root_regions->claim_next(); 1177 } 1178 } 1179 }; 1180 1181 void ConcurrentMark::scanRootRegions() { 1182 // Start of concurrent marking. 1183 ClassLoaderDataGraph::clear_claimed_marks(); 1184 1185 // scan_in_progress() will have been set to true only if there was 1186 // at least one root region to scan. So, if it's false, we 1187 // should not attempt to do any further work. 1188 if (root_regions()->scan_in_progress()) { 1189 _parallel_marking_threads = calc_parallel_marking_threads(); 1190 assert(parallel_marking_threads() <= max_parallel_marking_threads(), 1191 "Maximum number of marking threads exceeded"); 1192 uint active_workers = MAX2(1U, parallel_marking_threads()); 1193 1194 CMRootRegionScanTask task(this); 1195 _parallel_workers->set_active_workers(active_workers); 1196 _parallel_workers->run_task(&task); 1197 1198 // It's possible that has_aborted() is true here without actually 1199 // aborting the survivor scan earlier. This is OK as it's 1200 // mainly used for sanity checking. 1201 root_regions()->scan_finished(); 1202 } 1203 } 1204 1205 void ConcurrentMark::markFromRoots() { 1206 // we might be tempted to assert that: 1207 // assert(asynch == !SafepointSynchronize::is_at_safepoint(), 1208 // "inconsistent argument?"); 1209 // However that wouldn't be right, because it's possible that 1210 // a safepoint is indeed in progress as a younger generation 1211 // stop-the-world GC happens even as we mark in this generation. 1212 1213 _restart_for_overflow = false; 1214 force_overflow_conc()->init(); 1215 1216 // _g1h has _n_par_threads 1217 _parallel_marking_threads = calc_parallel_marking_threads(); 2976 assert(task_card_bm->size() == _card_bm.size(), "size mismatch"); 2977 assert(marked_bytes_array != NULL, "uninitialized"); 2978 2979 memset(marked_bytes_array, 0, (size_t) max_regions * sizeof(size_t)); 2980 task_card_bm->clear(); 2981 } 2982 } 2983 2984 void ConcurrentMark::print_stats() { 2985 if (verbose_stats()) { 2986 gclog_or_tty->print_cr("---------------------------------------------------------------------"); 2987 for (size_t i = 0; i < _active_tasks; ++i) { 2988 _tasks[i]->print_stats(); 2989 gclog_or_tty->print_cr("---------------------------------------------------------------------"); 2990 } 2991 } 2992 } 2993 2994 // abandon current marking iteration due to a Full GC 2995 void ConcurrentMark::abort() { 2996 // Clear all marks in the next bitmap for the next marking cycle. This will allow us to skip the next 2997 // concurrent bitmap clearing. 2998 _nextMarkBitMap->clearAll(); 2999 3000 // Note we cannot clear the previous marking bitmap here 3001 // since VerifyDuringGC verifies the objects marked during 3002 // a full GC against the previous bitmap. 3003 3004 // Clear the liveness counting data 3005 clear_all_count_data(); 3006 // Empty mark stack 3007 reset_marking_state(); 3008 for (uint i = 0; i < _max_worker_id; ++i) { 3009 _tasks[i]->clear_region_fields(); 3010 } 3011 _first_overflow_barrier_sync.abort(); 3012 _second_overflow_barrier_sync.abort(); 3013 const GCId& gc_id = _g1h->gc_tracer_cm()->gc_id(); 3014 if (!gc_id.is_undefined()) { 3015 // We can do multiple full GCs before ConcurrentMarkThread::run() gets a chance 3016 // to detect that it was aborted. Only keep track of the first GC id that we aborted. 3017 _aborted_gc_id = gc_id; 3018 } 3019 _has_aborted = true; 3020 3021 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); 3022 satb_mq_set.abandon_partial_marking(); 3023 // This can be called either during or outside marking, we'll read 3024 // the expected_active value from the SATB queue set. 3025 satb_mq_set.set_active_all_threads( 3026 false, /* new active value */ 3027 satb_mq_set.is_active() /* expected_active */); 3028 3029 _g1h->trace_heap_after_concurrent_cycle(); 3030 _g1h->register_concurrent_cycle_end(); 3031 } 3032 3033 const GCId& ConcurrentMark::concurrent_gc_id() { 3034 if (has_aborted()) { 3035 return _aborted_gc_id; 3036 } 3037 return _g1h->gc_tracer_cm()->gc_id(); 3038 } | 1162 ConcurrentMark* _cm; 1163 1164 public: 1165 CMRootRegionScanTask(ConcurrentMark* cm) : 1166 AbstractGangTask("Root Region Scan"), _cm(cm) { } 1167 1168 void work(uint worker_id) { 1169 assert(Thread::current()->is_ConcurrentGC_thread(), 1170 "this should only be done by a conc GC thread"); 1171 1172 CMRootRegions* root_regions = _cm->root_regions(); 1173 HeapRegion* hr = root_regions->claim_next(); 1174 while (hr != NULL) { 1175 _cm->scanRootRegion(hr, worker_id); 1176 hr = root_regions->claim_next(); 1177 } 1178 } 1179 }; 1180 1181 void ConcurrentMark::scanRootRegions() { 1182 double scan_start = os::elapsedTime(); 1183 1184 // Start of concurrent marking. 1185 ClassLoaderDataGraph::clear_claimed_marks(); 1186 1187 // scan_in_progress() will have been set to true only if there was 1188 // at least one root region to scan. So, if it's false, we 1189 // should not attempt to do any further work. 1190 if (root_regions()->scan_in_progress()) { 1191 if (G1Log::fine()) { 1192 gclog_or_tty->gclog_stamp(concurrent_gc_id()); 1193 gclog_or_tty->print_cr("[GC concurrent-root-region-scan-start]"); 1194 } 1195 1196 _parallel_marking_threads = calc_parallel_marking_threads(); 1197 assert(parallel_marking_threads() <= max_parallel_marking_threads(), 1198 "Maximum number of marking threads exceeded"); 1199 uint active_workers = MAX2(1U, parallel_marking_threads()); 1200 1201 CMRootRegionScanTask task(this); 1202 _parallel_workers->set_active_workers(active_workers); 1203 _parallel_workers->run_task(&task); 1204 1205 if (G1Log::fine()) { 1206 gclog_or_tty->gclog_stamp(concurrent_gc_id()); 1207 gclog_or_tty->print_cr("[GC concurrent-root-region-scan-end, %1.7lf secs]", os::elapsedTime() - scan_start); 1208 } 1209 1210 // It's possible that has_aborted() is true here without actually 1211 // aborting the survivor scan earlier. This is OK as it's 1212 // mainly used for sanity checking. 1213 root_regions()->scan_finished(); 1214 } 1215 } 1216 1217 void ConcurrentMark::markFromRoots() { 1218 // we might be tempted to assert that: 1219 // assert(asynch == !SafepointSynchronize::is_at_safepoint(), 1220 // "inconsistent argument?"); 1221 // However that wouldn't be right, because it's possible that 1222 // a safepoint is indeed in progress as a younger generation 1223 // stop-the-world GC happens even as we mark in this generation. 1224 1225 _restart_for_overflow = false; 1226 force_overflow_conc()->init(); 1227 1228 // _g1h has _n_par_threads 1229 _parallel_marking_threads = calc_parallel_marking_threads(); 2988 assert(task_card_bm->size() == _card_bm.size(), "size mismatch"); 2989 assert(marked_bytes_array != NULL, "uninitialized"); 2990 2991 memset(marked_bytes_array, 0, (size_t) max_regions * sizeof(size_t)); 2992 task_card_bm->clear(); 2993 } 2994 } 2995 2996 void ConcurrentMark::print_stats() { 2997 if (verbose_stats()) { 2998 gclog_or_tty->print_cr("---------------------------------------------------------------------"); 2999 for (size_t i = 0; i < _active_tasks; ++i) { 3000 _tasks[i]->print_stats(); 3001 gclog_or_tty->print_cr("---------------------------------------------------------------------"); 3002 } 3003 } 3004 } 3005 3006 // abandon current marking iteration due to a Full GC 3007 void ConcurrentMark::abort() { 3008 if (!cmThread()->during_cycle() || _has_aborted) { 3009 // We haven't started a concurrent cycle or we have already aborted it. No need to do anything. 3010 return; 3011 } 3012 3013 // Clear all marks in the next bitmap for the next marking cycle. This will allow us to skip the next 3014 // concurrent bitmap clearing. 3015 _nextMarkBitMap->clearAll(); 3016 3017 // Note we cannot clear the previous marking bitmap here 3018 // since VerifyDuringGC verifies the objects marked during 3019 // a full GC against the previous bitmap. 3020 3021 // Clear the liveness counting data 3022 clear_all_count_data(); 3023 // Empty mark stack 3024 reset_marking_state(); 3025 for (uint i = 0; i < _max_worker_id; ++i) { 3026 _tasks[i]->clear_region_fields(); 3027 } 3028 _first_overflow_barrier_sync.abort(); 3029 _second_overflow_barrier_sync.abort(); 3030 _aborted_gc_id = _g1h->gc_tracer_cm()->gc_id(); 3031 assert(!_aborted_gc_id.is_undefined(), "ConcurrentMark::abort() executed more than once?"); 3032 _has_aborted = true; 3033 3034 SATBMarkQueueSet& satb_mq_set = JavaThread::satb_mark_queue_set(); 3035 satb_mq_set.abandon_partial_marking(); 3036 // This can be called either during or outside marking, we'll read 3037 // the expected_active value from the SATB queue set. 3038 satb_mq_set.set_active_all_threads( 3039 false, /* new active value */ 3040 satb_mq_set.is_active() /* expected_active */); 3041 3042 _g1h->trace_heap_after_concurrent_cycle(); 3043 _g1h->register_concurrent_cycle_end(); 3044 } 3045 3046 const GCId& ConcurrentMark::concurrent_gc_id() { 3047 if (has_aborted()) { 3048 return _aborted_gc_id; 3049 } 3050 return _g1h->gc_tracer_cm()->gc_id(); 3051 } |