RFR: JDK-8302736: Major performance regression in Math.log on aarch64

Tobias Holenstein tholenstein at openjdk.org
Mon May 15 14:07:47 UTC 2023


On Sun, 14 May 2023 10:30:50 GMT, Andrew Haley <aph at openjdk.org> wrote:

> Maybe we should simply disable the intrinsic.

I am not sure I understand what you mean with disabling the intrinsics. Do you mean in general or to fix `JDK-8302736`?

If intrinsics are disabled in C2, Math and StrictMath will have the same performance. As mentioned in the PR description there are no intrinsics for `Math.tan`, `Math.exp`, `Math.log`, `Math.pow` and `Math.log10` on `macOS aarch64` but there exist c++ implementations in C2: `__ieee754_exp`, `__ieee754_pow`, `__ieee754_log`,` __ieee754_log10`, `SharedRuntime::dtan`

The math functions in `Math.java` are mostly just delegated to `StrictMath`:

@IntrinsicCandidate
public static double log(double a) {
    return StrictMath.log(a); // default impl. delegates to StrictMath
}

The main difference is the `@IntrinsicCandidate` which allows C2 to replace the function with an `intrinsics` or if there is no intrinsics available for an architecture with a call to a c++ implementation of the math function. 

Here are the results of the JMH benchmarks Math vs StrictMath  on `mainline`, `mainline with intrinsics disabled` and with this fix `JDK-8302736` :

| JMH Benchmark    | master (intrinsic on)   | master (intrinsic off)  | JDK-8302736        | Arrch64 C2 impl. | 
| ---------------: | -----------------: | -----------------: | -----------------: | :--------------  | 
| **Math.exp**         |   **13358** ops/ms     |  161142 ops/ms     |  **200088** ops/ms     | c++ | 
| StrictMath.exp   |  161669 ops/ms     |  161474 ops/ms     |  161031 ops/ms     | - | 
| **Math.pow**         |   **21598** ops/ms     |  486085 ops/ms     |  **356691** ops/ms     | c++ | 
| StrictMath.pow   |  490299 ops/ms     |  491422 ops/ms     |  494714 ops/ms     | - | 
| **Math.log**         |   **16170** ops/ms     |  221149 ops/ms     |  **210370** ops/ms     | c++ | 
| StrictMath.log   |  224129 ops/ms     |  222821 ops/ms     |  222042 ops/ms     | - | 
| **Math.log10**       |   **14791** ops/ms     |  150701 ops/ms     |  **158154** ops/ms     | c++  | 
| StrictMath.log10 |  152683 ops/ms     |  151418 ops/ms     |  151211 ops/ms     | - | 
| Math.sin         |  267036 ops/ms     |  159221 ops/ms     |  268296 ops/ms     | intrinsic | 
| StrictMath.sin   |  158828 ops/ms     |  158736 ops/ms     |  159116 ops/ms     | - | 
| Math.cos         |  292302 ops/ms     |  173359 ops/ms     |  291640 ops/ms     | intrinsic | 
| StrictMath.cos   |  172939 ops/ms     |  172890 ops/ms     |  172562 ops/ms     | - | 
| **Math.tan**         |   **12475** ops/ms     |   98477 ops/ms     |   **83818** ops/ms     | c++ |
| StrictMath.tan   |   98716 ops/ms     |   98078 ops/ms     |   98835 ops/ms     | - |
| Math.ceil        | 1758784 ops/ms     | 1192446 ops/ms     | 1728416 ops/ms     | intrinsic |
| StrictMath.ceil  | 1189807 ops/ms     | 1197845 ops/ms     | 1193485 ops/ms   | - |
| Math.floor       | 1734748 ops/ms     | 1311019 ops/ms     | 1762023 ops/ms   | intrinsic |
| StrictMath.floor | 1311644 ops/ms     | 1312581 ops/ms     | 1304094 ops/ms  | - |

-------------

PR Comment: https://git.openjdk.org/jdk/pull/13606#issuecomment-1547919744


More information about the hotspot-dev mailing list