From 8c4d27381cd06511e8efc572fffa02cf8a98c75b Mon Sep 17 00:00:00 2001 From: Kim Barrett Date: Fri, 13 Mar 2026 08:05:20 +0000 Subject: [PATCH] 8379273: Convert miscellaneous utilities to use Atomic Reviewed-by: dholmes, fbredberg --- src/hotspot/share/utilities/filterQueue.hpp | 8 ++++---- src/hotspot/share/utilities/filterQueue.inline.hpp | 6 +++--- src/hotspot/share/utilities/tableStatistics.cpp | 11 +++++------ src/hotspot/share/utilities/tableStatistics.hpp | 7 ++++--- src/hotspot/share/utilities/zipLibrary.cpp | 9 +++++---- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/hotspot/share/utilities/filterQueue.hpp b/src/hotspot/share/utilities/filterQueue.hpp index 141c40f09c8..ea47f07b7b8 100644 --- a/src/hotspot/share/utilities/filterQueue.hpp +++ b/src/hotspot/share/utilities/filterQueue.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,7 @@ #define SHARE_UTILITIES_FILTERQUEUE_HPP #include "memory/allocation.hpp" -#include "runtime/atomicAccess.hpp" +#include "runtime/atomic.hpp" // The FilterQueue is FIFO with the ability to skip over queued items. // The skipping is controlled by using a filter when popping. @@ -42,9 +42,9 @@ class FilterQueue { E _data; }; - Node* _first; + Atomic _first; Node* load_first() { - return AtomicAccess::load_acquire(&_first); + return _first.load_acquire(); } static bool match_all(E d) { return true; } diff --git a/src/hotspot/share/utilities/filterQueue.inline.hpp b/src/hotspot/share/utilities/filterQueue.inline.hpp index 18b40b81c6c..7fa1bc94b7b 100644 --- a/src/hotspot/share/utilities/filterQueue.inline.hpp +++ b/src/hotspot/share/utilities/filterQueue.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 @@ -37,7 +37,7 @@ void FilterQueue::push(E data) { while (true){ head = load_first(); insnode->_next = head; - if (AtomicAccess::cmpxchg(&_first, head, insnode) == head) { + if (_first.compare_set(head, insnode)) { break; } yield.wait(); @@ -91,7 +91,7 @@ E FilterQueue::pop(MATCH_FUNC& match_func) { if (match_prev == nullptr) { // Working on first - if (AtomicAccess::cmpxchg(&_first, match, match->_next) == match) { + if (_first.compare_set(match, match->_next)) { E ret = match->_data; delete match; return ret; diff --git a/src/hotspot/share/utilities/tableStatistics.cpp b/src/hotspot/share/utilities/tableStatistics.cpp index 331652becd5..34d0969969a 100644 --- a/src/hotspot/share/utilities/tableStatistics.cpp +++ b/src/hotspot/share/utilities/tableStatistics.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 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 @@ -22,7 +22,6 @@ * */ -#include "runtime/atomicAccess.hpp" #include "runtime/os.hpp" #include "utilities/debug.hpp" #include "utilities/macros.hpp" @@ -42,7 +41,7 @@ TableRateStatistics::~TableRateStatistics() { }; void TableRateStatistics::add() { #if INCLUDE_JFR if (Jfr::is_recording()) { - AtomicAccess::inc(&_added_items); + _added_items.add_then_fetch(1u); } #endif } @@ -50,7 +49,7 @@ void TableRateStatistics::add() { void TableRateStatistics::remove() { #if INCLUDE_JFR if (Jfr::is_recording()) { - AtomicAccess::inc(&_removed_items); + _removed_items.add_then_fetch(1u); } #endif } @@ -61,8 +60,8 @@ void TableRateStatistics::stamp() { _added_items_stamp_prev = _added_items_stamp; _removed_items_stamp_prev = _removed_items_stamp; - _added_items_stamp = _added_items; - _removed_items_stamp = _removed_items; + _added_items_stamp = _added_items.load_relaxed(); + _removed_items_stamp = _removed_items.load_relaxed(); if (_time_stamp == 0) { _time_stamp = now - 1000000000; diff --git a/src/hotspot/share/utilities/tableStatistics.hpp b/src/hotspot/share/utilities/tableStatistics.hpp index d4fd3302922..95856114833 100644 --- a/src/hotspot/share/utilities/tableStatistics.hpp +++ b/src/hotspot/share/utilities/tableStatistics.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 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,6 +26,7 @@ #define SHARE_UTILITIES_TABLE_STATISTICS_HPP #include "memory/allocation.hpp" +#include "runtime/atomic.hpp" #include "utilities/debug.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/numberSeq.hpp" @@ -35,8 +36,8 @@ class TableRateStatistics : public CHeapObj { friend class TableStatistics; private: - volatile size_t _added_items; - volatile size_t _removed_items; + Atomic _added_items; + Atomic _removed_items; jlong _time_stamp; double _seconds_stamp; diff --git a/src/hotspot/share/utilities/zipLibrary.cpp b/src/hotspot/share/utilities/zipLibrary.cpp index 54875516a0f..ad6bb82d43f 100644 --- a/src/hotspot/share/utilities/zipLibrary.cpp +++ b/src/hotspot/share/utilities/zipLibrary.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 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,6 +24,7 @@ #include "jvm_io.h" #include "runtime/arguments.hpp" +#include "runtime/atomic.hpp" #include "runtime/interfaceSupport.inline.hpp" #include "runtime/os.inline.hpp" #include "runtime/semaphore.inline.hpp" @@ -50,10 +51,10 @@ static ZIP_GZip_InitParams_t ZIP_GZip_InitParams = nullptr; static ZIP_GZip_Fully_t ZIP_GZip_Fully = nullptr; static void* _zip_handle = nullptr; -static bool _loaded = false; +static Atomic _loaded{false}; static inline bool is_loaded() { - return AtomicAccess::load_acquire(&_loaded); + return _loaded.load_acquire(); } static inline bool not_loaded() { @@ -111,7 +112,7 @@ static void load_zip_library(bool vm_exit_on_failure) { } store_function_pointers(&path[0], vm_exit_on_failure); - AtomicAccess::release_store(&_loaded, true); + _loaded.release_store(true); assert(is_loaded(), "invariant"); }