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

8265938: C2's conditional move optimization does not handle top Phi #3684

Closed
wants to merge 2 commits into from

Conversation

@TobiHartmann
Copy link
Member

@TobiHartmann TobiHartmann commented Apr 26, 2021

C2's CCP optimization sets the type of a PhiNode to TOP because it became dead after loop unrolling. Now since that node is not reachable from the bottom due to an infinite loop at the end of the method, CCP does not enqueue the PhiNode for IGVN. As a result, the dead subgraph is not removed. During loop opts, the conditional move optimization fails on the PhiNode because its type is top. The expected behavior is to simply bail out with "COMPILE SKIPPED: infinite loop (retry at different tier)".

I suggest to fix this by simply handling a TOP Phi in the conditional move optimization code.

This issue was reported by John Jiang (johnsjiang@tencent.com).

Thanks,
Tobias


Progress

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

Issue

  • JDK-8265938: C2's conditional move optimization does not handle top Phi

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3684

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

Using diff file

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

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Apr 26, 2021

👋 Welcome back thartmann! 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.

Loading

@openjdk openjdk bot added the rfr label Apr 26, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Apr 26, 2021

@TobiHartmann 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.

Loading

@mlbridge
Copy link

@mlbridge mlbridge bot commented Apr 26, 2021

Webrevs

Loading

Copy link
Member

@chhagedorn chhagedorn left a comment

Looks reasonable to me!

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Apr 26, 2021

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

8265938: C2's conditional move optimization does not handle top Phi

Reviewed-by: chagedorn, kvn, iignatyev

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

  • 377b346: 8264752: SIGFPE crash with option FlightRecorderOptions:threadbuffersize=30M
  • dc323a9: 8263421: Module image file is opened twice during VM startup
  • fbfd4ea: 8265914: Duplicated NotANode and not_a_node
  • 9481fad: 8163367: Test javax/swing/JComboBox/8033069/bug8033069NoScrollBar.java javax/swing/JComboBox/8033069/bug8033069ScrollBar.java fails intermittently
  • 9adbf15: 8265995: Shenandoah: Move ShenandoahInitMarkRootsClosure close to its use
  • 879a77f: 8265757: stack-use-after-scope in perfMemory_posix.cpp get_user_name_slow()
  • e4be968: 8265980: Fix systemDictionary and loaderConstraints printing
  • f6e26f6: 8265756: AArch64: initialize memory allocated for locals according to Windows AArch64 stack page growth requirement in template interpreter
  • 0a4c338: 8263432: javac may report an invalid package/class clash on case insensitive filesystems
  • 82b3719: 8265967: Unused NullCheckNode forward declaration in node.hpp
  • ... and 34 more: https://git.openjdk.java.net/jdk/compare/578a0b3c3de1cce6d74d02d973c2def360823c7b...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.

Loading

@openjdk openjdk bot added the ready label Apr 26, 2021
@TobiHartmann
Copy link
Member Author

@TobiHartmann TobiHartmann commented Apr 26, 2021

Thanks for the review, Christian!

Loading

@huishi-hs
Copy link

@huishi-hs huishi-hs commented Apr 26, 2021

@TobiHartmann Thanks for fixing tencent reported bug! Your fix is good.

Could an early check added after ccp GVN? Check if it is compiling a method currently in inifinite loop and abort compilation earlier?

--- a/src/hotspot/share/opto/compile.cpp
+++ b/src/hotspot/share/opto/compile.cpp
@@ -2287,6 +2287,9 @@ void Compile::Optimize() {
     TracePhase tp("iterGVN2", &timers[_t_iterGVN2]);
     igvn = ccp;
     igvn.optimize();
+    if (root()->req() == 1) {
+      record_method_not_compilable("trivial infinite loop after phase ccp");
+    }
   }
   print_method(PHASE_ITER_GVN2, 2);

Loading

@TobiHartmann
Copy link
Member Author

@TobiHartmann TobiHartmann commented Apr 26, 2021

