Changeset 196186 in webkit


Ignore:
Timestamp:
Feb 5, 2016, 1:34:27 PM (10 years ago)
Author:
sbarati@apple.com
Message:

bmalloc: largeMax calculation is wrong on iOS
https://bugs.webkit.org/show_bug.cgi?id=153923

Reviewed by Mark Lam.

Our number for largeMax was larger than what we had
space to actually allocate inside the LargeChunk. This made
it so that we would allocate a large object for something
that really should be extra large. Previously:
largeMax + sizeof(LargeChunk) > 1MB
which meant that when we would grow() to accommodate an allocation
of a particular size inside a LargeObject despite the fact that
the allocation size would be too large to actually fit in the LargeObject.
This would manifest when we had an allocation size in the range:
1MB - sizeof(LargeChunk) < allocation size < largeMax

We fix this bug by being precise in our calculation of largeMax
instead of just assuming largeChunkSize * 99/100 is enough
space for the metadata.

  • bmalloc/LargeChunk.h:

(bmalloc::LargeChunk::get):

  • bmalloc/Sizes.h:
Location:
trunk/Source/bmalloc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/bmalloc/ChangeLog

    r195942 r196186  
     12016-02-05  Saam barati  <sbarati@apple.com>
     2
     3        bmalloc: largeMax calculation is wrong on iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=153923
     5
     6        Reviewed by Mark Lam.
     7
     8        Our number for largeMax was larger than what we had
     9        space to actually allocate inside the LargeChunk. This made
     10        it so that we would allocate a large object for something
     11        that really should be extra large. Previously:
     12        largeMax + sizeof(LargeChunk) > 1MB
     13        which meant that when we would grow() to accommodate an allocation
     14        of a particular size inside a LargeObject despite the fact that
     15        the allocation size would be too large to actually fit in the LargeObject.
     16        This would manifest when we had an allocation size in the range:
     17        1MB - sizeof(LargeChunk) < allocation size < largeMax
     18
     19        We fix this bug by being precise in our calculation of largeMax
     20        instead of just assuming largeChunkSize * 99/100 is enough
     21        space for the metadata.
     22
     23        * bmalloc/LargeChunk.h:
     24        (bmalloc::LargeChunk::get):
     25        * bmalloc/Sizes.h:
     26
    1272016-01-31  Dan Bernstein  <mitz@apple.com>
    228
  • trunk/Source/bmalloc/bmalloc/LargeChunk.h

    r180037 r196186  
    7979};
    8080
     81static_assert(largeChunkMetadataSize == sizeof(LargeChunk), "'largeChunkMetadataSize' should be the same number as sizeof(LargeChunk) or our computation in Sizes.h for 'largeMax' is wrong");
     82static_assert(largeChunkMetadataSize + largeMax <= largeChunkSize, "We will think we can accommodate larger objects than we can in reality");
     83
    8184inline LargeChunk* LargeChunk::get(void* object)
    8285{
  • trunk/Source/bmalloc/bmalloc/Sizes.h

    r193373 r196186  
    7373
    7474    static const size_t largeChunkSize = superChunkSize / 2;
     75#if BPLATFORM(IOS)
     76    static const size_t largeChunkMetadataSize = 16 * kB;
     77#else
     78    static const size_t largeChunkMetadataSize = 4 * kB;
     79#endif
    7580    static const size_t largeChunkOffset = 0;
    7681    static const size_t largeChunkMask = ~(largeChunkSize - 1ul);
    7782
    7883    static const size_t largeAlignment = 64;
    79     static const size_t largeMax = largeChunkSize * 99 / 100; // Plenty of room for metadata.
     84    static const size_t largeMax = largeChunkSize - largeChunkMetadataSize;
    8085    static const size_t largeMin = mediumMax;
    8186   
  • trunk/Source/bmalloc/bmalloc/VMHeap.cpp

    r180960 r196186  
    5454
    5555    LargeChunk* largeChunk = superChunk->largeChunk();
    56     m_largeObjects.insert(LargeObject(LargeObject::init(largeChunk).begin()));
     56    LargeObject result(LargeObject::init(largeChunk).begin());
     57    BASSERT(result.size() == largeMax);
     58    m_largeObjects.insert(result);
    5759}
    5860
Note: See TracChangeset for help on using the changeset viewer.