Given a Java Object, how can I get a list of Objects that referring to it?
There must be extension mechanisms in the GC for doing this kind of thing, just can't seem to find them.
Given a Java Object, how can I get a list of Objects that referring to it?
There must be extension mechanisms in the GC for doing this kind of thing, just can't seem to find them.
I don't think there is such a mechanism, and there is no real reason the GC would need one.
If you're looking for a memory leak, I find analyzing heap dumps with Eclipse MAT to be very helpful. You can select an object and ask for paths to "GC roots", i.e. show me all chains of references that are keeping this object from being garbage collected.
I'm not sure if exactly what you're after is simply accessible.
The JPDA (Java Platform Debugger Architecture) enables construction of debuggers, so is a good starting point if you want to delve into the internals. There's a blog on the JPDA that you may also find useful. Check out the Sun Developer Network JPDA page for links to documentation, FAQs, sample code and forums.
Two interfaces that may be good starting points are:
It depends a little bit on how you want to use it but if you need it to analyze your memory usage, taking a heapdump and open it in MemoryAnalyzer or JHat will probably give you the information you need. Different ways of taking a heapdump can be found here.
The GC does not support this, though the JDPA APIs do. But I'd be very cautious about doing this kind of thing in a Java application. It is likely to be prohibitively expensive in both time and memory.