Browse Source

Add a DfsPackFile method to get the number of cached bytes

The counter is actually stored in the DfsPackKey so it can be
manipulated by the cache.

Change-Id: I10cee76c92d65c68d1aa1a9dd0c4fd7173c4cede
stable-1.2
Dave Borowitz 13 years ago committed by Shawn O. Pearce
parent
commit
4fc1af6850
  1. 11
      org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsBlockCache.java
  2. 5
      org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java
  3. 5
      org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackKey.java

11
org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsBlockCache.java

@ -115,8 +115,12 @@ public final class DfsBlockCache {
DfsBlockCache oc = cache;
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. */
@ -343,6 +347,7 @@ public final class DfsBlockCache {
e2 = table.get(slot);
}
key.cachedSize.addAndGet(v.size());
Ref<DfsBlock> ref = new Ref<DfsBlock>(key, position, v.size(), v);
ref.hot = true;
for (;;) {
@ -389,6 +394,7 @@ public final class DfsBlockCache {
dead.next = null;
dead.value = null;
live -= dead.size;
dead.pack.cachedSize.addAndGet(-dead.size);
statEvict++;
} while (maxBytes < live);
clockHand = prev;
@ -438,6 +444,7 @@ public final class DfsBlockCache {
}
}
key.cachedSize.addAndGet(size);
ref = new Ref<T>(key, pos, size, v);
ref.hot = true;
for (;;) {

5
org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackFile.java

@ -171,6 +171,11 @@ public final class DfsPackFile {
return packDesc;
}
/** @return bytes cached in memory for this pack, excluding the index. */
public long getCachedSize() {
return key.cachedSize.get();
}
private String getPackName() {
return packDesc.getPackName();
}

5
org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPackKey.java

@ -43,13 +43,18 @@
package org.eclipse.jgit.storage.dfs;
import java.util.concurrent.atomic.AtomicLong;
final class DfsPackKey {
final int hash;
final AtomicLong cachedSize;
DfsPackKey() {
// Multiply by 31 here so we can more directly combine with another
// value without doing the multiply there.
//
hash = System.identityHashCode(this) * 31;
cachedSize = new AtomicLong();
}
}

Loading…
Cancel
Save