Ignore:
Timestamp:
Jan 26, 2010, 9:57:34 PM (15 years ago)
Author:
[email protected]
Message:

Reviewed by Darin Adler.

https://bugs.webkit.org/show_bug.cgi?id=34150
WebKit needs a mechanism to catch stale HashMap entries

It is very difficult to catch stale pointers that are HashMap keys - since a pointer's hash
is just its value, it is very unlikely that any observable problem is reproducible.

This extends hash table consistency checks to check that pointers are referencing allocated
memory blocks, and makes it possible to invoke the checks explicitly (it is not feasible
to enable CHECK_HASHTABLE_CONSISTENCY by default, because that affects performance too much).

  • wtf/HashMap.h: (WTF::::checkConsistency): Call through to HashTable implementation. We can add similar calls to HashSet and HashCountedSet, but I haven't seen hard to debug problems with those yet.
  • wtf/HashSet.h: (WTF::::remove): The version of checkTableConsistency that's guarded by CHECK_HASHTABLE_CONSISTENCY is now called internalCheckTableConsistency().
  • wtf/HashTable.h: (WTF::HashTable::internalCheckTableConsistency): (WTF::HashTable::internalCheckTableConsistencyExceptSize): (WTF::HashTable::checkTableConsistencyExceptSize): Expose checkTableConsistency() even if CHECK_HASHTABLE_CONSISTENCY is off. (WTF::::add): Updated for checkTableConsistency renaming. (WTF::::addPassingHashCode): Ditto. (WTF::::removeAndInvalidate): Ditto. (WTF::::remove): Ditto. (WTF::::rehash): Ditto. (WTF::::checkTableConsistency): The assertion for !shouldExpand() was not correct - this function returns true for tables with m_table == 0. (WTF::::checkTableConsistencyExceptSize): Call checkValueConsistency for key. Potentially, we could do the same for values.
  • wtf/HashTraits.h: (WTF::GenericHashTraits::checkValueConsistency): An empty function that can be overridden to add checks. Currently, the only override is for pointer hashes.
  • wtf/RefPtrHashMap.h: (WTF::::remove): Updated for checkTableConsistency renaming.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/HashTable.h

    r53151 r53899  
    3131
    3232#define DUMP_HASHTABLE_STATS 0
     33// Enables internal WTF consistency checks that are invoked automatically. Non-WTF callers can call checkTableConsistency() even if internal checks are disabled.
    3334#define CHECK_HASHTABLE_CONSISTENCY 0
    3435
     
    341342        template<typename T, typename HashTranslator> ValueType* lookup(const T&);
    342343
    343 #if CHECK_HASHTABLE_CONSISTENCY
     344#if !ASSERT_DISABLED
    344345        void checkTableConsistency() const;
    345346#else
    346347        static void checkTableConsistency() { }
     348#endif
     349#if CHECK_HASHTABLE_CONSISTENCY
     350        void internalCheckTableConsistency() const { checkTableConsistency(); }
     351        void internalCheckTableConsistencyExceptSize() const { checkTableConsistencyExceptSize(); }
     352#else
     353        static void internalCheckTableConsistencyExceptSize() { }
     354        static void internalCheckTableConsistency() { }
    347355#endif
    348356
     
    384392        const_iterator makeKnownGoodConstIterator(ValueType* pos) const { return const_iterator(this, pos, m_table + m_tableSize, HashItemKnownGood); }
    385393
    386 #if CHECK_HASHTABLE_CONSISTENCY
     394#if !ASSERT_DISABLED
    387395        void checkTableConsistencyExceptSize() const;
    388396#else
    389         static void checkTableConsistencyExceptSize() { }
     397        static void checkTableConsistencyExceptSize() const { }
    390398#endif
    391399
     
    625633            expand();
    626634
    627         checkTableConsistency();
     635        internalCheckTableConsistency();
    628636
    629637        ASSERT(m_table);
     
    694702        }
    695703       
    696         checkTableConsistency();
     704        internalCheckTableConsistency();
    697705       
    698706        return std::make_pair(makeKnownGoodIterator(entry), true);
     
    710718            expand();
    711719
    712         checkTableConsistency();
     720        internalCheckTableConsistency();
    713721
    714722        FullLookupType lookupResult = fullLookupForWriting<T, HashTranslator>(key);
     
    739747        }
    740748
    741         checkTableConsistency();
     749        internalCheckTableConsistency();
    742750
    743751        return std::make_pair(makeKnownGoodIterator(entry), true);
     
    806814    {
    807815        invalidateIterators();
    808         checkTableConsistency();
     816        internalCheckTableConsistency();
    809817        remove(pos);
    810818    }
     
    824832            shrink();
    825833
    826         checkTableConsistency();
     834        internalCheckTableConsistency();
    827835    }
    828836
     
    893901    void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::rehash(int newTableSize)
    894902    {
    895         checkTableConsistencyExceptSize();
     903        internalCheckTableConsistencyExceptSize();
    896904
    897905        int oldTableSize = m_tableSize;
     
    915923        deallocateTable(oldTable, oldTableSize);
    916924
    917         checkTableConsistency();
     925        internalCheckTableConsistency();
    918926    }
    919927
     
    982990    }
    983991
    984 #if CHECK_HASHTABLE_CONSISTENCY
     992#if !ASSERT_DISABLED
    985993
    986994    template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>
     
    988996    {
    989997        checkTableConsistencyExceptSize();
    990         ASSERT(!shouldExpand());
     998        ASSERT(!m_table || !shouldExpand());
    991999        ASSERT(!shouldShrink());
    9921000    }
     
    10131021            ASSERT(entry == it.m_position);
    10141022            ++count;
     1023
     1024            KeyTraits::checkValueConsistency(it->first);
    10151025        }
    10161026
     
    10221032    }
    10231033
    1024 #endif // CHECK_HASHTABLE_CONSISTENCY
     1034#endif // ASSERT_DISABLED
    10251035
    10261036#if CHECK_HASHTABLE_ITERATORS
Note: See TracChangeset for help on using the changeset viewer.