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

Does jdk11 JIT have any problems when handling arithmetic operations?

XMLWordPrintable

    • x86_64
    • linux_ubuntu

      A DESCRIPTION OF THE PROBLEM :
      When I executed the following code using three different versions of jdk, I found obvious time differences. Analyzing the code, I believe that the JIT's handling of the performIntensiveCalculations() method's call to complexCalculation() is the cause of the performance difference.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      time /root/jvm_debug/openjdk/hotspot-jdk8u352/build/linux-x86_64-normal-server-fastdebug/jdk/bin/java B
      6525276770152
      216070688

      real 0m1.240s
      user 0m0.591s
      sys 0m0.616s

      time /root/jvm_debug/openjdk/hotspot-jdk-21.0.2/build/linux-x86_64-server-fastdebug/jdk/bin/java B
      6525276770152
      457029457

      real 0m2.640s
      user 0m9.747s
      sys 0m0.194s
      ACTUAL -
      /root/jvm_debug/openjdk/hotspot-jdk-11.0.15/build/linux-x86_64-normal-server-fastdebug/jdk/bin/java B
      6525276770152
      314471934

      real 0m19.329s
      user 2m20.893s
      sys 0m0.686s

      ---------- BEGIN SOURCE ----------
      public class B {
          public static void main(String[] args) {
              long startTime = System.nanoTime();

              long result = performIntensiveCalculations();

              long endTime = System.nanoTime();
              System.out.println("" + result);
              System.out.println("" + (endTime - startTime) + " ");
          }

          private static long performIntensiveCalculations() {
              long sum = 0;
              for (int i = 1; i <= 100000000; i++) {
                  sum += complexCalculation(i);
              }
              return sum;
          }

          private static int complexCalculation(int x) {
              int y = x * 33;
              y = y ^ (y << 10);
              y += y >> 3;
              y ^= (y << 4);
              y *= 7;
              y = y ^ (y << 9);
              y += y >> 2;
              y ^= (y << 5);
              y *= 3;
              return y;
          }
      }
      ---------- END SOURCE ----------

            mcadizolivar Mario Cadiz Olivares
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: