[foreign-memaccess+abi] RFR: 8266814: Improve library loading with SymbolLookup abstraction

Athijegannathan Sundararajan sundar at openjdk.java.net
Mon May 10 14:29:19 UTC 2021

On Mon, 10 May 2021 13:55:44 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This patch implements the library loading abstraction described in:
> https://mail.openjdk.java.net/pipermail/panama-dev/2021-May/013684.html
> That is, a functional interface called `SymbolLookup`, and a couple of factories to get a lookup for a given classloader, and to get a *system* lookup, useful to lookup C symbols.
> To implement the system lookup, we load `msvcrt.dll` on Windows, while we build and load an empty library (which depends on libc) on Mac/Linux. This approach is better than relying on RTLD_DEFAULT (which can sometimes leak symbols from libraries loaded independently). Also, doing this bypasses the problem of figuring out the location of libc, which, on Linux system is particularly gnarly, because of the multi-arch support.

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SymbolLookup.java line 60:

> 58:      * restricted methods, and use safe and supported functionalities, where possible.
> 59:      *
> 60:      * @return a symbol lookup suitable to find symbols in libraries loaded by given classloader.

"by given classloader" should be "by the caller's class loader"

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/SymbolLookup.java line 85:

> 83:     static SymbolLookup loaderLookup(ClassLoader loader) {
> 84:         Reflection.ensureNativeAccess(Reflection.getCallerClass());
> 85:         Objects.requireNonNull(loader);

why do we filter null (bootstrap) loader?

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/package-info.java line 100:

> 98:  * <h2>Foreign function access</h2>
> 99:  * The key abstractions introduced to support foreign function access are {@link jdk.incubator.foreign.SymbolLookup} and {@link jdk.incubator.foreign.CLinker}.
> 100:  * The former is used to load foreign libraries, as well as to lookup symbols inside said libraries; the latter

"is used to load foreign libraries" should be removed?


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

More information about the panama-dev mailing list