RFR: JDK-8319516 - Native library suffix impact on the library loading in AIX- Java Class Loader [v2]

Jaikiran Pai jpai at openjdk.org
Thu Mar 21 17:00:21 UTC 2024


On Thu, 21 Mar 2024 16:11:16 GMT, Suchismith Roy <sroy at openjdk.org> wrote:

>>> Hello @suchismith1993, I haven't fully caught up on the necessity of this change. The current proposed change, renames files in the underlying filesystem in the code flow of `System.loadLibrary()` and I don't think is the right thing to do irrespective of whether we do it in AIX specific code or common code.
>>> 
>>> Could you update the JBS issue description to clearly explain what (application?) code is causing what issue? I know you mentioned about jextract here, but it's not clear whether this is some issue in jextract or something else. Having all those details in the JBS issue will be helpful to decide what changes should be pursued.
>> 
>> This is not specific to an application. We are looking to support member objects of AIX shared libraries in the Java ClassLoader. 
>> As for the renaming, the renaming is necessary because the member object is not part of the actual filename. 
>> Example : libclang.a(libclang.so.16) 
>> This member object, is identified only by the dlopen() in the hotspot code. But there is no actual file named libclang.a(libclang.so.16) in the filesystem. 
>> So when the check is done if file exists, it fails,i.e it checks for libclang.a(libclang.so.16).So i remove the braces and member name to extract the actual name of the file in the filesystem, which is libclang.a. But when we pass libclang.a to the dlopen ,it will fail to open it. 
>> Hence i need to rename the file to the name with braces before it passes to dlopen.So i reconstruct it to libclang.a(libclang.so.16)
>
>> As for this:
>> 
>> > Yes we are trying to install liblcang and also jextract and it fails with errors.
>> 
>> > Exception in thread "main" java.lang.UnsatisfiedLinkError: no clang in java.library.path
>> 
>> ```
>> at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2439)
>> at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:916)
>> at java.base/java.lang.System.loadLibrary(System.java:2063)
>> at [org.openjdk.jextract at 22/org.openjdk.jextract.clang.libclang.RuntimeHelper.<clinit>(RuntimeHelper.java:65)](mailto:org.openjdk.jextract at 22/org.openjdk.jextract.clang.libclang.RuntimeHelper.%3cclinit%3e(RuntimeHelper.java:65))
>> at [org.openjdk.jextract at 22/org.openjdk.jextract.clang.libclang.constants$17.<clinit>(constants$17.java:46)](mailto:org.openjdk.jextract at 22/org.openjdk.jextract.clang.libclang.constants$17.%3cclinit%3e(constants$17.java:46))
>> at [org.openjdk.jextract at 22/org.openjdk.jextract.clang.libclang.Index_h.clang_getClangVersion$MH(Index_h.java:5690)](mailto:org.openjdk.jextract at 22/org.openjdk.jextract.clang.libclang.Index_h.clang_getClangVersion$MH(Index_h.java:5690))
>> at [org.openjdk.jextract at 22/org.openjdk.jextract.clang.libclang.Index_h.clang_getClangVersion(Index_h.java:5698)](mailto:org.openjdk.jextract at 22/org.openjdk.jextract.clang.libclang.Index_h.clang_getClangVersion(Index_h.java:5698))
>> at [org.openjdk.jextract at 22/org.openjdk.jextract.clang.LibClang.version(LibClang.java:93)](mailto:org.openjdk.jextract at 22/org.openjdk.jextract.clang.LibClang.version(LibClang.java:93))
>> at [org.openjdk.jextract at 22/org.openjdk.jextract.JextractTool.run(JextractTool.java:362)](mailto:org.openjdk.jextract at 22/org.openjdk.jextract.JextractTool.run(JextractTool.java:362))
>> at [org.openjdk.jextract at 22/org.openjdk.jextract.JextractTool.main(JextractTool.java:174)](mailto:org.openjdk.jextract at 22/org.openjdk.jextract.JextractTool.main(JextractTool.java:174))
>> ```
>> 
>> I had a quick look at the latest jextract code and I don't see some of the classes that are reported in that stacktrace. Which exact version of jextract is this? If jextract is what motivated this change, then I would recommend checking on jextract-dev mailing list first https://mail.openjdk.org/mailman/listinfo/jextract-dev to understand if this is an issue in jextract itself.
> 
> Jextract is one use case that prompted to make this change. There is no issue with the Jextract in particular. We probably might need a small change in the Index java file. But there are use cases where we need ...

> But there is no actual file named libclang.a(libclang.so.16) in the filesystem.
So when the check is done if file exists, it fails,i.e it checks for libclang.a(libclang.so.16).

I'll let Mandy and others more knowledgable of this area to correct me. From what I know, there was a change done a few releases back in the JDK (https://bugs.openjdk.org/browse/JDK-8275703) which accomodated macos platform where it too doesn't actually have the file on the filesystem in recent versions of macos. That change allowed platform specific code to dictate whether the file existence check needs to be done here in this loadLibrary code. That's done through the call to `jdk.internal.loader.ClassLoaderHelper.loadLibraryOnlyIfPresent()`. For macos, that implementation of that method resides in macos specific class here https://github.com/openjdk/jdk/blob/master/src/java.base/macosx/classes/jdk/internal/loader/ClassLoaderHelper.java#L41. For AIX too then, perhaps you could add an implementation which returns `false` (either always or in specific cases) and experiment with that to see if that's enough?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17945#discussion_r1534292292


More information about the core-libs-dev mailing list