lookup(String). A given native library remains loaded as long as there is at least one live library lookup instance referring to it. All symbol instances (see
LibraryLookup.Symbol) generated by a given library lookup object contain a strong reference to said lookup object, therefore preventing library unloading; in turn method handle instances obtained from
CLinker.downcallHandle(Addressable, MethodType, FunctionDescriptor)) also maintain a strong reference to the addressable parameter used for their construction. This means that there is always a strong reachability chain from a native method handle to a lookup object (the one that was used to lookup the native library symbol the method handle refers to); this is useful to prevent situations where a native library is unloaded in the middle of a native call.
MemoryAddress.asSegmentRestricted(long, Runnable, Object)restricted segment factory, as follows:
LibraryLookup defaultLookup = LibraryLookup.defaultLookup(); LibraryLookup.Symbol errno = defaultLookup.lookup("errno"); MemorySegment errnoSegment = errno.address().asRestrictedSegment(4, errno);
To allow for a library to be unloaded, a client will have to discard any strong references it maintains, directly, or indirectly to a lookup object associated with given library.
Unless otherwise specified, passing a
null argument, or an array argument containing one or more
elements to a method in this class causes a
NullPointerException to be thrown.
Nested Class SummaryModifier and TypeInterfaceDescription
static interfaceA symbol retrieved during a library lookup.
Method SummaryModifier and TypeMethodDescription
String name)(Looks up a symbol with given name in this library.
()Obtain a default library lookup object.
String libName)(Obtain a library lookup object corresponding to a library identified by given library name.
Path path)(Obtain a library lookup object corresponding to a library identified by given path.
lookupLooks up a symbol with given name in this library. The returned symbol maintains a strong reference to this lookup object.
name- the symbol name.
- the library symbol (if any).
ofDefaultstatic LibraryLookup ofDefault()Obtain a default library lookup object.
- the default library lookup object.
ofPathObtain a library lookup object corresponding to a library identified by given path.
path- the library absolute path.
- a library lookup object for given path.
IllegalArgumentException- if the specified path does not correspond to an absolute path, e.g. if
ofLibraryObtain a library lookup object corresponding to a library identified by given library name. The library name is decorated according to the platform conventions (e.g. on Linux, the
libprefix is added, as well as the
.soextension); the resulting name is then looked up in the standard native library path (which can be overriden, by setting the
libName- the library name.
- a library lookup object for given library name.