Title: [141407] trunk/Source
Revision
141407
Author
[email protected]
Date
2013-01-31 05:34:32 -0800 (Thu, 31 Jan 2013)

Log Message

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

Source/_javascript_Core:

Patch by Filip Pizlo <[email protected]> on 2013-01-30
Reviewed by Benjamin Poulain.

Remove assertion about Vector capacity that won't hold anymore since capacity()
may not be what you passed to reserveCapacity().

* bytecode/CodeBlock.cpp:
(JSC::CodeBlock::CodeBlock):

Source/WTF:

Reviewed by Benjamin Poulain.

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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (141406 => 141407)


--- trunk/Source/_javascript_Core/ChangeLog	2013-01-31 13:25:41 UTC (rev 141406)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-01-31 13:34:32 UTC (rev 141407)
@@ -1,5 +1,19 @@
 2013-01-30  Filip Pizlo  <[email protected]>
 
+        Vector should consult allocator about ideal size when choosing capacity.
+        <http://webkit.org/b/108410>
+        <rdar://problem/13124002>
+
+        Reviewed by Benjamin Poulain.
+
+        Remove assertion about Vector capacity that won't hold anymore since capacity()
+        may not be what you passed to reserveCapacity().
+
+        * bytecode/CodeBlock.cpp:
+        (JSC::CodeBlock::CodeBlock):
+
+2013-01-30  Andreas Kling  <[email protected]>
+
         DFG bytecode parser should have more assertions about the status of local accesses
         https://bugs.webkit.org/show_bug.cgi?id=108417
 

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp (141406 => 141407)


--- trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2013-01-31 13:25:41 UTC (rev 141406)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlock.cpp	2013-01-31 13:34:32 UTC (rev 141407)
@@ -1820,12 +1820,10 @@
     if (size_t size = unlinkedCodeBlock->numberOfResolveOperations())
         m_resolveOperations.grow(size);
     size_t putToBaseCount = unlinkedCodeBlock->numberOfPutToBaseOperations();
-    m_putToBaseOperations.reserveCapacity(putToBaseCount);
+    m_putToBaseOperations.reserveInitialCapacity(putToBaseCount);
     for (size_t i = 0; i < putToBaseCount; ++i)
-        m_putToBaseOperations.append(PutToBaseOperation(isStrictMode()));
+        m_putToBaseOperations.uncheckedAppend(PutToBaseOperation(isStrictMode()));
 
-    ASSERT(m_putToBaseOperations.capacity() == putToBaseCount);
-
     // Copy and translate the UnlinkedInstructions
     size_t instructionCount = unlinkedCodeBlock->instructions().size();
     UnlinkedInstruction* pc = unlinkedCodeBlock->instructions().data();

Modified: trunk/Source/WTF/ChangeLog (141406 => 141407)


--- trunk/Source/WTF/ChangeLog	2013-01-31 13:25:41 UTC (rev 141406)
+++ trunk/Source/WTF/ChangeLog	2013-01-31 13:34:32 UTC (rev 141407)
@@ -1,3 +1,27 @@
+2013-01-31  Andreas Kling  <[email protected]>
+
+        Vector should consult allocator about ideal size when choosing capacity.
+        <http://webkit.org/b/108410>
+        <rdar://problem/13124002>
+
+        Reviewed by Benjamin Poulain.
+
+        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):
+
 2013-01-30  Christophe Dumez  <[email protected]>
 
         Add a StringTypeAdapter for ASCIILiteral

Modified: trunk/Source/WTF/wtf/Deque.h (141406 => 141407)


