Top Description Inners Fields Constructors Methods
org.python.core

public abstract Class JyAttribute

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.python.core.JyAttribute.AttributeLink, org.python.core.JyAttribute.TransientAttributeLink
Imports
java.io.Serializable

Manages a linked list of general purpose Object-attributes that can be attached to arbitrary org.python.core.PyObjects. This method replaces the formerly used method of maintaining weak hash-maps (java.util.WeakHashMap) for such cases. These weak hash-maps were used to map PyObjects to such attributes, for instance to attach org.python.modules._weakref.GlobalRef-objects in the org.python.modules._weakref.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 PyObjects, the fields for org.python.core.finalization.FinalizeTriggers and javaProxy are included in the list; javaProxy always on top so there is no speed-regression, org.python.core.finalization.FinalizeTrigger on bottom, as it is usually never accessed.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv byte
public static final byte
public static final byte
GC_CYCLE_MARK_ATTR

Used by org.python.modules.gc-module to mark cyclic trash.

public static final byte
GC_DELAYED_FINALIZE_CRITICAL_MARK_ATTR

Used by org.python.modules.gc-module to mark finalizable objects that might have been resurrected during a delayed finalization process.

public static final byte
public static final byte
JYNI_HANDLE_ATTR

Reserved for use by JyNI.

private static byte
private static byte
public static final byte
PY_ID_ATTR

Allows the id of a org.python.core.PyObject to persist resurrection of that object.

public static final byte
public static final byte
WEAK_REF_ATTR

Stores list of weak references linking to this PyObject.

public static final byte
WEAKREF_PENDING_GET_ATTR

Holds the current thread for an org.python.modules._weakref.AbstractReference while referent-retrieval is pending due to a potentially restored-by-resurrection weak reference.

Constructor Summary

AccessConstructor and Description
protected
JyAttribute(byte attr_type)

Method Summary

Modifier and TypeMethod and Description
public static void
debugPrintAttributes(PyObject o, PrintStream out)

Prints the current state of the attribute-list of the given object to the given stream.

public 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).

public static Object
getAttr(PyObject ob, byte attr_type)

Retrieves the attribute of the given type from the given org.python.core.PyObject.

protected abstract JyAttribute
protected abstract Object
public static boolean
hasAttr(PyObject ob, byte attr_type)

Checks whether the given org.python.core.PyObject has an attribute of the given type attached.

public static byte

Returns:

a non-transient attr type for custom use
reserveCustomAttrType
()

Reserves and returns a new non-transient attr type for custom use.

public static byte

Returns:

a transient attr type for custom use
reserveTransientCustomAttrType
()

Reserves and returns a new transient attr type for custom use.

public static void
setAttr(PyObject ob, byte attr_type, Object value)

Sets the attribute of type attr_type in ob to value.

protected abstract void
protected abstract void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attr_typeback to summary
pack-priv byte attr_type
FINALIZE_TRIGGER_ATTRback to summary
public static final byte FINALIZE_TRIGGER_ATTR
GC_CYCLE_MARK_ATTRback to summary
public static final byte GC_CYCLE_MARK_ATTR

Used by org.python.modules.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.

GC_DELAYED_FINALIZE_CRITICAL_MARK_ATTRback to summary
public static final byte GC_DELAYED_FINALIZE_CRITICAL_MARK_ATTR

Used by org.python.modules.gc-module to mark finalizable objects that might have been resurrected during a delayed finalization process.

JAVA_PROXY_ATTRback to summary
public static final byte JAVA_PROXY_ATTR
JYNI_HANDLE_ATTRback to summary
public static final byte JYNI_HANDLE_ATTR

Reserved for use by JyNI.

nonBuiltinAttrTypeOffsetback to summary
private static byte nonBuiltinAttrTypeOffset
nonBuiltinTransientAttrTypeOffsetback to summary
private static byte nonBuiltinTransientAttrTypeOffset
PY_ID_ATTRback to summary
public static final byte PY_ID_ATTR

Allows the id of a org.python.core.PyObject to persist resurrection of that object.

PYCLASS_PY2JY_CACHE_ATTRback to summary
public static final byte PYCLASS_PY2JY_CACHE_ATTR

Only used internally by Py#javaPyClass(PyObject, Class)

WEAK_REF_ATTRback to summary
public static final byte WEAK_REF_ATTR

Stores list of weak references linking to this 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. org.python.modules._weakref.AbstractReference) linked to the object after a resurrection. A weak hash-map-based approach for this purpose would break on resurrection.

WEAKREF_PENDING_GET_ATTRback to summary
public static final byte WEAKREF_PENDING_GET_ATTR

Holds the current thread for an org.python.modules._weakref.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.

Constructor Detail

JyAttributeback to summary
protected JyAttribute(byte attr_type)

Method Detail

debugPrintAttributesback to summary
public static void debugPrintAttributes(PyObject o, PrintStream out)

Prints the current state of the attribute-list of the given object to the given stream. (Intended for debugging)

delAttrback to summary
public 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). This is equivalent to calling setAttr(ob, attr_type, null).

getAttrback to summary
public static Object getAttr(PyObject ob, byte attr_type)

Retrieves the attribute of the given type from the given org.python.core.PyObject. If no attribute of the given type is attached, null is returned.

getNextback to summary
protected abstract JyAttribute getNext()
getValueback to summary
protected abstract Object getValue()
hasAttrback to summary
public static boolean hasAttr(PyObject ob, byte attr_type)

Checks whether the given org.python.core.PyObject has an attribute of the given type attached.

reserveCustomAttrTypeback to summary
public static byte reserveCustomAttrType()

Reserves and returns a new non-transient attr type for custom use.

Returns:byte

a non-transient attr type for custom use

reserveTransientCustomAttrTypeback to summary
public static byte reserveTransientCustomAttrType()

Reserves and returns a new transient attr type for custom use.

Returns:byte

a transient attr type for custom use

setAttrback to summary
public static void setAttr(PyObject ob, byte attr_type, Object value)

Sets the attribute of type attr_type in ob to value. If no corresponding attribute exists yet, one is created. If value == null, the attribute is removed (if it existed at all).

setNextback to summary
protected abstract void setNext(JyAttribute next)
setValueback to summary
protected abstract void setValue(Object value)