8376400: C2: folding ifs may cause incorrect execution when trap is taken#30677
Open
rwestrel wants to merge 8 commits intoopenjdk:masterfrom
Open
8376400: C2: folding ifs may cause incorrect execution when trap is taken#30677rwestrel wants to merge 8 commits intoopenjdk:masterfrom
rwestrel wants to merge 8 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back roland! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
Contributor
Author
|
/template append |
|
@rwestrel The pull request template has been appended to the pull request body |
Member
|
Is it only uncommon_trap that has this problem? Can we rule out similar problems with other safepoints? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For the following test method:
The exception path and the 3rd if branch are compiled as uncommon
traps so in pseudo code:
next split thru phi runs:
next
IfNode::fold_compares()runs to transform the 2 signedcomparison into a single unsigned comparison:
test1is passed 0. That causes the uncommon trap to execute andexecution after deoptimization to resume at the
if (v == 0) {whichis reexecuted. The bug is that split if causes the stack captured in
the uncommon trap to be updated (the
Phivis replaced in thev = 0branch by 0). When execution resumes interpreted, it restarts with
v = 0and the
if (v == 0) {branch is taken (which is wrong).Folding the 2 ifs created an unsigned condition that is stricter that:
which would be fine if execution resumed at
if (v == 0) {with thestate of the interprer unmodified but, here, it is not in this case.
The fix I propose is to mark the uncommon trap
Callwhen split ifhappens and to check if the uncommon trap is marked in
IfNode::fold_compares(). I, initially, tried to fix this by tryingto validate the jvms state in
IfNode::fold_compares()beforeproceeding with the transformation (such as checking that the 2
uncommon traps have the same jvms state). Running some experiments, it
seems that would exclude a lot of cases where
IfNode::fold_compares()happens and is likely safe so I wasconcerned code quality would be impacted and by being overly
conservative.
I see that @merykitty mentions transformating the shape of the control
flow in a comment in the bug. My concern here is it could also impact
code quality (increase code size that gets in the way of inlining or
some hard to predict effect on register allocation) when it's usually
fine to proceed with
IfNode::fold_compares().Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30677/head:pull/30677$ git checkout pull/30677Update a local copy of the PR:
$ git checkout pull/30677$ git pull https://git.openjdk.org/jdk.git pull/30677/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 30677View PR using the GUI difftool:
$ git pr show -t 30677Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30677.diff
Using Webrev
Link to Webrev Comment