Adding @atomic operations to Java
Overview How might atomic operations work in Java, and is there a current alternative in OpenJDK/Hotspot it could translate to. Feedback In my previous article on Making operations on volatile fields atomic. it was pointed out a few times that "fixing" previous behaviour is unlikely to go ahead regardless of good intentions. An alternative to this is to add an @atomic annotation. This has the advantage of only applying to new code and not risk breaking old code. Note: The use of a lower case name is intentional as it *doesn't* follow current coding conventions. Atomic operations Any field listed with an @atomic would make the whole expression atomic. Variables which are non-volatile and non-atomic could be read at the start, or set after the completion of the expression. The expression itself may require locking on some platforms, CAS operations or TSX depending on the CPU technology. If fields are only read, or only one is written too, this wo