Changeset 87448 in webkit


Ignore:
Timestamp:
May 26, 2011 4:39:22 PM (13 years ago)
Author:
ggaren@apple.com
Message:

2011-05-26 Geoffrey Garen <ggaren@apple.com>

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.
Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r87445 r87448  
     12011-05-26  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Removed some interdependency between Heap and SmallStrings by simplifying
     6        the SmallStrings lifetime model
     7        https://bugs.webkit.org/show_bug.cgi?id=61579
     8       
     9        SunSpider reports no change.
     10       
     11        Using Weak<T> could accomplish this too, but we're not sure it will give
     12        us the performance we need. This is a first step, and it accomplishes
     13        most of the value of using Weak<T>.
     14
     15        * heap/Heap.cpp:
     16        (JSC::Heap::destroy):
     17        (JSC::Heap::markRoots):
     18        (JSC::Heap::reset): Finalize small strings just like other weak handles.
     19
     20        * runtime/SmallStrings.cpp:
     21        (JSC::finalize):
     22        (JSC::SmallStrings::finalizeSmallStrings):
     23        * runtime/SmallStrings.h: Make all small strings trivially weak, instead
     24        of having an "all for one, one for all" memory model.
     25
    1262011-05-26  Oliver Hunt  <oliver@apple.com>
    227
  • trunk/Source/JavaScriptCore/heap/Heap.cpp

    r87434 r87448  
    107107    m_markedSpace.clearMarks();
    108108    m_handleHeap.finalizeWeakHandles();
     109    m_globalData->smallStrings.finalizeSmallStrings();
    109110    m_markedSpace.destroy();
    110111
     
    260261    visitor.drain();
    261262
    262     // Mark the small strings cache as late as possible, since it will clear
    263     // itself if nothing else has marked it.
    264     // FIXME: Change the small strings cache to use Weak<T>.
    265     m_globalData->smallStrings.visitChildren(heapRootMarker);
    266     visitor.drain();
    267    
    268263    // Weak handles must be marked last, because their owners use the set of
    269264    // opaque roots to determine reachability.
     
    409404    markRoots();
    410405    m_handleHeap.finalizeWeakHandles();
     406    m_globalData->smallStrings.finalizeSmallStrings();
    411407
    412408    JAVASCRIPTCORE_GC_MARKED();
  • 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
  • trunk/Source/JavaScriptCore/runtime/SmallStrings.h

    r86209 r87448  
    6464        StringImpl* singleCharacterStringRep(unsigned char character);
    6565
    66         void visitChildren(HeapRootVisitor&);
     66        void finalizeSmallStrings();
    6767        void clear();
    6868
Note: See TracChangeset for help on using the changeset viewer.