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

HotSpot Style Guide suggests preferring bit manipulation utilities

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 16
    • hotspot

      The Style Guide currently says

        Use functions from globalDefinitions.hpp when performing bitwise
        operations on integers. Do not code directly as C operators, unless
        they are extremely simple.
        (Examples: `round_to`, `is_power_of_2`, `exact_log2`.)

      (Note that some of the named functions have been moved to other files, but the intent is the same.)

      Over the years, we've seen problems with the intptr_t bit manipulation functions in globalDefinitions.hpp. We have been slowly fixing these problems and moving some of them away into other headers like align.hpp and powerOfTwo.hpp. The bit-manipulation functions left in globalDefinitions.hpp still use intptr_t and we shouldn't encourage (or even require) people to using them before they have been rewritten, and fully tested with all integer types.

      Another problem is that existing implementations of some of them invoke undefined behavior in at least some uses.

      Yet another problem is that they aren't constexpr, which direct use of operators is. With C++11/14 that can be addressed.

      Note that the uptake of these functions has been somewhat limited, perhaps in part because of the problems with their current definitions.

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

              Created:
              Updated: