public class ObjectSizeCalculator extends Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
ObjectSizeCalculator.ArrayElementsVisitor |
private class |
ObjectSizeCalculator.ClassSizeInfo |
private static class |
ObjectSizeCalculator.CurrentLayout |
static interface |
ObjectSizeCalculator.MemoryLayoutSpecification
Describes constant memory overheads for various constructs in a JVM implementation.
|
| Modifier and Type | Field and Description |
|---|---|
private Set<Object> |
alreadyVisited |
private int |
arrayHeaderSize |
private com.google.common.cache.LoadingCache<Class<?>,ObjectSizeCalculator.ClassSizeInfo> |
classSizeInfos |
private int |
objectHeaderSize |
private int |
objectPadding |
private Deque<Object> |
pending |
private int |
referenceSize |
private long |
size |
private int |
superclassFieldPadding |
| Constructor and Description |
|---|
ObjectSizeCalculator(ObjectSizeCalculator.MemoryLayoutSpecification memoryLayoutSpecification)
Creates an object size calculator that can calculate object sizes for a given
memoryLayoutSpecification. |
| Modifier and Type | Method and Description |
|---|---|
long |
calculateObjectSize(Object obj)
Given an object, returns the total allocated size, in bytes, of the object
and all other objects reachable from it.
|
(package private) void |
enqueue(Object obj) |
(package private) static ObjectSizeCalculator.MemoryLayoutSpecification |
getEffectiveMemoryLayoutSpecification() |
static long |
getObjectSize(Object obj)
Given an object, returns the total allocated size, in bytes, of the object
and all other objects reachable from it.
|
private static long |
getPrimitiveFieldSize(Class<?> type) |
private void |
increaseByArraySize(int length,
long elementSize) |
(package private) void |
increaseSize(long objectSize) |
(package private) static long |
roundTo(long x,
int multiple) |
private void |
visit(Object obj) |
private void |
visitArray(Object array) |
private final int arrayHeaderSize
private final int objectHeaderSize
private final int objectPadding
private final int referenceSize
private final int superclassFieldPadding
private final com.google.common.cache.LoadingCache<Class<?>,ObjectSizeCalculator.ClassSizeInfo> classSizeInfos
private long size
public ObjectSizeCalculator(ObjectSizeCalculator.MemoryLayoutSpecification memoryLayoutSpecification)
memoryLayoutSpecification.memoryLayoutSpecification - a description of the JVM memory layout.public static long getObjectSize(Object obj) throws UnsupportedOperationException
UnsupportedOperationException;obj - the object; can be null. Passing in a Class object doesn't do
anything special, it measures the size of all objects
reachable through it (which will include its class loader, and by
extension, all other Class objects loaded by
the same loader, and all the parent class loaders). It doesn't provide the
size of the static fields in the JVM class that the Class object
represents.UnsupportedOperationException - if the current vm memory layout cannot be detected.public long calculateObjectSize(Object obj)
obj - the object; can be null. Passing in a Class object doesn't do
anything special, it measures the size of all objects
reachable through it (which will include its class loader, and by
extension, all other Class objects loaded by
the same loader, and all the parent class loaders). It doesn't provide the
size of the static fields in the JVM class that the Class object
represents.private void visit(Object obj)
private void visitArray(Object array)
private void increaseByArraySize(int length,
long elementSize)
void enqueue(Object obj)
void increaseSize(long objectSize)
static long roundTo(long x,
int multiple)
private static long getPrimitiveFieldSize(Class<?> type)
static ObjectSizeCalculator.MemoryLayoutSpecification getEffectiveMemoryLayoutSpecification()
Copyright © 2021 JBoss by Red Hat. All rights reserved.