How to get an object's references through JVM

Hi,

I am performing some runtime program analysis and would like to know at exactly what point an object becomes "unreachable".

For example, I have a Testing Program (TP) and a Program Under Test (PUT) containing a set of classes. For each object o created by the PUT, TP maintains an object reference to it. At some point later, if TP decides that the only reference to object o is from TP (i.e., o is pointed to by some object out of the scope of PUT), then object o is considered to be "dead" (although it is not real garbage from the GC's point of view).

Hence, I am wondering if it is possible for any given object, to retrieve all the references that are pointing to it. If I am able to do this, maybe I can know whether the reference from TP is the only reference to an object in PUT.

Thank you and have a nice weekend,

-- Sunny

[875 byte] By [Sunny_Daya] at [2007-10-3 0:37:08]
# 1

This could be achieved with JVMTI. See http://java.sun.com/j2se/1.5.0/docs/guide/jvmti/jvmti.html#Heap

There is no ready made function for achieving what you want, but all the building blocks are there, since you can iterate over the heap and you can get information about all reference relationships.

Regards,

Daniel

dsjobloma at 2007-7-14 17:30:58 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
Hi Daniel,Thanks for your suggestions. JVMTI is a possible solution but it requires C/C++ code. Maybe I should consider alternative ways if no higher level API is available for this purpose. Best,-- Sunny
Sunny_Daya at 2007-7-14 17:30:58 > top of Java-index,Java HotSpot Virtual Machine,Specifications...