Ignore:
Timestamp:
Jun 2, 2012, 3:49:05 PM (13 years ago)
Author:
[email protected]
Message:

DOM string cache should hash pointers, not characters
https://bugs.webkit.org/show_bug.cgi?id=88175

Reviewed by Phil Pizlo and Sam Weinig.

../JavaScriptCore:

  • heap/Weak.h:

(JSC::weakAdd):
(JSC::weakRemove): Made these function templates slightly more generic
to accommodate new client types.

../WebCore:

Dromaeo DOM Core reports no change.

http://trac.webkit.org/changeset/84934 accidentally changed from hashing
pointers to hashing characters, due to template defaults. Let's change back.

Hashing characters is not so good because:

(1) It's not memory-safe with HashMap::set(). HashMap::set() replaces
the value but not the key. Since our values own our keys, we need to
ensure object identity between key and value, or the key can be freed
prematurely. (This is impossible to demonstrate with our current
eager sweep behavior, but it shows up as crashes in layout tests if you
change to lazy sweep.)

(2) It's slower.

  • bindings/js/DOMWrapperWorld.h:

(WebCore): Override the default hash, which hashes based on characters.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/heap/Weak.h

    r118483 r119341  
    154154// This function helps avoid modifying a weak table while holding an iterator into it. (Object allocation
    155155// can run a finalizer that modifies the table. We avoid that by requiring a pre-constructed object as our value.)
    156 template<typename T, typename U> inline void weakAdd(HashMap<T, Weak<U> >& map, const T& key, PassWeak<U> value)
     156template<typename Map, typename Key, typename Value> inline void weakAdd(Map& map, const Key& key, Value value)
    157157{
    158158    ASSERT(!map.get(key));
     
    160160}
    161161
    162 template<typename T, typename U> inline void weakRemove(HashMap<T, Weak<U> >& map, const T& key, typename Weak<U>::GetType value)
    163 {
    164     typename HashMap<T, Weak<U> >::iterator it = map.find(key);
     162template<typename Map, typename Key, typename Value> inline void weakRemove(Map& map, const Key& key, Value value)
     163{
     164    typename Map::iterator it = map.find(key);
    165165    ASSERT_UNUSED(value, value);
    166166    ASSERT(it != map.end());
Note: See TracChangeset for help on using the changeset viewer.