From 6fda44172e955d4e1d181598a97902ed5b16c57b Mon Sep 17 00:00:00 2001 From: Axel Boldt-Christmas Date: Tue, 27 Jan 2026 08:42:44 +0000 Subject: [PATCH] 8374690: ZGC: Convert zRelocate to use Atomic Reviewed-by: stefank, tschatzl --- src/hotspot/share/gc/z/zRelocate.cpp | 26 +++++++++++++------------- src/hotspot/share/gc/z/zRelocate.hpp | 7 ++++--- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/hotspot/share/gc/z/zRelocate.cpp b/src/hotspot/share/gc/z/zRelocate.cpp index da07f67d859..d51cf5abbae 100644 --- a/src/hotspot/share/gc/z/zRelocate.cpp +++ b/src/hotspot/share/gc/z/zRelocate.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -64,31 +64,31 @@ ZRelocateQueue::ZRelocateQueue() _needs_attention(0) {} bool ZRelocateQueue::needs_attention() const { - return AtomicAccess::load(&_needs_attention) != 0; + return _needs_attention.load_relaxed() != 0; } void ZRelocateQueue::inc_needs_attention() { - const int needs_attention = AtomicAccess::add(&_needs_attention, 1); + const int needs_attention = _needs_attention.add_then_fetch(1); assert(needs_attention == 1 || needs_attention == 2, "Invalid state"); } void ZRelocateQueue::dec_needs_attention() { - const int needs_attention = AtomicAccess::sub(&_needs_attention, 1); + const int needs_attention = _needs_attention.sub_then_fetch(1); assert(needs_attention == 0 || needs_attention == 1, "Invalid state"); } void ZRelocateQueue::activate(uint nworkers) { - _is_active = true; + _is_active.store_relaxed(true); join(nworkers); } void ZRelocateQueue::deactivate() { - AtomicAccess::store(&_is_active, false); + _is_active.store_relaxed(false); clear(); } bool ZRelocateQueue::is_active() const { - return AtomicAccess::load(&_is_active); + return _is_active.load_relaxed(); } void ZRelocateQueue::join(uint nworkers) { @@ -453,7 +453,7 @@ static void retire_target_page(ZGeneration* generation, ZPage* page) { class ZRelocateSmallAllocator { private: ZGeneration* const _generation; - volatile size_t _in_place_count; + Atomic _in_place_count; public: ZRelocateSmallAllocator(ZGeneration* generation) @@ -463,7 +463,7 @@ public: ZPage* alloc_and_retire_target_page(ZForwarding* forwarding, ZPage* target) { ZPage* const page = alloc_page(forwarding); if (page == nullptr) { - AtomicAccess::inc(&_in_place_count); + _in_place_count.add_then_fetch(1u); } if (target != nullptr) { @@ -493,7 +493,7 @@ public: } size_t in_place_count() const { - return _in_place_count; + return _in_place_count.load_relaxed(); } }; @@ -503,7 +503,7 @@ private: ZConditionLock _lock; ZRelocationTargets* _shared_targets; bool _in_place; - volatile size_t _in_place_count; + Atomic _in_place_count; public: ZRelocateMediumAllocator(ZGeneration* generation, ZRelocationTargets* shared_targets) @@ -539,7 +539,7 @@ public: ZPage* const to_page = alloc_page(forwarding); _shared_targets->set(partition_id, to_age, to_page); if (to_page == nullptr) { - AtomicAccess::inc(&_in_place_count); + _in_place_count.add_then_fetch(1u); _in_place = true; } @@ -579,7 +579,7 @@ public: } size_t in_place_count() const { - return _in_place_count; + return _in_place_count.load_relaxed(); } }; diff --git a/src/hotspot/share/gc/z/zRelocate.hpp b/src/hotspot/share/gc/z/zRelocate.hpp index 038efba83eb..d25536e1bce 100644 --- a/src/hotspot/share/gc/z/zRelocate.hpp +++ b/src/hotspot/share/gc/z/zRelocate.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -28,6 +28,7 @@ #include "gc/z/zPageAge.hpp" #include "gc/z/zRelocationSet.hpp" #include "gc/z/zValue.hpp" +#include "runtime/atomic.hpp" class ZForwarding; class ZGeneration; @@ -42,8 +43,8 @@ private: uint _nworkers; uint _nsynchronized; bool _synchronize; - volatile bool _is_active; - volatile int _needs_attention; + Atomic _is_active; + Atomic _needs_attention; bool needs_attention() const; void inc_needs_attention();