dsjoblom@abo.fi wrote On 08/11/06 13:06,:
>>Hi
>>
[quoted text clipped - 11 lines]
> If you really need this is another matter. It is probably only useful
> if you are writing a debugger or profiler.
Well, you learn something new every day!
Still, the JVMTI stuff doesn't seem to provide a way
to retrieve an object's reference count, since Java still
isn't keeping track of such a thing. The machinery could
be used to compute reference counts on demand (using
IterateOverReachableObjects or one of its brethren, along
with GetTag and SetTag), but two drawbacks seem worthy
of note:
- Object manipulation comes to a halt during the process:
no objects are created, garbage collected, or changed
in any way during the iteration. This implies that the
results must be returned after the fact, by which time
they could be out of date.
- "JVMTI may not be available in all implementations of
the Java[tm] virtual machine."
Nonetheless, thanks for the reference! I've got know
immediate use for it, but it's worth knowing the capabilities
are there should the need arise.

Signature
Eric.Sosman@sun.com
dsjoblom@abo.fi - 11 Aug 2006 19:18 GMT
> dsjoblom@abo.fi wrote On 08/11/06 13:06,:
> >
[quoted text clipped - 29 lines]
> results must be returned after the fact, by which time
> they could be out of date.
True, it requires a fair bit of programming, and it isn't perfect. I
should also add that it is probably not a good idea to expect the JVMTI
implementation to have lightning speed performance for this particular
task (although who knows, it does have a low overhead for other things,
I've used it for bytecode rewriting and JIT compiled code disassembly).
> - "JVMTI may not be available in all implementations of
> the Java[tm] virtual machine."
Also true, but JVMTI is definitely a step in the right direction (as
opposed to previous similar attempts by Sun), since it is a
standardized interface that can be, and is supposed to be implemented
by any VM vendor. The drawback right now is that it is a fairly new
interface, introduced in 1.5.
Regards,
Daniel Sjöblom