[foreign-jextract] RFR: 8253307: Simplify code in RuntimeHelper::lookupGlobalVariable

Athijegannathan Sundararajan sundar at openjdk.java.net
Fri Sep 18 09:15:01 UTC 2020


On Thu, 17 Sep 2020 20:37:07 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> Earlier today, I added a workaround on RuntimeHelper when I tweaked it to use the new
> MemoryAddress::asSegmentRestricted API. The old code was adding the lookup symbol as an attachment to the returned
> segment, so I did a workaround to do just that under the new API.
> Turns out that the workaround wasn't needed (I think). Upon more thinking, I realized that we always store an array of
> LibraryLookup inside the very constant holder class - either as a static field, or as a dynamically loaded constant.
> I think in both cases that should be enough to prevent the lookup object from going unreachable.

While this solves the issue for for jextract which keeps LinkerLookups, as a general API usage, this should be
documented then i.e, it is up to the user to keep linker lookup objects alive

In the JNI world this problem does not arise because NativeLibrary is always loaded in the context of the class loader
that loaded and so native libraries are alive as long as the class loader is alive.

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

Marked as reviewed by sundar (Committer).

PR: https://git.openjdk.java.net/panama-foreign/pull/339


More information about the panama-dev mailing list