@huishi-hs thanks for the review. This version of the fix was also proposed by the reporter but is not sufficient because it assumes that the infinite loop is reachable from all exit paths. This is not the case in my version of the regression test, were the infinite loop is only in the b == true branch.

Loading

@huishi-hs
Copy link

@huishi-hs huishi-hs commented Apr 26, 2021

@huishi-hs thanks for the review. This version of the fix was also proposed by the reporter but is not sufficient because it assumes that the infinite loop is reachable from all exit paths. This is not the case in my version of the regression test, were the infinite loop is only in the b == true branch.

You're right. Test is modified. Thanks!

Loading

Copy link
Contributor

@vnkozlov vnkozlov left a comment

The fix is good.

I think you need System.exit(0) (or something else) at the end of test. Otherwise the test runs forever due to presence of infinite loop in an other thread. I tried.
May be @iignatev can suggest graceful solution for timely exit in such case.

Loading

@iignatev
Copy link
Member

@iignatev iignatev commented Apr 26, 2021

one way to solve it is to make the thread created at L#57 daemon thread (+L64: thread.setDaemon(true);).

I'd also recommend you to use jdk.test.lib.Utils::adjustTimeout to factor the sleep time at L66: Thread.sleep(Utils.adjustTimeout(4000));

Loading

@TobiHartmann
Copy link
Member Author

@TobiHartmann TobiHartmann commented Apr 27, 2021

Thanks for the reviews and suggestions.

@vnkozlov, how did you run the test? The exact same code is also used in compiler/loopopts/TestStrangeControl.java and we never had problems with that test not exiting.

@iignatev Thanks, I've updated the test(s) accordingly.

Loading

@vnkozlov
Copy link
Contributor

@vnkozlov vnkozlov commented Apr 27, 2021

@TobiHartmann I ran test locally (not with jtreg). TestStrangeControl.java has the same issue when run standalone.
I think JTREG may kill process when main thread exits or something like that.

Loading

Copy link
Contributor

@vnkozlov vnkozlov left a comment

I verified that thread.setDaemon(true); solved endless run issue with local testing I observed.

Loading

@iignatev
Copy link
Member

@iignatev iignatev commented Apr 27, 2021

I think JTREG may kill process when main thread exits or something like that.

correct, jtreg exits the process almost immediately after the main method exits.

Loading

@TobiHartmann
Copy link
Member Author

@TobiHartmann TobiHartmann commented Apr 27, 2021

I think JTREG may kill process when main thread exits or something like that.

Ah right, that explains it. Thanks for the review!

Loading

@TobiHartmann
Copy link
Member Author

@TobiHartmann TobiHartmann commented Apr 27, 2021

/integrate

Loading

@openjdk openjdk bot closed this Apr 27, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Apr 27, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Apr 27, 2021

@TobiHartmann Since your change was applied there have been 47 commits pushed to the master branch:

  • 5634f20: 8265932: Move safepoint related fields from class Thread to JavaThread
  • b67b2b1: 8265690: Use the latest Ubuntu base image version in Docker testing
  • b2628d1: 8263972: C2: LoadVector/StoreVector type mismatch in MemNode::can_see_stored_value()
  • 377b346: 8264752: SIGFPE crash with option FlightRecorderOptions:threadbuffersize=30M
  • dc323a9: 8263421: Module image file is opened twice during VM startup
  • fbfd4ea: 8265914: Duplicated NotANode and not_a_node
  • 9481fad: 8163367: Test javax/swing/JComboBox/8033069/bug8033069NoScrollBar.java javax/swing/JComboBox/8033069/bug8033069ScrollBar.java fails intermittently
  • 9adbf15: 8265995: Shenandoah: Move ShenandoahInitMarkRootsClosure close to its use
  • 879a77f: 8265757: stack-use-after-scope in perfMemory_posix.cpp get_user_name_slow()
  • e4be968: 8265980: Fix systemDictionary and loaderConstraints printing
  • ... and 37 more: https://git.openjdk.java.net/jdk/compare/578a0b3c3de1cce6d74d02d973c2def360823c7b...master

Your commit was automatically rebased without conflicts.

Pushed as commit ab2aec2.

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

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants