RFR: 8292989: Avoid dynamic memory in AsyncLogWriter [v6]

Xin Liu xliu at openjdk.org
Sun Sep 11 01:22:46 UTC 2022


> Current implementation of AsyncLogWriter uses dynamic memory. There are 2 sources. 
> 
> 1. Overhead of pointer-based linked-list. 
> 2. strdup of message contents
> 
> This implementation has impact on glibc/malloc. If allocation of logsites interleave with other allocation, it's hard to clean up all glibc arenas. This worsens fragmentation issue.
> 
> In this PR, we replace linked-list with `2 pre-allocated raw buffers`. AsyncLogWriter appends payload AsyncLogMessage to the serving buffer and avoids all dynamic allocation. Please note this effort won't eliminate mutex lock. We use ping-pong buffers to guarantee AsyncLogWriter is still non-blocking. A buffer serves as a FIFO queue like before. 
> 
> In addition, AsyncLogWriter doesn't enqueue meta messages anymore when it needs to report the number of discarded messages. This is archived using a temporary hashtable called `snapshot`. It copies the working hashtable with the protection of lock and reset it. After writing all regular messages, AsyncLogWriter writes meta messages from snapshot.

Xin Liu has updated the pull request incrementally with one additional commit since the last revision:

  fixed for MSVC: error C2131: expression did not evaluate to a constant
  
  MSVC doesn't use C99.

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/10092/files
  - new: https://git.openjdk.org/jdk/pull/10092/files/06a0904a..6b16302f

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=10092&range=05
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=10092&range=04-05

  Stats: 3 lines in 1 file changed: 2 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/10092.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/10092/head:pull/10092

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


More information about the hotspot-runtime-dev mailing list