Top Description Inners Constructors Methods
jnr.ffi

public abstract Class Runtime

extends Object
Class Inheritance
Known Direct Subclasses
jnr.ffi.provider.AbstractRuntime, jnr.ffi.provider.InvalidRuntime
Imports
jnr.ffi.provider.ClosureManager, .FFIProvider, .LoadedLibrary, .MemoryManager, jnr.ffi.provider.jffi.NativeLibrary, .NativeRuntime, java.nio.ByteOrder, java.util.List

Access JNR runtime functionality.

This class is needed by many classes to correctly initialize internal data structures, and each library loaded has its own instance of this class.

To obtain an instance of this class, use getRuntime(Object) on a loaded library.

Example

    public interface LibC {
        public long write(int fd, Pointer data, long len);
    }

    LibC library = LibraryLoader.create(LibC.class).load("c");

    byte[] bytes = "Hello, World\n".getBytes("UTF-8");

    // Use the loaded library's Runtime to allocate memory for the string
    jnr.ffi.Runtime runtime = jnr.ffi.Runtime.getRuntime(library);
    Pointer buffer = Memory.allocateDirect(runtime, bytes.length);

    // Copy the java string data to the native memory, then write the contents to STDOUT
    buffer.put(0, bytes, 0, bytes.length);
    library.write(1, buffer, bytes.length);
    
    

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Runtime.SingletonHolder

singleton holder for the default Runtime

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract long

Returns:

The address mask for the runtime.
addressMask
()

Gets the address mask for this runtime

public abstract int

Returns:

The size of an address in bytes.
addressSize
()

Gets the size of an address (e.g. a pointer) for this runtime

public abstract ByteOrder

Returns:

The byte order of the runtime
byteOrder
()

Gets the native byte order of the runtime.

public abstract Type

Returns:

A Type instance.
findType
(NativeType
The native pseudo-type.
type
)

Looks up the runtime-specific type that corresponds to the pseudo-type

public abstract Type

Returns:

A Type instance
findType
(TypeAlias
the type alias.
type
)

Looks up the runtime-specific type that corresponds to the type alias

public abstract ClosureManager

Returns:

The ClosureManager of the runtime
getClosureManager
()

Gets the native closure manager for this runtime

public abstract int

Returns:

The errno value.
getLastError
()

Gets the last native error code.

public static List<NativeLibrary.LoadedLibraryData>

Returns:

the list of NativeLibrary.LoadedLibraryData which represents all currently loaded libraries
getLoadedLibraries
()

Gets a list of NativeLibrary.LoadedLibraryData which represents all currently loaded libraries, or an empty list if none are loaded.

public abstract MemoryManager

Returns:

The MemoryManager of the runtime
getMemoryManager
()

Gets the native memory manager for this runtime

public static Runtime

Returns:

The runtime that loaded the library
getRuntime
(Object
A loaded library instance as returned from LibraryLoader#load()
library
)

Returns the runtime associated with the library instance.

public static Runtime

Returns:

The system runtime
getSystemRuntime
()

Gets the global Runtime for the current FFI provider

public abstract boolean

Returns:

true if the other runtime is compatible with this one
isCompatible
(Runtime
the other runtime to test for compatibility
other
)

Indicates whether this Runtime instance is compatible with another Runtime instance.

public abstract int

Returns:

The size of a C long integer in bytes.
longSize
()

Gets the size of a C long integer for this runtime

public abstract <
the type parameter of the ObjectReferenceManager.
T
>
ObjectReferenceManager<T>

Returns:

A new ObjectReferenceManager
newObjectReferenceManager
()

Creates a new ObjectReferenceManager

public abstract void
setLastError(int
The value to set errno to.
error
)

Sets the native error code.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Runtimeback to summary
public Runtime()

Method Detail

addressMaskback to summary
public abstract long addressMask()

Gets the address mask for this runtime

Returns:long

The address mask for the runtime.

addressSizeback to summary
public abstract int addressSize()

