8374677: ZGC: Convert zArray to use Atomic<T>

Reviewed-by: stefank, tschatzl
This commit is contained in:
Axel Boldt-Christmas 2026-01-26 13:44:06 +00:00
parent 37cb22826a
commit 319e21e9b4
2 changed files with 8 additions and 7 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,7 @@
#include "cppstdlib/type_traits.hpp" #include "cppstdlib/type_traits.hpp"
#include "memory/allocation.hpp" #include "memory/allocation.hpp"
#include "runtime/atomicAccess.hpp" #include "runtime/atomic.hpp"
#include "runtime/os.hpp" #include "runtime/os.hpp"
#include "runtime/thread.hpp" #include "runtime/thread.hpp"
#include "utilities/growableArray.hpp" #include "utilities/growableArray.hpp"
@ -78,7 +78,9 @@ public:
template <typename T, bool Parallel> template <typename T, bool Parallel>
class ZArrayIteratorImpl : public StackObj { class ZArrayIteratorImpl : public StackObj {
private: private:
size_t _next; using NextType = std::conditional_t<Parallel, Atomic<size_t>, size_t>;
NextType _next;
const size_t _end; const size_t _end;
const T* const _array; const T* const _array;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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/zArray.hpp"
#include "gc/z/zLock.inline.hpp" #include "gc/z/zLock.inline.hpp"
#include "runtime/atomicAccess.hpp"
template <typename T> template <typename T>
ZArraySlice<T>::ZArraySlice(T* data, int len) ZArraySlice<T>::ZArraySlice(T* data, int len)
@ -130,7 +129,7 @@ inline bool ZArrayIteratorImpl<T, Parallel>::next_serial(size_t* index) {
template <typename T, bool Parallel> template <typename T, bool Parallel>
inline bool ZArrayIteratorImpl<T, Parallel>::next_parallel(size_t* index) { inline bool ZArrayIteratorImpl<T, Parallel>::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) { if (claimed_index < _end) {
*index = claimed_index; *index = claimed_index;
@ -177,7 +176,7 @@ inline bool ZArrayIteratorImpl<T, Parallel>::next_if(T* elem, Function predicate
template <typename T, bool Parallel> template <typename T, bool Parallel>
inline bool ZArrayIteratorImpl<T, Parallel>::next_index(size_t* index) { inline bool ZArrayIteratorImpl<T, Parallel>::next_index(size_t* index) {
if (Parallel) { if constexpr (Parallel) {
return next_parallel(index); return next_parallel(index);
} else { } else {
return next_serial(index); return next_serial(index);