502
503 // Set the corresponding coarse bit.
504 size_t max_hrm_index = (size_t) max->hr()->hrm_index();
505 if (!_coarse_map.at(max_hrm_index)) {
506 _coarse_map.at_put(max_hrm_index, true);
507 _n_coarse_entries++;
508 }
509
510 // Unsplice.
511 *max_prev = max->collision_list_next();
512 Atomic::inc(&_n_coarsenings);
513 _n_fine_entries--;
514 return max;
515 }
516
517 void OtherRegionsTable::scrub(G1CardLiveData* live_data) {
518 // First eliminated garbage regions from the coarse map.
519 log_develop_trace(gc, remset, scrub)("Scrubbing region %u:", _hr->hrm_index());
520
521 log_develop_trace(gc, remset, scrub)(" Coarse map: before = " SIZE_FORMAT "...", _n_coarse_entries);
522 live_data->remove_nonlive_regions(&_coarse_map);
523 _n_coarse_entries = _coarse_map.count_one_bits();
524 log_develop_trace(gc, remset, scrub)(" after = " SIZE_FORMAT ".", _n_coarse_entries);
525
526 // Now do the fine-grained maps.
527 for (size_t i = 0; i < _max_fine_entries; i++) {
528 PerRegionTable* cur = _fine_grain_regions[i];
529 PerRegionTable** prev = &_fine_grain_regions[i];
530 while (cur != NULL) {
531 PerRegionTable* nxt = cur->collision_list_next();
532 // If the entire region is dead, eliminate.
533 log_develop_trace(gc, remset, scrub)(" For other region %u:", cur->hr()->hrm_index());
534 if (!live_data->is_region_live(cur->hr()->hrm_index())) {
535 *prev = nxt;
536 cur->set_collision_list_next(NULL);
537 _n_fine_entries--;
538 log_develop_trace(gc, remset, scrub)(" deleted via region map.");
539 unlink_from_all(cur);
540 PerRegionTable::free(cur);
541 } else {
542 // Do fine-grain elimination.
543 log_develop_trace(gc, remset, scrub)(" occ: before = %4d.", cur->occupied());
629 size_t OtherRegionsTable::fl_mem_size() {
630 return PerRegionTable::fl_mem_size();
631 }
632
633 void OtherRegionsTable::clear_fcc() {
634 G1FromCardCache::clear(_hr->hrm_index());
635 }
636
637 void OtherRegionsTable::clear() {
638 // if there are no entries, skip this step
639 if (_first_all_fine_prts != NULL) {
640 guarantee(_first_all_fine_prts != NULL && _last_all_fine_prts != NULL, "just checking");
641 PerRegionTable::bulk_free(_first_all_fine_prts, _last_all_fine_prts);
642 memset(_fine_grain_regions, 0, _max_fine_entries * sizeof(_fine_grain_regions[0]));
643 } else {
644 guarantee(_first_all_fine_prts == NULL && _last_all_fine_prts == NULL, "just checking");
645 }
646
647 _first_all_fine_prts = _last_all_fine_prts = NULL;
648 _sparse_table.clear();
649 _coarse_map.clear();
650 _n_fine_entries = 0;
651 _n_coarse_entries = 0;
652
653 clear_fcc();
654 }
655
656 bool OtherRegionsTable::contains_reference(OopOrNarrowOopStar from) const {
657 // Cast away const in this case.
658 MutexLockerEx x((Mutex*)_m, Mutex::_no_safepoint_check_flag);
659 return contains_reference_locked(from);
660 }
661
662 bool OtherRegionsTable::contains_reference_locked(OopOrNarrowOopStar from) const {
663 HeapRegion* hr = _g1h->heap_region_containing(from);
664 RegionIdx_t hr_ind = (RegionIdx_t) hr->hrm_index();
665 // Is this region in the coarse map?
666 if (_coarse_map.at(hr_ind)) return true;
667
668 PerRegionTable* prt = find_region_table(hr_ind & _mod_max_fine_entries_mask,
669 hr);
|
502
503 // Set the corresponding coarse bit.
504 size_t max_hrm_index = (size_t) max->hr()->hrm_index();
505 if (!_coarse_map.at(max_hrm_index)) {
506 _coarse_map.at_put(max_hrm_index, true);
507 _n_coarse_entries++;
508 }
509
510 // Unsplice.
511 *max_prev = max->collision_list_next();
512 Atomic::inc(&_n_coarsenings);
513 _n_fine_entries--;
514 return max;
515 }
516
517 void OtherRegionsTable::scrub(G1CardLiveData* live_data) {
518 // First eliminated garbage regions from the coarse map.
519 log_develop_trace(gc, remset, scrub)("Scrubbing region %u:", _hr->hrm_index());
520
521 log_develop_trace(gc, remset, scrub)(" Coarse map: before = " SIZE_FORMAT "...", _n_coarse_entries);
522 if (_n_coarse_entries > 0) {
523 live_data->remove_nonlive_regions(&_coarse_map);
524 _n_coarse_entries = _coarse_map.count_one_bits();
525 }
526 log_develop_trace(gc, remset, scrub)(" after = " SIZE_FORMAT ".", _n_coarse_entries);
527
528 // Now do the fine-grained maps.
529 for (size_t i = 0; i < _max_fine_entries; i++) {
530 PerRegionTable* cur = _fine_grain_regions[i];
531 PerRegionTable** prev = &_fine_grain_regions[i];
532 while (cur != NULL) {
533 PerRegionTable* nxt = cur->collision_list_next();
534 // If the entire region is dead, eliminate.
535 log_develop_trace(gc, remset, scrub)(" For other region %u:", cur->hr()->hrm_index());
536 if (!live_data->is_region_live(cur->hr()->hrm_index())) {
537 *prev = nxt;
538 cur->set_collision_list_next(NULL);
539 _n_fine_entries--;
540 log_develop_trace(gc, remset, scrub)(" deleted via region map.");
541 unlink_from_all(cur);
542 PerRegionTable::free(cur);
543 } else {
544 // Do fine-grain elimination.
545 log_develop_trace(gc, remset, scrub)(" occ: before = %4d.", cur->occupied());
631 size_t OtherRegionsTable::fl_mem_size() {
632 return PerRegionTable::fl_mem_size();
633 }
634
635 void OtherRegionsTable::clear_fcc() {
636 G1FromCardCache::clear(_hr->hrm_index());
637 }
638
639 void OtherRegionsTable::clear() {
640 // if there are no entries, skip this step
641 if (_first_all_fine_prts != NULL) {
642 guarantee(_first_all_fine_prts != NULL && _last_all_fine_prts != NULL, "just checking");
643 PerRegionTable::bulk_free(_first_all_fine_prts, _last_all_fine_prts);
644 memset(_fine_grain_regions, 0, _max_fine_entries * sizeof(_fine_grain_regions[0]));
645 } else {
646 guarantee(_first_all_fine_prts == NULL && _last_all_fine_prts == NULL, "just checking");
647 }
648
649 _first_all_fine_prts = _last_all_fine_prts = NULL;
650 _sparse_table.clear();
651 if (_n_coarse_entries > 0) {
652 _coarse_map.clear();
653 }
654 _n_fine_entries = 0;
655 _n_coarse_entries = 0;
656
657 clear_fcc();
658 }
659
660 bool OtherRegionsTable::contains_reference(OopOrNarrowOopStar from) const {
661 // Cast away const in this case.
662 MutexLockerEx x((Mutex*)_m, Mutex::_no_safepoint_check_flag);
663 return contains_reference_locked(from);
664 }
665
666 bool OtherRegionsTable::contains_reference_locked(OopOrNarrowOopStar from) const {
667 HeapRegion* hr = _g1h->heap_region_containing(from);
668 RegionIdx_t hr_ind = (RegionIdx_t) hr->hrm_index();
669 // Is this region in the coarse map?
670 if (_coarse_map.at(hr_ind)) return true;
671
672 PerRegionTable* prt = find_region_table(hr_ind & _mod_max_fine_entries_mask,
673 hr);
|