Video in progress
After we moved from x86 servers to ARM servers (for example, Graviton), some results started coming out wrong. What do you suspect from a concurrency standpoint?
x86 has a strong memory model (TSO) and "forgives" a lot of code that violates the JMM. ARM reorders writes and reads much more freely. So flags without volatile, objects that weren't safely published, and hand-written lock-free code are the first suspects.
📖 Answer
In the x86 TSO model there is only one reordering: a write can become visible after a later read (the store buffer). Write-write and read-read order is preserved. That's why the following code almost always works on x86 but not on ARM:
class Holder {
Config config; // not volatile
boolean ready; // not volatile
void init() { config = load(); ready = true; }
Config get() { return ready ? config : null; } // on ARM you can get ready=true, config=null
}
ARM can reorder two writes and also two reads. The JIT was allowed to do this too, but on x86 it rarely did in practice, so the bug lay dormant for years.
The important point: code that uses the JMM correctly behaves the same on both platforms. For volatile, synchronized, final and java.util.concurrent, the JVM puts in the necessary barriers on each platform itself (ldar/stlr, dmb on ARM). So ARM doesn't create a new bug, it reveals an existing one.
The search plan:
- Static review: fields shared between threads but without
volatileor a lock; hand-written DCL; weak modes withUnsafeorVarHandle; places with "benign race" comments. - Libraries: lock-free code in old versions, and native libraries: their ARM builds and known bugs.
- jcstress on ARM: small tests for the suspicious code. Outcomes that never showed up on x86 become visible here.
- Canary: put ARM nodes in front of a small share of traffic first, with invariant checks and result comparison (shadow traffic).
There's a performance side too: the relative cost of a volatile write and of CAS differs between platforms. What's cheap on x86 can be more expensive on ARM or the other way around, so hot paths need to be benchmarked again on ARM.
Sign up to mark studied questions and save your progress.