877 // At this time we record some metrics only for the evacuations after the initial one.
878 if (scan_phase == G1GCPhaseTimes::OptScanHR) {
879 p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_refs_scanned(), G1GCPhaseTimes::ScanHRScannedOptRefs);
880 p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_refs_memory_used(), G1GCPhaseTimes::ScanHRUsedMemory);
881 }
882 }
883
884 void G1RemSet::prepare_region_for_scan(HeapRegion* region) {
885 uint hrm_index = region->hrm_index();
886
887 _scan_state->reset_region_claim(hrm_index);
888 if (region->in_collection_set()) {
889 // Young regions had their card table marked as young at their allocation;
890 // we need to make sure that these marks are cleared at the end of GC, *but*
891 // they should not be scanned for cards.
892 // So directly add them to the "all_dirty_regions".
893 // Same for regions in the (initial) collection set: they may contain cards from
894 // the log buffers, make sure they are cleaned.
895 _scan_state->clear_scan_top(hrm_index);
896 _scan_state->add_all_dirty_region(hrm_index);
897 } else {
898 assert(region->is_old_or_humongous_or_archive(), "All other regions should be in the collection set");
899 _scan_state->set_scan_top(hrm_index, region->top());
900 }
901 }
902
903 void G1RemSet::prepare_for_scan_heap_roots() {
904 G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
905 dcqs.concatenate_logs();
906
907 _scan_state->prepare();
908 }
909
910 class G1MergeHeapRootsTask : public AbstractGangTask {
911
912 // Visitor for remembered sets, dropping entries onto the card table.
913 class G1MergeCardSetClosure : public HeapRegionClosure {
914 G1RemSetScanState* _scan_state;
915 G1CardTable* _ct;
916
917 uint _merged_sparse;
918 uint _merged_fine;
919 uint _merged_coarse;
1210 }
1211
1212 WorkGang* workers = g1h->workers();
1213 size_t const increment_length = g1h->collection_set()->increment_length();
1214
1215 uint const num_workers = initial_evacuation ? workers->active_workers() :
1216 MIN2(workers->active_workers(), (uint)increment_length);
1217
1218 {
1219 G1MergeHeapRootsTask cl(_scan_state, num_workers, initial_evacuation);
1220 log_debug(gc, ergo)("Running %s using %u workers for " SIZE_FORMAT " regions",
1221 cl.name(), num_workers, increment_length);
1222 workers->run_task(&cl, num_workers);
1223 }
1224
1225 if (log_is_enabled(Debug, gc, remset)) {
1226 print_merge_heap_roots_stats();
1227 }
1228 }
1229
1230 void G1RemSet::prepare_for_scan_heap_roots(uint region_idx) {
1231 _scan_state->clear_scan_top(region_idx);
1232 }
1233
1234 void G1RemSet::cleanup_after_scan_heap_roots() {
1235 G1GCPhaseTimes* phase_times = _g1h->phase_times();
1236
1237 // Set all cards back to clean.
1238 double start = os::elapsedTime();
1239 _scan_state->cleanup(_g1h->workers());
1240 phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0);
1241 }
1242
1243 inline void check_card_ptr(CardTable::CardValue* card_ptr, G1CardTable* ct) {
1244 #ifdef ASSERT
1245 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1246 assert(g1h->is_in_exact(ct->addr_for(card_ptr)),
1247 "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap",
1248 p2i(card_ptr),
1249 ct->index_for(ct->addr_for(card_ptr)),
1250 p2i(ct->addr_for(card_ptr)),
|
877 // At this time we record some metrics only for the evacuations after the initial one.
878 if (scan_phase == G1GCPhaseTimes::OptScanHR) {
879 p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_refs_scanned(), G1GCPhaseTimes::ScanHRScannedOptRefs);
880 p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_refs_memory_used(), G1GCPhaseTimes::ScanHRUsedMemory);
881 }
882 }
883
884 void G1RemSet::prepare_region_for_scan(HeapRegion* region) {
885 uint hrm_index = region->hrm_index();
886
887 _scan_state->reset_region_claim(hrm_index);
888 if (region->in_collection_set()) {
889 // Young regions had their card table marked as young at their allocation;
890 // we need to make sure that these marks are cleared at the end of GC, *but*
891 // they should not be scanned for cards.
892 // So directly add them to the "all_dirty_regions".
893 // Same for regions in the (initial) collection set: they may contain cards from
894 // the log buffers, make sure they are cleaned.
895 _scan_state->clear_scan_top(hrm_index);
896 _scan_state->add_all_dirty_region(hrm_index);
897 } else if (region->is_old_or_humongous_or_archive()) {
898 _scan_state->set_scan_top(hrm_index, region->top());
899 } else {
900 assert(region->is_free(), "Should only be free region at this point %s", region->get_type_str());
901 }
902 }
903
904 void G1RemSet::prepare_for_scan_heap_roots() {
905 G1DirtyCardQueueSet& dcqs = G1BarrierSet::dirty_card_queue_set();
906 dcqs.concatenate_logs();
907
908 _scan_state->prepare();
909 }
910
911 class G1MergeHeapRootsTask : public AbstractGangTask {
912
913 // Visitor for remembered sets, dropping entries onto the card table.
914 class G1MergeCardSetClosure : public HeapRegionClosure {
915 G1RemSetScanState* _scan_state;
916 G1CardTable* _ct;
917
918 uint _merged_sparse;
919 uint _merged_fine;
920 uint _merged_coarse;
1211 }
1212
1213 WorkGang* workers = g1h->workers();
1214 size_t const increment_length = g1h->collection_set()->increment_length();
1215
1216 uint const num_workers = initial_evacuation ? workers->active_workers() :
1217 MIN2(workers->active_workers(), (uint)increment_length);
1218
1219 {
1220 G1MergeHeapRootsTask cl(_scan_state, num_workers, initial_evacuation);
1221 log_debug(gc, ergo)("Running %s using %u workers for " SIZE_FORMAT " regions",
1222 cl.name(), num_workers, increment_length);
1223 workers->run_task(&cl, num_workers);
1224 }
1225
1226 if (log_is_enabled(Debug, gc, remset)) {
1227 print_merge_heap_roots_stats();
1228 }
1229 }
1230
1231 void G1RemSet::exclude_region_from_scan(uint region_idx) {
1232 _scan_state->clear_scan_top(region_idx);
1233 }
1234
1235 void G1RemSet::cleanup_after_scan_heap_roots() {
1236 G1GCPhaseTimes* phase_times = _g1h->phase_times();
1237
1238 // Set all cards back to clean.
1239 double start = os::elapsedTime();
1240 _scan_state->cleanup(_g1h->workers());
1241 phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0);
1242 }
1243
1244 inline void check_card_ptr(CardTable::CardValue* card_ptr, G1CardTable* ct) {
1245 #ifdef ASSERT
1246 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1247 assert(g1h->is_in_exact(ct->addr_for(card_ptr)),
1248 "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap",
1249 p2i(card_ptr),
1250 ct->index_for(ct->addr_for(card_ptr)),
1251 p2i(ct->addr_for(card_ptr)),
|