Title: [124268] trunk/Source
Revision
124268
Author
[email protected]
Date
2012-07-31 16:24:31 -0700 (Tue, 31 Jul 2012)

Log Message

Stop masking 8 bits off of the visited link hash. We need all the bits!
https://bugs.webkit.org/show_bug.cgi?id=92799

Reviewed by Anders Carlsson.

Source/_javascript_Core:

* runtime/Identifier.cpp:
(JSC::IdentifierCStringTranslator::hash):
(JSC::IdentifierLCharFromUCharTranslator::hash):
* runtime/Identifier.h:
(JSC::IdentifierCharBufferTranslator::hash):
Update for new function names.

Source/WebCore:

* loader/appcache/ApplicationCacheStorage.cpp:
(WebCore::urlHostHash):
* platform/network/blackberry/CredentialBackingStore.cpp:
(WebCore::hashCredentialInfo):
* plugins/blackberry/PluginPackageBlackBerry.cpp:
(WebCore::PluginPackage::hash):
Update for new function names.

Source/WTF:

* wtf/StringHasher.h:
(WTF::StringHasher::hashWithTop8BitsMasked):
(WTF::StringHasher::hash):
(StringHasher):
(WTF::StringHasher::computeHashAndMaskTop8Bits):
(WTF::StringHasher::hashMemory):
(WTF::StringHasher::avalancheBits):
Rename existing computeHash and hash functions to computeHashAndMaskTop8Bits
and hashWithTop8BitsMasked respectively. Add new computeHash and hash functions
that do the StringHash without the masking.

* wtf/text/AtomicString.cpp:
(WTF::CStringTranslator::hash):
(WTF::UCharBufferTranslator::hash):
(WTF::HashAndCharactersTranslator::hash):
(WTF::SubstringTranslator::hash):
(WTF::LCharBufferFromLiteralDataTranslator::hash):
(WTF::AtomicString::fromUTF8Internal):
* wtf/text/StringHash.h:
(WTF::CaseFoldingHash::hash):
* wtf/text/StringImpl.h:
(WTF::StringImpl::setHash):
* wtf/text/StringStatics.cpp:
(WTF::StringImpl::hashSlowCase):
* wtf/unicode/UTF8.cpp:
(WTF::Unicode::calculateStringHashAndLengthFromUTF8MaskingTop8Bits):
* wtf/unicode/UTF8.h:
Update for new function names.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (124267 => 124268)


--- trunk/Source/_javascript_Core/ChangeLog	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-07-31 23:24:31 UTC (rev 124268)
@@ -1,3 +1,17 @@
+2012-07-31  Sam Weinig  <[email protected]>
+
+        Stop masking 8 bits off of the visited link hash. We need all the bits!
+        https://bugs.webkit.org/show_bug.cgi?id=92799
+
+        Reviewed by Anders Carlsson.
+
+        * runtime/Identifier.cpp:
+        (JSC::IdentifierCStringTranslator::hash):
+        (JSC::IdentifierLCharFromUCharTranslator::hash):
+        * runtime/Identifier.h:
+        (JSC::IdentifierCharBufferTranslator::hash):
+        Update for new function names.
+
 2012-07-31  Geoffrey Garen  <[email protected]>
 
         Maybe break the Windows build.

Modified: trunk/Source/_javascript_Core/runtime/Identifier.cpp (124267 => 124268)


