On Tue, 29 Mar 2022 20:05:50 GMT, Mandy Chung <mch...@openjdk.org> wrote:

> A small improvement to `RawNativeLibraries`.   `RawNativeLibraries::load` 
> returns the same `NativeLibrary` instance of a given path if it's called 
> multiple times. This means that multiple clients have to coordinate that the 
> last one using the loaded library is the one to close the library by calling 
> `RawNativeLibraries::unload`; otherwise, an exception may be thrown.
> 
> This patch changes `RawNativeLibraries::load` to delegate to the underlying 
> platform-specific library loading mechanism e.g. dlopen/dlclose that keeps 
> the reference count.  So each call to `RawNativeLibraries::load` and `unload` 
> is simply a call to dlopen and dlclose respectively.  Each client of calling 
> `RawNativeLibraries::load` is responsible for calling 
> `RawNativeLibraries::unload`.  This will be consistent with the current 
> behavior when you call `load` and `unload` with a different 
> `RawNativeLibraries` instance.

src/java.base/share/classes/jdk/internal/loader/RawNativeLibraries.java line 49:

> 47: public final class RawNativeLibraries {
> 48:     final Set<RawNativeLibraryImpl> libraries = 
> ConcurrentHashMap.newKeySet();
> 49:     final Class<?> caller;

Hello Mandy, 
Apart from the `caller` being used for checks while constructing a 
`RawNativeLibraries` in `RawNativeLibraries.newInstance(MethodHandles.Lookup 
trustedCaller)`, I don't see this instance member being used anywhere. Do you 
think we need to store this as an instance member?

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

PR: https://git.openjdk.java.net/jdk/pull/8022

Reply via email to