RFR: JDK-8299688: Adopt C++14 compatible std::bit_cast introduced in C++20

Justin King jcking at openjdk.org
Thu Jan 5 18:40:42 UTC 2023


Adopts a C++14 compatible implementation of [std::bit_cast](https://en.cppreference.com/w/cpp/numeric/bit_cast).

`PrimitiveConversions::cast` is refactored into `bit_cast` and extended to support all compatible types. Additionally it makes use of `__builtin_bit_cast` when available, which is strictly well defined compared to fallback approaches which are sometimes lurking in undefined behavior territory.

Lastly some legacy casting is updated to use `bit_cast` in `utilities/globalDefinitions.hpp`.

-------------

Commit messages:
 - Correctly handle const/volatile pointers
 - Use __builtin_bit_cast when available for every specialization of bit_cast
 - Minor cleanup
 - Ensure operator& overloading is ignored
 - Fix interdependency
 - Fix interdependency
 - Do not use bit_cast for function pointer conversion
 - Use bit_cast in utilities/globalDefinitions.hpp
 - Add additional test cases
 - Remove <memory> include and fix another include
 - ... and 2 more: https://git.openjdk.org/jdk/compare/41900b57...4cff62ba

Changes: https://git.openjdk.org/jdk/pull/11865/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=11865&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8299688
  Stats: 687 lines in 18 files changed: 400 ins; 236 del; 51 mod
  Patch: https://git.openjdk.org/jdk/pull/11865.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/11865/head:pull/11865

PR: https://git.openjdk.org/jdk/pull/11865


More information about the hotspot-dev mailing list