This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Exception Handling
Andrew Haley writes:
> Vincent Gable writes:
> >
> > Does anybody know why exceptions in gcj are so slow? How are they
> > currently implemented?
I just had a look at the exception benchmark. It's this:
for(int i = 0; i < THROWS; i++) {
try {
throw exc;
} catch(MyException e) { }
}
There's a few reasons why this isn't a good way to measure things.
Firstly, the compiler can trivially determine that the exception
doesn't escape this context, and that the catch region doesn't
actually do anything, so it's not necessary to create the exception.
We could do this in gcj, but I'm somewhat doubtful that it would
affect any real world programs.
Also, adding all the runtimes of the different tests together without
assigning equal weightings is not going to get a reasonable result.
In benchmarks like this, it makes far more sense to combine the
runtimes by taking the geometric mean: multiply all the runtimes
together and take the Nth root.
Useful benchmarks do more things in a way that represents real world
patterns of execution. This is important, because otherwise
optimizations can determine that a program does nothing and optimize
it completely, but real world programs hopefully don't do nothing at
all!
I don't know what the dynamic exceution ratio of try blocks to throw
statements is, but I would guess at least 1000:1. There must be a
study somewhere, but I can't find it.
If that 1000:1 guess is right, then a better comparison is
for(int i = 0; i < THROWS; i++) {
try {
if (i % 1000 == 0)
throw exc;
} catch(MyException e) { }
}
There's a recent thread on benchmarks at
http://lists.gnu.org/archive/html/classpath/2004-06/msg00038.html.
Andrew.