JDK-8022109 : Evaluate adding incrementExact, decrementExact, negateExact to java.lang.Math
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-08-02
  • Updated: 2019-08-22
  • Resolved: 2013-08-14
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 8
8 b105Fixed
Related Reports
Relates :  
Relates :  
Description
Part of the Nashorn runtime performance effort is to add VM intrinsics for the addExact, mulExact and subExact methods in java.lang.Math.  We would of course like as much integer/long arithmetic with overflow exceptions as possible in java.lang.Math for intrinsification, so if these methods that were previously proposed could be put back, that'd be great.

The addExact intrinsic is basically

add eax, edx
jo fail:
ret //normal path

which would make it extremely fast and help JavaScript runtime performance

See also: http://blog.joda.org/2012/02/jdk-helper-math-methods.html

The following arithmetic operations exist in JavaScript

unary +, unary -, ++, --, add, div, mod, mul, sub, div

The unary plus that behaves like negateExact (but doesn't negate) would be useful to us all, as well as various comparison operations ifleExact(int, int), but they obviously don't belong in Math. I'm just mentioning them as reference.