Ignore:
Timestamp:
May 26, 2011, 4:39:22 PM (14 years ago)
Author:
[email protected]
Message:

2011-05-26 Geoffrey Garen <[email protected]>

Reviewed by Oliver Hunt.

Removed some interdependency between Heap and SmallStrings by simplifying
the SmallStrings lifetime model
https://bugs.webkit.org/show_bug.cgi?id=61579


SunSpider reports no change.


Using Weak<T> could accomplish this too, but we're not sure it will give
us the performance we need. This is a first step, and it accomplishes
most of the value of using Weak<T>.

  • heap/Heap.cpp: (JSC::Heap::destroy): (JSC::Heap::markRoots): (JSC::Heap::reset): Finalize small strings just like other weak handles.
  • runtime/SmallStrings.cpp: (JSC::finalize): (JSC::SmallStrings::finalizeSmallStrings):
  • runtime/SmallStrings.h: Make all small strings trivially weak, instead of having an "all for one, one for all" memory model.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/SmallStrings.cpp

    r87230 r87448  
    3535namespace JSC {
    3636
    37 static inline bool isMarked(JSCell* string)
     37static inline void finalize(JSString*& string)
    3838{
    39     return string && Heap::isMarked(string);
     39    if (!string || Heap::isMarked(string))
     40        return;
     41    string = 0;
    4042}
    4143
     
    7678}
    7779
    78 void SmallStrings::visitChildren(HeapRootVisitor& heapRootMarker)
     80void SmallStrings::finalizeSmallStrings()
    7981{
    80     /*
    81        Our hypothesis is that small strings are very common. So, we cache them
    82        to avoid GC churn. However, in cases where this hypothesis turns out to
    83        be false -- including the degenerate case where all JavaScript execution
    84        has terminated -- we don't want to waste memory.
    85 
    86        To test our hypothesis, we check if any small string has been marked. If
    87        so, it's probably reasonable to mark the rest. If not, we clear the cache.
    88      */
    89 
    90     bool isAnyStringMarked = isMarked(m_emptyString);
    91     for (unsigned i = 0; i < singleCharacterStringCount && !isAnyStringMarked; ++i)
    92         isAnyStringMarked = isMarked(m_singleCharacterStrings[i]);
    93    
    94     if (!isAnyStringMarked) {
    95         clear();
    96         return;
    97     }
    98    
    99     if (m_emptyString)
    100         heapRootMarker.mark(&m_emptyString);
    101     for (unsigned i = 0; i < singleCharacterStringCount; ++i) {
    102         if (m_singleCharacterStrings[i])
    103             heapRootMarker.mark(&m_singleCharacterStrings[i]);
    104     }
     82    finalize(m_emptyString);
     83    for (unsigned i = 0; i < singleCharacterStringCount; ++i)
     84        finalize(m_singleCharacterStrings[i]);
    10585}
    10686
Note: See TracChangeset for help on using the changeset viewer.