Atomics.load and Atomics.store need to be fully fenced
authorfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Jun 2017 17:58:24 +0000 (17:58 +0000)
committerfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Jun 2017 17:58:24 +0000 (17:58 +0000)
commit4fe084effaf6476c954f72ee7082054e2bbda3ff
treecb043241a06f042007f8849dcbf8dfb3bd9d571d
parente7c604abd64fba0665a0dcfed4ec249b23e5a3aa
Atomics.load and Atomics.store need to be fully fenced
https://bugs.webkit.org/show_bug.cgi?id=172844

Reviewed by Keith Miller.

Source/JavaScriptCore:

Implement fully fenced loads and stores in FTL using AtomicXchgAdd(0, ptr) for the load and
AtomicXchg(value, ptr) for the store.

DFG needed no changes because it implements all atomics using a CAS loop.

AtomicsObject.cpp now uses new Atomic<> API for fully fences loads and stores.

Prior to this change, we used half fences (acquire/release) for atomic loads and stores. This
is not correct according to my current understanding of the SAB memory model, which requires
that atomic operations are SC with respect to everything not just other atomics.

* ftl/FTLLowerDFGToB3.cpp:
(JSC::FTL::DFG::LowerDFGToB3::compileAtomicsReadModifyWrite):
* ftl/FTLOutput.cpp:
(JSC::FTL::Output::atomicWeakCAS):
* ftl/FTLOutput.h:
* runtime/AtomicsObject.cpp:

Source/WTF:

Add loadFullyFenced and storeFullyFenced to Atomic<>.

* wtf/Atomics.h:
(WTF::Atomic::loadFullyFenced):
(WTF::Atomic::storeRelaxed):
(WTF::Atomic::storeFullyFenced):
(WTF::atomicLoadFullyFenced):
(WTF::atomicStoreFullyFenced):

Websites/webkit.org:

Update documentation to say that the canonical way to do fully fenced loads and stores is
AtomicXchgAdd(0, ptr) and AtomicXchg(value, ptr), respectively.

* docs/b3/intermediate-representation.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@217722 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp
Source/JavaScriptCore/runtime/AtomicsObject.cpp
Source/WTF/ChangeLog
Source/WTF/wtf/Atomics.h
Websites/webkit.org/ChangeLog
Websites/webkit.org/docs/b3/intermediate-representation.html