How to counter object created by hotspot

Peter B. Kessler Peter.Kessler at Sun.COM
Mon Jul 13 16:07:23 PDT 2009


Those methods are only used for "slow-path" allocations: when an object can't be allocated by the inline code generated by the runtime compilers.  So, if you *just* count those, you should see almost no allocations.  You _can_ force all allocations to go through the slow path to make the counts accurate.  Needless to say, it's a major hit on performance to call into the runtime for each object allocation.  And you'd be serializing allocation, which will hurt even more on a big machine.  I think JVMTI forces slow-path allocation to notify on object allocations, I think by filling up the young generation, so the fast inline allocation fails, but maybe we complained so much that they don't do that any more.  Maybe JVMTI has some better kind of object histogram by type mechanism, and maybe the performance is acceptable.  I just haven't looked recently.

What problem are you trying to solve?  If you just want to know how many of what kind of objects have been created, why not iterate over the young generation *before* each young generation collection?  You'd have to look at all the dead objects, so it wouldn't be fast, but you'd be iterating in address order, so it might not be so bad.  You might want to keep track of a high-water mark in the old generation, too, so you could find objects allocated directly in the old generation.  Oh, serial GC can allocate objects in the from-space, when pushed to the wall, so for completeness you want to track that too.

If you just want to count particular kinds of regular Objects you can probably do that with bytecode annotations on their <init> methods.  That won't work for arrays, since they don't have <init> methods.

Maybe someone else has some different hammers in their toolbag.

			... peter

Colin(Du Li) wrote:
> Can anyone give a hand?
> Thanks a lot!
> 
> Colin
> 
> Colin(Du Li) wrote:
>> Hi, guys,
>>
>> I wanna count the number of Java Objects created by Hotspot. Does Hotspot
>> have some tool to count them?
>>
>> If no, I just count how many times the following two methods are invoked,
>> is that accurate? 
>>             CollectedHeap::common_permanent_mem_allocate_init(size_t size, TRAPS)
>>             CollectedHeap::common_mem_allocate_init(size_t size, bool is_noref, TRAPS)
>>
>> Is there better solution to do this counting?
>>
>> p.s. I use serial GC.
>>
>> Thanks a lot!
>>
>> Colin



More information about the hotspot-dev mailing list