Gets the size of an address (e.g. a pointer) for this runtime

Returns:int

The size of an address in bytes.

byteOrderback to summary
public abstract ByteOrder byteOrder()

Gets the native byte order of the runtime.

Returns:ByteOrder

The byte order of the runtime

findTypeback to summary
public abstract Type findType(NativeType type)

Looks up the runtime-specific type that corresponds to the pseudo-type

Parameters
type:NativeType

The native pseudo-type.

Returns:Type

A Type instance.

findTypeback to summary
public abstract Type findType(TypeAlias type)

Looks up the runtime-specific type that corresponds to the type alias

Parameters
type:TypeAlias

the type alias.

Returns:Type

A Type instance

getClosureManagerback to summary
public abstract ClosureManager getClosureManager()

Gets the native closure manager for this runtime

Returns:ClosureManager

The ClosureManager of the runtime

getLastErrorback to summary
public abstract int getLastError()

Gets the last native error code.

This returns the errno value that was set at the time of the last native function call.

Returns:int

The errno value.

getLoadedLibrariesback to summary
public static List<NativeLibrary.LoadedLibraryData> getLoadedLibraries()

Gets a list of NativeLibrary.LoadedLibraryData which represents all currently loaded libraries, or an empty list if none are loaded.
A library is "loaded" if the native library's file (.so, .dylib, .dll etc) was opened and loaded into memory successfully, ie a call to dlopen() was successful. If you don't see a library here then either:

  • It failed to load and threw an UnsatisfiedLinkError
  • It has not yet loaded because it is being loaded lazily, ie, upon needing to be used, you can disable this behavior by using LibraryOption#LoadNow at load time
When a library is unloaded (all references to your interface mapping have been GC'd), calling this method again will reflect the unload and you will no longer see the unloaded library.
Returns:List<NativeLibrary.LoadedLibraryData>

the list of NativeLibrary.LoadedLibraryData which represents all currently loaded libraries

See Also
NativeLibrary.LoadedLibraryData
getMemoryManagerback to summary
public abstract MemoryManager getMemoryManager()

Gets the native memory manager for this runtime

Returns:MemoryManager

The MemoryManager of the runtime

getRuntimeback to summary
public static Runtime getRuntime(Object library)

Returns the runtime associated with the library instance.

Parameters
library:Object

A loaded library instance as returned from LibraryLoader#load()

Returns:Runtime

The runtime that loaded the library

getSystemRuntimeback to summary
public static Runtime getSystemRuntime()

Gets the global Runtime for the current FFI provider

Returns:Runtime

The system runtime

isCompatibleback to summary
public abstract boolean isCompatible(Runtime other)

Indicates whether this Runtime instance is compatible with another Runtime instance.

This is not the same as calling equals - this method only indicates whether or not artifacts from the runtime (e.g. memory addresses) are compatible with artifacts from this one.

This is mostly for internal use.

Parameters
other:Runtime

the other runtime to test for compatibility

Returns:boolean

true if the other runtime is compatible with this one

longSizeback to summary
public abstract int longSize()

Gets the size of a C long integer for this runtime

Returns:int

The size of a C long integer in bytes.

newObjectReferenceManagerback to summary
public abstract <T> ObjectReferenceManager<T> newObjectReferenceManager()

Creates a new ObjectReferenceManager

Parameters
<T>
the type parameter of the ObjectReferenceManager.
Returns:ObjectReferenceManager<T>

A new ObjectReferenceManager

setLastErrorback to summary
public abstract void setLastError(int error)

Sets the native error code.

Parameters
error:int

The value to set errno to.

jnr.ffi back to summary

private final Class Runtime.SingletonHolder

extends Object
Class Inheritance

singleton holder for the default Runtime

Field Summary

Modifier and TypeField and Description
public static final Runtime

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

SYSTEM_RUNTIMEback to summary
public static final Runtime SYSTEM_RUNTIME

Constructor Detail

SingletonHolderback to summary
private SingletonHolder()