--- old/src/hotspot/share/utilities/bitMap.cpp 2019-11-26 19:23:24.890720664 -0500 +++ new/src/hotspot/share/utilities/bitMap.cpp 2019-11-26 19:23:24.618706085 -0500 @@ -174,14 +174,27 @@ } #ifdef ASSERT -void BitMap::verify_index(idx_t index) const { - assert(index < _size, "BitMap index out of bounds"); +void BitMap::verify_size(idx_t size_in_bits) { + assert(size_in_bits <= max_size_in_bits(), + "out of bounds: " SIZE_FORMAT, size_in_bits); } -void BitMap::verify_range(idx_t beg_index, idx_t end_index) const { - assert(beg_index <= end_index, "BitMap range error"); - // Note that [0,0) and [size,size) are both valid ranges. - if (end_index != _size) verify_index(end_index); +void BitMap::verify_index(idx_t bit) const { + assert(bit < _size, + "BitMap index out of bounds: " SIZE_FORMAT " >= " SIZE_FORMAT, + bit, _size); +} + +void BitMap::verify_limit(idx_t bit) const { + assert(bit <= _size, + "BitMap limit out of bounds: " SIZE_FORMAT " > " SIZE_FORMAT, + bit, _size); +} + +void BitMap::verify_range(idx_t beg, idx_t end) const { + assert(beg <= end, + "BitMap range error: " SIZE_FORMAT " > " SIZE_FORMAT, beg, end); + verify_limit(end); } #endif // #ifdef ASSERT @@ -228,8 +241,8 @@ void BitMap::set_range(idx_t beg, idx_t end) { verify_range(beg, end); - idx_t beg_full_word = word_index_round_up(beg); - idx_t end_full_word = word_index(end); + idx_t beg_full_word = to_words_align_up(beg); + idx_t end_full_word = to_words_align_down(end); if (beg_full_word < end_full_word) { // The range includes at least one full word. @@ -247,8 +260,8 @@ void BitMap::clear_range(idx_t beg, idx_t end) { verify_range(beg, end); - idx_t beg_full_word = word_index_round_up(beg); - idx_t end_full_word = word_index(end); + idx_t beg_full_word = to_words_align_up(beg); + idx_t end_full_word = to_words_align_down(end); if (beg_full_word < end_full_word) { // The range includes at least one full word. @@ -265,17 +278,19 @@ bool BitMap::is_small_range_of_words(idx_t beg_full_word, idx_t end_full_word) { // There is little point to call large version on small ranges. - // Need to check carefully, keeping potential idx_t underflow in mind. + // Need to check carefully, keeping potential idx_t over/underflow in mind, + // because beg_full_word > end_full_word can occur when beg and end are in + // the same word. // The threshold should be at least one word. STATIC_ASSERT(small_range_words >= 1); - return (beg_full_word + small_range_words >= end_full_word); + return beg_full_word + small_range_words >= end_full_word; } void BitMap::set_large_range(idx_t beg, idx_t end) { verify_range(beg, end); - idx_t beg_full_word = word_index_round_up(beg); - idx_t end_full_word = word_index(end); + idx_t beg_full_word = to_words_align_up(beg); + idx_t end_full_word = to_words_align_down(end); if (is_small_range_of_words(beg_full_word, end_full_word)) { set_range(beg, end); @@ -291,8 +306,8 @@ void BitMap::clear_large_range(idx_t beg, idx_t end) { verify_range(beg, end); - idx_t beg_full_word = word_index_round_up(beg); - idx_t end_full_word = word_index(end); + idx_t beg_full_word = to_words_align_up(beg); + idx_t end_full_word = to_words_align_down(end); if (is_small_range_of_words(beg_full_word, end_full_word)) { clear_range(beg, end); @@ -343,8 +358,8 @@ void BitMap::par_at_put_range(idx_t beg, idx_t end, bool value) { verify_range(beg, end); - idx_t beg_full_word = word_index_round_up(beg); - idx_t end_full_word = word_index(end); + idx_t beg_full_word = to_words_align_up(beg); + idx_t end_full_word = to_words_align_down(end); if (beg_full_word < end_full_word) { // The range includes at least one full word. @@ -375,8 +390,8 @@ void BitMap::par_at_put_large_range(idx_t beg, idx_t end, bool value) { verify_range(beg, end); - idx_t beg_full_word = word_index_round_up(beg); - idx_t end_full_word = word_index(end); + idx_t beg_full_word = to_words_align_up(beg); + idx_t end_full_word = to_words_align_down(end); if (is_small_range_of_words(beg_full_word, end_full_word)) { par_at_put_range(beg, end, value); @@ -420,7 +435,7 @@ assert(size() == other.size(), "must have same size"); const bm_word_t* dest_map = map(); const bm_word_t* other_map = other.map(); - idx_t limit = word_index(size()); + idx_t limit = to_words_align_down(size()); for (idx_t index = 0; index < limit; ++index) { // false if other bitmap has bits set which are clear in this bitmap. if ((~dest_map[index] & other_map[index]) != 0) return false; @@ -435,7 +450,7 @@ assert(size() == other.size(), "must have same size"); const bm_word_t* dest_map = map(); const bm_word_t* other_map = other.map(); - idx_t limit = word_index(size()); + idx_t limit = to_words_align_down(size()); for (idx_t index = 0; index < limit; ++index) { if ((dest_map[index] & other_map[index]) != 0) return true; } @@ -448,7 +463,7 @@ assert(size() == other.size(), "must have same size"); bm_word_t* dest_map = map(); const bm_word_t* other_map = other.map(); - idx_t limit = word_index(size()); + idx_t limit = to_words_align_down(size()); for (idx_t index = 0; index < limit; ++index) { dest_map[index] |= other_map[index]; } @@ -463,7 +478,7 @@ assert(size() == other.size(), "must have same size"); bm_word_t* dest_map = map(); const bm_word_t* other_map = other.map(); - idx_t limit = word_index(size()); + idx_t limit = to_words_align_down(size()); for (idx_t index = 0; index < limit; ++index) { dest_map[index] &= ~other_map[index]; } @@ -478,7 +493,7 @@ assert(size() == other.size(), "must have same size"); bm_word_t* dest_map = map(); const bm_word_t* other_map = other.map(); - idx_t limit = word_index(size()); + idx_t limit = to_words_align_down(size()); for (idx_t index = 0; index < limit; ++index) { dest_map[index] &= other_map[index]; } @@ -494,7 +509,7 @@ bool changed = false; bm_word_t* dest_map = map(); const bm_word_t* other_map = other.map(); - idx_t limit = word_index(size()); + idx_t limit = to_words_align_down(size()); for (idx_t index = 0; index < limit; ++index) { bm_word_t orig = dest_map[index]; bm_word_t temp = orig | other_map[index]; @@ -516,7 +531,7 @@ bool changed = false; bm_word_t* dest_map = map(); const bm_word_t* other_map = other.map(); - idx_t limit = word_index(size()); + idx_t limit = to_words_align_down(size()); for (idx_t index = 0; index < limit; ++index) { bm_word_t orig = dest_map[index]; bm_word_t temp = orig & ~other_map[index]; @@ -538,7 +553,7 @@ bool changed = false; bm_word_t* dest_map = map(); const bm_word_t* other_map = other.map(); - idx_t limit = word_index(size()); + idx_t limit = to_words_align_down(size()); for (idx_t index = 0; index < limit; ++index) { bm_word_t orig = dest_map[index]; bm_word_t temp = orig & other_map[index]; @@ -559,7 +574,7 @@ assert(size() == other.size(), "must have same size"); bm_word_t* dest_map = map(); const bm_word_t* other_map = other.map(); - idx_t copy_words = word_index(size()); + idx_t copy_words = to_words_align_down(size()); Copy::disjoint_words((HeapWord*)other_map, (HeapWord*)dest_map, copy_words); idx_t rest = bit_in_word(size()); if (rest > 0) { @@ -573,7 +588,7 @@ assert(size() == other.size(), "must have same size"); const bm_word_t* dest_map = map(); const bm_word_t* other_map = other.map(); - idx_t limit = word_index(size()); + idx_t limit = to_words_align_down(size()); for (idx_t index = 0; index < limit; ++index) { if (dest_map[index] != other_map[index]) return false; } @@ -583,7 +598,7 @@ bool BitMap::is_full() const { const bm_word_t* words = map(); - idx_t limit = word_index(size()); + idx_t limit = to_words_align_down(size()); for (idx_t index = 0; index < limit; ++index) { if (~words[index] != 0) return false; } @@ -593,7 +608,7 @@ bool BitMap::is_empty() const { const bm_word_t* words = map(); - idx_t limit = word_index(size()); + idx_t limit = to_words_align_down(size()); for (idx_t index = 0; index < limit; ++index) { if (words[index] != 0) return false; } @@ -612,8 +627,8 @@ bool BitMap::iterate(BitMapClosure* blk, idx_t leftOffset, idx_t rightOffset) { verify_range(leftOffset, rightOffset); - idx_t startIndex = word_index(leftOffset); - idx_t endIndex = MIN2(word_index(rightOffset) + 1, size_in_words()); + idx_t startIndex = to_words_align_down(leftOffset); + idx_t endIndex = to_words_align_up(rightOffset); for (idx_t index = startIndex, offset = leftOffset; offset < rightOffset && index < endIndex; offset = (++index) << LogBitsPerWord) {