Class MemoryLayoutBasedStrategy

java.lang.Object
org.github.jamm.strategies.MemoryLayoutBasedStrategy
All Implemented Interfaces:
MemoryMeterStrategy
Direct Known Subclasses:
InstrumentationAndSpecStrategy, UnsafeStrategy

public abstract class MemoryLayoutBasedStrategy extends Object implements MemoryMeterStrategy
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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
    measure(Object object)
    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
    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
    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 the computeArraySize operation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MemoryLayoutBasedStrategy

      public MemoryLayoutBasedStrategy()
  • Method Details

    • measure

      public final long measure(Object object)
      Description copied from interface: MemoryMeterStrategy
      Measures the shallow memory used by the specified object.
      Specified by:
      measure in interface MemoryMeterStrategy
      Parameters:
      object - the object to measure
      Returns:
      the shallow memory usage of the specified object
    • measureArray

      public long measureArray(Object[] array)
      Description copied from interface: MemoryMeterStrategy
      Measures the shallow memory used by the specified array.
      Specified by:
      measureArray in interface MemoryMeterStrategy
      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 interface MemoryMeterStrategy
      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 interface MemoryMeterStrategy
      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 interface MemoryMeterStrategy
      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 interface MemoryMeterStrategy
      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 interface MemoryMeterStrategy
      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 interface MemoryMeterStrategy
      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 interface MemoryMeterStrategy
      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 interface MemoryMeterStrategy
      Parameters:
      array - the long array to measure
      Returns:
      the shallow memory used by the specified double array.
    • measureInstance

      protected abstract long measureInstance(Object instance, Class<?> type)
      Measures the shallow memory used by objects of the specified class.
      Parameters:
      instance - the object to measure
      type - the object type
      Returns:
      the shallow memory used by the object
    • measureArray

      public final long measureArray(Object instance, Class<?> type)
      Measure the shallow memory used by the specified array.
      Specified by:
      measureArray in interface MemoryMeterStrategy
      Parameters:
      instance - the array instance
      type - 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 the computeArraySize operation.
      Specified by:
      supportComputeArraySize in interface MemoryMeterStrategy
      Returns:
      true if this instance support the computeArraySize 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 interface MemoryMeterStrategy
      Parameters:
      length - the array length
      elementSize - the size of the array elements
      Returns:
      the size of the array
    • measureField

      protected final int measureField(Class<?> type)
      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