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

8272562: C2: assert(false) failed: Bad graph detected in build_loop_late #5716

Closed
wants to merge 2 commits into from

Conversation

rwestrel
Copy link
Contributor

@rwestrel rwestrel commented Sep 27, 2021

A counted loop has an array access:

(LoadI (AddP (AddP (ConvI2L (CastII (AddI (Phi ...)))))))

that is

array[iv - 1]

The Phi is the iv Phi. The ConvI2L/CastII are from a range check
and capture type: 0..maxint-1 The loop is unrolled once, the
LoadI is cloned.

array[iv - 1]
array[iv]

The first LoadI is only used out of loop and is sunk with 2
clones. One of the clones is on the IfFalse branch of a test
for iv != 0.

(LoadI (AddP (AddP (ConvI2L (CastII (AddI (CastII ...)))))))

The second CastII pins the nodes out of the loop. The ConvI2L and
CastII are pushed thru the AddI (for -1). As a result the ConvI2L
has type:
1..maxint-1

The CastII, because it has the same input as the input for iv != 0,
becomes 0 which is not part of 1..maxint-1. The ConvI2L and all its
uses including the LoadI become top. The use of the LoadI is a Phi
that is transformed into its remaining input and the graph is broken.

The root cause is that the loop body initially contains:

if (iv - 1 >=u array.length) { // range check
trap();
}

if (iv == 0) {
// path where nodes are sunk later on
}

And obviously if iv - 1 >= 0 then iv == 0 is always false but c2 fails
to prove it. I tried to implement a simple fix for this issue but
while it fixes this bug, I couldn't convince myself that it was robust
enough.

So instead I propose following the suggestion Christian and Vladimir I.
made in:

#5199

that is to more generally exclude cast nodes from sinking as a
workaround for now.

I've been looking for a more general solution to this problem and I
have a prototype that fixes this failure but is a lot more
complicated. I'll revisit this workaround when it's ready.


Progress

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

Issue

  • JDK-8272562: C2: assert(false) failed: Bad graph detected in build_loop_late

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 5716

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 27, 2021

👋 Welcome back roland! 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 27, 2021
@openjdk
Copy link

openjdk bot commented Sep 27, 2021

@rwestrel 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 27, 2021
@mlbridge
Copy link

mlbridge bot commented Sep 27, 2021

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.

I agree with your suggestion to follow up with a more general solution later and go with this easier fix for now.

@@ -1445,7 +1445,8 @@ void PhaseIdealLoop::try_sink_out_of_loop(Node* n) {
!n->is_MergeMem() &&
!n->is_CMove() &&
!is_raw_to_oop_cast && // don't extend live ranges of raw oops
n->Opcode() != Op_Opaque4) {
n->Opcode() != Op_Opaque4 &&
(n->Opcode() == Op_CastII && ((CastIINode*)n)->has_range_check())) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the condition be inverted? This would only allow to sink range check CastII nodes.
And couldn't you use !(n->is_CastII() && n->as_CastII()->has_range_check()) instead of the explicit cast?

Copy link
Contributor Author

@rwestrel rwestrel Sep 27, 2021

Choose a reason for hiding this comment

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

Right! Thanks for catching this. Actually after thinking more about this, I changed the fix to prevent all nodes that can capture a type from being sunk to be on the safe side, for now.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, I guess you will undo that with your general fix later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the plan.

@openjdk
Copy link

openjdk bot commented Sep 27, 2021

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

8272562: C2: assert(false) failed: Bad graph detected in build_loop_late

Reviewed-by: chagedorn, kvn

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

  • be40373: 8274381: missing CAccessibility definitions in JNI code
  • 79865cd: 8274259: G1: assert(check_alignment(result)) failed: address not aligned: 0x00000008baadbabe after JDK-8270009
  • 961dcff: 8273581: Change the mechanism by which JDK loads the platform-specific FontManager class
  • 6a573b8: 8273508: Support archived heap objects in SerialGC
  • 3eca9c3: 8264707: HotSpot Style Guide should permit use of lambda
  • af50772: 8231640: (prop) Canonical property storage
  • ddc2627: 8273790: Potential cyclic dependencies between Gregorian and CalendarSystem
  • 633eab2: 8174819: java/nio/file/WatchService/LotsOfEvents.java fails intermittently
  • 8876eae: 8269685: Optimize HeapHprofBinWriter implementation
  • c880b87: 8274367: Re-indent stack-trace examples for Throwable.printStackTrace
  • ... and 125 more: https://git.openjdk.java.net/jdk/compare/17f7a45ce40ecf0666f282e68be1844d38a5d1c7...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 27, 2021
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.

@rwestrel
Copy link
Contributor Author

@chhagedorn @vnkozlov Thanks for the reviews.

@rwestrel
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Sep 29, 2021

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

  • 1dc8fa9: 8274340: [BACKOUT] JDK-8271880: Tighten condition for excluding regions from collecting cards with cross-references
  • aaa36cc: 8274242: Implement fast-path for ASCII-compatible CharsetEncoders on x86
  • c4d1157: 8271855: [TESTBUG] Wrong weakCompareAndSet assumption in UnsafeIntrinsicsTest
  • 756d22c: 8274130: C2: MulNode::Ideal chained transformations may act on wrong nodes
  • 5b0c9cc: 8274172: Convert JavadocTester to use NIO
  • 2657bcb: 8274136: -XX:+ExitOnOutOfMemoryError calls exit while threads are running
  • 53b25bc: 8273459: Update code segment alignment to 64 bytes
  • 1a29b1e: 8274016: Replace 'for' cycles with iterator with enhanced-for in java.desktop
  • d8a278f: 8274396: Suppress more warnings on non-serializable non-transient instance fields in client libs
  • e49e5b5: 8273972: Multi-core choke point in CMM engine (LCMSTransform.doTransform)
  • ... and 143 more: https://git.openjdk.java.net/jdk/compare/17f7a45ce40ecf0666f282e68be1844d38a5d1c7...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Sep 29, 2021

@rwestrel Pushed as commit 980c50d.

💡 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
3 participants