Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8327963 [Umbrella] Incorrect result of C2 compiled code since JDK-8237581
  3. JDK-8336293

C2 produces inconsistent results with loops with long trip counts

XMLWordPrintable

    • x86_64
    • linux_ubuntu

        ADDITIONAL SYSTEM INFORMATION :
        ```bash
        $ cat /etc/os-release
        PRETTY_NAME="Ubuntu 22.04.4 LTS"
        NAME="Ubuntu"
        VERSION_ID="22.04"
        VERSION="22.04.4 LTS (Jammy Jellyfish)"
        VERSION_CODENAME=jammy
        ID=ubuntu
        ID_LIKE=debian
        HOME_URL="https://www.ubuntu.com/"
        SUPPORT_URL="https://help.ubuntu.com/"
        BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
        PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
        UBUNTU_CODENAME=jammy

        jdk version: jdk-21.0.3

        A DESCRIPTION OF THE PROBLEM :
        When running the test case using the release version of OpenJDK21, it can be observed that the results are inconsistent before and after applying the -Xint parameter. We believe this could be a rather serious issue, as testing has shown that this problem occurs with OpenJDK17 release version, OpenJDK17 mainline, and OpenJDK23 mainline. However, it does not occur with OpenJDK11 and OpenJDK8.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        javac Test.java && java Test

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        4000000
        ACTUAL -
        3991842

        ---------- BEGIN SOURCE ----------
        class Test {
          int a = 400;
          double[] b = new double[a];
          long c;

          void bMeth() {
            long d;
            double[] e = new double[a];
            for (int f = 0; f < e.length; f++)
              e[f] = 1.116242;
            d = 1;
            while (++d < 7)
              synchronized (new Test()) { }
            long g = 0;
            for (int f = 0; f < e.length; f++)
              g += e[f];
            c += g;
          }

          void h() {
            for (int f = 0; f < 10000; ++f)
              bMeth();
            System.out.println(c);
          }

          public static void main(String[] i) {
            Test j = new Test();
            j.h();
          }
        }
        ---------- END SOURCE ----------

              roland Roland Westrelin
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: