RFR: 8300148: Consider using a StoreStore barrier instead of Release barrier on ctor exit [v3]
Dean Long
dlong at openjdk.org
Thu Mar 28 20:43:31 UTC 2024
On Wed, 27 Mar 2024 22:28:26 GMT, Chen Liang <liach at openjdk.org> wrote:
>> Joshua Cao has updated the pull request incrementally with one additional commit since the last revision:
>>
>> EA tests, static test classes, add @requires, fix comment
>
> I heard rumors that storeStore is only safe for the scenarios where the constructor doesn't read its already assigned final fields; so if we have something like
>
> class Sample {
> final int a, b;
> Sample(int v) {
> this.a = v;
> this.b = this.a + 1; // performs read instance field before publication
> }
> }
>
> then we still need a regular release barrier.
>
> Am I correct here?
@liach, in your example, I don't see an issue, unless "this" somehow escaped and allowed another thread to write to this.a, which would be difficult considering it is "final". This earlier discussion might help:
https://mail.openjdk.org/pipermail/jmm-dev/2016-November/000381.html
-------------
PR Comment: https://git.openjdk.org/jdk/pull/18505#issuecomment-2026077050
More information about the hotspot-compiler-dev
mailing list