Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8301119: Support for GB18030-2022 #12518

Closed
wants to merge 19 commits into from

Conversation

naotoj
Copy link
Member

@naotoj naotoj commented Feb 10, 2023

Upgrading the GB18030 charset in the JDK to the latest 2022 standard. Since this is not a compatible upgrade to the existing mapping, a new system property jdk.charset.GB18030 is introduced. If it is set to "2000", the mapping falls back to the existing mapping based on the 2000 standard, otherwise, it defaults to 2022 mapping. Refer to the corresponding CSR for more detail.


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
  • Change requires CSR request JDK-8301559 to be approved

Issues

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12518

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 10, 2023

👋 Welcome back naoto! 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 Feb 10, 2023

@naotoj The following labels will be automatically applied to this pull request:

  • build
  • core-libs
  • i18n
  • nio

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 build build-dev@openjdk.org nio nio-dev@openjdk.org core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org labels Feb 10, 2023
@naotoj naotoj force-pushed the JDK-8301119-GB18030-2022 branch 3 times, most recently from c070ed0 to 3f53394 Compare February 14, 2023 23:11
@sauzny
Copy link

sauzny commented Feb 16, 2023

Hi @sauzny, thanks for making a comment in an OpenJDK project!

All comments and discussions in the OpenJDK Community must be made available under the OpenJDK Terms of Use. If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please Use "Add GitHub user sauzny for the summary.

If you are not an OpenJDK Author, Committer or Reviewer, simply check the box below to accept the OpenJDK Terms of Use for your comments.

Your comment will be automatically restored once you have accepted the OpenJDK Terms of Use.

@naotoj naotoj marked this pull request as ready for review February 21, 2023 19:40
@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 21, 2023
@mlbridge
Copy link

mlbridge bot commented Feb 21, 2023

Webrevs

@@ -198,4 +206,19 @@ public class StandardCharsets extends CharsetProvider {

};
}

// Lazily initialized system property value
private static String GB18030_2000;
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this should be a stable field.

