Previously, we had said that we were changing the JVM requirements for
when final fields could be updated to be consistent with the JLS.
Gilad talked to me and said that they didn't really want to force the
JVM verifier to check for definite assignment. The verifier is already
complex, fragile and uses too many resources.
Instead, he suggested that we limit writes to final fields to the
methods in which those fields are allowed to be updated by the JLS.
However, the JVM will allow a final field to updated zero times, once,
or multiple times during construction (unlike the JLS, which requires
that it be updated exactly once). This is almost the same as saying
that a final field can be updated by a putfield only in a constructor
for the instance, but you also have to deal with constructors that
chain to other constructors of the same class (such constructors cannot
update final fields using putfield). Static fields can be updated by
putstatic only in the static initializer for the class.
This doesn't require any changes to the semantics for final fields. The
right thing just happens if a final field is written multiple times
(assuming the object is published correctly): the last write is the one
that counts.
Unless someone comes up with a show stopper as to why we shouldn't
allow this relaxation of the JVM spec on final fields, we will change
the spec accordingly.
Bill
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:08 EDT