From fef85ff932055cd5385633f3b283e6201cdcaa68 Mon Sep 17 00:00:00 2001 From: Axel Boldt-Christmas Date: Mon, 26 Jan 2026 14:13:48 +0000 Subject: [PATCH] 8374679: ZGC: Convert zForwardingAllocator to use Atomic Reviewed-by: stefank, tschatzl --- src/hotspot/share/gc/z/zForwardingAllocator.cpp | 5 +++-- src/hotspot/share/gc/z/zForwardingAllocator.hpp | 9 +++++---- src/hotspot/share/gc/z/zForwardingAllocator.inline.hpp | 7 +++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/hotspot/share/gc/z/zForwardingAllocator.cpp b/src/hotspot/share/gc/z/zForwardingAllocator.cpp index 0b4e6c7b08c..451a1d62754 100644 --- a/src/hotspot/share/gc/z/zForwardingAllocator.cpp +++ b/src/hotspot/share/gc/z/zForwardingAllocator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,6 +34,7 @@ ZForwardingAllocator::~ZForwardingAllocator() { } void ZForwardingAllocator::reset(size_t size) { - _start = _top = REALLOC_C_HEAP_ARRAY(char, _start, size, mtGC); + _start = REALLOC_C_HEAP_ARRAY(char, _start, size, mtGC); + _top.store_relaxed(_start); _end = _start + size; } diff --git a/src/hotspot/share/gc/z/zForwardingAllocator.hpp b/src/hotspot/share/gc/z/zForwardingAllocator.hpp index 8424fe6cd70..62d84885692 100644 --- a/src/hotspot/share/gc/z/zForwardingAllocator.hpp +++ b/src/hotspot/share/gc/z/zForwardingAllocator.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,13 +24,14 @@ #ifndef SHARE_GC_Z_ZFORWARDINGALLOCATOR_HPP #define SHARE_GC_Z_ZFORWARDINGALLOCATOR_HPP +#include "runtime/atomic.hpp" #include "utilities/globalDefinitions.hpp" class ZForwardingAllocator { private: - char* _start; - char* _end; - char* _top; + char* _start; + char* _end; + Atomic _top; public: ZForwardingAllocator(); diff --git a/src/hotspot/share/gc/z/zForwardingAllocator.inline.hpp b/src/hotspot/share/gc/z/zForwardingAllocator.inline.hpp index dc71507175c..c8811c84ede 100644 --- a/src/hotspot/share/gc/z/zForwardingAllocator.inline.hpp +++ b/src/hotspot/share/gc/z/zForwardingAllocator.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,7 +26,6 @@ #include "gc/z/zForwardingAllocator.hpp" -#include "runtime/atomicAccess.hpp" #include "utilities/debug.hpp" inline size_t ZForwardingAllocator::size() const { @@ -34,11 +33,11 @@ inline size_t ZForwardingAllocator::size() const { } inline bool ZForwardingAllocator::is_full() const { - return _top == _end; + return _top.load_relaxed() == _end; } inline void* ZForwardingAllocator::alloc(size_t size) { - char* const addr = AtomicAccess::fetch_then_add(&_top, size); + char* const addr = _top.fetch_then_add(size); assert(addr + size <= _end, "Allocation should never fail"); return addr; }