com.sleepycat.je.dbi
Class MemoryBudget

java.lang.Object
  extended by com.sleepycat.je.dbi.MemoryBudget
All Implemented Interfaces:
EnvConfigObserver

public class MemoryBudget
extends java.lang.Object
implements EnvConfigObserver

MemoryBudget calculates the available memory for JE and how to apportion it between cache and log buffers. It is meant to centralize all memory calculations. Objects that ask for memory budgets should get settings from this class, rather than using the configuration parameter values directly.


Nested Class Summary
static class MemoryBudget.Totals
          Common base class for shared and private totals.
 
Field Summary
static int ARRAY_OVERHEAD
           
static int ARRAY_SIZE_INCLUDED
           
static int BIN_FIXED_OVERHEAD
           
static int CHECKPOINT_REFERENCE_SIZE
           
static boolean CLEANUP_DONE
           
static int DBFILESUMMARY_OVERHEAD
           
static int DBIN_FIXED_OVERHEAD
           
static boolean DEBUG_ADMIN
           
static boolean DEBUG_LOCK
           
static boolean DEBUG_TREE
           
static boolean DEBUG_TREEADMIN
           
static boolean DEBUG_TXN
           
static int DIN_FIXED_OVERHEAD
           
static int DUPCOUNTLN_OVERHEAD
           
static int FILESUMMARYLN_OVERHEAD
           
static int HASHMAP_ENTRY_OVERHEAD
           
static int HASHMAP_OVERHEAD
           
static int HASHSET_ENTRY_OVERHEAD
           
static int HASHSET_OVERHEAD
           
static int IN_FIXED_OVERHEAD
           
static int KEY_OVERHEAD
           
static int LN_INFO_OVERHEAD
           
static int LN_OVERHEAD
           
static int LOCKIMPL_OVERHEAD
           
static int LOCKINFO_OVERHEAD
           
static int LONG_LIST_PER_ITEM_OVERHEAD
           
static int LONG_OVERHEAD
           
static int MAPLN_OVERHEAD
           
static long MIN_MAX_MEMORY_SIZE
           
static java.lang.String MIN_MAX_MEMORY_SIZE_STRING
           
static int OBJECT_ARRAY_ITEM_OVERHEAD
           
static int OBJECT_OVERHEAD
           
static int PRIMITIVE_LONG_ARRAY_ITEM_OVERHEAD
           
static int TFS_LIST_INITIAL_OVERHEAD
           
static int TFS_LIST_SEGMENT_OVERHEAD
           
static int THINLOCKIMPL_OVERHEAD
           
static int TREEMAP_ENTRY_OVERHEAD
           
static int TREEMAP_OVERHEAD
           
static int TWOHASHMAPS_OVERHEAD
           
static int TXN_OVERHEAD
           
static int UTILIZATION_PROFILE_ENTRY
           
static int WRITE_LOCKINFO_OVERHEAD
           
 
Method Summary
static int byteArraySize(int arrayLen)
          Returns the memory size occupied by a byte array of a given length.
 void envConfigUpdate(DbConfigManager configManager, EnvironmentMutableConfig ignore)
          Respond to config updates.
 long getAdminMemoryUsage()
          Used for unit testing.
 long getBINOverhead()
           
 long getCacheMemoryUsage()
           
 long getDBINOverhead()
           
 long getDINOverhead()
           
 long getINOverhead()
           
 long getLockMemoryUsage()
          Public for unit testing.
 long getLogBufferBudget()
           
 long getMaxMemory()
           
 long getMinTreeMemoryUsage()
          For unit tests.
static long getRuntimeMaxMemory()
          Returns Runtime.maxMemory(), accounting for a MacOS bug.
 MemoryBudget.Totals getTotals()
           
 long getTrackerBudget()
           
 long getTreeAdminMemoryUsage()
           
 long getTreeMemoryUsage()
          Used for unit testing.
static int intArraySize(int arrayLen)
           
 boolean isTreeUsageAboveMinimum()
          Returns whether eviction of INList information is allowed.
