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

Incorrect Array Exception Thrown with c2

XMLWordPrintable

    • b140
    • 9
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      # Java version
      openjdk 19.0.2 2023-01-17
      OpenJDK Runtime Environment (build 19.0.2+7-44)
      OpenJDK 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)

      # Operating system details
      $ cat /etc/*release
      DISTRIB_ID=Ubuntu
      DISTRIB_RELEASE=18.04
      DISTRIB_CODENAME=bionic
      DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
      NAME="Ubuntu"
      VERSION="18.04.5 LTS (Bionic Beaver)"
      ID=ubuntu
      ID_LIKE=debian
      PRETTY_NAME="Ubuntu 18.04.5 LTS"
      VERSION_ID="18.04"
      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"
      VERSION_CODENAME=bionic
      UBUNTU_CODENAME=bionic


      A DESCRIPTION OF THE PROBLEM :
      Different outputs of the attached program are observed between
      different compilation tiers. This bug affects java 11.0.17 2022-10-18,
      java 17 2021-09-14 LTS, Oracle JDK 18.0.2.1, Oracle JDK 19.0.2, and
      openjdk 20-ea 2023-03-21. It was not reproduced in java version
      "1.8.0_351".

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      ## Steps to Reprodcue
      The following steps shows how to reproduce the bug on Java 19.0.2 in a
      Ubuntu Linux environment.

      # Compile
      $ javac C.java

      # Default or compilation up to level 4
      $ java C
      # Output (incorrect)
      99997

      # Compilation up to level 1
      $ java -XX:TieredStopAtLevel=1 C
      # Output (correct)
      100000

      # Interpreter or compilation up to level 0
      $ java -Xint C
      # Output (correct)
      100000


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      # Output (correct)
      100000

      ACTUAL -
      # Output (incorrect)
      99997


      ---------- BEGIN SOURCE ----------
      ## Source code for an executable test case
      # C.java
      public class C {
          static byte[] m(byte[] arg1) {
              byte[] b = new byte[-1];
              System.arraycopy(arg1, 0, b, 0, arg1.length);
              return b;
          }

          public static void main(String[] args) {
              int count = 0;
              for (int i = 0; i < 100_000; ++i) {
                  try {
                      System.out.println(m(null));
                  } catch (Throwable e) {
                      if (e instanceof java.lang.NegativeArraySizeException) {
                          count++;
                      }
                  }
              }
              System.out.println(count); // Should be 100_000
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      ## Workaround
      Interpreter or compilation for Level 0, 1, 2, 3 are fine.
      $ java -XX:TieredStopAtLevel=3 C


      FREQUENCY : always


        1. C.java
          0.6 kB
          swati sharma

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: