We noticed that the test program below fails.
The arraycopy call has to throw an IndexOutOfBoundsException because the length is -1. We can see this happening when we switch off EliminateAllocations (or DoEscapeAnalysis).
Seems like PhaseMacroExpand::process_users_of_allocation removes the ArrayCopyNode without checking the parameters. After the ArrayCopyNode is removed, the parameters are no longer checked and no exception is thrown.
TestArrayCopyMinusOne.java
public class TestArrayCopyMinusOne{
public boolean do_test() {
try {
System.arraycopy(new Object[1], 1, new Object[1], 1, -1);
return false;
} catch (IndexOutOfBoundsException e) {
return true;
}
}
static final int loop_cnt=100000;
public static void main(String args[]){
TestArrayCopyMinusOne xyz = new TestArrayCopyMinusOne();
int errors = 0;
long duration = System.nanoTime();
for (int x = 0; x < loop_cnt; x++) {
if (!xyz.do_test()) errors++;
}
duration = System.nanoTime() - duration;
System.out.println("errors: " + errors + " (duration: " + duration/loop_cnt + ")");
}
}
The arraycopy call has to throw an IndexOutOfBoundsException because the length is -1. We can see this happening when we switch off EliminateAllocations (or DoEscapeAnalysis).
Seems like PhaseMacroExpand::process_users_of_allocation removes the ArrayCopyNode without checking the parameters. After the ArrayCopyNode is removed, the parameters are no longer checked and no exception is thrown.
TestArrayCopyMinusOne.java
public class TestArrayCopyMinusOne{
public boolean do_test() {
try {
System.arraycopy(new Object[1], 1, new Object[1], 1, -1);
return false;
} catch (IndexOutOfBoundsException e) {
return true;
}
}
static final int loop_cnt=100000;
public static void main(String args[]){
TestArrayCopyMinusOne xyz = new TestArrayCopyMinusOne();
int errors = 0;
long duration = System.nanoTime();
for (int x = 0; x < loop_cnt; x++) {
if (!xyz.do_test()) errors++;
}
duration = System.nanoTime() - duration;
System.out.println("errors: " + errors + " (duration: " + duration/loop_cnt + ")");
}
}
- is blocked by
-
JDK-8167578 C1: compiler.escapeAnalysis.TestArrayCopy fails to throw ArrayStoreException
-
- Closed
-
- relates to
-
JDK-8323682 C2: guard check is not generated in Arrays.copyOfRange intrinsic when allocation is eliminated by EA
-
- Resolved
-