On Mon, 31 Mar 2025 14:22:16 GMT, Maurizio Cimadamore <mcimadam...@openjdk.org> wrote:
>> Per Minborg has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Finish and clean up benchmarks > > src/java.base/share/classes/jdk/internal/lang/stable/StableValueImpl.java > line 161: > >> 159: >> 160: static String renderWrapped(Object t) { >> 161: return (t == null) ? UNSET_LABEL : Objects.toString(unwrap(t)); > > If I read correctly, this implementation is similar to what described here: > > https://preshing.com/20130930/double-checked-locking-is-fixed-in-cpp11/ > > (see section `Using C++11 Acquire and Release Fences`). > > We don't need the "relaxed" loads in Java because a reference load in Java > can never tear. Correct? As you rightfully say, references never tear in Java. The Acquire/Release fences are there to protect us from observing partially initialized objects. Without these barriers, there is no guarantee that all the stores performed by a first thread – in particular, those performed in a constructor – are visible to load operations in a second thread, even if the reference itself is visible (due to potential reordering) The monitor held by the first thread is not enough, since the second thread doesn’t acquire the monitor. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/23972#discussion_r2021194320