Ignore:
Timestamp:
Sep 8, 2013, 5:11:57 PM (12 years ago)
Author:
[email protected]
Message:

Calculating the size of the Heap should not require walking over it
https://bugs.webkit.org/show_bug.cgi?id=120910

Reviewed by Geoffrey Garen.

Currently Heap::size() is O(sizeof(Heap)). This is too expensive to
call during a collection. We should keep a count of visited and copied
bytes as each collection progresses so as to avoid re-walking the Heap
at the end of collection.

  • heap/GCThreadSharedData.cpp:

(JSC::GCThreadSharedData::childBytesVisited):
(JSC::GCThreadSharedData::childBytesCopied):

  • heap/GCThreadSharedData.h:
  • heap/Heap.cpp:

(JSC::Heap::Heap):
(JSC::Heap::markRoots):
(JSC::Heap::sizeAfterCollect):
(JSC::Heap::collect):

  • heap/Heap.h:
  • heap/SlotVisitor.cpp:

(JSC::SlotVisitor::SlotVisitor):
(JSC::SlotVisitor::reset):

  • heap/SlotVisitor.h:

(JSC::SlotVisitor::bytesVisited):
(JSC::SlotVisitor::bytesCopied):

  • heap/SlotVisitorInlines.h:

(JSC::SlotVisitor::internalAppend):
(JSC::SlotVisitor::copyLater):

File:
1 edited

Legend:

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

    r155316 r155317  
    252252    , m_bytesAllocated(0)
    253253    , m_bytesAbandoned(0)
     254    , m_totalBytesVisited(0)
     255    , m_totalBytesCopied(0)
    254256    , m_operationInProgress(NoOperation)
    255257    , m_blockAllocator()
     
    592594#endif
    593595
     596    m_totalBytesVisited = visitor.bytesVisited();
     597    m_totalBytesCopied = visitor.bytesCopied();
     598#if ENABLE(PARALLEL_GC)
     599    m_totalBytesVisited += m_sharedData.childBytesVisited();
     600    m_totalBytesCopied += m_sharedData.childBytesCopied();
     601#endif
     602
    594603    visitor.reset();
    595604#if ENABLE(PARALLEL_GC)
     
    635644}
    636645
     646size_t Heap::sizeAfterCollect()
     647{
     648    // The result here may not agree with the normal Heap::size().
     649    // This is due to the fact that we only count live copied bytes
     650    // rather than all used (including dead) copied bytes, thus it's
     651    // always the case that m_totalBytesCopied <= m_storageSpace.size().
     652    ASSERT(m_totalBytesCopied <= m_storageSpace.size());
     653    return m_totalBytesVisited + m_totalBytesCopied + extraSize();
     654}
     655
    637656size_t Heap::protectedGlobalObjectCount()
    638657{
     
    799818    }
    800819   
    801     size_t currentHeapSize = size();
     820    size_t currentHeapSize = sizeAfterCollect();
    802821    if (Options::gcMaxHeapSize() && currentHeapSize > Options::gcMaxHeapSize())
    803822        HeapStatistics::exitWithFailure();
Note: See TracChangeset for help on using the changeset viewer.