Ignore:
Timestamp:
Mar 23, 2012, 10:19:18 AM (13 years ago)
Author:
[email protected]
Message:

Simplify memory usage tracking in CopiedSpace
https://bugs.webkit.org/show_bug.cgi?id=80705

Reviewed by Filip Pizlo.

  • heap/CopiedAllocator.h:

(CopiedAllocator): Rename currentUtilization to currentSize.
(JSC::CopiedAllocator::currentCapacity):

  • heap/CopiedBlock.h:

(CopiedBlock):
(JSC::CopiedBlock::payload): Move the implementation of payload() out of the class
declaration.
(JSC):
(JSC::CopiedBlock::size): Add new function to calculate the block's size.
(JSC::CopiedBlock::capacity): Ditto for capacity.

  • heap/CopiedSpace.cpp:

(JSC::CopiedSpace::CopiedSpace): Remove old bogus memory stats fields and add a new
field for the water mark.
(JSC::CopiedSpace::init):
(JSC::CopiedSpace::tryAllocateSlowCase): When we fail to allocate from the current
block, we need to update our current water mark with the size of the block.
(JSC::CopiedSpace::tryAllocateOversize): When we allocate a new oversize block, we
need to update our current water mark with the size of the used portion of the block.
(JSC::CopiedSpace::tryReallocate): We don't need to update the water mark when
reallocating because it will either get accounted for when we fill up the block later
in the case of being able to reallocate in the current block or it will get picked up
immediately because we'll have to get a new block.
(JSC::CopiedSpace::tryReallocateOversize): We do, however, need to update in when
realloc-ing an oversize block because we deallocate the old block and allocate a brand
new one.
(JSC::CopiedSpace::doneFillingBlock): Update the water mark as blocks are returned to
the CopiedSpace by the SlotVisitors.
(JSC::CopiedSpace::doneCopying): Add in any pinned blocks to the water mark.
(JSC::CopiedSpace::getFreshBlock): We use the Heap's new function to tell us whether or
not we should collect now instead of doing the calculation ourself.
(JSC::CopiedSpace::destroy):
(JSC):
(JSC::CopiedSpace::size): Manually calculate the size of the CopiedSpace, similar to how
MarkedSpace does.
(JSC::CopiedSpace::capacity): Ditto for capacity.

  • heap/CopiedSpace.h:

(JSC::CopiedSpace::waterMark):
(CopiedSpace):

  • heap/CopiedSpaceInlineMethods.h:

(JSC::CopiedSpace::startedCopying): Reset water mark to 0 when we start copying during a
collection.
(JSC::CopiedSpace::allocateNewBlock):
(JSC::CopiedSpace::fitsInBlock):
(JSC::CopiedSpace::allocateFromBlock):

  • heap/Heap.cpp:

(JSC::Heap::size): Incorporate size of CopiedSpace into the total size of the Heap.
(JSC::Heap::capacity): Ditto for capacity.
(JSC::Heap::collect):

  • heap/Heap.h:

(Heap):
(JSC::Heap::shouldCollect): New function for other sub-parts of the Heap to use to
determine whether they should initiate a collection or continue to allocate new blocks.
(JSC):
(JSC::Heap::waterMark): Now is the sum of the water marks of the two sub-parts of the
Heap (MarkedSpace and CopiedSpace).

  • heap/MarkedAllocator.cpp:

(JSC::MarkedAllocator::allocateSlowCase): Changed to use the Heap's new shouldCollect() function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/heap/CopiedSpace.h

    r110902 r111877  
    6767    bool contains(void*, CopiedBlock*&);
    6868
    69     size_t totalMemoryAllocated() { return m_totalMemoryAllocated; }
    70     size_t totalMemoryUtilized() { return m_totalMemoryUtilized; }
     69    size_t waterMark() { return m_waterMark; }
     70    size_t size();
     71    size_t capacity();
    7172
    7273    void destroy();
     
    9293    static CopiedBlock* oversizeBlockFor(void* ptr);
    9394
     95    size_t calculateWaterMark();
     96
    9497    Heap* m_heap;
    9598
     
    101104
    102105    Mutex m_toSpaceLock;
    103     Mutex m_memoryStatsLock;
    104106
    105107    DoublyLinkedList<HeapBlock>* m_toSpace;
     
    110112    DoublyLinkedList<HeapBlock> m_oversizeBlocks;
    111113   
    112     size_t m_totalMemoryAllocated;
    113     size_t m_totalMemoryUtilized;
    114 
    115114    bool m_inCopyingPhase;
    116115
     
    118117    ThreadCondition m_loanedBlocksCondition;
    119118    size_t m_numberOfLoanedBlocks;
     119
     120    Mutex m_memoryStatsLock;
     121    size_t m_waterMark;
    120122
    121123    static const size_t s_maxAllocationSize = 32 * KB;
Note: See TracChangeset for help on using the changeset viewer.