Skip to content

8337506: Disable "best-fit" mapping on Windows command line #20428

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

Closed
wants to merge 2 commits into from

Conversation

naotoj
Copy link
Member

@naotoj naotoj commented Aug 1, 2024

Fixing the Java launcher's command line argument parsing issue on Windows. The Java launcher on Windows has been using GetCommandLineA() to obtain arguments, which by default does "best-fit" mapping when the arguments are converted to ANSI code page encoding. By disabling this "best-fit" mapping, the launcher's parsing works as expected. A corresponding CSR has been drafted for the behavioral change.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change requires CSR request JDK-8337509 to be approved
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issues

  • JDK-8337506: Disable "best-fit" mapping on Windows command line (Bug - P4)
  • JDK-8337509: Disable "best-fit" mapping on Windows command line (CSR)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 20428

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 1, 2024

👋 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 Aug 1, 2024

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

8337506: Disable "best-fit" mapping on Windows command line

Reviewed-by: alanb

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

  • 73718fb: 8337788: RISC-V: Cleanup code in MacroAssembler::reserved_stack_check
  • 965d6b9: 8335836: serviceability/jvmti/StartPhase/AllowedFunctions/AllowedFunctions.java fails with unexpected exit code: 112
  • 7146dae: 8337783: Use THROW_NULL instead of THROW_0 in pointer contexts in misc runtime code
  • 431d4f7: 8337785: Fix simple -Wzero-as-null-pointer-constant warnings in x86 code
  • e2c07d5: 8337299: vmTestbase/nsk/jdb/stop_at/stop_at002/stop_at002.java failure goes undetected
  • 08f697f: 8337819: Update GHA JDKs to 22.0.2
  • 42652b2: 8337787: Fix -Wzero-as-null-pointer-constant warnings when JVMTI feature is disabled
  • 807186f: 8337784: Fix simple -Wzero-as-null-pointer-constant warnings in linux/posix code
  • e68df52: 8337054: JDK 23 RDP2 L10n resource files update
  • 9856216: 8336928: GHA: Bundle artifacts removal broken
  • ... and 46 more: https://git.openjdk.org/jdk/compare/f5c9e8f1229f3aa00743119a2dee3e15d57048d8...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 csr Pull request needs approved CSR before integration rfr Pull request is ready for review labels Aug 1, 2024
@openjdk
Copy link

openjdk bot commented Aug 1, 2024

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

  • core-libs
  • hotspot-runtime

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 hotspot-runtime hotspot-runtime-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Aug 1, 2024
@mlbridge
Copy link

mlbridge bot commented Aug 1, 2024

Webrevs

WC_NO_BEST_FIT_CHARS | WC_COMPOSITECHECK | WC_DEFAULTCHAR,
wcCmdline, -1, NULL, 0, NULL, NULL);
LPSTR mbCmdline = JLI_MemAlloc(mbSize);
if (WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS | WC_COMPOSITECHECK | WC_DEFAULTCHAR,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this looks okay but will need to handle GetCommandLineW, WideCharToMultiByte, or JLI_MemAlloc failing.

Copy link
Member Author

Choose a reason for hiding this comment

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

IIUC, all errors should be handled with the proposed patch. On error with JLI_MemAlloc and WideCharToMultiByte, the process exits with exit(1). As to GetCommandLineW(), there is no description of error in the MS document (https://learn.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-getcommandlinew), so I suppose no error handling on our side is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, all errors should be handled with the proposed patch. On error with JLI_MemAlloc and WideCharToMultiByte, the process exits with exit(1).

I think I'm mostly wondering about WideCharToMultiByte as it returns 0 when it fails.

Copy link
Member Author

@naotoj naotoj Aug 2, 2024

Choose a reason for hiding this comment

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

The first call to WideCharToMultiByte() returns the required size for the multibyte buffer. When it returns 0, exit(1) is issued inside JLI_MemAlloc(). If the second call to WideCharToMultiByte() returns 0, it is explicitly dealt with the patch which also issues exit(1).

Copy link
Contributor

Choose a reason for hiding this comment

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

The first call to WideCharToMultiByte() returns the required size for the multibyte buffer. When it returns 0, exit(1) is issued inside JLI_MemAlloc().

That's a bit subtle. I think it needs to be handled here or at least include a comment to say that it returns 0 on error which will cause JLI_MemAlloc to exit.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, added the comment

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Aug 6, 2024
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 6, 2024
@naotoj
Copy link
Member Author

naotoj commented Aug 6, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Aug 6, 2024

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

  • 3f8b3e5: 8337887: [JVMCI] Clarify jdk.vm.ci.code.Architecture.getName javadoc
  • 53db937: 8337780: RISC-V: C2: Change C calling convention for sp to NS
  • ab509f1: 8337654: Relocate uncommon trap stub from SharedRuntime to OptoRuntime
  • 1348ece: 8332120: Potential compilation failure in istream.cpp:205 - loss of data on conversion
  • ef909bd: 8335121: Native memory leak when not recording any events
  • a117945: 8337344: Redundant javadoc at RasterPrinterJob.isCancelled
  • f9b8a22: 8337798: JFR: Remove jdk/jfr/api/consumer/recordingstream/TestOnEvent.java from ProblemList.txt
  • 958786b: 8332522: SwitchBootstraps::mappedEnumLookup constructs unused array
  • f92c60e: 8337810: ProblemList BasicDirectoryModel/LoaderThreadCount.java on Windows
  • 0d8ec42: 8337642: Remove unused APIs of GCPolicyCounters
  • ... and 57 more: https://git.openjdk.org/jdk/compare/f5c9e8f1229f3aa00743119a2dee3e15d57048d8...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Aug 6, 2024

@naotoj Pushed as commit ff634a9.

💡 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 hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants