Scrivio Interview library
InternalsIntermediate7 min read · updated 12 November 2026

How are volatile reads and writes implemented on x86 compared with ARM, and what are VarHandle's weaker access modes for?

On x86, ordinary loads and stores are already strongly ordered, so a volatile read compiles to a plain load and a volatile write is a store followed by a StoreLoad barrier, usually a locked instruction such as lock addl. On ARMv8, the JIT uses load-acquire (ldar) and store-release (stlr) instructions or explicit barriers, so volatile reads also cost something. VarHandle offers plain, opaque, acquire/release and volatile access modes; release/acquire is enough for one-way publication and avoids the full StoreLoad cost, but weaker modes should be used only with a clear argument and tests.

Why this question is asked

The Java Memory Model is written in terms of happens-before, without mentioning any processor. The JIT still has to turn it into real instructions, and the cost of volatile depends on the CPU. This matters more than it used to, because many teams now run Java on ARM servers as well as x86. Interviewers ask this question to see whether we understand where volatile's cost comes from, and when the finer-grained VarHandle modes are worth using. In this answer, we will recap the four kinds of reordering, see how x86 and ARM differ, look at what the JIT emits for volatile on each, and then go through VarHandle's access modes with an example of release/acquire publication.

1A Quick Recap: Four Kinds of Reordering

A processor can reorder a pair of memory operations in four ways, named by the two operations involved. LoadLoad: a later load completes before an earlier load. LoadStore: a later store becomes visible before an earlier load completes. StoreStore: a later store becomes visible before an earlier store. StoreLoad: a later load reads memory before an earlier store has become visible to other cores. A barrier, or fence, is an instruction that forbids some of these reorderings across it.

StoreLoad is the expensive one. Processors keep a store buffer, a small queue of writes waiting to reach the cache, so that a core does not stall on every write. Forbidding StoreLoad reordering means draining that buffer before the next load, which can cost tens of cycles or more.

2How x86 and ARM Differ

x86 uses a model often called total store order. It keeps loads in order, keeps stores in order, and never lets a store overtake an earlier load. The only reordering it allows is StoreLoad, caused by the store buffer. ARMv8 is weakly ordered: without barriers or special instructions, it may perform all four reorderings.

Hardware reorderings allowed
Reorderingx86 (TSO)ARMv8
LoadLoadNoYes
LoadStoreNoYes
StoreStoreNoYes
StoreLoadYes, via store bufferYes

This is why a racy Java program can work for years on x86 and fail on ARM. The JMM allows the reordering on both, but x86 hardware does not perform most of them, so only compiler reorderings show up there.

3What the JIT Emits for volatile

To implement volatile, the JIT must make a volatile write act as a release (earlier accesses cannot move after it), a volatile read act as an acquire (later accesses cannot move before it), and in addition prevent a volatile write from being reordered with a later volatile read, which is the StoreLoad case. It must also stop its own compiler optimizations from moving code across these points on every CPU.

On x86, loads already have acquire behaviour and stores already have release behaviour, so a volatile read is just an ordinary mov, and a volatile write is an ordinary mov followed by something that drains the store buffer. HotSpot uses a locked instruction for that, such as lock addl on the stack, because it is cheaper than mfence on most chips. So on x86, volatile reads are nearly free and volatile writes cost the StoreLoad barrier.

On ARMv8, HotSpot typically uses ldar, load-acquire, for volatile reads and stlr, store-release, for volatile writes. ARM defines these so that an stlr followed by an ldar is not reordered, which gives the StoreLoad guarantee volatile needs. Both instructions constrain the hardware, so on ARM a volatile read costs more than a plain load. The exact sequences depend on the JDK version and flags, so check your JVM's output with a disassembler if the details matter.

Java
// Simplified code shapes, check your JDK with -XX:+PrintAssembly
// volatile int x;
// x86-64
// read: mov eax, [obj+x] ; plain load
// write: mov [obj+x], eax ; plain store
// lock addl [rsp], 0 ; StoreLoad barrier
// ARMv8 (AArch64)
// read: ldar w0, [x_addr] ; load-acquire
// write: stlr w0, [x_addr] ; store-release

4VarHandle Access Modes

Java 9 introduced VarHandle, a typed reference to a field or array element that supports several access modes with different strength. They let library authors pay only for the ordering they need. From weakest to strongest: plain mode is an ordinary access with no ordering guarantees across threads. Opaque mode guarantees the access really happens and is coherent for that one variable, so a loop eventually sees a new value, but it orders nothing else. Acquire/release mode makes a setRelease write publish everything written before it, and a getAcquire read see everything written before the matching release. Volatile mode is full volatile semantics, including the StoreLoad ordering between volatile accesses.

