Hotspot currently has many places using C style casts, static_cast, or reinterpret_cast to convert between representations without changing the underlying bit representation.
C++20 introduced std::bit_cast for this purpose and it is well defined. It is actually possible to implement bit_cast for C++14, without some constexpr support.
This feature request is to refactor PrimitiveConversions::cast to bit_cast, expand bit_cast to support all compatible types, and use __builtin_bit_cast where available while falling back to the original implementations in PrimitiveConversions::cast. It then will replace some legacy conversion techniques with bit_cast.
C++20 introduced std::bit_cast for this purpose and it is well defined. It is actually possible to implement bit_cast for C++14, without some constexpr support.
This feature request is to refactor PrimitiveConversions::cast to bit_cast, expand bit_cast to support all compatible types, and use __builtin_bit_cast where available while falling back to the original implementations in PrimitiveConversions::cast. It then will replace some legacy conversion techniques with bit_cast.
- relates to
 - 
                    
JDK-8279143 Undefined behaviours in globalDefinitions.hpp
-         
     - Open
 
 -         
 - 
                    
JDK-8297539 Use PrimitiveConversions::cast for local uses of the int<->float union conversion trick
-         
     - Resolved
 
 -         
 - 
                    
JDK-8247825 Replace PrimitiveConversions::cast with C++20 std::bit_cast
-         
     - Closed
 
 -         
 
- links to
 - 
                    
        
        Review
        openjdk/jdk/11865