< prev index next >

src/hotspot/share/utilities/bitMap.inline.hpp

Print this page
rev 52445 : 8211926: Catastrophic size_t underflow in BitMap::*_large methods
Reviewed-by: kbarrett


 220   return get_next_bit_impl<find_ones_flip, true>(l_offset, r_offset);
 221 }
 222 
 223 // Returns a bit mask for a range of bits [beg, end) within a single word.  Each
 224 // bit in the mask is 0 if the bit is in the range, 1 if not in the range.  The
 225 // returned mask can be used directly to clear the range, or inverted to set the
 226 // range.  Note:  end must not be 0.
 227 inline BitMap::bm_word_t
 228 BitMap::inverted_bit_mask_for_range(idx_t beg, idx_t end) const {
 229   assert(end != 0, "does not work when end == 0");
 230   assert(beg == end || word_index(beg) == word_index(end - 1),
 231          "must be a single-word range");
 232   bm_word_t mask = bit_mask(beg) - 1;   // low (right) bits
 233   if (bit_in_word(end) != 0) {
 234     mask |= ~(bit_mask(end) - 1);       // high (left) bits
 235   }
 236   return mask;
 237 }
 238 
 239 inline void BitMap::set_large_range_of_words(idx_t beg, idx_t end) {

 240   memset(_map + beg, ~(unsigned char)0, (end - beg) * sizeof(bm_word_t));
 241 }
 242 
 243 inline void BitMap::clear_large_range_of_words(idx_t beg, idx_t end) {

 244   memset(_map + beg, 0, (end - beg) * sizeof(bm_word_t));
 245 }
 246 
 247 inline BitMap::idx_t BitMap::word_index_round_up(idx_t bit) const {
 248   idx_t bit_rounded_up = bit + (BitsPerWord - 1);
 249   // Check for integer arithmetic overflow.
 250   return bit_rounded_up > bit ? word_index(bit_rounded_up) : size_in_words();
 251 }
 252 
 253 inline bool BitMap2D::is_valid_index(idx_t slot_index, idx_t bit_within_slot_index) {
 254   verify_bit_within_slot_index(bit_within_slot_index);
 255   return (bit_index(slot_index, bit_within_slot_index) < size_in_bits());
 256 }
 257 
 258 inline bool BitMap2D::at(idx_t slot_index, idx_t bit_within_slot_index) const {
 259   verify_bit_within_slot_index(bit_within_slot_index);
 260   return _map.at(bit_index(slot_index, bit_within_slot_index));
 261 }
 262 
 263 inline void BitMap2D::set_bit(idx_t slot_index, idx_t bit_within_slot_index) {




 220   return get_next_bit_impl<find_ones_flip, true>(l_offset, r_offset);
 221 }
 222 
 223 // Returns a bit mask for a range of bits [beg, end) within a single word.  Each
 224 // bit in the mask is 0 if the bit is in the range, 1 if not in the range.  The
 225 // returned mask can be used directly to clear the range, or inverted to set the
 226 // range.  Note:  end must not be 0.
 227 inline BitMap::bm_word_t
 228 BitMap::inverted_bit_mask_for_range(idx_t beg, idx_t end) const {
 229   assert(end != 0, "does not work when end == 0");
 230   assert(beg == end || word_index(beg) == word_index(end - 1),
 231          "must be a single-word range");
 232   bm_word_t mask = bit_mask(beg) - 1;   // low (right) bits
 233   if (bit_in_word(end) != 0) {
 234     mask |= ~(bit_mask(end) - 1);       // high (left) bits
 235   }
 236   return mask;
 237 }
 238 
 239 inline void BitMap::set_large_range_of_words(idx_t beg, idx_t end) {
 240   assert(beg <= end, "underflow");
 241   memset(_map + beg, ~(unsigned char)0, (end - beg) * sizeof(bm_word_t));
 242 }
 243 
 244 inline void BitMap::clear_large_range_of_words(idx_t beg, idx_t end) {
 245   assert(beg <= end, "underflow");
 246   memset(_map + beg, 0, (end - beg) * sizeof(bm_word_t));
 247 }
 248 
 249 inline BitMap::idx_t BitMap::word_index_round_up(idx_t bit) const {
 250   idx_t bit_rounded_up = bit + (BitsPerWord - 1);
 251   // Check for integer arithmetic overflow.
 252   return bit_rounded_up > bit ? word_index(bit_rounded_up) : size_in_words();
 253 }
 254 
 255 inline bool BitMap2D::is_valid_index(idx_t slot_index, idx_t bit_within_slot_index) {
 256   verify_bit_within_slot_index(bit_within_slot_index);
 257   return (bit_index(slot_index, bit_within_slot_index) < size_in_bits());
 258 }
 259 
 260 inline bool BitMap2D::at(idx_t slot_index, idx_t bit_within_slot_index) const {
 261   verify_bit_within_slot_index(bit_within_slot_index);
 262   return _map.at(bit_index(slot_index, bit_within_slot_index));
 263 }
 264 
 265 inline void BitMap2D::set_bit(idx_t slot_index, idx_t bit_within_slot_index) {


< prev index next >