8303418: Improve parameter and variable names in BitMap

Reviewed-by: tschatzl, aboldtch
This commit is contained in:
Kim Barrett 2023-03-02 09:43:56 +00:00
parent dbb562d3b1
commit 3091744fff
3 changed files with 54 additions and 50 deletions
src/hotspot/share/utilities

@ -293,11 +293,11 @@ void BitMap::clear_large_range(idx_t beg, idx_t end) {
clear_range_within_word(bit_index(end_full_word), end);
}
void BitMap::at_put(idx_t offset, bool value) {
void BitMap::at_put(idx_t bit, bool value) {
if (value) {
set_bit(offset);
set_bit(bit);
} else {
clear_bit(offset);
clear_bit(bit);
}
}
@ -320,11 +320,11 @@ bool BitMap::par_at_put(idx_t bit, bool value) {
return value ? par_set_bit(bit) : par_clear_bit(bit);
}
void BitMap::at_put_range(idx_t beg_offset, idx_t end_offset, bool value) {
void BitMap::at_put_range(idx_t beg, idx_t end, bool value) {
if (value) {
set_range(beg_offset, end_offset);
set_range(beg, end);
} else {
clear_range(beg_offset, end_offset);
clear_range(beg, end);
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -125,7 +125,6 @@ class BitMap {
// Return the array of bitmap words, or a specific word from it.
bm_word_t* map() { return _map; }
const bm_word_t* map() const { return _map; }
bm_word_t map(idx_t word) const { return _map[word]; }
// Return a pointer to the word containing the specified bit.
bm_word_t* word_addr(idx_t bit) {
@ -135,6 +134,11 @@ class BitMap {
return map() + to_words_align_down(bit);
}
// Get a word and flip its bits according to flip.
bm_word_t flipped_word(idx_t word, bm_word_t flip) const {
return _map[word] ^ flip;
}
// Set a word to a specified value or to all ones; clear a word.
void set_word (idx_t word, bm_word_t val) { _map[word] = val; }
void set_word (idx_t word) { set_word(word, ~(bm_word_t)0); }
@ -212,8 +216,8 @@ class BitMap {
// will CAS the value into the bitmap and is quite a bit slower.
// The parallel version also returns a value indicating if the
// calling thread was the one that changed the value of the bit.
void at_put(idx_t index, bool value);
bool par_at_put(idx_t index, bool value);
void at_put(idx_t bit, bool value);
bool par_at_put(idx_t bit, bool value);
// Update a range of bits. Ranges are half-open [beg, end).
void set_range (idx_t beg, idx_t end);
@ -268,11 +272,11 @@ class BitMap {
idx_t get_next_one_offset (idx_t beg, idx_t end) const;
idx_t get_next_zero_offset(idx_t beg, idx_t end) const;
idx_t get_next_one_offset(idx_t offset) const {
return get_next_one_offset(offset, size());
idx_t get_next_one_offset(idx_t beg) const {
return get_next_one_offset(beg, size());
}
idx_t get_next_zero_offset(idx_t offset) const {
return get_next_zero_offset(offset, size());
idx_t get_next_zero_offset(idx_t beg) const {
return get_next_zero_offset(beg, size());
}
// Like "get_next_one_offset", except requires that "end" is

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -53,13 +53,13 @@ inline const BitMap::bm_word_t BitMap::load_word_ordered(const volatile bm_word_
}
}
inline bool BitMap::par_at(idx_t index, atomic_memory_order memory_order) const {
verify_index(index);
inline bool BitMap::par_at(idx_t bit, atomic_memory_order memory_order) const {
verify_index(bit);
assert(memory_order == memory_order_acquire ||
memory_order == memory_order_relaxed,
"unexpected memory ordering");
const volatile bm_word_t* const addr = word_addr(index);
return (load_word_ordered(addr, memory_order) & bit_mask(index)) != 0;
const volatile bm_word_t* const addr = word_addr(bit);
return (load_word_ordered(addr, memory_order) & bit_mask(bit)) != 0;
}
inline bool BitMap::par_set_bit(idx_t bit, atomic_memory_order memory_order) {
@ -166,10 +166,10 @@ inline void BitMap::par_clear_range(idx_t beg, idx_t end, RangeSizeHint hint) {
}
template<BitMap::bm_word_t flip, bool aligned_right>
inline BitMap::idx_t BitMap::get_next_bit_impl(idx_t l_index, idx_t r_index) const {
inline BitMap::idx_t BitMap::get_next_bit_impl(idx_t beg, idx_t end) const {
STATIC_ASSERT(flip == find_ones_flip || flip == find_zeros_flip);
verify_range(l_index, r_index);
assert(!aligned_right || is_aligned(r_index, BitsPerWord), "r_index not aligned");
verify_range(beg, end);
assert(!aligned_right || is_aligned(end, BitsPerWord), "end not aligned");
// The first word often contains an interesting bit, either due to
// density or because of features of the calling algorithm. So it's
@ -180,18 +180,18 @@ inline BitMap::idx_t BitMap::get_next_bit_impl(idx_t l_index, idx_t r_index) con
// The benefit from aligned_right being true is relatively small.
// It saves an operation in the setup for the word search loop.
// It also eliminates the range check on the final result.
// However, callers often have a comparison with r_index, and
// However, callers often have a comparison with end, and
// inlining often allows the two comparisons to be combined; it is
// important when !aligned_right that return paths either return
// r_index or a value dominated by a comparison with r_index.
// end or a value dominated by a comparison with end.
// aligned_right is still helpful when the caller doesn't have a
// range check because features of the calling algorithm guarantee
// an interesting bit will be present.
if (l_index < r_index) {
// Get the word containing l_index, and shift out low bits.
idx_t index = to_words_align_down(l_index);
bm_word_t cword = (map(index) ^ flip) >> bit_in_word(l_index);
if (beg < end) {
// Get the word containing beg, and shift out low bits.
idx_t word_index = to_words_align_down(beg);
bm_word_t cword = flipped_word(word_index, flip) >> bit_in_word(beg);
if ((cword & 1) != 0) {
// The first bit is similarly often interesting. When it matters
// (density or features of the calling algorithm make it likely
@ -200,47 +200,47 @@ inline BitMap::idx_t BitMap::get_next_bit_impl(idx_t l_index, idx_t r_index) con
// relatively expensive, plus there is the additional range check.
// But when the first bit isn't set, the cost of having tested for
// it is relatively small compared to the rest of the search.
return l_index;
return beg;
} else if (cword != 0) {
// Flipped and shifted first word is non-zero.
idx_t result = l_index + count_trailing_zeros(cword);
if (aligned_right || (result < r_index)) return result;
// Result is beyond range bound; return r_index.
idx_t result = beg + count_trailing_zeros(cword);
if (aligned_right || (result < end)) return result;
// Result is beyond range bound; return end.
} else {
// Flipped and shifted first word is zero. Word search through
// aligned up r_index for a non-zero flipped word.
idx_t limit = aligned_right
? to_words_align_down(r_index) // Minuscule savings when aligned.
: to_words_align_up(r_index);
while (++index < limit) {
cword = map(index) ^ flip;
// aligned up end for a non-zero flipped word.
idx_t word_limit = aligned_right
? to_words_align_down(end) // Minuscule savings when aligned.
: to_words_align_up(end);
while (++word_index < word_limit) {
cword = flipped_word(word_index, flip);
if (cword != 0) {
idx_t result = bit_index(index) + count_trailing_zeros(cword);
if (aligned_right || (result < r_index)) return result;
// Result is beyond range bound; return r_index.
assert((index + 1) == limit, "invariant");
idx_t result = bit_index(word_index) + count_trailing_zeros(cword);
if (aligned_right || (result < end)) return result;
// Result is beyond range bound; return end.
assert((word_index + 1) == word_limit, "invariant");
break;
}
}
// No bits in range; return r_index.
// No bits in range; return end.
}
}
return r_index;
return end;
}
inline BitMap::idx_t
BitMap::get_next_one_offset(idx_t l_offset, idx_t r_offset) const {
return get_next_bit_impl<find_ones_flip, false>(l_offset, r_offset);
BitMap::get_next_one_offset(idx_t beg, idx_t end) const {
return get_next_bit_impl<find_ones_flip, false>(beg, end);
}
inline BitMap::idx_t
BitMap::get_next_zero_offset(idx_t l_offset, idx_t r_offset) const {
return get_next_bit_impl<find_zeros_flip, false>(l_offset, r_offset);
BitMap::get_next_zero_offset(idx_t beg, idx_t end) const {
return get_next_bit_impl<find_zeros_flip, false>(beg, end);
}
inline BitMap::idx_t
BitMap::get_next_one_offset_aligned_right(idx_t l_offset, idx_t r_offset) const {
return get_next_bit_impl<find_ones_flip, true>(l_offset, r_offset);
BitMap::get_next_one_offset_aligned_right(idx_t beg, idx_t end) const {
return get_next_bit_impl<find_ones_flip, true>(beg, end);
}
template <typename BitMapClosureType>