Package com.infilos.utils.sizes
Class ObjectSizeCalculator
- java.lang.Object
-
- com.infilos.utils.sizes.ObjectSizeCalculator
-
public class ObjectSizeCalculator extends Object
-
-
Constructor Summary
Constructors Constructor Description ObjectSizeCalculator(MemoryLayoutSpec memoryLayoutSpec)
Creates an object size calculator that can calculate object sizes for a givenmemoryLayoutSpecification
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
calculateObjectSize(Object obj)
Given an object, returns the total allocated size, in bytes, of the object and all other objects reachable from it.
-
-
-
Constructor Detail
-
ObjectSizeCalculator
public ObjectSizeCalculator(MemoryLayoutSpec memoryLayoutSpec)
Creates an object size calculator that can calculate object sizes for a givenmemoryLayoutSpecification
.- Parameters:
memoryLayoutSpec
- a description of the JVM memory layout.
-
-
Method Detail
-
calculateObjectSize
public long calculateObjectSize(Object obj)
Given an object, returns the total allocated size, in bytes, of the object and all other objects reachable from it.- Parameters:
obj
- the object; can be null. Passing in aClass
object doesn't do anything special, it measures the size of all objects reachable through it (which will include its class loader, and by extension, all other Class objects loaded by the same loader, and all the parent class loaders). It doesn't provide the size of the static fields in the JVM class that the Class object represents.- Returns:
- the total allocated size of the object and all other objects it retains.
-
-