Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-2141

[drlvm][jit][opt] ABCD removes low bound check if certain constraint exists before array access with a negative index

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 5.0M10
    • DRLVM
    • None
    • Any

    Description

      ABCD optimization removes low bound check if certain constraint exists before array access with a negative index.

      ArrayIndexOutOfBoundsException must be thrown if array alement with negative index is accessed.
      But harmony doesn't throw the Exception if abcd pass is turned on in the following case:
      Array elements are accessed inside a loop and array index depends on the loop control variable.
      A call to an array element with negative index occurred if
      control loop variable satisfies some linear constraint.

      Please, see the code example below.

      Code for reproducing:

      public class abcdTest {

      public static void main(String[] args) {
      System.out.println("Start Test ...");
      int i = 0;
      int arr[] = new int[300000];
      try {
      for(i=0; i<100000; i++) {
      while(i<3)

      { arr[i-1] = 1; i++; }

      }
      System.out.println("TEST 1 FAILED: " +
      "ArrayIndexOutOfBoundsException wasn't thrown");
      } catch (ArrayIndexOutOfBoundsException ae)

      { System.out.println("TEST 1 PASSED"); }

      i = 0;
      try {
      for(i=0; i<100000; i++) {
      if (i>5)

      { arr[i-100] = 1; i++; }

      }
      System.out.println("TEST 2 FAILED: " +
      "ArrayIndexOutOfBoundsException wasn't thrown");
      } catch (ArrayIndexOutOfBoundsException ae)

      { System.out.println("TEST 2 PASSED"); }

      }
      }

      Steps to Reproduce:
      Compile abcdTest class and run it on harmony with '-Xem:server_static'.

      Note:
      If remove loop variable constraints 'while(i<3)' , 'if(i>5)' in test1, test2 correspondingly, then abcdTest passes.

      Windows output:
      Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or its licensors,
      as applicable.
      java version "1.5.0"
      pre-alpha : not complete or compatible
      svn = r473012, (Nov 10 2006), Windows/ia32/msvc 1310, release build
      http://incubator.apache.org/harmony
      Start Test ...
      TEST 1 FAILED: ArrayIndexOutOfBoundsException wasn't thrown
      TEST 2 FAILED: ArrayIndexOutOfBoundsException wasn't thrown

      Linux output:
      Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or its licensors, as applicable.
      java version "1.5.0"
      pre-alpha : not complete or compatible
      svn = r473012, (Nov 10 2006), Linux/ia32/icc 900, release build
      http://incubator.apache.org/harmony
      Start Test ...
      TEST 1 FAILED: ArrayIndexOutOfBoundsException wasn't thrown
      TEST 2 FAILED: ArrayIndexOutOfBoundsException wasn't thrown

      Output on RI:
      Start Test ...
      TEST 1 PASSED
      TEST 2 PASSED

      Attachments

        1. abcdTest.java
          0.8 kB
          Elena Sayapina

        Activity

          People

            Unassigned Unassigned
            evs Elena Sayapina
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: