This is the mail archive of the java-discuss@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Array bounds checks


Per Bothner wrote:

> But as for the questions why the compiler cannot optimize away the
> bounds check in your example, I don't know.

Upon further investigation, it appears that gcc doesn't do value range
propagation at all, yet. There is a patch to do it, however:

http://gcc.gnu.org/ml/gcc/2000-02/msg00103.html
http://gcc.gnu.org/ml/gcc-patches/2000-07/msg00968.html

My understanding is that it would only work for loops bounded by
constants, so the bounds check would be removed for a case such as the
following:

static final int LEN = ...;

int[] array = new int[LEN];

for (int i=0; i < LEN; i++)
  {
    array[i] = ...;
  }

In reality I don't think it will, however, because the optimizer won't see
array.length as a constant. Presumably, it would it help things if the
front end were to set array.length explicitly, rather than having the
runtime do it via _Jv_NewArray(), thus allowing constant propagation to
take effect?

regards

  [ bryce ]



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]