On Thu, 16 Jul 2026 02:46:57 GMT, Chen Liang <[email protected]> wrote:

> Simplifies maintenance for Value Objects: Unsafe reference comparison is no 
> longer the same as `==`, let's use VarHandle which is always up-to-date.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

src/java.base/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
 line 483:

> 481:         public final V get(T obj) {
> 482:             accessCheck(obj);
> 483:             return (V) handle.get(obj);

@liach VH::get is a plain read, so this needs to be volatile:

"Returns the value of a variable, with memory semantics of reading as if the 
variable was declared non-volatile. Commonly referred to as plain read access." 
- 
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/invoke/VarHandle.html#get(java.lang.Object...)


Suggestion:

            return (V) handle.getVolatile(obj);

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/31924#discussion_r3664838827

Reply via email to