final vs. volatile instance fields
sergey.kuksenko at oracle.com
Wed Dec 26 04:30:24 PST 2012
You may find a general (not exactly about hotspot) answer in "The
JSR-133 Cookbook for Compiler Writers".
On 12/26/2012 03:58 PM, Peter Levart wrote:
> Hi hotspot gurus,
> I have a question (actually two) someone might answer off the top of
> his/her hat:
> Are there any performance differences in reading and writing of volatile
> vs. final instance fields? I can see that reflection is doing the same
> for both types (via UnsafeQualifiedFieldAccessorImpl subtypes) and is
> reading/writing the fields using Unsafe.getXxxVolatile/putXxxVolatile.
> So what does the JIT compiled code do?
> a) Are there any differences between writing to those two types of
> fields? The Java spec. mandates writing to final fields exactly once in
> the constructors and Java Memory Model says that they are "frozen" at
> the end of constructor. What does "freeze" actually translate to in the
> compiled code?
> b) I can understand that the JIT compiler can generate code that caches
> the value of final field say in a register, but initially the code has
> to load the value from a final field and the question is whether this
> initial load is any different from a volatile read?
> Thank you,
More information about the hotspot-runtime-dev