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 intReturns the array base offset.longcomputeArraySize(int length, int elementSize) Computes the size of an array from its length and elementSize.final longMeasures the shallow memory used by the specified object.longmeasureArray(boolean[] array) Measures the shallow memory used by the specified boolean array.longmeasureArray(byte[] array) Measures the shallow memory used by the specified byte array.longmeasureArray(char[] array) Measures the shallow memory used by the specified char array.longmeasureArray(double[] array) Measures the shallow memory used by the specified double array.longmeasureArray(float[] array) Measures the shallow memory used by the specified float array.longmeasureArray(int[] array) Measures the shallow memory used by the specified int array.longmeasureArray(long[] array) Measures the shallow memory used by the specified long array.longmeasureArray(short[] array) Measures the shallow memory used by the specified short array.longmeasureArray(Object[] array) Measures the shallow memory used by the specified array.final longmeasureArray(Object instance, Class<?> type) Measure the shallow memory used by the specified array.protected final intmeasureField(Class<?> type) Returns the size of a field of the specified type.protected abstract longmeasureInstance(Object instance, Class<?> type) Measures the shallow memory used by objects of the specified class.booleanChecks if this instance supports thecomputeArraySizeoperation.
-
Constructor Details
-
MemoryLayoutBasedStrategy
public MemoryLayoutBasedStrategy()
-
-
Method Details
-
measure
Description copied from interface:MemoryMeterStrategyMeasures the shallow memory used by the specified object.- Specified by:
measurein interfaceMemoryMeterStrategy- Parameters:
object- the object to measure- Returns:
- the shallow memory usage of the specified object
-
measureArray
Description copied from interface:MemoryMeterStrategyMeasures the shallow memory used by the specified array.- Specified by:
measureArrayin 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:MemoryMeterStrategyMeasures the shallow memory used by the specified byte array.- Specified by:
measureArrayin 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:MemoryMeterStrategyMeasures the shallow memory used by the specified boolean array.- Specified by:
measureArrayin 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:MemoryMeterStrategyMeasures the shallow memory used by the specified short array.- Specified by:
measureArrayin 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:MemoryMeterStrategyMeasures the shallow memory used by the specified char array.- Specified by:
measureArrayin 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:MemoryMeterStrategyMeasures the shallow memory used by the specified int array.- Specified by:
measureArrayin 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:MemoryMeterStrategyMeasures the shallow memory used by the specified float array.- Specified by:
measureArrayin 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:MemoryMeterStrategyMeasures the shallow memory used by the specified long array.- Specified by:
measureArrayin 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:MemoryMeterStrategyMeasures the shallow memory used by the specified double array.- Specified by:
measureArrayin 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:
measureArrayin 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:MemoryMeterStrategyChecks if this instance supports thecomputeArraySizeoperation.- Specified by:
supportComputeArraySizein interfaceMemoryMeterStrategy- Returns:
trueif this instance support thecomputeArraySizeoperation,falseotherwise.
-
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:
computeArraySizein 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
-