From fb0efbe87403fa2f1263c9b916db1a3a3b037eeb Mon Sep 17 00:00:00 2001 From: Axel Boldt-Christmas Date: Mon, 10 Mar 2025 11:53:36 +0000 Subject: [PATCH] 8333578: Fix uses of overaligned types induced by ZCACHE_ALIGNED Reviewed-by: stefank, kbarrett --- src/hotspot/share/gc/z/zArguments.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/gc/z/zArguments.cpp b/src/hotspot/share/gc/z/zArguments.cpp index ee761d03e18..f972e0718b4 100644 --- a/src/hotspot/share/gc/z/zArguments.cpp +++ b/src/hotspot/share/gc/z/zArguments.cpp @@ -21,12 +21,13 @@ * questions. */ +#include "gc/shared/gcArguments.hpp" #include "gc/z/zAddressSpaceLimit.hpp" #include "gc/z/zArguments.hpp" #include "gc/z/zCollectedHeap.hpp" #include "gc/z/zGlobals.hpp" #include "gc/z/zHeuristics.hpp" -#include "gc/shared/gcArguments.hpp" +#include "gc/z/zUtils.inline.hpp" #include "runtime/globals.hpp" #include "runtime/globals_extension.hpp" #include "runtime/java.hpp" @@ -219,7 +220,21 @@ size_t ZArguments::heap_virtual_to_physical_ratio() { } CollectedHeap* ZArguments::create_heap() { - return new ZCollectedHeap(); + // ZCollectedHeap has an alignment greater than or equal to ZCacheLineSize, + // which may be larger than std::max_align_t. Instead of using operator new, + // align the storage manually and construct the ZCollectedHeap using operator + // placement new. + + static_assert(alignof(ZCollectedHeap) >= ZCacheLineSize, + "ZCollectedHeap is no longer ZCacheLineSize aligned"); + + // Allocate aligned storage for ZCollectedHeap + const size_t alignment = alignof(ZCollectedHeap); + const size_t size = sizeof(ZCollectedHeap); + void* const addr = reinterpret_cast(ZUtils::alloc_aligned_unfreeable(alignment, size)); + + // Construct ZCollectedHeap in the aligned storage + return ::new (addr) ZCollectedHeap(); } bool ZArguments::is_supported() const {