JDK-8231988 : Unexpected test result caused by C2 IdealLoopTree::do_remove_empty_loop
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11.0.1,12,13,14
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2019-10-08
  • Updated: 2021-01-26
  • Resolved: 2019-10-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 8 Other
11.0.6Fixed 8u251Fixed openjdk8u242Fixed
Related Reports
Duplicate :  
Description
Reduced fuzz test case:

public class Test {
    static {
        init();
    }

    public static void init() {
    }

    public void mainTest() {
        int i = 8;
        while ((i -= 3) > 0);
        System.out.println("i" + i);
    }

    public static void main(String[] args) {
        Test _instance = new Test();
        _instance.mainTest();
        _instance.mainTest();
    }
}


Two steps to reproduce the bug: 
Step1: Compile the test case with a 8u javac: javac Test.java
Step2: Run the test case with latest jdk14: java -XX:-BackgroundCompilation -XX:-TieredCompilation -Xcomp -XX:CompileCommand=compileonly,\*Test.\* Test

Expected output:
CompileCommand: compileonly *Test.*
i-1
i-1

Unexpected output:
CompileCommand: compileonly *Test.*
i-1
i/


Proposed fix which is currently under testing:
diff -r 5b5de2618756 src/hotspot/share/opto/loopTransform.cpp
--- a/src/hotspot/share/opto/loopTransform.cpp  Mon Oct 07 17:13:59 2019 -0700
+++ b/src/hotspot/share/opto/loopTransform.cpp  Wed Oct 09 15:39:42 2019 +0800
@@ -3129,6 +3129,13 @@
     // We also need to replace the original limit to collapse loop exit.
     Node* cmp = cl->loopexit()->cmp_node();
     assert(cl->limit() == cmp->in(2), "sanity");
+    // Duplicate cmp node if it has other users
+    if (cmp->outcnt() > 1) {
+      cmp = cmp->clone();
+      cmp = phase->_igvn.register_new_node_with_optimizer(cmp);
+      BoolNode *bol = cl->loopexit()->in(CountedLoopEndNode::TestValue)->as_Bool();
+      phase->_igvn.replace_input_of(bol, 1, cmp); // put bol on worklist
+    }
     phase->_igvn._worklist.push(cmp->in(2)); // put limit on worklist
     phase->_igvn.replace_input_of(cmp, 2, exact_limit); // put cmp on worklist
   }
Comments
13u Fix Request Backporting this patch fixes a c2 bug. Patch applies cleanly to 13u. New test fails without the product patch, and passes with it.
24-03-2020

8u Fix Request Backporting this patch fixes a C2 bug. Patch does not apply cleanly to 8u due to file path difference. Webrev: http://cr.openjdk.java.net/~fyang/8231988-8u-backport/webrev.00/ New test fails without the patch, and passes with it. jtreg test passes with the patch.
29-10-2019

Thanks Aleksey for doing this. I am still trying to pull on my laptop. The network status is not good :- (
25-10-2019

Hi Fei, I pushed this for you; in future, please contact jdk-updates-dev@ to get a sponsor.
24-10-2019

I am having some trouble pulling jdk11u-dev repo for now. Can someone help push this to jdk11u-dev repo please? This is labeled jdk11u-fix-yes. Thanks in advance.
16-10-2019

11u Fix Request Backporting this patch fixes a c2 bug. Patch applies cleanly to 11u. New test fails without the product patch, and passes with it. Tier1 tests pass with the patch.
15-10-2019

URL: https://hg.openjdk.java.net/jdk/jdk/rev/45a085445a8c User: fyang Date: 2019-10-14 23:38:37 +0000
14-10-2019

ILW = Incorrect execution of compiled code, easy to reproduce with generated test, disable loop opts or compilation of affected method = HMM = P2
08-10-2019