JDK-8294340 : The `StrictMath` implementation methods of `Math` intrinsics should also be intrinsics
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 20
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2022-09-25
  • Updated: 2024-07-12
  • Resolved: 2022-09-26
Related Reports
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
Since JEP 306 (JDK-8175916), the implementations of `java.lang.StrictMath` and `java.lang.Math` were changed to delegate to each other.
However there exist several methods in `Math` which are annotated with `@IntrinsicCandidate`, but the fallback implementation methods in `StrictMath` are not.

I propose that the implementation methods in `StrictMath` are also made into intrinsic candidates:

- `public static double java.lang.Math.sin(double)` → `public static native double java.lang.StrictMath.sin(double)`
- `public static double java.lang.Math.cos(double)` → `public static native double java.lang.StrictMath.cos(double)`
- `public static double java.lang.Math.tan(double)` → `public static native double java.lang.StrictMath.tan(double)`
- `public static double java.lang.Math.exp(double)` → `public static double java.lang.StrictMath.exp(double)`
- `public static double java.lang.Math.log(double)` → `public static native double java.lang.StrictMath.log(double)`
- `public static double java.lang.Math.log10(double)` → `public static native double java.lang.StrictMath.log10(double)`
- `public static double java.lang.Math.ceil(double)` → `public static double java.lang.StrictMath.ceil(double)`
- `public static double java.lang.Math.floor(double)` → `public static double java.lang.StrictMath.floor(double)`
- `public static double java.lang.Math.rint(double)` → `public static double java.lang.StrictMath.rint(double)`
- `public static double java.lang.Math.atan2(double,double)` → `public static double java.lang.StrictMath.atan2(double,double)`
- `public static double java.lang.Math.pow(double,double)` → `public static double java.lang.StrictMath.pow(double,double)`



Comments
The assumption in this bug that "Since JEP 306 (JDK-8175916), the implementations of `java.lang.StrictMath` and `java.lang.Math` were changed to delegate to each other." is false. This can be verified by looking at JDK-8266399: "Core libs update for JEP 306" where the delegation pattern does not change. The Math and StrictMath method are required to conform to the same quality of implementation criteria. The StrictMath method must use a particular algorithm, the Math methods need not. Therefore, it is the intended semantics that the Math methods may use the StrictMath counterpart as as implementation or may use a platform-optimized intrinsic. Closing as not a bug.
26-09-2022

Moved to JDK for further evaluations.
26-09-2022