--- trunk/Source/_javascript_Core/runtime/Identifier.cpp	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/_javascript_Core/runtime/Identifier.cpp	2012-07-31 23:24:31 UTC (rev 124268)
@@ -49,7 +49,7 @@
 struct IdentifierCStringTranslator {
     static unsigned hash(const LChar* c)
     {
-        return StringHasher::computeHash<LChar>(c);
+        return StringHasher::computeHashAndMaskTop8Bits<LChar>(c);
     }
 
     static bool equal(StringImpl* r, const LChar* s)
@@ -72,7 +72,7 @@
 struct IdentifierLCharFromUCharTranslator {
     static unsigned hash(const CharBuffer<UChar>& buf)
     {
-        return StringHasher::computeHash<UChar>(buf.s, buf.length);
+        return StringHasher::computeHashAndMaskTop8Bits<UChar>(buf.s, buf.length);
     }
     
     static bool equal(StringImpl* str, const CharBuffer<UChar>& buf)

Modified: trunk/Source/_javascript_Core/runtime/Identifier.h (124267 => 124268)


--- trunk/Source/_javascript_Core/runtime/Identifier.h	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/_javascript_Core/runtime/Identifier.h	2012-07-31 23:24:31 UTC (rev 124268)
@@ -143,7 +143,7 @@
     struct IdentifierCharBufferTranslator {
         static unsigned hash(const CharBuffer<T>& buf)
         {
-            return StringHasher::computeHash<T>(buf.s, buf.length);
+            return StringHasher::computeHashAndMaskTop8Bits<T>(buf.s, buf.length);
         }
         
         static bool equal(StringImpl* str, const CharBuffer<T>& buf)

Modified: trunk/Source/WTF/ChangeLog (124267 => 124268)


--- trunk/Source/WTF/ChangeLog	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/WTF/ChangeLog	2012-07-31 23:24:31 UTC (rev 124268)
@@ -1,3 +1,39 @@
+2012-07-31  Sam Weinig  <[email protected]>
+
+        Stop masking 8 bits off of the visited link hash. We need all the bits!
+        https://bugs.webkit.org/show_bug.cgi?id=92799
+
+        Reviewed by Anders Carlsson.
+
+        * wtf/StringHasher.h:
+        (WTF::StringHasher::hashWithTop8BitsMasked):
+        (WTF::StringHasher::hash):
+        (StringHasher):
+        (WTF::StringHasher::computeHashAndMaskTop8Bits):
+        (WTF::StringHasher::hashMemory):
+        (WTF::StringHasher::avalancheBits):
+        Rename existing computeHash and hash functions to computeHashAndMaskTop8Bits
+        and hashWithTop8BitsMasked respectively. Add new computeHash and hash functions
+        that do the StringHash without the masking.
+
+        * wtf/text/AtomicString.cpp:
+        (WTF::CStringTranslator::hash):
+        (WTF::UCharBufferTranslator::hash):
+        (WTF::HashAndCharactersTranslator::hash):
+        (WTF::SubstringTranslator::hash):
+        (WTF::LCharBufferFromLiteralDataTranslator::hash):
+        (WTF::AtomicString::fromUTF8Internal):
+        * wtf/text/StringHash.h:
+        (WTF::CaseFoldingHash::hash):
+        * wtf/text/StringImpl.h:
+        (WTF::StringImpl::setHash):
+        * wtf/text/StringStatics.cpp:
+        (WTF::StringImpl::hashSlowCase):
+        * wtf/unicode/UTF8.cpp:
+        (WTF::Unicode::calculateStringHashAndLengthFromUTF8MaskingTop8Bits):
+        * wtf/unicode/UTF8.h:
+        Update for new function names.
+
 2012-07-31  Thiago Marcos P. Santos  <[email protected]>
 
         Add a mechanism to dump the stack trace in case of a crash

Modified: trunk/Source/WTF/wtf/StringHasher.h (124267 => 124268)


--- trunk/Source/WTF/wtf/StringHasher.h	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/WTF/wtf/StringHasher.h	2012-07-31 23:24:31 UTC (rev 124268)
@@ -63,24 +63,10 @@
         m_hasPendingCharacter = true;
     }
 
-    inline unsigned hash() const
+    inline unsigned hashWithTop8BitsMasked() const
     {
-        unsigned result = m_hash;
+        unsigned result = avalancheBits();
 
-        // Handle end case.
-        if (m_hasPendingCharacter) {
-            result += m_pendingCharacter;
-            result ^= result << 11;
-            result += result >> 17;
-        }
-
-        // Force "avalanching" of final 31 bits.
-        result ^= result << 3;
-        result += result >> 5;
-        result ^= result << 2;
-        result += result >> 15;
-        result ^= result << 10;
-
         // Reserving space from the high bits for flags preserves most of the hash's
         // value, since hash lookup typically masks out the high bits anyway.
         result &= (1u << (sizeof(result) * 8 - flagCount)) - 1;
@@ -95,6 +81,67 @@
         return result;
     }
 
+    inline unsigned hash() const
+    {
+        unsigned result = avalancheBits();
+
+        // This avoids ever returning a hash code of 0, since that is used to
+        // signal "hash not computed yet". Setting the high bit maintains
+        // reasonable fidelity to a hash code of 0 because it is likely to yield
+        // exactly 0 when hash lookup masks out the high bits.
+        if (!result)
+            result = 0x80000000;
+
+        return result;
+    }
+
+    template<typename T, UChar Converter(T)> static inline unsigned computeHashAndMaskTop8Bits(const T* data, unsigned length)
+    {
+        StringHasher hasher;
+        bool rem = length & 1;
+        length >>= 1;
+
+        while (length--) {
+            hasher.addCharacters(Converter(data[0]), Converter(data[1]));
+            data += 2;
+        }
+
+        if (rem)
+            hasher.addCharacter(Converter(*data));
+
+        return hasher.hashWithTop8BitsMasked();
+    }
+
+    template<typename T, UChar Converter(T)> static inline unsigned computeHashAndMaskTop8Bits(const T* data)
+    {
+        StringHasher hasher;
+
+        while (true) {
+            UChar b0 = Converter(*data++);
+            if (!b0)
+                break;
+            UChar b1 = Converter(*data++);
+            if (!b1) {
+                hasher.addCharacter(b0);
+                break;
+            }
+
+            hasher.addCharacters(b0, b1);
+        }
+
+        return hasher.hashWithTop8BitsMasked();
+    }
+
+    template<typename T> static inline unsigned computeHashAndMaskTop8Bits(const T* data, unsigned length)
+    {
+        return computeHashAndMaskTop8Bits<T, defaultConverter>(data, length);
+    }
+
+    template<typename T> static inline unsigned computeHashAndMaskTop8Bits(const T* data)
+    {
+        return computeHashAndMaskTop8Bits<T, defaultConverter>(data);
+    }
+
     template<typename T, UChar Converter(T)> static inline unsigned computeHash(const T* data, unsigned length)
     {
         StringHasher hasher;
@@ -145,13 +192,13 @@
     template<size_t length> static inline unsigned hashMemory(const void* data)
     {
         COMPILE_ASSERT(!(length % 4), length_must_be_a_multible_of_four);
-        return computeHash<UChar>(static_cast<const UChar*>(data), length / sizeof(UChar));
+        return computeHashAndMaskTop8Bits<UChar>(static_cast<const UChar*>(data), length / sizeof(UChar));
     }
 
     static inline unsigned hashMemory(const void* data, unsigned size)
     {
         ASSERT(!(size % 2));
-        return computeHash<UChar>(static_cast<const UChar*>(data), size / sizeof(UChar));
+        return computeHashAndMaskTop8Bits<UChar>(static_cast<const UChar*>(data), size / sizeof(UChar));
     }
 
 private:
@@ -173,6 +220,27 @@
         m_hash += m_hash >> 11;
     }
 
+    inline unsigned avalancheBits() const
+    {
+        unsigned result = m_hash;
+
+        // Handle end case.
+        if (m_hasPendingCharacter) {
+            result += m_pendingCharacter;
+            result ^= result << 11;
+            result += result >> 17;
+        }
+
+        // Force "avalanching" of final 31 bits.
+        result ^= result << 3;
+        result += result >> 5;
+        result ^= result << 2;
+        result += result >> 15;
+        result ^= result << 10;
+
+        return result;
+    }
+
     unsigned m_hash;
     bool m_hasPendingCharacter;
     UChar m_pendingCharacter;

Modified: trunk/Source/WTF/wtf/text/AtomicString.cpp (124267 => 124268)


--- trunk/Source/WTF/wtf/text/AtomicString.cpp	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/WTF/wtf/text/AtomicString.cpp	2012-07-31 23:24:31 UTC (rev 124268)
@@ -88,7 +88,7 @@
 struct CStringTranslator {
     static unsigned hash(const LChar* c)
     {
-        return StringHasher::computeHash(c);
+        return StringHasher::computeHashAndMaskTop8Bits(c);
     }
 
     static inline bool equal(StringImpl* r, const LChar* s)
@@ -124,7 +124,7 @@
 struct UCharBufferTranslator {
     static unsigned hash(const UCharBuffer& buf)
     {
-        return StringHasher::computeHash(buf.s, buf.length);
+        return StringHasher::computeHashAndMaskTop8Bits(buf.s, buf.length);
     }
 
     static bool equal(StringImpl* const& str, const UCharBuffer& buf)
@@ -149,7 +149,7 @@
 struct HashAndCharactersTranslator {
     static unsigned hash(const HashAndCharacters& buffer)
     {
-        ASSERT(buffer.hash == StringHasher::computeHash(buffer.characters, buffer.length));
+        ASSERT(buffer.hash == StringHasher::computeHashAndMaskTop8Bits(buffer.characters, buffer.length));
         return buffer.hash;
     }
 
@@ -262,7 +262,7 @@
 struct SubstringTranslator {
     static unsigned hash(const SubstringLocation& buffer)
     {
-        return StringHasher::computeHash(buffer.baseString->characters() + buffer.start, buffer.length);
+        return StringHasher::computeHashAndMaskTop8Bits(buffer.baseString->characters() + buffer.start, buffer.length);
     }
 
     static bool equal(StringImpl* const& string, const SubstringLocation& buffer)
@@ -301,7 +301,7 @@
 struct LCharBufferFromLiteralDataTranslator {
     static unsigned hash(const LCharBuffer& buf)
     {
-        return StringHasher::computeHash(buf.s, buf.length);
+        return StringHasher::computeHashAndMaskTop8Bits(buf.s, buf.length);
     }
 
     static bool equal(StringImpl* const& str, const LCharBuffer& buf)
@@ -373,7 +373,7 @@
 {
     HashAndUTF8Characters buffer;
     buffer.characters = charactersStart;
-    buffer.hash = calculateStringHashAndLengthFromUTF8(charactersStart, charactersEnd, buffer.length, buffer.utf16Length);
+    buffer.hash = calculateStringHashAndLengthFromUTF8MaskingTop8Bits(charactersStart, charactersEnd, buffer.length, buffer.utf16Length);
 
     if (!buffer.hash)
         return nullAtom;

Modified: trunk/Source/WTF/wtf/text/StringHash.h (124267 => 124268)


--- trunk/Source/WTF/wtf/text/StringHash.h	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/WTF/wtf/text/StringHash.h	2012-07-31 23:24:31 UTC (rev 124268)
@@ -97,7 +97,7 @@
 
         static unsigned hash(const UChar* data, unsigned length)
         {
-            return StringHasher::computeHash<UChar, foldCase<UChar> >(data, length);
+            return StringHasher::computeHashAndMaskTop8Bits<UChar, foldCase<UChar> >(data, length);
         }
 
         static unsigned hash(StringImpl* str)
@@ -109,7 +109,7 @@
 
         static unsigned hash(const LChar* data, unsigned length)
         {
-            return StringHasher::computeHash<LChar, foldCase<LChar> >(data, length);
+            return StringHasher::computeHashAndMaskTop8Bits<LChar, foldCase<LChar> >(data, length);
         }
 
         static inline unsigned hash(const char* data, unsigned length)

Modified: trunk/Source/WTF/wtf/text/StringImpl.h (124267 => 124268)


--- trunk/Source/WTF/wtf/text/StringImpl.h	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/WTF/wtf/text/StringImpl.h	2012-07-31 23:24:31 UTC (rev 124268)
@@ -428,7 +428,7 @@
     {
         ASSERT(!hasHash());
         // Multiple clients assume that StringHasher is the canonical string hash function.
-        ASSERT(hash == (is8Bit() ? StringHasher::computeHash(m_data8, m_length) : StringHasher::computeHash(m_data16, m_length)));
+        ASSERT(hash == (is8Bit() ? StringHasher::computeHashAndMaskTop8Bits(m_data8, m_length) : StringHasher::computeHashAndMaskTop8Bits(m_data16, m_length)));
         ASSERT(!(hash & (s_flagMask << (8 * sizeof(hash) - s_flagCount)))); // Verify that enough high bits are empty.
         
         hash <<= s_flagCount;

Modified: trunk/Source/WTF/wtf/text/StringStatics.cpp (124267 => 124268)


--- trunk/Source/WTF/wtf/text/StringStatics.cpp	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/WTF/wtf/text/StringStatics.cpp	2012-07-31 23:24:31 UTC (rev 124268)
@@ -64,9 +64,9 @@
 NEVER_INLINE unsigned StringImpl::hashSlowCase() const
 {
     if (is8Bit())
-        setHash(StringHasher::computeHash(m_data8, m_length));
+        setHash(StringHasher::computeHashAndMaskTop8Bits(m_data8, m_length));
     else
-        setHash(StringHasher::computeHash(m_data16, m_length));
+        setHash(StringHasher::computeHashAndMaskTop8Bits(m_data16, m_length));
     return existingHash();
 }
 

Modified: trunk/Source/WTF/wtf/unicode/UTF8.cpp (124267 => 124268)


--- trunk/Source/WTF/wtf/unicode/UTF8.cpp	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/WTF/wtf/unicode/UTF8.cpp	2012-07-31 23:24:31 UTC (rev 124268)
@@ -356,7 +356,7 @@
     return result;
 }
 
-unsigned calculateStringHashAndLengthFromUTF8(const char* data, const char* dataEnd, unsigned& dataLength, unsigned& utf16Length)
+unsigned calculateStringHashAndLengthFromUTF8MaskingTop8Bits(const char* data, const char* dataEnd, unsigned& dataLength, unsigned& utf16Length)
 {
     if (!data)
         return 0;
@@ -404,7 +404,7 @@
             return 0;
     }
 
-    return stringHasher.hash();
+    return stringHasher.hashWithTop8BitsMasked();
 }
 
 bool equalUTF16WithUTF8(const UChar* a, const UChar* aEnd, const char* b, const char* bEnd)

Modified: trunk/Source/WTF/wtf/unicode/UTF8.h (124267 => 124268)


--- trunk/Source/WTF/wtf/unicode/UTF8.h	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/WTF/wtf/unicode/UTF8.h	2012-07-31 23:24:31 UTC (rev 124268)
@@ -74,7 +74,7 @@
                     const UChar** sourceStart, const UChar* sourceEnd, 
                     char** targetStart, char* targetEnd, bool strict = true);
 
-    unsigned calculateStringHashAndLengthFromUTF8(const char* data, const char* dataEnd, unsigned& dataLength, unsigned& utf16Length);
+    unsigned calculateStringHashAndLengthFromUTF8MaskingTop8Bits(const char* data, const char* dataEnd, unsigned& dataLength, unsigned& utf16Length);
 
     bool equalUTF16WithUTF8(const UChar* a, const UChar* aEnd, const char* b, const char* bEnd);
 

Modified: trunk/Source/WebCore/ChangeLog (124267 => 124268)


--- trunk/Source/WebCore/ChangeLog	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/WebCore/ChangeLog	2012-07-31 23:24:31 UTC (rev 124268)
@@ -1,3 +1,18 @@
+2012-07-31  Sam Weinig  <[email protected]>
+
+        Stop masking 8 bits off of the visited link hash. We need all the bits!
+        https://bugs.webkit.org/show_bug.cgi?id=92799
+
+        Reviewed by Anders Carlsson.
+
+        * loader/appcache/ApplicationCacheStorage.cpp:
+        (WebCore::urlHostHash):
+        * platform/network/blackberry/CredentialBackingStore.cpp:
+        (WebCore::hashCredentialInfo):
+        * plugins/blackberry/PluginPackageBlackBerry.cpp:
+        (WebCore::PluginPackage::hash):
+        Update for new function names.
+
 2012-07-31  Chris Rogers  <[email protected]>
 
         Allow AudioDestination to support local/live audio input

Modified: trunk/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp (124267 => 124268)


--- trunk/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp	2012-07-31 23:24:31 UTC (rev 124268)
@@ -92,7 +92,7 @@
     unsigned hostStart = url.hostStart();
     unsigned hostEnd = url.hostEnd();
     
-    return AlreadyHashed::avoidDeletedValue(StringHasher::computeHash(url.string().characters() + hostStart, hostEnd - hostStart));
+    return AlreadyHashed::avoidDeletedValue(StringHasher::computeHashAndMaskTop8Bits(url.string().characters() + hostStart, hostEnd - hostStart));
 }
 
 ApplicationCacheGroup* ApplicationCacheStorage::loadCacheGroup(const KURL& manifestURL)

Modified: trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.cpp (124267 => 124268)


--- trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.cpp	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.cpp	2012-07-31 23:24:31 UTC (rev 124268)
@@ -47,7 +47,7 @@
                                        static_cast<int>(space.serverType()),
                                        space.realm().utf8().data(),
                                        static_cast<int>(space.authenticationScheme()));
-    return StringHasher::computeHash(hashString.characters(), hashString.length());
+    return StringHasher::computeHashAndMaskTop8Bits(hashString.characters(), hashString.length());
 }
 
 CredentialBackingStore& credentialBackingStore()

Modified: trunk/Source/WebCore/plugins/blackberry/PluginPackageBlackBerry.cpp (124267 => 124268)


--- trunk/Source/WebCore/plugins/blackberry/PluginPackageBlackBerry.cpp	2012-07-31 23:20:07 UTC (rev 124267)
+++ trunk/Source/WebCore/plugins/blackberry/PluginPackageBlackBerry.cpp	2012-07-31 23:24:31 UTC (rev 124268)
@@ -196,7 +196,7 @@
         m_path.impl()->hash()
     };
 
-    return StringHasher::computeHash(reinterpret_cast<const UChar*>(hashCodes), sizeof(hashCodes) / sizeof(UChar));
+    return StringHasher::computeHashAndMaskTop8Bits(reinterpret_cast<const UChar*>(hashCodes), sizeof(hashCodes) / sizeof(UChar));
 }
 
 bool PluginPackage::load()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to