aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Fick <mfick@nvidia.com>2025-07-18 08:54:23 -0700
committerMatthias Sohn <matthias.sohn@sap.com>2025-07-30 13:22:02 +0200
commitee304e465bf41ddbd7e600004646cf16c7cf5981 (patch)
tree688c32d2795be2ff9538892ff37d1376b223dd41
parent37d1a65f07e711eb9b013c647936262c25ed403d (diff)
downloadjgit-ee304e465bf41ddbd7e600004646cf16c7cf5981.tar.gz
jgit-ee304e465bf41ddbd7e600004646cf16c7cf5981.zip
Use volatiles for bitmap and revIndex in Packstable-6.10
Previously idx() was memoized with a volatile to improve performance, do the same for the bitmap and reverseIndexes. Change-Id: I50515a3aaae7dd4f9d23989dcd5f79cefc9e0f07 Signed-off-by: Martin Fick <mfick@nvidia.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java28
1 files changed, 22 insertions, 6 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java
index d5957e5df4..bf574ec4c2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/Pack.java
@@ -124,9 +124,9 @@ public class Pack implements Iterable<PackIndex.MutableEntry> {
private volatile Optionally<PackIndex> loadedIdx = Optionally.empty();
- private Optionally<PackReverseIndex> reverseIdx = Optionally.empty();
+ private volatile Optionally<PackReverseIndex> reverseIdx = Optionally.empty();
- private Optionally<PackBitmapIndex> bitmapIdx = Optionally.empty();
+ private volatile Optionally<PackBitmapIndex> bitmapIdx = Optionally.empty();
/**
* Objects we have tried to read, and discovered to be corrupt.
@@ -321,8 +321,8 @@ public class Pack implements Iterable<PackIndex.MutableEntry> {
private synchronized void closeIndices() {
loadedIdx = Optionally.empty();
- reverseIdx.clear();
- bitmapIdx.clear();
+ reverseIdx = Optionally.empty();
+ bitmapIdx = Optionally.empty();
}
/**
@@ -1190,7 +1190,15 @@ public class Pack implements Iterable<PackIndex.MutableEntry> {
return getReverseIdx().findNextOffset(startOffset, maxOffset);
}
- synchronized PackBitmapIndex getBitmapIndex() throws IOException {
+ PackBitmapIndex getBitmapIndex() throws IOException {
+ Optional<PackBitmapIndex> optional = bitmapIdx.getOptional();
+ if (optional.isPresent()) {
+ return optional.get();
+ }
+ return memoizeBitmapIndexIfNeeded();
+ }
+
+ private synchronized PackBitmapIndex memoizeBitmapIndexIfNeeded() throws IOException {
if (invalid || bitmapIdxFile == null) {
return null;
}
@@ -1225,7 +1233,15 @@ public class Pack implements Iterable<PackIndex.MutableEntry> {
this.bitmapIdxFile = bitmapIndexFile;
}
- private synchronized PackReverseIndex getReverseIdx() throws IOException {
+ private PackReverseIndex getReverseIdx() throws IOException {
+ Optional<PackReverseIndex> optional = reverseIdx.getOptional();
+ if (optional.isPresent()) {
+ return optional.get();
+ }
+ return memoizeReverseIdxIfNeeded();
+ }
+
+ private synchronized PackReverseIndex memoizeReverseIdxIfNeeded() throws IOException {
if (invalid) {
throw new PackInvalidException(packFile, invalidatingCause);
}