-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
[jvm-packages] Fixing the NativeLibLoader on Java 9+ #4351
Conversation
The old NativeLibLoader had a short-circuit load path which modified java.library.path and attempted to load the xgboost library from outside the jar first, falling back to loading the library from inside the jar. This path is a no-op every time when using XGBoost outside of it's source tree. Additionally it triggers an illegal reflective access warning in the module system in 9, 10, and 11. On Java 12 the ClassLoader fields are not accessible via reflection (separately from the illegal reflective acces warning), and so it fails in a way that isn't caught by the code which falls back to loading the library from inside the jar. This commit removes that code path and always loads the xgboost library from inside the jar file as it's a valid technique across multiple JVM implementations and works with all versions of Java.
@hcho3 just to confirm before I merge it, Travis will eventually gone? |
@CodingCat Sort of. We may want to keep a few tests targeted for Mac however. |
@CodingCat @Craigacp I'm not sure if cross-jdk test is needed on Travis, since Travis will only have Mac targets after migration. |
@hcho3 we can only do that in linux/windows, but we still need some profile for only compiling xgboost4j now or in near future so I don't mind merging it now |
@CodingCat Yes, let's merge this PR. |
Do you still want me to make the pom.xml profile for xgboost4j only before merging? |
@Craigacp no, thanks! we can merge it now! |
Fix for issue #4342.
The old NativeLibLoader had a short-circuit load path which modified java.library.path and attempted to load the xgboost library from outside the jar first, falling back to loading the library from inside the jar. This path is a no-op every time when using XGBoost outside of it's source tree. Additionally it triggers an illegal reflective access warning in the module system in 9, 10, and 11.
On Java 12 the ClassLoader fields are not accessible via reflection (separately from the illegal reflective acces warning), and so it fails in a way that isn't caught by the code which falls back to loading the library from inside the jar.
This commit removes that code path and always loads the xgboost library from inside the jar file as it's a valid technique across multiple JVM implementations and works with all versions of Java.
I tested it on macOS Mojave using JDK 11 & 12, Linux using JDK 8, 11 and 12, and Windows using an older build using JDK 9 and 12.