8303900: Rename BitMap search functions

Reviewed-by: stefank, aboldtch
This commit is contained in:
Kim Barrett 2023-03-10 21:16:56 +00:00
parent d7f4221bfe
commit 2116928528
12 changed files with 75 additions and 75 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 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
@ -230,7 +230,7 @@ public:
uint next(uint const idx, size_t const size_in_bits) {
BitMapView bm(_bits, size_in_bits);
return static_cast<uint>(bm.get_next_one_offset(idx));
return static_cast<uint>(bm.find_first_set_bit(idx));
}
static size_t header_size_in_bytes();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 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
@ -99,13 +99,13 @@ void G1CommittedRegionMap::uncommit(uint start, uint end) {
HeapRegionRange G1CommittedRegionMap::next_active_range(uint offset) const {
// Find first active index from offset.
uint start = (uint) _active.get_next_one_offset(offset);
uint start = (uint) _active.find_first_set_bit(offset);
if (start == max_length()) {
// Early out when no active regions are found.
return HeapRegionRange(max_length(), max_length());
}
uint end = (uint) _active.get_next_zero_offset(start);
uint end = (uint) _active.find_first_clear_bit(start);
verify_active_range(start, end);
return HeapRegionRange(start, end);
@ -116,13 +116,13 @@ HeapRegionRange G1CommittedRegionMap::next_committable_range(uint offset) const
verify_no_inactive_regons();
// Find first free region from offset.
uint start = (uint) _active.get_next_zero_offset(offset);
uint start = (uint) _active.find_first_clear_bit(offset);
if (start == max_length()) {
// Early out when no free regions are found.
return HeapRegionRange(max_length(), max_length());
}
uint end = (uint) _active.get_next_one_offset(start);
uint end = (uint) _active.find_first_set_bit(start);
verify_free_range(start, end);
return HeapRegionRange(start, end);
@ -130,14 +130,14 @@ HeapRegionRange G1CommittedRegionMap::next_committable_range(uint offset) const
HeapRegionRange G1CommittedRegionMap::next_inactive_range(uint offset) const {
// Find first inactive region from offset.
uint start = (uint) _inactive.get_next_one_offset(offset);
uint start = (uint) _inactive.find_first_set_bit(offset);
if (start == max_length()) {
// Early when no inactive regions are found.
return HeapRegionRange(max_length(), max_length());
}
uint end = (uint) _inactive.get_next_zero_offset(start);
uint end = (uint) _inactive.find_first_clear_bit(start);
verify_inactive_range(start, end);
return HeapRegionRange(start, end);
@ -232,7 +232,7 @@ void G1CommittedRegionMap::verify_free_range(uint start, uint end) const {
}
void G1CommittedRegionMap::verify_no_inactive_regons() const {
BitMap::idx_t first_inactive = _inactive.get_next_one_offset(0);
BitMap::idx_t first_inactive = _inactive.find_first_set_bit(0);
assert(first_inactive == _inactive.size(), "Should be no inactive regions, but was at index: " SIZE_FORMAT, first_inactive);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 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
@ -39,7 +39,7 @@ inline bool G1CMBitMap::iterate(G1CMBitMapClosure* cl, MemRegion mr) {
p2i(mr.start()), p2i(mr.end()));
BitMap::idx_t const end_offset = addr_to_offset(mr.end());
BitMap::idx_t offset = _bm.get_next_one_offset(addr_to_offset(mr.start()), end_offset);
BitMap::idx_t offset = _bm.find_first_set_bit(addr_to_offset(mr.start()), end_offset);
while (offset < end_offset) {
HeapWord* const addr = offset_to_addr(offset);
@ -47,7 +47,7 @@ inline bool G1CMBitMap::iterate(G1CMBitMapClosure* cl, MemRegion mr) {
return false;
}
size_t const obj_size = cast_to_oop(addr)->size();
offset = _bm.get_next_one_offset(offset + (obj_size >> _shifter), end_offset);
offset = _bm.find_first_set_bit(offset + (obj_size >> _shifter), end_offset);
}
return true;
}

View File

@ -106,12 +106,12 @@ size_t G1PageBasedVirtualSpace::addr_to_page_index(char* addr) const {
bool G1PageBasedVirtualSpace::is_area_committed(size_t start_page, size_t size_in_pages) const {
size_t end_page = start_page + size_in_pages;
return _committed.get_next_zero_offset(start_page, end_page) >= end_page;
return _committed.find_first_clear_bit(start_page, end_page) >= end_page;
}
bool G1PageBasedVirtualSpace::is_area_uncommitted(size_t start_page, size_t size_in_pages) const {
size_t end_page = start_page + size_in_pages;
return _committed.get_next_one_offset(start_page, end_page) >= end_page;
return _committed.find_first_set_bit(start_page, end_page) >= end_page;
}
char* G1PageBasedVirtualSpace::page_start(size_t index) const {
@ -188,7 +188,7 @@ bool G1PageBasedVirtualSpace::commit(size_t start_page, size_t size_in_pages) {
if (_special) {
// Check for dirty pages and update zero_filled if any found.
if (_dirty.get_next_one_offset(start_page, end_page) < end_page) {
if (_dirty.find_first_set_bit(start_page, end_page) < end_page) {
zero_filled = false;
_dirty.par_clear_range(start_page, end_page, BitMap::unknown_range);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 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
@ -81,12 +81,12 @@ class G1RegionsLargerThanCommitSizeMapper : public G1RegionToSpaceMapper {
bool is_range_committed(uint start_idx, size_t num_regions) {
BitMap::idx_t end = start_idx + num_regions;
return _region_commit_map.get_next_zero_offset(start_idx, end) == end;
return _region_commit_map.find_first_clear_bit(start_idx, end) == end;
}
bool is_range_uncommitted(uint start_idx, size_t num_regions) {
BitMap::idx_t end = start_idx + num_regions;
return _region_commit_map.get_next_one_offset(start_idx, end) == end;
return _region_commit_map.find_first_set_bit(start_idx, end) == end;
}
virtual void commit_regions(uint start_idx, size_t num_regions, WorkerThreads* pretouch_workers) {
@ -146,7 +146,7 @@ class G1RegionsSmallerThanCommitSizeMapper : public G1RegionToSpaceMapper {
size_t region = page_idx * _regions_per_page;
size_t region_limit = region + _regions_per_page;
// Committed if there is a bit set in the range.
return _region_commit_map.get_next_one_offset(region, region_limit) != region_limit;
return _region_commit_map.find_first_set_bit(region, region_limit) != region_limit;
}
void numa_request_on_node(size_t page_idx) {
@ -175,7 +175,7 @@ class G1RegionsSmallerThanCommitSizeMapper : public G1RegionToSpaceMapper {
virtual void commit_regions(uint start_idx, size_t num_regions, WorkerThreads* pretouch_workers) {
uint region_limit = (uint)(start_idx + num_regions);
assert(num_regions > 0, "Must commit at least one region");
assert(_region_commit_map.get_next_one_offset(start_idx, region_limit) == region_limit,
assert(_region_commit_map.find_first_set_bit(start_idx, region_limit) == region_limit,
"Should be no committed regions in the range [%u, %u)", start_idx, region_limit);
size_t const NoPage = ~(size_t)0;
@ -228,7 +228,7 @@ class G1RegionsSmallerThanCommitSizeMapper : public G1RegionToSpaceMapper {
virtual void uncommit_regions(uint start_idx, size_t num_regions) {
uint region_limit = (uint)(start_idx + num_regions);
assert(num_regions > 0, "Must uncommit at least one region");
assert(_region_commit_map.get_next_zero_offset(start_idx, region_limit) == region_limit,
assert(_region_commit_map.find_first_clear_bit(start_idx, region_limit) == region_limit,
"Should only be committed regions in the range [%u, %u)", start_idx, region_limit);
size_t start_page = region_idx_to_page_idx(start_idx);

View File

@ -118,7 +118,7 @@ inline size_t ParMarkBitMap::obj_size(HeapWord* beg_addr, HeapWord* end_addr) co
}
inline size_t ParMarkBitMap::obj_size(idx_t beg_bit) const {
const idx_t end_bit = _end_bits.get_next_one_offset(beg_bit, size());
const idx_t end_bit = _end_bits.find_first_set_bit(beg_bit, size());
assert(is_marked(beg_bit), "obj not marked");
assert(end_bit < size(), "end bit missing");
return obj_size(beg_bit, end_bit);
@ -165,11 +165,11 @@ inline ParMarkBitMap::idx_t ParMarkBitMap::align_range_end(idx_t range_end) cons
}
inline ParMarkBitMap::idx_t ParMarkBitMap::find_obj_beg(idx_t beg, idx_t end) const {
return _beg_bits.get_next_one_offset_aligned_right(beg, end);
return _beg_bits.find_first_set_bit_aligned_right(beg, end);
}
inline ParMarkBitMap::idx_t ParMarkBitMap::find_obj_end(idx_t beg, idx_t end) const {
return _end_bits.get_next_one_offset_aligned_right(beg, end);
return _end_bits.find_first_set_bit_aligned_right(beg, end);
}
inline HeapWord* ParMarkBitMap::find_obj_beg(HeapWord* beg, HeapWord* end) const {

View File

@ -39,7 +39,7 @@ inline HeapWord* MarkBitMap::get_next_marked_addr(const HeapWord* const addr,
// Round addr up to a possible object boundary to be safe.
size_t const addr_offset = addr_to_offset(align_up(addr, HeapWordSize << _shifter));
size_t const limit_offset = addr_to_offset(limit);
size_t const nextOffset = _bm.get_next_one_offset(addr_offset, limit_offset);
size_t const nextOffset = _bm.find_first_set_bit(addr_offset, limit_offset);
return offset_to_addr(nextOffset);
}

View File

@ -690,8 +690,8 @@ void ShenandoahFreeSet::assert_bounds() const {
assert (_mutator_leftmost == _max || is_mutator_free(_mutator_leftmost), "leftmost region should be free: " SIZE_FORMAT, _mutator_leftmost);
assert (_mutator_rightmost == 0 || is_mutator_free(_mutator_rightmost), "rightmost region should be free: " SIZE_FORMAT, _mutator_rightmost);
size_t beg_off = _mutator_free_bitmap.get_next_one_offset(0);
size_t end_off = _mutator_free_bitmap.get_next_one_offset(_mutator_rightmost + 1);
size_t beg_off = _mutator_free_bitmap.find_first_set_bit(0);
size_t end_off = _mutator_free_bitmap.find_first_set_bit(_mutator_rightmost + 1);
assert (beg_off >= _mutator_leftmost, "free regions before the leftmost: " SIZE_FORMAT ", bound " SIZE_FORMAT, beg_off, _mutator_leftmost);
assert (end_off == _max, "free regions past the rightmost: " SIZE_FORMAT ", bound " SIZE_FORMAT, end_off, _mutator_rightmost);
@ -701,8 +701,8 @@ void ShenandoahFreeSet::assert_bounds() const {
assert (_collector_leftmost == _max || is_collector_free(_collector_leftmost), "leftmost region should be free: " SIZE_FORMAT, _collector_leftmost);
assert (_collector_rightmost == 0 || is_collector_free(_collector_rightmost), "rightmost region should be free: " SIZE_FORMAT, _collector_rightmost);
beg_off = _collector_free_bitmap.get_next_one_offset(0);
end_off = _collector_free_bitmap.get_next_one_offset(_collector_rightmost + 1);
beg_off = _collector_free_bitmap.find_first_set_bit(0);
end_off = _collector_free_bitmap.find_first_set_bit(_collector_rightmost + 1);
assert (beg_off >= _collector_leftmost, "free regions before the leftmost: " SIZE_FORMAT ", bound " SIZE_FORMAT, beg_off, _collector_leftmost);
assert (end_off == _max, "free regions past the rightmost: " SIZE_FORMAT ", bound " SIZE_FORMAT, end_off, _collector_rightmost);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -81,11 +81,11 @@ inline bool ZLiveMap::claim_segment(BitMap::idx_t segment) {
}
inline BitMap::idx_t ZLiveMap::first_live_segment() const {
return segment_live_bits().get_next_one_offset(0, nsegments);
return segment_live_bits().find_first_set_bit(0, nsegments);
}
inline BitMap::idx_t ZLiveMap::next_live_segment(BitMap::idx_t segment) const {
return segment_live_bits().get_next_one_offset(segment + 1, nsegments);
return segment_live_bits().find_first_set_bit(segment + 1, nsegments);
}
inline BitMap::idx_t ZLiveMap::segment_size() const {
@ -138,7 +138,7 @@ inline void ZLiveMap::iterate_segment(ObjectClosure* cl, BitMap::idx_t segment,
const BitMap::idx_t start_index = segment_start(segment);
const BitMap::idx_t end_index = segment_end(segment);
BitMap::idx_t index = _bitmap.get_next_one_offset(start_index, end_index);
BitMap::idx_t index = _bitmap.find_first_set_bit(start_index, end_index);
while (index < end_index) {
// Calculate object address
@ -159,7 +159,7 @@ inline void ZLiveMap::iterate_segment(ObjectClosure* cl, BitMap::idx_t segment,
break;
}
index = _bitmap.get_next_one_offset(next_index, end_index);
index = _bitmap.find_first_set_bit(next_index, end_index);
}
}

View File

@ -94,14 +94,14 @@ class BitMap {
return raw_to_words_align_down(bit);
}
// Helper for get_next_{zero,one}_bit variants.
// Helper for find_first_{set,clear}_bit variants.
// - flip designates whether searching for 1s or 0s. Must be one of
// find_{zeros,ones}_flip.
// - aligned_right is true if end is a priori on a bm_word_t boundary.
template<bm_word_t flip, bool aligned_right>
inline idx_t get_next_bit_impl(idx_t beg, idx_t end) const;
inline idx_t find_first_bit_impl(idx_t beg, idx_t end) const;
// Values for get_next_bit_impl flip parameter.
// Values for find_first_bit_impl flip parameter.
static const bm_word_t find_ones_flip = 0;
static const bm_word_t find_zeros_flip = ~(bm_word_t)0;
@ -290,19 +290,19 @@ class BitMap {
// Looking for 1's and 0's at indices equal to or greater than "beg",
// stopping if none has been found before "end", and returning
// "end" (which must be at most "size") in that case.
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 find_first_set_bit(idx_t beg, idx_t end) const;
idx_t find_first_clear_bit(idx_t beg, idx_t end) const;
idx_t get_next_one_offset(idx_t beg) const {
return get_next_one_offset(beg, size());
idx_t find_first_set_bit(idx_t beg) const {
return find_first_set_bit(beg, size());
}
idx_t get_next_zero_offset(idx_t beg) const {
return get_next_zero_offset(beg, size());
idx_t find_first_clear_bit(idx_t beg) const {
return find_first_clear_bit(beg, size());
}
// Like "get_next_one_offset", except requires that "end" is
// Like "find_first_set_bit", except requires that "end" is
// aligned to bitsizeof(bm_word_t).
idx_t get_next_one_offset_aligned_right(idx_t beg, idx_t end) const;
idx_t find_first_set_bit_aligned_right(idx_t beg, idx_t end) const;
// Returns the number of bits set in the bitmap.
idx_t count_one_bits() const;

View File

@ -166,7 +166,7 @@ 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 beg, idx_t end) const {
inline BitMap::idx_t BitMap::find_first_bit_impl(idx_t beg, idx_t end) const {
STATIC_ASSERT(flip == find_ones_flip || flip == find_zeros_flip);
verify_range(beg, end);
assert(!aligned_right || is_aligned(end, BitsPerWord), "end not aligned");
@ -229,18 +229,18 @@ inline BitMap::idx_t BitMap::get_next_bit_impl(idx_t beg, idx_t end) const {
}
inline BitMap::idx_t
BitMap::get_next_one_offset(idx_t beg, idx_t end) const {
return get_next_bit_impl<find_ones_flip, false>(beg, end);
BitMap::find_first_set_bit(idx_t beg, idx_t end) const {
return find_first_bit_impl<find_ones_flip, false>(beg, end);
}
inline BitMap::idx_t
BitMap::get_next_zero_offset(idx_t beg, idx_t end) const {
return get_next_bit_impl<find_zeros_flip, false>(beg, end);
BitMap::find_first_clear_bit(idx_t beg, idx_t end) const {
return find_first_bit_impl<find_zeros_flip, false>(beg, end);
}
inline BitMap::idx_t
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);
BitMap::find_first_set_bit_aligned_right(idx_t beg, idx_t end) const {
return find_first_bit_impl<find_ones_flip, true>(beg, end);
}
// IterateInvoker supports conditionally stopping iteration early. The
@ -271,7 +271,7 @@ template <typename Function>
inline bool BitMap::iterate(Function function, idx_t beg, idx_t end) const {
auto invoke = IterateInvoker<decltype(function(beg))>();
for (idx_t index = beg; true; ++index) {
index = get_next_one_offset(index, end);
index = find_first_set_bit(index, end);
if (index >= end) {
return true;
} else if (!invoke(function, index)) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 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
@ -112,20 +112,20 @@ static void test_search_ranges(BitMap& test_ones,
BitMap& test_zeros,
idx_t left,
idx_t right) {
// Test get_next_one_offset with full range of map.
EXPECT_EQ(left, test_ones.get_next_one_offset(0));
EXPECT_EQ(right, test_ones.get_next_one_offset(left + 1));
EXPECT_EQ(BITMAP_SIZE, test_ones.get_next_one_offset(right + 1));
// Test find_first_set_bit with full range of map.
EXPECT_EQ(left, test_ones.find_first_set_bit(0));
EXPECT_EQ(right, test_ones.find_first_set_bit(left + 1));
EXPECT_EQ(BITMAP_SIZE, test_ones.find_first_set_bit(right + 1));
// Test get_next_one_offset_aligned_right with full range of map.
EXPECT_EQ(left, test_ones.get_next_one_offset_aligned_right(0, BITMAP_SIZE));
EXPECT_EQ(right, test_ones.get_next_one_offset_aligned_right(left + 1, BITMAP_SIZE));
EXPECT_EQ(BITMAP_SIZE, test_ones.get_next_one_offset_aligned_right(right + 1, BITMAP_SIZE));
// Test find_first_set_bit_aligned_right with full range of map.
EXPECT_EQ(left, test_ones.find_first_set_bit_aligned_right(0, BITMAP_SIZE));
EXPECT_EQ(right, test_ones.find_first_set_bit_aligned_right(left + 1, BITMAP_SIZE));
EXPECT_EQ(BITMAP_SIZE, test_ones.find_first_set_bit_aligned_right(right + 1, BITMAP_SIZE));
// Test get_next_zero_offset with full range of map.
EXPECT_EQ(left, test_zeros.get_next_zero_offset(0));
EXPECT_EQ(right, test_zeros.get_next_zero_offset(left + 1));
EXPECT_EQ(BITMAP_SIZE, test_zeros.get_next_zero_offset(right + 1));
// Test find_first_clear_bit with full range of map.
EXPECT_EQ(left, test_zeros.find_first_clear_bit(0));
EXPECT_EQ(right, test_zeros.find_first_clear_bit(left + 1));
EXPECT_EQ(BITMAP_SIZE, test_zeros.find_first_clear_bit(right + 1));
// Check that iterate invokes the closure function on left and right values.
TestIteratorFn test_iteration(0, BITMAP_SIZE, left, right);
@ -170,23 +170,23 @@ static void test_search_ranges(BitMap& test_ones,
idx_t expected = compute_expected(start, end, left, right);
EXPECT_EQ(expected, test_ones.get_next_one_offset(start, end));
EXPECT_EQ(expected, test_zeros.get_next_zero_offset(start, end));
EXPECT_EQ(expected, test_ones.find_first_set_bit(start, end));
EXPECT_EQ(expected, test_zeros.find_first_clear_bit(start, end));
if (aligned_right) {
EXPECT_EQ(
expected,
test_ones.get_next_one_offset_aligned_right(start, end));
test_ones.find_first_set_bit_aligned_right(start, end));
}
idx_t start2 = MIN2(expected + 1, end);
idx_t expected2 = compute_expected(start2, end, left, right);
EXPECT_EQ(expected2, test_ones.get_next_one_offset(start2, end));
EXPECT_EQ(expected2, test_zeros.get_next_zero_offset(start2, end));
EXPECT_EQ(expected2, test_ones.find_first_set_bit(start2, end));
EXPECT_EQ(expected2, test_zeros.find_first_clear_bit(start2, end));
if (aligned_right) {
EXPECT_EQ(
expected2,
test_ones.get_next_one_offset_aligned_right(start2, end));
test_ones.find_first_set_bit_aligned_right(start2, end));
}
}
}
@ -204,8 +204,8 @@ TEST(BitMap, search) {
test_zeros.set_range(0, test_zeros.size());
// Searching "empty" sequence should return size.
EXPECT_EQ(BITMAP_SIZE, test_ones.get_next_one_offset(0));
EXPECT_EQ(BITMAP_SIZE, test_zeros.get_next_zero_offset(0));
EXPECT_EQ(BITMAP_SIZE, test_ones.find_first_set_bit(0));
EXPECT_EQ(BITMAP_SIZE, test_zeros.find_first_clear_bit(0));
// With left being in the first or second chunk...
for (size_t c_left = 0; c_left < 2; ++c_left) {