8379026: Convert utilities/events to use Atomic<T>

Reviewed-by: dholmes, fbredberg
This commit is contained in:
Kim Barrett 2026-03-13 02:43:09 +00:00
parent baf29eb3e5
commit b5d1af1f02
2 changed files with 10 additions and 12 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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,14 +26,15 @@
#include "memory/allocation.inline.hpp"
#include "oops/instanceKlass.hpp"
#include "oops/symbol.hpp"
#include "runtime/atomicAccess.hpp"
#include "runtime/atomic.hpp"
#include "runtime/javaThread.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/osThread.hpp"
#include "runtime/timer.hpp"
#include "utilities/events.hpp"
EventLog* Events::_logs = nullptr;
static Atomic<EventLog*> event_logs_list{};
StringEventLog* Events::_messages = nullptr;
StringEventLog* Events::_memprotect_messages = nullptr;
StringEventLog* Events::_nmethod_flush_messages = nullptr;
@ -51,15 +52,15 @@ EventLog::EventLog() {
// but use lock free add because there are some events that are created later.
EventLog* old_head;
do {
old_head = AtomicAccess::load(&Events::_logs);
old_head = event_logs_list.load_relaxed();
_next = old_head;
} while (AtomicAccess::cmpxchg(&Events::_logs, old_head, this) != old_head);
} while (!event_logs_list.compare_set(old_head, this));
}
// For each registered event logger, print out the current contents of
// the buffer.
void Events::print_all(outputStream* out, int max) {
EventLog* log = AtomicAccess::load(&Events::_logs);
EventLog* log = event_logs_list.load_relaxed();
while (log != nullptr) {
log->print_log_on(out, max);
log = log->next();
@ -68,7 +69,7 @@ void Events::print_all(outputStream* out, int max) {
// Print a single event log specified by name.
void Events::print_one(outputStream* out, const char* log_name, int max) {
EventLog* log = AtomicAccess::load(&Events::_logs);
EventLog* log = event_logs_list.load_relaxed();
int num_printed = 0;
while (log != nullptr) {
if (log->matches_name_or_handle(log_name)) {
@ -81,7 +82,7 @@ void Events::print_one(outputStream* out, const char* log_name, int max) {
if (num_printed == 0) {
out->print_cr("The name \"%s\" did not match any known event log. "
"Valid event log names are:", log_name);
EventLog* log = AtomicAccess::load(&Events::_logs);
EventLog* log = event_logs_list.load_relaxed();
while (log != nullptr) {
log->print_names(out);
out->cr();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -214,10 +214,7 @@ class ExceptionsEventLog : public ExtendedStringEventLog {
class Events : AllStatic {
friend class EventLog;
private:
static EventLog* _logs;
// A log for generic messages that aren't well categorized.
static StringEventLog* _messages;