From 319e21e9b48b4a9646c803e23d16f0b7df827d3f Mon Sep 17 00:00:00 2001 From: Axel Boldt-Christmas Date: Mon, 26 Jan 2026 13:44:06 +0000 Subject: [PATCH] 8374677: ZGC: Convert zArray to use Atomic Reviewed-by: stefank, tschatzl --- src/hotspot/share/gc/z/zArray.hpp | 8 +++++--- src/hotspot/share/gc/z/zArray.inline.hpp | 7 +++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hotspot/share/gc/z/zArray.hpp b/src/hotspot/share/gc/z/zArray.hpp index 2c2f8a5dbfb..d39def4096e 100644 --- a/src/hotspot/share/gc/z/zArray.hpp +++ b/src/hotspot/share/gc/z/zArray.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 @@ -26,7 +26,7 @@ #include "cppstdlib/type_traits.hpp" #include "memory/allocation.hpp" -#include "runtime/atomicAccess.hpp" +#include "runtime/atomic.hpp" #include "runtime/os.hpp" #include "runtime/thread.hpp" #include "utilities/growableArray.hpp" @@ -78,7 +78,9 @@ public: template class ZArrayIteratorImpl : public StackObj { private: - size_t _next; + using NextType = std::conditional_t, size_t>; + + NextType _next; const size_t _end; const T* const _array; diff --git a/src/hotspot/share/gc/z/zArray.inline.hpp b/src/hotspot/share/gc/z/zArray.inline.hpp index 9e2bc19118e..15caa54ebab 100644 --- a/src/hotspot/share/gc/z/zArray.inline.hpp +++ b/src/hotspot/share/gc/z/zArray.inline.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 @@ -27,7 +27,6 @@ #include "gc/z/zArray.hpp" #include "gc/z/zLock.inline.hpp" -#include "runtime/atomicAccess.hpp" template ZArraySlice::ZArraySlice(T* data, int len) @@ -130,7 +129,7 @@ inline bool ZArrayIteratorImpl::next_serial(size_t* index) { template inline bool ZArrayIteratorImpl::next_parallel(size_t* index) { - const size_t claimed_index = AtomicAccess::fetch_then_add(&_next, 1u, memory_order_relaxed); + const size_t claimed_index = _next.fetch_then_add(1u, memory_order_relaxed); if (claimed_index < _end) { *index = claimed_index; @@ -177,7 +176,7 @@ inline bool ZArrayIteratorImpl::next_if(T* elem, Function predicate template inline bool ZArrayIteratorImpl::next_index(size_t* index) { - if (Parallel) { + if constexpr (Parallel) { return next_parallel(index); } else { return next_serial(index);