RFR: 8356255: Add Stable Field Updaters to allow efficient lazy field evaluations [v3]
Shaojin Wen
swen at openjdk.org
Wed May 7 08:00:23 UTC 2025
On Wed, 7 May 2025 07:46:45 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`.
>
> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
>
> Add a method handle based field updater
src/java.base/share/classes/jdk/internal/lang/stable/StableFieldUpdater.java line 173:
> 171: if (!underlying.type().parameterType(0).equals(Object.class)) {
> 172: underlying = underlying.asType(underlying.type().changeParameterType(0, Object.class));
> 173: }
Suggestion:
var type = underlying.type();
if (type.returnType() != int.class || type.parameterCount() != 1) {
throw new IllegalArgumentException("Illegal underlying function: " + underlying);
}
if (!type.parameterType(0).equals(Object.class)) {
underlying = underlying.asType(type.changeParameterType(0, Object.class));
}
underlying.type() is used 4 times, local variables should be used
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25040#discussion_r2077031643
More information about the net-dev
mailing list