Changeset 54696 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Feb 11, 2010, 6:51:35 PM (15 years ago)
Author:
[email protected]
Message:

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

Reviewed by Gavin Barraclough.

Some progress toward fixing
https://bugs.webkit.org/show_bug.cgi?id=34864 | <rdar://problem/7594198>
Many objects left uncollected after visiting mail.google.com and closing
window


SunSpider reports no change.


Keep weak references, rather than protected references, to cached for-in
property name enumerators.


One problem with protected references is that a chain like

[ gc object 1 ] => [ non-gc object ] => [ gc object 2 ]

takes two GC passes to break, since the first pass collects [ gc object 1 ],
releasing [ non-gc object ] and unprotecting [ gc object 2 ], and only
then can a second pass collect [ gc object 2 ].


Another problem with protected references is that they can keep a bunch
of strings alive long after they're useful. In SunSpider and a few popular
websites, the size-speed tradeoff seems to favor weak references.

  • runtime/JSPropertyNameIterator.cpp: (JSC::JSPropertyNameIterator::JSPropertyNameIterator): Moved this constructor into the .cpp file, since it's not used elsewhere.

(JSC::JSPropertyNameIterator::~JSPropertyNameIterator): Added a destructor
to support our weak reference.

  • runtime/JSPropertyNameIterator.h: (JSC::Structure::setEnumerationCache): (JSC::Structure::clearEnumerationCache): (JSC::Structure::enumerationCache): Added a function for clearing a Structure's enumeration cache, used by our new destructor. Also fixed indentation to match the rest of the file.
  • runtime/Structure.h: Changed from protected pointer to weak pointer.
