8374683: ZGC: Convert zLock to use Atomic<T>

Reviewed-by: stefank, tschatzl
This commit is contained in:
Axel Boldt-Christmas 2026-01-26 15:14:42 +00:00
parent 99b4e05d50
commit 6648567574
2 changed files with 10 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, 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
@ -25,6 +25,7 @@
#define SHARE_GC_Z_ZLOCK_HPP
#include "memory/allocation.hpp"
#include "runtime/atomic.hpp"
#include "runtime/mutex.hpp"
class ZLock : public CHeapObj<mtGC> {
@ -40,7 +41,7 @@ public:
class ZReentrantLock {
private:
ZLock _lock;
Thread* volatile _owner;
Atomic<Thread*> _owner;
uint64_t _count;
public:

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.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,6 @@
#include "gc/z/zLock.hpp"
#include "runtime/atomicAccess.hpp"
#include "runtime/javaThread.hpp"
#include "runtime/os.inline.hpp"
#include "utilities/debug.hpp"
@ -50,11 +49,11 @@ inline ZReentrantLock::ZReentrantLock()
inline void ZReentrantLock::lock() {
Thread* const thread = Thread::current();
Thread* const owner = AtomicAccess::load(&_owner);
Thread* const owner = _owner.load_relaxed();
if (owner != thread) {
_lock.lock();
AtomicAccess::store(&_owner, thread);
_owner.store_relaxed(thread);
}
_count++;
@ -67,14 +66,14 @@ inline void ZReentrantLock::unlock() {
_count--;
if (_count == 0) {
AtomicAccess::store(&_owner, (Thread*)nullptr);
_owner.store_relaxed(nullptr);
_lock.unlock();
}
}
inline bool ZReentrantLock::is_owned() const {
Thread* const thread = Thread::current();
Thread* const owner = AtomicAccess::load(&_owner);
Thread* const owner = _owner.load_relaxed();
return owner == thread;
}