< prev index next >

src/hotspot/share/utilities/bitMap.cpp

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


 246 
 247 void BitMap::clear_range(idx_t beg, idx_t end) {
 248   verify_range(beg, end);
 249 
 250   idx_t beg_full_word = word_index_round_up(beg);
 251   idx_t end_full_word = word_index(end);
 252 
 253   if (beg_full_word < end_full_word) {
 254     // The range includes at least one full word.
 255     clear_range_within_word(beg, bit_index(beg_full_word));
 256     clear_range_of_words(beg_full_word, end_full_word);
 257     clear_range_within_word(bit_index(end_full_word), end);
 258   } else {
 259     // The range spans at most 2 partial words.
 260     idx_t boundary = MIN2(bit_index(beg_full_word), end);
 261     clear_range_within_word(beg, boundary);
 262     clear_range_within_word(boundary, end);
 263   }
 264 }
 265 








 266 void BitMap::set_large_range(idx_t beg, idx_t end) {
 267   verify_range(beg, end);
 268 
 269   idx_t beg_full_word = word_index_round_up(beg);
 270   idx_t end_full_word = word_index(end);
 271 
 272   assert(end_full_word - beg_full_word >= 32,
 273          "the range must include at least 32 bytes");


 274 
 275   // The range includes at least one full word.
 276   set_range_within_word(beg, bit_index(beg_full_word));
 277   set_large_range_of_words(beg_full_word, end_full_word);
 278   set_range_within_word(bit_index(end_full_word), end);
 279 }
 280 
 281 void BitMap::clear_large_range(idx_t beg, idx_t end) {
 282   verify_range(beg, end);
 283 
 284   idx_t beg_full_word = word_index_round_up(beg);
 285   idx_t end_full_word = word_index(end);
 286 
 287   if (end_full_word - beg_full_word < 32) {
 288     clear_range(beg, end);
 289     return;
 290   }
 291 
 292   // The range includes at least one full word.
 293   clear_range_within_word(beg, bit_index(beg_full_word));
 294   clear_large_range_of_words(beg_full_word, end_full_word);
 295   clear_range_within_word(bit_index(end_full_word), end);
 296 }
 297 
 298 void BitMap::at_put(idx_t offset, bool value) {
 299   if (value) {
 300     set_bit(offset);
 301   } else {
 302     clear_bit(offset);
 303   }
 304 }
 305 
 306 // Return true to indicate that this thread changed
 307 // the bit, false to indicate that someone else did.


 351     par_put_range_within_word(beg, boundary, value);
 352     par_put_range_within_word(boundary, end, value);
 353   }
 354 
 355 }
 356 
 357 void BitMap::at_put_large_range(idx_t beg, idx_t end, bool value) {
 358   if (value) {
 359     set_large_range(beg, end);
 360   } else {
 361     clear_large_range(beg, end);
 362   }
 363 }
 364 
 365 void BitMap::par_at_put_large_range(idx_t beg, idx_t end, bool value) {
 366   verify_range(beg, end);
 367 
 368   idx_t beg_full_word = word_index_round_up(beg);
 369   idx_t end_full_word = word_index(end);
 370 
 371   assert(end_full_word - beg_full_word >= 32,
 372          "the range must include at least 32 bytes");


 373 
 374   // The range includes at least one full word.
 375   par_put_range_within_word(beg, bit_index(beg_full_word), value);
 376   if (value) {
 377     set_large_range_of_words(beg_full_word, end_full_word);
 378   } else {
 379     clear_large_range_of_words(beg_full_word, end_full_word);
 380   }
 381   par_put_range_within_word(bit_index(end_full_word), end, value);
 382 }
 383 
 384 inline bm_word_t tail_mask(idx_t tail_bits) {
 385   assert(tail_bits != 0, "precondition"); // Works, but shouldn't be called.
 386   assert(tail_bits < (idx_t)BitsPerWord, "precondition");
 387   return (bm_word_t(1) << tail_bits) - 1;
 388 }
 389 
 390 // Get the low tail_bits of value, which is the last partial word of a map.
 391 inline bm_word_t tail_of_map(bm_word_t value, idx_t tail_bits) {
 392   return value & tail_mask(tail_bits);




 246 
 247 void BitMap::clear_range(idx_t beg, idx_t end) {
 248   verify_range(beg, end);
 249 
 250   idx_t beg_full_word = word_index_round_up(beg);
 251   idx_t end_full_word = word_index(end);
 252 
 253   if (beg_full_word < end_full_word) {
 254     // The range includes at least one full word.
 255     clear_range_within_word(beg, bit_index(beg_full_word));
 256     clear_range_of_words(beg_full_word, end_full_word);
 257     clear_range_within_word(bit_index(end_full_word), end);
 258   } else {
 259     // The range spans at most 2 partial words.
 260     idx_t boundary = MIN2(bit_index(beg_full_word), end);
 261     clear_range_within_word(beg, boundary);
 262     clear_range_within_word(boundary, end);
 263   }
 264 }
 265 
 266 bool BitMap::is_small_range_of_words(idx_t beg_full_word, idx_t end_full_word) {
 267   // There is little point to call large version on small ranges.
 268   // Need to check carefully, keeping potential idx_t underflow in mind.
 269   // The threshold should be at least one word.
 270   STATIC_ASSERT(small_range_words >= 1);
 271   return (beg_full_word + small_range_words >= end_full_word);
 272 }
 273 
 274 void BitMap::set_large_range(idx_t beg, idx_t end) {
 275   verify_range(beg, end);
 276 
 277   idx_t beg_full_word = word_index_round_up(beg);
 278   idx_t end_full_word = word_index(end);
 279 
 280   if (is_small_range_of_words(beg_full_word, end_full_word)) {
 281     set_range(beg, end);
 282     return;
 283   }
 284 
 285   // The range includes at least one full word.
 286   set_range_within_word(beg, bit_index(beg_full_word));
 287   set_large_range_of_words(beg_full_word, end_full_word);
 288   set_range_within_word(bit_index(end_full_word), end);
 289 }
 290 
 291 void BitMap::clear_large_range(idx_t beg, idx_t end) {
 292   verify_range(beg, end);
 293 
 294   idx_t beg_full_word = word_index_round_up(beg);
 295   idx_t end_full_word = word_index(end);
 296 
 297   if (is_small_range_of_words(beg_full_word, end_full_word)) {
 298     clear_range(beg, end);
 299     return;
 300   }
 301 
 302   // The range includes at least one full word.
 303   clear_range_within_word(beg, bit_index(beg_full_word));
 304   clear_large_range_of_words(beg_full_word, end_full_word);
 305   clear_range_within_word(bit_index(end_full_word), end);
 306 }
 307 
 308 void BitMap::at_put(idx_t offset, bool value) {
 309   if (value) {
 310     set_bit(offset);
 311   } else {
 312     clear_bit(offset);
 313   }
 314 }
 315 
 316 // Return true to indicate that this thread changed
 317 // the bit, false to indicate that someone else did.


 361     par_put_range_within_word(beg, boundary, value);
 362     par_put_range_within_word(boundary, end, value);
 363   }
 364 
 365 }
 366 
 367 void BitMap::at_put_large_range(idx_t beg, idx_t end, bool value) {
 368   if (value) {
 369     set_large_range(beg, end);
 370   } else {
 371     clear_large_range(beg, end);
 372   }
 373 }
 374 
 375 void BitMap::par_at_put_large_range(idx_t beg, idx_t end, bool value) {
 376   verify_range(beg, end);
 377 
 378   idx_t beg_full_word = word_index_round_up(beg);
 379   idx_t end_full_word = word_index(end);
 380 
 381   if (is_small_range_of_words(beg_full_word, end_full_word)) {
 382     par_at_put_range(beg, end, value);
 383     return;
 384   }
 385 
 386   // The range includes at least one full word.
 387   par_put_range_within_word(beg, bit_index(beg_full_word), value);
 388   if (value) {
 389     set_large_range_of_words(beg_full_word, end_full_word);
 390   } else {
 391     clear_large_range_of_words(beg_full_word, end_full_word);
 392   }
 393   par_put_range_within_word(bit_index(end_full_word), end, value);
 394 }
 395 
 396 inline bm_word_t tail_mask(idx_t tail_bits) {
 397   assert(tail_bits != 0, "precondition"); // Works, but shouldn't be called.
 398   assert(tail_bits < (idx_t)BitsPerWord, "precondition");
 399   return (bm_word_t(1) << tail_bits) - 1;
 400 }
 401 
 402 // Get the low tail_bits of value, which is the last partial word of a map.
 403 inline bm_word_t tail_of_map(bm_word_t value, idx_t tail_bits) {
 404   return value & tail_mask(tail_bits);


< prev index next >