RFR: 8288904: Incorrect memory ordering in UL [v2]
Patricio Chilano Mateo
pchilanomate at openjdk.org
Wed Jun 22 20:42:34 UTC 2022
On Wed, 22 Jun 2022 20:17:48 GMT, Erik Österlund <eosterlund at openjdk.org> wrote:
>> I'm going by ARM's memory model, which is understood by me as something like: "Any nondependent loads and stores may be observed in a different order than program order". Dependency here means register or address dependency.
>>
>> I think your program is allowed to crash, because I think you're invoking UB by making and dereferencing a pointer to random memory.
>
> I suppose the memory state change due to calling free on a node can reorder to before the load checking there are no readers. The. The memory can appear to be free memory and get allocated to random other memory that changes state arbitrarily, while there is still a concurrent reader.
Right but isn't there a control dependency that the hardware will still obey? Or can the hardware write to memory even if that path is never taken?
Regarding UB, I could paste the assembly of that instead (maybe I should have done that). My question was whether the cpu can execute that write instruction before even knowing if that branch will be taken.
Note: I found this interesting article about control dependencies (https://urldefense.com/v3/__https://lwn.net/Articles/860037/__;!!ACWV5N9M2RV99hQ!ONppXCB70bV7ccOwZEwlx-8yzEYb9NeIOdBFO6jpAxIJ-UUqDpaa9ySnJuhOrdFotRUvhQ_fpdyies-UqGWnrtmKxxqCFxa4A3IB$ ). It mentions that the hardware will respect that dependency but there could be some aggressive compiler optimizations on some cases. I don't think that applies here though.
@fisk sorry, not sure I understood the example.
-------------
PR: https://git.openjdk.org/jdk/pull/9225
More information about the hotspot-runtime-dev
mailing list