Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8302736

Major performance regression in Math.log on aarch64

XMLWordPrintable

    • b25
    • aarch64
    • os_x

        ADDITIONAL SYSTEM INFORMATION :
        aarch64, Apple M1 Max, macOS 13.2.1

        A DESCRIPTION OF THE PROBLEM :
        Math.log using the generic dlog intrinsic is much slower than StrictMath.log on aarch64.

        Caused by JDK-8215133
        Related to JDK-8210858

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        javac Main.java
        java Main
        java -XX:+UnlockDiagnosticVMOptions -XX:DisableIntrinsic=_dlog Main

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The elapsed time without additional options is less than or equal to the time with the _dlog intrinsic disabled.
        ACTUAL -
        java Main
        6200ms

        java -XX:+UnlockDiagnosticVMOptions -XX:DisableIntrinsic=_dlog Main
        860ms

        ---------- BEGIN SOURCE ----------
        import java.util.Random;
        import java.util.concurrent.TimeUnit;

        public class Main {
            public static void main(String[] args) throws Exception {
                while (true) {
                    final Random random = new Random();
                    final double[] values = new double[100_000_000];
                    for (int i = 0; i < values.length; i++)
                        values[i] = random.nextDouble();

                    System.gc();

                    final long start = System.nanoTime();

                    double blackhole = 0;
                    for (int i = 0; i < values.length; i++)
                        blackhole += Math.log(values[i]);

                    final long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);

                    System.out.println(elapsed + "ms (" + blackhole + ")");
                }
            }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Disable the _dlog intrinsic on aarch64 like -XX:DisableIntrinsic=_dlog do and use the StrictMath implementation.

        FREQUENCY : always


          1. JMH result.png
            JMH result.png
            254 kB
          2. Main.java
            0.8 kB

              tholenstein Tobias Holenstein (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              11 Start watching this issue

                Created:
                Updated:
                Resolved: