Hi Igor,
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 22, 2000 9:02 AM
> Subject: Re: Why catch (NullPointerException e)?
>
> ---- Ian wrote:
> > I agree, however, the explicit null check will slow
> > down the execution speed of applets.
>
> Why? In case of a JIT or compiled Java for applets "if (sm !=
> null)" will be branch predicted and cause no harm at all.
> Moreover, AFAIK try/catch in general produce more code and
> even if it is never executed it still can cause more
> processor cache misses.
We're still talking about the scenario in which the reference is very rarely
null, right?
Try/catch may indeed produce more code, but it will be distributed unevenly.
The hot path ("sm!=null") will be shorter (because there's no check), but
the cold path (with the exception handler) will possibly become longer. Any
good JIT compiler will put cold and hot code away from each other, so in the
common case we should have fewer cache misses if we use the OS to catch null
pointer exceptions.
Michal