Changeset 106676 in webkit


Ignore:
Timestamp:
Feb 3, 2012 11:21:28 AM (12 years ago)
Author:
mhahnenberg@apple.com
Message:

Refactor MarkedBlock::SizeClass into a separate class
https://bugs.webkit.org/show_bug.cgi?id=77600

Reviewed by Geoffrey Garen.

We pulled SizeClass out into its own class, named MarkedAllocator, and gave it
the responsibility of allocating objects from the collection of MarkedBlocks
that it manages. Also limited the amount of coupling to internal data fields
from other places, although it's mostly unavoidable in the JIT code.

Eventually MarkedAllocator will implement various policies to do with object
management, e.g. whether or not to run destructors on objects that it manages.
MarkedSpace will manage a collection of MarkedAllocators with varying policies,
as it does now but to a larger extent.

  • CMakeLists.txt:
  • GNUmakefile.list.am:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Target.pri:
  • dfg/DFGSpeculativeJIT.h:

(JSC::DFG::SpeculativeJIT::emitAllocateJSFinalObject):

  • heap/Heap.cpp:

(JSC::Heap::collect):
(JSC::Heap::resetAllocators):

  • heap/Heap.h:

(JSC::Heap::allocatorForObject):
(Heap):

  • heap/MarkedAllocator.cpp: Added.

(JSC):
(JSC::MarkedAllocator::tryAllocateHelper):
(JSC::MarkedAllocator::tryAllocate):
(JSC::MarkedAllocator::allocateSlowCase):
(JSC::MarkedAllocator::allocateBlock):
(JSC::MarkedAllocator::addBlock):
(JSC::MarkedAllocator::removeBlock):

  • heap/MarkedAllocator.h: Added.

(JSC):
(DFG):
(MarkedAllocator):
(JSC::MarkedAllocator::cellSize):
(JSC::MarkedAllocator::heap):
(JSC::MarkedAllocator::setHeap):
(JSC::MarkedAllocator::setCellSize):
(JSC::MarkedAllocator::setMarkedSpace):
(JSC::MarkedAllocator::MarkedAllocator):
(JSC::MarkedAllocator::allocate):
(JSC::MarkedAllocator::reset):
(JSC::MarkedAllocator::zapFreeList):
(JSC::MarkedAllocator::forEachBlock):

  • heap/MarkedSpace.cpp:

(JSC::MarkedSpace::MarkedSpace):
(JSC::MarkedSpace::resetAllocators):
(JSC::MarkedSpace::canonicalizeCellLivenessData):
(JSC::TakeIfUnmarked::operator()):

  • heap/MarkedSpace.h:

(MarkedSpace):
(JSC::MarkedSpace::allocatorFor):
(JSC::MarkedSpace::allocate):
(JSC::MarkedSpace::forEachBlock):
(JSC::MarkedSpace::didAddBlock):
(JSC::MarkedSpace::didConsumeFreeList):

  • jit/JITInlineMethods.h:

(JSC::JIT::emitAllocateBasicJSObject):

