The counter is actually stored in the DfsPackKey so it can be manipulated by the cache. Change-Id: I10cee76c92d65c68d1aa1a9dd0c4fd7173c4cedetags/v1.2.0.201112221803-r
DfsBlockCache oc = cache; | DfsBlockCache oc = cache; | ||||
cache = nc; | cache = nc; | ||||
if (oc != null && oc.readAheadService != null) | |||||
oc.readAheadService.shutdown(); | |||||
if (oc != null) { | |||||
if (oc.readAheadService != null) | |||||
oc.readAheadService.shutdown(); | |||||
for (DfsPackFile pack : oc.getPackFiles()) | |||||
pack.key.cachedSize.set(0); | |||||
} | |||||
} | } | ||||
/** @return the currently active DfsBlockCache. */ | /** @return the currently active DfsBlockCache. */ | ||||
e2 = table.get(slot); | e2 = table.get(slot); | ||||
} | } | ||||
key.cachedSize.addAndGet(v.size()); | |||||
Ref<DfsBlock> ref = new Ref<DfsBlock>(key, position, v.size(), v); | Ref<DfsBlock> ref = new Ref<DfsBlock>(key, position, v.size(), v); | ||||
ref.hot = true; | ref.hot = true; | ||||
for (;;) { | for (;;) { | ||||
dead.next = null; | dead.next = null; | ||||
dead.value = null; | dead.value = null; | ||||
live -= dead.size; | live -= dead.size; | ||||
dead.pack.cachedSize.addAndGet(-dead.size); | |||||
statEvict++; | statEvict++; | ||||
} while (maxBytes < live); | } while (maxBytes < live); | ||||
clockHand = prev; | clockHand = prev; | ||||
} | } | ||||
} | } | ||||
key.cachedSize.addAndGet(size); | |||||
ref = new Ref<T>(key, pos, size, v); | ref = new Ref<T>(key, pos, size, v); | ||||
ref.hot = true; | ref.hot = true; | ||||
for (;;) { | for (;;) { |
return packDesc; | return packDesc; | ||||
} | } | ||||
/** @return bytes cached in memory for this pack, excluding the index. */ | |||||
public long getCachedSize() { | |||||
return key.cachedSize.get(); | |||||
} | |||||
private String getPackName() { | private String getPackName() { | ||||
return packDesc.getPackName(); | return packDesc.getPackName(); | ||||
} | } |
package org.eclipse.jgit.storage.dfs; | package org.eclipse.jgit.storage.dfs; | ||||
import java.util.concurrent.atomic.AtomicLong; | |||||
final class DfsPackKey { | final class DfsPackKey { | ||||
final int hash; | final int hash; | ||||
final AtomicLong cachedSize; | |||||
DfsPackKey() { | DfsPackKey() { | ||||
// Multiply by 31 here so we can more directly combine with another | // Multiply by 31 here so we can more directly combine with another | ||||
// value without doing the multiply there. | // value without doing the multiply there. | ||||
// | // | ||||
hash = System.identityHashCode(this) * 31; | hash = System.identityHashCode(this) * 31; | ||||
cachedSize = new AtomicLong(); | |||||
} | } | ||||
} | } |