Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8213415

BitMap::word_index_round_up overflow problems

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 14
    • None
    • hotspot
    • None
    • gc
    • b26
    • generic
    • generic

    Description

      BitMap::word_index_round_up tries to be careful about overflow in

        bit + (BitsPerWord - 1)

      If that doesn't overflow, then it returns word_index of that. But if it overflows, the result of size_in_words is returned instead. But size_in_words just performs exactly the same computation that overflowed to get there; see calc_size_in_words.

      An always safe from overflow way to compute it is:

        word_index(bit) + (is_word_aligned(bit) ? 0 : 1)

      Of course, there is the practical consideration that overflow involves a bitmap that is "unlikely" to fit in memory, e.g > ~2 exabytes on a 64bit platform, making the overflow handling here probably a waste of time for actual bitmap indices. But overflow is quite possible on a 32bit platform, where only 1/2GByte bitmap is needed.

      Also note that BitMap::is_word_aligned uses the (slightly) more expensive word_align_up rather than word_align_down. is_word_aligned should just be is_aligned(bit, BitsPerWord).

      Attachments

        Issue Links

          Activity

            People

              kbarrett Kim Barrett
              kbarrett Kim Barrett
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: