RFR: 8376491: ZGC: crash in __memset_evex_unaligned_erms when initializing heap using high values for -XX:ConcGCThreads [v2]

Guanqiang Han ghan at openjdk.org
Mon Feb 9 21:39:24 UTC 2026


> Please review this change. Thanks!
> 
> **Description:**
> 
> This change fixes a crash during ZGC initialization when -XX:ConcGCThreads is set to an extremely large value.
> ZThreadLocalAllocBuffer::initialize() creates a ZPerWorker<ThreadLocalAllocStats>, which uses ZValueStorage::alloc to allocate per-worker storage which size is related to ConcGCThreads
> https://github.com/openjdk/jdk/blob/1161a640abe454b47de95ed73452a78535160deb/src/hotspot/share/gc/z/zThreadLocalAllocBuffer.cpp#L35-L38
> https://github.com/openjdk/jdk/blob/1161a640abe454b47de95ed73452a78535160deb/src/hotspot/share/gc/z/zValue.hpp#L111
> https://github.com/openjdk/jdk/blob/1161a640abe454b47de95ed73452a78535160deb/src/hotspot/share/gc/z/zValue.inline.hpp#L125-L127
> https://github.com/openjdk/jdk/blob/1161a640abe454b47de95ed73452a78535160deb/src/hotspot/share/gc/z/zValue.inline.hpp#L60-L61
> https://github.com/openjdk/jdk/blob/1161a640abe454b47de95ed73452a78535160deb/src/hotspot/share/gc/z/zValue.inline.hpp#L108-L110
> 
> For very large ConcGCThreads, the calculated block_size becomes huge and os::malloc() inside ZUtils::alloc_aligned_unfreeable() may fail.
> https://github.com/openjdk/jdk/blob/1161a640abe454b47de95ed73452a78535160deb/src/hotspot/share/gc/z/zUtils.inline.hpp#L37-L42
> 
> The current code does not check the returned pointer and unconditionally aligns and memset()s it, which can lead to a segmentation fault.
> 
> **Fix:**
> 
> The fix adds a NULL check after os::malloc() and terminates the VM with a proper OutOfMemoryError message instead of crashing.
> 
> **Test:**
> 
> GHA

Guanqiang Han has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:

 - Drop regression test
 - Merge remote-tracking branch 'upstream/master' into 8376491
 - fix test func
 - fix bug 8376491

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/29460/files
  - new: https://git.openjdk.org/jdk/pull/29460/files/b24d79e8..83491bb3

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=29460&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=29460&range=00-01

  Stats: 60546 lines in 952 files changed: 30259 ins; 18167 del; 12120 mod
  Patch: https://git.openjdk.org/jdk/pull/29460.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/29460/head:pull/29460

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


More information about the hotspot-gc-dev mailing list