Skip to content

8358426: Improve lazy computation in Locale#25646

Closed
justin-curtis-lu wants to merge 2 commits intoopenjdk:masterfrom
justin-curtis-lu:JDK-8358426-Locale-lazyInit-SV
Closed

8358426: Improve lazy computation in Locale#25646
justin-curtis-lu wants to merge 2 commits intoopenjdk:masterfrom
justin-curtis-lu:JDK-8358426-Locale-lazyInit-SV

Conversation

@justin-curtis-lu
Copy link
Member

@justin-curtis-lu justin-curtis-lu commented Jun 4, 2025

Please review this PR which improves occurrences of lazy computation in Locale and BaseLocale.

Existing lazy initialization strategies such as CHM, static nested class, and local inner class are replaced with Stable Values.

Lambda usage is intentionally avoided in this change during Locale creation and in static fields due to potential startup performance degradation as noted by JDK-8331932.

Rather than convert iso3166CodesMap to a Stable Map, each ISO 3166 resource is represented as a SV. Also, I did not think it was necessary to maintain a SV for both the array and set of ISO3166-1 alpha-2 codes.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8358426: Improve lazy computation in Locale (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25646/head:pull/25646
$ git checkout pull/25646

Update a local copy of the PR:
$ git checkout pull/25646
$ git pull https://git.openjdk.org/jdk.git pull/25646/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25646

View PR using the GUI difftool:
$ git pr show -t 25646

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25646.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 4, 2025

👋 Welcome back jlu! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jun 4, 2025

@justin-curtis-lu This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8358426: Improve lazy computation in Locale

Reviewed-by: naoto, liach

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 42 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot changed the title JDK-8358426: Improve lazy computation in Locale 8358426: Improve lazy computation in Locale Jun 4, 2025
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 4, 2025
@openjdk
Copy link

openjdk bot commented Jun 4, 2025

@justin-curtis-lu The following labels will be automatically applied to this pull request:

  • core-libs
  • i18n

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org labels Jun 4, 2025
@mlbridge
Copy link

mlbridge bot commented Jun 4, 2025

Webrevs

Copy link
Member

@liach liach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct. Note we have a separate effort #25040 to avoid anonymous supplier classes, don't know if @minborg wishes locale to migrate to that one directly or remain on the more high-level SV.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 5, 2025
private static volatile Locale defaultFormatLocale;

private transient volatile String languageTag;
private transient final Supplier<String> languageTag =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use blessed modifiers order

Suggested change
private transient final Supplier<String> languageTag =
private final transient Supplier<String> languageTag =

@minborg
Copy link
Contributor

minborg commented Jun 5, 2025

Looks good! As @liach mentioned, there is an even better way coming, but I think it's good to do this update anyway. Here is a similar one that I am working on: #25630

So, once we have stable field updaters, it will be almost trivial to update the code in this PR.

System.arraycopy(isoCountries, 0, result, 0, isoCountries.length);
return result;
String[] countries = ISO_3166_1_ALPHA2.get();
return Arrays.copyOf(countries, countries.length);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about return ISO_3166_1_ALPHA2.get().clone();

Copy link
Member Author

@justin-curtis-lu justin-curtis-lu Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clone is more concise, but I think I prefer the explicitness of copyOf here.

public Set<String> get() {
return Set.of(LocaleISOData.ISO3166_3);
}
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about moving these four stable suppliers and getISO2Table to LocaleISOData to shrink size of Locale.java?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this suggestion, we can also move getISO3Code in addition to those you mentioned, and have all ISO resources and methods come from LocaleISOData. @naotoj, would you be in favor of this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that would be more straightforward. Thanks for the suggestion!

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jun 5, 2025
Copy link
Member

@naotoj naotoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 6, 2025
public static Set<String> getISOCountries(IsoCountryCode type) {
Objects.requireNonNull(type);
return IsoCountryCode.retrieveISOCountryCodes(type);
return switch (type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The body of this method could also be moved to a method in LocaleISOData

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's OK as is, don't want to force re-approvals. Currently it is consistent with the other ISO related methods in Locale, which grab the ISO resources from LocaleISOData but handle some logic on their own as well.

@justin-curtis-lu
Copy link
Member Author

Thank you for the reviews!
/integrate

@openjdk
Copy link

openjdk bot commented Jun 9, 2025

Going to push as commit cd9b1bc.
Since your change was applied there have been 56 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 9, 2025
@openjdk openjdk bot closed this Jun 9, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 9, 2025
@openjdk
Copy link

openjdk bot commented Jun 9, 2025

@justin-curtis-lu Pushed as commit cd9b1bc.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

7 participants