This is the mail archive of the java@gcc.gnu.org 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]
Other format: [Raw text]

Re: Cost of having try-catch statements?


Hi there,

I was wondering: Is there any significant cost in having "unused" try-catches in my code? That is, I have a method that 99.99% of the times invoked never throws a given exception. However, in case it does, I need to log it...
The only cost is the unwinder tables, (which are not read into memory unless your exception is thrown) and the handler itself, which may cause some instruction cache presure.
So practically no overhead?
That's the idea. Really, if there is any significant overhead for an unused handler that would be a bug.
Great... I wouldn't like changing good coding manner...

This seems to indicate that in both gcj and J2SDK1.4.2_04 on Windows there is significant overhead. (And that the Sun JVM seems to be 4 times faster at this contrived "benchmark").
Ah yes, Windows still uses longjmp.
Similar hardware, Linux:
without try/catch 207ms with try/catch 227ms without try/catch 202ms
 with try/catch 209ms
Perfect, I'm running Linux on a PPC405! Thanks _alot_ for the answers...

Regards,
 Martin Egholm


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