Class MemoryLayoutSpecification


  • public abstract class MemoryLayoutSpecification
    extends java.lang.Object
    • Constructor Detail

      • MemoryLayoutSpecification

        public MemoryLayoutSpecification()
    • 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 array
        type - 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 array
        elementSize - In-memory size of each element's primitive stored
        Returns:
        In-memory size of the array