static int objectArraySize(int arrayLen)
           
static int shortArraySize(int arrayLen)
           
 java.lang.String toString()
           
 void updateAdminMemoryUsage(long increment)
          Update the environment wide admin memory count, wake up the evictor if necessary.
 void updateLockMemoryUsage(long increment, int lockTableIndex)
           
 void updateTreeAdminMemoryUsage(long increment)
          Update the treeAdmin memory count, wake up the evictor if necessary.
 void updateTreeMemoryUsage(long increment)
          Update the environment wide tree memory count, wake up the evictor if necessary.
 void updateTxnMemoryUsage(long increment)
          Update the environment wide txn memory count, wake up the evictor if necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLEANUP_DONE

public static boolean CLEANUP_DONE

DEBUG_ADMIN

public static boolean DEBUG_ADMIN

DEBUG_LOCK

public static boolean DEBUG_LOCK

DEBUG_TXN

public static boolean DEBUG_TXN

DEBUG_TREEADMIN

public static boolean DEBUG_TREEADMIN

DEBUG_TREE

public static boolean DEBUG_TREE

LONG_OVERHEAD

public static final int LONG_OVERHEAD

ARRAY_OVERHEAD

public static final int ARRAY_OVERHEAD

ARRAY_SIZE_INCLUDED

public static final int ARRAY_SIZE_INCLUDED

OBJECT_OVERHEAD

public static final int OBJECT_OVERHEAD

OBJECT_ARRAY_ITEM_OVERHEAD

public static final int OBJECT_ARRAY_ITEM_OVERHEAD

HASHMAP_OVERHEAD

public static final int HASHMAP_OVERHEAD

HASHMAP_ENTRY_OVERHEAD

public static final int HASHMAP_ENTRY_OVERHEAD

HASHSET_OVERHEAD

public static final int HASHSET_OVERHEAD

HASHSET_ENTRY_OVERHEAD

public static final int HASHSET_ENTRY_OVERHEAD

TWOHASHMAPS_OVERHEAD

public static final int TWOHASHMAPS_OVERHEAD

TREEMAP_OVERHEAD

public static final int TREEMAP_OVERHEAD

TREEMAP_ENTRY_OVERHEAD

public static final int TREEMAP_ENTRY_OVERHEAD

MAPLN_OVERHEAD

public static final int MAPLN_OVERHEAD

LN_OVERHEAD

public static final int LN_OVERHEAD

DUPCOUNTLN_OVERHEAD

public static final int DUPCOUNTLN_OVERHEAD

BIN_FIXED_OVERHEAD

public static final int BIN_FIXED_OVERHEAD

DIN_FIXED_OVERHEAD

public static final int DIN_FIXED_OVERHEAD

DBIN_FIXED_OVERHEAD

public static final int DBIN_FIXED_OVERHEAD

IN_FIXED_OVERHEAD

public static final int IN_FIXED_OVERHEAD

KEY_OVERHEAD

public static final int KEY_OVERHEAD

LOCKIMPL_OVERHEAD

public static final int LOCKIMPL_OVERHEAD

THINLOCKIMPL_OVERHEAD

public static final int THINLOCKIMPL_OVERHEAD

LOCKINFO_OVERHEAD

public static final int LOCKINFO_OVERHEAD

WRITE_LOCKINFO_OVERHEAD

public static final int WRITE_LOCKINFO_OVERHEAD

TXN_OVERHEAD

public static final int TXN_OVERHEAD

CHECKPOINT_REFERENCE_SIZE

public static final int CHECKPOINT_REFERENCE_SIZE

UTILIZATION_PROFILE_ENTRY

public static final int UTILIZATION_PROFILE_ENTRY

DBFILESUMMARY_OVERHEAD

public static final int DBFILESUMMARY_OVERHEAD

TFS_LIST_INITIAL_OVERHEAD

public static final int TFS_LIST_INITIAL_OVERHEAD

TFS_LIST_SEGMENT_OVERHEAD

public static final int TFS_LIST_SEGMENT_OVERHEAD

