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):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.