Consider the following function:
int foo(int[] indices) {
int[] lookup = new int[256];
fill(lookup); // populate values, not shown
int sum = 0;
for (int i : indices) {
sum += lookup[i & 0xFF]; // array access
}
return sum;
}
Can modern HotSpot eliminate the bounds check on the lookup[i & 0xFF]
access? This access cannot be out of bounds since i & 0xFF
is in the range 0-255 and the array has 256 elements.