--- trunk/Source/WTF/wtf/Deque.h	2013-01-31 13:25:41 UTC (rev 141406)
+++ trunk/Source/WTF/wtf/Deque.h	2013-01-31 13:34:32 UTC (rev 141407)
@@ -383,14 +383,13 @@
     {
         checkValidity();
         size_t oldCapacity = m_buffer.capacity();
-        size_t newCapacity = std::max(static_cast<size_t>(16), oldCapacity + oldCapacity / 4 + 1);
         T* oldBuffer = m_buffer.buffer();
-        m_buffer.allocateBuffer(newCapacity);
+        m_buffer.allocateBuffer(std::max(static_cast<size_t>(16), oldCapacity + oldCapacity / 4 + 1));
         if (m_start <= m_end)
             TypeOperations::move(oldBuffer + m_start, oldBuffer + m_end, m_buffer.buffer() + m_start);
         else {
             TypeOperations::move(oldBuffer, oldBuffer + m_end, m_buffer.buffer());
-            size_t newStart = newCapacity - (oldCapacity - m_start);
+            size_t newStart = m_buffer.capacity() - (oldCapacity - m_start);
             TypeOperations::move(oldBuffer + m_start, oldBuffer + oldCapacity, m_buffer.buffer() + newStart);
             m_start = newStart;
         }

Modified: trunk/Source/WTF/wtf/FastMalloc.cpp (141406 => 141407)


--- trunk/Source/WTF/wtf/FastMalloc.cpp	2013-01-31 13:25:41 UTC (rev 141406)
+++ trunk/Source/WTF/wtf/FastMalloc.cpp	2013-01-31 13:34:32 UTC (rev 141407)
@@ -237,6 +237,15 @@
 
 namespace WTF {
 
+size_t fastMallocGoodSize(size_t bytes)
+{
+#if OS(DARWIN)
+    return malloc_good_size(bytes);
+#else
+    return bytes;
+#endif
+}
+
 TryMallocReturnValue tryFastMalloc(size_t n) 
 {
     ASSERT(!isForbidden());
@@ -1027,6 +1036,11 @@
   }
 }
 
+size_t fastMallocGoodSize(size_t bytes)
+{
+    return AllocationSize(bytes);
+}
+
 // Information kept for a span (a contiguous run of pages).
 struct Span {
   PageID        start;          // Starting page number

Modified: trunk/Source/WTF/wtf/FastMalloc.h (141406 => 141407)


--- trunk/Source/WTF/wtf/FastMalloc.h	2013-01-31 13:25:41 UTC (rev 141406)
+++ trunk/Source/WTF/wtf/FastMalloc.h	2013-01-31 13:34:32 UTC (rev 141407)
@@ -35,6 +35,7 @@
     WTF_EXPORT_PRIVATE void* fastRealloc(void*, size_t);
     WTF_EXPORT_PRIVATE char* fastStrDup(const char*);
     WTF_EXPORT_PRIVATE size_t fastMallocSize(const void*);
+    WTF_EXPORT_PRIVATE size_t fastMallocGoodSize(size_t);
 
     struct TryMallocReturnValue {
         TryMallocReturnValue(void* data)

Modified: trunk/Source/WTF/wtf/Vector.h (141406 => 141407)


--- trunk/Source/WTF/wtf/Vector.h	2013-01-31 13:25:41 UTC (rev 141406)
+++ trunk/Source/WTF/wtf/Vector.h	2013-01-31 13:34:32 UTC (rev 141407)
@@ -252,10 +252,11 @@
         void allocateBuffer(size_t newCapacity)
         {
             ASSERT(newCapacity);
-            m_capacity = newCapacity;
             if (newCapacity > std::numeric_limits<size_t>::max() / sizeof(T))
                 CRASH();
-            m_buffer = static_cast<T*>(fastMalloc(newCapacity * sizeof(T)));
+            size_t sizeToAllocate = fastMallocGoodSize(newCapacity * sizeof(T));
+            m_capacity = sizeToAllocate / sizeof(T);
+            m_buffer = static_cast<T*>(fastMalloc(sizeToAllocate));
         }
 
         bool tryAllocateBuffer(size_t newCapacity)
@@ -264,9 +265,10 @@
             if (newCapacity > std::numeric_limits<size_t>::max() / sizeof(T))
                 return false;
 
+            size_t sizeToAllocate = fastMallocGoodSize(newCapacity * sizeof(T));
             T* newBuffer;
-            if (tryFastMalloc(newCapacity * sizeof(T)).getValue(newBuffer)) {
-                m_capacity = newCapacity;
+            if (tryFastMalloc(sizeToAllocate).getValue(newBuffer)) {
+                m_capacity = sizeToAllocate / sizeof(T);
                 m_buffer = newBuffer;
                 return true;
             }
@@ -281,10 +283,11 @@
         void reallocateBuffer(size_t newCapacity)
         {
             ASSERT(shouldReallocateBuffer(newCapacity));
-            m_capacity = newCapacity;
             if (newCapacity > std::numeric_limits<size_t>::max() / sizeof(T))
                 CRASH();
-            m_buffer = static_cast<T*>(fastRealloc(m_buffer, newCapacity * sizeof(T)));
+            size_t sizeToAllocate = fastMallocGoodSize(newCapacity * sizeof(T));
+            m_capacity = sizeToAllocate / sizeof(T);
+            m_buffer = static_cast<T*>(fastRealloc(m_buffer, sizeToAllocate));
         }
 
         void deallocateBuffer(T* bufferToDeallocate)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to