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

Enabling AOT cache slows down very short applications

XMLWordPrintable

      We are chasing a curious regression in JDK 25 AOT mode, which manifests as Java application running a little bit (5..10ms) slower with AOT cache enabled, when we actually start running the code. The *startup* is tremendously (hundreds of ms) faster, so it hides the regression in end-to-end tests.

      But if you start measuring time from *within* the workload, it shows curious result:

      $ cat HelloStream.java

      import java.util.*;
      import java.util.stream.*;

      public class HelloStream {
          public static void main(String ... args) {
              long time1 = System.nanoTime();
              var words = List.of("hello", "fuzzy", "world");
              var greeting = words.stream()
                  .filter(w -> !w.contains("z"))
                  .collect(Collectors.joining(", "));
              long time2 = System.nanoTime();
              String msg = greeting + " (" + (time2 - time1)/1000 + " us)";
              System.out.println(msg);
          }
      }

      $ build/linux-x86_64-server-release/images/jdk/bin/java -XX:AOTCacheOutput=aot.app -Xms128m -Xmx128m HelloStream.java

      hello, world (416 us)
      Temporary AOTConfiguration recorded: aot.app.config
      Launching child process /home/shade/trunks/jdk/build/linux-x86_64-server-release/images/jdk/bin/java to assemble AOT cache aot.app using configuration aot.app.config
      Picked up JAVA_TOOL_OPTIONS: -Xms128m -Xmx128m --add-modules=ALL-DEFAULT -XX:AOTCacheOutput=aot.app -XX:AOTConfiguration=aot.app.config -XX:AOTMode=create
      Reading AOTConfiguration aot.app.config and writing AOTCache aot.app
      AOTCache creation is complete: aot.app 25800704 bytes
      Removed temporary AOT configuration file aot.app.config


      # ---- Interpreter

      $ for I in `seq 1 10`; do taskset -c 0 build/linux-x86_64-server-release/images/jdk/bin/java -XX:AOTCache=aot.app -Xint -Xms128m -Xmx128m HelloStream.java; done
      hello, world (777 us)
      hello, world (741 us)
      hello, world (781 us)
      hello, world (756 us)
      hello, world (759 us)
      hello, world (752 us)
      hello, world (775 us)
      hello, world (765 us)
      hello, world (753 us)
      hello, world (774 us)

      $ for I in `seq 1 10`; do taskset -c 0 build/linux-x86_64-server-release/images/jdk/bin/java -Xint -Xms128m -Xmx128m HelloStream.java; done
      hello, world (645 us)
      hello, world (638 us)
      hello, world (641 us)
      hello, world (651 us)
      hello, world (638 us)
      hello, world (635 us)
      hello, world (648 us)
      hello, world (632 us)
      hello, world (641 us)
      hello, world (649 us)


      # ---- C1 only

      $ for I in `seq 1 10`; do taskset -c 0 build/linux-x86_64-server-release/images/jdk/bin/java -XX:TieredStopAtLevel=1 -Xms128m -Xmx128m HelloStream.java; done
      hello, world (281 us)
      hello, world (301 us)
      hello, world (302 us)
      hello, world (305 us)
      hello, world (304 us)
      hello, world (308 us)
      hello, world (286 us)
      hello, world (294 us)
      hello, world (327 us)
      hello, world (303 us)

      $ for I in `seq 1 10`; do taskset -c 0 build/linux-x86_64-server-release/images/jdk/bin/java -XX:AOTCache=aot.app -XX:TieredStopAtLevel=1 -Xms128m -Xmx128m HelloStream.java; done
      hello, world (3662 us)
      hello, world (4327 us)
      hello, world (4539 us)
      hello, world (3714 us)
      hello, world (4487 us)
      hello, world (4488 us)
      hello, world (538 us)
      hello, world (3837 us)
      hello, world (3737 us)
      hello, world (4048 us)

      # ---- Out of the box

      $ for I in `seq 1 10`; do taskset -c 0 build/linux-x86_64-server-release/images/jdk/bin/java -Xms128m -Xmx128m HelloStream.java; done
      hello, world (375 us)
      hello, world (387 us)
      hello, world (409 us)
      hello, world (376 us)
      hello, world (388 us)
      hello, world (394 us)
      hello, world (387 us)
      hello, world (373 us)
      hello, world (420 us)
      hello, world (373 us)

      $ for I in `seq 1 10`; do taskset -c 0 build/linux-x86_64-server-release/images/jdk/bin/java -XX:AOTCache=aot.app -Xms128m -Xmx128m HelloStream.java; done
      hello, world (4084 us)
      hello, world (4074 us)
      hello, world (586 us)
      hello, world (4176 us)
      hello, world (4540 us)
      hello, world (4137 us)
      hello, world (3671 us)
      hello, world (590 us)
      hello, world (544 us)
      hello, world (7160 us)

            shade Aleksey Shipilev
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: