public static final long sizeOf(Object obj) { return DEFAULT_SIZE_OF.sizeOf(obj); } }
public static final long deepSizeOf(Object obj) { return DEFAULT_SIZE_OF.deepSizeOf(Integer.MAX_VALUE, true, obj).getCalculated(); }
@BeforeClass public static void attachProfiler() { // tests whether the agent still works if other agents are around new AgentSizeOf(); Stagemonitor.init(); }
/** * Builds a new SizeOf that will filter fields according to the provided filter * @param fieldFilter The filter to apply * @param caching whether to cache reflected fields * @see SizeOfFilter */ public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); }
@Override public long sizeOf(Object obj) { return Math.max(CURRENT_JVM_INFORMATION.getMinimumObjectSize(), AgentLoader.agentSizeOf(obj) + CURRENT_JVM_INFORMATION.getAgentSizeOfAdjustment()); } }
/** * The size on an array * @return size in bytes */ public static long getArraySize() { return CURRENT_JVM_INFORMATION.getObjectHeaderSize() + INT.getSize(); }
/** * The size of an object header in bytes. */ public int getObjectHeaderSize() { return getPointerSize() + getJavaPointerSize(); }
/** * Finds the matching PrimitiveType for a type * @param type the type to find the PrimitiveType for * @return the PrimitiveType instance or null if none found */ public static PrimitiveType forType(final Class<?> type) { for (PrimitiveType primitiveType : values()) { if (primitiveType.getType() == type) { return primitiveType; } } return null; } }
/** * Minimal size an object will occupy on the heap in bytes. */ public int getMinimumObjectSize() { return getObjectAlignment(); }
/** * The size of a pointer * @return size in bytes */ public static int getReferenceSize() { return CURRENT_JVM_INFORMATION.getJavaPointerSize(); }
/** * The size of the jvm-specific field offset adjustment in bytes. */ public int getFieldOffsetAdjustment() { return parent.getFieldOffsetAdjustment(); }
/** * The size of the jvm-specific agent result adjustment in bytes. */ public int getAgentSizeOfAdjustment() { return parent.getAgentSizeOfAdjustment(); }
/** * Whether the jvm can support ReflectionSizeOf implementation. */ public boolean supportsReflectionSizeOf() { return parent.supportsReflectionSizeOf(); }
private long calculateSize(Object ref) { long visitSize = 0; if (ref == null) { return 0; } else { visitSize = visitor.visit(ref); } return visitSize; }
/** * {@inheritDoc} */ public long visit(Object object) { return sizeOf(object); } }
/** * Size of a pointer in bytes on this runtime */ public int getPointerSize() { return parent.getPointerSize(); }
/** * Whether the jvm can support UnsafeSizeOf implementation. */ public boolean supportsUnsafeSizeOf() { return parent.supportsUnsafeSizeOf(); }
/** * Whether the jvm can support AgentSizeOf implementation. */ public boolean supportsAgentSizeOf() { return parent.supportsAgentSizeOf(); }
/** * Object alignment / padding in bytes */ public int getObjectAlignment() { return parent.getObjectAlignment(); }
/** * Size of a java pointer in bytes on this runtime (that differs when compressedOops are being used) */ public int getJavaPointerSize() { return parent.getJavaPointerSize(); }