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

8296412: Special case infinite loops with unmerged backedges in IdealLoopTree::check_safepts #11706

Closed
wants to merge 3 commits into from

Conversation

eme64
Copy link
Contributor

@eme64 eme64 commented Dec 16, 2022

Context
During parsing, we insert SafePoints if we jump from higher to lower bci (maybe_add_safepoint is called for every if, goto etc).

void maybe_add_safepoint(int target_bci) {
if (target_bci <= bci()) {
add_safepoint();
}
}

Generally, this alligns with backedges: the assumption is that the loop-head sits at the smallest bci of all blocks in the loop. So every jump back to the loop-head goes from higher to lower bci, hence we place a SafePoint just before the jump.

Also: the first build_loop_tree may not attach an infinite loop to the loop-tree. If during the same loop-opts-phase we go to beautify_loops and it requires us rebuilding the loop-tree (eg because some other loop did merge_many_backedges), we call build_loop_tree again, and this time around we do detect the infinite loop (it now has a NeverBranch exit, so it is attached because of that).
Afterwards, we call IdealLoopTree::check_safepts, which tries to find SafePoints on all backedges. Normally, we have SafePoints on all backedges, just before we go back to the head.

Problem case
My jasm fuzzer produced some infinite loops that have the following form:
The loop head is not at the smallest bci (bytecode index) of all blocks in the loop. So the SafePoints are placed somewhere in the body of the loop, just before an if branches into the two backedges. Because this is an infinite loop, it is only attached to the loop-tree in build_loop_tree after beautify_loops, so the two backedges were not merged.
When we call IdealLoopTree::check_safepts, we start with the inner loop, where we find the SafePoint above the if. Then we go to the outer loop. We don't find a SafePoint before we find the inner body. Now we decide to skip the inner body (which implies skipping the SafePoint in the body). The code assumes after skipping the inner loop, we are still in the outer loop. This is not true, because inner and outer loop have the same loop head (the backedges were not merged). We trigger an assert that checks that we are still in the outer loop (nested loop).

Why did we not find this earlier?
We have not extensively tested infinite loops before. Also, we have not tested loops with loop-heads that are not at the smallest bci of the loop. However, with my bytecode fuzzer I can find these issues. It is also more likely with irreducible loops: there at least one loop-entry cannot be at the smallest bci. Irreducible loops are not processed by maybe_add_safepoint, but once it only has a singe entry, it is not irreducible any more, and so it can happen that a loop-entry becomes loop head that does not have the smallest bci.

Solution
We could fix maybe_add_safepoint to not depend on bci, but rather the loop-tree from ciTypeFlow. That would be complex, and risky. That is not justified just for infinite loops, and even infinite loops where the loop head is not at the lowest bci.

I decided to simply special case infinite loops. I detect if we have an outer loop with the same head as an inner loop. This should not happen, as we must have merged those backedges. Except if it is an infinite loop: We can break the scan, as we have already reached the loop's head.


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-8296412: Special case infinite loops with unmerged backedges in IdealLoopTree::check_safepts

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11706

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 16, 2022

👋 Welcome back epeter! 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 Dec 16, 2022

@eme64 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 Dec 16, 2022
@eme64 eme64 marked this pull request as ready for review December 16, 2022 11:11
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 16, 2022
@mlbridge
Copy link

mlbridge bot commented Dec 16, 2022

Webrevs

Copy link
Member

@chhagedorn chhagedorn 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! That looks reasonable to go with this simpler fix instead of fixing maybe_add_safepoint() given that this case is rare.

@openjdk
Copy link

openjdk bot commented Dec 16, 2022

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

8296412: Special case infinite loops with unmerged backedges in IdealLoopTree::check_safepts

Reviewed-by: chagedorn, 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 23 new commits pushed to the master branch:

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 Dec 16, 2022
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.

Looks good.

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.

…gedBackedgesMain.java


remove redundant empty line

Co-authored-by: Tobias Hartmann <tobias.hartmann@oracle.com>
@eme64
Copy link
Contributor Author

eme64 commented Dec 19, 2022

Thanks @TobiHartmann @chhagedorn @vnkozlov for the discussions and reviews!
/integrate

@openjdk
Copy link

openjdk bot commented Dec 19, 2022

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

  • 8e49fcd: 8295661: CompileTask::compile_id() should be passed as int
  • 86d588b: 8283740: C1: Convert flag TwoOperandLIRForm to a constant on all platforms
  • ec95991: 8298736: Revisit usages of log10 in compiler code
  • 1622563: 8265688: Unused ciMethodType::ptype_at should be removed
  • 3637660: 8298813: [C2] Converting double to float cause a loss of precision and resulting crypto.aes scores fluctuate
  • 5e678f7: 8298824: C2 crash: assert(is_Bool()) failed: invalid node class: ConI
  • ba942c2: 8298244: AArch64: Optimize vector implementation of AddReduction for floating point
  • 7938f8c: 8298639: Perform I/O operations in bulk for RandomAccessFile
  • bfa921a: 8160404: RelocationHolder constructors have bugs
  • bf9a8ce: 8249826: 5 javax/net/ssl/SSLEngine tests use @ignore w/o bug-id
  • ... and 17 more: https://git.openjdk.org/jdk/compare/fa322e40b68abf0a253040d14414d41f4e01e028...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 19, 2022
@openjdk openjdk bot closed this Dec 19, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 19, 2022
@openjdk
Copy link

openjdk bot commented Dec 19, 2022

@eme64 Pushed as commit da38d43.

💡 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
Development

Successfully merging this pull request may close these issues.

4 participants