gecko-dev/xpcom/ds
L. David Baron 07c2f2dc49 Bug 1352889 - Ensure that PLDHashTable's second hash doesn't have padding with 0 bits for tables with capacity larger than 2^16. r=njn
PLDHashTable takes the result of the hash function and multiplies it by
kGoldenRatio to ensure that it has a good distribution of bits across
the 32-bit hash value, and then zeroes out the low bit so that it can be
used for the collision flag.  This result is called hash0.  From hash0
it computes two different numbers used to find entries in the table
storage:  hash1 is used to find an initial position in the table to
begin searching for an entry; hash2 is then used to repeatedly offset
that position (mod the size of the table) to build a chain of positions
to search.

In a table with capacity 2^c entries, hash1 is simply the upper c bits
of hash0.  This patch does not change this.

Prior to this patch, hash2 was the c bits below hash1, padded at the low
end with zeroes when c > 16.  (Note that bug 927705, changeset
1a02bec165e16f370cace3da21bb2b377a0a7242, increased the maximum capacity
from 2^23 to 2^26 since 2^23 was sometimes insufficient!)  This manner
of computing hash2 is problematic because it increases the risk of long
chains for very large tables, since there is less variation in the hash2
result due to the zero padding.

So this patch changes the hash2 computation by using the low bits of
hash0 instead of shifting it around, thus avoiding 0 bits in parts of
the hash2 value that are significant.

Note that this changes what hash2 is in all cases except when the table
capacity is exactly 2^16, so it does change our hashing characteristics.
For tables with capacity less than 2^16, it should be using a different
second hash, but with the same amount of random-ish data.  For tables
with capacity greater than 2^16, it should be using more random-ish
data.

Note that this patch depends on the patch for bug 1353458 in order to
avoid causing test failures.

MozReview-Commit-ID: JvnxAMBY711

