>>>>> "Jiang" == Jiang Wu <[EMAIL PROTECTED]> writes:
Thanks, this description helps alot.
Jiang> Background: The relationship between the various objects
Jiang> are quite tricky. It takes some time to think them
Jiang> through. Basically, to reference a Tcl_Obj, the C
Jiang> structure representing a Tcl object in the C Tcl
Jiang> interpreter, TclBlend creates a TclObject, a Java class
Jiang> instance using the following relationship:
Jiang> TclObject (tcl.lang.TclObject, Java class) <contains>
Jiang> CObject (tcl.lang.CObject, Java class) <contains>
Jiang> a pointer to Tcl_Obj
In the case above what does the Tcl_Obj represent? Is it just a native
tcl object such as a string, a list, or an array?
Jiang> CObject is a subclass of InternalObject
Jiang> (tcl.lang.InternalObject). InternalObject is an abstract
Jiang> class containing an interface so that TclObject can be used
Jiang> as the common interface to not only Tcl_Obj, but also other
Jiang> types of TclBlend objects such as ReflectObject,
Jiang> TclInteger, etc, all of those are subclass of
Jiang> InternalObject.
Jiang> On the C side, the C Tcl interpreter needs access to Java
Jiang> objects defined in TclBlend, such as ReflectObject,
Jiang> TclInteger, etc. TclBlend uses a Tcl_Obj implementation to
Jiang> wrap around any TclObject using the following relationship:
Jiang> Tcl_Obj (A C struct with function pointers to functions
Jiang> that are specifically designed to manipulate TclBlend's
Jiang> TclObject. Defined in javaObj.c in TclBlend.) <contains>
Jiang> reference/pointer to the Java TclObject
This makes sense. The Tcl_Obj internal rep always holds a jobject
handle to a java TclObject.
Jiang> It seems that you can get infinite recusive containment as
Jiang> in:
Jiang> Tcl_Object <contains>
Jiang> Tcl_Obj <contains>
Jiang> Tcl_Object <contains>
Jiang> Tcl_Obj <contains> ...
Yeh this was confusing me, especially when I started thinking about
the changes you made to the refcounting code.
Jiang> TclBlend is smart enough to detect such attempt. When it
Jiang> is detected, TclBlend removes the extra level containment
Jiang> so that most of the time you will have either:
Is that what's going on in the setInternalRep method of the TclObject
class? It checks for a CObject internal rep and creates a new
reference to the current TclObject instance if the new rep is not of
type CObject. Where else is this detection done?
Jiang> Tcl_Object <contains> Tcl_Obj
Jiang> or
Jiang> Tcl_Obj <contains> Tcl_Object
Jiang> The Problem:
Jiang> The proposed solution is to never use the GC thread to free
Jiang> Tcl_Obj and always use the thread that created the Tcl_Obj
Jiang> to free the Tcl_Obj.
My initial impression is that this is the correct way to do it, though
it can be tricky to get all of the reference counting right.
-Dan
----------------------------------------------------------------
The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe: send mail to [EMAIL PROTECTED]
with the word SUBSCRIBE as the subject.
To unsubscribe: send mail to [EMAIL PROTECTED]
with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'.
An archive is available at http://www.mail-archive.com/tcljava@scriptics.com