Changeset 90865 in webkit


Ignore:
Timestamp:
Jul 12, 2011 3:35:39 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

COLLECT_ON_EVERY_ALLOCATION no longer works.
https://bugs.webkit.org/show_bug.cgi?id=64388

Patch by Filip Pizlo <fpizlo@apple.com> on 2011-07-12
Reviewed by Oliver Hunt.

Added a flag to Heap that determines if it's safe to collect (which for now means that
JSGlobalObject has actually been initialized, but it should work for other things, too).
This allows JSGlobalObject to allocate even if the allocator wants to GC; instead of
GCing it just grows the heap, if necessary.

Then changed Heap::allocate() to not recurse ad infinitum when
COLLECT_ON_EVERY_ALLOCATION is set. This also makes the allocator generally more
resilient against bugs; this change allowed me to put in handy assertions, such as that
an allocation must succeed after either a collection or after a new block was added.

  • heap/Heap.cpp:

(JSC::Heap::Heap):
(JSC::Heap::tryAllocate):
(JSC::Heap::allocate):
(JSC::Heap::collectAllGarbage):
(JSC::Heap::collect):

  • heap/Heap.h:

(JSC::Heap::notifyIsSafeToCollect):

  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::JSGlobalData):

Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r90854 r90865  
     12011-07-12  Filip Pizlo  <fpizlo@apple.com>
     2
     3        COLLECT_ON_EVERY_ALLOCATION no longer works.
     4        https://bugs.webkit.org/show_bug.cgi?id=64388
     5
     6        Reviewed by Oliver Hunt.
     7       
     8        Added a flag to Heap that determines if it's safe to collect (which for now means that
     9        JSGlobalObject has actually been initialized, but it should work for other things, too).
     10        This allows JSGlobalObject to allocate even if the allocator wants to GC; instead of
     11        GCing it just grows the heap, if necessary.
     12       
     13        Then changed Heap::allocate() to not recurse ad infinitum when
     14        COLLECT_ON_EVERY_ALLOCATION is set.  This also makes the allocator generally more
     15        resilient against bugs; this change allowed me to put in handy assertions, such as that
     16        an allocation must succeed after either a collection or after a new block was added.
     17
     18        * heap/Heap.cpp:
     19        (JSC::Heap::Heap):
     20        (JSC::Heap::tryAllocate):
     21        (JSC::Heap::allocate):
     22        (JSC::Heap::collectAllGarbage):
     23        (JSC::Heap::collect):
     24        * heap/Heap.h:
     25        (JSC::Heap::notifyIsSafeToCollect):
     26        * runtime/JSGlobalData.cpp:
     27        (JSC::JSGlobalData::JSGlobalData):
     28
    1292011-07-12  Filip Pizlo  <fpizlo@apple.com>
    230
  • trunk/Source/JavaScriptCore/heap/Heap.cpp

    r90415 r90865  
    249249    , m_slotVisitor(globalData->jsArrayVPtr)
    250250    , m_handleHeap(globalData)
     251    , m_isSafeToCollect(false)
    251252    , m_globalData(globalData)
    252253{
     
    312313}
    313314
     315inline void* Heap::tryAllocate(NewSpace::SizeClass& sizeClass)
     316{
     317    m_operationInProgress = Allocation;
     318    void* result = m_newSpace.allocate(sizeClass);
     319    m_operationInProgress = NoOperation;
     320    return result;
     321}
     322
    314323void* Heap::allocate(NewSpace::SizeClass& sizeClass)
    315324{
     
    319328#endif
    320329
    321     m_operationInProgress = Allocation;
    322     void* result = m_newSpace.allocate(sizeClass);
    323     m_operationInProgress = NoOperation;
    324 
     330    void* result = tryAllocate(sizeClass);
     331
     332    if (LIKELY(result != 0))
     333        return result;
     334
     335    if (m_newSpace.waterMark() < m_newSpace.highWaterMark() || !m_isSafeToCollect) {
     336        m_newSpace.addBlock(sizeClass, allocateBlock(sizeClass.cellSize));
     337        void* result = tryAllocate(sizeClass);
     338        ASSERT(result);
     339        return result;
     340    }
     341
     342    collect(DoNotSweep);
     343   
     344    result = tryAllocate(sizeClass);
     345   
    325346    if (result)
    326347        return result;
    327 
    328     if (m_newSpace.waterMark() < m_newSpace.highWaterMark()) {
    329         m_newSpace.addBlock(sizeClass, allocateBlock(sizeClass.cellSize));
    330         return allocate(sizeClass);
    331     }
    332 
    333     collect(DoNotSweep);
    334     return allocate(sizeClass);
     348   
     349    ASSERT(m_newSpace.waterMark() < m_newSpace.highWaterMark());
     350   
     351    m_newSpace.addBlock(sizeClass, allocateBlock(sizeClass.cellSize));
     352   
     353    result = tryAllocate(sizeClass);
     354    ASSERT(result);
     355    return result;
    335356}
    336357
     
    526547void Heap::collectAllGarbage()
    527548{
     549    if (!m_isSafeToCollect)
     550        return;
    528551    m_slotVisitor.setShouldUnlinkCalls(true);
    529552    collect(DoSweep);
     
    534557{
    535558    ASSERT(globalData()->identifierTable == wtfThreadData().currentIdentifierTable());
     559    ASSERT(m_isSafeToCollect);
    536560    JAVASCRIPTCORE_GC_BEGIN();
    537561
  • trunk/Source/JavaScriptCore/heap/Heap.h

    r89885 r90865  
    8383        void* allocate(size_t);
    8484        void* allocate(NewSpace::SizeClass&);
     85        void notifyIsSafeToCollect() { m_isSafeToCollect = true; }
    8586        void collectAllGarbage();
    8687
     
    136137        void markTempSortVectors(HeapRootVisitor&);
    137138
     139        void* tryAllocate(NewSpace::SizeClass&);
     140       
    138141        enum SweepToggle { DoNotSweep, DoSweep };
    139142        void collect(SweepToggle);
     
    161164        HandleHeap m_handleHeap;
    162165        HandleStack m_handleStack;
     166       
     167        bool m_isSafeToCollect;
    163168
    164169        JSGlobalData* m_globalData;
  • trunk/Source/JavaScriptCore/runtime/JSGlobalData.cpp

    r90415 r90865  
    262262    jitStubs = adoptPtr(new JITThunks(this));
    263263#endif
     264
     265    heap.notifyIsSafeToCollect();
    264266}
    265267
Note: See TracChangeset for help on using the changeset viewer.