Skip to content

Commit

Permalink
8272231: G1: Refactor G1CardSet::get_card_set to return G1CardSetHash…
Browse files Browse the repository at this point in the history
…TableValue*

Reviewed-by: tschatzl, kbarrett
  • Loading branch information
Ivan Walulya committed Aug 16, 2021
1 parent 83d0e12 commit 0a03481
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
35 changes: 21 additions & 14 deletions src/hotspot/share/gc/g1/g1CardSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ class G1CardSetHashTable : public CHeapObj<mtGCCardSet> {
class G1CardSetHashTableFound : public StackObj {
G1CardSetHashTableValue* _value;
public:
G1CardSetHashTableFound() : _value(nullptr) { }

void operator()(G1CardSetHashTableValue* value) {
_value = value;
}
Expand Down Expand Up @@ -247,14 +249,12 @@ class G1CardSetHashTable : public CHeapObj<mtGCCardSet> {
return found.value();
}

CardSetPtr get(uint region_idx) {
G1CardSetHashTableValue* get(uint region_idx) {
G1CardSetHashTableLookUp lookup(region_idx);
G1CardSetHashTableFound found;

if (_table.get(Thread::current(), lookup, found)) {
return found.value()->_card_set;
}
return nullptr;
_table.get(Thread::current(), lookup, found);
return found.value();
}

void iterate_safepoint(G1CardSet::G1CardSetPtrIterator* cl2) {
Expand Down Expand Up @@ -611,8 +611,9 @@ void G1CardSet::transfer_cards_in_howl(CardSetPtr parent_card_set,
G1CardSetHowl* howling_array = card_set_ptr<G1CardSetHowl>(parent_card_set);
Atomic::add(&howling_array->_num_entries, diff, memory_order_relaxed);

bool should_grow_table = false;
G1CardSetHashTableValue* table_entry = get_or_add_card_set(card_region, &should_grow_table);
G1CardSetHashTableValue* table_entry = get_card_set(card_region);
assert(table_entry != nullptr, "Table entry not found for transferred cards");

Atomic::add(&table_entry->_num_occupied, diff, memory_order_relaxed);

Atomic::add(&_num_occupied, diff, memory_order_relaxed);
Expand Down Expand Up @@ -656,7 +657,7 @@ G1CardSetHashTableValue* G1CardSet::get_or_add_card_set(uint card_region, bool*
return _table->get_or_add(card_region, should_grow_table);
}

G1CardSet::CardSetPtr G1CardSet::get_card_set(uint card_region) {
G1CardSetHashTableValue* G1CardSet::get_card_set(uint card_region) {
return _table->get(card_region);
}

Expand Down Expand Up @@ -709,10 +710,13 @@ bool G1CardSet::contains_card(uint card_region, uint card_in_region) {

// Protect the card set from reclamation.
GlobalCounter::CriticalSection cs(Thread::current());
CardSetPtr card_set = get_card_set(card_region);
if (card_set == nullptr) {
G1CardSetHashTableValue* table_entry = get_card_set(card_region);
if (table_entry == nullptr) {
return false;
} else if (card_set == FullCardSet) {
}

CardSetPtr card_set = table_entry->_card_set;
if (card_set == FullCardSet) {
// contains_card() is not a performance critical method so we do not hide that
// case in the switch below.
return true;
Expand All @@ -736,11 +740,14 @@ bool G1CardSet::contains_card(uint card_region, uint card_in_region) {
}

void G1CardSet::print_info(outputStream* st, uint card_region, uint card_in_region) {
CardSetPtr card_set = get_card_set(card_region);
if (card_set == nullptr) {
G1CardSetHashTableValue* table_entry = get_card_set(card_region);
if (table_entry == nullptr) {
st->print("NULL card set");
return;
} else if (card_set == FullCardSet) {
}

CardSetPtr card_set = table_entry->_card_set;
if (card_set == FullCardSet) {
st->print("FULL card set)");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/g1/g1CardSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class G1CardSet : public CHeapObj<mtGCCardSet> {
G1AddCardResult add_to_howl(CardSetPtr parent_card_set, uint card_region, uint card_in_region, bool increment_total = true);

G1CardSetHashTableValue* get_or_add_card_set(uint card_region, bool* should_grow_table);
CardSetPtr get_card_set(uint card_region);
G1CardSetHashTableValue* get_card_set(uint card_region);

// Iterate over cards of a card set container during transfer of the cards from
// one container to another. Executes
Expand Down

1 comment on commit 0a03481

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.