Changeset 207186 in webkit


Ignore:
Timestamp:
Oct 11, 2016 8:14:56 PM (7 years ago)
Author:
sbarati@apple.com
Message:

HasOwnPropertyCache needs to ref the UniquedStringImpls it sees
https://bugs.webkit.org/show_bug.cgi?id=163255

Reviewed by Geoffrey Garen.

The cache needs to be responsible for ensuring that things
in the cache stay alive. Before, it wasn't doing this, and
that was wrong.

  • runtime/HasOwnPropertyCache.h:

(JSC::HasOwnPropertyCache::Entry::operator=):
(JSC::HasOwnPropertyCache::operator delete):
(JSC::HasOwnPropertyCache::create):
(JSC::HasOwnPropertyCache::get):
(JSC::HasOwnPropertyCache::tryAdd):
(JSC::HasOwnPropertyCache::clear):
(JSC::HasOwnPropertyCache::zeroBuffer):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r207179 r207186  
     12016-10-11  Saam Barati  <sbarati@apple.com>
     2
     3        HasOwnPropertyCache needs to ref the UniquedStringImpls it sees
     4        https://bugs.webkit.org/show_bug.cgi?id=163255
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        The cache needs to be responsible for ensuring that things
     9        in the cache stay alive. Before, it wasn't doing this, and
     10        that was wrong.
     11
     12        * runtime/HasOwnPropertyCache.h:
     13        (JSC::HasOwnPropertyCache::Entry::operator=):
     14        (JSC::HasOwnPropertyCache::operator delete):
     15        (JSC::HasOwnPropertyCache::create):
     16        (JSC::HasOwnPropertyCache::get):
     17        (JSC::HasOwnPropertyCache::tryAdd):
     18        (JSC::HasOwnPropertyCache::clear):
     19        (JSC::HasOwnPropertyCache::zeroBuffer):
     20
    1212016-10-06  Filip Pizlo  <fpizlo@apple.com>
    222
  • trunk/Source/JavaScriptCore/runtime/HasOwnPropertyCache.h

    r206885 r207186  
    4343        static ptrdiff_t offsetOfResult() { return OBJECT_OFFSETOF(Entry, result); }
    4444
    45         UniquedStringImpl* impl;
    46         StructureID structureID;
    47         bool result;
     45        Entry() = default;
     46
     47        Entry& operator=(Entry&& other)
     48        {
     49            impl = WTFMove(other.impl);
     50            structureID = other.structureID;
     51            result = other.result;
     52            return *this;
     53        }
     54
     55        RefPtr<UniquedStringImpl> impl { };
     56        StructureID structureID { 0 };
     57        bool result { false };
    4858    };
    4959
     
    5262    void operator delete(void* cache)
    5363    {
     64        static_cast<HasOwnPropertyCache*>(cache)->clear();
    5465        fastFree(cache);
    5566    }
     
    5970        size_t allocationSize = sizeof(Entry) * size;
    6071        HasOwnPropertyCache* result = static_cast<HasOwnPropertyCache*>(fastMalloc(allocationSize));
    61         result->clear();
     72        result->clearBuffer();
    6273        return result;
    6374    }
     
    7485        uint32_t index = HasOwnPropertyCache::hash(id, impl) & mask;
    7586        Entry& entry = bitwise_cast<Entry*>(this)[index];
    76         if (entry.structureID == id && entry.impl == impl)
     87        if (entry.structureID == id && entry.impl.get() == impl)
    7788            return entry.result;
    7889        return Nullopt;
     
    105116            StructureID id = structure->id();
    106117            uint32_t index = HasOwnPropertyCache::hash(id, impl) & mask;
    107             bitwise_cast<Entry*>(this)[index] = Entry{ impl, id, result };
     118            bitwise_cast<Entry*>(this)[index] = Entry{ RefPtr<UniquedStringImpl>(impl), id, result };
    108119        }
    109120    }
     
    111122    void clear()
    112123    {
    113         memset(this, 0, sizeof(Entry) * size);
     124        Entry* buffer = bitwise_cast<Entry*>(this);
     125        for (uint32_t i = 0; i < size; ++i)
     126            buffer[i].Entry::~Entry();
     127
     128        clearBuffer();
     129    }
     130
     131private:
     132    void clearBuffer()
     133    {
     134        Entry* buffer = bitwise_cast<Entry*>(this);
     135        for (uint32_t i = 0; i < size; ++i)
     136            new (&buffer[i]) Entry();
    114137    }
    115138};
Note: See TracChangeset for help on using the changeset viewer.