You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6ab0aeb
Browse filesBrowse the repository at this point in the historyBrowse files
https://bugs.webkit.org/show_bug.cgi?id=328577
rdar://190772091
Reviewed by Marcus Plutowski and Dan Hecht.
Replace the runtime `std::memory_order` parameter on `WTF::Atomic` and the
free-standing `atomic*` functions with a compile-time `WTF::MemoryOrder`
template parameter that explicitly documents and exposes the stronger hardware
guarantees WebKit relies on (multi-copy atomicity on ARM64 and x86_64, and
full-fence read-modify-writes). This helps clarify what people can actually
rely on for hardware WebKit officially supports. Additionally, I believe
this model can also be made to work for RISCV and MIPS efficiently. At least
to the extent that MIPS has high performance atomics.
In the C++ memory model, a `memory_order_seq_cst` read-modify-write does not
prevent earlier non-`seq_cst` stores from reordering past later non-`seq_cst`
loads, so Dekker-style protocols normally require a separate `storeLoadFence()`
(`dmb ish` on ARM64). On x86_64 (`lock`-prefixed instructions) and ARM64 with
LSE (`ldaddal`, `ldsetal`, `ldclral`, `swpal`, `casal`), a successful `seq_cst`
RMW is already a full barrier in hardware. Add `MemoryOrder::FullyFenced` for
read-modify-writes to express this guarantee directly: it lowers to a single
`seq_cst` RMW on x86 and ARM64+LSE, and appends a `seq_cst` thread fence only
on LL/SC targets. Passing invalid load/store/failure orders is now rejected at
compile time via `static_assert`.
Also, add `Atomic<T>::loadAndFence(T&)` to pair a relaxed load with a
`Dependency` (falling back to an `Acquire` load under TSan, which does not
model address dependencies), and use it where callers previously relied on raw
`loadRelaxed()` assuming implicit hardware dependency ordering without hiding
the dependency from the compiler.
Tests: Tools/TestWebKitAPI/Tests/WTF/ReadWriteLock.cpp
Tools/TestWebKitAPI/Tests/WTF/VersionedField.cpp
* Source/JavaScriptCore/heap/BlockDirectory.cpp:
(JSC::BlockDirectory::releaseAndNoteIfStealable):
(JSC::BlockDirectory::findEmptyBlockToSteal):
Replace the explicit `WTF::storeLoadFence()` calls in the empty-block stealing
protocol with `releaseInUse<MemoryOrder::FullyFenced>()` and
`m_emptyCursor.watch<MemoryOrder::FullyFenced>()`. Also avoid the `FullyFenced`
RMW in `releaseAndNoteIfStealable()` when the block isn't stealable.
* Source/JavaScriptCore/heap/BlockDirectory.h:
(JSC::BlockDirectory::releaseInUse):
Parameterize `releaseInUse` on `MemoryOrder` (defaulting to `Release`) so
`releaseAndNoteIfStealable()` can request `FullyFenced`.
* Source/WTF/wtf/Atomics.h:
(WTF::Atomic<T>::loadAndFence const):
(WTF::ensurePointer):
Use `loadAndFence` + `Dependency::consume` on the fast path and `Dependency::fence`
on the CAS-failure path so loads through the returned pointer have a true address
dependency preserved across compiler optimizations.
* Source/WTF/wtf/FastBitVector.h:
(WTF::FastBitReference::concurrentGet const):
(WTF::FastBitReference::concurrentSet):
(WTF::FastBitReference::concurrentTestAndSet):
(WTF::FastBitReference::concurrentTestAndClear):
Template the concurrent bit operations on `MemoryOrder`.
* Source/WTF/wtf/ThreadSafeLazyUniquePtr.h:
(WTF::ThreadSafeLazyUniquePtr::ensure const):
(WTF::ThreadSafeLazyUniquePtr::get const):
Use `loadAndFence` + `Dependency::consume` in `ensure()` and `get()` (and
`Dependency::fence` when losing the installation race) instead of relying on an
unfenced relaxed load.
* Source/WTF/wtf/ThreadSafeWeakPtr.h:
(WTF::ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr::bits const):
Use `m_bits.loadAndFence()` in `bits()` so loads through the control block carry
an explicit address dependency on the load of `m_bits` (and automatically use
`Acquire` under TSan).
* Source/WTF/wtf/VersionedField.h:
(WTF::VersionedField::watch):
Template operations on `MemoryOrder`. In `watch<MemoryOrder::FullyFenced>()`, the
initial load when checking whether the watched bit is already set uses
`MemoryOrder::Acquire` while the `exchangeOr` that sets the bit uses
`MemoryOrder::FullyFenced`; by multi-copy atomicity, observing an already-watched
value published by an earlier `FullyFenced` watch orders the reader after
everything ordered by that watch's fence.
Canonical link: https://commits.webkit.org/324977@main
0 commit comments