java.lang.instrument.Instrumentation.getObjectSize for java.lang.Class instance

David Holmes david.holmes at
Sun Dec 16 18:57:47 PST 2012

On 17/12/2012 12:20 PM, Krystal Mok wrote:
> On Mon, Dec 17, 2012 at 10:01 AM, David Holmes<david.holmes at>  wrote:
> <snip>
>> But the key thing is that you need two different API's here: one for regular
>> objects and one for Class instances. To that end
>> Instrumentation.getObjectSize is not that useful for Class instances, but I
>> think the implementation chosen is not what people would generally want when
>> asking about Class sizes.
> Yes, I totally agree with having Instrumentation.getObjectSize return
> a more intuitive value for Class sizes, and perhaps adding another
> dedicated method for those that need the current behavior for Class.
> The JavaDoc [1] for this method is quite loose. Does anybody know the
> history of why there was special handling for Class in the first
> place?

I can only guess that someone was trying to deal with the fact that you 
really want to know the size of the class instance for a given Class (ie 
including the static fields).

I'm not 100% sure what it actually does return. The whole setup with 
class mirrors etc was rather confusing to me pre-PermGenRemoval. But 
post NPG I don't know what to use to get the "right" size info.


> Regards,
> Kris
> [1]:
>> David

More information about the hotspot-runtime-dev mailing list