Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8288975

Incorrect result with C2 compiled code

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      ADDITIONAL SYSTEM INFORMATION :

      Arch: x86_64
      OS: Ubuntu 20.04.4 LTS
      HotSpot
      - openjdk version "11.0.17-internal" 2022-10-18
      - OpenJDK Runtime Environment (fastdebug build 11.0.17-internal+0-adhoc.congli.my-jdk11u)
      - OpenJDK 64-Bit Server VM (fastdebug build 11.0.17-internal+0-adhoc.congli.my-jdk11u, mixed mode)
      javac: javac 11.0.17-internal

      A DESCRIPTION OF THE PROBLEM :
      The problem was found in the repo https://github.com/openjdk/jdk11u-dev (commit f915a327), OpenJDK 11.0.17 (internal).

      HotSpot's JIT and INT gives different result:

      ```
      $ ./jdk11u/bin/java -Xint Test
      -66
      125
      61
      -4
      -70
      122
      57
      -8
      -73
      118

      $ ./jdk11u/bin/java -Xbatch Test
      -66
      5
      -59
      -125
      66
      2
      -63
      127
      63
      -1
      ```


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. javac Test.java
      2. java -Xint Test
      3. java -Xbatch Test
      4. observe the output of Step 2 and Step 3

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      -66
      125
      61
      -4
      -70
      122
      57
      -8
      -73
      118
      ACTUAL -
      -66
      5
      -59
      -125
      66
      2
      -63
      127
      63
      -1

      ---------- BEGIN SOURCE ----------
      class Test {
        final int N = 256;
        byte byFld;
        float fFld;
        int iFld;
        int[] iArrFld;

        void vMeth1() {
          int i6 = 199, iArr[] = new int[N];
          float f2 = 45.363F;
          init(iArr, 5);
          iArrFld = iArr;
          for (int i5 : iArr) {
            try {
              i5 = 12430 / iArrFld[(i5 >>> 1) % N];
              iArrFld[(i5 >>> 1) % N] = 141 / i5;
              i5 = i5 / i5;
            } catch (ArithmeticException a_e) {
            }
            switch ((i5 >>> 1) % 10 + 36) {
              case 36:
                java.io.PrintStream ax$2 =
                    new java.io.PrintStream(
                        new java.io.OutputStream() {
                          public void write(int b) {}
                        });
                for (int ax$8 = -2967; ax$8 < 4342; ax$8 += 4) {}
                byFld += f2;
              case 40:
                break;
              case 41:
                iArr[1] -= i6;
            }
          }
        }

        void vMeth() {
          if (ax$18) return;
          vMeth1();
        }

        float fMeth(float f, int i, short s) {
          int i1;
          short[] sArr = new short[N];
          for (i1 = 2; i1 < 215; ++i1) {
            try {
              ax$18 = true;
              for (int ax$25 = 0; ax$25 < 9676; ax$25 += 1) vMeth();
            } finally {
              ax$18 = false;
            }
            vMeth();
          }
          long meth_res = checkSum(sArr);
          return meth_res;
        }

        void mainTest(String[] strArr1) {
          short s2 = 10116;
          fMeth(fFld, iFld, s2);
          System.out.println(byFld);
        }

        public static void main(String[] strArr) {
          Test _instance = new Test();
          for (int i = 0; i < 10; i++) _instance.mainTest(strArr);
        }

        public static long checkSum(short[] a) {
          long sum = 0;
          for (int j = 0; j < a.length; j++) {
            sum += (short) (a[j] / (j + 1) + a[j] % (j + 1));
          }
          return sum;
        }

        public static void init(int[] a, int seed) {
          for (int j = 0; j < a.length; j++) {
            a[j] = (j % 2 == 0) ? seed + j : seed - j;
          }
        }

        Boolean ax$18;
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: