RFR: 8288327: Executable.hasRealParameterData should not be volatile [v3]
ExE Boss
duke at openjdk.org
Fri Jun 17 10:43:01 UTC 2022
On Fri, 17 Jun 2022 09:29:22 GMT, Сергей Цыпанов <duke at openjdk.org> wrote:
>> If there are two threads calling `Executable.hasRealParameterData()` under race and the first one writes into volatile `Executable.parameters` field (doing _releasing store_) and the second thread reads non-null value from the same field (doing acquiring read) then it must read exactly the same value written into `hasRealParameterData` within `privateGetParameters()`. The reason for this is that we assign `hasRealParameterData` before _releasing store_.
>>
>> In the opposite case (_acquiring read_ reads null) the second thread writes the value itself and returns it from the method so there is no change in behavior.
>
> Сергей Цыпанов has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:
>
> - Merge branch 'master' into 8288327
> - 8288327: Use record store
> - 8288327: Add clarifying comments
> - 8288327: Executable.hasRealParameterData should not be volatile
src/java.base/share/classes/java/lang/reflect/Executable.java line 777:
> 775: }
> 776:
> 777: record ParameterData(Parameter[] parameters, boolean real) {}
The `ParameterData.parameters` field can probably be marked as [`@Stable`] (since the `parameters` array is never modified):
Suggestion:
record ParameterData(@Stable Parameter[] parameters, boolean real) {}
Also the `real` record component should probably be renamed to `isReal` as @liach suggested in [GH‑9143 (comment)].
[GH‑9143 (comment)]: https://urldefense.com/v3/__https://github.com/openjdk/jdk/pull/9143*discussion_r899802093__;Iw!!ACWV5N9M2RV99hQ!OeL5Zo46nS8lb1vkbw1RNZVCCXGuOaxOVhP-yBBYLYoIlq4QhUjuO5GL-gf8bJNP2adueR7So62POAr5EyKP$
[`@Stable`]: https://urldefense.com/v3/__https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/jdk/internal/vm/annotation/Stable.java__;!!ACWV5N9M2RV99hQ!OeL5Zo46nS8lb1vkbw1RNZVCCXGuOaxOVhP-yBBYLYoIlq4QhUjuO5GL-gf8bJNP2adueR7So62POFGSimfz$
-------------
PR: https://git.openjdk.org/jdk/pull/9143
More information about the core-libs-dev
mailing list