8379273: Convert miscellaneous utilities to use Atomic<T>

Reviewed-by: dholmes, fbredberg
This commit is contained in:
Kim Barrett 2026-03-13 08:05:20 +00:00
parent d93204eaff
commit 8c4d27381c
5 changed files with 21 additions and 20 deletions

View File

@ -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<Node*> _first;
Node* load_first() {
return AtomicAccess::load_acquire(&_first);
return _first.load_acquire();
}
static bool match_all(E d) { return true; }

View File

@ -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<E>::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<E>::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;

View File

@ -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;

View File

@ -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<mtStatistics> {
friend class TableStatistics;
private:
volatile size_t _added_items;
volatile size_t _removed_items;
Atomic<size_t> _added_items;
Atomic<size_t> _removed_items;
jlong _time_stamp;
double _seconds_stamp;

View File

@ -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<bool> _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");
}