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
Nested ClassesModifier and TypeClassDescriptionprivate static classMemoryLayout abstracts details about the JVM object layout.private static classUnsafeLayout uses Unsafe to guesstimate the object-layout related parameters like object header sizes and oop sizes See HBASE-15950. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intArray overheadstatic final intOverhead for ArrayList(0)static final intOverhead for AtomicBooleanstatic final intOverhead for AtomicIntegerstatic final intOverhead for AtomicLongstatic final intOverhead for AtomicReferencestatic final intOverhead for ByteBufferstatic final intOverhead for CellArrayMapstatic final intOverhead for Cell Array Entrystatic final intOverhead for CellChunkMapstatic final intOverhead for Cell Chunk Map Entrystatic final intOverhead for CellFlatMapstatic final intOverhead for CellSkipListSetstatic final intOverhead for ConcurrentHashMapstatic final intOverhead for ConcurrentHashMap.Entrystatic final intOverhead for ConcurrentHashMap.Segmentstatic final intOverhead for ConcurrentSkipListMapstatic final intOverhead for ConcurrentSkipListMap Entrystatic final intOverhead for CopyOnWriteArrayListstatic final intOverhead for CopyOnWriteArraySetstatic final intOverhead for an Integerstatic final intOverhead for LinkedList(0)static final intOverhead for a single entry in LinkedListprivate static final org.slf4j.Loggerstatic final intOverhead for entry in mapprivate static final ClassSize.MemoryLayoutstatic final intOverhead for NonSyncTimeRangeTrackerstatic final intObject overhead is minimum 2 * reference size (8 bytes on 64-bit)static final intOverhead for ReentrantReadWriteLockstatic final intReference size is 8 bytes on 64-bit, 4 bytes on 32-bitstatic final intstatic final intString overheadstatic final intOverhead for SyncTimeRangeTrackerstatic final intOverhead for timerangestatic final intOverhead for TreeMapprivate static final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intalign(int num) Aligns a number to 8.static longalign(long num) Aligns a number to 8.static longestimateBase(Class cl, boolean debug) Estimate the static space taken up by the fields of a class.private static longestimateBaseFromCoefficients(int[] coeff, boolean debug) Estimate the static space taken up by a class instance given the coefficients returned by getSizeCoefficients.private static ClassSize.MemoryLayoutprivate 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 booleanDetermines if we are running in a 32-bit JVM.static longsizeOf(byte[] b) Calculate the memory consumption (in byte) of a byte array, including the array header and the whole backing byte array.static longsizeOfByteArray(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
-