Changeset 147282 in webkit


Ignore:
Timestamp:
Mar 30, 2013 12:01:51 PM (11 years ago)
Author:
mhahnenberg@apple.com
Message:

Move Region into its own header
https://bugs.webkit.org/show_bug.cgi?id=113617

Reviewed by Geoffrey Garen.

BlockAllocator.h is getting a little crowded. We should move the Region class into its own
header, since it's pretty independent from the BlockAllocator.

(JSC):

  • heap/Region.h: Added.

(JSC):
(DeadBlock):
(JSC::DeadBlock::DeadBlock):
(Region):
(JSC::Region::blockSize):
(JSC::Region::isFull):
(JSC::Region::isEmpty):
(JSC::Region::isCustomSize):
(JSC::Region::create):
(JSC::Region::createCustomSize):
(JSC::Region::Region):
(JSC::Region::~Region):
(JSC::Region::reset):
(JSC::Region::allocate):
(JSC::Region::deallocate):

Location:
trunk/Source/JavaScriptCore
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r147252 r147282  
     12013-03-30  Mark Hahnenberg  <mhahnenberg@apple.com>
     2
     3        Move Region into its own header
     4        https://bugs.webkit.org/show_bug.cgi?id=113617
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        BlockAllocator.h is getting a little crowded. We should move the Region class into its own
     9        header, since it's pretty independent from the BlockAllocator.
     10
     11        * GNUmakefile.list.am:
     12        * JavaScriptCore.gypi:
     13        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
     14        * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
     15        * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
     16        * JavaScriptCore.xcodeproj/project.pbxproj:
     17        * heap/BlockAllocator.h:
     18        (JSC):
     19        * heap/Region.h: Added.
     20        (JSC):
     21        (DeadBlock):
     22        (JSC::DeadBlock::DeadBlock):
     23        (Region):
     24        (JSC::Region::blockSize):
     25        (JSC::Region::isFull):
     26        (JSC::Region::isEmpty):
     27        (JSC::Region::isCustomSize):
     28        (JSC::Region::create):
     29        (JSC::Region::createCustomSize):
     30        (JSC::Region::Region):
     31        (JSC::Region::~Region):
     32        (JSC::Region::reset):
     33        (JSC::Region::allocate):
     34        (JSC::Region::deallocate):
     35
    1362013-03-29  Mark Hahnenberg  <mhahnenberg@apple.com>
    237
  • trunk/Source/JavaScriptCore/GNUmakefile.list.am

    r146734 r147282  
    357357        Source/JavaScriptCore/heap/MarkedSpace.h \
    358358        Source/JavaScriptCore/heap/PassWeak.h \
     359        Source/JavaScriptCore/heap/Region.h \
    359360        Source/JavaScriptCore/heap/Strong.h \
    360361        Source/JavaScriptCore/heap/StrongInlines.h \
  • trunk/Source/JavaScriptCore/JavaScriptCore.gypi

    r146734 r147282  
    394394            'heap/MarkStackInlines.h',
    395395            'heap/PassWeak.h',
     396            'heap/Region.h',
    396397            'heap/SlotVisitor.cpp',
    397398            'heap/SlotVisitor.h',
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj

    r146734 r147282  
    27792779                        </File>
    27802780                        <File
     2781                                RelativePath="..\..\heap\Region.h"
     2782                                >
     2783                        </File>
     2784                        <File
    27812785                                RelativePath="..\..\heap\SlotVisitor.cpp"
    27822786                                >
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj

    r146734 r147282  
    531531    <ClInclude Include="..\heap\MarkStackInlines.h" />
    532532    <ClInclude Include="..\heap\PassWeak.h" />
     533    <ClInclude Include="..\heap\Region.h" />
    533534    <ClInclude Include="..\heap\SlotVisitor.h" />
    534535    <ClInclude Include="..\heap\SlotVisitorInlines.h" />
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters

    r146734 r147282  
    11401140      <Filter>heap</Filter>
    11411141    </ClInclude>
     1142    <ClInclude Include="..\heap\Region.h">
     1143      <Filter>heap</Filter>
     1144    </ClInclude>
    11421145    <ClInclude Include="..\heap\SlotVisitor.h">
    11431146      <Filter>heap</Filter>
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r146734 r147282  
    818818                BCFD8C920EEB2EE700283848 /* JumpTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCFD8C900EEB2EE700283848 /* JumpTable.cpp */; };
    819819                BCFD8C930EEB2EE700283848 /* JumpTable.h in Headers */ = {isa = PBXBuildFile; fileRef = BCFD8C910EEB2EE700283848 /* JumpTable.h */; settings = {ATTRIBUTES = (Private, ); }; };
     820                C20B25991706536200C21F4E /* Region.h in Headers */ = {isa = PBXBuildFile; fileRef = C20B25981706536200C21F4E /* Region.h */; settings = {ATTRIBUTES = (Private, ); }; };
    820821                C20BA92D16BB1C1500B3AEA2 /* StructureRareDataInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = C20BA92C16BB1C1500B3AEA2 /* StructureRareDataInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
    821822                C21122E115DD9AB300790E3A /* GCThreadSharedData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C21122DE15DD9AB300790E3A /* GCThreadSharedData.cpp */; };
     
    17241725                BCFD8C900EEB2EE700283848 /* JumpTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JumpTable.cpp; sourceTree = "<group>"; };
    17251726                BCFD8C910EEB2EE700283848 /* JumpTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JumpTable.h; sourceTree = "<group>"; };
     1727                C20B25981706536200C21F4E /* Region.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Region.h; sourceTree = "<group>"; };
    17261728                C20BA92C16BB1C1500B3AEA2 /* StructureRareDataInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StructureRareDataInlines.h; sourceTree = "<group>"; };
    17271729                C21122DE15DD9AB300790E3A /* GCThreadSharedData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GCThreadSharedData.cpp; sourceTree = "<group>"; };
     
    21642166                                C28318FF16FE4B7D00157BFD /* HandleBlock.h */,
    21652167                                C283190116FE533E00157BFD /* HandleBlockInlines.h */,
     2168                                C20B25981706536200C21F4E /* Region.h */,
    21662169                        );
    21672170                        path = heap;
     
    29632966                                0F63945515D07057006A597C /* ArrayProfile.h in Headers */,
    29642967                                BC18C3E70E16F5CD00B34460 /* ArrayPrototype.h in Headers */,
     2968                                C20B25991706536200C21F4E /* Region.h in Headers */,
    29652969                                C283190016FE4B7D00157BFD /* HandleBlock.h in Headers */,
    29662970                                BC18C41D0E16F5CD00B34460 /* JSClassRef.h in Headers */,
  • trunk/Source/JavaScriptCore/heap/BlockAllocator.h

    r146734 r147282  
    2828
    2929#include "HeapBlock.h"
     30#include "Region.h"
    3031#include <wtf/DoublyLinkedList.h>
    3132#include <wtf/Forward.h>
     
    4243class MarkStackSegment;
    4344class MarkedBlock;
    44 class Region;
    4545class WeakBlock;
    4646
    4747// Simple allocator to reduce VM cost by holding onto blocks of memory for
    4848// short periods of time and then freeing them on a secondary thread.
    49 
    50 class DeadBlock : public HeapBlock<DeadBlock> {
    51 public:
    52     DeadBlock(Region*);
    53 };
    54 
    55 inline DeadBlock::DeadBlock(Region* region)
    56     : HeapBlock<DeadBlock>(region)
    57 {
    58 }
    59 
    60 class Region : public DoublyLinkedListNode<Region> {
    61     friend CLASS_IF_GCC DoublyLinkedListNode<Region>;
    62     friend class BlockAllocator;
    63 public:
    64     ~Region();
    65     static Region* create(size_t blockSize);
    66     static Region* createCustomSize(size_t blockSize, size_t blockAlignment);
    67     Region* reset(size_t blockSize);
    68 
    69     size_t blockSize() const { return m_blockSize; }
    70     bool isFull() const { return m_blocksInUse == m_totalBlocks; }
    71     bool isEmpty() const { return !m_blocksInUse; }
    72     bool isCustomSize() const { return m_isCustomSize; }
    73 
    74     DeadBlock* allocate();
    75     void deallocate(void*);
    76 
    77     static const size_t s_regionSize = 64 * KB;
    78 
    79 private:
    80     Region(PageAllocationAligned&, size_t blockSize, size_t totalBlocks);
    81 
    82     PageAllocationAligned m_allocation;
    83     size_t m_totalBlocks;
    84     size_t m_blocksInUse;
    85     size_t m_blockSize;
    86     bool m_isCustomSize;
    87     Region* m_prev;
    88     Region* m_next;
    89     DoublyLinkedList<DeadBlock> m_deadBlocks;
    90 };
    91 
    92 inline Region* Region::create(size_t blockSize)
    93 {
    94     ASSERT(blockSize <= s_regionSize);
    95     ASSERT(!(s_regionSize % blockSize));
    96     PageAllocationAligned allocation = PageAllocationAligned::allocate(s_regionSize, s_regionSize, OSAllocator::JSGCHeapPages);
    97     RELEASE_ASSERT(static_cast<bool>(allocation));
    98     return new Region(allocation, blockSize, s_regionSize / blockSize);
    99 }
    100 
    101 inline Region* Region::createCustomSize(size_t blockSize, size_t blockAlignment)
    102 {
    103     PageAllocationAligned allocation = PageAllocationAligned::allocate(blockSize, blockAlignment, OSAllocator::JSGCHeapPages);
    104     RELEASE_ASSERT(static_cast<bool>(allocation));
    105     Region* region = new Region(allocation, blockSize, 1);
    106     region->m_isCustomSize = true;
    107     return region;
    108 }
    109 
    110 inline Region::Region(PageAllocationAligned& allocation, size_t blockSize, size_t totalBlocks)
    111     : DoublyLinkedListNode<Region>()
    112     , m_allocation(allocation)
    113     , m_totalBlocks(totalBlocks)
    114     , m_blocksInUse(0)
    115     , m_blockSize(blockSize)
    116     , m_isCustomSize(false)
    117     , m_prev(0)
    118     , m_next(0)
    119 {
    120     ASSERT(allocation);
    121     char* start = static_cast<char*>(m_allocation.base());
    122     char* end = start + m_allocation.size();
    123     for (char* current = start; current < end; current += blockSize)
    124         m_deadBlocks.append(new (NotNull, current) DeadBlock(this));
    125 }
    126 
    127 inline Region::~Region()
    128 {
    129     ASSERT(isEmpty());
    130     m_allocation.deallocate();
    131 }
    132 
    133 inline Region* Region::reset(size_t blockSize)
    134 {
    135     ASSERT(isEmpty());
    136     PageAllocationAligned allocation = m_allocation;
    137     return new (NotNull, this) Region(allocation, blockSize, s_regionSize / blockSize);
    138 }
    139 
    140 inline DeadBlock* Region::allocate()
    141 {
    142     ASSERT(!isFull());
    143     m_blocksInUse++;
    144     return m_deadBlocks.removeHead();
    145 }
    146 
    147 inline void Region::deallocate(void* base)
    148 {
    149     ASSERT(base);
    150     ASSERT(m_blocksInUse);
    151     ASSERT(base >= m_allocation.base() && base < static_cast<char*>(m_allocation.base()) + m_allocation.size());
    152     DeadBlock* block = new (NotNull, base) DeadBlock(this);
    153     m_deadBlocks.push(block);
    154     m_blocksInUse--;
    155 }
    15649
    15750class BlockAllocator {
Note: See TracChangeset for help on using the changeset viewer.