Changeset 141716 in webkit


Ignore:
Timestamp:
Feb 3, 2013 5:37:41 AM (11 years ago)
Author:
akling@apple.com
Message:

Vector should consult allocator about ideal size when choosing capacity.
<http://webkit.org/b/108410>
<rdar://problem/13124002>

Reviewed by Benjamin Poulain.

Source/JavaScriptCore:

Remove assertion about Vector capacity that won't hold anymore since capacity()
may not be what you passed to reserveCapacity().
Also export WTF::fastMallocGoodSize() for Windows builds.

  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCoreExports.def:
  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::CodeBlock):

Source/WTF:

Added WTF::fastMallocGoodSize(), a workalike/wrapper for OS X's malloc_good_size().
It returns the actual size of the block that will get allocated for a given byte size.

Vector's internal buffer now checks with the allocator if the resulting allocation
could actually house more objects and updates its capacity to make use of the space.

  • wtf/Deque.h:

(WTF::::expandCapacity):

  • wtf/FastMalloc.cpp:

(WTF::fastMallocGoodSize):

  • wtf/FastMalloc.h:
  • wtf/Vector.h:

(WTF::VectorBufferBase::allocateBuffer):
(WTF::VectorBufferBase::tryAllocateBuffer):
(WTF::VectorBufferBase::reallocateBuffer):

Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r141702 r141716  
     12013-02-02  Andreas Kling  <akling@apple.com>
     2
     3        Vector should consult allocator about ideal size when choosing capacity.
     4        <http://webkit.org/b/108410>
     5        <rdar://problem/13124002>
     6
     7        Reviewed by Benjamin Poulain.
     8
     9        Remove assertion about Vector capacity that won't hold anymore since capacity()
     10        may not be what you passed to reserveCapacity().
     11        Also export WTF::fastMallocGoodSize() for Windows builds.
     12
     13        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCoreExports.def:
     14        * bytecode/CodeBlock.cpp:
     15        (JSC::CodeBlock::CodeBlock):
     16
    1172013-02-02  Patrick Gansterer  <paroga@webkit.org>
    218
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCoreExports.def

    r141521 r141716  
    207207    ?fastFree@WTF@@YAXPAX@Z
    208208    ?fastMalloc@WTF@@YAPAXI@Z
     209    ?fastMallocGoodSize@WTF@@YAII@Z
    209210    ?fastMallocMatchFailed@Internal@WTF@@YAXPAX@Z
    210211    ?fastMallocSize@WTF@@YAIPBX@Z
  • trunk/Source/JavaScriptCore/bytecode/CodeBlock.cpp

    r141504 r141716  
    18211821        m_resolveOperations.grow(size);
    18221822    size_t putToBaseCount = unlinkedCodeBlock->numberOfPutToBaseOperations();
    1823     m_putToBaseOperations.reserveCapacity(putToBaseCount);
     1823    m_putToBaseOperations.reserveInitialCapacity(putToBaseCount);
    18241824    for (size_t i = 0; i < putToBaseCount; ++i)
    1825         m_putToBaseOperations.append(PutToBaseOperation(isStrictMode()));
    1826 
    1827     ASSERT(m_putToBaseOperations.capacity() == putToBaseCount);
     1825        m_putToBaseOperations.uncheckedAppend(PutToBaseOperation(isStrictMode()));
    18281826
    18291827    // Copy and translate the UnlinkedInstructions
  • trunk/Source/WTF/ChangeLog

    r141700 r141716  
     12013-02-02  Andreas Kling  <akling@apple.com>
     2
     3        Vector should consult allocator about ideal size when choosing capacity.
     4        <http://webkit.org/b/108410>
     5        <rdar://problem/13124002>
     6
     7        Reviewed by Benjamin Poulain.
     8
     9        Added WTF::fastMallocGoodSize(), a workalike/wrapper for OS X's malloc_good_size().
     10        It returns the actual size of the block that will get allocated for a given byte size.
     11
     12        Vector's internal buffer now checks with the allocator if the resulting allocation
     13        could actually house more objects and updates its capacity to make use of the space.
     14
     15        * wtf/Deque.h:
     16        (WTF::::expandCapacity):
     17        * wtf/FastMalloc.cpp:
     18        (WTF::fastMallocGoodSize):
     19        * wtf/FastMalloc.h:
     20        * wtf/Vector.h:
     21        (WTF::VectorBufferBase::allocateBuffer):
     22        (WTF::VectorBufferBase::tryAllocateBuffer):
     23        (WTF::VectorBufferBase::reallocateBuffer):
     24
    1252013-02-02  Mark Rowe  <mrowe@apple.com>
    226
  • trunk/Source/WTF/wtf/Deque.h

    r141504 r141716  
    384384        checkValidity();
    385385        size_t oldCapacity = m_buffer.capacity();
    386         size_t newCapacity = std::max(static_cast<size_t>(16), oldCapacity + oldCapacity / 4 + 1);
    387386        T* oldBuffer = m_buffer.buffer();
    388         m_buffer.allocateBuffer(newCapacity);
     387        m_buffer.allocateBuffer(std::max(static_cast<size_t>(16), oldCapacity + oldCapacity / 4 + 1));
    389388        if (m_start <= m_end)
    390389            TypeOperations::move(oldBuffer + m_start, oldBuffer + m_end, m_buffer.buffer() + m_start);
    391390        else {
    392391            TypeOperations::move(oldBuffer, oldBuffer + m_end, m_buffer.buffer());
    393             size_t newStart = newCapacity - (oldCapacity - m_start);
     392            size_t newStart = m_buffer.capacity() - (oldCapacity - m_start);
    394393            TypeOperations::move(oldBuffer + m_start, oldBuffer + oldCapacity, m_buffer.buffer() + newStart);
    395394            m_start = newStart;
  • trunk/Source/WTF/wtf/FastMalloc.cpp

    r141700 r141716  
    238238namespace WTF {
    239239
     240size_t fastMallocGoodSize(size_t bytes)
     241{
     242#if OS(DARWIN)
     243    return malloc_good_size(bytes);
     244#else
     245    return bytes;
     246#endif
     247}
     248
    240249TryMallocReturnValue tryFastMalloc(size_t n)
    241250{
     
    25572566
    25582567#define pageheap getPageHeap()
     2568
     2569size_t fastMallocGoodSize(size_t bytes)
     2570{
     2571    if (!phinited)
     2572        TCMalloc_ThreadCache::InitModule();
     2573    return AllocationSize(bytes);
     2574}
    25592575
    25602576#if USE_BACKGROUND_THREAD_TO_SCAVENGE_MEMORY
  • trunk/Source/WTF/wtf/FastMalloc.h

    r141504 r141716  
    3636    WTF_EXPORT_PRIVATE char* fastStrDup(const char*);
    3737    WTF_EXPORT_PRIVATE size_t fastMallocSize(const void*);
     38    WTF_EXPORT_PRIVATE size_t fastMallocGoodSize(size_t);
    3839
    3940    struct TryMallocReturnValue {
     
    224225using WTF::fastFree;
    225226using WTF::fastMalloc;
     227using WTF::fastMallocGoodSize;
    226228using WTF::fastMallocSize;
    227229using WTF::fastRealloc;
  • trunk/Source/WTF/wtf/Vector.h

    r141504 r141716  
    253253        {
    254254            ASSERT(newCapacity);
    255             m_capacity = newCapacity;
    256255            if (newCapacity > std::numeric_limits<size_t>::max() / sizeof(T))
    257256                CRASH();
    258             m_buffer = static_cast<T*>(fastMalloc(newCapacity * sizeof(T)));
     257            size_t sizeToAllocate = fastMallocGoodSize(newCapacity * sizeof(T));
     258            m_capacity = sizeToAllocate / sizeof(T);
     259            m_buffer = static_cast<T*>(fastMalloc(sizeToAllocate));
    259260        }
    260261
     
    265266                return false;
    266267
     268            size_t sizeToAllocate = fastMallocGoodSize(newCapacity * sizeof(T));
    267269            T* newBuffer;
    268             if (tryFastMalloc(newCapacity * sizeof(T)).getValue(newBuffer)) {
    269                 m_capacity = newCapacity;
     270            if (tryFastMalloc(sizeToAllocate).getValue(newBuffer)) {
     271                m_capacity = sizeToAllocate / sizeof(T);
    270272                m_buffer = newBuffer;
    271273                return true;
     
    282284        {
    283285            ASSERT(shouldReallocateBuffer(newCapacity));
    284             m_capacity = newCapacity;
    285286            if (newCapacity > std::numeric_limits<size_t>::max() / sizeof(T))
    286287                CRASH();
    287             m_buffer = static_cast<T*>(fastRealloc(m_buffer, newCapacity * sizeof(T)));
     288            size_t sizeToAllocate = fastMallocGoodSize(newCapacity * sizeof(T));
     289            m_capacity = sizeToAllocate / sizeof(T);
     290            m_buffer = static_cast<T*>(fastRealloc(m_buffer, sizeToAllocate));
    288291        }
    289292
Note: See TracChangeset for help on using the changeset viewer.