mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
ba9b85f7c3
At first, it might look like the atomicIncrement operations here, since they resolve to OSAtomicCompareAndSwap32Barrier, ought to provide all the memory barrier guarantees we need; however, it turns out it's not quite sufficient. Here's why: Apple's OSAtomic*Barrier operations guarantee that memory operations *before* the atomic op won't be reordered with memory operations *after* the atomic op - but makes no guarantee that the atomic op itself won't be reordered with other operations before or after it. The key is that the atomic operation is not really atomic, but rather consists of separate read, check and write steps - in a loop, no less. Here, presumably, the read of t->m->exclusive is hoisted by the out-of-order processor to between the read and write steps of the "atomic" increment of t->m->activeCount. Longer term, it probably makes sense to replace this with the c11 <stdatomic.h> operations or the c++11 <atomic> types. We ought to actually use the atomic increment operations provided there. As it is, our atomicIncrement looks substantially less efficient than those, since it's actually implemented on arm64 as two nested loops (one in atomicIncrement and one in the compare-and-swap) instead of one. We should also evaluate whether the various instances of atomic operations actually need as strong of barriers as we're giving them. FWIW, the gcc __sync_* builtins seem to have the same problem, at least on arm64. |
||
---|---|---|
.. | ||
android | ||
avian | ||
codegen | ||
heap | ||
lzma | ||
openjdk | ||
system | ||
tools | ||
util | ||
arm64.S | ||
arm.masm | ||
arm.S | ||
boot-javahome.cpp | ||
boot.cpp | ||
bootimage-fields.cpp | ||
bootimage-template.cpp | ||
builtin.cpp | ||
classpath-android.cpp | ||
classpath-avian.cpp | ||
classpath-openjdk.cpp | ||
CMakeLists.txt | ||
compile-arm64.S | ||
compile-arm.masm | ||
compile-arm.S | ||
compile-i386.masm | ||
compile-i386.S | ||
compile-x86_64.S | ||
compile.cpp | ||
continuations-x86.S | ||
debug-util.cpp | ||
debug-util.h | ||
embed.cpp | ||
embedded-loader.cpp | ||
finder.cpp | ||
heapdump.cpp | ||
heapwalk.cpp | ||
i386.masm | ||
i386.S | ||
interpret.cpp | ||
jnienv.cpp | ||
lzma-decode.cpp | ||
lzma-encode.cpp | ||
machine.cpp | ||
main.cpp | ||
powerpc-regs.S | ||
process.cpp | ||
thunks.cpp | ||
types.def | ||
util.cpp | ||
x86_64.S |