private void doUsed(final Node node) { Node moreUsed = node.mMoreUsed; if (moreUsed != null) { Node lessUsed = node.mLessUsed; moreUsed.mLessUsed = lessUsed; if (lessUsed == null) { mLeastRecentlyUsed = moreUsed; } else { lessUsed.mMoreUsed = moreUsed; } node.mMoreUsed = null; (node.mLessUsed = mMostRecentlyUsed).mMoreUsed = node; mMostRecentlyUsed = node; } releaseExclusive(); }
private void doUsed(final Node node) { Node moreUsed = node.mMoreUsed; if (moreUsed != null) { Node lessUsed = node.mLessUsed; moreUsed.mLessUsed = lessUsed; if (lessUsed == null) { mLeastRecentlyUsed = moreUsed; } else { lessUsed.mMoreUsed = moreUsed; } node.mMoreUsed = null; (node.mLessUsed = mMostRecentlyUsed).mMoreUsed = node; mMostRecentlyUsed = node; } releaseExclusive(); }
/** * Allow a Node which was allocated as unevictable to be evictable, starting off as the * most recently used. */ void makeEvictable(final Node node) { acquireExclusive(); try { // Only insert if not closed and if not already in the list. The node latch doesn't // need to be held, and so a concurrent call to the unused method might insert the // node sooner. if (mMaxSize != 0 && node.mMoreUsed == null) { Node most = mMostRecentlyUsed; if (node != most) { node.mLessUsed = most; if (most == null) { mLeastRecentlyUsed = node; } else { most.mMoreUsed = node; } mMostRecentlyUsed = node; } } } finally { releaseExclusive(); } }
/** * Allow a Node which was allocated as unevictable to be evictable, starting off as the * most recently used. */ void makeEvictable(final Node node) { acquireExclusive(); try { // Only insert if not closed and if not already in the list. The node latch doesn't // need to be held, and so a concurrent call to the unused method might insert the // node sooner. if (mMaxSize != 0 && node.mMoreUsed == null) { Node most = mMostRecentlyUsed; if (node != most) { node.mLessUsed = most; if (most == null) { mLeastRecentlyUsed = node; } else { most.mMoreUsed = node; } mMostRecentlyUsed = node; } } } finally { releaseExclusive(); } }
/** * Allow a Node which was allocated as evictable to be unevictable. */ void makeUnevictable(final Node node) { acquireExclusive(); try { if (mMaxSize != 0) { doMakeUnevictable(node); } } finally { releaseExclusive(); } }
/** * Allow a Node which was allocated as evictable to be unevictable. */ void makeUnevictable(final Node node) { acquireExclusive(); try { if (mMaxSize != 0) { doMakeUnevictable(node); } } finally { releaseExclusive(); } }
/** * @param usedRate must be power of 2 minus 1, and it determines the likelihood that * calling the used method actually moves the node in the usage list. The higher the used * rate value, the less likely that calling the used method does anything. The used rate * value should be proportional to the total cache size. For larger caches, exact MRU * ordering is less critical, and the cost of updating the ordering is also higher. Hence, * a larger used rate value is recommended. */ NodeUsageList(LocalDatabase db, long usedRate, int maxSize) { if (maxSize <= 0) { throw new IllegalArgumentException(); } mDatabase = db; mPageSize = db.pageSize(); mUsedRate = usedRate; acquireExclusive(); mMaxSize = maxSize; releaseExclusive(); }
/** * @param usedRate must be power of 2 minus 1, and it determines the likelihood that * calling the used method actually moves the node in the usage list. The higher the used * rate value, the less likely that calling the used method does anything. The used rate * value should be proportional to the total cache size. For larger caches, exact MRU * ordering is less critical, and the cost of updating the ordering is also higher. Hence, * a larger used rate value is recommended. */ NodeUsageList(LocalDatabase db, long usedRate, int maxSize) { if (maxSize <= 0) { throw new IllegalArgumentException(); } mDatabase = db; mPageSize = db.pageSize(); mUsedRate = usedRate; acquireExclusive(); mMaxSize = maxSize; releaseExclusive(); }
/** * Allow a Node which was allocated as unevictable to be evictable, as the least recently * used. */ void makeEvictableNow(final Node node) { acquireExclusive(); try { // See comment in the makeEvictable method. if (mMaxSize != 0 && node.mLessUsed == null) { doMakeEvictableNow(node); } } finally { releaseExclusive(); } }
/** * Allow a Node which was allocated as unevictable to be evictable, as the least recently * used. */ void makeEvictableNow(final Node node) { acquireExclusive(); try { // See comment in the makeEvictable method. if (mMaxSize != 0 && node.mLessUsed == null) { doMakeEvictableNow(node); } } finally { releaseExclusive(); } }
/** * Must be called when object is no longer referenced. */ void delete() { acquireExclusive(); try { // Prevent new allocations. mMaxSize = 0; Node node = mLeastRecentlyUsed; mLeastRecentlyUsed = null; mMostRecentlyUsed = null; while (node != null) { Node next = node.mMoreUsed; node.mLessUsed = null; node.mMoreUsed = null; // Free memory and make node appear to be evicted. node.delete(mDatabase); node = next; } } finally { releaseExclusive(); } } }
/** * Must be called when object is no longer referenced. */ void delete() { acquireExclusive(); try { // Prevent new allocations. mMaxSize = 0; Node node = mLeastRecentlyUsed; mLeastRecentlyUsed = null; mMostRecentlyUsed = null; while (node != null) { Node next = node.mMoreUsed; node.mLessUsed = null; node.mMoreUsed = null; // Free memory and make node appear to be evicted. node.delete(mDatabase); node = next; } } finally { releaseExclusive(); } } }
/** * Initialize and preallocate a minimum amount of nodes. * * @param arena optional */ void initialize(Object arena, int min) throws DatabaseException, OutOfMemoryError { while (--min >= 0) { acquireExclusive(); if (mSize >= mMaxSize) { releaseExclusive(); break; } doAllocLatchedNode(arena, 0).releaseExclusive(); } }
/** * Initialize and preallocate a minimum amount of nodes. * * @param arena optional */ void initialize(Object arena, int min) throws DatabaseException, OutOfMemoryError { while (--min >= 0) { acquireExclusive(); if (mSize >= mMaxSize) { releaseExclusive(); break; } doAllocLatchedNode(arena, 0).releaseExclusive(); } }
releaseExclusive(); doMakeUnevictable(node); } else { releaseExclusive(); usageList.makeUnevictable(node); releaseExclusive(); releaseExclusive(); throw e; releaseExclusive();
releaseExclusive(); doMakeUnevictable(node); } else { releaseExclusive(); usageList.makeUnevictable(node); releaseExclusive(); releaseExclusive(); throw e; releaseExclusive();