Class HeapUsageEstimator

java.lang.Object
com.gigaspaces.internal.jvm.HeapUsageEstimator

public class HeapUsageEstimator extends Object
Based on Java memory spec, and specifically https://github.com/jbellis/jamm/blob/master/src/org/github/jamm/MemoryLayoutSpecification.java
Since:
15.5
Author:
Niv Ingberg
  • Constructor Details

    • HeapUsageEstimator

      public HeapUsageEstimator()
  • Method Details

    • getDesc

      public String getDesc()
    • getObjectHeaderSize

      public int getObjectHeaderSize()
    • getObjectPadding

      public int getObjectPadding()
    • getSuperclassFieldPadding

      public int getSuperclassFieldPadding()
    • getReferenceSize

      public int getReferenceSize()
    • sizeOf

      public long sizeOf(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
    • sizeOfField

      public int sizeOfField(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
    • sizeOfInstance

      public long sizeOfInstance(Class<?> type)
      Estimated from the declared field types plus the platform's header and padding rules. This is very close to accurate, but occasionally yields a slightly incorrect answer: when long fields are used and cannot be 8-byte aligned, an extra 4 bytes is allocated that this does not see.

      There used to be a second path that asked sun.misc.Unsafe for the highest field offset in the object, which got the alignment exactly right. It went with the rest of Unsafe in PIC-6303: its memory-access methods are deprecated for removal, and nothing supported replaces them here - the JVM deliberately exposes no way to ask for a Java object's layout, since it is free to change it. So the estimate above is now the only path, and the four bytes are the price.

    • sizeOfArray

      public long sizeOfArray(Class<?> type, int length)
    • roundTo

      public static long roundTo(long x, int multiple)
    • main

      public static void main(String[] args)