Ignore:
Timestamp:
May 24, 2012, 2:18:10 PM (13 years ago)
Author:
[email protected]
Message:

Made WeakSet per-block instead of per-heap
https://bugs.webkit.org/show_bug.cgi?id=87401

Reviewed by Oliver Hunt.

This allows us fast access to the set of all weak pointers for a block,
which is a step toward lazy finalization.

No performance change.

  • heap/Heap.cpp:

(JSC::Heap::Heap):
(JSC::Heap::lastChanceToFinalize): Removed the per-heap weak set, since
it's per-block now.

(JSC::Heap::markRoots): Delegate weak set visiting to the marked space,
since it knows how to iterate all blocks.

(JSC::Heap::collect): Moved the reaping outside of markRoots, since it
doesn't mark anything.

Make sure to reset allocators after shrinking, since shrinking may
deallocate the current allocator.

  • heap/Heap.h:

(Heap): No more per-heap weak set, since it's per-block now.

  • heap/MarkedBlock.cpp:

(JSC::MarkedBlock::MarkedBlock):

  • heap/MarkedBlock.h:

(MarkedBlock):
(JSC::MarkedBlock::lastChanceToFinalize): Migrated finalization logic
here from the heap, so the heap doesn't need to know about our internal
data structures like our weak set.

(JSC::MarkedBlock::heap):
(JSC::MarkedBlock::weakSet):
(JSC::MarkedBlock::shrink):
(JSC::MarkedBlock::resetAllocator):
(JSC::MarkedBlock::visitWeakSet):
(JSC::MarkedBlock::reapWeakSet):
(JSC::MarkedBlock::sweepWeakSet):

  • heap/MarkedSpace.cpp:

(JSC::VisitWeakSet::VisitWeakSet):
(JSC::VisitWeakSet::operator()):
(VisitWeakSet):
(JSC):
(JSC::ReapWeakSet::operator()):
(JSC::SweepWeakSet::operator()):
(JSC::LastChanceToFinalize::operator()):
(JSC::MarkedSpace::lastChanceToFinalize):
(JSC::ResetAllocator::operator()):
(JSC::MarkedSpace::resetAllocators):
(JSC::MarkedSpace::visitWeakSets):
(JSC::MarkedSpace::reapWeakSets):
(JSC::MarkedSpace::sweepWeakSets):
(JSC::Shrink::operator()):
(JSC::MarkedSpace::shrink):

  • heap/MarkedSpace.h:

(MarkedSpace): Make sure to account for our weak sets when sweeping,
shrinking, etc.

  • heap/WeakSet.cpp:

(JSC):

  • heap/WeakSet.h:

(WeakSet):
(JSC::WeakSet::heap):
(JSC):
(JSC::WeakSet::lastChanceToFinalize):
(JSC::WeakSet::visit):
(JSC::WeakSet::reap):
(JSC::WeakSet::shrink):
(JSC::WeakSet::resetAllocator): Inlined some things since they're called
once per block now instead of once per heap.

  • heap/WeakSetInlines.h:

(JSC::WeakSet::allocate): Use the per-block weak set since there is no
per-heap weak set anymore.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/heap/Heap.cpp

    r118269 r118416  
    249249    , m_sharedData(globalData)
    250250    , m_slotVisitor(m_sharedData)
    251     , m_weakSet(this)
    252251    , m_handleSet(globalData)
    253252    , m_isSafeToCollect(false)
     
    279278        WTFLogAlways("ERROR: JavaScriptCore heap deallocated while %ld values were still protected", static_cast<unsigned long>(size));
    280279
    281     m_weakSet.lastChanceToFinalize();
    282280    m_objectSpace.lastChanceToFinalize();
    283281
     
    562560        GCPHASE(VisitingLiveWeakHandles);
    563561        while (true) {
    564             m_weakSet.visit(heapRootVisitor);
     562            m_objectSpace.visitWeakSets(heapRootVisitor);
    565563            harvestWeakReferences();
    566564            if (visitor.isEmpty())
     
    576574    }
    577575
    578     {
    579         GCPHASE(ReapingWeakHandles);
    580         m_weakSet.reap();
    581     }
    582 
    583576    GCCOUNTER(VisitedValueCount, visitor.visitCount());
    584577
     
    684677   
    685678    {
     679        GCPHASE(ReapingWeakHandles);
     680        m_objectSpace.reapWeakSets();
     681    }
     682
     683    {
    686684        GCPHASE(FinalizeUnconditionalFinalizers);
    687685        finalizeUnconditionalFinalizers();
    688686    }
    689        
     687
    690688    {
    691689        GCPHASE(FinalizeWeakHandles);
    692         m_weakSet.sweep();
     690        m_objectSpace.sweepWeakSets();
    693691        m_globalData->smallStrings.finalizeSmallStrings();
    694692    }
     
    696694    JAVASCRIPTCORE_GC_MARKED();
    697695
    698     {
    699         GCPHASE(ResetAllocators);
    700         m_objectSpace.resetAllocators();
    701         m_weakSet.resetAllocator();
    702     }
    703    
    704696    {
    705697        GCPHASE(DeleteCodeBlocks);
     
    712704        m_objectSpace.sweep();
    713705        m_objectSpace.shrink();
    714         m_weakSet.shrink();
    715706        m_bytesAbandoned = 0;
    716707    }
    717708
     709    {
     710        GCPHASE(ResetAllocators);
     711        m_objectSpace.resetAllocators();
     712    }
     713   
    718714    size_t currentHeapSize = size();
    719715    if (fullGC) {
Note: See TracChangeset for help on using the changeset viewer.