RFR: 8318720: G1: Memory leak in G1CodeRootSet after JDK-8315503

Thomas Schatzl tschatzl at openjdk.org
Wed Oct 25 08:15:30 UTC 2023


On Tue, 24 Oct 2023 23:04:28 GMT, Zhengyu Gu <zgu at openjdk.org> wrote:

> Calling `ConcurrentHashTable:table.unsafe_reset()` in `G1CodeRootSet::clear()` does not free the entries that still in the table. This patch empties the table before the `unsafe_reset()` call to avoid memory leak.
> 
> Test:
>  tier1 and tier2 (fastdebug and release) on Linux x86_64

Changes requested by tschatzl (Reviewer).

src/hotspot/share/gc/g1/g1CodeRootSet.cpp line 164:

> 162:       Atomic::store(&_num_entries, (size_t)0);
> 163:     }
> 164:     _table.unsafe_reset();

Thanks for catching this!

 I believe something like a call to `_table.clean([] (nmethod** value) { return true; });` should do roughly the same. (It is fine to name the lambda with something meaningful, like `always_true`. Or `delete_all`. `do_value` is just too unspecific to me).

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

PR Review: https://git.openjdk.org/jdk/pull/16352#pullrequestreview-1696648989
PR Review Comment: https://git.openjdk.org/jdk/pull/16352#discussion_r1371335267


More information about the hotspot-gc-dev mailing list