Top Inners Fields Constructors Methods
com.kenai.jffi

public final Class ClosurePool

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, java.util.*, java.util.concurrent.ConcurrentLinkedQueue

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ClosurePool.Handle

Manages the lifecycle of a native closure.

private static class
private static class
pack-priv static class
ClosurePool.Proxy

This is a proxy passed to the native code, to be called by the native trampoline code.

Field Summary

Modifier and TypeField and Description
private final CallContext
private final ConcurrentLinkedQueue<ClosurePool.Handle>
private final Set<ClosurePool.Magazine>
private static final Closure
private final ConcurrentLinkedQueue<ClosurePool.Handle>

Constructor Summary

AccessConstructor and Description
pack-priv
ClosurePool(CallContext callContext)

Method Summary

Modifier and TypeMethod and Description
private ClosurePool.Handle
public Closure.Handle
pack-priv synchronized void
pack-priv void
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callContextback to summary
private final CallContext callContext
freeQueueback to summary
private final ConcurrentLinkedQueue<ClosurePool.Handle> freeQueue
magazinesback to summary
private final Set<ClosurePool.Magazine> magazines
NULL_CLOSUREback to summary
private static final Closure NULL_CLOSURE
partialQueueback to summary
private final ConcurrentLinkedQueue<ClosurePool.Handle> partialQueue

Constructor Detail

ClosurePoolback to summary
pack-priv ClosurePool(CallContext callContext)

Method Detail

allocateNewHandleback to summary
private ClosurePool.Handle allocateNewHandle()
newClosureHandleback to summary
public Closure.Handle newClosureHandle(Closure closure)
recycleback to summary
pack-priv synchronized void recycle(ClosurePool.Magazine magazine)
recycleback to summary
pack-priv void recycle(ClosurePool.Magazine.Slot slot, ClosurePool.MagazineHolder holder)
useMagazineback to summary
private void useMagazine(ClosurePool.Magazine m)
com.kenai.jffi back to summary

private final Class ClosurePool.Handle

extends Object
implements Handle
Class Inheritance
All Implemented Interfaces
com.kenai.jffi.Closure.Handle

Manages the lifecycle of a native closure. Implements Closure.Handle interface.

Field Summary

Modifier and TypeField and Description
private volatile boolean
pack-priv final ClosurePool.MagazineHolder
holder

Keep references to the closure pool so it does not get garbage collected until all closures using it do.

pack-priv final ClosurePool.Magazine.Slot

Constructor Summary

AccessConstructor and Description
pack-priv
Handle(ClosurePool.Magazine.Slot
THe magazine slot this handle belongs to
slot
,
ClosurePool.MagazineHolder
The magazine holder containing this handle
holder
)

Creates a new Handle to lifecycle manager the native closure.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
dispose()

Implements com.kenai.jffi.Closure.Handle.dispose.

Releases the closure memory back to the operating system.
public void
free()

Implements com.kenai.jffi.Closure.Handle.free.

Deprecated
public long
getAddress()

Implements com.kenai.jffi.Closure.Handle.getAddress.

Gets the native code address of the closure.
public void
setAutoRelease(boolean
If true, the closure memory is automatically managed, else the closure memory must be explicitly freed.
autorelease
)

Implements com.kenai.jffi.Closure.Handle.setAutoRelease.

Sets whether the closure memory should be released when the Handle is garbage collected or not.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

disposedback to summary
private volatile boolean disposed
holderback to summary
pack-priv final ClosurePool.MagazineHolder holder

Keep references to the closure pool so it does not get garbage collected until all closures using it do.

slotback to summary
pack-priv final ClosurePool.Magazine.Slot slot

Constructor Detail

Handleback to summary
pack-priv Handle(ClosurePool.Magazine.Slot slot, ClosurePool.MagazineHolder holder)

Creates a new Handle to lifecycle manager the native closure.

Parameters
slot:ClosurePool.Magazine.Slot

THe magazine slot this handle belongs to

holder:ClosurePool.MagazineHolder

The magazine holder containing this handle

Method Detail

disposeback to summary
public synchronized void dispose()

Implements com.kenai.jffi.Closure.Handle.dispose.

Doc from com.kenai.jffi.Closure.Handle.dispose.

Releases the closure memory back to the operating system. Although the closure trampoline memory will normally be released when the Handle is garbage collected, this may not happen for some time, and is non-deterministic. This allows explicit control over memory reclamation.

freeback to summary
public void free()

Implements com.kenai.jffi.Closure.Handle.free.

Deprecated

Annotations
@Deprecated
getAddressback to summary
public long getAddress()

Implements com.kenai.jffi.Closure.Handle.getAddress.

Doc from com.kenai.jffi.Closure.Handle.getAddress.

Gets the native code address of the closure. This can be passed into a native function that takes a function pointer.

Returns:long

The native address of the closure code.

