This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: exceptions and threads---a survival tactic!
- To: branko dot cibej at hermes dot si (Branko Cibej)
- Subject: Re: exceptions and threads---a survival tactic!
- From: Joe Buck <jbuck at synopsys dot com>
- Date: Thu, 12 Mar 98 11:28:49 PST
- Cc: jbuck at synopsys dot com, kaz at cafe dot net, egcs at cygnus dot com
> > ... He finds that, for very large arrays,
> >
> > try {
> > for (int i = 0; ; i++) {
> > anInt[i] = i;
> > }
> > }
> > catch (ArrayIndexOutOfBoundsException e) {}
> >
> > is 30-40% faster on JDK 1.1.3 (Sun's Windows version) than the traditional
> >
> > for (int i = 0; i < ARRAY_SIZE; i++) {
> > anInt[i] = i;
> > }
> >
> > (I suspect, though, that this is because there is a range check on each
> > array access in Java, so the traditional code does the same test twice).
> Aha! And someday, when (e)gcs gets a Java front-end, it could be taught
> to recognize the second form and optimize it to the first form, and at
> once become the best Java optimizing compiler available.
Actually, I suspect that for JIT compilers the second form is better,
since it would be fairly trivial to eliminate the range check. In fact,
one point made by the Byte article is that in Microsoft's implementation
the *second* form is faster (in Sun's implementation try blocks add zero
cost but in Microsoft's try blocks slow things down, indicating a
completely different way of implementing exceptions), meaning that if you
care about performance, Java isn't really portable: you have to know which
implementation your users will be running.