sizeOf(Object), shallowSizeOf(Object), shallowSizeOfInstance(Class)
| Modifier and Type | Class and Description |
|---|---|
| private static class | RamUsageEstimator.ClassCache
Cached information about a given class. |
| private static class | |
| private static class | |
| public static enum | RamUsageEstimator.JvmFeature
JVM diagnostic features. |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | JVM_INFO_STRING
JVM info string for debugging and reports. |
| public static final int | NUM_BYTES_ARRAY_HEADER
Number of bytes to represent an array header (no content, but with alignments). |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | NUM_BYTES_OBJECT_ALIGNMENT
A constant specifying the object alignment boundary inside the JVM. |
| public static final int | NUM_BYTES_OBJECT_HEADER
Number of bytes to represent an object header (no fields, no alignments). |
| public static final int | NUM_BYTES_OBJECT_REF
Number of bytes this jvm uses to represent an object reference. |
| public static final int | |
| private static final Method | objectFieldOffsetMethod
A handle to |
| public static final long | ONE_GB
One gigabyte bytes. |
| public static final long | ONE_KB
One kilobyte bytes. |
| public static final long | ONE_MB
One megabyte bytes. |
| private static final Map | primitiveSizes
Sizes of primitive classes. |
| private static final EnumSet | supportedFeatures
All the supported "internal" JVM features detected at clinit. |
| private static final Object | theUnsafe
A handle to |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static long | adjustForField(long sizeSoFar, final Field f)
This method returns the maximum representation size of an object. |
| public static long | alignObjectSize(long size)
Aligns an object size to be the next multiple of |
| private static RamUsageEstimator. | createCacheEntry(final Class<?> clazz)
Create a cached information about shallow size and reference fields for a given class. |
| public static EnumSet | |
| public static EnumSet | |
| public static String | |
| public static String | humanReadableUnits(long bytes, DecimalFormat df)
Returns |
| public static String | |
| public static boolean | |
| private static long | |
| public static long | |
| public static long | |
| public static long | shallowSizeOfAll(Iterable<Object> objects)
Same as |
| private static long | |
| public static long | shallowSizeOfInstance(Class<?> clazz)
Returns the shallow instance size in bytes an instance of the given class would occupy. |
| public static long | |
| public static long | |
| public static long | |
| public static long | |
| public static long | |
| public static long | |
| public static long | |
| public static long | |
| public static long | |
| public static long | |
| public static long |
| JVM_INFO_STRING | back to summary |
|---|---|
| public static final String JVM_INFO_STRING JVM info string for debugging and reports. | |
| NUM_BYTES_ARRAY_HEADER | back to summary |
|---|---|
| public static final int NUM_BYTES_ARRAY_HEADER Number of bytes to represent an array header (no content, but with alignments). | |
| NUM_BYTES_BOOLEAN | back to summary |
|---|---|
| public static final int NUM_BYTES_BOOLEAN | |
| NUM_BYTES_BYTE | back to summary |
|---|---|
| public static final int NUM_BYTES_BYTE | |
| NUM_BYTES_CHAR | back to summary |
|---|---|
| public static final int NUM_BYTES_CHAR | |
| NUM_BYTES_DOUBLE | back to summary |
|---|---|
| public static final int NUM_BYTES_DOUBLE | |
| NUM_BYTES_FLOAT | back to summary |
|---|---|
| public static final int NUM_BYTES_FLOAT | |
| NUM_BYTES_INT | back to summary |
|---|---|
| public static final int NUM_BYTES_INT | |
| NUM_BYTES_LONG | back to summary |
|---|---|
| public static final int NUM_BYTES_LONG | |
| NUM_BYTES_OBJECT_ALIGNMENT | back to summary |
|---|---|
| public static final int NUM_BYTES_OBJECT_ALIGNMENT A constant specifying the object alignment boundary inside the JVM. Objects will always take a full multiple of this constant, possibly wasting some space. | |
| NUM_BYTES_OBJECT_HEADER | back to summary |
|---|---|
| public static final int NUM_BYTES_OBJECT_HEADER Number of bytes to represent an object header (no fields, no alignments). | |
| NUM_BYTES_OBJECT_REF | back to summary |
|---|---|
| public static final int NUM_BYTES_OBJECT_REF Number of bytes this jvm uses to represent an object reference. | |
| NUM_BYTES_SHORT | back to summary |
|---|---|
| public static final int NUM_BYTES_SHORT | |
| objectFieldOffsetMethod | back to summary |
|---|---|
| private static final Method objectFieldOffsetMethod A handle to | |
| ONE_GB | back to summary |
|---|---|
| public static final long ONE_GB One gigabyte bytes. | |
| ONE_KB | back to summary |
|---|---|
| public static final long ONE_KB One kilobyte bytes. | |
| ONE_MB | back to summary |
|---|---|
| public static final long ONE_MB One megabyte bytes. | |
| primitiveSizes | back to summary |
|---|---|
| private static final Map<Class<?>, Integer> primitiveSizes Sizes of primitive classes. | |
| supportedFeatures | back to summary |
|---|---|
| private static final EnumSet<RamUsageEstimator. All the supported "internal" JVM features detected at clinit. | |
| theUnsafe | back to summary |
|---|---|
| private static final Object theUnsafe A handle to | |
| RamUsageEstimator | back to summary |
|---|---|
| private RamUsageEstimator() No instantiation. | |
| adjustForField | back to summary |
|---|---|
| private static long adjustForField(long sizeSoFar, final Field f) This method returns the maximum representation size of an object. The returned offset will be the maximum of whatever was measured so far and
| |
| alignObjectSize | back to summary |
|---|---|
| public static long alignObjectSize(long size) Aligns an object size to be the next multiple of | |
| createCacheEntry | back to summary |
|---|---|
| private static RamUsageEstimator. Create a cached information about shallow size and reference fields for a given class. | |
| getSupportedFeatures | back to summary |
|---|---|
| public static EnumSet Return the set of supported JVM features that improve the estimation. | |
| getUnsupportedFeatures | back to summary |
|---|---|
| public static EnumSet Return the set of unsupported JVM features that improve the estimation. | |
| humanReadableUnits | back to summary |
|---|---|
| public static String humanReadableUnits(long bytes) Returns | |
| humanReadableUnits | back to summary |
|---|---|
| public static String humanReadableUnits(long bytes, DecimalFormat df) Returns | |
| humanSizeOf | back to summary |
|---|---|
| public static String humanSizeOf(Object object) Return a human-readable size of a given object.
| |
| isSupportedJVM | back to summary |
|---|---|
| public static boolean isSupportedJVM() Returns true, if the current JVM is fully supported by | |
| measureSizeOf | back to summary |
|---|---|
| private static long measureSizeOf(ArrayList<Object> stack) Non-recursive version of object descend. This consumes more memory than recursive in-depth traversal but prevents stack overflows on long chains of objects or complex graphs (a max. recursion depth on my machine was ~5000 objects linked in a chain so not too much). | |
| shallowSizeOf | back to summary |
|---|---|
| public static long shallowSizeOf(Object obj) 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. | |
| shallowSizeOfAll | back to summary |
|---|---|
| public static long shallowSizeOfAll(Object... objects) Same as | |
| shallowSizeOfAll | back to summary |
|---|---|
| public static long shallowSizeOfAll(Iterable<Object> objects) Same as | |
| shallowSizeOfArray | back to summary |
|---|---|
| private static long shallowSizeOfArray(Object array) Return shallow size of any | |
| shallowSizeOfInstance | back to summary |
|---|---|
| public static long shallowSizeOfInstance(Class<?> clazz) 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).
| |
| sizeOf | back to summary |
|---|---|
| public static long sizeOf(byte[] arr) Returns the size in bytes of the byte[] object. | |
| sizeOf | back to summary |
|---|---|
| public static long sizeOf(boolean[] arr) Returns the size in bytes of the boolean[] object. | |
| sizeOf | back to summary |
|---|---|
| public static long sizeOf(char[] arr) Returns the size in bytes of the char[] object. | |
| sizeOf | back to summary |
|---|---|
| public static long sizeOf(short[] arr) Returns the size in bytes of the short[] object. | |
| sizeOf | back to summary |
|---|---|
| public static long sizeOf(int[] arr) Returns the size in bytes of the int[] object. | |
| sizeOf | back to summary |
|---|---|
| public static long sizeOf(float[] arr) Returns the size in bytes of the float[] object. | |
| sizeOf | back to summary |
|---|---|
| public static long sizeOf(long[] arr) Returns the size in bytes of the long[] object. | |
| sizeOf | back to summary |
|---|---|
| public static long sizeOf(double[] arr) Returns the size in bytes of the double[] object. | |
| sizeOf | back to summary |
|---|---|
| public static long sizeOf(Object obj) Estimates the RAM usage by the given object. It will walk the object tree and sum up all referenced objects. Resource Usage: This method internally uses a set of every object seen during traversals so it does allocate memory (it isn't side-effect free). After the method exits, this memory should be GCed. | |
| sizeOfAll | back to summary |
|---|---|
| public static long sizeOfAll(Object... objects) Same as | |
| sizeOfAll | back to summary |
|---|---|
| public static long sizeOfAll(Iterable<Object> objects) Same as | |
| Modifier and Type | Field and Description |
|---|---|
| public final long | |
| public final Field[] |
| Access | Constructor and Description |
|---|---|
| public |
| alignedShallowInstanceSize | back to summary |
|---|---|
| public final long alignedShallowInstanceSize | |
| referenceFields | back to summary |
|---|---|
| public final Field[] referenceFields | |
| ClassCache | back to summary |
|---|---|
| public ClassCache(long alignedShallowInstanceSize, Field[] referenceFields) | |
| Modifier and Type | Field and Description |
|---|---|
| public byte |
| Access | Constructor and Description |
|---|---|
| private |
| base | back to summary |
|---|---|
| public byte base | |
| DummyOneFieldObject | back to summary |
|---|---|
| private DummyOneFieldObject() | |
| Access | Constructor and Description |
|---|---|
| private |
| DummyTwoLongObject | back to summary |
|---|---|
| private DummyTwoLongObject() | |
| Modifier and Type | Field and Description |
|---|---|
| public static final RamUsageEstimator. | |
| public final String | |
| public static final RamUsageEstimator. | |
| public static final RamUsageEstimator. | |
| public static final RamUsageEstimator. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public String | toString()
Overrides java. |
| public static RamUsageEstimator. | |
| public static RamUsageEstimator. |
| ARRAY_HEADER_SIZE | back to summary |
|---|---|
| public static final RamUsageEstimator. | |
| description | back to summary |
|---|---|
| public final String description | |
| FIELD_OFFSETS | back to summary |
|---|---|
| public static final RamUsageEstimator. | |
| OBJECT_ALIGNMENT | back to summary |
|---|---|
| public static final RamUsageEstimator. | |
| OBJECT_REFERENCE_SIZE | back to summary |
|---|---|
| public static final RamUsageEstimator. | |
| JvmFeature | back to summary |
|---|---|
| private JvmFeature(String description) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists. | |
| valueOf | back to summary |
|---|---|
| public static RamUsageEstimator. | |
| values | back to summary |
|---|---|
| public static RamUsageEstimator. | |