8276093: Improve naming in closures to iterate over card sets

Reviewed-by: sjohanss, ayang
This commit is contained in:
Thomas Schatzl 2021-11-18 16:59:41 +00:00
parent 5d249c46ab
commit ce0f00f66e
5 changed files with 62 additions and 61 deletions

View File

@ -231,9 +231,9 @@ class G1CardSetHashTable : public CHeapObj<mtGCCardSet> {
};
class G1CardSetHashTableScan : public StackObj {
G1CardSet::G1CardSetPtrIterator* _scan_f;
G1CardSet::CardSetPtrClosure* _scan_f;
public:
explicit G1CardSetHashTableScan(G1CardSet::G1CardSetPtrIterator* f) : _scan_f(f) { }
explicit G1CardSetHashTableScan(G1CardSet::CardSetPtrClosure* f) : _scan_f(f) { }
bool operator()(G1CardSetHashTableValue* value) {
_scan_f->do_cardsetptr(value->_region_idx, value->_num_occupied, value->_card_set);
@ -284,12 +284,12 @@ public:
return found.value();
}
void iterate_safepoint(G1CardSet::G1CardSetPtrIterator* cl2) {
void iterate_safepoint(G1CardSet::CardSetPtrClosure* cl2) {
G1CardSetHashTableScan cl(cl2);
_table.do_safepoint_scan(cl);
}
void iterate(G1CardSet::G1CardSetPtrIterator* cl2) {
void iterate(G1CardSet::CardSetPtrClosure* cl2) {
G1CardSetHashTableScan cl(cl2);
_table.do_scan(Thread::current(), cl);
}
@ -800,7 +800,7 @@ void G1CardSet::print_info(outputStream* st, uint card_region, uint card_in_regi
}
template <class CardVisitor>
void G1CardSet::iterate_cards_during_transfer(CardSetPtr const card_set, CardVisitor& found) {
void G1CardSet::iterate_cards_during_transfer(CardSetPtr const card_set, CardVisitor& cl) {
uint type = card_set_type(card_set);
assert(type == CardSetInlinePtr || type == CardSetArrayOfCards,
"invalid card set type %d to transfer from",
@ -809,11 +809,11 @@ void G1CardSet::iterate_cards_during_transfer(CardSetPtr const card_set, CardVis
switch (type) {
case CardSetInlinePtr: {
G1CardSetInlinePtr ptr(card_set);
ptr.iterate(found, _config->inline_ptr_bits_per_card());
ptr.iterate(cl, _config->inline_ptr_bits_per_card());
return;
}
case CardSetArrayOfCards : {
card_set_ptr<G1CardSetArray>(card_set)->iterate(found);
card_set_ptr<G1CardSetArray>(card_set)->iterate(cl);
return;
}
default:
@ -821,56 +821,57 @@ void G1CardSet::iterate_cards_during_transfer(CardSetPtr const card_set, CardVis
}
}
void G1CardSet::iterate_containers(G1CardSetPtrIterator* found, bool at_safepoint) {
void G1CardSet::iterate_containers(CardSetPtrClosure* cl, bool at_safepoint) {
if (at_safepoint) {
_table->iterate_safepoint(found);
_table->iterate_safepoint(cl);
} else {
_table->iterate(found);
_table->iterate(cl);
}
}
// Applied to all card (ranges) of the containers.
template <typename Closure>
class G1ContainerCards {
Closure& _iter;
class G1ContainerCardsClosure {
Closure& _cl;
uint _region_idx;
public:
G1ContainerCards(Closure& iter, uint region_idx) : _iter(iter), _region_idx(region_idx) { }
G1ContainerCardsClosure(Closure& cl, uint region_idx) : _cl(cl), _region_idx(region_idx) { }
bool start_iterate(uint tag) { return true; }
void operator()(uint card_idx) {
_iter.do_card(_region_idx, card_idx);
_cl.do_card(_region_idx, card_idx);
}
void operator()(uint card_idx, uint length) {
for (uint i = 0; i < length; i++) {
_iter.do_card(_region_idx, card_idx);
_cl.do_card(_region_idx, card_idx);
}
}
};
template <typename Closure, template <typename> class CardOrRanges>
class G1CardSetIterateCardsIterator : public G1CardSet::G1CardSetPtrIterator {
class G1CardSetContainersClosure : public G1CardSet::CardSetPtrClosure {
G1CardSet* _card_set;
Closure& _iter;
Closure& _cl;
public:
G1CardSetIterateCardsIterator(G1CardSet* card_set,
Closure& iter) :
G1CardSetContainersClosure(G1CardSet* card_set,
Closure& cl) :
_card_set(card_set),
_iter(iter) { }
_cl(cl) { }
void do_cardsetptr(uint region_idx, size_t num_occupied, G1CardSet::CardSetPtr card_set) override {
CardOrRanges<Closure> cl(_iter, region_idx);
CardOrRanges<Closure> cl(_cl, region_idx);
_card_set->iterate_cards_or_ranges_in_container(card_set, cl);
}
};
void G1CardSet::iterate_cards(G1CardSetCardIterator& iter) {
G1CardSetIterateCardsIterator<G1CardSetCardIterator, G1ContainerCards> cl(this, iter);
iterate_containers(&cl);
void G1CardSet::iterate_cards(CardClosure& cl) {
G1CardSetContainersClosure<CardClosure, G1ContainerCardsClosure> cl2(this, cl);
iterate_containers(&cl2);
}
bool G1CardSet::occupancy_less_or_equal_to(size_t limit) const {
@ -886,11 +887,11 @@ size_t G1CardSet::occupied() const {
}
size_t G1CardSet::num_containers() {
class GetNumberOfContainers : public G1CardSetPtrIterator {
class GetNumberOfContainers : public CardSetPtrClosure {
public:
size_t _count;
GetNumberOfContainers() : G1CardSetPtrIterator(), _count(0) { }
GetNumberOfContainers() : CardSetPtrClosure(), _count(0) { }
void do_cardsetptr(uint region_idx, size_t num_occupied, CardSetPtr card_set) override {
_count++;

View File

@ -291,7 +291,7 @@ private:
//
// on the given class.
template <class CardVisitor>
void iterate_cards_during_transfer(CardSetPtr const card_set, CardVisitor& found);
void iterate_cards_during_transfer(CardSetPtr const card_set, CardVisitor& vl);
uint card_set_type_to_mem_object_type(uintptr_t type) const;
uint8_t* allocate_mem_object(uintptr_t type);
@ -353,21 +353,21 @@ public:
// start_iterate().
//
template <class CardOrRangeVisitor>
void iterate_cards_or_ranges_in_container(CardSetPtr const card_set, CardOrRangeVisitor& found);
void iterate_cards_or_ranges_in_container(CardSetPtr const card_set, CardOrRangeVisitor& cl);
class G1CardSetPtrIterator {
class CardSetPtrClosure {
public:
virtual void do_cardsetptr(uint region_idx, size_t num_occupied, CardSetPtr card_set) = 0;
};
void iterate_containers(G1CardSetPtrIterator* iter, bool safepoint = false);
void iterate_containers(CardSetPtrClosure* cl, bool safepoint = false);
class G1CardSetCardIterator {
class CardClosure {
public:
virtual void do_card(uint region_idx, uint card_idx) = 0;
};
void iterate_cards(G1CardSetCardIterator& iter);
void iterate_cards(CardClosure& cl);
};
class G1CardSetHashTableValue {

View File

@ -42,18 +42,18 @@ inline G1CardSet::CardSetPtr G1CardSet::make_card_set_ptr(void* value, uintptr_t
}
template <class CardOrRangeVisitor>
inline void G1CardSet::iterate_cards_or_ranges_in_container(CardSetPtr const card_set, CardOrRangeVisitor& found) {
inline void G1CardSet::iterate_cards_or_ranges_in_container(CardSetPtr const card_set, CardOrRangeVisitor& cl) {
switch (card_set_type(card_set)) {
case CardSetInlinePtr: {
if (found.start_iterate(G1GCPhaseTimes::MergeRSMergedInline)) {
if (cl.start_iterate(G1GCPhaseTimes::MergeRSMergedInline)) {
G1CardSetInlinePtr ptr(card_set);
ptr.iterate(found, _config->inline_ptr_bits_per_card());
ptr.iterate(cl, _config->inline_ptr_bits_per_card());
}
return;
}
case CardSetArrayOfCards : {
if (found.start_iterate(G1GCPhaseTimes::MergeRSMergedArrayOfCards)) {
card_set_ptr<G1CardSetArray>(card_set)->iterate(found);
if (cl.start_iterate(G1GCPhaseTimes::MergeRSMergedArrayOfCards)) {
card_set_ptr<G1CardSetArray>(card_set)->iterate(cl);
}
return;
}
@ -65,13 +65,13 @@ inline void G1CardSet::iterate_cards_or_ranges_in_container(CardSetPtr const car
case CardSetHowl: {
assert(card_set_type(FullCardSet) == CardSetHowl, "Must be");
if (card_set == FullCardSet) {
if (found.start_iterate(G1GCPhaseTimes::MergeRSMergedFull)) {
found(0, _config->max_cards_in_region());
if (cl.start_iterate(G1GCPhaseTimes::MergeRSMergedFull)) {
cl(0, _config->max_cards_in_region());
}
return;
}
if (found.start_iterate(G1GCPhaseTimes::MergeRSMergedHowl)) {
card_set_ptr<G1CardSetHowl>(card_set)->iterate(found, _config);
if (cl.start_iterate(G1GCPhaseTimes::MergeRSMergedHowl)) {
card_set_ptr<G1CardSetHowl>(card_set)->iterate(cl, _config);
}
return;
}

View File

@ -57,49 +57,49 @@ void HeapRegionRemSet::set_state_complete() {
template <typename Closure>
class G1ContainerCardsOrRanges {
Closure& _iter;
Closure& _cl;
uint _region_idx;
uint _offset;
public:
G1ContainerCardsOrRanges(Closure& iter, uint region_idx, uint offset) : _iter(iter), _region_idx(region_idx), _offset(offset) { }
G1ContainerCardsOrRanges(Closure& cl, uint region_idx, uint offset) : _cl(cl), _region_idx(region_idx), _offset(offset) { }
bool start_iterate(uint tag) {
return _iter.start_iterate(tag, _region_idx);
return _cl.start_iterate(tag, _region_idx);
}
void operator()(uint card_idx) {
_iter.do_card(card_idx + _offset);
_cl.do_card(card_idx + _offset);
}
void operator()(uint card_idx, uint length) {
_iter.do_card_range(card_idx + _offset, length);
_cl.do_card_range(card_idx + _offset, length);
}
};
template <typename Closure, template <typename> class CardOrRanges>
class G1HeapRegionRemSetMergeCardIterator : public G1CardSet::G1CardSetPtrIterator {
class G1HeapRegionRemSetMergeCardClosure : public G1CardSet::CardSetPtrClosure {
G1CardSet* _card_set;
Closure& _iter;
Closure& _cl;
uint _log_card_regions_per_region;
uint _card_regions_per_region_mask;
uint _log_card_region_size;
public:
G1HeapRegionRemSetMergeCardIterator(G1CardSet* card_set,
Closure& iter,
G1HeapRegionRemSetMergeCardClosure(G1CardSet* card_set,
Closure& cl,
uint log_card_regions_per_region,
uint log_card_region_size) :
_card_set(card_set),
_iter(iter),
_cl(cl),
_log_card_regions_per_region(log_card_regions_per_region),
_card_regions_per_region_mask((1 << log_card_regions_per_region) - 1),
_log_card_region_size(log_card_region_size) {
}
void do_cardsetptr(uint card_region_idx, size_t num_occupied, G1CardSet::CardSetPtr card_set) override {
CardOrRanges<Closure> cl(_iter,
CardOrRanges<Closure> cl(_cl,
card_region_idx >> _log_card_regions_per_region,
(card_region_idx & _card_regions_per_region_mask) << _log_card_region_size);
_card_set->iterate_cards_or_ranges_in_container(card_set, cl);
@ -108,10 +108,10 @@ public:
template <class CardOrRangeVisitor>
inline void HeapRegionRemSet::iterate_for_merge(CardOrRangeVisitor& cl) {
G1HeapRegionRemSetMergeCardIterator<CardOrRangeVisitor, G1ContainerCardsOrRanges> cl2(&_card_set,
cl,
_card_set.config()->log2_card_region_per_heap_region(),
_card_set.config()->log2_cards_per_card_region());
G1HeapRegionRemSetMergeCardClosure<CardOrRangeVisitor, G1ContainerCardsOrRanges> cl2(&_card_set,
cl,
_card_set.config()->log2_card_region_per_heap_region(),
_card_set.config()->log2_cards_per_card_region());
_card_set.iterate_containers(&cl2, true /* at_safepoint */);
}

View File

@ -34,7 +34,7 @@
class G1CardSetTest : public ::testing::Test {
class G1CountCardsClosure : public G1CardSet::G1CardSetCardIterator {
class G1CountCardsClosure : public G1CardSet::CardClosure {
public:
size_t _num_cards;
@ -82,7 +82,7 @@ public:
static void translate_cards(uint cards_per_region, uint region_idx, uint* cards, uint num_cards);
static void iterate_cards(G1CardSet* card_set, G1CardSet::G1CardSetCardIterator* cl);
static void iterate_cards(G1CardSet* card_set, G1CardSet::CardClosure* cl);
};
WorkerThreads* G1CardSetTest::_workers = NULL;
@ -101,7 +101,7 @@ void G1CardSetTest::add_cards(G1CardSet* card_set, uint cards_per_region, uint*
}
}
class G1CheckCardClosure : public G1CardSet::G1CardSetCardIterator {
class G1CheckCardClosure : public G1CardSet::CardClosure {
G1CardSet* _card_set;
uint _cards_per_region;
@ -163,7 +163,7 @@ void G1CardSetTest::translate_cards(uint cards_per_region, uint region_idx, uint
}
}
class G1CountCardsOccupied : public G1CardSet::G1CardSetPtrIterator {
class G1CountCardsOccupied : public G1CardSet::CardSetPtrClosure {
size_t _num_occupied;
public:
@ -178,7 +178,7 @@ public:
void G1CardSetTest::check_iteration(G1CardSet* card_set, const size_t expected, const bool single_threaded) {
class CheckIterator : public G1CardSet::G1CardSetCardIterator {
class CheckIterator : public G1CardSet::CardClosure {
public:
G1CardSet* _card_set;
size_t _num_found;