Summary
Change the language and virtual machine to only support a single, strict, set of semantics for floating-point expressions.
Problem
Since Java SE 1.2, the language and VM have allowed two variants of floating-point semantics:
- "strict" semantics: marked with
strictfp
in the language,ACC_STRICT
in the VM - non-strict semantics: the default
The non-strict semantics allow, in some circumstances, extra exponent range to be used for intermediate float
and double
values. This flexibility allowed faster code execution for certain popular processors common circa the Java SE 1.2. However, the processor family in question no longer benefits from this spec laxity and the existence of two subtly different variants of floating-point semantics causes on-going costs in maintenance and in developing new platform features.
Solution
Require all floating-point to be done strictly under a single set of semantics.
Specification
For javac
, a new lint option strictfp
whose usage text is:
Warn about unnecessary use of the strictfp modifier.
For the detailed JLS and JVMS changes, see the attached documents. In summary, in the JLS the notions of value set and value set conversion are removed from the specification. The language-level checks about combinations of other modifiers with strictfp
remain. Otherwise, for the purposes of floating-point semantics, strictfp
is a no-op. Many small edits in chapter 15, Expressions, are needed to implement this change. In the JVMS, value set conversion, FP-strict mode, and not FP-strict mode are removed as concepts. The ACC_STRICT
method modifier is undefined for class file with major version 61 and above. Therefore the VM checks for ACC_STRICT
and ACC_ABSTRACT
methods do not apply for class file with major version 61 and above. The check still occurs for class file major versions 46 through 60. This is a deliberate design difference between the handling of "strict abstract" methods in the language the VM. Chapter 6 of the JVMS, The Java Virtual Machine Instruction Set, has small edits in many floating-point instructions.
- csr of
-
JDK-8244146 javac changes for JEP 306
- Resolved
-
JDK-8266530 HotSpot changes for JEP 306
- Resolved
- relates to
-
JDK-8266670 Better modeling of access flags in core reflection
- Resolved
-
JDK-8244143 JLS changes for Restore Always-Strict Floating-Point Semantics
- Resolved
-
JDK-8244144 JVMS changes for Restore Always-Strict Floating-Point Semantics
- Resolved
-
JDK-8299801 Numerical computation differences between and JDK17 JDK8
- Open