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

Changeset 180688 in webkit


Ignore:
Timestamp:
Feb 26, 2015, 11:30:11 AM (12 years ago)
Author:
ggaren@apple.com
Message:

bmalloc: free up a bit in BoundaryTag
https://bugs.webkit.org/show_bug.cgi?id=142048

Reviewed by Brady Eidson.

We were wasting a bit by accident, and I need one now.

  • bmalloc/Algorithm.h:

(bmalloc::rightShift): Deleted. Not needed, now that I've simplified
the math.

  • bmalloc/BoundaryTag.h: Since each boundary tag bucket is 1024 bytes

long, the maximum offset into a bucket is 1023.

You need 5 bits to count up to 1024, but only 4 to count up to 1023.

Math is hard.

(bmalloc::BoundaryTag::compactBegin): Switched to division because it
is simpler, and easier to match up with our ASSERT. The compiler will
turn division by constant power of two into a shift for us.

(bmalloc::BoundaryTag::setRange): Added an ASSERT for compactBegin
because we do encode it, so we should ASSERT that encoding did not
lose information.

  • bmalloc/Sizes.h: Shifting is no longer used since we use division

instead.

Location:
trunk/Source/bmalloc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/bmalloc/ChangeLog

    r180604 r180688  
     12015-02-26  Geoffrey Garen  <ggaren@apple.com>
     2
     3        bmalloc: free up a bit in BoundaryTag
     4        https://bugs.webkit.org/show_bug.cgi?id=142048
     5
     6        Reviewed by Brady Eidson.
     7
     8        We were wasting a bit by accident, and I need one now.
     9
     10        * bmalloc/Algorithm.h:
     11        (bmalloc::rightShift): Deleted. Not needed, now that I've simplified
     12        the math.
     13
     14        * bmalloc/BoundaryTag.h: Since each boundary tag bucket is 1024 bytes
     15        long, the maximum offset into a bucket is 1023.
     16
     17        You need 5 bits to count up to 1024, but only 4 to count up to 1023.
     18       
     19        Math is hard.
     20
     21        (bmalloc::BoundaryTag::compactBegin): Switched to division because it
     22        is simpler, and easier to match up with our ASSERT. The compiler will
     23        turn division by constant power of two into a shift for us.
     24
     25        (bmalloc::BoundaryTag::setRange): Added an ASSERT for compactBegin
     26        because we do encode it, so we should ASSERT that encoding did not
     27        lose information.
     28
     29        * bmalloc/Sizes.h: Shifting is no longer used since we use division
     30        instead.
     31
    1322015-02-24  Stephanie Lewis  <slewis@apple.com>
    233
  • trunk/Source/bmalloc/bmalloc/Algorithm.h

    r180359 r180688  
    5454}
    5555
    56 template<typename T> inline constexpr T rightShift(T value, uintptr_t shift)
    57 {
    58     return reinterpret_cast<T>(reinterpret_cast<uintptr_t>(value) >> shift);
    59 }
    60 
    6156template<typename T> inline constexpr bool test(T value, uintptr_t mask)
    6257{
  • trunk/Source/bmalloc/bmalloc/BoundaryTag.h

    r180576 r180688  
    6969private:
    7070    static const size_t flagBits = 3;
    71     static const size_t compactBeginBits = 5;
     71    static const size_t compactBeginBits = 4;
    7272    static const size_t sizeBits = bitCount<unsigned>() - flagBits - compactBeginBits;
    7373
    74     static_assert((1 << compactBeginBits) - 1 >= largeMin / largeAlignment, "compactBegin must be encodable in a BoundaryTag.");
    75     static_assert((1 << sizeBits) - 1 >= largeMax, "largeMax must be encodable in a BoundaryTag.");
     74    static_assert(
     75        (1 << compactBeginBits) - 1 >= (largeMin - 1) / largeAlignment,
     76        "compactBegin must be encodable in a BoundaryTag.");
     77
     78    static_assert(
     79        (1 << sizeBits) - 1 >= largeMax,
     80        "largeMax must be encodable in a BoundaryTag.");
    7681
    7782    bool m_isFree: 1;
     
    8590{
    8691    return static_cast<unsigned>(
    87         reinterpret_cast<uintptr_t>(
    88             rightShift(
    89                 mask(object, largeMin - 1), largeAlignmentShift)));
     92        reinterpret_cast<uintptr_t>(mask(object, largeMin - 1)) / largeAlignment);
    9093}
    9194
     
    9396{
    9497    m_compactBegin = compactBegin(range.begin());
     98    BASSERT(this->compactBegin() == compactBegin(range.begin()));
     99
    95100    m_size = static_cast<unsigned>(range.size());
    96101    BASSERT(this->size() == range.size());
  • trunk/Source/bmalloc/bmalloc/Sizes.h

    r179927 r180688  
    7777
    7878    static const size_t largeAlignment = 64;
    79     static const size_t largeAlignmentShift = 6;
    80     static_assert(1 << largeAlignmentShift == largeAlignment, "largeAlignmentShift be log2(largeAlignment).");
    8179    static const size_t largeMax = largeChunkSize * 99 / 100; // Plenty of room for metadata.
    8280    static const size_t largeMin = mediumMax;
Note: See TracChangeset for help on using the changeset viewer.