title: AtomicReference vs AtomicReferenceFieldUpdater, what's a purpose of AtomicReferenceFieldUpdater?
body: <p>I'd like to atomically upgrade my reference. For example to use <code>compareAndSet</code>, <code>getAndSet</code> and other atomic operations.</p>
  
  <p>I came from C++, so in C++ I've got <code>volatile</code> keyword and different atomic intrinsics, or the <code>&lt;atomic&gt;</code> <a href="https://en.cppreference.com/w/cpp/atomic/atomic" rel="noreferrer">API</a>. In java, there's also a <code>volatile</code> keyword and different <a href="http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/9b8c96f96a0f/src/share/classes/sun/misc/Unsafe.java" rel="noreferrer">unsafe atomic operations</a>.</p>
  
  <p>By the way, there's also a well-documented <a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicReference.html" rel="noreferrer">AtomicReference</a> (as well as <code>Long</code>, <code>Integer</code>, <code>Boolean</code>), so <strong>JDK</strong> creators provided us a way to safely execute atomic operations against references and primitives. There's nothing wrong about the API, it is rich and seems very familiar.</p>
  
  <p>But, there's also an <a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.html" rel="noreferrer">AtomicReferenceFieldUpdater</a> whick provides a kinda weird way to execute atomic operations: you have to "find" the field via reflection by name and then you can use exactly the same operations.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>What's the purpose of <code>AtomicReferenceFieldUpdater</code> at all? In my
  opinion it is implicit and kinda weird: you need to declare a
  volatile variable filed <strong>AND</strong> and the field updater itself. So where
  should I use a <code>FieldUpdater</code>?</li>
  <li>It provides an indirection: you're
  <em>manipulating</em> (not <strong>changing</strong>!) the <code>FieldUpdater</code>, not the variable, this confuses.</li>
  <li>Performance: as far as I know, both <code>AtomicReferenceFieldUpdater</code> and
  <code>AtomicReference</code> are delegating to the Unsafe, so their performance
  is similar, but anyway: are there any performance penalties of
  <code>FieldUpdater</code> agaist Reference?</li>
  </ol>