Class ClassSize

java.lang.Object
org.apache.hadoop.hbase.util.ClassSize

@Private public class ClassSize extends Object
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
  • Field Details

    • LOG

      private static final org.slf4j.Logger LOG
    • ARRAY

      public static final int ARRAY
      Array overhead
    • ARRAYLIST

      public static final int ARRAYLIST
      Overhead for ArrayList(0)
    • LINKEDLIST

      public static final int LINKEDLIST
      Overhead for LinkedList(0)
    • LINKEDLIST_ENTRY

      public static final int LINKEDLIST_ENTRY
      Overhead for a single entry in LinkedList
    • BYTE_BUFFER

      public static final int BYTE_BUFFER
      Overhead for ByteBuffer
    • INTEGER

      public static final int INTEGER
      Overhead for an Integer
    • MAP_ENTRY

      public static final int MAP_ENTRY
      Overhead for entry in map
    • OBJECT

      public static final int OBJECT
      Object overhead is minimum 2 * reference size (8 bytes on 64-bit)
    • REFERENCE

      public static final int REFERENCE
      Reference size is 8 bytes on 64-bit, 4 bytes on 32-bit
    • STRING

      public static final int STRING
      String overhead
    • TREEMAP

      public static final int TREEMAP
      Overhead for TreeMap
    • CONCURRENT_HASHMAP

      public static final int CONCURRENT_HASHMAP
      Overhead for ConcurrentHashMap
    • CONCURRENT_HASHMAP_ENTRY

      public static final int CONCURRENT_HASHMAP_ENTRY
      Overhead for ConcurrentHashMap.Entry
    • CONCURRENT_HASHMAP_SEGMENT

      public static final int CONCURRENT_HASHMAP_SEGMENT
      Overhead for ConcurrentHashMap.Segment
    • CONCURRENT_SKIPLISTMAP

      public static final int CONCURRENT_SKIPLISTMAP
      Overhead for ConcurrentSkipListMap
    • CONCURRENT_SKIPLISTMAP_ENTRY

      public static final int CONCURRENT_SKIPLISTMAP_ENTRY
      Overhead for ConcurrentSkipListMap Entry
    • CELL_FLAT_MAP

      public static final int CELL_FLAT_MAP
      Overhead for CellFlatMap
    • CELL_CHUNK_MAP

      public static final int CELL_CHUNK_MAP
      Overhead for CellChunkMap
    • CELL_CHUNK_MAP_ENTRY

      public static final int CELL_CHUNK_MAP_ENTRY
      Overhead for Cell Chunk Map Entry
    • CELL_ARRAY_MAP

      public static final int CELL_ARRAY_MAP
      Overhead for CellArrayMap
    • CELL_ARRAY_MAP_ENTRY

      public static final int CELL_ARRAY_MAP_ENTRY
      Overhead for Cell Array Entry
    • REENTRANT_LOCK

      public static final int REENTRANT_LOCK
      Overhead for ReentrantReadWriteLock
    • ATOMIC_LONG

      public static final int ATOMIC_LONG
      Overhead for AtomicLong
    • ATOMIC_INTEGER

      public static final int ATOMIC_INTEGER
      Overhead for AtomicInteger
    • ATOMIC_BOOLEAN

      public static final int ATOMIC_BOOLEAN
      Overhead for AtomicBoolean
    • ATOMIC_REFERENCE

      public static final int ATOMIC_REFERENCE
      Overhead for AtomicReference
    • COPYONWRITE_ARRAYSET

      public static final int COPYONWRITE_ARRAYSET
      Overhead for CopyOnWriteArraySet
    • COPYONWRITE_ARRAYLIST

      public static final int COPYONWRITE_ARRAYLIST
      Overhead for CopyOnWriteArrayList
    • TIMERANGE

      public static final int TIMERANGE
      Overhead for timerange
    • SYNC_TIMERANGE_TRACKER

      public static final int SYNC_TIMERANGE_TRACKER
      Overhead for SyncTimeRangeTracker
    • NON_SYNC_TIMERANGE_TRACKER

      public static final int NON_SYNC_TIMERANGE_TRACKER
      Overhead for NonSyncTimeRangeTracker
    • CELL_SET

      public static final int CELL_SET
      Overhead for CellSkipListSet
    • STORE_SERVICES

      public static final int STORE_SERVICES
    • memoryLayout

      private static final ClassSize.MemoryLayout memoryLayout
    • USE_UNSAFE_LAYOUT

      private static final boolean USE_UNSAFE_LAYOUT
  • Constructor Details

  • Method Details

    • getMemoryLayout

    • useUnsafeLayout

      public static boolean useUnsafeLayout()
    • getSizeCoefficients

      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. 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 estimated
      debug - 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

      private static long estimateBaseFromCoefficients(int[] coeff, boolean debug)
      Estimate the static space taken up by a class instance given the coefficients returned by getSizeCoefficients.
      Parameters:
      coeff - the coefficients
      debug - debug flag
      Returns:
      the size estimate, in bytes
    • estimateBase

      public static long estimateBase(Class cl, boolean debug)
      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 - class
      debug - debug flag
      Returns:
      the size estimate in bytes.
    • align

      public static int align(int num)
      Aligns a number to 8.
      Parameters:
      num - number to align to 8
      Returns:
      smallest number >= input that is a multiple of 8
    • align

      public static long align(long num)
      Aligns a number to 8.
      Parameters:
      num - number to align to 8
      Returns:
      smallest number >= input that is a multiple of 8
    • is32BitJVM

      public static boolean is32BitJVM()
      Determines if we are running in a 32-bit JVM. Some unit tests need to know this too.
    • sizeOf

      public 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. If the whole byte array is occupied (not shared with other objects), please use this function. If not, please use sizeOfByteArray(int) instead.
      Parameters:
      b - the byte array
      Returns:
      the memory consumption (in byte) of the whole byte array
    • sizeOfByteArray

      public 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. This function is used when the byte array backs multiple objects. For example, in KeyValue, multiple KeyValue objects share a same backing byte array (KeyValue.bytes). Also see KeyValue.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