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

JDK-8301491: C2: java.lang.StringUTF16::indexOfChar intrinsic called with negative character argument #12538

Closed
wants to merge 3 commits into from

Conversation

dafedafe
Copy link
Contributor

@dafedafe dafedafe commented Feb 13, 2023

The java.lang.StringUTF16::indexOfChar is supposed to return -1 for characters with value < 0. Its intrinsic methods don't always do so.

private static int indexOfChar(byte[] value, int ch, int fromIndex, int max) {

The intrinsic methods expect the int character being passed to be >= 0. Unfortunately this is not enforced in the Java part (indexOf only checks for the upper bound):

if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {

The intrinsic methods assume that only the lower 16 bits are used (0 <= ch <= 0xFFFF) and either don't care about the upper 16 bits or implicitly mask them, e.g. for aarch64:
orr(ch, ch, ch, LSL, 16);
orr(ch, ch, ch, LSL, 32);
or avx:
vpbroadcastw(vec1, vec1, Assembler::AVX_256bit);

On the other hand, the Java method indexOfCharUnsafe makes this check implicitly by comparing a char with an int;

if (getChar(value, i) == ch) {
return i;
}

As there doesn't seem to be a good reason to call indexOfChar with ch < 0, it seems reasonable to add a check in LibraryCallKit::inline_string_indexOfChar that triggers a deoptimization if it fails.


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-8301491: C2: java.lang.StringUTF16::indexOfChar intrinsic called with negative character argument

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12538

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 13, 2023

👋 Welcome back dafedafe! 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 13, 2023

@dafedafe The following label will be automatically applied to this pull request:

  • hotspot-compiler

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

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Feb 13, 2023
@dafedafe dafedafe changed the title JDK-8301491: C2: java.lang.StringUTF16::indexOfChar instrinsic produces wrong result JDK-8301491: C2: java.lang.StringUTF16::indexOfChar instrinsic called with negative character argument Feb 15, 2023
@dafedafe dafedafe changed the title JDK-8301491: C2: java.lang.StringUTF16::indexOfChar instrinsic called with negative character argument JDK-8301491: C2: java.lang.StringUTF16::indexOfChar intrinsic called with negative character argument Feb 15, 2023
Copy link
Member

@TobiHartmann TobiHartmann left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@dafedafe dafedafe marked this pull request as ready for review February 16, 2023 07:57
@openjdk
Copy link

openjdk bot commented Feb 16, 2023

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

8301491: C2: java.lang.StringUTF16::indexOfChar intrinsic called with negative character argument

Reviewed-by: thartmann, kvn

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

  • 49eb68b: 8296158: Refactor the verification of CDS region checksum
  • 655a712: 8301444: Port fdlibm hyperbolic transcendental functions to Java
  • b242eef: 8280419: Remove dead code related to VerifyThread and verify_thread()
  • 4ce493f: 8302225: SunJCE Provider doesn't validate key sizes when using 'constrained' transforms for AES/KW and AES/KWP
  • a39cf2e: 8301753: AppendFile/WriteFile has differences between make 3.81 and 4+
  • de80dd9: 8296010: AssertionError in annotationTargetType
  • e5042dd: 8302671: libawt has a memmove decay error
  • 574b48c: 8302678: validate_source fails after JDK-8293313
  • 90e0922: 8293313: NMT: Rework MallocLimit
  • f558a6c: 8298276: JFR: Update NMT events to make use of common periodic timestamp feature
  • ... and 165 more: https://git.openjdk.org/jdk/compare/96c50a3486e3b6cdce7f8fb409d015b289770811...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@TobiHartmann, @vnkozlov) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 16, 2023
@mlbridge
Copy link

mlbridge bot commented Feb 16, 2023

Webrevs

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Good.

@dafedafe
Copy link
Contributor Author

@TobiHartmann @vnkozlov thanks a lot for your reviews!

@dafedafe
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Feb 17, 2023
@openjdk
Copy link

openjdk bot commented Feb 17, 2023

@dafedafe
Your change (at version c07718b) is now ready to be sponsored by a Committer.

@TobiHartmann
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Feb 17, 2023

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

  • 49eb68b: 8296158: Refactor the verification of CDS region checksum
  • 655a712: 8301444: Port fdlibm hyperbolic transcendental functions to Java
  • b242eef: 8280419: Remove dead code related to VerifyThread and verify_thread()
  • 4ce493f: 8302225: SunJCE Provider doesn't validate key sizes when using 'constrained' transforms for AES/KW and AES/KWP
  • a39cf2e: 8301753: AppendFile/WriteFile has differences between make 3.81 and 4+
  • de80dd9: 8296010: AssertionError in annotationTargetType
  • e5042dd: 8302671: libawt has a memmove decay error
  • 574b48c: 8302678: validate_source fails after JDK-8293313
  • 90e0922: 8293313: NMT: Rework MallocLimit
  • f558a6c: 8298276: JFR: Update NMT events to make use of common periodic timestamp feature
  • ... and 165 more: https://git.openjdk.org/jdk/compare/96c50a3486e3b6cdce7f8fb409d015b289770811...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Feb 17, 2023

@TobiHartmann @dafedafe Pushed as commit 47ca577.

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