⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 196847 in webkit


Ignore:
Timestamp:
Feb 19, 2016, 5:06:49 PM (11 years ago)
Author:
ggaren@apple.com
Message:

bmalloc: Chunk, Page, and Line don't need to be class templates
​https://bugs.webkit.org/show_bug.cgi?id=154480

Reviewed by Gavin Barraclough.

We needed class templates to distinguish between small and medium,
but medium is gone now.

  • bmalloc.xcodeproj/project.pbxproj:
  • bmalloc/Chunk.h: Removed.
  • bmalloc/Heap.cpp:

(bmalloc::Heap::initializeLineMetadata):
(bmalloc::Heap::allocateSmallBumpRanges):

  • bmalloc/Heap.h:
  • bmalloc/Line.h: Removed.
  • bmalloc/Page.h: Removed.
  • bmalloc/Sizes.h:
  • bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h.

(bmalloc::SmallChunk::begin):
(bmalloc::SmallChunk::end):
(bmalloc::SmallChunk::lines):
(bmalloc::SmallChunk::pages):
(bmalloc::SmallChunk::get):
(bmalloc::SmallLine::get):
(bmalloc::SmallLine::begin):
(bmalloc::SmallLine::end):
(bmalloc::SmallPage::get):
(bmalloc::SmallPage::begin):
(bmalloc::SmallPage::end):
(bmalloc::Chunk::begin): Deleted.
(bmalloc::Chunk::end): Deleted.
(bmalloc::Chunk::lines): Deleted.
(bmalloc::Chunk::pages): Deleted.

  • bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h.

(bmalloc::SmallLine::ref):
(bmalloc::SmallLine::deref):
(bmalloc::Line<Traits>::begin): Deleted.
(bmalloc::Line<Traits>::end): Deleted.
(bmalloc::Line<Traits>::ref): Deleted.
(bmalloc::Line<Traits>::deref): Deleted.

  • bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h.

(bmalloc::SmallPage::hasFreeLines):
(bmalloc::SmallPage::setHasFreeLines):
(bmalloc::SmallPage::ref):
(bmalloc::SmallPage::deref):
(bmalloc::Page::hasFreeLines): Deleted.
(bmalloc::Page::setHasFreeLines): Deleted.
(bmalloc::Page<Traits>::ref): Deleted.
(bmalloc::Page<Traits>::deref): Deleted.

  • bmalloc/SmallTraits.h: Removed.
