Kevan wrote: > On Jun 2, 2011, at 6:39 PM, Alasdair Nottingham wrote: > > > Is that claim about final methods true of all JVMs do you know? I > know different JVMs tend to have different JITs so I was wondering > if they are talking about just the hotspur JVM? > > I've asked some JVM types to see if I can find any data on this. Is > there any evidence that a 'final method' makes a difference on any JVM's? > > Initial general advice I've gotten back (which would fit with my > general outlook on the subject) was: don't write code for JIT > optimization until warranted and well understood... Hopefully, I'll > hear back on some specifics of JIT behavior.
I'd concur with this. I think a few years ago, adding final modifiers to methods was a reasonable optimisation, because it avoided the expenses of virtual methods. Now, (at least some) JITs will assume methods aren't virtual (when they're not overridden), and then dynamically detect overloading and go through a de-compile un-unline re-compile loop if the situation changes. So a non-overridden non-final method will have the same performance as a final method. JITs are pretty smart things and they tend to be optimised for the most popular development practices, rather than the 'cleverest' code. Holly Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
