Package org.github.jamm
Class MemoryLayoutSpecification
- java.lang.Object
-
- org.github.jamm.MemoryLayoutSpecification
-
public abstract class MemoryLayoutSpecification extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static MemoryLayoutSpecification
SPEC
-
Constructor Summary
Constructors Constructor Description MemoryLayoutSpecification()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract int
getArrayHeaderSize()
abstract int
getObjectHeaderSize()
abstract int
getObjectPadding()
abstract int
getReferenceSize()
abstract int
getSuperclassFieldPadding()
static boolean
hasUnsafe()
static long
sizeOf(java.lang.Object obj)
static int
sizeOf(java.lang.reflect.Field field)
static long
sizeOfArray(int length, long elementSize)
Memory an array will consumestatic long
sizeOfArray(int length, java.lang.Class<?> type)
Memory an arraystatic long
sizeOfArray(java.lang.Object instance, java.lang.Class<?> type)
static int
sizeOfField(java.lang.Class<?> type)
static long
sizeOfInstance(java.lang.Class<?> type)
static long
sizeOfInstanceWithUnsafe(java.lang.Class<?> type)
static long
sizeOfWithUnsafe(java.lang.Object obj)
-
-
-
Field Detail
-
SPEC
public static final MemoryLayoutSpecification SPEC
-
-
Method Detail
-
getArrayHeaderSize
public abstract int getArrayHeaderSize()
-
getObjectHeaderSize
public abstract int getObjectHeaderSize()
-
getObjectPadding
public abstract int getObjectPadding()
-
getReferenceSize
public abstract int getReferenceSize()
-
getSuperclassFieldPadding
public abstract int getSuperclassFieldPadding()
-
hasUnsafe
public static boolean hasUnsafe()
-
sizeOf
public static int sizeOf(java.lang.reflect.Field field)
- Returns:
- sizeOfField(field.getType())
-
sizeOfField
public static int sizeOfField(java.lang.Class<?> type)
- Returns:
- The memory size of a field of a class of the provided type; for Objects this is the size of the reference only
-
sizeOf
public static long sizeOf(java.lang.Object obj)
- Returns:
- The size of the provided instance as defined by the detected MemoryLayoutSpecification. For an array this is dependent on the size of the array, but for an object this is fixed for all instances
-
sizeOfWithUnsafe
public static long sizeOfWithUnsafe(java.lang.Object obj)
- Returns:
- this allocated heap size of the instance provided; for arrays this is equivalent to sizeOf(obj), which uses the memory layout specification, however for objects this method uses
-
sizeOfInstance
public static long sizeOfInstance(java.lang.Class<?> type)
-
sizeOfInstanceWithUnsafe
public static long sizeOfInstanceWithUnsafe(java.lang.Class<?> type)
-
sizeOfArray
public static long sizeOfArray(java.lang.Object instance, java.lang.Class<?> type)
-
sizeOfArray
public static long sizeOfArray(int length, java.lang.Class<?> type)
Memory an array- Parameters:
length
- Number of elements in the arraytype
- the array class type- Returns:
- In-memory size of the array
-
sizeOfArray
public static long sizeOfArray(int length, long elementSize)
Memory an array will consume- Parameters:
length
- Number of elements in the arrayelementSize
- In-memory size of each element's primitive stored- Returns:
- In-memory size of the array
-
-