JDK-8297539 : Use PrimitiveConversions::cast for local uses of the int<->float union conversion trick
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 20
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-11-24
  • Updated: 2025-06-13
  • Resolved: 2023-04-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21
21 b17Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
The fix for JDK-8295351 reemployed the basic union trick for converting  int<->float in sharedRuntime.cpp. But we also have the the existing JavaValue type which is also a union and can be used for the same conversion trick. And then we also have the cast function in metaprogramming/primitiveConversions.hpp. There may be other cases too.

It would be good if we could standardise on the use of this technique so that we don't duplicate it in numerous places.

Note this RFE is to fix the int<->float union conversion tricks found in various bits of code to use PrimitiveConversions::cast() and not to change JavaValue. Changing JavaValue (if there's a reason to do this) needs to be explored in another RFE.
This RFE moves in the direction of consolidation towards calling PrimitiveConversions::cast.
Comments
A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/13136 Date: 2023-03-22 10:59:18 +0000
13-06-2025

Changeset: a19b28ab Author: Afshin Zafari <Afshin.zafari@oracle.com> Committer: David Holmes <dholmes@openjdk.org> Date: 2023-04-01 01:02:05 +0000 URL: https://git.openjdk.org/jdk/commit/a19b28ab3ed2d2da4eb04ce9b187dda8a75ba16a
01-04-2023

I've limited the scope of this CR. See linked CRs for related work.
20-03-2023

So there are some float<-> int unions that can be converted using PrimitiveConversions::cast((). This should be cleaned up with this RFE. Removing JavaValue should not be done here. JavaValue is used for return values from Java calls all over the JVM.
15-03-2023

JavaValue is not used for conversions. It is an ordinary discriminated union, and shouldn't be changed.
15-02-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/12384 Date: 2023-02-02 10:17:21 +0000
02-02-2023