Interface MemoryMeterStrategy

All Known Implementing Classes:
InstrumentationAndSpecStrategy, MemoryLayoutBasedStrategy, UnsafeStrategy
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface MemoryMeterStrategy
Represents a strategy to measure the shallow memory used by a Java object.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The memory layout detected by JAMM.
  • Method Summary

    Modifier and Type
    Method
    Description
    default long
    computeArraySize(int length, int elementSize)
    Computes an array size from its length and element size (optional operation).
    long
    measure(Object object)
    Measures the shallow memory used by the specified object.
    default long
    measureArray(boolean[] array)
    Measures the shallow memory used by the specified boolean array.
    default long
    measureArray(byte[] array)
    Measures the shallow memory used by the specified byte array.
    default long
    measureArray(char[] array)
    Measures the shallow memory used by the specified char array.
    default long
    measureArray(double[] array)
    Measures the shallow memory used by the specified double array.
    default long
    measureArray(float[] array)
    Measures the shallow memory used by the specified float array.
    default long
    measureArray(int[] array)
    Measures the shallow memory used by the specified int array.
    default long
    measureArray(long[] array)
    Measures the shallow memory used by the specified long array.
    default long
    measureArray(short[] array)
    Measures the shallow memory used by the specified short array.
    default long
    Measures the shallow memory used by the specified array.
    default long
    measureArray(Object array, Class<?> type)
    Measures the shallow memory used by the specified array.
    default boolean
    Checks if this instance supports the computeArraySize operation.
  • Field Details

  • Method Details

    • measure

      long measure(Object object)
      Measures the shallow memory used by the specified object.
      Parameters:
      object - the object to measure
      Returns:
      the shallow memory usage of the specified object
    • measureArray

      default long measureArray(Object array, Class<?> type)
      Measures the shallow memory used by the specified array.
      Parameters:
      array - the array to measure
      type - the array type
      Returns:
      the shallow memory usage of the specified array
    • measureArray

      default long measureArray(Object[] array)
      Measures the shallow memory used by the specified array.
      Parameters:
      array - the array to measure
      Returns:
      the shallow memory used by the specified array.
    • measureArray

      default long measureArray(byte[] array)
      Measures the shallow memory used by the specified byte array.
      Parameters:
      array - the array to measure
      Returns:
      the shallow memory used by the specified byte array.
    • measureArray

      default long measureArray(boolean[] array)
      Measures the shallow memory used by the specified boolean array.
      Parameters:
      array - the boolean array to measure
      Returns:
      the shallow memory used by the specified boolean array.
    • measureArray

      default long measureArray(short[] array)
      Measures the shallow memory used by the specified short array.
      Parameters:
      array - the short array to measure
      Returns:
      the shallow memory used by the specified short array.
    • measureArray

      default long measureArray(char[] array)
      Measures the shallow memory used by the specified char array.
      Parameters:
      array - the char array to measure
      Returns:
      the shallow memory used by the specified char array.
    • measureArray

      default long measureArray(int[] array)
      Measures the shallow memory used by the specified int array.
      Parameters:
      array - the int array to measure
      Returns:
      the shallow memory used by the specified int array.
    • measureArray

      default long measureArray(float[] array)
      Measures the shallow memory used by the specified float array.
      Parameters:
      array - the float array to measure
      Returns:
      the shallow memory used by the specified float array.
    • measureArray

      default long measureArray(long[] array)
      Measures the shallow memory used by the specified long array.
      Parameters:
      array - the long array to measure
      Returns:
      the shallow memory used by the specified long array.
    • measureArray

      default long measureArray(double[] array)
      Measures the shallow memory used by the specified double array.
      Parameters:
      array - the long array to measure
      Returns:
      the shallow memory used by the specified double array.
    • supportComputeArraySize

      default boolean supportComputeArraySize()
      Checks if this instance supports the computeArraySize operation.
      Returns:
      true if this instance support the computeArraySize operation, false otherwise.
    • computeArraySize

      default long computeArraySize(int length, int elementSize)
      Computes an array size from its length and element size (optional operation).

      supportComputeArraySize should be used before calling this method to check if this operation is supported.

      Parameters:
      length - the array length
      elementSize - the size of the elements
      Returns:
      the array size
      Throws:
      UnsupportedOperationException - if the operation is not supported