final field values should be trusted as constant (filed as JDK-8233873)

Doug Lea dl at cs.oswego.edu
Sat Nov 9 19:21:00 UTC 2019


On 11/8/19 8:24 PM, John Rose wrote:

> ## Side note on races
> 
> Although race conditions (on non-volatile fields) allow the JVM some
> latitute to return "stale" values for field references, such latitude
> would usually be quite narrow, since an execution of the invalid
> optimized method is likely to occur downstream of the invalidating
> field update (as determined by the happens-before relation of the
> JMM). 

Ever since initial revisions of JLS1 version, the intent of JMM specs
(including current) is to allow compilers to believe that the value they
see in initial reads of a final field is the only value they will ever
see. So no revision is necessary on these grounds (although one of these
days there will be one that accommodates VarHandle modes etc,
formalizing http://gee.cs.oswego.edu/dl/html/j9mm.html). Some of the
spec messiness exists just to explain why compilers are allowed not to
believe this as well, because of reflection etc.

In other words, don't let JMM concerns stop you from this worthwhile effort.

-Doug



More information about the hotspot-compiler-dev mailing list