--HG--
extra : transplant_source : 2%D2%C2%CE%E1%92%C8%F8H%D7%15%A4%86%5B%3Ac%0B%08%3DA
2017-05-31 13:44:02 -07:00
..
ArenaAllocator.h Bug 943156 - Add a templated ArenaAllocator. r=froydnj 2017-03-30 16:46:55 -07:00
ArenaAllocatorExtensions.h Bug 1351732 - Part 1: Add an ArenaAllocator strdup extension. r=froydnj 2017-03-30 16:46:56 -07:00
ArrayIterator.h Bug 1342303 part 1 - Make nsTArrayIterator an independent class. r=erahm 2017-02-24 16:14:06 +11:00
IncrementalTokenizer.cpp Bug 1339537 - Part 6: Pass std::function values tree by const reference instead of by value, r=ehsan 2017-04-27 12:44:57 -04:00
IncrementalTokenizer.h Bug 1339537 - Part 6: Pass std::function values tree by const reference instead of by value, r=ehsan 2017-04-27 12:44:57 -04:00
moz.build Bug 1351732 - Part 2: Replace use of PLArena with ArenaAllocator in xpcom. r=froydnj 2017-03-30 16:46:58 -07:00
nsArray.cpp Bug 1311191 - Part 1: Add nsISupportsArray-like iteration to nsArray. r=froydnj 2016-10-24 13:24:26 -07:00
nsArray.h Bug 1311191 - Part 1: Add nsISupportsArray-like iteration to nsArray. r=froydnj 2016-10-24 13:24:26 -07:00
nsArrayEnumerator.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsArrayEnumerator.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsArrayUtils.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsArrayUtils.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsAtomService.cpp Bug 1260871 - Remove do_GetAtom() and rename NS_NewAtom() as NS_Atomize(). r=erahm. 2016-03-29 10:09:43 +11:00
nsAtomService.h
nsAtomTable.cpp Bug 1351303, add main thread only cache for nsIAtoms to speed up atomization, r=froydnj 2017-04-03 23:13:18 +03:00
nsAtomTable.h Bug 1275755 - Use an explicit init routine for the atom table. r=froydnj 2016-05-28 17:08:05 +01:00
nsBaseHashtable.h Bug 1359848 - Part 1: Add the nsClassHashtable::LookupForAdd() API to allow consumers to lookup and add an entry to a class hashtable if it doesn't exist already with a single lookup; r=froydnj 2017-05-03 08:59:48 -04:00
nsCharSeparatedTokenizer.h
nsCheapSets.h Bug 1268772 (part 1) - Remove nsCheapSet::Put()'s return value. r=erahm. 2016-04-28 15:59:58 +10:00
nsClassHashtable.h Bug 1361745 - Part 1: Improve the nsClassHashtable::LookupForAdd() API; r=froydnj 2017-05-08 10:02:04 -04:00
nsCOMArray.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsCOMArray.h Bug 1342303 part 6 - Remove nsCOMArray::Enumerate{Forwards,Backwards}. r=erahm 2017-02-24 21:37:07 +11:00
nsCRT.cpp
nsCRT.h Bug 1232696 - Remove NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW as it causes segfaulting for GCC 6 builds (5 of 5, fixes for docshell/). r=bzbarsky. 2017-01-24 17:12:10 +01:00
nsDataHashtable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsDeque.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsDeque.h Bug 1336215 - Optimize iterator if nsDeque is const - r=froydnj 2017-02-03 13:08:10 +11:00
nsEnumeratorUtils.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsEnumeratorUtils.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsExpirationTracker.h Bug 1311425 - Avoid expiration timers when scheduling idle runnables, r=froydnj 2017-05-24 21:17:06 -04:00
nsHashKeys.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsHashPropertyBag.cpp Bug 1353660 - proxy destruction of nsHashPropertyBag's hash table to the main thread; r=mccr8 2017-04-05 15:31:20 -04:00
nsHashPropertyBag.h Bug 1353660 - proxy destruction of nsHashPropertyBag's hash table to the main thread; r=mccr8 2017-04-05 15:31:20 -04:00
nsIArray.idl
nsIArrayExtensions.idl Bug 1311191 - Part 1: Add nsISupportsArray-like iteration to nsArray. r=froydnj 2016-10-24 13:24:26 -07:00
nsIAtom.idl Bug 1351303, add main thread only cache for nsIAtoms to speed up atomization, r=froydnj 2017-04-03 23:13:18 +03:00
nsIAtomService.idl Bug 1260871 - Remove do_GetAtom() and rename NS_NewAtom() as NS_Atomize(). r=erahm. 2016-03-29 10:09:43 +11:00
nsIHashable.idl
nsIINIParser.idl
nsIMutableArray.idl Bug 1355216 - Mark last parameters that are almost always falsy as optional, r=froydnj. 2017-04-12 00:07:30 +02:00
nsINIParserImpl.cpp
nsINIParserImpl.h
nsINIProcessor.js Bug 1285063 - Part 1: Add a helper to XPCOMUtils to iterate over entries in a category. r=kmag 2016-07-11 17:33:06 -07:00
nsINIProcessor.manifest
nsInterfaceHashtable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsIObserver.idl
nsIObserverService.idl Bug 1355216 - Mark last parameters that are almost always falsy as optional, r=froydnj. 2017-04-12 00:07:30 +02:00
nsIPersistentProperties2.idl
nsIPersistentProperties.h
nsIProperties.idl
nsIProperty.idl
nsIPropertyBag2.idl
nsIPropertyBag.idl
nsISerializable.idl
nsISimpleEnumerator.idl
nsIStringEnumerator.idl
nsISupportsIterators.idl
nsISupportsPrimitives.idl Bug 1329718 - remove nsISupportsVoid and associated machinery; r=erahm 2017-01-10 16:31:48 -05:00
nsIVariant.idl
nsIWindowsRegKey.idl
nsIWritablePropertyBag2.idl
nsIWritablePropertyBag.idl
nsJSThingHashtable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsMathUtils.h Bug 1354510 - Firefox build should recognize Solaris. r=glandium 2017-04-11 00:01:32 -07:00
nsObserverList.cpp Backed out changeset 491237dbcb5d (bug 1323207) 2016-12-16 20:06:43 +01:00
nsObserverList.h Bug 1268772 (part 5) - Use MOZ_MUST_USE in other parts of xpcom/ds/. r=erahm. 2016-04-28 17:11:17 +10:00
nsObserverService.cpp Bug 1297658 - Avoid unnecessary checking in memory reporters. r=erahm. 2016-08-24 15:23:45 +10:00
nsObserverService.h Bug 1268772 (part 5) - Use MOZ_MUST_USE in other parts of xpcom/ds/. r=erahm. 2016-04-28 17:11:17 +10:00
nsPersistentProperties.cpp Bug 1351732 - Part 2: Replace use of PLArena with ArenaAllocator in xpcom. r=froydnj 2017-03-30 16:46:58 -07:00
nsPersistentProperties.h Bug 1351732 - Part 2: Replace use of PLArena with ArenaAllocator in xpcom. r=froydnj 2017-03-30 16:46:58 -07:00
nsPointerHashKeys.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsProperties.cpp
nsProperties.h
nsQuickSort.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsQuickSort.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsRefPtrHashtable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsStaticAtom.h Bug 1277106 - Part 4: Remove MOZ_UTF16() macro. r=Waldo 2016-07-19 21:07:53 -07:00
nsStaticNameTable.cpp Bug 1350423 - Remove unused PL_ARENA macro in nsStaticNameTable. r=froydnj 2017-03-27 09:15:38 -07:00
nsStaticNameTable.h
nsStringEnumerator.cpp Bug 1262399 - remove Impl suffixes from nsSupports* implementations; r=mccr8 2016-05-03 15:25:41 -05:00
nsStringEnumerator.h Bug 1268772 (part 5) - Use MOZ_MUST_USE in other parts of xpcom/ds/. r=erahm. 2016-04-28 17:11:17 +10:00
nsSupportsPrimitives.cpp Bug 1329718 - remove nsISupportsVoid and associated machinery; r=erahm 2017-01-10 16:31:48 -05:00
nsSupportsPrimitives.h Bug 1329718 - remove nsISupportsVoid and associated machinery; r=erahm 2017-01-10 16:31:48 -05:00
nsTArray-inl.h Bug 1348123 - Add release bounds checking when inserting and replacing. r=froydnj 2017-03-17 16:40:53 -07:00
nsTArray.cpp Bug 1338574 - Part 7: Use MOZ_CRASH_UNSAFE_PRINTF in XPCOM. r=froydnj 2017-02-21 18:02:03 +01:00
nsTArray.h Bug 1295611 - Add mozilla::Span. r=froydnj,gerv. 2017-03-31 13:32:18 +03:00
nsTArrayForwardDeclare.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsTHashtable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsTObserverArray.cpp Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsTObserverArray.h Bug 1339537 - Part 6: Pass std::function values tree by const reference instead of by value, r=ehsan 2017-04-27 12:44:57 -04:00
nsTPriorityQueue.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
nsVariant.cpp Bug 1334318 - remove last uses of PR_smprintf; r=froydnj 2017-04-28 10:13:26 -06:00
nsVariant.h Bug 1268772 (part 2) - Make infallible nsVariant methods return |void| instead of |nsresult|. r=erahm. 2016-04-29 13:47:44 +10:00
nsWhitespaceTokenizer.h
nsWindowsRegKey.cpp Bug 1305422 - followup - use correct check for memory allocation failure in nsWindowsRegKey.cpp; r=bustage 2016-09-30 01:56:28 -04:00
nsWindowsRegKey.h Bug 1268772 (part 3) - Remove NS_NewWindowsRegKey()'s return value. r=erahm. 2016-05-02 09:06:45 +10:00
Observer.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
PLDHashTable.cpp Bug 1352889 - Ensure that PLDHashTable's second hash doesn't have padding with 0 bits for tables with capacity larger than 2^16. r=njn 2017-05-31 13:44:02 -07:00
PLDHashTable.h Bug 1332631 part C - file moves from xpcom/glue to xpcom/ds, r=froydnj 2017-01-20 13:59:21 -05:00
StickyTimeDuration.h
Tokenizer.cpp Bug 1340581 - Add some release-grade assertions to mozilla::Tokenizer to catch string overflows. r=froydnj 2017-02-22 06:53:00 -05:00
Tokenizer.h Bug 1322825 - Incremental tokenizer. r=froydnj 2017-02-06 10:49:00 -05:00