Browse Source

dfs: Take size as long instead of int

Practically we wouldn't have 2GB+ objects in the DfsBlockCache, but by
making it long, we can clean up some long-to-integer conversions.

Change-Id: I1217f5f273a1420d80e2307ac9ff4a52460237a2
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
next
Masaya Suzuki 5 years ago
parent
commit
c0cfdcd2f1
  1. 14
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java
  2. 20
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java

14
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java

@ -449,7 +449,7 @@ public final class DfsBlockCache {
}
@SuppressWarnings("unchecked")
private void reserveSpace(int reserve, DfsStreamKey key) {
private void reserveSpace(long reserve, DfsStreamKey key) {
clockLock.lock();
try {
long live = LongStream.of(getCurrentSize()).sum() + reserve;
@ -486,7 +486,7 @@ public final class DfsBlockCache {
}
}
private void creditSpace(int credit, DfsStreamKey key) {
private void creditSpace(long credit, DfsStreamKey key) {
clockLock.lock();
try {
getStat(liveBytes, key).addAndGet(-credit);
@ -496,7 +496,7 @@ public final class DfsBlockCache {
}
@SuppressWarnings("unchecked")
private void addToClock(Ref ref, int credit) {
private void addToClock(Ref ref, long credit) {
clockLock.lock();
try {
if (credit != 0) {
@ -576,10 +576,10 @@ public final class DfsBlockCache {
}
<T> Ref<T> putRef(DfsStreamKey key, long size, T v) {
return put(key, 0, (int) Math.min(size, Integer.MAX_VALUE), v);
return put(key, 0, size, v);
}
<T> Ref<T> put(DfsStreamKey key, long pos, int size, T v) {
<T> Ref<T> put(DfsStreamKey key, long pos, long size, T v) {
int slot = slot(key, pos);
HashEntry e1 = table.get(slot);
Ref<T> ref = scanRef(e1, key, pos);
@ -722,12 +722,12 @@ public final class DfsBlockCache {
static final class Ref<T> {
final DfsStreamKey key;
final long position;
final int size;
final long size;
volatile T value;
Ref next;
volatile boolean hot;
Ref(DfsStreamKey key, long position, int size, T v) {
Ref(DfsStreamKey key, long position, long size, T v) {
this.key = key;
this.position = position;
this.size = size;

20
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java

@ -1035,12 +1035,13 @@ public final class DfsPackFile extends BlockBasedFile {
bs = wantSize;
}
PackIndex idx = PackIndex.read(new BufferedInputStream(in, bs));
int sz = (int) Math.min(
idx.getObjectCount() * REC_SIZE,
Integer.MAX_VALUE);
ctx.stats.readIdxBytes += rc.position();
index = idx;
return new DfsBlockCache.Ref<>(idxKey, REF_POSITION, sz, idx);
return new DfsBlockCache.Ref<>(
idxKey,
REF_POSITION,
idx.getObjectCount() * REC_SIZE,
idx);
} finally {
ctx.stats.readIdxMicros += elapsedMicros(start);
}
@ -1058,9 +1059,12 @@ public final class DfsPackFile extends BlockBasedFile {
private DfsBlockCache.Ref<PackReverseIndex> loadReverseIdx(
DfsReader ctx, DfsStreamKey revKey, PackIndex idx) {
PackReverseIndex revidx = new PackReverseIndex(idx);
int sz = (int) Math.min(idx.getObjectCount() * 8, Integer.MAX_VALUE);
reverseIndex = revidx;
return new DfsBlockCache.Ref<>(revKey, REF_POSITION, sz, revidx);
return new DfsBlockCache.Ref<>(
revKey,
REF_POSITION,
idx.getObjectCount() * 8,
revidx);
}
private DfsBlockCache.Ref<PackBitmapIndex> loadBitmapIndex(
@ -1089,9 +1093,9 @@ public final class DfsPackFile extends BlockBasedFile {
ctx.stats.readIdxBytes += size;
ctx.stats.readIdxMicros += elapsedMicros(start);
}
int sz = (int) Math.min(size, Integer.MAX_VALUE);
bitmapIndex = bmidx;
return new DfsBlockCache.Ref<>(bitmapKey, REF_POSITION, sz, bmidx);
return new DfsBlockCache.Ref<>(
bitmapKey, REF_POSITION, size, bmidx);
} catch (EOFException e) {
throw new IOException(MessageFormat.format(
DfsText.get().shortReadOfIndex,

Loading…
Cancel
Save