This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: exceptions and threads---a survival tactic!




Joe Buck wrote:

> > The fact is, with properly implemented exception-handling code that *does*
> > care about runtime overhead, you can write much faster code by using EH for
> > flow control than by the traditional "if (foo) bar(); else baz();" method.
>
> Yes, and this can be even more true in Java.  The March '98 issue of Byte
> has a piece by David Orchard entitled "Better Performance With Exceptions
> in Java".  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.

(Would this be called "range check elimination"? :-)

--
Branko Cibej   <branko.cibej@hermes.si>
HERMES SoftLab, Litijska 51, 1000 Ljubljana, Slovenia
phone: (++386 61) 186 53 49  fax: (++386 61) 186 52 70




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