Top Inners Fields Constructors Methods
org.python.modules._weakref

public Class GlobalRef

extends WeakReference<PyObject>
implements ReferenceBackend
Class Inheritance
All Implemented Interfaces
org.python.modules._weakref.ReferenceBackend
Imports
java.lang.ref.ReferenceQueue, .WeakReference, java.util.ArrayList, .List, java.util.concurrent.Callable, .ConcurrentMap, java.util.concurrent.locks.ReentrantReadWriteLock, org.python.core.JyAttribute, .Py, .PyList, .PyObject, .PySystemState, org.python.util.Generic, org.python.modules.gc

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
protected boolean
cleared

This boolean is set true when the callback is processed.

private static List<GlobalRef>
public static ReferenceBackendFactory
factory

This is a hook for JyNI to insert a native-objects-aware implementation of ReferenceBackend.

private int
hashCode

This reference's hashCode: The System.identityHashCode of the referent.

private boolean
havePythonHashCode

Whether pythonHashCode was already determined.

private static ConcurrentMap<GlobalRef, ReferenceBackend>
private int
pythonHashCode

The public hashCode for the Python AbstractReference wrapper.

private static ReentrantReadWriteLock
private static volatile Thread
private static ReferenceQueue<PyObject>
private List<WeakReference<AbstractReference>>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
pack-priv synchronized void
call()

Call each of the registered references.

public synchronized int
private static void
private static void
delayedCallback(GlobalRef cl)

Stores the callback for later processing.

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Allow GlobalRefs to be used as hashtable-keys.

public synchronized AbstractReference
find(Class<?> cls)

Implements org.python.modules._weakref.ReferenceBackend.find.

Search for a reusable reference.

public static int

Returns:

an int reference count
getCount
(PyObject
a PyObject
object
)

Return the number of references to the specified org.python.core.PyObject.

private final AbstractReference
getReferenceAt(int idx)

public static PyList

Returns:

a org.python.core.PyList of references. May be empty.
getRefs
(PyObject object)

Return a list of references to the specified org.python.core.PyObject.

public static boolean
public int

Returns:

a hashCode int-value
hashCode
()

Overrides java.lang.Object.hashCode.

Allows GlobalRef to be used as hashtable-keys.

private static void
public boolean
public static ReferenceBackend

Returns:

a new tracked ReferenceBackend
newInstance
(PyObject object)

Create a new tracked ReferenceBackend.

public static void
processDelayedCallbacks()

Call all callbacks that were enqueued via delayedCallback(GlobalRef) method.

public int

Returns:

a hashCode int-value
pythonHashCode
()

Implements org.python.modules._weakref.ReferenceBackend.pythonHashCode.

The publicly used hashCode, for the org.python.modules._weakref.AbstractReference wrapper.

public synchronized PyList
public synchronized void
restore(PyObject formerReferent)

Implements org.python.modules._weakref.ReferenceBackend.restore.

Restores this weak reference to its former referent.

protected synchronized ReferenceBackend
retryFactory()

Returns null if nothing is changed.

Field Detail

clearedback to summary
protected boolean cleared

