JDK-8228336 : Refactor native library loading implementation
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang:class_loading
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-07-17
  • Updated: 2022-03-07
  • Resolved: 2020-03-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 15
15 b15Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
See https://mail.openjdk.java.net/pipermail/core-libs-dev/2019-July/061268.html

A few ideas of potential clean up:

1. ClassLoader::sys_paths is the library path for boot loader whereas ClassLoader::usr_paths is the library path for user-defined loaders

We should consider refactoring the native library loading implementation
such that ClassLoader::loadLibrary can delegate to BootLoader::loadLibrary
and the permission checks for user-defined loader is not needed for the boot loader.  So BootLoader::loadLibrary can further be optimized.

2. This refactoring enables Panama LibraryLookup to load a native library without the limitation to restrict only lookups from the same class loader can access functions from a native library.

JDK-8236075 has addressed the potential race in initializing sys_paths and usr_paths.
Comments
Git URL: https://github.com/openjdk/jdk/commit/d5d6dc0caa1d2db6e85b3fe979ae7a204678de57
07-03-2022

URL: https://hg.openjdk.java.net/jdk/jdk/rev/1ca940d73efc User: mchung Date: 2020-03-12 18:54:31 +0000
12-03-2020

Review thread: https://mail.openjdk.java.net/pipermail/core-libs-dev/2020-March/065194.html
10-03-2020

I've gone through the changes in JDK-8227587 and I agree there is follow-up work needed. In addition to the refactoring, I think BootLoader.loadLibrary should be re-examined. It would be okay to have BootLoader define a findLibrary method but loadLibrary isn't quite right as it's more of a system helper method.
22-07-2019