setAutoReleaseback to summary
public void setAutoRelease(boolean autorelease)

Implements com.kenai.jffi.Closure.Handle.setAutoRelease.

Doc from com.kenai.jffi.Closure.Handle.setAutoRelease.

Sets whether the closure memory should be released when the Handle is garbage collected or not.

Parameters
autorelease:boolean

If true, the closure memory is automatically managed, else the closure memory must be explicitly freed.

com.kenai.jffi back to summary

private final Class ClosurePool.Magazine

extends Object
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final CallContext
private final Foreign
foreign

A handle to the foreign interface to keep it alive as long as this object is alive

private int
private static final MemoryIO
IO

Store a reference to the MemoryIO accessor here for easy access

private final long
private int
private final ClosurePool.Magazine.Slot[]

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
pack-priv ClosurePool.Magazine.Slot
get()

pack-priv boolean
pack-priv boolean
pack-priv void
Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ctxback to summary
private final CallContext ctx
foreignback to summary
private final Foreign foreign

A handle to the foreign interface to keep it alive as long as this object is alive

Annotations
@SuppressWarnings:FieldCanBeLocal, UnusedDeclaration
freeCountback to summary
private int freeCount
IOback to summary
private static final MemoryIO IO

Store a reference to the MemoryIO accessor here for easy access

magazineback to summary
private final long magazine
nextback to summary
private int next
slotsback to summary
private final ClosurePool.Magazine.Slot[] slots

Constructor Detail

Magazineback to summary
pack-priv Magazine(CallContext ctx)

Method Detail

finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override
Exceptions
Throwable:
the Exception raised by this method
getback to summary
pack-priv ClosurePool.Magazine.Slot get()
isEmptyback to summary
pack-priv boolean isEmpty()
isFullback to summary
pack-priv boolean isFull()
recycleback to summary
pack-priv void recycle()
com.kenai.jffi back to summary

pack-priv final Class ClosurePool.Magazine.Slot

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv volatile boolean
pack-priv final long
codeAddress

The code trampoline address

pack-priv final long
handle

The address of the native closure structure

Note

This is NOT the code address, but a pointer to the structure which contains the code address.

pack-priv final ClosurePool.Proxy

Constructor Summary

AccessConstructor and Description
public
Slot(long handle, ClosurePool.Proxy proxy)

Field Detail

autoreleaseback to summary
pack-priv volatile boolean autorelease
codeAddressback to summary
pack-priv final long codeAddress

The code trampoline address

handleback to summary
pack-priv final long handle

The address of the native closure structure

Note

This is NOT the code address, but a pointer to the structure which contains the code address.

proxyback to summary
pack-priv final ClosurePool.Proxy proxy

Constructor Detail

Slotback to summary
public Slot(long handle, ClosurePool.Proxy proxy)
com.kenai.jffi back to summary

private final Class ClosurePool.MagazineHolder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final ClosurePool.Magazine
pack-priv final ClosurePool

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

magazineback to summary
pack-priv final ClosurePool.Magazine magazine
poolback to summary
pack-priv final ClosurePool pool

Constructor Detail

MagazineHolderback to summary
public MagazineHolder(ClosurePool pool, ClosurePool.Magazine magazine)

Method Detail

finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override
Exceptions
Throwable:
the Exception raised by this method
com.kenai.jffi back to summary

pack-priv final Class ClosurePool.Proxy

extends Object
Class Inheritance

This is a proxy passed to the native code, to be called by the native trampoline code.

Field Summary

Modifier and TypeField and Description
pack-priv final CallContext
callContext

Keep references to the return and parameter types so they do not get garbage collected until the closure does.

pack-priv volatile Closure
pack-priv static final Method

Constructor Summary

AccessConstructor and Description
pack-priv
Proxy(CallContext callContext)

Method Summary

Modifier and TypeMethod and Description
private static Method

Returns:

The method to be invoked by native code
getMethod
()

Gets the Method to be invoked by native code

public void
invoke(long
The address of the native return value buffer
retvalAddress
,
long
The address of the native parameter buffer.
paramAddress
)

Invoked by the native closure trampoline to execute the java side of the closure.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callContextback to summary
pack-priv final CallContext callContext

Keep references to the return and parameter types so they do not get garbage collected until the closure does.

closureback to summary
pack-priv volatile Closure closure
METHODback to summary
pack-priv static final Method METHOD

Constructor Detail

Proxyback to summary
pack-priv Proxy(CallContext callContext)

Method Detail

getMethodback to summary
private static Method getMethod()

Gets the Method to be invoked by native code

Returns:Method

The method to be invoked by native code

invokeback to summary
public void invoke(long retvalAddress, long paramAddress)

Invoked by the native closure trampoline to execute the java side of the closure.

Parameters
retvalAddress:long

The address of the native return value buffer

paramAddress:long

The address of the native parameter buffer.