RFR: JDK-8302736: Major performance regression in Math.log on aarch64
Tobias Holenstein
tholenstein at openjdk.org
Tue May 23 15:13:18 UTC 2023
On Tue, 23 May 2023 09:28:38 GMT, Andrew Haley <aph at openjdk.org> wrote:
>> ### Performance java.lang.Math exp, log, log10, pow and tan
>> The class`java.lang.Math` contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. The numeric methods of class `java.lang.StrictMath` are defined to return the bit-for-bit same results on all platforms. The implementations of the equivalent functions in class `java.lang.Math` do not have this requirement. This relaxation permits better-performing implementations where strict reproducibility is not required. By default most of the `java.lang.Math` methods simply call the equivalent method in `java.lang.StrictMath` for their implementation. Code generators (like C2) are encouraged to use platform-specific native libraries or microprocessor instructions, where available, to provide higher-performance implementations of `java.lang.Math` methods. Such higher-performance implementations still must conform to the specification for `java.lang.Math`
>>
>> Running JMH benchmarks `org.openjdk.bench.java.lang.StrictMathBench` and `org.openjdk.bench.java.lang.MathBench` on `aarch64` shows that for `exp`, `log`, `log10`, `pow` and `tan` `java.lang.Math` is around 10x slower than `java.lang.StrictMath` - which is NOT expected.
>>
>> ### Reason for major performance regression
>> If there is an intrinsic implemented, like for `Math.sin` and `Math.cos`, C2 generates a `StubRoutines`.
>> Unfortunately, on `macOS aarch64` there is no intrinsics for `Math.tan`, `Math.exp`, `Math.log`, `Math.pow` and `Math.log10` yet.
>>
>> _Tracked here:_
>> [JDK-8189106 AARCH64: create intrinsic for tan - Java Bug System](https://bugs.openjdk.org/browse/JDK-8189106)
>> [JDK-8189107 AARCH64: create intrinsic for pow - Java Bug System](https://bugs.openjdk.org/browse/JDK-8189107)
>> [JDK-8307332 AARCH64: create intrinsic for exp - Java Bug System](https://bugs.openjdk.org/browse/JDK-8307332)
>> [JDK-8210858 AArch64: Math.log intrinsic gives incorrect results - Java Bug System](https://bugs.openjdk.org/browse/JDK-8210858)
>>
>> Instead, for `Math.tan`, `Math.exp`, `Math.log`, `Math.pow` and `Math.log10` a call to a `c++` function is generated in `LibraryCallKit::inline_math_native` with `CAST_FROM_FN_PTR(address, SharedRuntime:: dlog)`
>>
>> The shared runtime functions are implemented in `sharedRuntimeTrans.cpp` as follows:
>> ```c++
>> JRT_LEAF(jdouble, SharedRuntime::dlog(jdouble x))
>> return __ieee754_log(x);
>> JRT_END
>> ```
>>
>> `JRT_L...
>
> Ok, for now. I think we need to revisit the way W^X is handed at some point.
Thanks @theRealAph , @dholmes-ora , @dean-long , @jddarcy and @TobiHartmann for the inputs and reviews!
-------------
PR Comment: https://git.openjdk.org/jdk/pull/13606#issuecomment-1559369512
More information about the hotspot-dev
mailing list