I am trying to write just an ObjectUtils
class that contains many utility methods for all objects. I would like one of them to be called getObjectSize(Object)
, where you pass it an instance of the object and return the size of the object in memory:
public class ObjectUtils { private static volatile Instrumentation instrumentation; public static final long getObjectSize(final Object p_oToGauge) { return instrumentation.getObjectSize(p_oToGauge); } }
However, it seems that in order to get an implemented instance of Instrumentation
you need to do all kinds of fancy things with the help of JRE agents and the so-called premain
method.
Is there an easy way to access local instances of JRE Instrumentation
? I searched for something through the Runtime
API, but couldn't find anything.
source share