RFR: JDK-8317661: [REDO] store/load order not preserved when handling memory pool due to weakly ordered memory architecture of aarch64
Damon Fenacci
dfenacci at openjdk.org
Thu Oct 19 14:12:08 UTC 2023
On Thu, 19 Oct 2023 05:23:22 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> @dholmes-ora you’re right, it is quite difficult to get the whole picture: let me try to make it a bit clearer (I hope it makes sense).
>>
>> The issue originates here:
>> https://github.com/openjdk/jdk/blob/138542de7889e8002df0e15a79e31d824c6a0473/src/hotspot/share/services/memoryPool.cpp#L181-L182
>> We want to ensure that the values used to calculate `committed` are actually saved before the values used to calculate `used` are used.
>>
>> The problem starts in `CodeCache::allocate`. First `CodeHeap::allocate` is called and if there is not enough space we call `CodeHeap::expand_by` and retry `CodeHeap::allocate` (while loop):
>> https://github.com/openjdk/jdk/blob/e510dee162612d9a706ba54d0ab79a49139e77d8/src/hotspot/share/code/codeCache.cpp#L535-L537
>> During the second call of `CodeHeap::allocate` we update the values used to calculate the `used` variable (`_next_segment` in particular since it is the last to be updated) and we want to make sure that when we read it, all earlier values have been written.
>>
>> As for the link between `used` and `_next_segment`, `used` is calculated here
>> https://github.com/openjdk/jdk/blob/e510dee162612d9a706ba54d0ab79a49139e77d8/src/hotspot/share/memory/heap.cpp#L556 from `_next_segment` and `_freelist_segments`. `_next_segment` is the last to be written and it is updated here
>> https://github.com/openjdk/jdk/blob/e510dee162612d9a706ba54d0ab79a49139e77d8/src/hotspot/share/memory/heap.cpp#L306 which is called from `CodeCache::allocate`
>> https://github.com/openjdk/jdk/blob/e510dee162612d9a706ba54d0ab79a49139e77d8/src/hotspot/share/code/codeCache.cpp#L535
>
> Sorry I'm still missing part of this (and I know we discussed it a few weeks ago). What is the variable(s) that is written before `_next_segment` that we need to see updated when we call `_codeHeap->capacity()`?
Basically it would be the field `VirtualSpace::_high`. `_codeHeap->capacity()` calls `VirtualSpace::committed_size` which reads the `_high` and `_low` fields: https://github.com/openjdk/jdk/blob/e510dee162612d9a706ba54d0ab79a49139e77d8/src/hotspot/share/memory/virtualspace.cpp#L768-L770
`_low` doesn't really get updated but `_high` is increased in `VirtualSpace::expand_by`, which is called by `CodeHeap::expand_by` https://github.com/openjdk/jdk/blob/e510dee162612d9a706ba54d0ab79a49139e77d8/src/hotspot/share/memory/heap.cpp#L259 which in turn is called in `CodeCache::allocate`: https://github.com/openjdk/jdk/blob/e510dee162612d9a706ba54d0ab79a49139e77d8/src/hotspot/share/code/codeCache.cpp#L537
@dholmes-ora is there possibly a way to restrict the update that we need to see to that `_high` variable only?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16143#discussion_r1365596432
PR Review Comment: https://git.openjdk.org/jdk/pull/16143#discussion_r1365607442
More information about the hotspot-runtime-dev
mailing list