Bug 1293260 - Improve ObjectGroup hash in TenureCountCache in 64 bit builds r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Tue, 09 Aug 2016 10:22:21 +0100
changeset 308815 547340fb951dbfc522c9b28c215a7ee31a144e40
parent 308814 05bc24cabedf4075141396080ecc41e9c0412056
child 308816 5df7daac885a736f269f831673d8dfe88e7894ff
push id20279
push usercbook@mozilla.com
push dateWed, 10 Aug 2016 14:04:43 +0000
treeherderfx-team@531100c1d950 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs1293260
milestone51.0a1
Bug 1293260 - Improve ObjectGroup hash in TenureCountCache in 64 bit builds r=terrence
js/src/gc/GCInternals.h
--- a/js/src/gc/GCInternals.h
+++ b/js/src/gc/GCInternals.h
@@ -177,21 +177,37 @@ struct TenureCount
     int count;
 };
 
 // Keep rough track of how many times we tenure objects in particular groups
 // during minor collections, using a fixed size hash for efficiency at the cost
 // of potential collisions.
 struct TenureCountCache
 {
-    TenureCount entries[16];
+    static const size_t EntryShift = 4;
+    static const size_t EntryCount = 1 << EntryShift;
+
+    TenureCount entries[EntryCount];
 
     TenureCountCache() { mozilla::PodZero(this); }
 
+    HashNumber hash(ObjectGroup* group) {
+#if JS_BITS_PER_WORD == 32
+        static const size_t ZeroBits = 3;
+#else
+        static const size_t ZeroBits = 4;
+#endif
+
+        uintptr_t word = uintptr_t(group);
+        MOZ_ASSERT((word & ((1 << ZeroBits) - 1)) == 0);
+        word >>= ZeroBits;
+        return HashNumber((word >> EntryShift) ^ word);
+    }
+
     TenureCount& findEntry(ObjectGroup* group) {
-        return entries[PointerHasher<ObjectGroup*, 3>::hash(group) % mozilla::ArrayLength(entries)];
+        return entries[hash(group) % EntryCount];
     }
 };
 
 } /* namespace gc */
 } /* namespace js */
 
 #endif /* gc_GCInternals_h */