RFR: 8356255: Add Stable Field Updaters to allow efficient lazy field evaluations

ExE Boss duke at openjdk.org
Tue May 6 14:15:15 UTC 2025


On Mon, 5 May 2025 13:41:22 GMT, Per Minborg <pminborg at openjdk.org> wrote:

> This sketch shows how "Stable Updaters" can be used to create stable computations of `@Stable` fields. Only one updater is needed per class, similar to `AtomicIntegerFieldUpdater`.

src/java.base/share/classes/jdk/internal/lang/stable/StableFieldUpdater.java line 214:

> 212:             }
> 213:             Objects.requireNonNull(underlying);
> 214:             return new StableLongFieldUpdater<>(holderType, offset, underlying, zeroReplacement);

This should probably construct `TearingStableLongFieldUpdater` on 32‑bit platforms:
Suggestion:

            if (Architecture.is64bit()) {
                // We are also relying on the fact that the VM will not place 64-bit
                // instance fields that can cross cache lines.
                return new StableLongFieldUpdater<>(holderType, offset, underlying, zeroReplacement);
            } else {
                return new TearingStableLongFieldUpdater<>(holderType, offset, underlying, zeroReplacement);
            }

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25040#discussion_r2075572314


More information about the net-dev mailing list