RFR: 8254275: Development to revise "value-based class" & apply to wrappers [v2]
Dan Smith
dlsmith at openjdk.java.net
Fri Oct 16 17:38:21 UTC 2020
On Wed, 14 Oct 2020 20:08:32 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
>> Dan Smith has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Revise definition for more flexible ==. Apply revised boilerplate to wrappers and existing references.
>
> src/java.base/share/classes/java/lang/doc-files/ValueBased.html line 70:
>
>> 68: <p>Synchronization on instances of value-based classes is strongly discouraged,
>> 69: because the programmer cannot usually guarantee unique ownership of the
>> 70: associated lock.</p>
>
> I don't think the phrase:
> `because the programmer cannot usually guarantee unique ownership of the associated lock.`
> adds anything and is obscure. Until the semantics of object change, there is no change in the synchronization behavior.
> For Valhalla value-based instances, there is explicitly no (implicitly) associated lock, so synchronization is illegal.
The point is that if you can't prove you have a unique identity (per the factory method clause), then you can't
guarantee that you have exclusive control over the monitor, so synchronization is dangerous. A variant of the text
discouraging synchronization was there before any design discussions about primitive object semantics.
I added "usually" because of the possibility that someone can prove that a field value they provide is unique
(according to 'equals') and thus can prove that the value-based class instance is also unique. But when I think about
actual examples of value-based classes, that seems quite unlikely, and it would probably be clearer to remove the
"usually".
-------------
PR: https://git.openjdk.java.net/valhalla/pull/222
More information about the valhalla-dev
mailing list