[concurrency-interest] Explicitly initializing volatile fields with default values

Doug Lea dl at cs.oswego.edu
Thu Dec 17 19:53:24 EST 2015

On 12/17/2015 04:36 PM, Aleksey Shipilev wrote:

>   * Since Case A and Case B cover all possible variables (with the
> exception of the volatile field itself), this seems to imply that
> explicit field initializers that store default values have no effect on
> memory ordering.
> Is it a correct way to think about it?

Yes. Without a machine-checkable JLS and JMM formalization, it's hard to prove
this definitively. But your account is a more careful version of reasoning
we've done before to conclude that there is never any reason to explicitly
initialize fields to 0/0.0/false/null. (There might be traces of these
discussions in the original JSR133 mail archives.)

Some people like to explicitly initialize to 0/0.0/false/null for clarity.
Arguably javac should not penalize this by generating unnecessary code.


More information about the Concurrency-interest mailing list