jnr.ffi
Class Runtime

java.lang.Object
  extended by jnr.ffi.Runtime
Direct Known Subclasses:
AbstractRuntime

public abstract class Runtime
extends Object

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);
     
     


Constructor Summary
Runtime()
           
 
Method Summary
abstract  long addressMask()
          Gets the address mask for this runtime
abstract  int addressSize()
          Gets the size of an address (e.g.
abstract  ByteOrder byteOrder()
          Gets the native byte order of the runtime.
abstract  Type findType(NativeType type)
          Looks up the runtime-specific type that corresponds to the pseudo-type
abstract  Type findType(TypeAlias type)
          Looks up the runtime-specific type that corresponds to the type alias
abstract  ClosureManager getClosureManager()
          Gets the native closure manager for this runtime
abstract  int getLastError()
          Gets the last native error code.
abstract  MemoryManager getMemoryManager()
          Gets the native memory manager for this runtime
static Runtime getRuntime(Object library)
          Returns the runtime associated with the library instance.
static Runtime getSystemRuntime()
          Gets the global Runtime for the current FFI provider
abstract  boolean isCompatible(Runtime other)
          Indicates whether this Runtime instance is compatible with another Runtime instance.
abstract  int longSize()
          Gets the size of a C long integer for this runtime
abstract
<T> ObjectReferenceManager<T>
newObjectReferenceManager()
          Creates a new ObjectReferenceManager
abstract  void setLastError(int error)
          Sets the native error code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Runtime

public Runtime()
Method Detail

getSystemRuntime

public static Runtime getSystemRuntime()
Gets the global Runtime for the current FFI provider

Returns:
The system runtime

getRuntime

public static Runtime getRuntime(Object library)
Returns the runtime associated with the library instance.

Parameters:
library - A loaded library instance as returned from LibraryLoader.load()
Returns:
The runtime that loaded the library

findType

public abstract Type findType(NativeType type)
Looks up the runtime-specific type that corresponds to the pseudo-type

Returns:
A Type instance

findType

public abstract Type findType(TypeAlias type)
Looks up the runtime-specific type that corresponds to the type alias

Returns:
A Type instance

getMemoryManager

public abstract MemoryManager getMemoryManager()
Gets the native memory manager for this runtime

Returns:
The MemoryManager of the runtime

getClosureManager

public abstract ClosureManager getClosureManager()
Gets the native closure manager for this runtime

Returns:
The ClosureManager of the runtime

newObjectReferenceManager

public abstract <T> ObjectReferenceManager<T> newObjectReferenceManager()
Creates a new ObjectReferenceManager

Returns:
A new ObjectReferenceManager

getLastError

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:
The errno value.

setLastError

public abstract void setLastError(int error)
Sets the native error code.

Parameters:
error - The value to set errno to.

addressMask

public abstract long addressMask()
Gets the address mask for this runtime

Returns:
The address mask for the runtime.

addressSize

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

Returns:
The size of an address in bytes.

longSize

public abstract int longSize()
Gets the size of a C long integer for this runtime

Returns:
The size of a C long integer in bytes.

byteOrder

public abstract ByteOrder byteOrder()
Gets the native byte order of the runtime.

Returns:
The byte order of the runtime

isCompatible

public abstract boolean isCompatible(Runtime other)
Indicates whether this Runtime instance is compatible with another Runtime instance.

This is not the same as calling Object.equals(java.lang.Object) - 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 - the other runtime to test for compatibility
Returns:
true if the other runtime is compatible with this one


Copyright © 2013. All Rights Reserved.