-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8353638: C2: deoptimization and re-execution cycle with StringBuilder #25149
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
8353638: C2: deoptimization and re-execution cycle with StringBuilder #25149
Conversation
…OnAllocationException
|
👋 Welcome back mchevalier! A progress list of the required criteria for merging this PR into |
|
@marc-chevalier 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: 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 148 new commits pushed to the
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 |
|
@marc-chevalier The following label will be automatically applied to this pull request:
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. |
|
/label add hotspot-compiler |
|
@marc-chevalier |
Webrevs
|
|
This may be a dumb question, but why would we want to optimize throwing NegativeArraySizeException? Maybe I'm missing something, but I would be surprised if any real apps would be helped by this fix. I know we have some optimizations for exception throwing, but I would expect those optimizations to be most useful for unavoidable exceptions, like NoClassDefFoundError. |
|
I agree it's a corner case and it should matter little in real life. Nevertheless, having worst performance in C2 than in C1 is never very nice looking. But to be honest, if the problem were more involved, and the fix more complicated, it's not clear to me whether it would be worth it just for that, indeed. BUT! This fix should also speedup any exception that happens during allocation. There seem to be quite some
THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string()); |
TobiHartmann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that such exceptional cases are usually not worth optimizing but in this case we already emitted all the code to handle them, so why deopt? The change looks good to me.
|
This change looks good, but do we still need StressCompiledExceptionHandlers after this? The only other use is in JavaThread::handle_async_exception, and it looks like it should be change too because it's dealing with the same issue. |
|
I've found a failing test (maybe even two) related to asynchronous exceptions when using this flag. I suspect something is wrong there (JDK-8356648). It's also not clear to me whether the failure is directly linked to faulty exceptions handlers: asynchronous exceptions have a complicated (to me) handshake mechanism and maybe it's faulty without the deopts (or deopts makes it less likely). Unlike in JDK-8004741 (that added For allocations, I couldn't find any problem, and the logic seems simpler. I think it's fine to still use the one that works. |
chhagedorn
left a comment
There was a problem hiding this 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.
| product(bool, DeoptimizeOnAllocationException, false, DIAGNOSTIC, \ | ||
| "Deoptimize on exception during allocation instead of using the" \ | ||
| " compiled exception handlers") \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with other flag definitions:
| product(bool, DeoptimizeOnAllocationException, false, DIAGNOSTIC, \ | |
| "Deoptimize on exception during allocation instead of using the" \ | |
| " compiled exception handlers") \ | |
| product(bool, DeoptimizeOnAllocationException, false, DIAGNOSTIC, \ | |
| "Deoptimize on exception during allocation instead of using the " \ | |
| "compiled exception handlers") \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, it was a bit ugly. I think I have my spaces in row now.
|
I'm ready for new review (hopefully approval): since last review, I just fixed the spaces as @chhagedorn pointed out. |
|
/integrate And thanks again @TobiHartmann and @chhagedorn! |
|
Going to push as commit a0a3060.
Your commit was automatically rebased without conflicts. |
|
@marc-chevalier Pushed as commit a0a3060. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Unlike what was assumed at first, it is quite different from JDK-8346989. The problem is actually unrelated to
StringBuilder, but has to do with the underlying array allocation.Here, the problem is that the array allocation function, that is throwing when given a negative length, causes a deopt rather than using the compiled exception handlers. This is an old workaround, and the flag
StressCompiledExceptionHandlersto rather use compiled handlers instead of deopting was added in JDK-8004741 in 2012. This flag is used in testing since october 2022.So maybe it's time to use the compiled exception handlers! I propose to turn them on by default, and instead, add a diagnostic flag to deopt instead, in case something goes wrong. Doing so improve the performance to match the ones of C1 (both for direct array allocation, and
StringBuilderconstruction). For instance, with the case given in the JBS issue:I've run some tests (up to tier10), it seems all fine, ignoring the usual noise. I've checked with @dougxc, it shouldn't impact Graal as it doesn't use
OptoRuntime.Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25149/head:pull/25149$ git checkout pull/25149Update a local copy of the PR:
$ git checkout pull/25149$ git pull https://git.openjdk.org/jdk.git pull/25149/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25149View PR using the GUI difftool:
$ git pr show -t 25149Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25149.diff
Using Webrev
Link to Webrev Comment