By: Rob Thorpe (rthorpe.delete@this.realworldtech.com), October 27, 2006 4:38 am
Room: Moderated Discussions
I've had a through look on the web. It seems that this issue has come up in the Java community. In particular William Pugh, Tim Lindholm and Doug Lea have looked at it.
It seems that the original Java specs were vague on the issue we are discussing. Later it came to be accepted that it's possible for objects to be modified (due to reordering) before the constructor has completed! This is actually what happens in some JVMs. According to Pugh's page in the past JVMs on platforms with quite strong memory consistency still failed because of compiler optimizations people had put in without checking their validity.
A JSR, number 133, has been written to change this behaviour. This JSR introduces the concept of "final" variables which solve the problem to some extent. JSR133 will be fully implemented in Java 1.5 apparently, though some is in 1.4.
This means current Javas are only really SAFE1 and future Javas will only be SAFE1 too, unless all fields in objects are declared "final".
See:-
IBM developerworks article on the subject (see section on initialization safety)
http://www-128.ibm.com/developerworks/java/library/j-jtp03304/
Pugh's original description of the problem
http://www.cs.umd.edu/~pugh/java/broken.pdf
The draft JSR133 spec. See especially page 13 & 14 referring to this problem
http://www.cs.umd.edu/~pugh/java/memoryModel/CurrentDraftSpec.pdf
The Java community process JSR133 page
http://jcp.org/en/jsr/detail?id=133
It seems that the original Java specs were vague on the issue we are discussing. Later it came to be accepted that it's possible for objects to be modified (due to reordering) before the constructor has completed! This is actually what happens in some JVMs. According to Pugh's page in the past JVMs on platforms with quite strong memory consistency still failed because of compiler optimizations people had put in without checking their validity.
A JSR, number 133, has been written to change this behaviour. This JSR introduces the concept of "final" variables which solve the problem to some extent. JSR133 will be fully implemented in Java 1.5 apparently, though some is in 1.4.
This means current Javas are only really SAFE1 and future Javas will only be SAFE1 too, unless all fields in objects are declared "final".
See:-
IBM developerworks article on the subject (see section on initialization safety)
http://www-128.ibm.com/developerworks/java/library/j-jtp03304/
Pugh's original description of the problem
http://www.cs.umd.edu/~pugh/java/broken.pdf
The draft JSR133 spec. See especially page 13 & 14 referring to this problem
http://www.cs.umd.edu/~pugh/java/memoryModel/CurrentDraftSpec.pdf
The Java community process JSR133 page
http://jcp.org/en/jsr/detail?id=133