public final class MemoryMeter extends Object
This class supports multithreading and can be reused safely.
| Modifier and Type | Class and Description |
|---|---|
static class |
MemoryMeter.Builder
Builder for
MemoryMeter instances |
static class |
MemoryMeter.ByteBufferMode
The different way of measuring deeply a ByteBuffer.
|
static class |
MemoryMeter.Guess
The different strategies that can be used by a
MemoryMeter instance to measure the shallow size of an object. |
| Modifier and Type | Field and Description |
|---|---|
static List<MemoryMeter.Guess> |
BEST
The default guesses in accuracy order.
|
| Constructor and Description |
|---|
MemoryMeter(MemoryMeterStrategy strategy,
FieldAndClassFilter classFilter,
FieldFilter fieldFilter,
MemoryMeterListener.Factory listenerFactory)
Create a new
MemoryMeter instance from the different component it needs to measure object graph. |
| Modifier and Type | Method and Description |
|---|---|
static void |
agentmain(String options,
Instrumentation inst) |
static MemoryMeter.Builder |
builder() |
static MemoryLayoutSpecification |
getMemoryLayoutSpecification()
Provides information about the memory layout used by the JVM.
|
static boolean |
hasInstrumentation() |
static boolean |
hasUnsafe() |
long |
measure(Object object)
Measures the shallow memory usage of the object.
|
long |
measureArray(boolean[] array)
Measures the shallow memory usage of the specified boolean array.
|
long |
measureArray(byte[] array)
Measures the shallow memory usage of the specified byte array.
|
long |
measureArray(char[] array)
Measures the shallow memory usage of the specified char array.
|
long |
measureArray(double[] array)
Measures the shallow memory usage of the specified double array.
|
long |
measureArray(float[] array)
Measures the shallow memory usage of the specified float array.
|
long |
measureArray(int[] array)
Measures the shallow memory usage of the specified int array.
|
long |
measureArray(long[] array)
Measures the shallow memory usage of the specified long array.
|
long |
measureArray(Object[] array)
Measures the shallow memory usage of the specified Object array.
|
long |
measureArray(short[] array)
Measures the shallow memory usage of the specified short array.
|
long |
measureDeep(Object object)
Measures the memory usage of the object including referenced objects.
|
long |
measureDeep(Object object,
MemoryMeter.ByteBufferMode bbMode)
Measures the memory usage of the object including referenced objects.
|
long |
measureStringDeep(String s)
Measures the deep memory usage of the specified
String |
static void |
premain(String options,
Instrumentation inst) |
static boolean |
useStringOptimization() |
public static final List<MemoryMeter.Guess> BEST
public MemoryMeter(MemoryMeterStrategy strategy, FieldAndClassFilter classFilter, FieldFilter fieldFilter, MemoryMeterListener.Factory listenerFactory)
MemoryMeter instance from the different component it needs to measure object graph.
Unless there is a specific need to override some of the MemoryMeter logic people should only create
MemoryMeter instances through MemoryMeter.builder(). This constructor provides a way to modify part of the
logic being used by allowing to use specific implementations for the strategy or filters.
strategy - the MemoryMeterStrategy to use for measuring object shallow size.classFilter - the filter used to filter out classes from the measured object graphfieldFilter - the filter used to filter out fields from the measured object graphlistenerFactory - the factory used to create the listener listening to the object graph traversalpublic static void premain(String options, Instrumentation inst)
public static void agentmain(String options, Instrumentation inst)
public static boolean hasInstrumentation()
public static boolean hasUnsafe()
public static boolean useStringOptimization()
public static MemoryMeter.Builder builder()
public static MemoryLayoutSpecification getMemoryLayoutSpecification()
public long measure(Object object)
If the object is null the value returned will be zero.
object - the object to measurepublic long measureArray(Object[] array)
If the object is null the value returned will be zero.
array - the object array to measurepublic long measureArray(byte[] array)
If the object is null the value returned will be zero.
array - the byte array to measurepublic long measureArray(boolean[] array)
If the object is null the value returned will be zero.
array - the boolean array to measurepublic long measureArray(short[] array)
If the object is null the value returned will be zero.
array - the short array to measurepublic long measureArray(char[] array)
If the object is null the value returned will be zero.
array - the char array to measurepublic long measureArray(int[] array)
If the object is null the value returned will be zero.
array - the int array to measurepublic long measureArray(float[] array)
If the object is null the value returned will be zero.
array - the float array to measurepublic long measureArray(double[] array)
If the object is null the value returned will be zero.
array - the double array to measurepublic long measureArray(long[] array)
If the object is null the value returned will be zero.
array - the long array to measurepublic long measureStringDeep(String s)
Strings - the String to measurepublic long measureDeep(Object object)
If the object is null the value returned will be zero.
Calling this method is equivalent to calling measureDeep(object, ByteBufferMode) with a NORMAL ByteBufferMode.
object - the object to measurepublic long measureDeep(Object object, MemoryMeter.ByteBufferMode bbMode)
If the object is null the value returned will be zero.
object - the object to measurebbMode - the mode that should be used to measure ByteBuffers.Copyright © 2023. All rights reserved.