Package com.carrotsearch.hppc
Class RamUsageEstimator
java.lang.Object
com.carrotsearch.hppc.RamUsageEstimator
Helper class that helps estimate memory usage
Mostly forked from Lucene
tag releases/lucene-solr/8.5.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanTrue, iff compressed references (oops) are enabled by this JVM(package private) static final String(package private) static final boolean(package private) static final Stringstatic final intNumber of bytes to represent an array header (no content, but with alignments).static final intA constant specifying the object alignment boundary inside the JVM.static final intNumber of bytes to represent an object header (no fields, no alignments).static final intNumber of bytes this JVM uses to represent an object reference.static final longOne gigabyte bytes.static final longOne kilobyte bytes.static final longOne megabyte bytes.(package private) static final StringSizes of primitive classes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static longadjustForField(long sizeSoFar, Field f) This method returns the maximum representation size of an object.static longalignObjectSize(long size) Aligns an object size to be the next multiple ofNUM_BYTES_OBJECT_ALIGNMENT.static longshallowSizeOf(Object obj) Estimates a "shallow" memory usage of the given object.private static longshallowSizeOfArray(Object array) Return shallow size of anyarray.static longshallowSizeOfInstance(Class<?> clazz) Returns the shallow instance size in bytes an instance of the given class would occupy.static longshallowUsedSizeOfArray(Object array, int usedSize) Return used part of shallow size of anyarray.
-
Field Details
-
ONE_KB
public static final long ONE_KBOne kilobyte bytes.- See Also:
-
ONE_MB
public static final long ONE_MBOne megabyte bytes.- See Also:
-
ONE_GB
public static final long ONE_GBOne gigabyte bytes.- See Also:
-
COMPRESSED_REFS_ENABLED
public static final boolean COMPRESSED_REFS_ENABLEDTrue, iff compressed references (oops) are enabled by this JVM -
NUM_BYTES_OBJECT_REF
public static final int NUM_BYTES_OBJECT_REFNumber of bytes this JVM uses to represent an object reference. -
NUM_BYTES_OBJECT_HEADER
public static final int NUM_BYTES_OBJECT_HEADERNumber of bytes to represent an object header (no fields, no alignments). -
NUM_BYTES_ARRAY_HEADER
public static final int NUM_BYTES_ARRAY_HEADERNumber of bytes to represent an array header (no content, but with alignments). -
NUM_BYTES_OBJECT_ALIGNMENT
public static final int NUM_BYTES_OBJECT_ALIGNMENTA constant specifying the object alignment boundary inside the JVM. Objects will always take a full multiple of this constant, possibly wasting some space. -
primitiveSizes
Sizes of primitive classes. -
JRE_IS_64BIT
static final boolean JRE_IS_64BIT -
MANAGEMENT_FACTORY_CLASS
- See Also:
-
HOTSPOT_BEAN_CLASS
- See Also:
-
OS_ARCH
-
-
Constructor Details
-
RamUsageEstimator
private RamUsageEstimator()No instantiation.
-
-
Method Details
-
alignObjectSize
public static long alignObjectSize(long size) Aligns an object size to be the next multiple ofNUM_BYTES_OBJECT_ALIGNMENT. -
shallowSizeOfInstance
Returns the shallow instance size in bytes an instance of the given class would occupy. This works with all conventional classes and primitive types, but not with arrays (the size then depends on the number of elements and varies from object to object).- Throws:
IllegalArgumentException- ifclazzis an array class.- See Also:
-
shallowSizeOf
Estimates a "shallow" memory usage of the given object. For arrays, this will be the memory taken by array storage (no subreferences will be followed). For objects, this will be the memory taken by the fields. JVM object alignments are also applied. -
shallowUsedSizeOfArray
Return used part of shallow size of anyarray.- Parameters:
usedSize- Size that array is actually used
-
shallowSizeOfArray
Return shallow size of anyarray. -
adjustForField
This method returns the maximum representation size of an object.sizeSoFaris the object's size measured so far.fis the field being probed.The returned offset will be the maximum of whatever was measured so far and
ffield's offset and representation size (unaligned).
-