Location:
trunk/Source/bmalloc
Files:
1 deleted
5 edited
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/bmalloc/ChangeLog

    r196845 r196847  
     12016-02-19  Geoffrey Garen  <ggaren@apple.com>
     2
     3        bmalloc: Chunk, Page, and Line don't need to be class templates
     4        https://bugs.webkit.org/show_bug.cgi?id=154480
     5
     6        Reviewed by Gavin Barraclough.
     7
     8        We needed class templates to distinguish between small and medium,
     9        but medium is gone now.
     10
     11        * bmalloc.xcodeproj/project.pbxproj:
     12        * bmalloc/Chunk.h: Removed.
     13        * bmalloc/Heap.cpp:
     14        (bmalloc::Heap::initializeLineMetadata):
     15        (bmalloc::Heap::allocateSmallBumpRanges):
     16        * bmalloc/Heap.h:
     17        * bmalloc/Line.h: Removed.
     18        * bmalloc/Page.h: Removed.
     19        * bmalloc/Sizes.h:
     20        * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h.
     21        (bmalloc::SmallChunk::begin):
     22        (bmalloc::SmallChunk::end):
     23        (bmalloc::SmallChunk::lines):
     24        (bmalloc::SmallChunk::pages):
     25        (bmalloc::SmallChunk::get):
     26        (bmalloc::SmallLine::get):
     27        (bmalloc::SmallLine::begin):
     28        (bmalloc::SmallLine::end):
     29        (bmalloc::SmallPage::get):
     30        (bmalloc::SmallPage::begin):
     31        (bmalloc::SmallPage::end):
     32        (bmalloc::Chunk::begin): Deleted.
     33        (bmalloc::Chunk::end): Deleted.
     34        (bmalloc::Chunk::lines): Deleted.
     35        (bmalloc::Chunk::pages): Deleted.
     36        * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h.
     37        (bmalloc::SmallLine::ref):
     38        (bmalloc::SmallLine::deref):
     39        (bmalloc::Line<Traits>::begin): Deleted.
     40        (bmalloc::Line<Traits>::end): Deleted.
     41        (bmalloc::Line<Traits>::ref): Deleted.
     42        (bmalloc::Line<Traits>::deref): Deleted.
     43        * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h.
     44        (bmalloc::SmallPage::hasFreeLines):
     45        (bmalloc::SmallPage::setHasFreeLines):
     46        (bmalloc::SmallPage::ref):
     47        (bmalloc::SmallPage::deref):
     48        (bmalloc::Page::hasFreeLines): Deleted.
     49        (bmalloc::Page::setHasFreeLines): Deleted.
     50        (bmalloc::Page<Traits>::ref): Deleted.
     51        (bmalloc::Page<Traits>::deref): Deleted.
     52        * bmalloc/SmallTraits.h: Removed.
     53
    1542016-02-18  Geoffrey Garen  <ggaren@apple.com>
    255
  • trunk/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj

    r196845 r196847  
    3838                14DD789A18F48D4A00950702 /* Deallocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 145F685A179DC90200D65598 /* Deallocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
    3939                14DD789C18F48D4A00950702 /* BumpAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1413E462189DE1CD00546D68 /* BumpAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
    40                 14DD78B418F48D6B00950702 /* Chunk.h in Headers */ = {isa = PBXBuildFile; fileRef = 147AAA9418CE5CA6002201E4 /* Chunk.h */; settings = {ATTRIBUTES = (Private, ); }; };
    41                 14DD78B518F48D6B00950702 /* Line.h in Headers */ = {isa = PBXBuildFile; fileRef = 14DA32071885F9E6007269E0 /* Line.h */; settings = {ATTRIBUTES = (Private, ); }; };
    42                 14DD78BA18F48D6B00950702 /* Page.h in Headers */ = {isa = PBXBuildFile; fileRef = 146BEE2318C980D60002D5A2 /* Page.h */; settings = {ATTRIBUTES = (Private, ); }; };
    4340                14DD78BB18F48D6B00950702 /* SmallChunk.h in Headers */ = {isa = PBXBuildFile; fileRef = 147AAA8C18CD36A7002201E4 /* SmallChunk.h */; settings = {ATTRIBUTES = (Private, ); }; };
    4441                14DD78BC18F48D6B00950702 /* SmallLine.h in Headers */ = {isa = PBXBuildFile; fileRef = 1452478618BC757C00F80098 /* SmallLine.h */; settings = {ATTRIBUTES = (Private, ); }; };
    4542                14DD78BD18F48D6B00950702 /* SmallPage.h in Headers */ = {isa = PBXBuildFile; fileRef = 143E29ED18CAE90500FE8A0F /* SmallPage.h */; settings = {ATTRIBUTES = (Private, ); }; };
    46                 14DD78BE18F48D6B00950702 /* SmallTraits.h in Headers */ = {isa = PBXBuildFile; fileRef = 147AAA9718CE5FB6002201E4 /* SmallTraits.h */; settings = {ATTRIBUTES = (Private, ); }; };
    4743                14DD78C518F48D7500950702 /* Algorithm.h in Headers */ = {isa = PBXBuildFile; fileRef = 1421A87718EE462A00B4DD68 /* Algorithm.h */; settings = {ATTRIBUTES = (Private, ); }; };
    4844                14DD78C618F48D7500950702 /* AsyncTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 1417F65218BA88A00076FA3F /* AsyncTask.h */; settings = {ATTRIBUTES = (Private, ); }; };
    … …  
    114110                146BEE1E18C841C50002D5A2 /* SegregatedFreeList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SegregatedFreeList.h; path = bmalloc/SegregatedFreeList.h; sourceTree = "<group>"; };
    115111                146BEE2118C845AE0002D5A2 /* SegregatedFreeList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SegregatedFreeList.cpp; path = bmalloc/SegregatedFreeList.cpp; sourceTree = "<group>"; };
    116                 146BEE2318C980D60002D5A2 /* Page.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Page.h; path = bmalloc/Page.h; sourceTree = "<group>"; };
    117112                1479E21217A1A255006D4E9D /* Vector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = Vector.h; path = bmalloc/Vector.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
    118113                1479E21417A1A63E006D4E9D /* VMAllocate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = VMAllocate.h; path = bmalloc/VMAllocate.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
    119114                147AAA8818CD17CE002201E4 /* LargeChunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LargeChunk.h; path = bmalloc/LargeChunk.h; sourceTree = "<group>"; };
    120115                147AAA8C18CD36A7002201E4 /* SmallChunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SmallChunk.h; path = bmalloc/SmallChunk.h; sourceTree = "<group>"; };
    121                 147AAA9418CE5CA6002201E4 /* Chunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Chunk.h; path = bmalloc/Chunk.h; sourceTree = "<group>"; };
    122                 147AAA9718CE5FB6002201E4 /* SmallTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SmallTraits.h; path = bmalloc/SmallTraits.h; sourceTree = "<group>"; };
    123116                1485655E18A43AF900ED6942 /* BoundaryTag.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BoundaryTag.h; path = bmalloc/BoundaryTag.h; sourceTree = "<group>"; };
    124117                1485656018A43DBA00ED6942 /* ObjectType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ObjectType.h; path = bmalloc/ObjectType.h; sourceTree = "<group>"; };
    … …  
    134127                14D2CD9A1AA12CFB00770440 /* VMState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VMState.h; path = bmalloc/VMState.h; sourceTree = "<group>"; };
    135128                14D9DB4517F2447100EAAB79 /* FixedVector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = FixedVector.h; path = bmalloc/FixedVector.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
    136                 14DA32071885F9E6007269E0 /* Line.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = Line.h; path = bmalloc/Line.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
    137129                14DA320C18875B09007269E0 /* Heap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Heap.h; path = bmalloc/Heap.h; sourceTree = "<group>"; };
    138130                14DA320E18875D9F007269E0 /* Heap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Heap.cpp; path = bmalloc/Heap.cpp; sourceTree = "<group>"; };
    … …  
    194186                        isa = PBXGroup;
    195187                        children = (
    196                                 147AAA9418CE5CA6002201E4 /* Chunk.h */,
    197                                 14DA32071885F9E6007269E0 /* Line.h */,
    198                                 146BEE2318C980D60002D5A2 /* Page.h */,
    199188                                147AAA8C18CD36A7002201E4 /* SmallChunk.h */,
    200189                                1452478618BC757C00F80098 /* SmallLine.h */,
    201190                                143E29ED18CAE90500FE8A0F /* SmallPage.h */,
    202                                 147AAA9718CE5FB6002201E4 /* SmallTraits.h */,
    203191                        );
    204192                        name = "heap: small | medium";
    … …  
    304292                        buildActionMask = 2147483647;
    305293                        files = (
    306                                 14DD78B518F48D6B00950702 /* Line.h in Headers */,
    307294                                14DD78CF18F48D7500950702 /* Vector.h in Headers */,
    308295                                14C919C918FCC59F0028DB43 /* BPlatform.h in Headers */,
    … …  
    312299                                140FA00519CE4B6800FFD3C8 /* LineMetadata.h in Headers */,
    313300                                14DD78CC18F48D7500950702 /* PerThread.h in Headers */,
    314                                 14DD78B418F48D6B00950702 /* Chunk.h in Headers */,
    315301                                14DD78CA18F48D7500950702 /* Mutex.h in Headers */,
    316302                                143CB81D19022BC900B16A45 /* StaticMutex.h in Headers */,
    … …  
    323309                                14DD789C18F48D4A00950702 /* BumpAllocator.h in Headers */,
    324310                                14DD789918F48D4A00950702 /* Cache.h in Headers */,
    325                                 14DD78BE18F48D6B00950702 /* SmallTraits.h in Headers */,
    326311                                14DD789018F48CEB00950702 /* Sizes.h in Headers */,
    327312                                14DD78C718F48D7500950702 /* BAssert.h in Headers */,
    … …  
    331316                                14DD78CE18F48D7500950702 /* Syscall.h in Headers */,
    332317                                14DD78C618F48D7500950702 /* AsyncTask.h in Headers */,
    333                                 14DD78BA18F48D6B00950702 /* Page.h in Headers */,
    334318                                14DD78BB18F48D6B00950702 /* SmallChunk.h in Headers */,
    335319                                14DD78C918F48D7500950702 /* Inline.h in Headers */,
  • trunk/Source/bmalloc/bmalloc/Heap.cpp

    r196845 r196847  
    2828#include "LargeChunk.h"
    2929#include "LargeObject.h"
    30 #include "Line.h"
    31 #include "Page.h"
    3230#include "PerProcess.h"
    3331#include "SmallChunk.h"
     32#include "SmallLine.h"
     33#include "SmallPage.h"
    3434#include <thread>
    3535
    … …  
    5555        size_t line = 0;
    5656        while (object < vmPageSize) {
    57             line = object / SmallPage::lineSize;
    58             size_t leftover = object % SmallPage::lineSize;
     57            line = object / smallLineSize;
     58            size_t leftover = object % smallLineSize;
    5959
    6060            size_t objectCount;
    6161            size_t remainder;
    62             divideRoundingUp(SmallPage::lineSize - leftover, size, objectCount, remainder);
     62            divideRoundingUp(smallLineSize - leftover, size, objectCount, remainder);
    6363
    6464            metadata[line] = { static_cast<unsigned short>(leftover), static_cast<unsigned short>(objectCount) };
    … …  
    115115
    116116    // Find a free line.
    117     for (size_t lineNumber = 0; lineNumber < SmallPage::lineCount; ++lineNumber) {
     117    for (size_t lineNumber = 0; lineNumber < smallLineCount; ++lineNumber) {
    118118        if (lines[lineNumber].refCount(lock))
    119119            continue;
    … …  
    135135
    136136        // Merge with subsequent free lines.
    137         while (++lineNumber < SmallPage::lineCount) {
     137        while (++lineNumber < smallLineCount) {
    138138            if (lines[lineNumber].refCount(lock))
    139139                break;
  • trunk/Source/bmalloc/bmalloc/Heap.h

    r196845 r196847  
    8787    void scavengeLargeObjects(std::unique_lock<StaticMutex>&, std::chrono::milliseconds);
    8888
    89     std::array<std::array<LineMetadata, SmallPage::lineCount>, smallMax / alignment> m_smallLineMetadata;
     89    std::array<std::array<LineMetadata, smallLineCount>, smallMax / alignment> m_smallLineMetadata;
    9090
    9191    std::array<Vector<SmallPage*>, smallMax / alignment> m_smallPagesWithFreeLines;
  • trunk/Source/bmalloc/bmalloc/Sizes.h

    r196845 r196847  
    5959    static const size_t smallMax = 1024;
    6060    static const size_t smallLineSize = 256;
     61    static const size_t smallLineCount = vmPageSize / smallLineSize;
    6162    static const size_t smallLineMask = ~(smallLineSize - 1ul);
    6263
  • trunk/Source/bmalloc/bmalloc/SmallChunk.h

    r196845 r196847  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    … …  
    2424 */
    2525
    26 #ifndef Chunk_h
    27 #define Chunk_h
     26#ifndef SmallChunk_h
     27#define SmallChunk_h
    2828
    29 #include "ObjectType.h"
    3029#include "Sizes.h"
     30#include "SmallLine.h"
     31#include "SmallPage.h"
    3132#include "VMAllocate.h"
    3233
    3334namespace bmalloc {
    3435
    35 template<class Traits>
    36 class Chunk {
     36class SmallChunk {
    3737public:
    38     typedef typename Traits::PageType Page;
    39     typedef typename Traits::LineType Line;
     38    static SmallChunk* get(void*);
    4039
    41     static const size_t lineSize = Traits::lineSize;
    42     static const size_t chunkSize = Traits::chunkSize;
    43     static const size_t chunkOffset = Traits::chunkOffset;
    44     static const uintptr_t chunkMask = Traits::chunkMask;
    45 
    46     static Chunk* get(void*);
    47 
    48     Page* begin() { return Page::get(Line::get(m_memory)); }
    49     Page* end() { return &m_pages[pageCount]; }
     40    SmallPage* begin() { return SmallPage::get(SmallLine::get(m_memory)); }
     41    SmallPage* end() { return &m_pages[pageCount]; }
    5042   
    51     Line* lines() { return m_lines; }
    52     Page* pages() { return m_pages; }
     43    SmallLine* lines() { return m_lines; }
     44    SmallPage* pages() { return m_pages; }
    5345
    5446private:
    55     static_assert(!(vmPageSize % lineSize), "vmPageSize must be an even multiple of line size");
    56     static_assert(!(chunkSize % lineSize), "chunk size must be an even multiple of line size");
     47    static_assert(!(vmPageSize % smallLineSize), "vmPageSize must be an even multiple of line size");
     48    static_assert(!(smallChunkSize % smallLineSize), "chunk size must be an even multiple of line size");
    5749
    58     static const size_t lineCount = chunkSize / lineSize;
    59     static const size_t pageCount = chunkSize / vmPageSize;
     50    static const size_t lineCount = smallChunkSize / smallLineSize;
     51    static const size_t pageCount = smallChunkSize / vmPageSize;
    6052
    61     Line m_lines[lineCount];
    62     Page m_pages[pageCount];
     53    SmallLine m_lines[lineCount];
     54    SmallPage m_pages[pageCount];
    6355
    6456    // Align to vmPageSize to avoid sharing physical pages with metadata.
    … …  
    7567};
    7668
    77 template<class Traits>
    78 inline auto Chunk<Traits>::get(void* object) -> Chunk*
     69inline SmallChunk* SmallChunk::get(void* object)
    7970{
    8071    BASSERT(isSmall(object));
    81     return static_cast<Chunk*>(mask(object, chunkMask));
     72    return static_cast<SmallChunk*>(mask(object, smallChunkMask));
     73}
     74
     75inline SmallLine* SmallLine::get(void* object)
     76{
     77    BASSERT(isSmall(object));
     78    SmallChunk* chunk = SmallChunk::get(object);
     79    size_t lineNumber = (reinterpret_cast<char*>(object) - reinterpret_cast<char*>(chunk)) / smallLineSize;
     80    return &chunk->lines()[lineNumber];
     81}
     82
     83inline char* SmallLine::begin()
     84{
     85    SmallChunk* chunk = SmallChunk::get(this);
     86    size_t lineNumber = this - chunk->lines();
     87    size_t offset = lineNumber * smallLineSize;
     88    return &reinterpret_cast<char*>(chunk)[offset];
     89}
     90
     91inline char* SmallLine::end()
     92{
     93    return begin() + smallLineSize;
     94}
     95
     96inline SmallPage* SmallPage::get(SmallLine* line)
     97{
     98    SmallChunk* chunk = SmallChunk::get(line);
     99    size_t lineNumber = line - chunk->lines();
     100    size_t pageNumber = lineNumber * smallLineSize / vmPageSize;
     101    return &chunk->pages()[pageNumber];
     102}
     103
     104inline SmallLine* SmallPage::begin()
     105{
     106    SmallChunk* chunk = SmallChunk::get(this);
     107    size_t pageNumber = this - chunk->pages();
     108    size_t lineNumber = pageNumber * smallLineCount;
     109    return &chunk->lines()[lineNumber];
     110}
     111
     112inline SmallLine* SmallPage::end()
     113{
     114    return begin() + smallLineCount;
    82115}
    83116
  • trunk/Source/bmalloc/bmalloc/SmallLine.h

    r196845 r196847  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    … …  
    2424 */
    2525
    26 #ifndef Line_h
    27 #define Line_h
     26#ifndef SmallLine_h
     27#define SmallLine_h
    2828
    2929#include "BAssert.h"
    … …  
    3434namespace bmalloc {
    3535
    36 template<class Traits>
    37 class Line {
     36class SmallLine {
    3837public:
    39     typedef typename Traits::ChunkType Chunk;
     38    static const unsigned char maxRefCount = std::numeric_limits<unsigned char>::max();
     39    static_assert(smallLineSize / alignment < maxRefCount, "maximum object count must fit in Line");
    4040
    41     static const size_t minimumObjectSize = Traits::minimumObjectSize;
    42     static const size_t lineSize = Traits::lineSize;
    43    
    44     static const unsigned char maxRefCount = std::numeric_limits<unsigned char>::max();
    45     static_assert(lineSize / minimumObjectSize < maxRefCount, "maximum object count must fit in Line");
    46 
    47     static Line* get(void*);
     41    static SmallLine* get(void*);
    4842
    4943    void ref(std::lock_guard<StaticMutex>&, unsigned char);
    … …  
    5852};
    5953
    60 template<class Traits>
    61 inline auto Line<Traits>::get(void* object) -> Line*
    62 {
    63     BASSERT(isSmall(object));
    64     Chunk* chunk = Chunk::get(object);
    65     size_t lineNumber = (reinterpret_cast<char*>(object) - reinterpret_cast<char*>(chunk)) / lineSize;
    66     return &chunk->lines()[lineNumber];
    67 }
    68 
    69 template<class Traits>
    70 inline char* Line<Traits>::begin()
    71 {
    72     Chunk* chunk = Chunk::get(this);
    73     size_t lineNumber = this - chunk->lines();
    74     size_t offset = lineNumber * lineSize;
    75     return &reinterpret_cast<char*>(chunk)[offset];
    76 }
    77 
    78 template<class Traits>
    79 inline char* Line<Traits>::end()
    80 {
    81     return begin() + lineSize;
    82 }
    83 
    84 template<class Traits>
    85 inline void Line<Traits>::ref(std::lock_guard<StaticMutex>&, unsigned char refCount)
     54inline void SmallLine::ref(std::lock_guard<StaticMutex>&, unsigned char refCount)
    8655{
    8756    BASSERT(!m_refCount);
    … …  
    9059}
    9160
    92 template<class Traits>
    93 inline bool Line<Traits>::deref(std::lock_guard<StaticMutex>&)
     61inline bool SmallLine::deref(std::lock_guard<StaticMutex>&)
    9462{
    9563    BASSERT(m_refCount);
    … …  
    10068} // namespace bmalloc
    10169
    102 #endif // Line_h
     70#endif // SmallLine_h
  • trunk/Source/bmalloc/bmalloc/SmallPage.h

    r196845 r196847  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
    … …  
    2424 */
    2525
    26 #ifndef Page_h
    27 #define Page_h
     26#ifndef SmallPage_h
     27#define SmallPage_h
    2828
    2929#include "BAssert.h"
    … …  
    3434namespace bmalloc {
    3535
    36 template<typename Traits>
    37 class Page {
     36class SmallPage {
    3837public:
    39     typedef typename Traits::ChunkType Chunk;
    40     typedef typename Traits::LineType Line;
    41 
    42     static const size_t lineSize = Traits::lineSize;
    43     static const size_t lineCount = vmPageSize / lineSize;
    44 
    4538    static const unsigned char maxRefCount = std::numeric_limits<unsigned char>::max();
    46     static_assert(lineCount < maxRefCount, "maximum line count must fit in Page");
     39    static_assert(smallLineCount < maxRefCount, "maximum line count must fit in SmallPage");
    4740   
    48     static Page* get(Line*);
     41    static SmallPage* get(SmallLine*);
    4942
    5043    void ref(std::lock_guard<StaticMutex>&);
    … …  
    5851    void setHasFreeLines(std::lock_guard<StaticMutex>&, bool hasFreeLines) { m_hasFreeLines = hasFreeLines; }
    5952   
    60     Line* begin();
    61     Line* end();
     53    SmallLine* begin();
     54    SmallLine* end();
    6255
    6356private:
    … …  
    6760};
    6861
    69 template<typename Traits>
    70 inline void Page<Traits>::ref(std::lock_guard<StaticMutex>&)
     62inline void SmallPage::ref(std::lock_guard<StaticMutex>&)
    7163{
    7264    BASSERT(m_refCount < maxRefCount);
    … …  
    7466}
    7567
    76 template<typename Traits>
    77 inline bool Page<Traits>::deref(std::lock_guard<StaticMutex>&)
     68inline bool SmallPage::deref(std::lock_guard<StaticMutex>&)
    7869{
    7970    BASSERT(m_refCount);
    … …  
    8273}
    8374
    84 template<typename Traits>
    85 inline auto Page<Traits>::get(Line* line) -> Page*
    86 {
    87     Chunk* chunk = Chunk::get(line);
    88     size_t lineNumber = line - chunk->lines();
    89     size_t pageNumber = lineNumber * lineSize / vmPageSize;
    90     return &chunk->pages()[pageNumber];
    91 }
    92 
    93 template<typename Traits>
    94 inline auto Page<Traits>::begin() -> Line*
    95 {
    96     Chunk* chunk = Chunk::get(this);
    97     size_t pageNumber = this - chunk->pages();
    98     size_t lineNumber = pageNumber * lineCount;
    99     return &chunk->lines()[lineNumber];
    100 }
    101 
    102 template<typename Traits>
    103 inline auto Page<Traits>::end() -> Line*
    104 {
    105     return begin() + lineCount;
    106 }
    107 
    10875} // namespace bmalloc
    10976
    110 #endif // Page_h
     77#endif // SmallPage_h
Note: See TracChangeset for help on using the changeset viewer.