[foreign-preview] RFR: 8282873: Bring back SymbolLookup

Maurizio Cimadamore mcimadamore at openjdk.java.net
Wed Mar 9 11:22:02 UTC 2022


On Wed, 9 Mar 2022 11:10:03 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This patch brings back the `SymbolLookup` abstraction, which was initially left behind during the move to java.base.
> 
> In hindsight, moving lookup capabilities to `CLinker` and `ClassLoader`, while economical in terms of API surface, is problematic, as it is much harder to users of the API to understand how to look up for library symbols (since lookup capabilities are scattered across different classes).
> 
> Moreover, recent JDK changes, such as JDK-8281335 and JDK-8282608, make library loading more flexible, and much closer to a raw dlopen/dlsym/dlclose. Which means we can now provide, in addition to loader and system lookup, a *third* kind of lookup, which features deterministic library loading/unloading (see `SymbolLoojup::libraryLookup`).
> 
> Overall, I think that having a dedicated abstraction for looking up symbols in libraries is a good thing; not only it makes the API more discoverable, but it also allows clients to define custom lookup (as `SymbolLookup` is a simple functional interface).

src/java.base/share/classes/java/lang/foreign/MemoryAddress.java line 127:

> 125:      * java.nio.charset.CharsetDecoder} class should be used when more control
> 126:      * over the decoding process is required.
> 127:      * <p>

This is unrelated, but I realized that this method javadoc was missing the "restricted" section.

src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java line 340:

> 338: 
> 339:     // lazy init MH_ALLOC and MH_FREE handles
> 340:     private static class AllocHolder {

These methods were no longer used - and I cleaned them up.

test/jdk/java/foreign/handles/lookup_module/handle/lookup/MethodHandleLookup.java line 129:

> 127:                             MethodType.methodType(void.class, ValueLayout.OfAddress.class, long.class, Addressable.class)),
> 128:                             "MemoryAddress::set/address" },
> 129:                     { MethodHandles.lookup().findVirtual(MemoryAddress.class, "getAtIndex",

I realized this class was not testing _all_ restricted methods - so I have added the missing test cases.

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

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


More information about the panama-dev mailing list