RFR: 8348668: Prevent first resource cleanup in confined arena from escaping [v2]
Jorn Vernee
jvernee at openjdk.org
Wed Jan 29 19:20:34 UTC 2025
> Currently, to free the memory allocated in a confined arena, we keep track of a list of 'cleanup actions', stored in linked list format in a so-called `ResourceList`, attached to the scope of the arena. When the scope is closed, we loop over all the entries in this resource list, and run all the cleanup actions one by one.
>
> However, due to this linked list format, plus the control flow introduced by the cleanup loop, C2's escape analysis can not keep track of the nodes of this linked list (`ResourceList.ResourceCleanup`), and as a result, they can not be scalar replaced.
>
> We can prevent just the first `ResourceCleanup` instance from escaping, by pulling out the first element of the list into a separate field. I also tried a setup where I had 2 separate fields for the first 2 elements, as well as a setup with an array with a fixed set of elements. While these also worked to prevent the first node from escaping, they were not able to provide the same benefit for multiple resource cleanup instances. Nevertheless, avoiding the allocation of the first element is relatively simple, and seems like a low-hanging fruit.
>
> I've changed the `AllocTest` benchmark a bit so that we don't return the `MemorySegment` in `alloc_confined`, which would make it always escape. That way, we can use this existing benchmark to test whether there are any allocations when calling `allocate` on a confined arena. This matches what we were doing in the other benchmark methods in the same class.
Jorn Vernee 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 seven additional commits since the last revision:
- update copyright year
- Merge branch 'master' into NoEscape
- polish v2
- simplify benchmark
- polish
- One element cache
- fix bench
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/23321/files
- new: https://git.openjdk.org/jdk/pull/23321/files/dc386bbe..05774fc2
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=23321&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=23321&range=00-01
Stats: 21481 lines in 2734 files changed: 9957 ins; 5708 del; 5816 mod
Patch: https://git.openjdk.org/jdk/pull/23321.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/23321/head:pull/23321
PR: https://git.openjdk.org/jdk/pull/23321
More information about the core-libs-dev
mailing list