From c0cfdcd2f1a14eba2240ce26b3969b9e9267027d Mon Sep 17 00:00:00 2001 From: Masaya Suzuki Date: Sun, 16 Jun 2019 09:09:16 -0700 Subject: [PATCH] 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 --- .../internal/storage/dfs/DfsBlockCache.java | 14 ++++++------- .../internal/storage/dfs/DfsPackFile.java | 20 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java index cd5ada64a..16e7a0d53 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java +++ b/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 { } Ref 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); } - Ref put(DfsStreamKey key, long pos, int size, T v) { + Ref put(DfsStreamKey key, long pos, long size, T v) { int slot = slot(key, pos); HashEntry e1 = table.get(slot); Ref ref = scanRef(e1, key, pos); @@ -722,12 +722,12 @@ public final class DfsBlockCache { static final class Ref { 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; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java index bca891a52..6c69019e0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java +++ b/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 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 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,