RFR: 8333578: Fix uses of overaligned types induced by ZCACHE_ALIGNED

Stefan Karlsson stefank at openjdk.org
Thu Mar 6 15:33:59 UTC 2025


On Tue, 4 Mar 2025 07:49:23 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:

> The only directly heap allocated, constructed object of types that are overaligned because of ZCACHE_ALIGNED is ZCollectedHeap. The other are either in static storage or contained in (and constructed as part of) ZCollectedHeap. So we only need to fix ZCollectedHeap allocation. 
> 
> As the CollectedHeap is only ever created once and is never destroyed, we can simply align the allocation and create an unfreeable pointer.
> 
> This implementation imposes that `ZCacheLineSize` is a power of two, but we already have this requirement elsewhere (e.g. `ZContendedStorage`).
> 
> Testing:
>  * tier 1 through tier 5 Oracle supported platforms
>  * GHA

Marked as reviewed by stefank (Reviewer).

src/hotspot/share/gc/z/zArguments.cpp line 223:

> 221: 
> 222: CollectedHeap* ZArguments::create_heap() {
> 223:   // ZCollectedHeap has an alignment >= ZCacheLineSize, which may be larger than

The `ZCollectedHeap has an alignment >= ZCacheLineSize,` had me reading the sentence a couple of times. I think it would be easier to read if this used words instead of >=.

src/hotspot/share/gc/z/zArguments.cpp line 225:

> 223:   // ZCollectedHeap has an alignment >= ZCacheLineSize, which may be larger than
> 224:   // std::max_align_t. Instead of using operator new, align the storage manually
> 225:   // and construct the ZCollectedHeap using operator placement new

Suggestion:

  // and construct the ZCollectedHeap using operator placement new.

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

PR Review: https://git.openjdk.org/jdk/pull/23885#pullrequestreview-2664809137
PR Review Comment: https://git.openjdk.org/jdk/pull/23885#discussion_r1983571395
PR Review Comment: https://git.openjdk.org/jdk/pull/23885#discussion_r1983568901


More information about the hotspot-gc-dev mailing list