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

8271459: C2: Missing NegativeArraySizeException when creating StringBuilder with negative capacity #5652

Closed
wants to merge 2 commits into from

Conversation

chhagedorn
Copy link
Member

@chhagedorn chhagedorn commented Sep 23, 2021

Stringopts does not take into account that a negative int argument for StringBuilder(int) results in a NegativeArraySizeException when optimizing away StringBuilder usages into single strings.

The suggested fix does the following:

  • Bailout of Stringopts if C2 knows that an int argument is always negative.
  • Apply stringopts but insert an additional runtime check with an UCT if C2 cannot tell if an int argument is positive or negative.

I added some IR tests to verify the fix and also ran some standard benchmarks.

I also updated TestIRMatching to test the new and updated default regexes.

Thanks,
Christian


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8271459: C2: Missing NegativeArraySizeException when creating StringBuilder with negative capacity

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5652/head:pull/5652
$ git checkout pull/5652

Update a local copy of the PR:
$ git checkout pull/5652
$ git pull https://git.openjdk.java.net/jdk pull/5652/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 5652

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5652.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 23, 2021

👋 Welcome back chagedorn! 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 openjdk bot added the rfr Pull request is ready for review label Sep 23, 2021
@openjdk
Copy link

openjdk bot commented Sep 23, 2021

@chhagedorn 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 Sep 23, 2021
@mlbridge
Copy link

mlbridge bot commented Sep 23, 2021

Webrevs

Copy link
Contributor

@rwestrel rwestrel left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me.

@openjdk
Copy link

openjdk bot commented Sep 23, 2021

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

8271459: C2: Missing NegativeArraySizeException when creating StringBuilder with negative capacity

Reviewed-by: roland, thartmann, neliasso

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

  • 2e690ba: 8274322: Problems with oopDesc construction
  • a8edd1b: 8274527: Minimal VM build fails after JDK-8273459
  • 7326481: 8274393: Suppress more warnings on non-serializable non-transient instance fields in security libs
  • 8215b2e: 8274398: Suppress more warnings on non-serializable non-transient instance fields in management libs
  • 9573022: 8253197: vmTestbase/nsk/jvmti/StopThread/stopthrd007/TestDescription.java fails with "ERROR: DebuggeeSleepingThread: ThreadDeath lost"
  • f08180f: 8274501: c2i entry barriers read int as long on AArch64
  • c57ed22: 8274528: Add comment to explain an HKDF optimization in SSLSecretDerivation
  • 9180d9a: 8273216: JCMD does not work across container boundaries with Podman
  • 3e0d7c3: 8270290: NTLM authentication fails if HEAD request is used
  • bfd6163: 8274196: Crashes in VM_HeapDumper::work after JDK-8252842
  • ... and 198 more: https://git.openjdk.java.net/jdk/compare/4c673df31e46644b21fefa51e0ea01f7d9b94856...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 Sep 23, 2021
@chhagedorn
Copy link
Member Author

Thanks Roland for your review!

@neliasso
Copy link

If we hit the uncommontrap - should we recompile without applying strconcat? Or is this code so uncommon that we don't want to add complexity for that case?

@chhagedorn
Copy link
Member Author

I guess we could do that by changing the UCT from Action_none to Action_maybe_recompile. I pushed an update.

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.

That looks good to me given that we check for too_many_traps in StringConcat::validate_control_flow().

@chhagedorn
Copy link
Member Author

Thanks for your review Tobias! Right, that should prevent the application of stringopts again.

Copy link

@neliasso neliasso 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!

@chhagedorn
Copy link
Member Author

Thanks Nils for your review!

@chhagedorn
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Oct 5, 2021

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

  • 53d7e95: 8274635: Use String.equals instead of String.compareTo in jdk.accessibility
  • e43f540: 8274651: Possible race in FontDesignMetrics.KeyReference.dispose
  • 2e542e3: 8274349: ForkJoinPool.commonPool() does not work with 1 CPU
  • 7e757f6: 8274559: JFR: Typo in 'jfr help configure' text
  • 75d6688: 8274745: ProblemList TestSnippetTag.java
  • 9914e5c: 8274610: Add linux-aarch64 to bootcycle build profiles
  • 0ca094b: 8273244: Improve diagnostic output related to ErroneousTree
  • 6f727d8: 8274666: rename HtmlStyle.descfrmTypeLabel to be less cryptic
  • 139a833: 8268869: java in source-file mode suggests javac-only Xlint flags
  • f63c4a8: 8274471: Verification of OCSP Response signed with RSASSA-PSS fails
  • ... and 226 more: https://git.openjdk.java.net/jdk/compare/4c673df31e46644b21fefa51e0ea01f7d9b94856...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Oct 5, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Oct 5, 2021
@openjdk
Copy link

openjdk bot commented Oct 5, 2021

@chhagedorn Pushed as commit 3953e07.

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

@chhagedorn chhagedorn deleted the JDK-8271459 branch April 24, 2023 10:32
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
Development

Successfully merging this pull request may close these issues.

4 participants