RFR: 8267517: async logging for stdout and stderr

Xin Liu xliu at openjdk.java.net
Tue Dec 7 02:59:41 UTC 2021


This patch refactors LogFileStreamOutput so stdout/stderr can support support -Xlog:async.
LogFileStreamOutput::flush() is virtual. 

With  `-Xlog:all=trace:stdout`, the helloworld in Java outputs 16520 log entries to stdout.  We are see that the wall time reduces from  86.977ms to 72.436ms, or the throughput increases 20% because of async logging.


$perf stat -r 300 ./build/linux-x86_64-server-release/images/jdk/bin/java -Xlog:all=trace:stdout -Xlog:async -XX:AsyncLogBufferSize=48M HelloWorld > /dev/null

 Performance counter stats for './build/linux-x86_64-server-release/images/jdk/bin/java -Xlog:all=trace:stdout -Xlog:async -XX:AsyncLogBufferSize=48M HelloWorld' (300 runs):

            112.59 msec task-clock                #    1.554 CPUs utilized            ( +-  0.15% )
             1,517      context-switches          #    0.013 M/sec                    ( +-  0.61% )
                 1      cpu-migrations            #    0.010 K/sec                    ( +-  4.80% )
             4,014      page-faults               #    0.036 M/sec                    ( +-  0.01% )
...
          0.072436 +- 0.000135 seconds time elapsed  ( +-  0.19% )

 Performance counter stats for 'java -Xlog:all=trace:stdout  HelloWorld' (300 runs):

             90.73 msec task-clock                #    1.043 CPUs utilized            ( +-  0.11% )
               318      context-switches          #    0.004 M/sec                    ( +-  0.32% )
                 1      cpu-migrations            #    0.009 K/sec                    ( +-  4.80% )
             4,010      page-faults               #    0.044 M/sec                    ( +-  0.00% )
...
         0.0869777 +- 0.0000979 seconds time elapsed  ( +-  0.11% )


In this patch, we also fold two locks(RotationLocker and FileLock) of LogFileOutput into one. FileLocker now can protect _stream from multiplexing and log rotation.  The other change is that AsyncLog writing doesn't require any lock protection because it's single-threaded. 

Add a new jtreg to cover a scenario that the blocked stdout doesn't freeze the JVM application.

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

Commit messages:
 - Remove the unused semaphore in LogFileOutput.
 - Merge branch 'master' into JDK-8267517
 - Fixed the regression test.
 - Fix the deadlock issue on single core.
 - Update the jtreg test.
 - Merge branch 'master' into JDK-8267517
 - Add a jtreg test to demonstrate -Xlog:async can prevent JVM from blocking
 - _locking_thread_id should be a member data of LogFileStreamOutput.
 - Make FileLocker an inner class of LogFileStreamOutput.
 - make LogFileStreamOutput::flush() virtual.
 - ... and 1 more: https://git.openjdk.java.net/jdk/compare/ea8d3c92...45e15916

Changes: https://git.openjdk.java.net/jdk/pull/6132/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=6132&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8267517
  Stats: 416 lines in 9 files changed: 285 ins; 79 del; 52 mod
  Patch: https://git.openjdk.java.net/jdk/pull/6132.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/6132/head:pull/6132

PR: https://git.openjdk.java.net/jdk/pull/6132


More information about the hotspot-runtime-dev mailing list