On 6 August 2013 07:14, Ian Boston <i...@tfd.co.uk> wrote:

>
> Finally, ;) , last time I read the java memory management docs and
> hotspot description, IIRC, final can prevent hotspot optimising the
> code, so some versions strip it or ignore it. I would have to find the
> detail to be certain of that.
>


[1] Page 25 indicates the problems associated with using final on
fields, not least that if it is relied upon to isolate a class during
construction that can't be guaranteed. Also, don't forget,
serialisation and reflection make it possible to bypass final.

Also [2] which is a little old has some views on the subject as does
[3], not all of the pointers are relevant to final classes and final
is not all bad but as [2] says its overused and sometimes in the wrong
way which can lead to problems downstream.

Part of Java's speed under load is the ability to dynamically inline
methods. To do that methods must be small. Putting final keywords in
on methods and classes blocks extension (fields are possibly ok) which
results in more, cooler spots from a hotspot point of view, resulting
less efficient runtime optimisation, and relying entirely on the
programmer to know everything about the runtime to deliver better than
interpreted speed.

But I am +1 on documentation and any other methods we can find to
indicate our intention.

Ian

1 http://www.cs.umd.edu/~pugh/java/memoryModel/jsr133.pdf
2 http://www.ibm.com/developerworks/java/library/j-jtp1029/index.html
3 http://www.oracle.com/technetwork/java/whitepaper-135217.html#impact

Reply via email to