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

Hotspot deoptimizes div/mod pair usage

XMLWordPrintable

    • b137
    • generic
    • generic

      FULL PRODUCT VERSION :
      jdk8 u66, jdk9 u108

      FULL OS VERSION :
      openSuse 42.1 - 64bit
      kernel 4.1.15-8-default

      A DESCRIPTION OF THE PROBLEM :
      I wanted to try, if hotspot can optimize pair of divide / modulo with same arguments to one instruction.
      I made little program, and found strange behaviour. If it counts div only (comment mod line), it runs with constant speed.

      0 3741 1197102800
      1 3506 1197102800
      2 3512 1197102800
      3 3503 1197102800
      4 3498 1197102800
      .....

      If it counts div/mod pair, it starts as fast as previous case, but it slows down after few iterations.

      0 3687 -1176719460
      1 3509 -1176719460
      2 7020 -1176719460
      3 7022 -1176719460
      4 7021 -1176719460
      ...

      Sometimes speed changes more times, it prints something like

      0 fast
      1 fast
      2 slow
      3 fast
      4 fast
      5 slow
      .. slow

      THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run given microbenchmark (i know, it is not best microbenchmark:)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public final class Test {
      public static void main(final String[] args) {
      new Test().test();
      }

      private void test() {
      for (int i = 0; i < 100000; i++) {
      long ts = System.nanoTime();
      int sum = aaa();
      System.out.println(i + "\t" + ((System.nanoTime() - ts) / 1000000) + "\t" + sum);
      }
      }

      private int aaa() {
      int sum = 0;
      for (int i = 1; i < 100000; i++){
      for (int j = 1; j < 10000; j++){
      int d = i / j;
      int m = i % j;
      sum += d;
      sum += m;
      }
      }
      return sum;
      }
      }
      ---------- END SOURCE ----------

            vdeshpande Vivek Deshpande (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: