Changeset 147150 in webkit


Ignore:
Timestamp:
Mar 28, 2013 1:21:08 PM (11 years ago)
Author:
mhahnenberg@apple.com
Message:

Safari hangs during test262 run in CodeCache::pruneSlowCase
https://bugs.webkit.org/show_bug.cgi?id=113469

Reviewed by Geoffrey Garen.

We can end up hanging for quite some time if we add a lot of small keys to the CodeCache.
By the time we get around to pruning the cache, we have a potentially tens or hundreds of
thousands of small entries, which can cause a noticeable hang when pruning them.

To fix this issue we added a hard cap to the number of entries in the cache because we
could potentially have to remove every element in the map.

  • runtime/CodeCache.cpp:

(JSC::CodeCacheMap::pruneSlowCase): We need to prune until we're both under the hard cap and the
capacity in bytes.

  • runtime/CodeCache.h:

(CodeCacheMap):
(JSC::CodeCacheMap::numberOfEntries): Convenience accessor function to the number of entries in
the map that does the cast to size_t of m_map.size() for us.
(JSC::CodeCacheMap::canPruneQuickly): Checks that the total number is under the hard cap. We put this
check inside a function to more accurately describe why we're doing the check and to abstract out
the actual calculation in case we want to coalesce calls to pruneSlowCase in the future.
(JSC::CodeCacheMap::prune): Check the number of entries against our hard cap. If it's greater than
the cap then we need to drop down to pruneSlowCase.

Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r147079 r147150  
     12013-03-28  Mark Hahnenberg  <mhahnenberg@apple.com>
     2
     3        Safari hangs during test262 run in CodeCache::pruneSlowCase
     4        https://bugs.webkit.org/show_bug.cgi?id=113469
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        We can end up hanging for quite some time if we add a lot of small keys to the CodeCache.
     9        By the time we get around to pruning the cache, we have a potentially tens or hundreds of
     10        thousands of small entries, which can cause a noticeable hang when pruning them.
     11
     12        To fix this issue we added a hard cap to the number of entries in the cache because we
     13        could potentially have to remove every element in the map.
     14
     15        * runtime/CodeCache.cpp:
     16        (JSC::CodeCacheMap::pruneSlowCase): We need to prune until we're both under the hard cap and the
     17        capacity in bytes.
     18        * runtime/CodeCache.h:
     19        (CodeCacheMap):
     20        (JSC::CodeCacheMap::numberOfEntries): Convenience accessor function to the number of entries in
     21        the map that does the cast to size_t of m_map.size() for us.
     22        (JSC::CodeCacheMap::canPruneQuickly): Checks that the total number is under the hard cap. We put this
     23        check inside a function to more accurately describe why we're doing the check and to abstract out
     24        the actual calculation in case we want to coalesce calls to pruneSlowCase in the future.
     25        (JSC::CodeCacheMap::prune): Check the number of entries against our hard cap. If it's greater than
     26        the cap then we need to drop down to pruneSlowCase.
     27
    1282013-03-28  Zan Dobersek  <zdobersek@igalia.com>
    229
  • trunk/Source/JavaScriptCore/runtime/CodeCache.cpp

    r147079 r147150  
    4848        m_capacity = m_minCapacity;
    4949
    50     while (m_size > m_capacity) {
     50    while (m_size > m_capacity || !canPruneQuickly()) {
    5151        MapType::iterator it = m_map.begin();
    5252        m_size -= it->key.length();
  • trunk/Source/JavaScriptCore/runtime/CodeCache.h

    r145171 r147150  
    197197    // working set to enter the cache before it starts evicting.
    198198    static const double workingSetTime;
    199     static const int64_t workingSetMax = 16000000;
     199    static const int64_t workingSetMaxBytes = 16000000;
     200    static const size_t workingSetMaxEntries = 2000;
    200201
    201202    // This constant factor biases cache capacity toward recent activity. We
     
    208209    static const int64_t oldObjectSamplingMultiplier = 32;
    209210
     211    size_t numberOfEntries() const { return static_cast<size_t>(m_map.size()); }
     212    bool canPruneQuickly() const { return numberOfEntries() < workingSetMaxEntries; }
     213
    210214    void pruneSlowCase();
    211215    void prune()
    212216    {
    213         if (m_size <= m_capacity)
     217        if (m_size <= m_capacity && canPruneQuickly())
    214218            return;
    215219
    216220        if (monotonicallyIncreasingTime() - m_timeAtLastPrune < workingSetTime
    217             && m_size - m_sizeAtLastPrune < workingSetMax)
     221            && m_size - m_sizeAtLastPrune < workingSetMaxBytes
     222            && canPruneQuickly())
    218223                return;
    219224
Note: See TracChangeset for help on using the changeset viewer.