-
Sub-task
-
Resolution: Fixed
-
P3
-
None
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8084587 | emb-9 | Chris Hegarty | P3 | Resolved | Fixed | team |
To adhere to final field semantics Serialization should issue a "freeze action" after reconstituting objects that have values set on their final fields, see JLS 17.5 [1].
A number of years ago there was a proposal to use Unsafe.put*Volatile methods to set final fields during default deserialisation,JDK-6647361 [2][3], but it never made it due to concerns about the potential negative impact of the additional fences. Now we have a, private, fences API in the platform, I think it is time to revisit this.
Note:
Section 17.5.3 in the JLS [3], “Freezes of a final field occur both
at the end of the constructor in which the final field is set, and
immediately after each modification of a final field via reflection
or other special mechanism.” I believe this is a consequence of
the way in which setting of final fields is supported in the public
API, Field.setAccessible(), ( as defined by JSR 133 ) and should
not restrict an implementation from using a more performant
means, as is suggested here. The statement in the JLS should
be revisited.
[1] http://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5
[2] https://bugs.openjdk.java.net/browse/JDK-6647361
[3] http://mail.openjdk.java.net/pipermail/core-libs-dev/2010-November/005292.html
http://mail.openjdk.java.net/pipermail/core-libs-dev/2010-December/005456.html
[4] http://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5.3
A number of years ago there was a proposal to use Unsafe.put*Volatile methods to set final fields during default deserialisation,
Note:
Section 17.5.3 in the JLS [3], “Freezes of a final field occur both
at the end of the constructor in which the final field is set, and
immediately after each modification of a final field via reflection
or other special mechanism.” I believe this is a consequence of
the way in which setting of final fields is supported in the public
API, Field.setAccessible(), ( as defined by JSR 133 ) and should
not restrict an implementation from using a more performant
means, as is suggested here. The statement in the JLS should
be revisited.
[1] http://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5
[2] https://bugs.openjdk.java.net/browse/JDK-6647361
[3] http://mail.openjdk.java.net/pipermail/core-libs-dev/2010-November/005292.html
http://mail.openjdk.java.net/pipermail/core-libs-dev/2010-December/005456.html
[4] http://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5.3
- backported by
-
JDK-8084587 Serialization should issue a freeze action after reconstituting a graph that contains objects with final fields
-
- Resolved
-
- relates to
-
JDK-6647361 use Unsafe.put*Volatile methods to set final fields during default deserialization
-
- Closed
-