Thread (18 messages) flat view 18 messages, 3 authors, 2016-06-15
STALE3742d

[JGIT PATCH 07/13] Clear dead OffsetCache cells when clearing a reference

From: Shawn O. Pearce <hidden>
Date: 2016-06-15 22:46:40
Subsystem: the rest · Maintainer: Linus Torvalds

If we just cleared a Reference from the queue than there is a good
chance that there is a dead Entry cell in the hash table's bucket
for this position.  If we find one that matches we know we should
clear out that chain.

Signed-off-by: Shawn O. Pearce <redacted>
---
 .../src/org/spearce/jgit/lib/OffsetCache.java      |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/OffsetCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/OffsetCache.java
index 170c5d2..12912d9 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/OffsetCache.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/OffsetCache.java
@@ -418,8 +418,22 @@ private void gc() {
 			// skew the resource counters we maintain. Our canClear() check here
 			// provides a way to skip the redundant dequeues, if any.
 			//
-			if (r.canClear())
+			if (r.canClear()) {
 				clear(r);
+
+				boolean found = false;
+				final int s = slot(r.pack, r.position);
+				final Entry<V> e1 = table.get(s);
+				for (Entry<V> n = e1; n != null; n = n.next) {
+					if (n.ref == r) {
+						n.dead = true;
+						found = true;
+						break;
+					}
+				}
+				if (found)
+					table.compareAndSet(s, e1, clean(e1));
+			}
 		}
 	}
 
-- 
1.6.3.rc1.205.g37f8
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help