Location:
trunk/Source/JavaScriptCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/CMakeLists.txt

    r106197 r106676  
    8181    heap/HandleStack.cpp
    8282    heap/MachineStackMarker.cpp
     83    heap/MarkedAllocator.cpp
    8384    heap/MarkedBlock.cpp
    8485    heap/MarkedSpace.cpp
  • trunk/Source/JavaScriptCore/ChangeLog

    r106650 r106676  
     12012-02-03  Mark Hahnenberg  <mhahnenberg@apple.com>
     2
     3        Refactor MarkedBlock::SizeClass into a separate class
     4        https://bugs.webkit.org/show_bug.cgi?id=77600
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        We pulled SizeClass out into its own class, named MarkedAllocator, and gave it
     9        the responsibility of allocating objects from the collection of MarkedBlocks
     10        that it manages. Also limited the amount of coupling to internal data fields
     11        from other places, although it's mostly unavoidable in the JIT code.
     12
     13        Eventually MarkedAllocator will implement various policies to do with object
     14        management, e.g. whether or not to run destructors on objects that it manages.
     15        MarkedSpace will manage a collection of MarkedAllocators with varying policies,
     16        as it does now but to a larger extent.
     17
     18        * CMakeLists.txt:
     19        * GNUmakefile.list.am:
     20        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
     21        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
     22        * JavaScriptCore.xcodeproj/project.pbxproj:
     23        * Target.pri:
     24        * dfg/DFGSpeculativeJIT.h:
     25        (JSC::DFG::SpeculativeJIT::emitAllocateJSFinalObject):
     26        * heap/Heap.cpp:
     27        (JSC::Heap::collect):
     28        (JSC::Heap::resetAllocators):
     29        * heap/Heap.h:
     30        (JSC::Heap::allocatorForObject):
     31        (Heap):
     32        * heap/MarkedAllocator.cpp: Added.
     33        (JSC):
     34        (JSC::MarkedAllocator::tryAllocateHelper):
     35        (JSC::MarkedAllocator::tryAllocate):
     36        (JSC::MarkedAllocator::allocateSlowCase):
     37        (JSC::MarkedAllocator::allocateBlock):
     38        (JSC::MarkedAllocator::addBlock):
     39        (JSC::MarkedAllocator::removeBlock):
     40        * heap/MarkedAllocator.h: Added.
     41        (JSC):
     42        (DFG):
     43        (MarkedAllocator):
     44        (JSC::MarkedAllocator::cellSize):
     45        (JSC::MarkedAllocator::heap):
     46        (JSC::MarkedAllocator::setHeap):
     47        (JSC::MarkedAllocator::setCellSize):
     48        (JSC::MarkedAllocator::setMarkedSpace):
     49        (JSC::MarkedAllocator::MarkedAllocator):
     50        (JSC::MarkedAllocator::allocate):
     51        (JSC::MarkedAllocator::reset):
     52        (JSC::MarkedAllocator::zapFreeList):
     53        (JSC::MarkedAllocator::forEachBlock):
     54        * heap/MarkedSpace.cpp:
     55        (JSC::MarkedSpace::MarkedSpace):
     56        (JSC::MarkedSpace::resetAllocators):
     57        (JSC::MarkedSpace::canonicalizeCellLivenessData):
     58        (JSC::TakeIfUnmarked::operator()):
     59        * heap/MarkedSpace.h:
     60        (MarkedSpace):
     61        (JSC::MarkedSpace::allocatorFor):
     62        (JSC::MarkedSpace::allocate):
     63        (JSC::MarkedSpace::forEachBlock):
     64        (JSC::MarkedSpace::didAddBlock):
     65        (JSC::MarkedSpace::didConsumeFreeList):
     66        * jit/JITInlineMethods.h:
     67        (JSC::JIT::emitAllocateBasicJSObject):
     68
    1692012-02-03  Simon Hausmann  <simon.hausmann@nokia.com>
    270
  • trunk/Source/JavaScriptCore/GNUmakefile.list.am

    r106598 r106676  
    206206        Source/JavaScriptCore/heap/MarkStack.h \
    207207        Source/JavaScriptCore/heap/HeapRootVisitor.h \
     208    Source/JavaScriptCore/heap/MarkedAllocator.cpp \
     209    Source/JavaScriptCore/heap/MarkedAllocator.h \
    208210        Source/JavaScriptCore/heap/MarkedBlock.cpp \
    209211        Source/JavaScriptCore/heap/MarkedBlock.h \
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r106454 r106676  
    6565    ?addStaticGlobals@JSGlobalObject@JSC@@IAEXPAUGlobalPropertyInfo@12@H@Z
    6666    ?allocatePropertyStorage@JSObject@JSC@@QAEXAAVJSGlobalData@2@II@Z
    67     ?allocateSlowCase@MarkedSpace@JSC@@AAEPAXAAUSizeClass@12@@Z
     67    ?allocateSlowCase@MarkedAllocator@JSC@@AAEPAXXZ
    6868    ?append@StringBuilder@WTF@@QAEXPBEI@Z
    6969    ?append@StringBuilder@WTF@@QAEXPB_WI@Z
     
    284284    ?releaseDecommitted@OSAllocator@WTF@@SAXPAXI@Z
    285285    ?releaseExecutableMemory@JSGlobalData@JSC@@QAEXXZ
     286    ?removeBlock@MarkedAllocator@JSC@@QAEXPAVMarkedBlock@2@@Z
    286287    ?reportExtraMemoryCostSlowCase@Heap@JSC@@AAEXI@Z
    287288    ?reserveAndCommit@OSAllocator@WTF@@SAPAXIW4Usage@12@_N11@Z
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj

    r106197 r106676  
    20672067                            </File>
    20682068                            <File
     2069                                    RelativePath="..\..\heap\MarkedAllocator.cpp"
     2070                                    >
     2071                            </File>
     2072                            <File
     2073                                    RelativePath="..\..\heap\MarkedAllocator.h"
     2074                                    >
     2075                            </File>
     2076                            <File
    20692077                                    RelativePath="..\..\heap\MarkedBlock.cpp"
    20702078                                    >
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r106606 r106676  
    722722                C22C531513FAF6EF00B7DC0D /* utils.h in Headers */ = {isa = PBXBuildFile; fileRef = C22C52BB13FAF6EF00B7DC0D /* utils.h */; settings = {ATTRIBUTES = (Private, ); }; };
    723723                C240305514B404E60079EB64 /* BumpSpace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C240305314B404C90079EB64 /* BumpSpace.cpp */; };
     724                C2B916C214DA014E00CBAC86 /* MarkedAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = C2B916C114DA014E00CBAC86 /* MarkedAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
     725                C2B916C514DA040C00CBAC86 /* MarkedAllocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C2B916C414DA040C00CBAC86 /* MarkedAllocator.cpp */; };
    724726                C2C8D02D14A3C6E000578E65 /* BumpSpaceInlineMethods.h in Headers */ = {isa = PBXBuildFile; fileRef = C2C8D02B14A3C6B200578E65 /* BumpSpaceInlineMethods.h */; settings = {ATTRIBUTES = (Private, ); }; };
    725727                C2C8D03014A3CEFC00578E65 /* BumpBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = C2C8D02E14A3CEFC00578E65 /* BumpBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    15041506                C22C52BB13FAF6EF00B7DC0D /* utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = utils.h; sourceTree = "<group>"; };
    15051507                C240305314B404C90079EB64 /* BumpSpace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BumpSpace.cpp; sourceTree = "<group>"; };
     1508                C2B916C114DA014E00CBAC86 /* MarkedAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MarkedAllocator.h; sourceTree = "<group>"; };
     1509                C2B916C414DA040C00CBAC86 /* MarkedAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MarkedAllocator.cpp; sourceTree = "<group>"; };
    15061510                C2C8D02B14A3C6B200578E65 /* BumpSpaceInlineMethods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BumpSpaceInlineMethods.h; sourceTree = "<group>"; };
    15071511                C2C8D02E14A3CEFC00578E65 /* BumpBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BumpBlock.h; sourceTree = "<group>"; };
     
    18011805                                14B7233F12D7D0DA003BD5ED /* MachineStackMarker.cpp */,
    18021806                                14B7234012D7D0DA003BD5ED /* MachineStackMarker.h */,
     1807                                C2B916C414DA040C00CBAC86 /* MarkedAllocator.cpp */,
     1808                                C2B916C114DA014E00CBAC86 /* MarkedAllocator.h */,
    18031809                                142D6F0613539A2800B02E86 /* MarkedBlock.cpp */,
    18041810                                142D6F0713539A2800B02E86 /* MarkedBlock.h */,
     
    26732679                                C2D9CA1314BCC04600304B46 /* CheckedBoolean.h in Headers */,
    26742680                                A73BE16B148420520091204B /* ArrayBufferView.h in Headers */,
     2681                                C2B916C214DA014E00CBAC86 /* MarkedAllocator.h in Headers */,
    26752682                                BC18C3E60E16F5CD00B34460 /* ArrayConstructor.h in Headers */,
    26762683                                BC18C3E70E16F5CD00B34460 /* ArrayPrototype.h in Headers */,
     
    36593666                                86B5826714D2796C00A9C306 /* CodeProfile.cpp in Sources */,
    36603667                                86B5826914D2797000A9C306 /* CodeProfiling.cpp in Sources */,
     3668                                C2B916C514DA040C00CBAC86 /* MarkedAllocator.cpp in Sources */,
    36613669                        );
    36623670                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/JavaScriptCore/Target.pri

    r106197 r106676  
    7474    heap/MachineStackMarker.cpp \
    7575    heap/MarkStack.cpp \
     76    heap/MarkedAllocator.cpp \
    7677    heap/MarkedBlock.cpp \
    7778    heap/MarkedSpace.cpp \
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h

    r106502 r106676  
    3434#include "DFGOSRExit.h"
    3535#include "DFGOperations.h"
     36#include "MarkedAllocator.h"
    3637#include "ValueRecovery.h"
    3738
     
    15531554    void emitAllocateJSFinalObject(T structure, GPRReg resultGPR, GPRReg scratchGPR, MacroAssembler::JumpList& slowPath)
    15541555    {
    1555         MarkedSpace::SizeClass* sizeClass = &m_jit.globalData()->heap.sizeClassForObject(sizeof(JSFinalObject));
     1556        MarkedAllocator* allocator = &m_jit.globalData()->heap.allocatorForObject(sizeof(JSFinalObject));
    15561557       
    1557         m_jit.loadPtr(&sizeClass->firstFreeCell, resultGPR);
     1558        m_jit.loadPtr(&allocator->m_firstFreeCell, resultGPR);
    15581559        slowPath.append(m_jit.branchTestPtr(MacroAssembler::Zero, resultGPR));
    15591560       
     
    15671568        // Now that we have scratchGPR back, remove the object from the free list
    15681569        m_jit.loadPtr(MacroAssembler::Address(resultGPR), scratchGPR);
    1569         m_jit.storePtr(scratchGPR, &sizeClass->firstFreeCell);
     1570        m_jit.storePtr(scratchGPR, &allocator->m_firstFreeCell);
    15701571       
    15711572        // Initialize the object's classInfo pointer
  • trunk/Source/JavaScriptCore/heap/Heap.cpp

    r105442 r106676  
    812812    {
    813813        GCPHASE(ResetAllocator);
    814         resetAllocator();
     814        resetAllocators();
    815815    }
    816816   
     
    847847}
    848848
    849 void Heap::resetAllocator()
     849void Heap::resetAllocators()
    850850{
    851851    m_extraCost = 0;
    852     m_objectSpace.resetAllocator();
     852    m_objectSpace.resetAllocators();
    853853}
    854854
  • trunk/Source/JavaScriptCore/heap/Heap.h

    r106078 r106676  
    2626#include "HandleHeap.h"
    2727#include "HandleStack.h"
     28#include "MarkedAllocator.h"
    2829#include "MarkedBlock.h"
    2930#include "MarkedBlockSet.h"
     
    9596        inline bool isBusy();
    9697       
    97         MarkedSpace::SizeClass& sizeClassForObject(size_t bytes) { return m_objectSpace.sizeClassFor(bytes); }
     98        MarkedAllocator& allocatorForObject(size_t bytes) { return m_objectSpace.allocatorFor(bytes); }
    9899        void* allocate(size_t);
    99100        CheckedBoolean tryAllocateStorage(size_t, void**);
     
    137138    private:
    138139        friend class MarkedSpace;
     140        friend class MarkedAllocator;
    139141        friend class MarkedBlock;
    140142        friend class BumpSpace;
     
    161163        void canonicalizeCellLivenessData();
    162164
    163         void resetAllocator();
     165        void resetAllocators();
    164166        void freeBlocks(MarkedBlock*);
    165167
  • trunk/Source/JavaScriptCore/heap/MarkedSpace.cpp

    r106078 r106676  
    3636    , m_heap(heap)
    3737{
    38     for (size_t cellSize = preciseStep; cellSize <= preciseCutoff; cellSize += preciseStep)
    39         sizeClassFor(cellSize).cellSize = cellSize;
     38    for (size_t cellSize = preciseStep; cellSize <= preciseCutoff; cellSize += preciseStep) {
     39        allocatorFor(cellSize).setCellSize(cellSize);
     40        allocatorFor(cellSize).setHeap(heap);
     41        allocatorFor(cellSize).setMarkedSpace(this);
     42    }
    4043
    41     for (size_t cellSize = impreciseStep; cellSize <= impreciseCutoff; cellSize += impreciseStep)
    42         sizeClassFor(cellSize).cellSize = cellSize;
     44    for (size_t cellSize = impreciseStep; cellSize <= impreciseCutoff; cellSize += impreciseStep) {
     45        allocatorFor(cellSize).setCellSize(cellSize);
     46        allocatorFor(cellSize).setHeap(heap);
     47        allocatorFor(cellSize).setMarkedSpace(this);
     48    }
    4349}
    4450
    45 void MarkedSpace::addBlock(SizeClass& sizeClass, MarkedBlock* block)
    46 {
    47     ASSERT(!sizeClass.currentBlock);
    48     ASSERT(!sizeClass.firstFreeCell);
    49 
    50     sizeClass.blockList.append(block);
    51     sizeClass.currentBlock = block;
    52     sizeClass.firstFreeCell = block->sweep(MarkedBlock::SweepToFreeList);
    53 }
    54 
    55 void MarkedSpace::removeBlock(MarkedBlock* block)
    56 {
    57     SizeClass& sizeClass = sizeClassFor(block->cellSize());
    58     if (sizeClass.currentBlock == block)
    59         sizeClass.currentBlock = 0;
    60     sizeClass.blockList.remove(block);
    61 }
    62 
    63 void MarkedSpace::resetAllocator()
     51void MarkedSpace::resetAllocators()
    6452{
    6553    m_waterMark = 0;
     
    6755
    6856    for (size_t cellSize = preciseStep; cellSize <= preciseCutoff; cellSize += preciseStep)
    69         sizeClassFor(cellSize).resetAllocator();
     57        allocatorFor(cellSize).reset();
    7058
    7159    for (size_t cellSize = impreciseStep; cellSize <= impreciseCutoff; cellSize += impreciseStep)
    72         sizeClassFor(cellSize).resetAllocator();
     60        allocatorFor(cellSize).reset();
    7361}
    7462
     
    7664{
    7765    for (size_t cellSize = preciseStep; cellSize <= preciseCutoff; cellSize += preciseStep)
    78         sizeClassFor(cellSize).zapFreeList();
     66        allocatorFor(cellSize).zapFreeList();
    7967
    8068    for (size_t cellSize = impreciseStep; cellSize <= impreciseCutoff; cellSize += impreciseStep)
    81         sizeClassFor(cellSize).zapFreeList();
     69        allocatorFor(cellSize).zapFreeList();
    8270}
    8371
    84 inline void* MarkedSpace::tryAllocateHelper(MarkedSpace::SizeClass& sizeClass)
    85 {
    86     MarkedBlock::FreeCell* firstFreeCell = sizeClass.firstFreeCell;
    87     if (!firstFreeCell) {
    88         for (MarkedBlock*& block = sizeClass.currentBlock; block; block = static_cast<MarkedBlock*>(block->next())) {
    89             firstFreeCell = block->sweep(MarkedBlock::SweepToFreeList);
    90             if (firstFreeCell)
    91                 break;
    92             m_nurseryWaterMark += block->capacity() - block->size();
    93             m_waterMark += block->capacity();
    94             block->didConsumeFreeList();
    95         }
    96 
    97         if (!firstFreeCell)
    98             return 0;
    99     }
    100 
    101     ASSERT(firstFreeCell);
    102     sizeClass.firstFreeCell = firstFreeCell->next;
    103     return firstFreeCell;
    104 }
    105 
    106 inline void* MarkedSpace::tryAllocate(MarkedSpace::SizeClass& sizeClass)
    107 {
    108     m_heap->m_operationInProgress = Allocation;
    109     void* result = tryAllocateHelper(sizeClass);
    110     m_heap->m_operationInProgress = NoOperation;
    111     return result;
    112 }
    113 
    114 void* MarkedSpace::allocateSlowCase(MarkedSpace::SizeClass& sizeClass)
    115 {
    116 #if COLLECT_ON_EVERY_ALLOCATION
    117     m_heap->collectAllGarbage();
    118     ASSERT(m_heap->m_operationInProgress == NoOperation);
    119 #endif
    120    
    121     void* result = tryAllocate(sizeClass);
    122    
    123     if (LIKELY(result != 0))
    124         return result;
    125    
    126     AllocationEffort allocationEffort;
    127    
    128     if ((
    129 #if ENABLE(GGC)
    130          nurseryWaterMark() < m_heap->m_minBytesPerCycle
    131 #else
    132          m_heap->waterMark() < m_heap->highWaterMark()
    133 #endif
    134          ) || !m_heap->m_isSafeToCollect)
    135         allocationEffort = AllocationMustSucceed;
    136     else
    137         allocationEffort = AllocationCanFail;
    138    
    139     MarkedBlock* block = allocateBlock(sizeClass.cellSize, allocationEffort);
    140     if (block) {
    141         addBlock(sizeClass, block);
    142         void* result = tryAllocate(sizeClass);
    143         ASSERT(result);
    144         return result;
    145     }
    146    
    147     m_heap->collect(Heap::DoNotSweep);
    148    
    149     result = tryAllocate(sizeClass);
    150    
    151     if (result)
    152         return result;
    153    
    154     ASSERT(m_heap->waterMark() < m_heap->highWaterMark());
    155    
    156     addBlock(sizeClass, allocateBlock(sizeClass.cellSize, AllocationMustSucceed));
    157    
    158     result = tryAllocate(sizeClass);
    159     ASSERT(result);
    160     return result;
    161 }
    162 
    163 MarkedBlock* MarkedSpace::allocateBlock(size_t cellSize, AllocationEffort allocationEffort)
    164 {
    165     MarkedBlock* block;
    166    
    167     {
    168         MutexLocker locker(m_heap->m_freeBlockLock);
    169         if (m_heap->m_numberOfFreeBlocks) {
    170             block = static_cast<MarkedBlock*>(m_heap->m_freeBlocks.removeHead());
    171             ASSERT(block);
    172             m_heap->m_numberOfFreeBlocks--;
    173         } else
    174             block = 0;
    175     }
    176     if (block)
    177         block = MarkedBlock::recycle(block, m_heap, cellSize);
    178     else if (allocationEffort == AllocationCanFail)
    179         return 0;
    180     else
    181         block = MarkedBlock::create(m_heap, cellSize);
    182    
    183     m_blocks.add(block);
    184    
    185     return block;
    186 }
    18772
    18873void MarkedSpace::freeBlocks(MarkedBlock* head)
     
    223108        return;
    224109   
    225     m_markedSpace->removeBlock(block);
     110    m_markedSpace->allocatorFor(block->cellSize()).removeBlock(block);
    226111    m_empties.append(block);
    227112}
  • trunk/Source/JavaScriptCore/heap/MarkedSpace.h

    r106433 r106676  
    2424
    2525#include "MachineStackMarker.h"
     26#include "MarkedAllocator.h"
    2627#include "MarkedBlock.h"
    2728#include "MarkedBlockSet.h"
     
    4950    static const size_t maxCellSize = 2048;
    5051
    51     struct SizeClass {
    52         SizeClass();
    53         void resetAllocator();
    54         void zapFreeList();
    55 
    56         MarkedBlock::FreeCell* firstFreeCell;
    57         MarkedBlock* currentBlock;
    58         DoublyLinkedList<HeapBlock> blockList;
    59         size_t cellSize;
    60     };
    61 
    6252    MarkedSpace(Heap*);
    6353
    64     SizeClass& sizeClassFor(size_t);
     54    MarkedAllocator& allocatorFor(size_t);
    6555    void* allocate(size_t);
    66     void* allocate(SizeClass&);
    6756   
    68     void resetAllocator();
     57    void resetAllocators();
    6958
    70     void addBlock(SizeClass&, MarkedBlock*);
    71     void removeBlock(MarkedBlock*);
    7259    MarkedBlockSet& blocks() { return m_blocks; }
    7360   
     
    8673    void shrink();
    8774    void freeBlocks(MarkedBlock* head);
     75    void didAddBlock(MarkedBlock*);
     76    void didConsumeFreeList(MarkedBlock*);
    8877
    8978private:
    90     JS_EXPORT_PRIVATE void* allocateSlowCase(SizeClass&);
    91     void* tryAllocateHelper(MarkedSpace::SizeClass&);
    92     void* tryAllocate(MarkedSpace::SizeClass&);
    93     MarkedBlock* allocateBlock(size_t, AllocationEffort);
    94 
    9579    // [ 32... 256 ]
    9680    static const size_t preciseStep = MarkedBlock::atomSize;
     
    10387    static const size_t impreciseCount = impreciseCutoff / impreciseStep;
    10488
    105     FixedArray<SizeClass, preciseCount> m_preciseSizeClasses;
    106     FixedArray<SizeClass, impreciseCount> m_impreciseSizeClasses;
     89    FixedArray<MarkedAllocator, preciseCount> m_preciseSizeClasses;
     90    FixedArray<MarkedAllocator, impreciseCount> m_impreciseSizeClasses;
    10791    size_t m_waterMark;
    10892    size_t m_nurseryWaterMark;
     
    137121}
    138122
    139 inline MarkedSpace::SizeClass& MarkedSpace::sizeClassFor(size_t bytes)
     123inline MarkedAllocator& MarkedSpace::allocatorFor(size_t bytes)
    140124{
    141125    ASSERT(bytes && bytes <= maxCellSize);
     
    147131inline void* MarkedSpace::allocate(size_t bytes)
    148132{
    149     SizeClass& sizeClass = sizeClassFor(bytes);
    150     return allocate(sizeClass);
    151 }
    152 
    153 inline void* MarkedSpace::allocate(SizeClass& sizeClass)
    154 {
    155     // This is a light-weight fast path to cover the most common case.
    156     MarkedBlock::FreeCell* firstFreeCell = sizeClass.firstFreeCell;
    157     if (UNLIKELY(!firstFreeCell))
    158         return allocateSlowCase(sizeClass);
    159    
    160     sizeClass.firstFreeCell = firstFreeCell->next;
    161     return firstFreeCell;
     133    return allocatorFor(bytes).allocate();
    162134}
    163135
     
    165137{
    166138    for (size_t i = 0; i < preciseCount; ++i) {
    167         SizeClass& sizeClass = m_preciseSizeClasses[i];
    168         HeapBlock* next;
    169         for (HeapBlock* block = sizeClass.blockList.head(); block; block = next) {
    170             next = block->next();
    171             functor(static_cast<MarkedBlock*>(block));
    172         }
     139        m_preciseSizeClasses[i].forEachBlock(functor);
    173140    }
    174141
    175142    for (size_t i = 0; i < impreciseCount; ++i) {
    176         SizeClass& sizeClass = m_impreciseSizeClasses[i];
    177         HeapBlock* next;
    178         for (HeapBlock* block = sizeClass.blockList.head(); block; block = next) {
    179             next = block->next();
    180             functor(static_cast<MarkedBlock*>(block));
    181         }
     143        m_impreciseSizeClasses[i].forEachBlock(functor);
    182144    }
    183145
     
    191153}
    192154
    193 inline MarkedSpace::SizeClass::SizeClass()
    194     : firstFreeCell(0)
    195     , currentBlock(0)
    196     , cellSize(0)
     155inline void MarkedSpace::didAddBlock(MarkedBlock* block)
    197156{
     157    m_blocks.add(block);
    198158}
    199159
    200 inline void MarkedSpace::SizeClass::resetAllocator()
     160inline void MarkedSpace::didConsumeFreeList(MarkedBlock* block)
    201161{
    202     currentBlock = static_cast<MarkedBlock*>(blockList.head());
    203 }
    204 
    205 inline void MarkedSpace::SizeClass::zapFreeList()
    206 {
    207     if (!currentBlock) {
    208         ASSERT(!firstFreeCell);
    209         return;
    210     }
    211 
    212     currentBlock->zapFreeList(firstFreeCell);
    213     firstFreeCell = 0;
     162    m_nurseryWaterMark += block->capacity() - block->size();
     163    m_waterMark += block->capacity();
    214164}
    215165
  • trunk/Source/JavaScriptCore/jit/JITInlineMethods.h

    r105533 r106676  
    402402template <typename ClassType, typename StructureType> inline void JIT::emitAllocateBasicJSObject(StructureType structure, RegisterID result, RegisterID storagePtr)
    403403{
    404     MarkedSpace::SizeClass* sizeClass = &m_globalData->heap.sizeClassForObject(sizeof(ClassType));
    405     loadPtr(&sizeClass->firstFreeCell, result);
     404    MarkedAllocator* allocator = &m_globalData->heap.allocatorForObject(sizeof(ClassType));
     405    loadPtr(&allocator->m_firstFreeCell, result);
    406406    addSlowCase(branchTestPtr(Zero, result));
    407407
    408408    // remove the object from the free list
    409409    loadPtr(Address(result), storagePtr);
    410     storePtr(storagePtr, &sizeClass->firstFreeCell);
     410    storePtr(storagePtr, &allocator->m_firstFreeCell);
    411411
    412412    // initialize the object's structure
Note: See TracChangeset for help on using the changeset viewer.