RFR: JDK-8317661: [REDO] store/load order not preserved when handling memory pool due to weakly ordered memory architecture of aarch64

David Holmes dholmes at openjdk.org
Thu Oct 19 05:25:56 UTC 2023


On Wed, 18 Oct 2023 10:19:32 GMT, Damon Fenacci <dfenacci at openjdk.org> wrote:

>> src/hotspot/share/memory/heap.cpp line 306:
>> 
>>> 304:     block = block_at(_next_segment);
>>> 305:     block->initialize(number_of_segments);
>>> 306:     Atomic::release_store(&_next_segment, _next_segment + number_of_segments);
>> 
>> When we do the release here, what previous stores are we trying to order with the reading code below? It is hard to see the complete picture with this code just from the PR changes.
>
> @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()`?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16143#discussion_r1364910367


More information about the hotspot-runtime-dev mailing list