So, is JMM still useful for modern Java?
Not really.
So, is JMM still valid for modern Java?
Yes, is still valid
Most of the java memory are handled behind the scene, garbage collection calls and manual memory manipulation is very rarely used and considered bad design. Most people will tell you it is still useful due to certain things can be done such as native memory allocation or create native concurrency.
While JMM is supported and is valid, no one really uses it. Why? Those type of things are not safe to be done using sun.misc.Unsafe. One reason why it is unsafe code is because the instances are never garbage collected. (unless this is what you want). Is like using volatile variable for thread; it never cached locally and it cost you performance and is difficult to write. In a non atomic operation may give you different result!
It is not wrong to use fence code but think about the trade offs. Ask yourself why do you use java and not C?
In short, it could be useful to get certain things done but it is not practical, due to there would be alternative way to do this. (native code)
For Vince's comment I will add this:
volatile int i = 0;
public void foo() {
if (i == 0) i = i + 1;
}
The above code is inherently unsafe, even though the variable's declaration as being volatile means that reads and writes are flushed to main memory - the only safe implementation of such a method would be something like:
int i = 0;
public synchronized void foo() {
if (i == 0)
i = i + 1;
}
So which should you prefer? Well, if you have multiple threads modifying a field dependent on that field's value (i.e. compare-and set), then synchronized is the only safe solution.