RFR: 8355080: java.base/jdk.internal.foreign.SystemLookup.find() doesn't work on static JDK [v3]

Magnus Ihse Bursie ihse at openjdk.org
Mon Apr 28 19:50:52 UTC 2025


On Mon, 28 Apr 2025 08:30:43 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Jiangli Zhou has updated the pull request incrementally with two additional commits since the last revision:
>> 
>>  - Merge branch 'JDK-8355080' of ssh://github.com/jianglizhou/jdk into JDK-8355080
>>  - Address henryjen@ comment:
>>    - Remove '#include <jni.h>'.
>
> The changes here look good. Essentially, if `syslookup` is statically linked, trying to do a `dlopen` on it will fail, as the shared library for it doesn't exist. For this reason, this PR seems to "upgrade" syslookup to a JNI library. The presence of the `JNI_OnLoad_syslookup` is then used, as per [JEP 178](https://openjdk.org/jeps/178) to determine whether `syslookup` is a "builtin" library -- that is, a library for which no dynamic linking should occur.
> 
> The loaded library is associated with the boot classloader. This could be problematic, in principle. However, since the requests to `loadLibrary` also come from the boot loader (they are from the `SystemLookup` class) it all works out ok.
> 
> Having to upgrade to JNI is a bit sad -- although I get that it is required as a workaround for now. For the longer term I'd prefer a better way to integrate static lookups in the FFM API. For instance, all `JNI::loadLibrary` does when it comes to static libraries is to return the so called "process handle" -- e.g. a handle to the running process (the JVM). If there was a way to retrieve such a handle (e.g. via a dedicated `SymbolLookup` factory) it would be possible to avoid the JNI dance: just get the process symbol lookup, and look for statically linked symbols in there.

@mcimadamore 

> Having to upgrade to JNI is a bit sad 

I'm not quite sure what you mean that "upgrades" the library to a "JNI library"? Nor why this is sad?

What we do is that we add a marker to identify the library as a built-in library. The name of the marker contains the letters `JNI`, but that is the only JNI thing about it. As Jiangli says, we have added this marker for all other internal JDK libraries. I agree that the name could have been better, but it seems like a minor detail.

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

PR Comment: https://git.openjdk.org/jdk/pull/24801#issuecomment-2836346969


More information about the core-libs-dev mailing list