JEP 306, implemented in Java 17, provides always-strict floating point semantics, deprecating the strictfp flag. Does this mean that java.lang.Math can be counted on to behave exactly the same as the analogous methods in StrictMath (i.e., that java.lang.Math methods can no longer be replaced by the JVM with intrinsics as used to be allowed)? Does it also mean that there should no longer be any differences in floating point math results among different architectures, no matter which library is used?
I'm curious if I'm misunderstanding the new Java 17 feature, since we do see differences in today's code between Apple Silicon vs Intel.
First of all,
strictfpis not a flag, this is a Java keyword ensuring the same calculation results on every platform while doing operations over floating-point variables (floatanddouble).As of your question, there are two major PRs in OpenJDK involving the changes for JEP 306
If you look into the first one, especially into StrictMath you'll see that it now delegates directly to
j.l.Mathand the comment aboutstrictfpsemantics is now removed (along withstrictfpkeyword in OpenJDK codebase). Moreover, starting from Java 17javacissues an explicit warning forstrictfpkeyword (seecompiler.properties:So for the question
The answer is "yes", for some methods e.g.
Math.sinh(double)delegate toStrictMath.sinh(double)(and later on toFdLibm.Sinh.compute(dobule)) and e.g. methodStrictMath.toRadians(double)delegates toMath.toRadians(double). Eventually for floating-point variables it does not matter whether you call a method ofMathorStrictMath, the same code is executed under the hood.As of this part of the same question:
The PRs does not impose any changes regarding intrinsics which are platform-specific and applied by JVM at runtime regardless of whether operation is strict or not. Moreover, as @Holger pointed out, there is no contradiction between strictness and intrinsics.
The answer is "yes as of Java 17 or newer". Prior to it there could be difference in results, see https://stackoverflow.com/a/22335100/12473843. Before Java 17 if an operation over floating-point variable was not strict the standard assumed that
See also 8268224: Cleanup references to "strictfp" in core lib comments
P.S.
I think it's quite natural for compiler to produce different code for different platforms, the question here is whether you see different results of computations on mentioned platforms.