public final class RamUsageEstimator extends Object
shallowSizeOf(Object)
,
shallowSizeOfInstance(Class)
Modifier and Type | Class and Description |
---|---|
static class |
RamUsageEstimator.JvmFeature
JVM diagnostic features.
|
Modifier and Type | Field and Description |
---|---|
static String |
JVM_INFO_STRING
JVM info string for debugging and reports.
|
static int |
NUM_BYTES_ARRAY_HEADER
Number of bytes to represent an array header (no content, but with alignments).
|
static int |
NUM_BYTES_BOOLEAN |
static int |
NUM_BYTES_BYTE |
static int |
NUM_BYTES_CHAR |
static int |
NUM_BYTES_DOUBLE |
static int |
NUM_BYTES_FLOAT |
static int |
NUM_BYTES_INT |
static int |
NUM_BYTES_LONG |
static int |
NUM_BYTES_OBJECT_ALIGNMENT
A constant specifying the object alignment boundary inside the JVM.
|
static int |
NUM_BYTES_OBJECT_HEADER
Number of bytes to represent an object header (no fields, no alignments).
|
static int |
NUM_BYTES_OBJECT_REF
Number of bytes this jvm uses to represent an object reference.
|
static int |
NUM_BYTES_SHORT |
static long |
ONE_GB
One gigabyte bytes.
|
static long |
ONE_KB
One kilobyte bytes.
|
static long |
ONE_MB
One megabyte bytes.
|
Modifier and Type | Method and Description |
---|---|
static long |
alignObjectSize(long size)
Aligns an object size to be the next multiple of
NUM_BYTES_OBJECT_ALIGNMENT . |
static EnumSet<RamUsageEstimator.JvmFeature> |
getSupportedFeatures()
Return the set of supported JVM features that improve the estimation.
|
static EnumSet<RamUsageEstimator.JvmFeature> |
getUnsupportedFeatures()
Return the set of unsupported JVM features that improve the estimation.
|
static String |
humanReadableUnits(long bytes)
Returns
size in human-readable units (GB, MB, KB or bytes). |
static String |
humanReadableUnits(long bytes,
DecimalFormat df)
Returns
size in human-readable units (GB, MB, KB or bytes). |
static boolean |
isSupportedJVM()
Returns true, if the current JVM is fully supported by
RamUsageEstimator . |
static long |
shallowSizeOf(Object obj)
Estimates a "shallow" memory usage of the given object.
|
static long |
shallowSizeOf(Object[] arr)
Returns the shallow size in bytes of the Object[] object.
|
static long |
shallowSizeOfInstance(Class<?> clazz)
Returns the shallow instance size in bytes an instance of the given class would occupy.
|
static long |
sizeOf(boolean[] arr)
Returns the size in bytes of the boolean[] object.
|
static long |
sizeOf(byte[] arr)
Returns the size in bytes of the byte[] object.
|
static long |
sizeOf(char[] arr)
Returns the size in bytes of the char[] object.
|
static long |
sizeOf(double[] arr)
Returns the size in bytes of the double[] object.
|
static long |
sizeOf(float[] arr)
Returns the size in bytes of the float[] object.
|
static long |
sizeOf(int[] arr)
Returns the size in bytes of the int[] object.
|
static long |
sizeOf(Long value)
Return the size of the provided
Long object, returning 0 if it is
cached by the JVM and its shallow size otherwise. |
static long |
sizeOf(long[] arr)
Returns the size in bytes of the long[] object.
|
static long |
sizeOf(short[] arr)
Returns the size in bytes of the short[] object.
|
public static final String JVM_INFO_STRING
public static final long ONE_KB
public static final long ONE_MB
public static final long ONE_GB
public static final int NUM_BYTES_BOOLEAN
public static final int NUM_BYTES_BYTE
public static final int NUM_BYTES_CHAR
public static final int NUM_BYTES_SHORT
public static final int NUM_BYTES_INT
public static final int NUM_BYTES_FLOAT
public static final int NUM_BYTES_LONG
public static final int NUM_BYTES_DOUBLE
public static final int NUM_BYTES_OBJECT_REF
public static final int NUM_BYTES_OBJECT_HEADER
public static final int NUM_BYTES_ARRAY_HEADER
public static final int NUM_BYTES_OBJECT_ALIGNMENT
public static boolean isSupportedJVM()
RamUsageEstimator
.
If this method returns false
you are maybe using a 3rd party Java VM
that is not supporting Oracle/Sun private APIs. The memory estimates can be
imprecise then (no way of detecting compressed references, alignments, etc.).
Lucene still tries to use sensible defaults.public static long alignObjectSize(long size)
NUM_BYTES_OBJECT_ALIGNMENT
.public static long sizeOf(Long value)
Long
object, returning 0 if it is
cached by the JVM and its shallow size otherwise.public static long sizeOf(byte[] arr)
public static long sizeOf(boolean[] arr)
public static long sizeOf(char[] arr)
public static long sizeOf(short[] arr)
public static long sizeOf(int[] arr)
public static long sizeOf(float[] arr)
public static long sizeOf(long[] arr)
public static long sizeOf(double[] arr)
public static long shallowSizeOf(Object[] arr)
public static long shallowSizeOf(Object obj)
public static long shallowSizeOfInstance(Class<?> clazz)
IllegalArgumentException
- if clazz
is an array class.shallowSizeOf(Object)
public static EnumSet<RamUsageEstimator.JvmFeature> getUnsupportedFeatures()
public static EnumSet<RamUsageEstimator.JvmFeature> getSupportedFeatures()
public static String humanReadableUnits(long bytes)
size
in human-readable units (GB, MB, KB or bytes).public static String humanReadableUnits(long bytes, DecimalFormat df)
size
in human-readable units (GB, MB, KB or bytes).Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.