-
Type:
Enhancement
-
Resolution: Unresolved
-
Priority:
P4
-
None
-
Affects Version/s: None
-
Component/s: core-libs
-
None
I needed to use FFM to invoke a symbol in a library which may or may not have been loaded in the VM (by another classloader). I used the pattern in the following snippet in the apidoc ("Obtaining a symbol lookup") section of SymbolLookup
try (Arena arena = Arena.ofConfined()) {
SymbolLookup libGL = SymbolLookup.libraryLookup("libGL.so", arena); // libGL.so loaded here
MemorySegment glGetString = libGL.findOrThrow("glGetString");
...
} // libGL.so unloaded here
What would have helped would be some comment to the effect that the library name can be constructed in a platform independent manner by using:
System.mapLibraryName("GL")
This could be added as a comment to the snippet or maybe documented somewhere in the libraryLookup() method itself.
Note, I was initially drawn to the SymbolLookup.loaderLookup() method but it turns out this approach is not usable if the library has already been loaded by another classloader, but the docs for loaderLookup() don't say anything about this. I wonder if something could be added to the apidoc about that.
try (Arena arena = Arena.ofConfined()) {
SymbolLookup libGL = SymbolLookup.libraryLookup("libGL.so", arena); // libGL.so loaded here
MemorySegment glGetString = libGL.findOrThrow("glGetString");
...
} // libGL.so unloaded here
What would have helped would be some comment to the effect that the library name can be constructed in a platform independent manner by using:
System.mapLibraryName("GL")
This could be added as a comment to the snippet or maybe documented somewhere in the libraryLookup() method itself.
Note, I was initially drawn to the SymbolLookup.loaderLookup() method but it turns out this approach is not usable if the library has already been loaded by another classloader, but the docs for loaderLookup() don't say anything about this. I wonder if something could be added to the apidoc about that.