From 2ec433e990672fc63e8bf251db018f3e1afe62a2 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Thu, 26 Feb 2009 18:21:49 +0000 Subject: [PATCH] HBASE-1188 Memory size of Java Objects - Make cacheable objects implement HeapSize git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@748259 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../org/apache/hadoop/hbase/io/HeapSize.java | 36 +++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 36870458345..543248629a6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -63,6 +63,8 @@ Release 0.20.0 - Unreleased options show up (Erik Holstad via Stack) HBASE-1189 Changing the map type used internally for HbaseMapWritable (Erik Holstad via Stack) + HBASE-1188 Memory size of Java Objects - Make cacheable objects implement + HeapSize (Erik Holstad via Stack) Release 0.19.0 - 01/21/2009 INCOMPATIBLE CHANGES diff --git a/src/java/org/apache/hadoop/hbase/io/HeapSize.java b/src/java/org/apache/hadoop/hbase/io/HeapSize.java index 3beea9df6a2..cfabf406d58 100644 --- a/src/java/org/apache/hadoop/hbase/io/HeapSize.java +++ b/src/java/org/apache/hadoop/hbase/io/HeapSize.java @@ -25,9 +25,41 @@ package org.apache.hadoop.hbase.io; * probably do not account for 32 vs 64 bit nor for different VM implemenations. */ public interface HeapSize { + + /** Reference size is 8 bytes on 64-bit, 4 bytes on 32-bit */ + static final int REFERENCE = 8; + + /** Object overhead is minimum 2 * reference size (8 bytes on 64-bit) */ + static final int OBJECT = 2 * REFERENCE; + + /** + * The following types are always allocated in blocks of 8 bytes (on 64bit) + * For example, if you have two ints in a class, it will use 8 bytes. + * If you have three ints in a class, it will use 16 bytes. + */ + static final int SHORT = 4; + static final int INT = 4; + static final int FLOAT = 4; + static final int BOOLEAN = 4; + static final int CHAR = 4; + static final int BYTE = 1; + + /** These types are always 8 bytes */ + static final int DOUBLE = 8; + static final int LONG = 8; + + /** Array overhead */ + static final int BYTE_ARRAY = REFERENCE; + static final int ARRAY = 3 * REFERENCE; + static final int MULTI_ARRAY = (4 * REFERENCE) + ARRAY; + + static final int BLOCK_SIZE_TAX = 8; + + + /** * @return Approximate 'exclusive deep size' of implementing object. Includes * count of payload and hosting object sizings. - */ + */ public long heapSize(); -} \ No newline at end of file +}