Note that this is a simulated CAS (as the name itself implies); in words of Brian Goetz (the listing comes from his "Java Concurrency In Practice" book):
SimulatedCAS
in Listing 15.1 illustrates the semantics (but not the implementation or performance) of CAS.
Actual implementation of CAS needs CPU support, classes from the java.util.concurrent.atomic
package call native
methods.