Array bounds checks

Boehm, Hans hans_boehm@hp.com
Thu Oct 26 12:03:00 GMT 2000


> Some compilers generate code twice:
> 
>    if (upper < array.length)
>      for (int i = 0;  i < upper; i++)
>         ... no bounds checking ...
>    else
>      for (int i = 0;  i < upper; i++)
>         ... with bounds checking ...
> 
> I don't particularly care for this idea ...
> 
My impression was that you could get more mileage out of this approach by
also checking for other properties when you decide which version to use.  In
particular multianewarray should potentially be able to tag the arrays it
allocates as rectangular and contiguously allocated, and you should be able
to check for that case here, thus reducing multidimensional array access
back to the Fortran case (at the risk of retaining more memory than needed).
I have no idea whether anyone has ever done this, or whether it's really
feasible/worthwhile.

Hans


More information about the Java mailing list