Class Database
java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.nd.db.Database
Database encapsulates access to a flat binary format file with a memory-manager-like API for
obtaining and releasing areas of storage (memory).
Some terminology is used throughout this class: A block is a variable-size piece of contiguous memory returned by malloc. A chunk is a fixed-size piece of contiguous memory that is the atomic unit for paging, caching, reads, and writes. A free block is contiguous variable-length piece of memory that is created by free and is potentially usable by malloc. Most chunks contain multiple blocks and free blocks, but it is possible for a single block to use multiple chunks. Such blocks are referred to as "large blocks". A free block is always smaller than a chunk.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic int
static int
static int
static int
static int
static int
static int
static boolean
True iff large chunk self-diagnostics should be enabled.static boolean
static int
static int
org.aspectj.org.eclipse.jdt.internal.core.nd.db.Chunk
static int
static int
static int
static int
static int
static int
static long
static long
static int
static int
static double
static int
static int
static short
static short
static short
Id for the first node type.static short
static short
static short
Misc pool -- may be used for any purpose that doesn't fit the IDs below.static short
static short
static short
static int
static int
static int
static int
static int
-
Constructor Summary
ConstructorDescriptionDatabase(File location, ChunkCache cache, int version, boolean openReadOnly)
Construct a new Database object, creating a backing file if necessary. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
clear(int version)
Empty the contents of the Database, make it ready to start again.void
clearBytes(long offset, int byteCount)
void
clearRange(long startAddress, long bytesToClear)
Clears all the bytes in the given range by setting them to zero.void
close()
Closes the database.boolean
flush()
static String
formatByteString(long valueInBytes)
void
free(long address, short poolId)
Free an allocated block.int
get3ByteUnsignedInt(long offset)
double
double
byte
getByte(long offset)
void
getBytes(long offset, byte[] data)
void
getBytes(long offset, byte[] data, int dataPos, int len)
long
Returns the number of bytes allocated bymalloc(long, short)
since thisDatabase
instance was instantiated.long
Returns the number of bytes freed byfree(long, short)
since thisDatabase
instance was instantiated.long
static long
getBytesThatFitInChunks(int numChunks)
Returns the number of bytes that can fit in the payload of the given number of chunks.long
getCache()
long
long
char
getChar(long offset)
org.aspectj.org.eclipse.jdt.internal.core.nd.db.Chunk
getChunk(long offset)
Return the Chunk that contains the given offset.Returns the cache used for this database.int
static int
getChunksNeededForBytes(long datasize)
Returns the number of chunks needed to fit the given number of bytes of payload.long
long
int
double
getDouble(long offset)
float
getFloat(long offset)
int
getInt(long offset)
This method is public for testing purposes only.getLog()
long
getLong(long offset)
static long
getRecPtr(byte[] buffer, int idx)
A Record Pointer is a pointer as returned by Database.malloc().long
getRecPtr(long offset)
short
getShort(long offset)
long
getString(long offset)
int
void
long
malloc(long datasize, short poolId)
Allocate a block out of the database.void
memcpy(long dest, long source, int numBytes)
Copies numBytes from source to destinationnewString(char[] chars)
void
put3ByteUnsignedInt(long offset, int value)
void
putByte(long offset, byte value)
void
putBytes(long offset, byte[] data, int len)
void
putBytes(long offset, byte[] data, int dataPos, int len)
void
putChar(long offset, char value)
void
putDouble(long offset, double value)
void
putFloat(long offset, float value)
void
putInt(long offset, int value)
void
putLong(long offset, long value)
static void
putRecPtr(long value, byte[] buffer, int idx)
A Record Pointer is a pointer as returned by Database.malloc().void
putRecPtr(long offset, long value)
void
putShort(long offset, short value)
void
For debugging purposes, only.void
void
Asserts that database is used by one thread exclusively.void
setLocked(boolean val)
void
setVersion(int version)
void
transferTo(FileChannel target)
void
-
Field Details
-
CHAR_SIZE
public static final int CHAR_SIZE- See Also:
- Constant Field Values
-
BYTE_SIZE
public static final int BYTE_SIZE- See Also:
- Constant Field Values
-
SHORT_SIZE
public static final int SHORT_SIZE- See Also:
- Constant Field Values
-
INT_SIZE
public static final int INT_SIZE- See Also:
- Constant Field Values
-
LONG_SIZE
public static final int LONG_SIZE- See Also:
- Constant Field Values
-
CHUNK_SIZE
public static final int CHUNK_SIZE- See Also:
- Constant Field Values
-
OFFSET_IN_CHUNK_MASK
public static final int OFFSET_IN_CHUNK_MASK- See Also:
- Constant Field Values
-
BLOCK_HEADER_SIZE
public static final int BLOCK_HEADER_SIZE- See Also:
- Constant Field Values
-
BLOCK_SIZE_DELTA_BITS
public static final int BLOCK_SIZE_DELTA_BITS- See Also:
- Constant Field Values
-
BLOCK_SIZE_DELTA
public static final int BLOCK_SIZE_DELTA- See Also:
- Constant Field Values
-
MIN_BLOCK_DELTAS
public static final int MIN_BLOCK_DELTAS- See Also:
- Constant Field Values
-
MAX_BLOCK_DELTAS
public static final int MAX_BLOCK_DELTAS -
MAX_SINGLE_BLOCK_MALLOC_SIZE
public static final int MAX_SINGLE_BLOCK_MALLOC_SIZE -
PTR_SIZE
public static final int PTR_SIZE- See Also:
- Constant Field Values
-
STRING_SIZE
public static final int STRING_SIZE- See Also:
- Constant Field Values
-
FLOAT_SIZE
public static final int FLOAT_SIZE- See Also:
- Constant Field Values
-
DOUBLE_SIZE
public static final int DOUBLE_SIZE- See Also:
- Constant Field Values
-
MAX_DB_SIZE
public static final long MAX_DB_SIZE- See Also:
- Constant Field Values
-
MAX_MALLOC_SIZE
public static final long MAX_MALLOC_SIZE -
VERSION_OFFSET
public static final int VERSION_OFFSET- See Also:
- Constant Field Values
-
MALLOC_TABLE_OFFSET
public static final int MALLOC_TABLE_OFFSET- See Also:
- Constant Field Values
-
FREE_BLOCK_OFFSET
public static final int FREE_BLOCK_OFFSET- See Also:
- Constant Field Values
-
WRITE_NUMBER_OFFSET
public static final int WRITE_NUMBER_OFFSET- See Also:
- Constant Field Values
-
MALLOC_STATS_OFFSET
public static final int MALLOC_STATS_OFFSET- See Also:
- Constant Field Values
-
DATA_AREA_OFFSET
public static final int DATA_AREA_OFFSET -
NUM_HEADER_CHUNKS
public static final int NUM_HEADER_CHUNKS- See Also:
- Constant Field Values
-
POOL_MISC
public static final short POOL_MISCMisc pool -- may be used for any purpose that doesn't fit the IDs below.- See Also:
- Constant Field Values
-
POOL_BTREE
public static final short POOL_BTREE- See Also:
- Constant Field Values
-
POOL_DB_PROPERTIES
public static final short POOL_DB_PROPERTIES- See Also:
- Constant Field Values
-
POOL_STRING_LONG
public static final short POOL_STRING_LONG- See Also:
- Constant Field Values
-
POOL_STRING_SHORT
public static final short POOL_STRING_SHORT- See Also:
- Constant Field Values
-
POOL_LINKED_LIST
public static final short POOL_LINKED_LIST- See Also:
- Constant Field Values
-
POOL_STRING_SET
public static final short POOL_STRING_SET- See Also:
- Constant Field Values
-
POOL_GROWABLE_ARRAY
public static final short POOL_GROWABLE_ARRAY- See Also:
- Constant Field Values
-
POOL_FIRST_NODE_TYPE
public static final short POOL_FIRST_NODE_TYPEId for the first node type. All node types will record their stats in a pool whose ID is POOL_FIRST_NODE_TYPE + node_id- See Also:
- Constant Field Values
-
DEBUG_FREE_SPACE
public static boolean DEBUG_FREE_SPACETrue iff large chunk self-diagnostics should be enabled. -
DEBUG_PAGE_CACHE
public static boolean DEBUG_PAGE_CACHE -
fMostRecentlyFetchedChunk
public org.aspectj.org.eclipse.jdt.internal.core.nd.db.Chunk fMostRecentlyFetchedChunk -
MIN_BYTES_PER_MILLISECOND
public static final double MIN_BYTES_PER_MILLISECOND- See Also:
- Constant Field Values
-
-
Constructor Details
-
Database
public Database(File location, ChunkCache cache, int version, boolean openReadOnly) throws IndexExceptionConstruct a new Database object, creating a backing file if necessary.- Parameters:
location
- the local file path for the databasecache
- the cache to be used optimizationversion
- the version number to store in the database (only applicable for new databases)openReadOnly
- whether this Database object will ever need writing to- Throws:
IndexException
-
-
Method Details
-
getLog
-
transferTo
- Throws:
IOException
-
getVersion
public int getVersion() -
setVersion
- Throws:
IndexException
-
clear
Empty the contents of the Database, make it ready to start again. Interrupting the thread withThread.interrupt()
won't interrupt the write. Returns true iff the thread was interrupted withThread.interrupt()
.- Throws:
IndexException
-
getChunk
public org.aspectj.org.eclipse.jdt.internal.core.nd.db.Chunk getChunk(long offset) throws IndexExceptionReturn the Chunk that contains the given offset.- Throws:
IndexException
-
assertLocked
public void assertLocked() -
memcpy
public void memcpy(long dest, long source, int numBytes)Copies numBytes from source to destination -
malloc
Allocate a block out of the database.- Throws:
IndexException
-
clearRange
public void clearRange(long startAddress, long bytesToClear)Clears all the bytes in the given range by setting them to zero.- Parameters:
startAddress
- first address to clearbytesToClear
- number of addresses to clear
-
validateFreeSpace
public void validateFreeSpace() -
free
Free an allocated block.- Parameters:
address
- memory address to be freedpoolId
- the same ID that was previously passed into malloc when allocating this memory address- Throws:
IndexException
-
putByte
- Throws:
IndexException
-
getByte
- Throws:
IndexException
-
putInt
- Throws:
IndexException
-
getInt
- Throws:
IndexException
-
putRecPtr
- Throws:
IndexException
-
getRecPtr
- Throws:
IndexException
-
put3ByteUnsignedInt
- Throws:
IndexException
-
get3ByteUnsignedInt
- Throws:
IndexException
-
putShort
- Throws:
IndexException
-
getShort
- Throws:
IndexException
-
putLong
- Throws:
IndexException
-
putDouble
- Throws:
IndexException
-
putFloat
- Throws:
IndexException
-
getLong
- Throws:
IndexException
-
getDouble
- Throws:
IndexException
-
getFloat
- Throws:
IndexException
-
putChar
- Throws:
IndexException
-
getChar
- Throws:
IndexException
-
clearBytes
- Throws:
IndexException
-
putBytes
- Throws:
IndexException
-
putBytes
- Throws:
IndexException
-
getBytes
- Throws:
IndexException
-
getBytes
- Throws:
IndexException
-
newString
- Throws:
IndexException
-
newString
- Throws:
IndexException
-
getString
- Throws:
IndexException
-
getDatabaseSize
public long getDatabaseSize() -
getBytesFreed
public long getBytesFreed()Returns the number of bytes freed byfree(long, short)
since thisDatabase
instance was instantiated. Intended for use in unit tests. -
getBytesAllocated
public long getBytesAllocated()Returns the number of bytes allocated bymalloc(long, short)
since thisDatabase
instance was instantiated. Intended for use in unit tests. -
reportFreeBlocks
For debugging purposes, only.- Throws:
IndexException
-
close
Closes the database.The behavior of any further calls to the Database is undefined
- Throws:
IndexException
-
getLocation
This method is public for testing purposes only. -
getChunkCache
Returns the cache used for this database.- Since:
- 4.0
-
setExclusiveLock
public void setExclusiveLock()Asserts that database is used by one thread exclusively. This is necessary when doing write operations. -
setLocked
public void setLocked(boolean val) -
giveUpExclusiveLock
public void giveUpExclusiveLock() -
flush
- Throws:
IndexException
-
resetCacheCounters
public void resetCacheCounters() -
getBytesWritten
public long getBytesWritten() -
getAverageReadBytesPerMs
public double getAverageReadBytesPerMs() -
getAverageWriteBytesPerMs
public double getAverageWriteBytesPerMs() -
getBytesRead
public long getBytesRead() -
getCacheHits
public long getCacheHits() -
getCacheMisses
public long getCacheMisses() -
getCumulativeFlushTimeMs
public long getCumulativeFlushTimeMs() -
getSizeBytes
- Throws:
IOException
-
getChunkCount
public int getChunkCount() -
putRecPtr
public static void putRecPtr(long value, byte[] buffer, int idx)A Record Pointer is a pointer as returned by Database.malloc(). This is a pointer to a block + BLOCK_HEADER_SIZE. -
getRecPtr
public static long getRecPtr(byte[] buffer, int idx)A Record Pointer is a pointer as returned by Database.malloc(). This is a pointer to a block + BLOCK_HEADER_SIZE. -
getMemoryStats
-
getBytesThatFitInChunks
public static long getBytesThatFitInChunks(int numChunks)Returns the number of bytes that can fit in the payload of the given number of chunks. -
getChunksNeededForBytes
public static int getChunksNeededForBytes(long datasize)Returns the number of chunks needed to fit the given number of bytes of payload. -
getCache
-
getDirtyChunkCount
public int getDirtyChunkCount() -
formatByteString
-
getChunkStats
-
describeProblem
-