paul brown said:
maybe its handled in a similar way that people handle circular references
for object persistence frameworks?
i think they use a flag which says to the algorithm doing the
GCing/persisting..."you've been here during your first time round the
circle, so back off"
/snip/
Please remember that a "reachable" object must be
reachable starting with a local variable or with a
static field and following the reference chains of
the instance fields. (How else could a thread reach it?)
Note that JNI uses global and local "locking" of an
instance which serve analogous purposes to a static
field and an local variable, respectively. Do not
confuse JNI "locking" with synchronization (holding
an instance monitor). They are two entirely different
concepts. A global "lock" survives across a JNI method
call, while a local "lock" does not. When a JNI method
returns, all local "locks" that the method acquired are
automatically released. (This is similar to popping a
stackframe when a Java method returns and its local
variables are essentially nullified.) Releasing a "lock"
is analogous to assigning null (for the purposes of this
topic).
An object that is only reachable from an instance
field implies that the instance field that refers
to the object is owned by an instance that is also
unreachable. I.e., if you can only reach an instance
by starting at an instance field, then the instance
that owns that instance field is also only reachable by
an instance field (not a static field or a local variable).
So, the "brute-force" GC simply starts its search with
marking everything "collectable" (i.e., the "mark" phase),
then walks the chains of object references that are rooted
in the local variables of live threads (and the local
"locks" of active JNI methods) and all static fields of
loaded classes (and the global "locks" acquired by JNI
methods).
E.g., the GC search will not encounter a circular list of
instances that cannot be reached from any local variable of any
live thread or any static field, and thus all of those instances
will stay marked "collectable". The second phase, called "sweep",
will reclaim everything in the circular list.
The actual mark-and-sweep technique is slightly more
complicated due to SoftReference, WeakReference,
and PhantomReference processing, and some GC algorithms
copy/move live instances to defragment the heap.
--
----------------------------
Jeffrey D. Smith
Farsight Systems Corporation
24 BURLINGTON DRIVE
LONGMONT, CO 80501-6906
http://www.farsight-systems.com
z/Debug debugs your Systems/C programs running on IBM z/OS!
Are ISV upgrade fees too high? Check our custom product development!