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

Lambda deduplication does not work when debugging info is generated

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 11.0.20, 17.0.8, 21, 22
    • tools
    • None
    • 18

      Create the following source file:

      import java.util.function.IntSupplier;
      import java.util.stream.IntStream;

      class Test {
      private int compute() {
      IntSupplier s1 = () -> IntStream.range(0, 10000).map(v -> 1).sum();
      IntSupplier s2 = () -> IntStream.range(0, 10000).map(v -> 1).sum();
      IntSupplier s3 = () -> IntStream.range(0, 10000).map(v -> 1).sum();
      return s1.getAsInt() + s2.getAsInt() + s3.getAsInt();
      }
      }

      Compile it with using openjdk 17.0.1 2021-10-19, without debug info:

      $ javac Test.java

      Then observe that lambdas were deduplicated using javap -p:

      $ javap -p Test.class
      Compiled from "Test.java"
      class Test {
        Test();
        private int compute();
        private static int lambda$compute$1();
        private static int lambda$compute$0(int);
      }

      There are only two lambda bodies, despite we have six in the source code. This is expected behavior (see JDK-8200301).

      Do the same with java 18 or later (java 22 is also affected). Now, the lambdas are not deduplicated:

      $ javap -p Test.class
      Compiled from "Test.java"
      class Test {
        Test();
        private int compute();
        private static int lambda$compute$5();
        private static int lambda$compute$4(int);
        private static int lambda$compute$3();
        private static int lambda$compute$2(int);
        private static int lambda$compute$1();
        private static int lambda$compute$0(int);
      }

      This is an unexpected regression.

            Unassigned Unassigned
            tvaleev Tagir Valeev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: