RE: JavaMemoryModel: Unexpected weakness/divergence in old JVM spec of final fields

From: David Holmes (dholmes@dltech.com.au)
Date: Sun Dec 28 2003 - 20:07:24 EST


Bill Pugh wrote:

> Steve Dever from Sun pointed out that the old JVM spec for final
> fields has a far weaker definition than the JLS spec.
>
> The only restriction on final fields I could find in the
> JVM spec is that write-access to final fields is private.

Bill, this issue was raised in October (see mailing subject RE:
JavaMemoryModel: Final Means Different Things To VM and Java Language.
Does That Impact JITs?). Apart from the necessary but insufficient
restriction in PUTFIELD, the description of the ACC_FINAL bit also
defines semantics: JVMS Section 4.5 Table 4.4 - ACC_FINAL: Declared
final; no further assignment after initialization.

As discussed in those earlier emails it can be interpreted that the
JVMS does preclude assignment to final fields outside of
initialization code, but that the JVMS does not explicitly mandate
detection of this by the PUTFIELD/PUTSTATIC implementation.

> Option 1:
> We continue as planned, bring the restrictions on final fields in
> bytecode in sync with those in the JLS (e.g., every final
> field must
> be written to exactly once in a constructor, or in the static
> initializer for final static fields).

The current spec for ACC_FINAL already states this (in loose terms).
Do we require that either:

a) PUTFIELD/PUTSTATIC check for this; or
b) that the verifier check for this?

Regards,
David Holmes

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:55 EDT