RFR: 8351565: Implement JEP 502: Stable Values (Preview)

Johannes Graham duke at openjdk.org
Thu Mar 13 11:20:14 UTC 2025


On Mon, 10 Mar 2025 23:42:06 GMT, Chen Liang <liach at openjdk.org> wrote:

>> src/java.base/share/classes/jdk/internal/lang/stable/StableEnumFunction.java line 112:
>> 
>>> 110:         final Class<E> enumType = (Class<E>)inputs.iterator().next().getClass();
>>> 111:         return (Function<T, R>) new StableEnumFunction<E, R>(enumType, min, StableValueFactories.array(size), (Function<E, R>) original);
>>> 112:     }
>> 
>> If `inputs` contains the enumuration constants with ordinals 0 and 2, wouldn't this code wrongly cause the enumeration constant with ordinal 1 to be an allowed input?
>
> Indeed, a bit set predicate can be used to check input validity if it is necessary - I think for enums, using a `StableFunction.ofEnum` dedicated API might be better just because `StableValue` can access `Class.getEnumConstantsShared` easily.

What if instead you had a `@Stable` array of Object of the appropriate size, and populated each cell with a StableValue if the corresponding index was in the set, otherwise used a sentinel value. Then on the lookup, if it was the sentinel you throw, else you use the the SV.

Also there is an awful lot of similarity between the enum function and the int function. Could one possibly be implemented using the other?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23972#discussion_r1988195668


More information about the core-libs-dev mailing list