LN_INFO_OVERHEAD

public static final int LN_INFO_OVERHEAD

FILESUMMARYLN_OVERHEAD

public static final int FILESUMMARYLN_OVERHEAD

LONG_LIST_PER_ITEM_OVERHEAD

public static final int LONG_LIST_PER_ITEM_OVERHEAD

PRIMITIVE_LONG_ARRAY_ITEM_OVERHEAD

public static final int PRIMITIVE_LONG_ARRAY_ITEM_OVERHEAD
See Also:
Constant Field Values

MIN_MAX_MEMORY_SIZE

public static final long MIN_MAX_MEMORY_SIZE
See Also:
Constant Field Values

MIN_MAX_MEMORY_SIZE_STRING

public static final java.lang.String MIN_MAX_MEMORY_SIZE_STRING
Method Detail

envConfigUpdate

public void envConfigUpdate(DbConfigManager configManager,
                            EnvironmentMutableConfig ignore)
                     throws DatabaseException
Respond to config updates.

Specified by:
envConfigUpdate in interface EnvConfigObserver
Throws:
DatabaseException

getRuntimeMaxMemory

public static long getRuntimeMaxMemory()
Returns Runtime.maxMemory(), accounting for a MacOS bug. May return Long.MAX_VALUE if there is no inherent limit. Used by unit tests as well as by this class.


isTreeUsageAboveMinimum

public boolean isTreeUsageAboveMinimum()
Returns whether eviction of INList information is allowed. To prevent extreme cache churn, eviction of Btree information is prohibited unless the tree memory usage is above this minimum value.


getMinTreeMemoryUsage

public long getMinTreeMemoryUsage()
For unit tests.


updateTreeMemoryUsage

public void updateTreeMemoryUsage(long increment)
Update the environment wide tree memory count, wake up the evictor if necessary.

Parameters:
increment - note that increment may be negative.

updateTxnMemoryUsage

public void updateTxnMemoryUsage(long increment)
Update the environment wide txn memory count, wake up the evictor if necessary.

Parameters:
increment - note that increment may be negative.

updateAdminMemoryUsage

public void updateAdminMemoryUsage(long increment)
Update the environment wide admin memory count, wake up the evictor if necessary.

Parameters:
increment - note that increment may be negative.

updateTreeAdminMemoryUsage

public void updateTreeAdminMemoryUsage(long increment)
Update the treeAdmin memory count, wake up the evictor if necessary.

Parameters:
increment - note that increment may be negative.

updateLockMemoryUsage

public void updateLockMemoryUsage(long increment,
                                  int lockTableIndex)

getLockMemoryUsage

public long getLockMemoryUsage()
Public for unit testing.


getCacheMemoryUsage

public long getCacheMemoryUsage()

getMaxMemory

public long getMaxMemory()

getTreeMemoryUsage

public long getTreeMemoryUsage()
Used for unit testing.


getAdminMemoryUsage

public long getAdminMemoryUsage()
Used for unit testing.


getTreeAdminMemoryUsage

public long getTreeAdminMemoryUsage()

getLogBufferBudget

public long getLogBufferBudget()

getTrackerBudget

public long getTrackerBudget()

getINOverhead

public long getINOverhead()

getBINOverhead

public long getBINOverhead()

getDINOverhead

public long getDINOverhead()

getDBINOverhead

public long getDBINOverhead()

byteArraySize

public static int byteArraySize(int arrayLen)
Returns the memory size occupied by a byte array of a given length. All arrays (regardless of element type) have the same overhead for a zero length array. On 32b Java, there are 4 bytes included in that fixed overhead that can be used for the first N elements -- however many fit in 4 bytes. On 64b Java, there is no extra space included. In all cases, space is allocated in 8 byte chunks.


shortArraySize

public static int shortArraySize(int arrayLen)

intArraySize

public static int intArraySize(int arrayLen)

objectArraySize

public static int objectArraySize(int arrayLen)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getTotals

public MemoryBudget.Totals getTotals()