This boolean is set true when the callback is processed. If the reference is cleared it might potentially be restored until this boolean is set true. If weak reference restoring is activated (c.f. gc#PRESERVE_WEAKREFS_ON_RESURRECTION), AbstractReference#get() would block until a consistent state is reached (i.e. referent is non-null or cleared == true).

See Also
gc#PRESERVE_WEAKREFS_ON_RESURRECTION, AbstractReference#get()
delayedCallbacksback to summary
private static List<GlobalRef> delayedCallbacks
factoryback to summary
public static ReferenceBackendFactory factory

This is a hook for JyNI to insert a native-objects-aware implementation of ReferenceBackend.

hashCodeback to summary
private int hashCode

This reference's hashCode: The System.identityHashCode of the referent. Only used internally.

havePythonHashCodeback to summary
private boolean havePythonHashCode

Whether pythonHashCode was already determined.

objectsback to summary
private static ConcurrentMap<GlobalRef, ReferenceBackend> objects
pythonHashCodeback to summary
private int pythonHashCode

The public hashCode for the Python AbstractReference wrapper. Derived from the referent's hashCode.

reaperLockback to summary
private static ReentrantReadWriteLock reaperLock
reaperThreadback to summary
private static volatile Thread reaperThread
referenceQueueback to summary
private static ReferenceQueue<PyObject> referenceQueue
referencesback to summary
private List<WeakReference<AbstractReference>> references

Constructor Detail

GlobalRefback to summary
public GlobalRef(PyObject object)

Method Detail

addback to summary
public synchronized void add(AbstractReference ref)

Implements org.python.modules._weakref.ReferenceBackend.add.

callback to summary
pack-priv synchronized void call()

Call each of the registered references.

countback to summary
public synchronized int count()

Implements org.python.modules._weakref.ReferenceBackend.count.

createReaperThreadIfAbsentback to summary
private static void createReaperThreadIfAbsent()
delayedCallbackback to summary
private static void delayedCallback(GlobalRef cl)

Stores the callback for later processing. This is needed if weak reference restoration (c.f. gc#PRESERVE_WEAKREFS_ON_RESURRECTION) is active. In this case the callback is delayed until it was determined whether a resurrection restored the reference.

See Also
gc#PRESERVE_WEAKREFS_ON_RESURRECTION, gc#FORCE_DELAYED_WEAKREF_CALLBACKS
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Allow GlobalRefs to be used as hashtable-keys.

Parameters
o:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

findback to summary
public synchronized AbstractReference find(Class<?> cls)

Implements org.python.modules._weakref.ReferenceBackend.find.

Search for a reusable reference. To be reused, it must be of the same class and it must not have a callback.

getCountback to summary
public static int getCount(PyObject object)

Return the number of references to the specified org.python.core.PyObject.

Parameters
object:PyObject

a PyObject

Returns:int

an int reference count

getReferenceAtback to summary
private final AbstractReference getReferenceAt(int idx)
getRefsback to summary
public static PyList getRefs(PyObject object)

Return a list of references to the specified org.python.core.PyObject.

Parameters
object:PyObject

a org.python.core.PyObject

Returns:PyList

a org.python.core.PyList of references. May be empty.

hasDelayedCallbacksback to summary
public static boolean hasDelayedCallbacks()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Allows GlobalRef to be used as hashtable-keys.

Returns:int

a hashCode int-value

initReaperThreadback to summary
private static void initReaperThread()
isClearedback to summary
public boolean isCleared()

Implements org.python.modules._weakref.ReferenceBackend.isCleared.

newInstanceback to summary
public static ReferenceBackend newInstance(PyObject object)

Create a new tracked ReferenceBackend. If no ReferenceBackendFactory is registered, it actually returns a GlobalRef.

Parameters
object:PyObject

a org.python.core.PyObject to reference

Returns:ReferenceBackend

a new tracked ReferenceBackend

processDelayedCallbacksback to summary
public static void processDelayedCallbacks()

Call all callbacks that were enqueued via delayedCallback(GlobalRef) method.

See Also
delayedCallback(GlobalRef)
pythonHashCodeback to summary
public int pythonHashCode()

Implements org.python.modules._weakref.ReferenceBackend.pythonHashCode.

The publicly used hashCode, for the org.python.modules._weakref.AbstractReference wrapper.

Returns:int

a hashCode int-value

refsback to summary
public synchronized PyList refs()

Implements org.python.modules._weakref.ReferenceBackend.refs.

restoreback to summary
public synchronized void restore(PyObject formerReferent)

Implements org.python.modules._weakref.ReferenceBackend.restore.

Restores this weak reference to its former referent. This actually means that a fresh GlobalRef is created and inserted into all adjacent org.python.modules._weakref.AbstractReferences. The current GlobalRef is disbanded. If the given org.python.core.PyObject is not the former referent of this weak reference, an java.lang.IllegalArgumentException is thrown.

Exceptions
IllegalArgumentException:
if formerReferent is not the actual former referent.
retryFactoryback to summary
protected synchronized ReferenceBackend retryFactory()

Returns null if nothing is changed. If a factory exists and produces a result different from this, this result is returned. Also, this result is then installed in all weak-references, in the referent's JyAttribute and in the objects-map to act as a proxy for this GlobalRef, which will still serve as a backend for the proxy. This method is most likely used exclusively by JyNI.

org.python.modules._weakref back to summary

private Class GlobalRef.RefReaper

extends Object
implements Runnable, Callable<Void>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Callable, java.lang.Runnable

Field Summary

Modifier and TypeField and Description
private volatile boolean
private Thread

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Void
call()

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

public void
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

exitback to summary
private volatile boolean exit
threadback to summary
private Thread thread

Constructor Detail

RefReaperback to summary
private RefReaper()

Method Detail

callback to summary
public Void call() throws Exception

Implements java.util.concurrent.Callable.call.

Doc from java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

Returns:Void

computed result

Annotations
@Override
Exceptions
Exception:
if unable to compute a result

collectback to summary
public void collect() throws InterruptedException
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override