Package org.apache.hadoop.hbase.util
Class ClassSize
java.lang.Object
org.apache.hadoop.hbase.util.ClassSize
Class for determining the "size" of a class, an attempt to calculate the actual bytes that an
object of this class will occupy in memory The core of this class is taken from the Derby project
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static class
MemoryLayout abstracts details about the JVM object layout.private static class
UnsafeLayout uses Unsafe to guesstimate the object-layout related parameters like object header sizes and oop sizes See HBASE-15950. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Array overheadstatic final int
Overhead for ArrayList(0)static final int
Overhead for AtomicBooleanstatic final int
Overhead for AtomicIntegerstatic final int
Overhead for AtomicLongstatic final int
Overhead for AtomicReferencestatic final int
Overhead for ByteBufferstatic final int
Overhead for CellArrayMapstatic final int
Overhead for Cell Array Entrystatic final int
Overhead for CellChunkMapstatic final int
Overhead for Cell Chunk Map Entrystatic final int
Overhead for CellFlatMapstatic final int
Overhead for CellSkipListSetstatic final int
Overhead for ConcurrentHashMapstatic final int
Overhead for ConcurrentHashMap.Entrystatic final int
Overhead for ConcurrentHashMap.Segmentstatic final int
Overhead for ConcurrentSkipListMapstatic final int
Overhead for ConcurrentSkipListMap Entrystatic final int
Overhead for CopyOnWriteArrayListstatic final int
Overhead for CopyOnWriteArraySetstatic final int
Overhead for an Integerstatic final int
Overhead for LinkedList(0)static final int
Overhead for a single entry in LinkedListprivate static final org.slf4j.Logger
static final int
Overhead for entry in mapprivate static final ClassSize.MemoryLayout
static final int
Overhead for NonSyncTimeRangeTrackerstatic final int
Object overhead is minimum 2 * reference size (8 bytes on 64-bit)static final int
Overhead for ReentrantReadWriteLockstatic final int
Reference size is 8 bytes on 64-bit, 4 bytes on 32-bitstatic final int
static final int
String overheadstatic final int
Overhead for SyncTimeRangeTrackerstatic final int
Overhead for timerangestatic final int
Overhead for TreeMapprivate static final boolean
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
align
(int num) Aligns a number to 8.static long
align
(long num) Aligns a number to 8.static long
estimateBase
(Class cl, boolean debug) Estimate the static space taken up by the fields of a class.private static long
estimateBaseFromCoefficients
(int[] coeff, boolean debug) Estimate the static space taken up by a class instance given the coefficients returned by getSizeCoefficients.private static ClassSize.MemoryLayout
private static int[]
getSizeCoefficients
(Class cl, boolean debug) The estimate of the size of a class instance depends on whether the JVM uses 32 or 64 bit addresses, that is it depends on the size of an object reference.static boolean
Determines if we are running in a 32-bit JVM.static long
sizeOf
(byte[] b) Calculate the memory consumption (in byte) of a byte array, including the array header and the whole backing byte array.static long
sizeOfByteArray
(int len) Calculate the memory consumption (in byte) of a part of a byte array, including the array header and the part of the backing byte array.static boolean
-
Field Details
-
LOG
-
ARRAY
Array overhead -
ARRAYLIST
Overhead for ArrayList(0) -
LINKEDLIST
Overhead for LinkedList(0) -
LINKEDLIST_ENTRY
Overhead for a single entry in LinkedList -
BYTE_BUFFER
Overhead for ByteBuffer -
INTEGER
Overhead for an Integer -
MAP_ENTRY
Overhead for entry in map -
OBJECT
Object overhead is minimum 2 * reference size (8 bytes on 64-bit) -
REFERENCE
Reference size is 8 bytes on 64-bit, 4 bytes on 32-bit -
STRING
String overhead -
TREEMAP
Overhead for TreeMap -
CONCURRENT_HASHMAP
Overhead for ConcurrentHashMap -
CONCURRENT_HASHMAP_ENTRY
Overhead for ConcurrentHashMap.Entry -
CONCURRENT_HASHMAP_SEGMENT
Overhead for ConcurrentHashMap.Segment -
CONCURRENT_SKIPLISTMAP
Overhead for ConcurrentSkipListMap -
CONCURRENT_SKIPLISTMAP_ENTRY
Overhead for ConcurrentSkipListMap Entry -
CELL_FLAT_MAP
Overhead for CellFlatMap -
CELL_CHUNK_MAP
Overhead for CellChunkMap -
CELL_CHUNK_MAP_ENTRY
Overhead for Cell Chunk Map Entry -
CELL_ARRAY_MAP
Overhead for CellArrayMap -
CELL_ARRAY_MAP_ENTRY
Overhead for Cell Array Entry -
REENTRANT_LOCK
Overhead for ReentrantReadWriteLock -
ATOMIC_LONG
Overhead for AtomicLong -
ATOMIC_INTEGER
Overhead for AtomicInteger -
ATOMIC_BOOLEAN
Overhead for AtomicBoolean -
ATOMIC_REFERENCE
Overhead for AtomicReference -
COPYONWRITE_ARRAYSET
Overhead for CopyOnWriteArraySet -
COPYONWRITE_ARRAYLIST
Overhead for CopyOnWriteArrayList -
TIMERANGE
Overhead for timerange -
SYNC_TIMERANGE_TRACKER
Overhead for SyncTimeRangeTracker -
NON_SYNC_TIMERANGE_TRACKER
Overhead for NonSyncTimeRangeTracker -
CELL_SET
Overhead for CellSkipListSet -
STORE_SERVICES
-
memoryLayout
-
USE_UNSAFE_LAYOUT
-
-
Constructor Details
-
ClassSize
public ClassSize()
-
-
Method Details
-
getMemoryLayout
-
useUnsafeLayout
-
getSizeCoefficients
The estimate of the size of a class instance depends on whether the JVM uses 32 or 64 bit addresses, that is it depends on the size of an object reference. It is a linear function of the size of a reference, e.g. 24 + 5*r where r is the size of a reference (usually 4 or 8 bytes). This method returns the coefficients of the linear function, e.g. {24, 5} in the above example.- Parameters:
cl
- A class whose instance size is to be estimateddebug
- debug flag- Returns:
- an array of 3 integers. The first integer is the size of the primitives, the second the number of arrays and the third the number of references.
-
estimateBaseFromCoefficients
Estimate the static space taken up by a class instance given the coefficients returned by getSizeCoefficients.- Parameters:
coeff
- the coefficientsdebug
- debug flag- Returns:
- the size estimate, in bytes
-
estimateBase
Estimate the static space taken up by the fields of a class. This includes the space taken up by by references (the pointer) but not by the referenced object. So the estimated size of an array field does not depend on the size of the array. Similarly the size of an object (reference) field does not depend on the object.- Parameters:
cl
- classdebug
- debug flag- Returns:
- the size estimate in bytes.
-
align
Aligns a number to 8.- Parameters:
num
- number to align to 8- Returns:
- smallest number >= input that is a multiple of 8
-
align
Aligns a number to 8.- Parameters:
num
- number to align to 8- Returns:
- smallest number >= input that is a multiple of 8
-
is32BitJVM
Determines if we are running in a 32-bit JVM. Some unit tests need to know this too. -
sizeOf
Calculate the memory consumption (in byte) of a byte array, including the array header and the whole backing byte array. If the whole byte array is occupied (not shared with other objects), please use this function. If not, please usesizeOfByteArray(int)
instead.- Parameters:
b
- the byte array- Returns:
- the memory consumption (in byte) of the whole byte array
-
sizeOfByteArray
Calculate the memory consumption (in byte) of a part of a byte array, including the array header and the part of the backing byte array. This function is used when the byte array backs multiple objects. For example, inKeyValue
, multiple KeyValue objects share a same backing byte array (KeyValue.bytes
). Also seeKeyValue.heapSize()
.- Parameters:
len
- the length (in byte) used partially in the backing byte array- Returns:
- the memory consumption (in byte) of the part of the byte array
-