if (GB18030_2000 == null) {
if (VM.initLevel() < 1) {
// Cannot get the system property yet. Assumes non-2000
GB18030_2000 = "";
Copy link
Contributor

Choose a reason for hiding this comment

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

curious - what scenario triggers this call at initLevel < 1 ? would it be better to simply return "false" at that time and leave the GB18030_2000 variable to be set once we're at initLevel >=1 ? -- or perhaps that would invalidate the workflow of the original caller (which called in at initLevel <1)

Copy link
Contributor

Choose a reason for hiding this comment

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

curious - what scenario triggers this call at initLevel < 1 ?

It's not supported, but it is possible that someone might run with -Dfile.encoding=GB18030, in which case the default charset is used before the system properties are initialized in initPhase1. Checking the init level breaks the circularity, the only downside is that can't switch to GB18030-2000 at the same time.

Copy link
Member Author

Choose a reason for hiding this comment

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

Charset class is initialized before system properties are set up, in order to check the JNU encoding (used for file path name) is a supported charset or not. In some OS environments, GB18030 is the native encoding so we need to avoid checking the system property in such a case.

Copy link
Member

Choose a reason for hiding this comment

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

@Stable semantics are still fuzzy to me but the rule I've adhered to is that back to back stores to the field - if unavoidable - needs to be idempotent since the JIT (or AOT) may record any non-null value as a compile time constant at any time.

I'd write this to not update the static field if initLevel() < 1. Such calls should be rare and only happen once on a system that has GB18030 as their native encoding.

Copy link
Member

Choose a reason for hiding this comment

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

Scratch that: as it seems to be important that we don't switch after startup then what this code is really reaching for is static final field semantics. Since StandardCharsets might be loaded very early a holder class pattern might be necessary:

    isGB18030_2000() { return GB18030Properties.GB18030_2000; }

    private static class GB18030Properties {
        private static final GB18030_2000 = init();
        private static boolean init() {
            if (VM.initLevel() < 1) {
                // Cannot get the system property yet. Assumes non-2000
                return false;
            }
            return "2000".equals(GetPropertyAction.privilegedGetProperty("jdk.charset.GB18030"));
        }
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, doing nothing for the initLevel < 1 case means that -Dfile.encoding=GB18030 -Djdk.charset.GB18030=2000 would use version 2022 in early startup (JNU encoding init) and then switch to version 2000. Using a holder class seems a better idea than trying to coordinate concurrent writers.

Copy link
Contributor

Choose a reason for hiding this comment

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

would use of jdk.internal.util.SystemProps be an option here (if having to retrieve that value when we're at VM init level <1 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

would use of jdk.internal.util.SystemProps be an option here (if having to retrieve that value when we're at VM init level <1 ?

The early startup scenario is early in the system property initialization, specifically SystemProps.Raw. which will cause the encoding to be initialized. This has to avoid make use of system properties, otherwise you get a circular initialization issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

what this code is really reaching for is static final field semantics.

Exactly. Introducing the holder pattern in StandardCharset would solve the issue, but instead I moved the flag init into GB18030 so that we can literally make it static final.

@AlanBateman
Copy link
Contributor

Overall I think it looks very good, just StandardCharsets.isGB18030_2000 needs attention. Having GB18030 be in java.base in all builds, rather than everywhere except macOS, is okay and makes things a lot simpler.

Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

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

Latest version looks good to me, avoids needing stable field or holder class.

@openjdk
Copy link

openjdk bot commented Feb 24, 2023

@naotoj 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:

8301119: Support for GB18030-2022

Reviewed-by: alanb, coffeys, lancea

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 44 new commits pushed to the master branch:

  • 83d77b1: 8303072: Memory leak in exeNullCallerTest.cpp
  • 7d8b8ba: 8303131: pandoc.exe mangles all processed html files
  • 8f7c496: 8302810: NMT gtests don't correctly check for marked ranges
  • 1a07871: 8302173: Button border overlaps with button icon on macOS system LaF
  • 796cdd5: 8302677: JFR: Cache label and contentType in EventType and ValueDescriptor
  • 6b24b4a: 8302821: JFR: Periodic task thread spins after recording has stopped
  • 4d33fbd: 8303089: [jittester] Add time limit to IRTree generation
  • f612dcf: 8302512: Update IANA Language Subtag Registry to Version 2023-02-14
  • 6397cb6: 8301200: Don't scale timeout stress with timeout factor
  • 71dd7ea: 8303085: Runtime problem list cleanup
  • ... and 34 more: https://git.openjdk.org/jdk/compare/f319c92bd0fc68a64e6ac35ad4569740b858c9b2...master

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 added the ready Pull request is ready to be integrated label Feb 24, 2023
@takiguc
Copy link

takiguc commented Feb 24, 2023

Hello @naotoj .
Sorry for bothering you.

I have following question:

  • Why GB18030.java.template is in src/jdk.charsets/share/classes/sun/nio/cs/ext/ directory even if the generated code is always stored into sun/nio/cs ?
    I think the file should be moved to src/java.base/share/classes/sun/nio/cs and the file name should be GB18030.java instead of GB18030.java.template.
    Is there specific reason ?

@AlanBateman
Copy link
Contributor

  • Why GB18030.java.template is in src/jdk.charsets/share/classes/sun/nio/cs/ext/ directory even if the generated code is always stored into sun/nio/cs ?

That is a good question. It could move, and $PACKAGE replaced with sun.nio.cs, so it would be more obvious from the source location that it is generated into java.base rather than jdk.charsets. Up until now, GB18030 went into java.base on some platforms and jdk.charsets on other platforms. It will be the same for all platforms once this PR is integrated.

@naotoj
Copy link
Member Author

naotoj commented Feb 24, 2023

Hello @naotoj . Sorry for bothering you.

I have following question:

  • Why GB18030.java.template is in src/jdk.charsets/share/classes/sun/nio/cs/ext/ directory even if the generated code is always stored into sun/nio/cs ?
    I think the file should be moved to src/java.base/share/classes/sun/nio/cs and the file name should be GB18030.java instead of GB18030.java.template.
    Is there specific reason ?

No, there is not. Thanks for pointing it out. Fixed.

@takiguc
Copy link

takiguc commented Feb 26, 2023

Thanks @naotoj .
That's what I expected.

@naotoj
Copy link
Member Author

naotoj commented Feb 27, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Feb 27, 2023

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

  • 55e6bb6: 8302685: Some javac unit tests aren't reliably closing open files
  • f5a1276: 8262895: [macos_aarch64] runtime/CompressedOops/CompressedClassPointers.java fails with 'Narrow klass base: 0x0000000000000000' missing from stdout/stderr
  • 2fe4e5f: 8303169: Remove Windows specific workaround from libdt
  • f2b03f9: 8303051: Stop saving 5 chunks in each ChunkPool
  • fbc036e: 8303135: JFR: Log periodic events using periodic tag
  • dbb5581: 8081474: SwingWorker calls 'done' before the 'doInBackground' is finished
  • 306134d: 8300792: Refactor examples in java.net.http to use @snippet
  • a2c5a4a: 8302732: sun/net/www/http/HttpClient/MultiThreadTest.java still failing intermittently
  • db217c9: 8292583: Comment for ciArrayKlass::make is wrong
  • 2613b94: 8302149: Speed up compiler/jsr292/methodHandleExceptions/TestAMEnotNPE.java
  • ... and 54 more: https://git.openjdk.org/jdk/compare/f319c92bd0fc68a64e6ac35ad4569740b858c9b2...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Feb 27, 2023

@naotoj Pushed as commit a253b46.

💡 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
build build-dev@openjdk.org core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org integrated Pull request has been integrated nio nio-dev@openjdk.org
7 participants