110 // Temporary buffer holding the regions we used to store remembered set scan duplicate
111 // information. These are also called "dirty". Valid entries are from [0.._cur_dirty_region)
112 uint* _dirty_region_buffer;
113
114 typedef jbyte IsDirtyRegionState;
115 static const IsDirtyRegionState Clean = 0;
116 static const IsDirtyRegionState Dirty = 1;
117 // Holds a flag for every region whether it is in the _dirty_region_buffer already
118 // to avoid duplicates. Uses jbyte since there are no atomic instructions for bools.
119 IsDirtyRegionState* _in_dirty_region_buffer;
120 size_t _cur_dirty_region;
121
122 // Creates a snapshot of the current _top values at the start of collection to
123 // filter out card marks that we do not want to scan.
124 class G1ResetScanTopClosure : public HeapRegionClosure {
125 private:
126 HeapWord** _scan_top;
127 public:
128 G1ResetScanTopClosure(HeapWord** scan_top) : _scan_top(scan_top) { }
129
130 virtual bool doHeapRegion(HeapRegion* r) {
131 uint hrm_index = r->hrm_index();
132 if (!r->in_collection_set() && r->is_old_or_humongous()) {
133 _scan_top[hrm_index] = r->top();
134 } else {
135 _scan_top[hrm_index] = r->bottom();
136 }
137 return false;
138 }
139 };
140
141 // For each region, contains the maximum top() value to be used during this garbage
142 // collection. Subsumes common checks like filtering out everything but old and
143 // humongous regions outside the collection set.
144 // This is valid because we are not interested in scanning stray remembered set
145 // entries from free or archive regions.
146 HeapWord** _scan_top;
147 public:
148 G1RemSetScanState() :
149 _max_regions(0),
150 _iter_states(NULL),
332 }
333
334 void G1ScanRSForRegionClosure::scan_card(MemRegion mr, uint region_idx_for_card) {
335 HeapRegion* const card_region = _g1h->region_at(region_idx_for_card);
336 _scan_objs_on_card_cl->set_region(card_region);
337 card_region->oops_on_card_seq_iterate_careful<true>(mr, _scan_objs_on_card_cl);
338 _cards_scanned++;
339 }
340
341 void G1ScanRSForRegionClosure::scan_strong_code_roots(HeapRegion* r) {
342 double scan_start = os::elapsedTime();
343 r->strong_code_roots_do(_code_root_cl);
344 _strong_code_root_scan_time_sec += (os::elapsedTime() - scan_start);
345 }
346
347 void G1ScanRSForRegionClosure::claim_card(size_t card_index, const uint region_idx_for_card){
348 _ct_bs->set_card_claimed(card_index);
349 _scan_state->add_dirty_region(region_idx_for_card);
350 }
351
352 bool G1ScanRSForRegionClosure::doHeapRegion(HeapRegion* r) {
353 assert(r->in_collection_set(), "should only be called on elements of CS.");
354 uint region_idx = r->hrm_index();
355
356 if (_scan_state->iter_is_complete(region_idx)) {
357 return false;
358 }
359 if (_scan_state->claim_iter(region_idx)) {
360 // If we ever free the collection set concurrently, we should also
361 // clear the card table concurrently therefore we won't need to
362 // add regions of the collection set to the dirty cards region.
363 _scan_state->add_dirty_region(region_idx);
364 }
365
366 // We claim cards in blocks so as to reduce the contention.
367 size_t const block_size = G1RSetScanBlockSize;
368
369 HeapRegionRemSetIterator iter(r->rem_set());
370 size_t card_index;
371
372 size_t claimed_card_block = _scan_state->iter_claimed_next(region_idx, block_size);
505 _scan_state->reset();
506 }
507
508 void G1RemSet::cleanup_after_oops_into_collection_set_do() {
509 G1GCPhaseTimes* phase_times = _g1->g1_policy()->phase_times();
510
511 // Set all cards back to clean.
512 double start = os::elapsedTime();
513 _scan_state->clear_card_table(_g1->workers());
514 phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0);
515 }
516
517 class G1ScrubRSClosure: public HeapRegionClosure {
518 G1CollectedHeap* _g1h;
519 G1CardLiveData* _live_data;
520 public:
521 G1ScrubRSClosure(G1CardLiveData* live_data) :
522 _g1h(G1CollectedHeap::heap()),
523 _live_data(live_data) { }
524
525 bool doHeapRegion(HeapRegion* r) {
526 if (!r->is_continues_humongous()) {
527 r->rem_set()->scrub(_live_data);
528 }
529 return false;
530 }
531 };
532
533 void G1RemSet::scrub(uint worker_num, HeapRegionClaimer *hrclaimer) {
534 G1ScrubRSClosure scrub_cl(&_card_live_data);
535 _g1->heap_region_par_iterate_from_worker_offset(&scrub_cl, hrclaimer, worker_num);
536 }
537
538 inline void check_card_ptr(jbyte* card_ptr, CardTableModRefBS* ct_bs) {
539 #ifdef ASSERT
540 G1CollectedHeap* g1 = G1CollectedHeap::heap();
541 assert(g1->is_in_exact(ct_bs->addr_for(card_ptr)),
542 "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap",
543 p2i(card_ptr),
544 ct_bs->index_for(ct_bs->addr_for(card_ptr)),
545 p2i(ct_bs->addr_for(card_ptr)),
|
110 // Temporary buffer holding the regions we used to store remembered set scan duplicate
111 // information. These are also called "dirty". Valid entries are from [0.._cur_dirty_region)
112 uint* _dirty_region_buffer;
113
114 typedef jbyte IsDirtyRegionState;
115 static const IsDirtyRegionState Clean = 0;
116 static const IsDirtyRegionState Dirty = 1;
117 // Holds a flag for every region whether it is in the _dirty_region_buffer already
118 // to avoid duplicates. Uses jbyte since there are no atomic instructions for bools.
119 IsDirtyRegionState* _in_dirty_region_buffer;
120 size_t _cur_dirty_region;
121
122 // Creates a snapshot of the current _top values at the start of collection to
123 // filter out card marks that we do not want to scan.
124 class G1ResetScanTopClosure : public HeapRegionClosure {
125 private:
126 HeapWord** _scan_top;
127 public:
128 G1ResetScanTopClosure(HeapWord** scan_top) : _scan_top(scan_top) { }
129
130 virtual bool do_heap_region(HeapRegion* r) {
131 uint hrm_index = r->hrm_index();
132 if (!r->in_collection_set() && r->is_old_or_humongous()) {
133 _scan_top[hrm_index] = r->top();
134 } else {
135 _scan_top[hrm_index] = r->bottom();
136 }
137 return false;
138 }
139 };
140
141 // For each region, contains the maximum top() value to be used during this garbage
142 // collection. Subsumes common checks like filtering out everything but old and
143 // humongous regions outside the collection set.
144 // This is valid because we are not interested in scanning stray remembered set
145 // entries from free or archive regions.
146 HeapWord** _scan_top;
147 public:
148 G1RemSetScanState() :
149 _max_regions(0),
150 _iter_states(NULL),
332 }
333
334 void G1ScanRSForRegionClosure::scan_card(MemRegion mr, uint region_idx_for_card) {
335 HeapRegion* const card_region = _g1h->region_at(region_idx_for_card);
336 _scan_objs_on_card_cl->set_region(card_region);
337 card_region->oops_on_card_seq_iterate_careful<true>(mr, _scan_objs_on_card_cl);
338 _cards_scanned++;
339 }
340
341 void G1ScanRSForRegionClosure::scan_strong_code_roots(HeapRegion* r) {
342 double scan_start = os::elapsedTime();
343 r->strong_code_roots_do(_code_root_cl);
344 _strong_code_root_scan_time_sec += (os::elapsedTime() - scan_start);
345 }
346
347 void G1ScanRSForRegionClosure::claim_card(size_t card_index, const uint region_idx_for_card){
348 _ct_bs->set_card_claimed(card_index);
349 _scan_state->add_dirty_region(region_idx_for_card);
350 }
351
352 bool G1ScanRSForRegionClosure::do_heap_region(HeapRegion* r) {
353 assert(r->in_collection_set(), "should only be called on elements of CS.");
354 uint region_idx = r->hrm_index();
355
356 if (_scan_state->iter_is_complete(region_idx)) {
357 return false;
358 }
359 if (_scan_state->claim_iter(region_idx)) {
360 // If we ever free the collection set concurrently, we should also
361 // clear the card table concurrently therefore we won't need to
362 // add regions of the collection set to the dirty cards region.
363 _scan_state->add_dirty_region(region_idx);
364 }
365
366 // We claim cards in blocks so as to reduce the contention.
367 size_t const block_size = G1RSetScanBlockSize;
368
369 HeapRegionRemSetIterator iter(r->rem_set());
370 size_t card_index;
371
372 size_t claimed_card_block = _scan_state->iter_claimed_next(region_idx, block_size);
505 _scan_state->reset();
506 }
507
508 void G1RemSet::cleanup_after_oops_into_collection_set_do() {
509 G1GCPhaseTimes* phase_times = _g1->g1_policy()->phase_times();
510
511 // Set all cards back to clean.
512 double start = os::elapsedTime();
513 _scan_state->clear_card_table(_g1->workers());
514 phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0);
515 }
516
517 class G1ScrubRSClosure: public HeapRegionClosure {
518 G1CollectedHeap* _g1h;
519 G1CardLiveData* _live_data;
520 public:
521 G1ScrubRSClosure(G1CardLiveData* live_data) :
522 _g1h(G1CollectedHeap::heap()),
523 _live_data(live_data) { }
524
525 bool do_heap_region(HeapRegion* r) {
526 if (!r->is_continues_humongous()) {
527 r->rem_set()->scrub(_live_data);
528 }
529 return false;
530 }
531 };
532
533 void G1RemSet::scrub(uint worker_num, HeapRegionClaimer *hrclaimer) {
534 G1ScrubRSClosure scrub_cl(&_card_live_data);
535 _g1->heap_region_par_iterate_from_worker_offset(&scrub_cl, hrclaimer, worker_num);
536 }
537
538 inline void check_card_ptr(jbyte* card_ptr, CardTableModRefBS* ct_bs) {
539 #ifdef ASSERT
540 G1CollectedHeap* g1 = G1CollectedHeap::heap();
541 assert(g1->is_in_exact(ct_bs->addr_for(card_ptr)),
542 "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap",
543 p2i(card_ptr),
544 ct_bs->index_for(ct_bs->addr_for(card_ptr)),
545 p2i(ct_bs->addr_for(card_ptr)),
|