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)
}
System.out.println("TEST 1 FAILED: " +
"ArrayIndexOutOfBoundsException wasn't thrown");
} catch (ArrayIndexOutOfBoundsException ae)
i = 0;
try {
for(i=0; i<100000; i++) {
if (i>5)
}
System.out.println("TEST 2 FAILED: " +
"ArrayIndexOutOfBoundsException wasn't thrown");
} catch (ArrayIndexOutOfBoundsException ae)
}
}
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