Class HeapUsageEstimator
java.lang.Object
com.gigaspaces.internal.jvm.HeapUsageEstimator
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
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetDesc()intintintintstatic voidstatic longroundTo(long x, int multiple) longlongsizeOfArray(Class<?> type, int length) intsizeOfField(Class<?> type) longsizeOfInstance(Class<?> type) Estimated from the declared field types plus the platform's header and padding rules.
-
Constructor Details
-
HeapUsageEstimator
public HeapUsageEstimator()
-
-
Method Details
-
getDesc
-
getObjectHeaderSize
public int getObjectHeaderSize() -
getObjectPadding
public int getObjectPadding() -
getSuperclassFieldPadding
public int getSuperclassFieldPadding() -
getReferenceSize
public int getReferenceSize() -
sizeOf
- 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
- 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
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.Unsafefor the highest field offset in the object, which got the alignment exactly right. It went with the rest ofUnsafein 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
-
roundTo
public static long roundTo(long x, int multiple) -
main
-