public ChunkCache(long maxSize) { this.fPageTable= new Chunk[computeLength(maxSize)]; }
public synchronized void add(Chunk chunk) { if (chunk.fCacheIndex >= 0) { chunk.fCacheHitFlag= true; return; } if (this.fTableIsFull) { evictChunk(); chunk.fCacheIndex= this.fPointer; this.fPageTable[this.fPointer]= chunk; } else { chunk.fCacheIndex= this.fPointer; this.fPageTable[this.fPointer]= chunk; this.fPointer++; if (this.fPointer == this.fPageTable.length) { this.fPointer= 0; this.fTableIsFull= true; } } }
public Nd(File dbPath, NdNodeTypeRegistry<NdNode> nodeTypes, int minVersion, int maxVersion, int currentVersion) throws IndexException { this(dbPath, ChunkCache.getSharedInstance(), nodeTypes, minVersion, maxVersion, currentVersion); }
@Override public void preferenceChange(PreferenceChangeEvent event) { if (JavaIndex.ENABLE_NEW_JAVA_INDEX.equals(event.getKey())) { if (JavaIndex.isEnabled()) { getInstance().rescanAll(); } else { ChunkCache.getSharedInstance().clear(); } } } };
this.fMostRecentlyFetchedChunk = lastChunk; lastChunk.makeDirty(); this.fCache.add(lastChunk); long result = (long) firstChunkIndex * CHUNK_SIZE;
private void removeChunksFromCache() { int scanIndex = NUM_HEADER_CHUNKS; while (scanIndex < this.fChunksUsed) { synchronized (this.fCache) { int countMax = Math.min(MAX_ITERATIONS_PER_LOCK, this.fChunksUsed - scanIndex); for (int count = 0; count < countMax; count++) { Chunk chunk = this.fChunks[scanIndex++]; if (chunk != null) { this.fCache.remove(chunk); if (DEBUG_PAGE_CACHE) { System.out.println("CHUNK " + chunk.fSequenceNumber //$NON-NLS-1$ + ": removing from vector in removeChunksFromCache - instance " //$NON-NLS-1$ + System.identityHashCode(chunk)); } this.fChunks[chunk.fSequenceNumber] = null; } } } } }
int totalCacheSize = (int) (this.db.getCache().getMaxSize() / Database.CHUNK_SIZE); if (dirtyPages > totalCacheSize * MAX_DIRTY_CACHE_RATIO) { flush = true;
@Override public void preferenceChange(PreferenceChangeEvent event) { if (JavaIndex.ENABLE_NEW_JAVA_INDEX.equals(event.getKey())) { if (JavaIndex.isEnabled()) { getInstance().rescanAll(); } else { ChunkCache.getSharedInstance().clear(); } } } };
this.fMostRecentlyFetchedChunk = lastChunk; lastChunk.makeDirty(); this.fCache.add(lastChunk); long result = (long) firstChunkIndex * CHUNK_SIZE;
private void removeChunksFromCache() { int scanIndex = NUM_HEADER_CHUNKS; while (scanIndex < this.fChunksUsed) { synchronized (this.fCache) { int countMax = Math.min(MAX_ITERATIONS_PER_LOCK, this.fChunksUsed - scanIndex); for (int count = 0; count < countMax; count++) { Chunk chunk = this.fChunks[scanIndex++]; if (chunk != null) { this.fCache.remove(chunk); if (DEBUG_PAGE_CACHE) { System.out.println("CHUNK " + chunk.fSequenceNumber //$NON-NLS-1$ + ": removing from vector in removeChunksFromCache - instance " //$NON-NLS-1$ + System.identityHashCode(chunk)); } this.fChunks[chunk.fSequenceNumber] = null; } } } } }
int totalCacheSize = (int) (this.db.getCache().getMaxSize() / Database.CHUNK_SIZE); if (dirtyPages > totalCacheSize * MAX_DIRTY_CACHE_RATIO) { flush = true;
public Nd(File dbPath, NdNodeTypeRegistry<NdNode> nodeTypes, int minVersion, int maxVersion, int currentVersion) throws IndexException { this(dbPath, ChunkCache.getSharedInstance(), nodeTypes, minVersion, maxVersion, currentVersion); }
public ChunkCache(long maxSize) { this.fPageTable= new Chunk[computeLength(maxSize)]; }
this.fCache.add(chunk); this.fMostRecentlyFetchedChunk = chunk;
public synchronized void add(Chunk chunk) { if (chunk.fCacheIndex >= 0) { chunk.fCacheHitFlag= true; return; } if (this.fTableIsFull) { evictChunk(); chunk.fCacheIndex= this.fPointer; this.fPageTable[this.fPointer]= chunk; } else { chunk.fCacheIndex= this.fPointer; this.fPageTable[this.fPointer]= chunk; this.fPointer++; if (this.fPointer == this.fPageTable.length) { this.fPointer= 0; this.fTableIsFull= true; } } }
public static Nd getGlobalNd() { Nd localNd; synchronized (ndMutex) { localNd = globalNd; } if (localNd != null) { return localNd; } localNd = createNd(getDBFile(), ChunkCache.getSharedInstance()); synchronized (ndMutex) { if (globalNd == null) { globalNd = localNd; } return globalNd; } }
/** * Clears the page table and changes it to hold chunks with * maximum total memory of <code>maxSize</code>. * @param maxSize the total size of the chunks in bytes. */ public synchronized void setMaxSize(long maxSize) { final int newLength= computeLength(maxSize); final int oldLength= this.fTableIsFull ? this.fPageTable.length : this.fPointer; if (newLength > oldLength) { Chunk[] newTable= new Chunk[newLength]; System.arraycopy(this.fPageTable, 0, newTable, 0, oldLength); this.fTableIsFull= false; this.fPointer= oldLength; this.fPageTable= newTable; } else { for (int i = newLength; i < oldLength; i++) { Chunk chunk = this.fPageTable[i]; chunk.fCacheIndex = -1; chunk.fDatabase.checkIfChunkReleased(chunk); } Chunk[] newTable= new Chunk[newLength]; System.arraycopy(this.fPageTable, 0, newTable, 0, newLength); this.fTableIsFull= true; this.fPointer= 0; this.fPageTable= newTable; } }
this.fCache.add(chunk); this.fMostRecentlyFetchedChunk = chunk;
public static Nd getGlobalNd() { Nd localNd; synchronized (ndMutex) { localNd = globalNd; } if (localNd != null) { return localNd; } localNd = createNd(getDBFile(), ChunkCache.getSharedInstance()); synchronized (ndMutex) { if (globalNd == null) { globalNd = localNd; } return globalNd; } }
/** * Clears the page table and changes it to hold chunks with * maximum total memory of <code>maxSize</code>. * @param maxSize the total size of the chunks in bytes. */ public synchronized void setMaxSize(long maxSize) { final int newLength= computeLength(maxSize); final int oldLength= this.fTableIsFull ? this.fPageTable.length : this.fPointer; if (newLength > oldLength) { Chunk[] newTable= new Chunk[newLength]; System.arraycopy(this.fPageTable, 0, newTable, 0, oldLength); this.fTableIsFull= false; this.fPointer= oldLength; this.fPageTable= newTable; } else { for (int i = newLength; i < oldLength; i++) { Chunk chunk = this.fPageTable[i]; chunk.fCacheIndex = -1; chunk.fDatabase.checkIfChunkReleased(chunk); } Chunk[] newTable= new Chunk[newLength]; System.arraycopy(this.fPageTable, 0, newTable, 0, newLength); this.fTableIsFull= true; this.fPointer= 0; this.fPageTable= newTable; } }