Skip to content
Permalink
Browse files
8277789: G1: G1CardSetConfiguration prefixes num_ and max_ used inter…
…changeably

Reviewed-by: mli, tschatzl
  • Loading branch information
Ivan Walulya committed Nov 29, 2021
1 parent 614c6e6 commit ad51d0692534744d04a32959e7e50ee5e87adff5
Showing 5 changed files with 51 additions and 53 deletions.
@@ -135,8 +135,8 @@ void G1Arguments::initialize_card_set_configuration() {
uint region_size_log_mb = (uint)MAX2(HeapRegion::LogOfHRGrainBytes - LOG_M, 0);

if (FLAG_IS_DEFAULT(G1RemSetArrayOfCardsEntries)) {
uint num_cards_in_inline_ptr = G1CardSetConfiguration::num_cards_in_inline_ptr(HeapRegion::LogOfHRGrainBytes - CardTable::card_shift);
FLAG_SET_ERGO(G1RemSetArrayOfCardsEntries, MAX2(num_cards_in_inline_ptr * 2,
uint max_cards_in_inline_ptr = G1CardSetConfiguration::max_cards_in_inline_ptr(HeapRegion::LogOfHRGrainBytes - CardTable::card_shift);
FLAG_SET_ERGO(G1RemSetArrayOfCardsEntries, MAX2(max_cards_in_inline_ptr * 2,
G1RemSetArrayOfCardsEntriesBase * (1u << (region_size_log_mb + 1))));
}

@@ -57,7 +57,7 @@ static uint default_log2_card_region_per_region() {

G1CardSetConfiguration::G1CardSetConfiguration() :
G1CardSetConfiguration(HeapRegion::LogCardsPerRegion, /* inline_ptr_bits_per_card */
G1RemSetArrayOfCardsEntries, /* num_cards_in_array */
G1RemSetArrayOfCardsEntries, /* max_cards_in_array */
(double)G1RemSetCoarsenHowlBitmapToHowlFullPercent / 100, /* cards_in_bitmap_threshold_percent */
G1RemSetHowlNumBuckets, /* num_buckets_in_howl */
(double)G1RemSetCoarsenHowlToFullPercent / 100, /* cards_in_howl_threshold_percent */
@@ -68,39 +68,39 @@ G1CardSetConfiguration::G1CardSetConfiguration() :
"inconsistent heap region virtualization setup");
}

G1CardSetConfiguration::G1CardSetConfiguration(uint num_cards_in_array,
G1CardSetConfiguration::G1CardSetConfiguration(uint max_cards_in_array,
double cards_in_bitmap_threshold_percent,
uint max_buckets_in_howl,
double cards_in_howl_threshold_percent,
uint max_cards_in_card_set,
uint log2_card_region_per_region) :
G1CardSetConfiguration(log2i_exact(max_cards_in_card_set), /* inline_ptr_bits_per_card */
num_cards_in_array, /* num_cards_in_array */
max_cards_in_array, /* max_cards_in_array */
cards_in_bitmap_threshold_percent, /* cards_in_bitmap_threshold_percent */
G1CardSetHowl::num_buckets(max_cards_in_card_set, /* num_buckets_in_howl */
num_cards_in_array,
max_cards_in_array,
max_buckets_in_howl),
cards_in_howl_threshold_percent, /* cards_in_howl_threshold_percent */
max_cards_in_card_set, /* max_cards_in_cardset */
log2_card_region_per_region)
{ }

G1CardSetConfiguration::G1CardSetConfiguration(uint inline_ptr_bits_per_card,
uint num_cards_in_array,
uint max_cards_in_array,
double cards_in_bitmap_threshold_percent,
uint num_buckets_in_howl,
double cards_in_howl_threshold_percent,
uint max_cards_in_card_set,
uint log2_card_regions_per_heap_region) :
_inline_ptr_bits_per_card(inline_ptr_bits_per_card),
_num_cards_in_array(num_cards_in_array),
_max_cards_in_array(max_cards_in_array),
_num_buckets_in_howl(num_buckets_in_howl),
_max_cards_in_card_set(max_cards_in_card_set),
_cards_in_howl_threshold(max_cards_in_card_set * cards_in_howl_threshold_percent),
_num_cards_in_howl_bitmap(G1CardSetHowl::bitmap_size(_max_cards_in_card_set, _num_buckets_in_howl)),
_cards_in_howl_bitmap_threshold(_num_cards_in_howl_bitmap * cards_in_bitmap_threshold_percent),
_log2_num_cards_in_howl_bitmap(log2i_exact(_num_cards_in_howl_bitmap)),
_bitmap_hash_mask(~(~(0) << _log2_num_cards_in_howl_bitmap)),
_max_cards_in_howl_bitmap(G1CardSetHowl::bitmap_size(_max_cards_in_card_set, _num_buckets_in_howl)),
_cards_in_howl_bitmap_threshold(_max_cards_in_howl_bitmap * cards_in_bitmap_threshold_percent),
_log2_max_cards_in_howl_bitmap(log2i_exact(_max_cards_in_howl_bitmap)),
_bitmap_hash_mask(~(~(0) << _log2_max_cards_in_howl_bitmap)),
_log2_card_regions_per_heap_region(log2_card_regions_per_heap_region),
_log2_cards_per_card_region(log2i_exact(_max_cards_in_card_set) - _log2_card_regions_per_heap_region) {

@@ -118,8 +118,8 @@ G1CardSetConfiguration::~G1CardSetConfiguration() {
void G1CardSetConfiguration::init_card_set_alloc_options() {
_card_set_alloc_options = NEW_C_HEAP_ARRAY(G1CardSetAllocOptions, num_mem_object_types(), mtGC);
new (&_card_set_alloc_options[0]) G1CardSetAllocOptions((uint)CardSetHash::get_node_size());
new (&_card_set_alloc_options[1]) G1CardSetAllocOptions((uint)G1CardSetArray::size_in_bytes(_num_cards_in_array), 2, 256);
new (&_card_set_alloc_options[2]) G1CardSetAllocOptions((uint)G1CardSetBitMap::size_in_bytes(_num_cards_in_howl_bitmap), 2, 256);
new (&_card_set_alloc_options[1]) G1CardSetAllocOptions((uint)G1CardSetArray::size_in_bytes(_max_cards_in_array), 2, 256);
new (&_card_set_alloc_options[2]) G1CardSetAllocOptions((uint)G1CardSetBitMap::size_in_bytes(_max_cards_in_howl_bitmap), 2, 256);
new (&_card_set_alloc_options[3]) G1CardSetAllocOptions((uint)G1CardSetHowl::size_in_bytes(_num_buckets_in_howl), 2, 256);
}

@@ -130,19 +130,19 @@ void G1CardSetConfiguration::log_configuration() {
"Howl #buckets %u coarsen threshold %u "
"Howl Bitmap #elems %u size %zu coarsen threshold %u "
"Card regions per heap region %u cards per card region %u",
num_cards_in_inline_ptr(), sizeof(void*),
num_cards_in_array(), G1CardSetArray::size_in_bytes(num_cards_in_array()),
max_cards_in_inline_ptr(), sizeof(void*),
max_cards_in_array(), G1CardSetArray::size_in_bytes(max_cards_in_array()),
num_buckets_in_howl(), cards_in_howl_threshold(),
num_cards_in_howl_bitmap(), G1CardSetBitMap::size_in_bytes(num_cards_in_howl_bitmap()), cards_in_howl_bitmap_threshold(),
max_cards_in_howl_bitmap(), G1CardSetBitMap::size_in_bytes(max_cards_in_howl_bitmap()), cards_in_howl_bitmap_threshold(),
(uint)1 << log2_card_regions_per_heap_region(),
(uint)1 << log2_cards_per_card_region());
}

uint G1CardSetConfiguration::num_cards_in_inline_ptr() const {
return num_cards_in_inline_ptr(_inline_ptr_bits_per_card);
uint G1CardSetConfiguration::max_cards_in_inline_ptr() const {
return max_cards_in_inline_ptr(_inline_ptr_bits_per_card);
}

uint G1CardSetConfiguration::num_cards_in_inline_ptr(uint bits_per_card) {
uint G1CardSetConfiguration::max_cards_in_inline_ptr(uint bits_per_card) {
return G1CardSetInlinePtr::max_cards_in_inline_ptr(bits_per_card);
}

@@ -508,19 +508,19 @@ G1AddCardResult G1CardSet::add_to_howl(CardSetPtr parent_card_set,
G1AddCardResult G1CardSet::add_to_bitmap(CardSetPtr card_set, uint card_in_region) {
G1CardSetBitMap* bitmap = card_set_ptr<G1CardSetBitMap>(card_set);
uint card_offset = _config->howl_bitmap_offset(card_in_region);
return bitmap->add(card_offset, _config->cards_in_howl_bitmap_threshold(), _config->num_cards_in_howl_bitmap());
return bitmap->add(card_offset, _config->cards_in_howl_bitmap_threshold(), _config->max_cards_in_howl_bitmap());
}

G1AddCardResult G1CardSet::add_to_inline_ptr(CardSetPtr volatile* card_set_addr, CardSetPtr card_set, uint card_in_region) {
G1CardSetInlinePtr value(card_set_addr, card_set);
return value.add(card_in_region, _config->inline_ptr_bits_per_card(), _config->num_cards_in_inline_ptr());
return value.add(card_in_region, _config->inline_ptr_bits_per_card(), _config->max_cards_in_inline_ptr());
}

G1CardSet::CardSetPtr G1CardSet::create_coarsened_array_of_cards(uint card_in_region, bool within_howl) {
uint8_t* data = nullptr;
CardSetPtr new_card_set;
if (within_howl) {
uint const size_in_bits = _config->num_cards_in_howl_bitmap();
uint const size_in_bits = _config->max_cards_in_howl_bitmap();
uint card_offset = _config->howl_bitmap_offset(card_in_region);
data = allocate_mem_object(CardSetBitMap);
new (data) G1CardSetBitMap(card_offset, size_in_bits);
@@ -549,7 +549,7 @@ bool G1CardSet::coarsen_card_set(volatile CardSetPtr* card_set_addr,
break;
}
case CardSetInlinePtr: {
uint const size = _config->num_cards_in_array();
uint const size = _config->max_cards_in_array();
uint8_t* data = allocate_mem_object(CardSetArrayOfCards);
new (data) G1CardSetArray(card_in_region, size);
new_card_set = make_card_set_ptr(data, CardSetArrayOfCards);
@@ -626,7 +626,7 @@ void G1CardSet::transfer_cards_in_howl(CardSetPtr parent_card_set,
G1TransferCard iter(this, card_region);
iterate_cards_during_transfer(source_card_set, iter);
} else {
uint diff = _config->num_cards_in_howl_bitmap() - card_set_ptr<G1CardSetBitMap>(source_card_set)->num_bits_set();
uint diff = _config->max_cards_in_howl_bitmap() - card_set_ptr<G1CardSetBitMap>(source_card_set)->num_bits_set();

// Need to correct for that the Full remembered set occupies more cards than the
// bitmap before.
@@ -755,7 +755,7 @@ bool G1CardSet::contains_card(uint card_region, uint card_in_region) {
return ptr.contains(card_in_region, _config->inline_ptr_bits_per_card());
}
case CardSetArrayOfCards : return card_set_ptr<G1CardSetArray>(card_set)->contains(card_in_region);
case CardSetBitMap: return card_set_ptr<G1CardSetBitMap>(card_set)->contains(card_in_region, _config->num_cards_in_howl_bitmap());
case CardSetBitMap: return card_set_ptr<G1CardSetBitMap>(card_set)->contains(card_in_region, _config->max_cards_in_howl_bitmap());
case CardSetHowl: {
G1CardSetHowl* howling_array = card_set_ptr<G1CardSetHowl>(card_set);

@@ -50,21 +50,21 @@ class G1CardSetConfiguration {
// regions covered by this card set.
uint _inline_ptr_bits_per_card;

uint _num_cards_in_array;
uint _max_cards_in_array;
uint _num_buckets_in_howl;
uint _max_cards_in_card_set;
uint _cards_in_howl_threshold;
uint _num_cards_in_howl_bitmap;
uint _max_cards_in_howl_bitmap;
uint _cards_in_howl_bitmap_threshold;
uint _log2_num_cards_in_howl_bitmap;
uint _log2_max_cards_in_howl_bitmap;
size_t _bitmap_hash_mask;
uint _log2_card_regions_per_heap_region;
uint _log2_cards_per_card_region;

G1CardSetAllocOptions* _card_set_alloc_options;

G1CardSetConfiguration(uint inline_ptr_bits_per_card,
uint num_cards_in_array,
uint max_cards_in_array,
double cards_in_bitmap_threshold_percent,
uint num_buckets_in_howl,
double cards_in_howl_threshold_percent,
@@ -79,7 +79,7 @@ class G1CardSetConfiguration {
G1CardSetConfiguration();
// Initialize card set configuration from parameters.
// Testing only.
G1CardSetConfiguration(uint num_cards_in_array,
G1CardSetConfiguration(uint max_cards_in_array,
double cards_in_bitmap_threshold_percent,
uint max_buckets_in_howl,
double cards_in_howl_threshold_percent,
@@ -90,29 +90,27 @@ class G1CardSetConfiguration {

// Inline pointer configuration
uint inline_ptr_bits_per_card() const { return _inline_ptr_bits_per_card; }
uint num_cards_in_inline_ptr() const;
static uint num_cards_in_inline_ptr(uint bits_per_card);
uint max_cards_in_inline_ptr() const;
static uint max_cards_in_inline_ptr(uint bits_per_card);

// Array of Cards configuration
bool use_cards_in_array() const { return _num_cards_in_array != 0; } // Unused for now
// Number of cards in "Array of Cards" set; 0 to disable.
// Maximum number of cards in "Array of Cards" set; 0 to disable.
// Always coarsen to next level if full, so no specific threshold.
uint num_cards_in_array() const { return _num_cards_in_array; }
uint max_cards_in_array() const { return _max_cards_in_array; }

// Bitmap within Howl card set container configuration
bool use_cards_in_howl_bitmap() const { return _num_cards_in_howl_bitmap != 0; } // Unused for now
uint num_cards_in_howl_bitmap() const { return _num_cards_in_howl_bitmap; }
uint max_cards_in_howl_bitmap() const { return _max_cards_in_howl_bitmap; }
// (Approximate) Number of cards in bitmap to coarsen Howl Bitmap to Howl Full.
uint cards_in_howl_bitmap_threshold() const { return _cards_in_howl_bitmap_threshold; }
uint log2_num_cards_in_howl_bitmap() const {return _log2_num_cards_in_howl_bitmap;}
uint log2_max_cards_in_howl_bitmap() const {return _log2_max_cards_in_howl_bitmap;}

// Howl card set container configuration
uint num_buckets_in_howl() const { return _num_buckets_in_howl; }
// Threshold at which to turn howling arrays into Full.
uint cards_in_howl_threshold() const { return _cards_in_howl_threshold; }
uint howl_bitmap_offset(uint card_idx) const { return card_idx & _bitmap_hash_mask; }
// Given a card index, return the bucket in the array of card sets.
uint howl_bucket_index(uint card_idx) { return card_idx >> _log2_num_cards_in_howl_bitmap; }
uint howl_bucket_index(uint card_idx) { return card_idx >> _log2_max_cards_in_howl_bitmap; }

// Full card configuration
// Maximum number of cards in a non-full card set for a single region. Card sets
@@ -252,14 +252,14 @@ inline void G1CardSetBitMap::iterate(CardVisitor& found, size_t size_in_bits, ui

inline G1CardSetHowl::G1CardSetHowl(EntryCountType card_in_region, G1CardSetConfiguration* config) :
G1CardSetContainer(),
_num_entries((config->num_cards_in_array() + 1)) /* Card Transfer will not increment _num_entries */ {
_num_entries((config->max_cards_in_array() + 1)) /* Card Transfer will not increment _num_entries */ {
EntryCountType num_buckets = config->num_buckets_in_howl();
EntryCountType bucket = config->howl_bucket_index(card_in_region);
for (uint i = 0; i < num_buckets; ++i) {
_buckets[i] = G1CardSetInlinePtr();
if (i == bucket) {
G1CardSetInlinePtr value(&_buckets[i], _buckets[i]);
value.add(card_in_region, config->inline_ptr_bits_per_card(), config->num_cards_in_inline_ptr());
value.add(card_in_region, config->inline_ptr_bits_per_card(), config->max_cards_in_inline_ptr());
}
}
}
@@ -275,7 +275,7 @@ inline bool G1CardSetHowl::contains(uint card_idx, G1CardSetConfiguration* confi
}
case G1CardSet::CardSetBitMap: {
uint card_offset = config->howl_bitmap_offset(card_idx);
return G1CardSet::card_set_ptr<G1CardSetBitMap>(card_set)->contains(card_offset, config->num_cards_in_howl_bitmap());
return G1CardSet::card_set_ptr<G1CardSetBitMap>(card_set)->contains(card_offset, config->max_cards_in_howl_bitmap());
}
case G1CardSet::CardSetInlinePtr: {
G1CardSetInlinePtr ptr(card_set);
@@ -321,28 +321,28 @@ inline void G1CardSetHowl::iterate_cardset(CardSetPtr const card_set, uint index
}
case G1CardSet::CardSetBitMap: {
if (found.start_iterate(G1GCPhaseTimes::MergeRSHowlBitmap)) {
uint offset = index << config->log2_num_cards_in_howl_bitmap();
G1CardSet::card_set_ptr<G1CardSetBitMap>(card_set)->iterate(found, config->num_cards_in_howl_bitmap(), offset);
uint offset = index << config->log2_max_cards_in_howl_bitmap();
G1CardSet::card_set_ptr<G1CardSetBitMap>(card_set)->iterate(found, config->max_cards_in_howl_bitmap(), offset);
}
return;
}
case G1CardSet::CardSetHowl: { // actually FullCardSet
assert(card_set == G1CardSet::FullCardSet, "Must be");
if (found.start_iterate(G1GCPhaseTimes::MergeRSHowlFull)) {
uint offset = index << config->log2_num_cards_in_howl_bitmap();
found(offset, config->num_cards_in_howl_bitmap());
uint offset = index << config->log2_max_cards_in_howl_bitmap();
found(offset, config->max_cards_in_howl_bitmap());
}
return;
}
}
}

inline G1CardSetHowl::EntryCountType G1CardSetHowl::num_buckets(size_t size_in_bits, size_t num_cards_in_array, size_t max_num_buckets) {
inline G1CardSetHowl::EntryCountType G1CardSetHowl::num_buckets(size_t size_in_bits, size_t max_cards_in_array, size_t max_num_buckets) {
size_t size_bitmap_bytes = BitMap::calc_size_in_words(size_in_bits) * BytesPerWord;
// Ensure that in the worst case arrays consume half the memory size
// of storing the entire bitmap
size_t max_size_arrays_bytes = size_bitmap_bytes / 2;
size_t size_array_bytes = num_cards_in_array * sizeof(G1CardSetArray::EntryDataType);
size_t size_array_bytes = max_cards_in_array * sizeof(G1CardSetArray::EntryDataType);
size_t num_arrays = max_size_arrays_bytes / size_array_bytes;
// We use shifts and masks for indexing the array. So round down to the next
// power of two to not use more than expected memory.
@@ -345,17 +345,17 @@ void G1CardSetTest::cardset_basic_test() {
ASSERT_TRUE(count == card_set.occupied());
}

G1AddCardResult res = card_set.add_card(99, config.num_cards_in_howl_bitmap() - 1);
G1AddCardResult res = card_set.add_card(99, config.max_cards_in_howl_bitmap() - 1);
// Adding above card should have coarsened Bitmap -> Full.
ASSERT_TRUE(res == Added);
ASSERT_TRUE(config.num_cards_in_howl_bitmap() == card_set.occupied());
ASSERT_TRUE(config.max_cards_in_howl_bitmap() == card_set.occupied());

res = card_set.add_card(99, config.num_cards_in_howl_bitmap() - 2);
res = card_set.add_card(99, config.max_cards_in_howl_bitmap() - 2);
ASSERT_TRUE(res == Found);

uint threshold = config.cards_in_howl_threshold();
uint adjusted_threshold = config.cards_in_howl_bitmap_threshold() * config.num_buckets_in_howl();
i = config.num_cards_in_howl_bitmap();
i = config.max_cards_in_howl_bitmap();
count = i;
for (; i < threshold; i++) {
G1AddCardResult res = card_set.add_card(99, i);

1 comment on commit ad51d06

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on ad51d06 Nov 29, 2021

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.