< prev index next >

src/share/vm/utilities/bitMap.cpp

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

*** 152,169 **** clear_range_within_word(beg, boundary); clear_range_within_word(boundary, end); } } 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); ! assert(end_full_word - beg_full_word >= 32, ! "the range must include at least 32 bytes"); // The range includes at least one full word. set_range_within_word(beg, bit_index(beg_full_word)); set_large_range_of_words(beg_full_word, end_full_word); set_range_within_word(bit_index(end_full_word), end); --- 152,179 ---- clear_range_within_word(beg, boundary); clear_range_within_word(boundary, end); } } + 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. + // The threshold should be at least one word. + STATIC_ASSERT(small_range_words >= 1); + 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); ! if (is_small_range_of_words(beg_full_word, end_full_word)) { ! set_range(beg, end); ! return; ! } // The range includes at least one full word. set_range_within_word(beg, bit_index(beg_full_word)); set_large_range_of_words(beg_full_word, end_full_word); set_range_within_word(bit_index(end_full_word), end);
*** 173,184 **** verify_range(beg, end); idx_t beg_full_word = word_index_round_up(beg); idx_t end_full_word = word_index(end); ! assert(end_full_word - beg_full_word >= 32, ! "the range must include at least 32 bytes"); // The range includes at least one full word. clear_range_within_word(beg, bit_index(beg_full_word)); clear_large_range_of_words(beg_full_word, end_full_word); clear_range_within_word(bit_index(end_full_word), end); --- 183,196 ---- verify_range(beg, end); idx_t beg_full_word = word_index_round_up(beg); idx_t end_full_word = word_index(end); ! if (is_small_range_of_words(beg_full_word, end_full_word)) { ! clear_range(beg, end); ! return; ! } // The range includes at least one full word. clear_range_within_word(beg, bit_index(beg_full_word)); clear_large_range_of_words(beg_full_word, end_full_word); clear_range_within_word(bit_index(end_full_word), end);
*** 262,273 **** verify_range(beg, end); idx_t beg_full_word = word_index_round_up(beg); idx_t end_full_word = word_index(end); ! assert(end_full_word - beg_full_word >= 32, ! "the range must include at least 32 bytes"); // The range includes at least one full word. par_put_range_within_word(beg, bit_index(beg_full_word), value); if (value) { set_large_range_of_words(beg_full_word, end_full_word); --- 274,287 ---- verify_range(beg, end); idx_t beg_full_word = word_index_round_up(beg); idx_t end_full_word = word_index(end); ! if (is_small_range_of_words(beg_full_word, end_full_word)) { ! par_at_put_range(beg, end, value); ! return; ! } // The range includes at least one full word. par_put_range_within_word(beg, bit_index(beg_full_word), value); if (value) { set_large_range_of_words(beg_full_word, end_full_word);
< prev index next >