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

8268019: C2: assert(no_dead_loop) failed: dead loop detected #4860

Closed
wants to merge 2 commits into from

Conversation

chhagedorn
Copy link
Member

@chhagedorn chhagedorn commented Jul 21, 2021

In the testcase, a path containing a loop is found to be dead. These nodes are then removed during IGVN after parsing (before loop opts). One of these nodes is a loop header region through which an If is split. Splitting an If through a loop header region is not intended and was disabled by JDK-8232539. However, the bailouts in the current code are not enough to prevent the split if optimization for this dying loop header node due to the following reasons:

  • The region is not a LoopNode, yet, and we do not bail out at:
    if (r->is_Loop()) return NULL;
  • The loop header region has only one phi left (the other phis were already killed) and we do not bail out at:
    if( u != phi ) {
    // CNC - do not allow any other merged value
    //tty->print_cr("Merging another value");
    //u->dump(2);
    return NULL;
    }
  • The phi merges a ConP constant (dead path) and a CastPP node which is also allowed as constant:
    // Also allow null-vs-not-null checks
    const TypePtr *tp = igvn->type(con1)->isa_ptr();
    if( tp && tp->_ptr == TypePtr::NotNull )
    break;
  • The loop entry was already replaced by top and thus no predicates can be found to bail out:
    Node* proj = PhaseIdealLoop::find_predicate(r->in(ii));
    if (proj != NULL) {
    return NULL;
    }

These conditions let the split if optimization to be applied without a bailout. The CastPP node is a use of the phi and is thus rewired in the process. The problem now is that the CastPP node is an input and output of the loop phi while being a constant to be merged:
before_split_if

This lets the split if optimization to create a data loop by setting the input of the CastPP to itself.

This scenario is rare and highly depends on the order in which IGVN processes the nodes. As a fix, I propose to extend the bailout checks for loop header regions to catch this edge case. The new check looks at all inputs of the region and bail out if only one path is non-top. This also avoids unnecessary splits through regions which are dying anyways.

Thanks,
Christian


Progress

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

Issue

  • JDK-8268019: C2: assert(no_dead_loop) failed: dead loop detected

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4860

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 21, 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 Jul 21, 2021
@openjdk
Copy link

openjdk bot commented Jul 21, 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 Jul 21, 2021
@mlbridge
Copy link

mlbridge bot commented Jul 21, 2021

Webrevs

@chhagedorn
Copy link
Member Author

Ping - due to outage

if (r->is_Loop()) return NULL;
if( phi->region() != r ) return NULL;
Node* r = iff->in(0);
if (!r->is_Region() || r->is_Loop() || phi->region() != r) {
Copy link
Contributor

Choose a reason for hiding this comment

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

May be also add || r->as_Region()->is_copy() || igvn->_worklist.member(r) checks.

Copy link
Member Author

@chhagedorn chhagedorn Jul 23, 2021

Choose a reason for hiding this comment

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

Could we then possibly miss a split if opportunity when bailing out with igvn->_worklist.member(r)? Should we readd the If node to the worklist in this case? We could also think about adding igvn->_worklist.member(r) further down when we are really sure that we could do a split if.

Copy link
Contributor

Choose a reason for hiding this comment

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

My thinking is that Region could go away after it is processed (when input[s] are dead/top). Why bother to split through it?

I am concern that you are checking dead inputs by hand in these changes - input's transformation to Top should put Region node on worklist. Can you do experiment without your dead inputs check and only checking worklist?

I think the issue (as usual) is the order of processing of worklist. That is why I suggested this check.
Yes, you can delay worklist checking to see if we should put If node back on worklist only when we can do split if.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, this additional worklist check should then be enough and is more clean. I reverted the fix and added a worklist check at the latest possible location. This works for repeated runs with StressIGVN + RepeatCompilation. I also included the is_copy() check.

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.

@openjdk
Copy link

openjdk bot commented Jul 26, 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:

8268019: C2: assert(no_dead_loop) failed: dead loop detected

Reviewed-by: kvn, thartmann

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:

  • 6afcf5f: 8270886: Crash in PhaseIdealLoop::verify_strip_mined_scheduling
  • a0504cf: Merge
  • 20d2dc1: 8271403: mark hotspot runtime/memory tests which ignore external VM flags
  • e593e3d: 8271402: mark hotspot runtime/os tests which ignore external VM flags
  • 7bf72ce: 8271412: ProblemList javax/sound/midi/Sequencer/Looping.java
  • 6878b05: 8271251: JavaThread::java_suspend() fails with "fatal error: Illegal threadstate encountered: 6"
  • c8ae7e5: 8271174: runtime/ClassFile/UnsupportedClassFileVersion.java can be run in driver mode
  • 5fcf720: 8271352: Extend jcc erratum mitigation to additional processors
  • 6e1da64: 8270908: TestParallelRefProc fails on single core machines
  • 2ec45dc: 8225082: Remove IdenTrust certificate that is expiring in September 2021
  • ... and 198 more: https://git.openjdk.java.net/jdk/compare/375fc2a2b29c454b36d3ae068a080b28f6ec04e9...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 Jul 26, 2021
@chhagedorn
Copy link
Member Author

Thanks Vladimir for your review!

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.

Nice analysis. Looks good to me.

@TobiHartmann
Copy link
Member

And just for the record: We need to be careful to not create an infinite loop of node processing when "manually" re-adding nodes that haven't changed to the worklist. For example, while processing node A, it is re-added to the worklist because node B is still on the worklist. Then while node B is processed, it's also re-added to the worklist because node A is still on the worklist and so on. I don't think that's an issue here but I've debugged similar bugs in the past in Valhalla.

@chhagedorn
Copy link
Member Author

Thank you for your review Tobias!

And just for the record: We need to be careful to not create an infinite loop of node processing when "manually" re-adding nodes that haven't changed to the worklist. For example, while processing node A, it is re-added to the worklist because node B is still on the worklist. Then while node B is processed, it's also re-added to the worklist because node A is still on the worklist and so on. I don't think that's an issue here but I've debugged similar bugs in the past in Valhalla.

That's a good point to keep in mind. I also think it's fine in this case but in general we need to be careful when doing it.

@chhagedorn
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jul 29, 2021

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

  • 6afcf5f: 8270886: Crash in PhaseIdealLoop::verify_strip_mined_scheduling
  • a0504cf: Merge
  • 20d2dc1: 8271403: mark hotspot runtime/memory tests which ignore external VM flags
  • e593e3d: 8271402: mark hotspot runtime/os tests which ignore external VM flags
  • 7bf72ce: 8271412: ProblemList javax/sound/midi/Sequencer/Looping.java
  • 6878b05: 8271251: JavaThread::java_suspend() fails with "fatal error: Illegal threadstate encountered: 6"
  • c8ae7e5: 8271174: runtime/ClassFile/UnsupportedClassFileVersion.java can be run in driver mode
  • 5fcf720: 8271352: Extend jcc erratum mitigation to additional processors
  • 6e1da64: 8270908: TestParallelRefProc fails on single core machines
  • 2ec45dc: 8225082: Remove IdenTrust certificate that is expiring in September 2021
  • ... and 198 more: https://git.openjdk.java.net/jdk/compare/375fc2a2b29c454b36d3ae068a080b28f6ec04e9...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Jul 29, 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 Jul 29, 2021
@openjdk
Copy link

openjdk bot commented Jul 29, 2021

@chhagedorn Pushed as commit 489e5fd.

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

@chhagedorn chhagedorn deleted the JDK-8268019 branch August 30, 2021 09:39
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.

3 participants