Package com.kenai.jffi
Class Library
- java.lang.Object
-
- com.kenai.jffi.Library
-
public final class Library extends java.lang.ObjectRepresents a native library
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classLibrary.DefaultLibraryA handle to the current process
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,java.lang.ref.WeakReference<Library>>cacheA cache of opened librariesprivate intdisposedIndicates whether this library has been disposed of.private ForeignforeignA handle to the foreign interface to keep it alive as long as this object is alivestatic intGLOBALAll symbols in the library are made available to other librariesprivate longhandleThe native dl/LoadLibrary handleprivate static java.lang.ThreadLocal<java.lang.String>lastErrorStores the last error returned by a dlopen or dlsym callstatic intLAZYPerform lazy binding.static intLOCALSymbols in this library are not made available to other librariesprivate static java.lang.ObjectlockA lock used to serialize all dlopen/dlsym callsprivate java.lang.StringnameThe name of thisLibrarystatic intNOWResolve all symbols when loading the libraryprivate static java.util.concurrent.atomic.AtomicIntegerFieldUpdater<Library>UPDATER
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static longdlopen(Foreign foreign, java.lang.String name, int flags)Internal wrapper around dlopen.protected voidfinalize()static LibrarygetCachedInstance(java.lang.String name, int flags)Gets a handle for the named library.static LibrarygetDefault()Gets a handle to the default library.static java.lang.StringgetLastError()Gets the current error string from dlopen/LoadLibrary.longgetSymbolAddress(java.lang.String name)Gets the address of a symbol within theLibrary.static LibraryopenLibrary(java.lang.String name, int flags)Gets a handle for the named library.
-
-
-
Field Detail
-
cache
private static final java.util.Map<java.lang.String,java.lang.ref.WeakReference<Library>> cache
A cache of opened libraries
-
lock
private static final java.lang.Object lock
A lock used to serialize all dlopen/dlsym calls
-
lastError
private static final java.lang.ThreadLocal<java.lang.String> lastError
Stores the last error returned by a dlopen or dlsym call
-
LAZY
public static final int LAZY
Perform lazy binding. Only resolve symbols as needed- See Also:
- Constant Field Values
-
NOW
public static final int NOW
Resolve all symbols when loading the library- See Also:
- Constant Field Values
-
LOCAL
public static final int LOCAL
Symbols in this library are not made available to other libraries- See Also:
- Constant Field Values
-
GLOBAL
public static final int GLOBAL
All symbols in the library are made available to other libraries- See Also:
- Constant Field Values
-
handle
private final long handle
The native dl/LoadLibrary handle
-
name
private final java.lang.String name
The name of thisLibrary
-
foreign
private final Foreign foreign
A handle to the foreign interface to keep it alive as long as this object is alive
-
disposed
private volatile int disposed
Indicates whether this library has been disposed of.
-
UPDATER
private static final java.util.concurrent.atomic.AtomicIntegerFieldUpdater<Library> UPDATER
-
-
Constructor Detail
-
Library
private Library(Foreign foreign, java.lang.String name, long address)
-
-
Method Detail
-
dlopen
private static long dlopen(Foreign foreign, java.lang.String name, int flags)
Internal wrapper around dlopen. If the library open fails, then this stores the native error in a thread local variable for later retrieval.- Parameters:
name- The name of the library to openflags- The flags to pass to dlopen- Returns:
- The native handle for the opened library, or 0 if it failed to open.
-
getDefault
public static final Library getDefault()
Gets a handle to the default library.- Returns:
- A
Libraryinstance representing the default library.
-
getCachedInstance
public static final Library getCachedInstance(java.lang.String name, int flags)
Gets a handle for the named library.- Parameters:
name- The name or path of the library to open.flags- The library flags (e.g.LAZY, NOW, LOCAL, GLOBAL)- Returns:
- A
Libraryinstance representing the named library, ornullif the library could not be opened.
-
openLibrary
public static final Library openLibrary(java.lang.String name, int flags)
Gets a handle for the named library. Note This will not cache the instance, nor will it return a cached instance. Only use when you really need a new handle for the library.- Parameters:
name- The name or path of the library to open.flags- The library flags (e.g.LAZY, NOW, LOCAL, GLOBAL)- Returns:
- A
Libraryinstance representing the named library, or null if the library cannot be opened.
-
getSymbolAddress
public final long getSymbolAddress(java.lang.String name)
Gets the address of a symbol within theLibrary.- Parameters:
name- The name of the symbol to locate.- Returns:
- The address of the symbol within the current address space.
-
getLastError
public static final java.lang.String getLastError()
Gets the current error string from dlopen/LoadLibrary.- Returns:
- A
Stringdescribing the last error.
-
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
-