Package org.github.jamm.strategies
Class MemoryLayoutBasedStrategy
java.lang.Object
org.github.jamm.strategies.MemoryLayoutBasedStrategy
- All Implemented Interfaces:
MemoryMeterStrategy
- Direct Known Subclasses:
InstrumentationAndSpecStrategy
,UnsafeStrategy
Base class for strategies that need access to the
MemoryLayoutSpecification
for computing object size.-
Field Summary
Fields inherited from interface org.github.jamm.MemoryMeterStrategy
MEMORY_LAYOUT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int
Returns the array base offset.long
computeArraySize
(int length, int elementSize) Computes the size of an array from its length and elementSize.final long
Measures the shallow memory used by the specified object.long
measureArray
(boolean[] array) Measures the shallow memory used by the specified boolean array.long
measureArray
(byte[] array) Measures the shallow memory used by the specified byte array.long
measureArray
(char[] array) Measures the shallow memory used by the specified char array.long
measureArray
(double[] array) Measures the shallow memory used by the specified double array.long
measureArray
(float[] array) Measures the shallow memory used by the specified float array.long
measureArray
(int[] array) Measures the shallow memory used by the specified int array.long
measureArray
(long[] array) Measures the shallow memory used by the specified long array.long
measureArray
(short[] array) Measures the shallow memory used by the specified short array.long
measureArray
(Object[] array) Measures the shallow memory used by the specified array.final long
measureArray
(Object instance, Class<?> type) Measure the shallow memory used by the specified array.protected final int
measureField
(Class<?> type) Returns the size of a field of the specified type.protected abstract long
measureInstance
(Object instance, Class<?> type) Measures the shallow memory used by objects of the specified class.boolean
Checks if this instance supports thecomputeArraySize
operation.
-
Constructor Details
-
MemoryLayoutBasedStrategy
public MemoryLayoutBasedStrategy()
-
-
Method Details
-
measure
Description copied from interface:MemoryMeterStrategy
Measures the shallow memory used by the specified object.- Specified by:
measure
in interfaceMemoryMeterStrategy
- Parameters:
object
- the object to measure- Returns:
- the shallow memory usage of the specified object
-
measureArray
Description copied from interface:MemoryMeterStrategy
Measures the shallow memory used by the specified array.- Specified by:
measureArray
in interfaceMemoryMeterStrategy
- Parameters:
array
- the array to measure- Returns:
- the shallow memory used by the specified array.
-
measureArray
public long measureArray(byte[] array) Description copied from interface:MemoryMeterStrategy
Measures the shallow memory used by the specified byte array.- Specified by:
measureArray
in interfaceMemoryMeterStrategy
- Parameters:
array
- the array to measure- Returns:
- the shallow memory used by the specified byte array.
-
measureArray
public long measureArray(boolean[] array) Description copied from interface:MemoryMeterStrategy
Measures the shallow memory used by the specified boolean array.- Specified by:
measureArray
in interfaceMemoryMeterStrategy
- Parameters:
array
- the boolean array to measure- Returns:
- the shallow memory used by the specified boolean array.
-
measureArray
public long measureArray(short[] array) Description copied from interface:MemoryMeterStrategy
Measures the shallow memory used by the specified short array.- Specified by:
measureArray
in interfaceMemoryMeterStrategy
- Parameters:
array
- the short array to measure- Returns:
- the shallow memory used by the specified short array.
-
measureArray
public long measureArray(char[] array) Description copied from interface:MemoryMeterStrategy
Measures the shallow memory used by the specified char array.- Specified by:
measureArray
in interfaceMemoryMeterStrategy
- Parameters:
array
- the char array to measure- Returns:
- the shallow memory used by the specified char array.
-
measureArray
public long measureArray(int[] array) Description copied from interface:MemoryMeterStrategy
Measures the shallow memory used by the specified int array.- Specified by:
measureArray
in interfaceMemoryMeterStrategy
- Parameters:
array
- the int array to measure- Returns:
- the shallow memory used by the specified int array.
-
measureArray
public long measureArray(float[] array) Description copied from interface:MemoryMeterStrategy
Measures the shallow memory used by the specified float array.- Specified by:
measureArray
in interfaceMemoryMeterStrategy
- Parameters:
array
- the float array to measure- Returns:
- the shallow memory used by the specified float array.
-
measureArray
public long measureArray(long[] array) Description copied from interface:MemoryMeterStrategy
Measures the shallow memory used by the specified long array.- Specified by:
measureArray
in interfaceMemoryMeterStrategy
- Parameters:
array
- the long array to measure- Returns:
- the shallow memory used by the specified long array.
-
measureArray
public long measureArray(double[] array) Description copied from interface:MemoryMeterStrategy
Measures the shallow memory used by the specified double array.- Specified by:
measureArray
in interfaceMemoryMeterStrategy
- Parameters:
array
- the long array to measure- Returns:
- the shallow memory used by the specified double array.
-
measureInstance
Measures the shallow memory used by objects of the specified class.- Parameters:
instance
- the object to measuretype
- the object type- Returns:
- the shallow memory used by the object
-
measureArray
Measure the shallow memory used by the specified array.- Specified by:
measureArray
in interfaceMemoryMeterStrategy
- Parameters:
instance
- the array instancetype
- the array type- Returns:
- the shallow memory used by the specified array
-
supportComputeArraySize
public boolean supportComputeArraySize()Description copied from interface:MemoryMeterStrategy
Checks if this instance supports thecomputeArraySize
operation.- Specified by:
supportComputeArraySize
in interfaceMemoryMeterStrategy
- Returns:
true
if this instance support thecomputeArraySize
operation,false
otherwise.
-
arrayBaseOffset
protected int arrayBaseOffset()Returns the array base offset.Array base is aligned based on heap word. It is not visible by default as compressed references are used and the header size is 16 but becomes visible when they are disabled.
- Returns:
- the array base offset.
-
computeArraySize
public long computeArraySize(int length, int elementSize) Computes the size of an array from its length and elementSize.- Specified by:
computeArraySize
in interfaceMemoryMeterStrategy
- Parameters:
length
- the array lengthelementSize
- the size of the array elements- Returns:
- the size of the array
-
measureField
Returns the size of a field of the specified type.- Parameters:
type
- the field 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
-