8333578: Fix uses of overaligned types induced by ZCACHE_ALIGNED

Reviewed-by: stefank, kbarrett
This commit is contained in:
Axel Boldt-Christmas 2025-03-10 11:53:36 +00:00
parent 99547c5b25
commit fb0efbe874

View File

@ -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<void*>(ZUtils::alloc_aligned_unfreeable(alignment, size));
// Construct ZCollectedHeap in the aligned storage
return ::new (addr) ZCollectedHeap();
}
bool ZArguments::is_supported() const {