VarHandle access modes
ModeMethodsTypical use
Plainget, setSingle-threaded access to the field
OpaquegetOpaque, setOpaqueProgress flags, no data published
Acquire/releasegetAcquire, setReleaseOne-way publication of data
VolatilegetVolatile, setVolatileSame as a volatile field

5Release/Acquire for One-Way Publication

The common pattern in a library is one writer that fills an object and publishes it, and many readers that pick it up. That needs release on the write and acquire on the read, and nothing more. It does not need the StoreLoad barrier, which only matters when a thread writes one volatile and then reads another volatile and both orders must be agreed by all threads, as in Dekker-style mutual exclusion.

Java
class Slot {
private Node node; // accessed through NODE
private static final VarHandle NODE;
static {
try {
NODE = MethodHandles.lookup().findVarHandle(Slot.class, "node", Node.class);
} catch (ReflectiveOperationException e) { throw new ExceptionInInitializerError(e); }
}
void publish(Node n) { // n is fully built before this call
NODE.setRelease(this, n); // x86: plain store, no lock addl; ARM: stlr
}
Node read() {
return (Node) NODE.getAcquire(this); // x86: plain load; ARM: ldar or ldapr
}
}

On x86 this removes the locked instruction from the write, which matters in a very hot path. On ARM, newer cores support ldapr, a slightly weaker load-acquire that the JVM can use for getAcquire, though whether yours does depends on the JDK and CPU. The catch is that the reasoning becomes harder. If a later change adds a second published variable that another thread reads after writing, the missing StoreLoad ordering can produce outcomes that volatile would forbid. So weaker modes belong in carefully reviewed library code with a written argument and jcstress tests run on ARM, and most code should keep using volatile fields or higher-level utilities such as AtomicReference and ConcurrentHashMap.

6Follow-up questions

Why does HotSpot use lock addl instead of mfence on x86?

Both drain the store buffer and give the StoreLoad guarantee. A locked read-modify-write on a stack location that the thread already owns has historically been faster than mfence on most Intel and AMD processors, and it is enough for the ordering volatile needs. The exact choice can change between JDK versions and CPUs.

Is a volatile read free on x86?

At the hardware level nearly so, since it is an ordinary load. But it still costs something in the compiler: the JIT cannot hoist it out of a loop, combine it with other reads, or move other accesses across it. In a tight loop that can matter more than any barrier.

7Conclusion

In this answer, we saw that x86 allows only StoreLoad reordering, so a volatile read is a plain load and a volatile write needs a StoreLoad barrier such as lock addl, while ARMv8 reorders freely and the JIT uses ldar and stlr, so volatile reads cost something too. VarHandle's plain, opaque, acquire/release and volatile modes let library code choose its ordering, and release/acquire is enough for one-way publication without the full StoreLoad cost. Weaker modes need a clear argument and tests; most code should use volatile or higher-level utilities.

What to say in the interviewAbout 100 seconds aloud

Open with

It starts with the hardware. x86 uses total store order: it keeps loads in order and stores in order and only allows a later load to pass an earlier store, because of the store buffer.

Then, if they want more

So on x86 a volatile read is just a plain mov, and a volatile write is a store followed by a StoreLoad barrier, which HotSpot implements with a locked instruction like lock addl on the stack because it is usually cheaper than mfence.

ARMv8 is weakly ordered and can reorder all four combinations, so the JIT uses load-acquire, ldar, for volatile reads and store-release, stlr, for volatile writes; ARM guarantees an stlr followed by an ldar stays in order, which gives volatile its StoreLoad property. That means on ARM volatile reads cost something too.

VarHandle, added in Java 9, exposes four access modes: plain, opaque, acquire/release and volatile. Opaque guarantees the access happens and is coherent for that variable, but orders nothing else.

Release/acquire is the useful one: setRelease publishes everything written before it, and getAcquire sees it, which is exactly what one-way publication needs, and it avoids the full StoreLoad cost, so on x86 the write has no locked instruction.

But the reasoning gets harder and mistakes only show up on weak hardware, so I would use weaker modes only in reviewed library code with a written argument and jcstress tests on ARM, and keep volatile fields or classes like AtomicReference everywhere else.

About this answer

Last updated
12 November 2026
Versions it names
Java 9
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
JLS chapter 17, Threads and Locks
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How are volatile reads and writes implemented on x86 compared with ARM, and what are...": https://scrivio-interview-library.netlify.app/java/java-memory-model/ffd3f58626/