RFR: 8359119: Change Charset to use StableValue [v2]

Alan Bateman alanb at openjdk.org
Thu Jun 12 11:14:32 UTC 2025


On Tue, 10 Jun 2025 15:15:44 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> Fields and methods can better leverage the Stable Value API compared to using DCL and holder classes. There are also some fields that can be marked `@Stable`.
>> 
>> This PR passes tier1, tier2, and tier3 tests on multiple platforms.
>
> Per Minborg has updated the pull request incrementally with three additional commits since the last revision:
> 
>  - Revert for loop
>  - Revert more
>  - Revert changes

Overall I think this is okay but will need to run startup benchmarks due to this class being used in early startup.

src/java.base/share/classes/java/nio/charset/Charset.java line 431:

> 429:     /* The extended set of charsets */
> 430:     private static final Supplier<List<CharsetProvider>> EXTENDED_PROVIDERS = StableValue.supplier(
> 431:             new Supplier<>() { public List<CharsetProvider> get() { return extendedProviders0(); }});

This one looks okay.

src/java.base/share/classes/java/nio/charset/Charset.java line 627:

> 625:         return Objects.requireNonNullElse(
> 626:                 standardProvider.charsetForName(StaticProperty.fileEncoding()),
> 627:                 sun.nio.cs.UTF_8.INSTANCE);

I think it would more readable to keep the if-then-else rather than using requireNonNullElse here.

src/java.base/share/classes/java/nio/charset/Charset.java line 657:

> 655:     @Stable
> 656:     private final String name;          // tickles a bug in oldjavac
> 657:     @Stable

If we touching these then we can remove the "tickles a bug in oldjavac" comment as I think that goes back to before JDK 5.

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

PR Comment: https://git.openjdk.org/jdk/pull/25727#issuecomment-2966203126
PR Review Comment: https://git.openjdk.org/jdk/pull/25727#discussion_r2142374192
PR Review Comment: https://git.openjdk.org/jdk/pull/25727#discussion_r2142377094
PR Review Comment: https://git.openjdk.org/jdk/pull/25727#discussion_r2142380225


More information about the nio-dev mailing list