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

Closed System.out/err causes hanging with -XX:AOTCacheOutput

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • 26
    • 25, 26
    • hotspot

      Note: The underlying cause is in core libs (JDK-8366736). If that cannot be easily fixed, we might try to implement a work-around in this bug (JDK-8366731).
      =========
      With a program like this:

      import java.io.*;
      public class PrintWriterTest {
          public static void main(String args[]) throws Throwable {
              System.out.println("Before");

              try (var log = new PrintWriter(System.err);
                   var ref = new PrintWriter(System.out)) {
                System.err.println("Middle with System.err");
                for (int i = 0; i < 1; i++) {
                  log.println("Middle with log");
                }
              }

              System.out.println("Done");
          }
      }


      $ java.exe -cp app.jar -XX:AOTCacheOutput=app.aot PrintWriterTest
      Before
      Middle with System.err

      Program finishes, but not that "Done" is not printed, because System.out has been closed

      $ java.exe -cp app.jar -XX:AOTCacheOutput=app.aot -Xlog:aot PrintWriterTest
      [0.003s][info][aot] Selected AOTMode=record because AOTCacheOutput is specified
      [0.020s][info][aot] Core region alignment: 65536
      Before
      Middle with System.err

      Program gets stuck here, because child process cannot write its output and gets stuck, causing the process to wait here forever.

      "main" #3 [43936] prio=5 os_prio=0 cpu=546.88ms elapsed=21.23s tid=0x000001fd23fbb550 nid=43936 runnable [0x00000061f29fd000]
         java.lang.Thread.State: RUNNABLE
      Thread: 0x000001fd23fbb550 [0xaba0] State: _at_safepoint _at_poll_safepoint 0
         JavaThread state: _thread_in_native
              at java.lang.ProcessImpl.waitForInterruptibly(java.base@26-internal/Native Method)
              at java.lang.ProcessImpl.waitFor(java.base@26-internal/ProcessImpl.java:555)
              at jdk.internal.misc.CDS$ProcessLauncher.execWithJavaToolOptions(java.base@26-internal/CDS.java:549)
              at java.lang.Shutdown.halt0(java.base@26-internal/Native Method)
              at java.lang.Shutdown.halt(java.base@26-internal/Shutdown.java:149)
              - locked <0x00000006408e2758> (a java.lang.Shutdown$Lock)
              at java.lang.Shutdown.exit(java.base@26-internal/Shutdown.java:168)
              - locked <0x00000006408e2538> (a java.lang.Class for java.lang.Shutdown)
              at java.lang.Runtime.exit(java.base@26-internal/Runtime.java:177)
              at java.lang.System.exit(java.base@26-internal/System.java:1540)
              at javasoft.sqe.javatest.Status.exit(Status.java:235)
              at javasoft.sqe.tests.api.java.lang.ThreadGroup.toString.toString0101.toString0101.main(toString0101.java:40)


      =============
      Impact:
      This happens more often on Windows, but it could affect other platforms as well, if the amount of logging exceeds the OS's buffer for child process output.

      =============
      Work around:
      [1] Do not close System.err/out in your program if you want to use -XX:AOTCacheOutput.

      or

      [2] Use the two step AOT workflow -XX:AOTMode=record, and then AOTMode=create , in separate processes.


            iklam Ioi Lam
            iklam Ioi Lam
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated: