RFR: 8351565: Implement JEP 502: Stable Values (Preview) [v40]
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Apr 3 14:50:15 UTC 2025
On Thu, 3 Apr 2025 14:00:00 GMT, Per Minborg <pminborg at openjdk.org> wrote:
>> Implement JEP 502.
>>
>> The PR passes tier1-tier3 tests.
>
> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
>
> Make the sqrt example different
src/java.base/share/classes/java/lang/StableValue.java line 211:
> 209: * StableValue.function(CACHED_KEYS, LOG2_ORIGINAL);
> 210: *
> 211: * public static double log2(int a) {
IMHO this example reveals a lack of compositionality of the partial functions we have. If the functions returned optional (to indicate "not defined"), then code like this would become much simpler to express:
return LOG2_CACHED.apply(a)
.orElse(LOG2_ORIGINAL.apply(a));
It's not just that this is more fluent -- this is also using the caching function to check whether the input is cached or not -- instead of having a separate check (potentially duplicating the costs).
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23972#discussion_r2027173623
More information about the core-libs-dev
mailing list