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

JDK 11: Performance Issue When Using IntStream.forEach

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      18.04.1-Ubuntu

      A DESCRIPTION OF THE PROBLEM :
      In JDK 11 (HotSpot JDK 11.0.25), the performance of initializing a static array using `IntStream.forEach` is significantly lower compared to JDK 8 and JDK 17. Even after attempting various JIT compilation optimization options (see reproduction command), the performance remains unimproved.

      Additionally, by examining the optimization logs, I found that JDK 11 compiled `B60236::lambda$static$0` multiple times and marked it as *made not entrant*, indicating that the optimization attempts failed or encountered conflicts.

      Explanation of *made not entrant*:
      [https://stackoverflow.com/questions/2930838/java-printcompilation-output-whats-the-meaning-of-made-not-entrant-and-made](https://stackoverflow.com/questions/2930838/java-printcompilation-output-whats-the-meaning-of-made-not-entrant-and-made)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the following command:
      ```
      /root/hotspot/jdk-11.0.25/bin/javac /root/test/B60236.java
      /root/hotspot/jdk-11.0.25/bin/java B60236
      or
      /root/hotspot/jdk-11.0.25/bin/java -XX:MaxInlineSize=100 -XX:FreqInlineSize=500 B60236
      /root/hotspot/jdk-11.0.25/bin/java -XX:+TieredCompilation -XX:TieredStopAtLevel=4 B60236
      /root/hotspot/jdk-11.0.25/bin/java -XX:+Inline B60236
      ```

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The performance should remain consistent across different JDK versions (8, 11, and 17), particularly after applying optimization options.
      ACTUAL -
      root@c260e0ee214f:~/test# /root/hotspot/jdk-17.0.13/bin/java B60236
      Static block time: 0.016919661s

      root@c260e0ee214f:~/test# /root/hotspot/jdk1.8.0_431/bin/java B60236
      Static block time: 0.731349944s

      root@c260e0ee214f:~/test# /root/hotspot/jdk-11.0.25/bin/java B60236
      Static block time: 6.838753824s

      root@c260e0ee214f:~/test# /root/hotspot/jdk-11.0.25/bin/java -XX:MaxInlineSize=100 -XX:FreqInlineSize=500 B60236
      Static block time: 6.928276135s

      root@c260e0ee214f:~/test# /root/hotspot/jdk-11.0.25/bin/java -XX:+TieredCompilation -XX:TieredStopAtLevel=4 B60236
      Static block time: 6.866443708s

      root@c260e0ee214f:~/test# /root/hotspot/jdk-11.0.25/bin/java -XX:+Inline B60236
      Static block time: 6.929799162s

      ---------- BEGIN SOURCE ----------
      import java.util.stream.IntStream;

      public class B60236 {
          static final int SIZE = 1000000;
          static final float[] inputArray = new float[SIZE];
          static final float[] outputArray = new float[SIZE];

          static {
              long start = System.nanoTime();
              IntStream.range(0, SIZE).forEach(i -> inputArray[i] = (float) i);
              long end = System.nanoTime();
              System.out.println("Static block time: " + (end - start) / 1e9 + "s");
          }

          public static void main(String[] args) {
              // Empty main method; performance issue observed in static block
          }
      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: