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

[jvm-packages] Fixing the NativeLibLoader on Java 9+ #4351

Merged
merged 1 commit into from
Apr 10, 2019

Conversation

Craigacp
Copy link
Contributor

@Craigacp Craigacp commented Apr 9, 2019

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.

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.
@CodingCat
Copy link
Member

LGTM, let's merge it when Travis is ready and after @hcho3 bring up the java worker, we can have test across jdk versions there...(don't need to work on Travis now which looks like to be eventually discarded? @hcho3 )

@CodingCat
Copy link
Member

@hcho3 just to confirm before I merge it, Travis will eventually gone?

@hcho3
Copy link
Collaborator

hcho3 commented Apr 10, 2019

@CodingCat Sort of. We may want to keep a few tests targeted for Mac however.

@CodingCat
Copy link
Member

@hcho3 got it, thx!

@Craigacp do you mind adding some profile in pom.xml which only compiles xgboost4j module, and add some cross jdk test in travis then?

@hcho3
Copy link
Collaborator

hcho3 commented Apr 10, 2019

@CodingCat @Craigacp I'm not sure if cross-jdk test is needed on Travis, since Travis will only have Mac targets after migration.

@CodingCat
Copy link
Member

@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

@hcho3
Copy link
Collaborator

hcho3 commented Apr 10, 2019

@CodingCat Yes, let's merge this PR.

@Craigacp
Copy link
Contributor Author

Do you still want me to make the pom.xml profile for xgboost4j only before merging?

@CodingCat
Copy link
Member

@Craigacp no, thanks! we can merge it now!

@CodingCat CodingCat merged commit a448a83 into dmlc:master Apr 10, 2019
@hcho3 hcho3 mentioned this pull request Apr 21, 2019
18 tasks
@lock lock bot locked as resolved and limited conversation to collaborators Jul 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants