[foreign-preview] RFR: 8276648: Downcall stubs are never freed
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Tue Feb 22 14:52:13 UTC 2022
On Tue, 22 Feb 2022 14:06:28 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
> Hi,
>
> The current code adds native invokers (downcall stubs) to a CocurrentHashMap cache, and they stay there until the application exits.
>
> This patch replaces that cache with a SoftReferenceCache (brought to the top level from AbstractLinker), which allows at least the values to be evicted when they become unreachable.
>
> Those value, which are NativeEntryPoint instances, are also registered with a cleaner, whose cleanup action will free the stub from the code cache.
>
> Thanks,
> Jorn
Looks good
src/java.base/share/classes/jdk/internal/foreign/abi/NativeEntryPoint.java line 68:
> 66:
> 67: CacheKey key = new CacheKey(methodType, abi, Arrays.asList(argMoves), Arrays.asList(returnMoves), needsReturnBuffer);
> 68: return INVOKER_CACHE.get(key, k -> {
This uses a combination of soft references (cache) and phantom references (cleaner). So, cache entries will be evicted when the NEP is softly reachable - meaning that the GC will clear the entries when under pressure. But the cleaner won't be able to run until the entry is evicted (because the entry has a soft reference to the NEP, and to be phantom-reachable you need NOT to be soft-reachable). Assuming that's what you want, then it looks ok. E.g. the cleaner here will "just" make sure that some action is executed when the entry is evicted.
-------------
Marked as reviewed by mcimadamore (Committer).
PR: https://git.openjdk.java.net/panama-foreign/pull/651
More information about the panama-dev
mailing list