|
Oracle® Coherence Java API Reference Release 3.7.1.0 E22843-01 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
com.tangosol.util.Base
com.tangosol.net.cache.SimpleMemoryCalculator
public class SimpleMemoryCalculator
A UnitCalculator implementation that weighs a cache entry based upon the amount of physical memory (in bytes) required to store the entry.
This implementation can only determine an accurate entry size if both the entry key and value object types are one of the following classes (or an array thereof or of the primitive forms thereof):
Binary
If either the key or value object is not one of these types, an exception will be thrown during the unit calculation.
Field Summary | |
---|---|
static java.util.Map |
MAP_FIXED_SIZES An immutable map of fixed-sized classes to instance size (in bytes). |
protected static int |
SIZE_BASIC_OBJECT The unalligned size of the simplest object. |
static int |
SIZE_BIGDECIMAL The size (in bytes) of a BigDecimal object. |
static int |
SIZE_BIGINTEGER The size (in bytes) of a BigInteger object. |
static int |
SIZE_BINARY The minimum size (in bytes) of a Binary object. |
static int |
SIZE_BOOLEAN The size (in bytes) of a Boolean object. |
static int |
SIZE_BYTE The size (in bytes) of a Byte object. |
static int |
SIZE_CHARACTER The size (in bytes) of a Character object. |
static int |
SIZE_DATE The size (in bytes) of a Date , Date or Time object. |
static int |
SIZE_DOUBLE The size (in bytes) of a Double object. |
static int |
SIZE_ENTRY The minimum size (in bytes) of an LocalCache.Entry object. |
static int |
SIZE_FLOAT The size (in bytes) of a Float object. |
static int |
SIZE_INTEGER The size (in bytes) of a Integer object. |
static int |
SIZE_LONG The size (in bytes) of a Long object. |
static int |
SIZE_OBJECT The size (in bytes) of an Object . |
static int |
SIZE_OBJECT_REF The size (in bytes) of an object reference. |
static int |
SIZE_SHORT The size (in bytes) of a Short object. |
static int |
SIZE_STRING The minimum size (in bytes) of a String object. |
static int |
SIZE_TIMESTAMP The size (in bytes) of a Timestamp object. |
Constructor Summary | |
---|---|
SimpleMemoryCalculator() |
Method Summary | |
---|---|
protected static int |
calculateShallowSize(java.lang.Class clz) Calculate the approximate number of bytes required to store an instance of the given class and its non-static fields in memory. |
int |
calculateUnits(java.lang.Object oKey, java.lang.Object oValue) Calculate a cache cost for the specified cache entry key and value. |
java.lang.String |
getName() Obtain the name of the unit calculator. |
static void |
main(java.lang.String[] asArg) Unit test. |
protected static int |
padMemorySize(int cb) Round the given number of bytes to the next closest integer that is divisible by 16. |
protected int |
sizeOf(java.lang.Class clz) Determine the minimum number of bytes required to store an instance of the given fixed-sized class in memory. |
int |
sizeOf(java.lang.Object o) Estimate the number of bytes of memory consumed by the given object. |
Field Detail |
---|
public static final int SIZE_OBJECT_REF
On a 32 bit JVM, an object reference is 4 bytes. On a 64 bit JVM, an object reference is 8 bytes.
public static final int SIZE_OBJECT
Object
.public static final int SIZE_BOOLEAN
Boolean
object.public static final int SIZE_BYTE
Byte
object.public static final int SIZE_SHORT
Short
object.public static final int SIZE_CHARACTER
Character
object.public static final int SIZE_INTEGER
Integer
object.public static final int SIZE_FLOAT
Float
object.public static final int SIZE_LONG
Long
object.public static final int SIZE_DOUBLE
Double
object.public static final int SIZE_DATE
Date
, Date
or Time
object.public static final int SIZE_TIMESTAMP
Timestamp
object.public static final int SIZE_BIGINTEGER
BigInteger
object.public static final int SIZE_BIGDECIMAL
BigDecimal
object.public static final int SIZE_STRING
String
object.public static final int SIZE_BINARY
Binary
object.public static final int SIZE_ENTRY
LocalCache.Entry
object.public static final java.util.Map MAP_FIXED_SIZES
protected static final int SIZE_BASIC_OBJECT
Constructor Detail |
---|
public SimpleMemoryCalculator()
Method Detail |
---|
public int calculateUnits(java.lang.Object oKey, java.lang.Object oValue)
calculateUnits
in interface ConfigurableCacheMap.UnitCalculator
oKey
- the cache key to evaluate for unit costoValue
- the cache value to evaluate for unit costpublic java.lang.String getName()
getName
in interface ConfigurableCacheMap.UnitCalculator
public int sizeOf(java.lang.Object o)
The calculation is based on the class of the given object, with reference types assumed to be aligned on a 16-byte boundary:
Class Size boolean 1 byte 1 short 2 char 2 int 4 long 8 float 4 double 8 Object SIZE_OBJECT
Boolean SIZE_OBJECT
+ 1Byte SIZE_OBJECT
+ 1Short SIZE_OBJECT
+ 2Character SIZE_OBJECT
+ 2Integer SIZE_OBJECT
+ 4Long SIZE_OBJECT
+ 8Float SIZE_OBJECT
+ 4Double SIZE_OBJECT
+ 8BigInteger SIZE_OBJECT
+ 48BigDecimal SIZE_OBJECT
+ 4 +SIZE_OBJECT_REF
+SIZE_BIGINTEGER
Date SIZE_OBJECT
+SIZE_OBJECT_REF
+ 8Time SIZE_OBJECT
+SIZE_OBJECT_REF
+ 8Timestamp SIZE_OBJECT
+SIZE_OBJECT_REF
+ 12Binary SIZE_BINARY
+ arrayString SIZE_STRING
+ arrayarray SIZE_OBJECT
+ 4 + [element size]*length()
o
- the object to measure the size ofjava.lang.IllegalArgumentException
- if the type of the object is not one of the classes listed aboveprotected int sizeOf(java.lang.Class clz)
The calculation is based on the following table, with reference types assumed to be aligned on an 16-byte boundary:
Class Size boolean 1 byte 1 short 2 char 2 int 4 long 8 float 4 double 8 Object SIZE_OBJECT
Boolean SIZE_OBJECT
+ 1Byte SIZE_OBJECT
+ 1Short SIZE_OBJECT
+ 2Character SIZE_OBJECT
+ 2Integer SIZE_OBJECT
+ 4Long SIZE_OBJECT
+ 8Float SIZE_OBJECT
+ 4Double SIZE_OBJECT
+ 8BigInteger SIZE_OBJECT
+ 48BigDecimal SIZE_OBJECT
+ 4 +SIZE_OBJECT_REF
+SIZE_BIGINTEGER
Date SIZE_OBJECT
+SIZE_OBJECT_REF
+ 8Time SIZE_OBJECT
+SIZE_OBJECT_REF
+ 8Timestamp SIZE_OBJECT
+SIZE_OBJECT_REF
+ 12
clz
- the target classjava.lang.IllegalArgumentException
- if the type of the object is not one of the classes listed aboveprotected static int padMemorySize(int cb)
This method is used to pad the result of a memory calculation assuming that fields are ordered to minimize padding and that allocation granularity is 16 bytes.
cb
- the number of bytes to roundprotected static int calculateShallowSize(java.lang.Class clz)
The size calculation is shallow, in that fields that are references to variable-sized classes are not included in the estimate.
clz
- the target classpublic static void main(java.lang.String[] asArg)
Usage:
java com.tangosol.net.cache.SimpleMemoryCalculator [class name]
asArg
- command line arguments
|
Oracle® Coherence Java API Reference Release 3.7.1.0 E22843-01 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |