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

Document HotSpot assumptions about C++

XMLWordPrintable

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

      HotSpot code makes various assumptions about supported platforms, even though those assumptions are not porable according to the C/C++ standards. It would be helpful (esp. to folks new to HotSpot, but also as a reminder for experienced developers) to document those assumptions in an easily found place. Even better would be to check them with (preferably static) assertions where possible.

      It has been suggested that we add the file share/utilities/assumptions.cpp to serve as a respository for a information. Another place for some information of this kind might be the HotSpot Style Guide.

      Some examples:

      - Integral types use two's complement representation. Mandated by C++20. No known platform supporting a "modern" C++ implementation fails to provide this.

      - Right shift of a signed integer sign-extends. Mandated by C++20, UB prior. All supported platforms provide this behavior, though until C++20 tools like ubsan might complain, and constexpr evaluation will fail.

      - The "union trick" (aka type punning via a union) works. Performs bitwise conversion from one type to another without changing the bit pattern, by writing to one union member and reading from another. UB according to all C++ standards through C++26, and all C standards before C11. All supported platforms provide this behavior, though constexpr evaluation will fail. (Uses of the union trick should not proliferate. There are a few places where it is used, wrapped up in utility functions for specific use cases. Those uses might someday be replaced by using std::bit_cast<T>, which would also eliminate the constexpr limitation.)

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

              Created:
              Updated: