public abstract class JyAttribute extends Object implements Serializable
Manages a linked list of general purpose Object-attributes that
can be attached to arbitrary PyObject
s.
This method replaces the formerly used method of maintaining weak
hash-maps (WeakHashMap
) for such cases.
These weak hash-maps were used to map
PyObject
s to such attributes, for instance
to attach
GlobalRef
-objects in the
WeakrefModule
.
Attributes attached via the weak hash-map-method break, if the
PyObject
is resurrected in its finalizer. The
JyAttribute
-method is resurrection-safe.
To reduce memory footprint of PyObject
s, the fields for
FinalizeTrigger
s and
javaProxy
are included in the list; javaProxy
always
on top so there is no speed-regression,
FinalizeTrigger
on bottom,
as it is usually never accessed.
Modifier and Type | Field and Description |
---|---|
static byte |
FINALIZE_TRIGGER_ATTR |
static byte |
GC_CYCLE_MARK_ATTR
Used by
gc -module to mark cyclic
trash. |
static byte |
GC_DELAYED_FINALIZE_CRITIC_MARK_ATTR
Used by
gc -module to mark
finalizable objects that might have been resurrected
during a delayed finalization process. |
static byte |
JAVA_PROXY_ATTR |
static byte |
JYNI_HANDLE_ATTR
Reserved for use by JyNI.
|
static byte |
PY_ID_ATTR
Allows the id of a
PyObject to persist
resurrection of that object. |
static byte |
WEAK_REF_ATTR
Stores list of weak references linking to this
PyObject . |
static byte |
WEAKREF_PENDING_GET_ATTR
Holds the current thread for an
{@link org.python.modules.
|
Modifier and Type | Method and Description |
---|---|
static void |
debugPrintAttributes(PyObject o,
PrintStream out)
Prints the current state of the attribute-list of the
given object to the given stream.
|
static void |
delAttr(PyObject ob,
byte attr_type)
Removes the attribute of given type from the given object's attribute-list
(if it existed at all).
|
static Object |
getAttr(PyObject ob,
byte attr_type)
Retrieves the attribute of the given type from the given
PyObject . |
static boolean |
hasAttr(PyObject ob,
byte attr_type)
Checks whether the given
PyObject
has an attribute of the given type attached. |
static byte |
reserveCustomAttrType()
Reserves and returns a new non-transient attr type for custom use.
|
static byte |
reserveTransientCustomAttrType()
Reserves and returns a new transient attr type for custom use.
|
static void |
setAttr(PyObject ob,
byte attr_type,
Object value)
Sets the attribute of type
attr_type in ob to value . |
public static final byte JAVA_PROXY_ATTR
public static final byte WEAK_REF_ATTR
PyObject
.
This list is weakref-based, so it does not keep the
weakrefs alive. This is the only way to find out which
weakrefs (i.e. AbstractReference
)
linked to the object after a resurrection. A weak
hash-map-based approach for this purpose would break on
resurrection.public static final byte JYNI_HANDLE_ATTR
public static final byte PY_ID_ATTR
PyObject
to persist
resurrection of that object.public static final byte WEAKREF_PENDING_GET_ATTR
AbstractReference
while referent-retrieval is pending due to a potentially
restored-by-resurrection weak reference. After the
restore has happened or the clear was confirmed, the
thread is interrupted and the attribute is cleared.public static final byte GC_CYCLE_MARK_ATTR
gc
-module to mark cyclic
trash. Searching for cyclic trash is usually not required
by Jython. It is only done if gc-features are enabled that
mimic CPython behavior.public static final byte GC_DELAYED_FINALIZE_CRITIC_MARK_ATTR
gc
-module to mark
finalizable objects that might have been resurrected
during a delayed finalization process.public static final byte FINALIZE_TRIGGER_ATTR
public static byte reserveCustomAttrType()
public static byte reserveTransientCustomAttrType()
public static boolean hasAttr(PyObject ob, byte attr_type)
PyObject
has an attribute of the given type attached.public static Object getAttr(PyObject ob, byte attr_type)
PyObject
.
If no attribute of the given type is attached, null is returned.public static void debugPrintAttributes(PyObject o, PrintStream out)
public static void setAttr(PyObject ob, byte attr_type, Object value)
attr_type
in ob
to value
.
If no corresponding attribute exists yet, one is created. If ,
the attribute is removed (if it existed at all).public static void delAttr(PyObject ob, byte attr_type)
setAttr(ob, attr_type, null)
.