Location:
trunk/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r54684 r54696  
     12010-02-11  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Gavin Barraclough.
     4
     5        Some progress toward fixing
     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        SunSpider reports no change.
     11       
     12        Keep weak references, rather than protected references, to cached for-in
     13        property name enumerators.
     14       
     15        One problem with protected references is that a chain like
     16            [ gc object 1 ] => [ non-gc object ] => [ gc object 2 ]
     17        takes two GC passes to break, since the first pass collects [ gc object 1 ],
     18        releasing [ non-gc object ] and unprotecting [ gc object 2 ], and only
     19        then can a second pass collect [ gc object 2 ].
     20       
     21        Another problem with protected references is that they can keep a bunch
     22        of strings alive long after they're useful. In SunSpider and a few popular
     23        websites, the size-speed tradeoff seems to favor weak references.
     24
     25        * runtime/JSPropertyNameIterator.cpp:
     26        (JSC::JSPropertyNameIterator::JSPropertyNameIterator): Moved this constructor
     27        into the .cpp file, since it's not used elsewhere.
     28
     29        (JSC::JSPropertyNameIterator::~JSPropertyNameIterator): Added a destructor
     30        to support our weak reference.
     31
     32        * runtime/JSPropertyNameIterator.h:
     33        (JSC::Structure::setEnumerationCache):
     34        (JSC::Structure::clearEnumerationCache):
     35        (JSC::Structure::enumerationCache): Added a function for clearing a
     36        Structure's enumeration cache, used by our new destructor. Also fixed
     37        indentation to match the rest of the file.
     38
     39        * runtime/Structure.h: Changed from protected pointer to weak pointer.
     40
    1412010-02-11  Chris Rogers  <[email protected]>
    242
  • trunk/JavaScriptCore/runtime/JSPropertyNameIterator.cpp

    r51801 r54696  
    3535
    3636ASSERT_CLASS_FITS_IN_CELL(JSPropertyNameIterator);
     37
     38inline JSPropertyNameIterator::JSPropertyNameIterator(ExecState* exec, PropertyNameArrayData* propertyNameArrayData, size_t numCacheableSlots)
     39    : JSCell(exec->globalData().propertyNameIteratorStructure.get())
     40    , m_cachedStructure(0)
     41    , m_numCacheableSlots(numCacheableSlots)
     42    , m_jsStringsSize(propertyNameArrayData->propertyNameVector().size())
     43    , m_jsStrings(new JSValue[m_jsStringsSize])
     44{
     45    PropertyNameArrayData::PropertyNameVector& propertyNameVector = propertyNameArrayData->propertyNameVector();
     46    for (size_t i = 0; i < m_jsStringsSize; ++i)
     47        m_jsStrings[i] = jsOwnedString(exec, propertyNameVector[i].ustring());
     48}
     49
     50JSPropertyNameIterator::~JSPropertyNameIterator()
     51{
     52    if (m_cachedStructure)
     53        m_cachedStructure->clearEnumerationCache(this);
     54}
    3755
    3856JSPropertyNameIterator* JSPropertyNameIterator::create(ExecState* exec, JSObject* o)
  • trunk/JavaScriptCore/runtime/JSPropertyNameIterator.h

    r54022 r54696  
    5050            return Structure::create(prototype, TypeInfo(CompoundType, OverridesMarkChildren), AnonymousSlotCount);
    5151        }
     52       
     53        virtual ~JSPropertyNameIterator();
    5254
    5355        virtual bool isPropertyNameIterator() const { return true; }
     
    8284    };
    8385
    84 inline JSPropertyNameIterator::JSPropertyNameIterator(ExecState* exec, PropertyNameArrayData* propertyNameArrayData, size_t numCacheableSlots)
    85     : JSCell(exec->globalData().propertyNameIteratorStructure.get())
    86     , m_cachedStructure(0)
    87     , m_numCacheableSlots(numCacheableSlots)
    88     , m_jsStringsSize(propertyNameArrayData->propertyNameVector().size())
    89     , m_jsStrings(new JSValue[m_jsStringsSize])
    90 {
    91     PropertyNameArrayData::PropertyNameVector& propertyNameVector = propertyNameArrayData->propertyNameVector();
    92     for (size_t i = 0; i < m_jsStringsSize; ++i)
    93         m_jsStrings[i] = jsOwnedString(exec, propertyNameVector[i].ustring());
    94 }
     86    inline void Structure::setEnumerationCache(JSPropertyNameIterator* enumerationCache)
     87    {
     88        ASSERT(!isDictionary());
     89        m_enumerationCache = enumerationCache;
     90    }
    9591
    96 inline void Structure::setEnumerationCache(JSPropertyNameIterator* enumerationCache)
    97 {
    98     ASSERT(!isDictionary());
    99     m_enumerationCache = enumerationCache;
    100 }
     92    inline void Structure::clearEnumerationCache(JSPropertyNameIterator* enumerationCache)
     93    {
     94        m_enumerationCache.clear(enumerationCache);
     95    }
     96
     97    inline JSPropertyNameIterator* Structure::enumerationCache()
     98    {
     99        return m_enumerationCache.get();
     100    }
    101101
    102102} // namespace JSC
  • trunk/JavaScriptCore/runtime/Structure.h

    r54520 r54696  
    3737#include "JSTypeInfo.h"
    3838#include "UString.h"
     39#include "WeakGCPtr.h"
    3940#include <wtf/PassRefPtr.h>
    4041#include <wtf/RefCounted.h>
     
    136137
    137138        void setEnumerationCache(JSPropertyNameIterator* enumerationCache); // Defined in JSPropertyNameIterator.h.
    138         JSPropertyNameIterator* enumerationCache() { return m_enumerationCache.get(); }
     139        void clearEnumerationCache(JSPropertyNameIterator* enumerationCache); // Defined in JSPropertyNameIterator.h.
     140        JSPropertyNameIterator* enumerationCache(); // Defined in JSPropertyNameIterator.h.
    139141        void getPropertyNames(PropertyNameArray&, EnumerationMode mode);
    140142       
     
    200202        StructureTransitionTable table;
    201203
    202         ProtectedPtr<JSPropertyNameIterator> m_enumerationCache;
     204        WeakGCPtr<JSPropertyNameIterator> m_enumerationCache;
    203205
    204206        PropertyMapHashTable* m_propertyTable;
Note: See TracChangeset for help on using the changeset viewer.