RFR: 8371944: AOT configuration is corrupted when app closes System.out

Ioi Lam iklam at openjdk.org
Sat Nov 15 04:57:38 UTC 2025


During an AOT training run, some application may close `System.out` (usually inadvertently by naive code like the following):


try (var err = new PrintWriter(System.err);
      var out = new PrintWriter(System.out)) {
     out.println("Hello Confused World");
}


This has the side effect of closing the JVM's STDOUT.

When the JVM is about to exit, we will open the AOT configuration file for writing. On Windows we may get back a file HANDLE (which is just an integer) that's identical to the now closed STDOUT.

If the JVM writes to STDOUT (usually with UL logging), it will corrupt the contents of the AOT configuration file.

This doesn't happen on Posix as `System.out.close()` will keep file descriptions 1 and 2 open, preventing them from being reused by files that are opened in the future.

The fix is to open the AOT configuration file early, before any application code is executed. That way we can guarantee that we will have a file HANDLE (or file descriptor) that's different than STDOUT.

The test failed failed about 20% of the time on Windows before the fix. After the fix, it ran 100 times without failure.

-------------

Commit messages:
 - 8371944: AOT configuration is corrupted when app closes System.out

Changes: https://git.openjdk.org/jdk/pull/28335/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28335&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8371944
  Stats: 130 lines in 6 files changed: 117 ins; 9 del; 4 mod
  Patch: https://git.openjdk.org/jdk/pull/28335.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/28335/head:pull/28335

PR: https://git.openjdk.org/jdk/pull/28335


More information about the hotspot-runtime-dev mailing list