Changeset 54701 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Feb 11, 2010, 9:01:07 PM (15 years ago)
Author:
[email protected]
Message:

2010-02-11 Geoffrey Garen <[email protected]>

Reviewed by Oliver Hunt and Darin Adler.

The rest of the fix for
https://bugs.webkit.org/show_bug.cgi?id=34864 | <rdar://problem/7594198>
Many objects left uncollected after visiting mail.google.com and closing
window


Don't unconditionally hang onto small strings. Instead, hang onto all
small strings as long as any small string is still referenced.


SunSpider reports no change.

  • runtime/Collector.cpp: (JSC::Heap::markRoots): Mark the small strings cache last, so it can check if anything else has kept any strings alive.
  • runtime/SmallStrings.cpp: (JSC::isMarked): (JSC::SmallStrings::markChildren): Only keep our strings alive if some other reference to at least one of them exists, too.
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r54696 r54701  
     12010-02-11  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Oliver Hunt and Darin Adler.
     4
     5        The rest of the fix for
     6        https://bugs.webkit.org/show_bug.cgi?id=34864 | <rdar://problem/7594198>
     7        Many objects left uncollected after visiting mail.google.com and closing
     8        window
     9       
     10        Don't unconditionally hang onto small strings. Instead, hang onto all
     11        small strings as long as any small string is still referenced.
     12       
     13        SunSpider reports no change.
     14
     15        * runtime/Collector.cpp:
     16        (JSC::Heap::markRoots): Mark the small strings cache last, so it can
     17        check if anything else has kept any strings alive.
     18
     19        * runtime/SmallStrings.cpp:
     20        (JSC::isMarked):
     21        (JSC::SmallStrings::markChildren): Only keep our strings alive if some
     22        other reference to at least one of them exists, too.
     23
    1242010-02-11  Geoffrey Garen  <[email protected]>
    225
  • trunk/JavaScriptCore/runtime/Collector.cpp

    r54672 r54701  
    11231123    if (m_globalData->exception)
    11241124        markStack.append(m_globalData->exception);
    1125     m_globalData->smallStrings.markChildren(markStack);
    11261125    if (m_globalData->functionCodeBlockBeingReparsed)
    11271126        m_globalData->functionCodeBlockBeingReparsed->markAggregate(markStack);
    11281127    if (m_globalData->firstStringifierToMark)
    11291128        JSONObject::markStringifiers(markStack, m_globalData->firstStringifierToMark);
     1129
     1130    // Mark the small strings cache last, since it will clear itself if nothing
     1131    // else has marked it.
     1132    m_globalData->smallStrings.markChildren(markStack);
    11301133
    11311134    markStack.drain();
  • trunk/JavaScriptCore/runtime/SmallStrings.cpp

    r54574 r54701  
    3535static const unsigned numCharactersToStore = 0x100;
    3636
     37static inline bool isMarked(JSString* string)
     38{
     39    return string && Heap::isCellMarked(string);
     40}
     41
    3742class SmallStringsStorage : public Noncopyable {
    3843public:
     
    6772void SmallStrings::markChildren(MarkStack& markStack)
    6873{
     74    /*
     75       Our hypothesis is that small strings are very common. So, we cache them
     76       to avoid GC churn. However, in cases where this hypothesis turns out to
     77       be false -- including the degenerate case where all JavaScript execution
     78       has terminated -- we don't want to waste memory.
     79
     80       To test our hypothesis, we check if any small string has been marked. If
     81       so, it's probably reasonable to mark the rest. If not, we clear the cache.
     82     */
     83
     84    bool isAnyStringMarked = isMarked(m_emptyString);
     85    for (unsigned i = 0; i < numCharactersToStore && !isAnyStringMarked; ++i)
     86        isAnyStringMarked |= isMarked(m_singleCharacterStrings[i]);
     87   
     88    if (!isAnyStringMarked) {
     89        clear();
     90        return;
     91    }
     92   
    6993    if (m_emptyString)
    7094        markStack.append(m_emptyString);
Note: See TracChangeset for help on using the changeset viewer.