Changeset 64849 in webkit


Ignore:
Timestamp:
Aug 6, 2010, 7:55:54 AM (15 years ago)
Author:
[email protected]
Message:

2010-08-06 Nathan Lawrence <[email protected]>

Reviewed by Geoffrey Garen.

https://bugs.webkit.org/show_bug.cgi?id=43207

WeakGCPtr's should instead of directly pointing to the GC'd object
should be directed to an array of pointers that can be updated for
movable objects.

  • Android.mk:
  • GNUmakefile.am:
  • JavaScriptCore.exp:
  • JavaScriptCore.gypi:
  • JavaScriptCore.pro:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • runtime/Collector.cpp: (JSC::Heap::destroy): (JSC::Heap::allocateBlock): (JSC::Heap::freeBlock): (JSC::Heap::updateWeakGCHandles): (JSC::WeakGCHandlePool::update): (JSC::Heap::addWeakGCHandle): (JSC::Heap::markRoots):
  • runtime/Collector.h: (JSC::Heap::weakGCHandlePool):
  • runtime/GCHandle.cpp: Added. (JSC::WeakGCHandle::pool): (JSC::WeakGCHandlePool::WeakGCHandlePool): (JSC::WeakGCHandlePool::allocate): (JSC::WeakGCHandlePool::free): (JSC::WeakGCHandlePool::operator new):
  • runtime/GCHandle.h: Added. (JSC::WeakGCHandle::isValidPtr): (JSC::WeakGCHandle::isPtr): (JSC::WeakGCHandle::isNext): (JSC::WeakGCHandle::invalidate): (JSC::WeakGCHandle::get): (JSC::WeakGCHandle::set): (JSC::WeakGCHandle::getNextInFreeList): (JSC::WeakGCHandle::setNextInFreeList): (JSC::WeakGCHandlePool::isFull):
  • runtime/WeakGCPtr.h: (JSC::WeakGCPtr::WeakGCPtr): (JSC::WeakGCPtr::~WeakGCPtr): (JSC::WeakGCPtr::get): (JSC::WeakGCPtr::clear): (JSC::WeakGCPtr::assign): (JSC::get):
