Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a better error message for failed library loads on jdk17+ #17374

Merged
merged 1 commit into from
May 10, 2023

Conversation

pshipton
Copy link
Member

@pshipton pshipton commented May 9, 2023

JVM_LoadLibrary() is used to load JNI libraries from jdk17.

Fixes #17285

The library being loaded needs to exist to get the better message. With this change you get an error message to explain why the load failed.

Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to load library ("/home/pete/openj9-openjdk-jdk17/build/linux-x86_64-server-release/images/jdk/lib/libabc.so") /home/pete/openj9-openjdk-jdk17/build/linux-x86_64-server-release/images/jdk/lib/libabc.so: file too short

Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to load library ("/home/pete/openj9-openjdk-jdk17/build/linux-x86_64-server-release/images/jdk/lib/libabc.so") /home/pete/openj9-openjdk-jdk17/build/linux-x86_64-server-release/images/jdk/lib/libabc.so: invalid ELF header

@pshipton pshipton requested a review from keithc-ca May 9, 2023 23:10
Copy link
Contributor

@keithc-ca keithc-ca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description and commit message should be updated to reflect that this applies to jdk11+.

runtime/j9vm/jvm.c Show resolved Hide resolved
runtime/j9vm/jvm.c Outdated Show resolved Hide resolved
runtime/j9vm/jvm.c Outdated Show resolved Hide resolved
runtime/j9vm/jvm.c Show resolved Hide resolved
@pshipton
Copy link
Member Author

pshipton commented May 10, 2023

The description and commit message should be updated to reflect that this applies to jdk11+.

It only applies to jdk17+. jdk17 changed how JNI libraries are loaded, making this change necessary. jdk11 uses OpenJ9 to load libraries, which already provides the better error messages.

@pshipton
Copy link
Member Author

Pushed a change to address the other review comments.

Comment on lines +3975 to +3981
/* jdk17+ calls JVM_LoadLibrary with decorated library names. If the following is done
* then it overwrites the real error with a failure to load "liblib<name>.so.so".
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we don't expect this function to be used at all prior to jdk17; I'll plan to create a follow-up PR that simply asserts that and remove unnecessary code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful, I only checked jdk11.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't be easy to check IBM Java 8.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use defined(OPENJ9_BUILD) to avoid impacting IBM Java 8 builds.

runtime/j9vm/jvm.c Outdated Show resolved Hide resolved
runtime/j9vm/jvm.c Outdated Show resolved Hide resolved
@keithc-ca
Copy link
Contributor

Jenkins compile win32 jdk8

@keithc-ca
Copy link
Contributor

Jenkins compile alinux64 jdk17

@keithc-ca
Copy link
Contributor

I'm not sure whether to expect the jdk8 build to fail because attemptedLoad is read only for jdk17+.

@pshipton pshipton force-pushed the loaderror branch 5 times, most recently from 615a5d7 to 007c7eb Compare May 10, 2023 19:49
runtime/j9vm/jvm.c Outdated Show resolved Hide resolved
runtime/j9vm/jvm.c Outdated Show resolved Hide resolved
runtime/j9vm/jvm.c Outdated Show resolved Hide resolved
JVM_LoadLibrary() is used to load JNI libraries from jdk17.

Issue eclipse-openj9#17285

Signed-off-by: Peter Shipton <Peter_Shipton@ca.ibm.com>
@keithc-ca
Copy link
Contributor

Jenkins compile win32 jdk8

@keithc-ca
Copy link
Contributor

Jenkins compile amac jdk17

@keithc-ca keithc-ca merged commit 7806354 into eclipse-openj9:master May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

jdk17+ should give a better error message for failed library loads
2 participants