Location:
trunk/JavaScriptCore
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/Android.mk

    r64106 r64849  
    9797        runtime/FunctionConstructor.cpp \
    9898        runtime/FunctionPrototype.cpp \
     99        runtime/GCHandle.cpp \
    99100        runtime/GetterSetter.cpp \
    100101        runtime/GlobalEvalFunction.cpp \
  • trunk/JavaScriptCore/ChangeLog

    r64842 r64849  
     12010-08-06  Nathan Lawrence  <[email protected]>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=43207
     6
     7        WeakGCPtr's should instead of directly pointing to the GC'd object
     8        should be directed to an array of pointers that can be updated for
     9        movable objects.
     10
     11        * Android.mk:
     12        * GNUmakefile.am:
     13        * JavaScriptCore.exp:
     14        * JavaScriptCore.gypi:
     15        * JavaScriptCore.pro:
     16        * JavaScriptCore.xcodeproj/project.pbxproj:
     17        * runtime/Collector.cpp:
     18        (JSC::Heap::destroy):
     19        (JSC::Heap::allocateBlock):
     20        (JSC::Heap::freeBlock):
     21        (JSC::Heap::updateWeakGCHandles):
     22        (JSC::WeakGCHandlePool::update):
     23        (JSC::Heap::addWeakGCHandle):
     24        (JSC::Heap::markRoots):
     25        * runtime/Collector.h:
     26        (JSC::Heap::weakGCHandlePool):
     27        * runtime/GCHandle.cpp: Added.
     28        (JSC::WeakGCHandle::pool):
     29        (JSC::WeakGCHandlePool::WeakGCHandlePool):
     30        (JSC::WeakGCHandlePool::allocate):
     31        (JSC::WeakGCHandlePool::free):
     32        (JSC::WeakGCHandlePool::operator new):
     33        * runtime/GCHandle.h: Added.
     34        (JSC::WeakGCHandle::isValidPtr):
     35        (JSC::WeakGCHandle::isPtr):
     36        (JSC::WeakGCHandle::isNext):
     37        (JSC::WeakGCHandle::invalidate):
     38        (JSC::WeakGCHandle::get):
     39        (JSC::WeakGCHandle::set):
     40        (JSC::WeakGCHandle::getNextInFreeList):
     41        (JSC::WeakGCHandle::setNextInFreeList):
     42        (JSC::WeakGCHandlePool::isFull):
     43        * runtime/WeakGCPtr.h:
     44        (JSC::WeakGCPtr::WeakGCPtr):
     45        (JSC::WeakGCPtr::~WeakGCPtr):
     46        (JSC::WeakGCPtr::get):
     47        (JSC::WeakGCPtr::clear):
     48        (JSC::WeakGCPtr::assign):
     49        (JSC::get):
     50
    1512010-08-06  Tor Arne Vestbø  <[email protected]>
    252
  • trunk/JavaScriptCore/GNUmakefile.am

    r64759 r64849  
    269269        JavaScriptCore/runtime/GCActivityCallback.cpp \
    270270        JavaScriptCore/runtime/GCActivityCallback.h \
     271        JavaScriptCore/runtime/GCHandle.cpp \
     272        JavaScriptCore/runtime/GCHandle.h \
    271273        JavaScriptCore/runtime/GetterSetter.cpp \
    272274        JavaScriptCore/runtime/GetterSetter.h \
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r64585 r64849  
    142142__ZN3JSC12StringObject4infoE
    143143__ZN3JSC12StringObjectC2EPNS_9ExecStateEN3WTF17NonNullPassRefPtrINS_9StructureEEERKNS_7UStringE
     144__ZN3JSC12WeakGCHandle4poolEv
    144145__ZN3JSC12jsNumberCellEPNS_9ExecStateEd
    145146__ZN3JSC12nonInlineNaNEv
     
    172173__ZN3JSC16JSVariableObject14symbolTableGetERKNS_10IdentifierERNS_18PropertyDescriptorE
    173174__ZN3JSC16JSVariableObject19getOwnPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayENS_15EnumerationModeE
     175__ZN3JSC16WeakGCHandlePool4freeEPNS_12WeakGCHandleE
    174176__ZN3JSC16createRangeErrorEPNS_9ExecStateERKNS_7UStringE
    175177__ZN3JSC16throwSyntaxErrorEPNS_9ExecStateE
     
    202204__ZN3JSC3NaNE
    203205__ZN3JSC4Heap14primaryHeapEndEv
     206__ZN3JSC4Heap15addWeakGCHandleEPNS_6JSCellE
    204207__ZN3JSC4Heap15recordExtraCostEm
    205208__ZN3JSC4Heap16objectTypeCountsEv
  • trunk/JavaScriptCore/JavaScriptCore.gypi

    r64696 r64849  
    218218            'runtime/GCActivityCallback.cpp',
    219219            'runtime/GCActivityCallback.h',
     220            'runtime/GCHandle.cpp',
     221            'runtime/GCHandle.h',
    220222            'runtime/GetterSetter.cpp',
    221223            'runtime/GetterSetter.h',
  • trunk/JavaScriptCore/JavaScriptCore.pro

    r64624 r64849  
    141141    runtime/FunctionPrototype.cpp \
    142142    runtime/GCActivityCallback.cpp \
     143    runtime/GCHandle.cpp \
    143144    runtime/GetterSetter.cpp \
    144145    runtime/GlobalEvalFunction.cpp \
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r64801 r64849  
    513513                DD2724691208D1FF00F9ABE7 /* AlignedMemoryAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = DD2724671208D1FF00F9ABE7 /* AlignedMemoryAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
    514514                DD377CBC12072C18006A2517 /* Bitmap.h in Headers */ = {isa = PBXBuildFile; fileRef = DD377CBB12072C18006A2517 /* Bitmap.h */; settings = {ATTRIBUTES = (Private, ); }; };
     515                DDE82AD31209D955005C1756 /* GCHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDE82AD11209D955005C1756 /* GCHandle.cpp */; };
     516                DDE82AD41209D955005C1756 /* GCHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDE82AD11209D955005C1756 /* GCHandle.cpp */; };
     517                DDE82AD51209D955005C1756 /* GCHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDE82AD11209D955005C1756 /* GCHandle.cpp */; };
     518                DDE82AD61209D955005C1756 /* GCHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = DDE82AD21209D955005C1756 /* GCHandle.h */; };
     519                DDE82AD71209D955005C1756 /* GCHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDE82AD11209D955005C1756 /* GCHandle.cpp */; };
     520                DDE82AD81209D955005C1756 /* GCHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = DDE82AD21209D955005C1756 /* GCHandle.h */; settings = {ATTRIBUTES = (Private, ); }; };
    515521                DDF7ABD411F60ED200108E36 /* GCActivityCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = DDF7ABD211F60ED200108E36 /* GCActivityCallback.h */; };
    516522                DDF7ABD511F60ED200108E36 /* GCActivityCallbackCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDF7ABD311F60ED200108E36 /* GCActivityCallbackCF.cpp */; };
     
    10591065                DD2724671208D1FF00F9ABE7 /* AlignedMemoryAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AlignedMemoryAllocator.h; sourceTree = "<group>"; };
    10601066                DD377CBB12072C18006A2517 /* Bitmap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Bitmap.h; sourceTree = "<group>"; };
     1067                DDE82AD11209D955005C1756 /* GCHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GCHandle.cpp; sourceTree = "<group>"; };
     1068                DDE82AD21209D955005C1756 /* GCHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCHandle.h; sourceTree = "<group>"; };
    10611069                DDF7ABD211F60ED200108E36 /* GCActivityCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCActivityCallback.h; sourceTree = "<group>"; };
    10621070                DDF7ABD311F60ED200108E36 /* GCActivityCallbackCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GCActivityCallbackCF.cpp; sourceTree = "<group>"; };
     
    16251633                                F692A85C0255597D01FF60F7 /* FunctionPrototype.cpp */,
    16261634                                F692A85D0255597D01FF60F7 /* FunctionPrototype.h */,
     1635                                DDE82AD11209D955005C1756 /* GCHandle.cpp */,
     1636                                DDE82AD21209D955005C1756 /* GCHandle.h */,
    16271637                                BC02E9B80E184545000F9297 /* GetterSetter.cpp */,
    16281638                                BC337BDE0E1AF0B80076918A /* GetterSetter.h */,
     
    19131923                                1440074A0A536CC20005F061 /* NodeList.h in Headers */,
    19141924                                DD2724681208D1FF00F9ABE7 /* AlignedMemoryAllocator.h in Headers */,
     1925                                DDE82AD61209D955005C1756 /* GCHandle.h in Headers */,
    19151926                        );
    19161927                        runOnlyForDeploymentPostprocessing = 0;
     
    22152226                                DDF7ABD411F60ED200108E36 /* GCActivityCallback.h in Headers */,
    22162227                                DD2724691208D1FF00F9ABE7 /* AlignedMemoryAllocator.h in Headers */,
     2228                                DDE82AD81209D955005C1756 /* GCHandle.h in Headers */,
    22172229                        );
    22182230                        runOnlyForDeploymentPostprocessing = 0;
     
    24762488                                1440063F0A53598A0005F061 /* Node.c in Sources */,
    24772489                                1440074B0A536CC20005F061 /* NodeList.c in Sources */,
     2490                                DDE82AD51209D955005C1756 /* GCHandle.cpp in Sources */,
    24782491                        );
    24792492                        runOnlyForDeploymentPostprocessing = 0;
     
    24842497                        files = (
    24852498                                1440F6100A4F85670005F061 /* testapi.c in Sources */,
     2499                                DDE82AD41209D955005C1756 /* GCHandle.cpp in Sources */,
    24862500                        );
    24872501                        runOnlyForDeploymentPostprocessing = 0;
     
    26632677                                DDF7ABD511F60ED200108E36 /* GCActivityCallbackCF.cpp in Sources */,
    26642678                                8627E5EB11F1281900A313B5 /* PageAllocation.cpp in Sources */,
     2679                                DDE82AD71209D955005C1756 /* GCHandle.cpp in Sources */,
    26652680                        );
    26662681                        runOnlyForDeploymentPostprocessing = 0;
     
    26712686                        files = (
    26722687                                932F5BDD0822A1C700736975 /* jsc.cpp in Sources */,
     2688                                DDE82AD31209D955005C1756 /* GCHandle.cpp in Sources */,
    26732689                        );
    26742690                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/JavaScriptCore/runtime/Collector.cpp

    r64695 r64849  
    171171    freeBlocks();
    172172
     173    for (unsigned i = 0; i < m_weakGCHandlePools.size(); ++i)
     174        m_weakGCHandlePools[i].deallocate();
     175
    173176#if ENABLE(JSC_MULTIPLE_THREADS)
    174177    if (m_currentThreadRegistrar) {
     
    190193NEVER_INLINE CollectorBlock* Heap::allocateBlock()
    191194{
    192     AlignedBlock allocation = m_blockallocator.allocate();
     195    AlignedCollectorBlock allocation = m_blockallocator.allocate();
    193196    CollectorBlock* block = static_cast<CollectorBlock*>(allocation.base());
    194197    if (!block)
     
    208211    size_t numBlocks = m_heap.numBlocks;
    209212    if (m_heap.usedBlocks == numBlocks) {
    210         static const size_t maxNumBlocks = ULONG_MAX / sizeof(AlignedBlock) / GROWTH_FACTOR;
     213        static const size_t maxNumBlocks = ULONG_MAX / sizeof(AlignedCollectorBlock) / GROWTH_FACTOR;
    211214        if (numBlocks > maxNumBlocks)
    212215            CRASH();
    213216        numBlocks = max(MIN_ARRAY_SIZE, numBlocks * GROWTH_FACTOR);
    214217        m_heap.numBlocks = numBlocks;
    215         m_heap.blocks = static_cast<AlignedBlock*>(fastRealloc(m_heap.blocks, numBlocks * sizeof(AlignedBlock)));
     218        m_heap.blocks = static_cast<AlignedCollectorBlock*>(fastRealloc(m_heap.blocks, numBlocks * sizeof(AlignedCollectorBlock)));
    216219    }
    217220    m_heap.blocks[m_heap.usedBlocks++] = allocation;
     
    236239    if (m_heap.numBlocks > MIN_ARRAY_SIZE && m_heap.usedBlocks < m_heap.numBlocks / LOW_WATER_FACTOR) {
    237240        m_heap.numBlocks = m_heap.numBlocks / GROWTH_FACTOR;
    238         m_heap.blocks = static_cast<AlignedBlock*>(fastRealloc(m_heap.blocks, m_heap.numBlocks * sizeof(AlignedBlock)));
     241        m_heap.blocks = static_cast<AlignedCollectorBlock*>(fastRealloc(m_heap.blocks, m_heap.numBlocks * sizeof(AlignedCollectorBlock)));
    239242    }
    240243}
     
    907910}
    908911
     912void Heap::updateWeakGCHandles()
     913{
     914    for (unsigned i = 0; i < m_weakGCHandlePools.size(); ++i)
     915        weakGCHandlePool(i)->update();
     916}
     917
     918void WeakGCHandlePool::update()
     919{
     920    for (unsigned i = 1; i < WeakGCHandlePool::numPoolEntries; ++i) {
     921        if (m_entries[i].isValidPtr()) {
     922            JSCell* cell = m_entries[i].get();
     923            if (!cell || !Heap::isCellMarked(cell))
     924                m_entries[i].invalidate();
     925        }
     926    }
     927}
     928
     929WeakGCHandle* Heap::addWeakGCHandle(JSCell* ptr)
     930{
     931    for (unsigned i = 0; i < m_weakGCHandlePools.size(); ++i)
     932        if (!weakGCHandlePool(i)->isFull())
     933            return weakGCHandlePool(i)->allocate(ptr);
     934
     935    AlignedMemory<WeakGCHandlePool::poolSize> allocation = m_weakGCHandlePoolAllocator.allocate();
     936    m_weakGCHandlePools.append(allocation);
     937
     938    WeakGCHandlePool* pool = new (allocation) WeakGCHandlePool();
     939    return pool->allocate(ptr);
     940}
     941
    909942void Heap::protect(JSValue k)
    910943{
     
    10431076    markStack.compact();
    10441077
     1078    updateWeakGCHandles();
     1079
    10451080    m_heap.operationInProgress = NoOperation;
    10461081}
  • trunk/JavaScriptCore/runtime/Collector.h

    r64695 r64849  
    2424
    2525#include "AlignedMemoryAllocator.h"
     26#include "GCHandle.h"
    2627#include <stddef.h>
    2728#include <string.h>
     
    6364#endif
    6465
    65     typedef AlignedMemoryAllocator<BLOCK_SIZE> AlignedAllocator;
    66     typedef AlignedMemory<BLOCK_SIZE> AlignedBlock;
     66    typedef AlignedMemoryAllocator<BLOCK_SIZE> CollectorBlockAllocator;
     67    typedef AlignedMemory<BLOCK_SIZE> AlignedCollectorBlock;
    6768
    6869    struct CollectorHeap {
    6970        size_t nextBlock;
    7071        size_t nextCell;
    71         AlignedBlock* blocks;
     72        AlignedCollectorBlock* blocks;
    7273       
    7374        void* nextNumber;
     
    131132        static bool isCellMarked(const JSCell*);
    132133        static void markCell(JSCell*);
     134
     135        WeakGCHandle* addWeakGCHandle(JSCell*);
    133136
    134137        void markConservatively(MarkStack&, void* start, void* end);
     
    173176        void markStackObjectsConservatively(MarkStack&);
    174177
     178        void updateWeakGCHandles();
     179        WeakGCHandlePool* weakGCHandlePool(size_t index);
     180
    175181        typedef HashCountedSet<JSCell*> ProtectCountSet;
    176182
     
    178184
    179185        ProtectCountSet m_protectedValues;
     186        WTF::Vector<AlignedMemory<WeakGCHandlePool::poolSize> > m_weakGCHandlePools;
    180187
    181188        HashSet<MarkedArgumentBuffer*>* m_markListSet;
     
    195202
    196203        // Allocates collector blocks with correct alignment
    197         AlignedAllocator m_blockallocator;
     204        CollectorBlockAllocator m_blockallocator;
     205        WeakGCHandlePool::Allocator m_weakGCHandlePoolAllocator;
    198206       
    199207        JSGlobalData* m_globalData;
     
    303311        return result;
    304312    }
     313
     314
     315    inline WeakGCHandlePool* Heap::weakGCHandlePool(size_t index)
     316    {
     317        return static_cast<WeakGCHandlePool*>(m_weakGCHandlePools[index].base());
     318    }
    305319} // namespace JSC
    306320
  • trunk/JavaScriptCore/runtime/WeakGCPtr.h

    r58267 r64849  
    2828
    2929#include "Collector.h"
     30#include "GCHandle.h"
    3031#include <wtf/Noncopyable.h>
    3132
     
    3536template <typename T> class WeakGCPtr : Noncopyable {
    3637public:
    37     WeakGCPtr() : m_ptr(0) { }
     38    WeakGCPtr()
     39        : m_ptr(0)
     40    {
     41    }
     42
    3843    WeakGCPtr(T* ptr) { assign(ptr); }
     44
     45    ~WeakGCPtr()
     46    {
     47        if (m_ptr)
     48            m_ptr->pool()->free(m_ptr);
     49    }
    3950
    4051    T* get() const
    4152    {
    42         if (!m_ptr || !Heap::isCellMarked(m_ptr))
    43             return 0;
    44         return m_ptr;
     53        if (m_ptr && m_ptr->isValidPtr())
     54            return static_cast<T*>(m_ptr->get());
     55        return 0;
    4556    }
    4657   
    47     bool clear(JSCell* ptr)
     58    bool clear(JSCell* p)
    4859    {
    49         if (ptr == m_ptr) {
    50             m_ptr = 0;
    51             return true;
    52         }
    53         return false;
     60        if (!m_ptr || m_ptr->get() != p)
     61            return false;
     62
     63        m_ptr->pool()->free(m_ptr);
     64        m_ptr = 0;
     65        return true;
    5466    }
    5567
     
    6375    operator bool() const { return m_ptr; }
    6476#else
    65     typedef T* WeakGCPtr::*UnspecifiedBoolType;
     77    typedef WeakGCHandle* WeakGCPtr::*UnspecifiedBoolType;
    6678    operator UnspecifiedBoolType() const { return get() ? &WeakGCPtr::m_ptr : 0; }
    6779#endif
     
    7486
    7587private:
    76     void assign(T* ptr)
     88    void assign(JSCell* ptr)
    7789    {
    7890        ASSERT(ptr);
    79         Heap::markCell(ptr);
    80         m_ptr = ptr;
     91        if (m_ptr)
     92            m_ptr->set(ptr);
     93        else
     94            m_ptr = Heap::heap(ptr)->addWeakGCHandle(ptr);
    8195    }
    8296
    83     T* m_ptr;
     97    WeakGCHandle* m_ptr;
    8498};
    8599
     
    130144}
    131145
    132 template <typename T> inline T* getPtr(const WeakGCPtr<T>& p)
     146template <typename T> inline T* get(const WeakGCPtr<T>& p)
    133147{
    134148    return p.get();
Note: See TracChangeset for help on using the changeset viewer.