Title: [148891] trunk/Source
Revision
148891
Author
[email protected]
Date
2013-04-22 10:00:17 -0700 (Mon, 22 Apr 2013)

Log Message

Shrink baseline size of WTF::Vector on 64-bit by switching to unsigned capacity and size.
<http://webkit.org/b/97268>
<rdar://problem/12376519>

Reviewed by Sam Weinig.

Source/_javascript_Core:

Update LLInt WTF::Vector offset constants to match the new memory layout.

* llint/LowLevelInterpreter.asm:

Source/WebCore:

* CMakeLists.txt: Add a workaround for GCC 4.6.x in Release mode so it
does not crash.

Source/WTF:

Shrink Vector by 8 bytes on 64-bit by using 32-bit capacity and size.
Vector now inherits from VectorBuffer instead of having a VectorBuffer member;
this is necessary for m_size to fall into the padding after the base class members.

The WTF::Vector API still uses size_t.

Based on Blink r148313 by <[email protected]>.

* wtf/SizeLimits.cpp:
* wtf/Vector.h:
(WTF::VectorBufferBase::allocateBuffer):
(WTF::VectorBufferBase::tryAllocateBuffer):
(VectorBufferBase):
(WTF::VectorBuffer::shouldReallocateBuffer):
(Vector):
(WTF::Vector::Vector):
(WTF::Vector::capacity):
(WTF::Vector::at):
(WTF::Vector::data):
(WTF::Vector::swap):
(WTF::::Vector):
(WTF::::reserveCapacity):
(WTF::::tryReserveCapacity):
(WTF::::reserveInitialCapacity):
(WTF::::shrinkCapacity):
(WTF::::releaseBuffer):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (148890 => 148891)


--- trunk/Source/_javascript_Core/ChangeLog	2013-04-22 16:43:57 UTC (rev 148890)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-04-22 17:00:17 UTC (rev 148891)
@@ -1,3 +1,15 @@
+2013-04-22  Andreas Kling  <[email protected]>
+
+        Shrink baseline size of WTF::Vector on 64-bit by switching to unsigned capacity and size.
+        <http://webkit.org/b/97268>
+        <rdar://problem/12376519>
+
+        Reviewed by Sam Weinig.
+
+        Update LLInt WTF::Vector offset constants to match the new memory layout.
+
+        * llint/LowLevelInterpreter.asm:
+
 2013-04-21  Oliver Hunt  <[email protected]>
 
         JS Lexer and Parser should be more informative when they encounter errors

Modified: trunk/Source/_javascript_Core/llint/LowLevelInterpreter.asm (148890 => 148891)


--- trunk/Source/_javascript_Core/llint/LowLevelInterpreter.asm	2013-04-22 16:43:57 UTC (rev 148890)
+++ trunk/Source/_javascript_Core/llint/LowLevelInterpreter.asm	2013-04-22 17:00:17 UTC (rev 148891)
@@ -154,11 +154,11 @@
 end
 
 # This must match wtf/Vector.h
-const VectorSizeOffset = 0
+const VectorBufferOffset = 0
 if JSVALUE64
-    const VectorBufferOffset = 8
+    const VectorSizeOffset = 12
 else
-    const VectorBufferOffset = 4
+    const VectorSizeOffset = 8
 end
 
 

Modified: trunk/Source/WTF/ChangeLog (148890 => 148891)


--- trunk/Source/WTF/ChangeLog	2013-04-22 16:43:57 UTC (rev 148890)
+++ trunk/Source/WTF/ChangeLog	2013-04-22 17:00:17 UTC (rev 148891)
@@ -1,3 +1,38 @@
+2013-04-22  Andreas Kling  <[email protected]>
+
+        Shrink baseline size of WTF::Vector on 64-bit by switching to unsigned capacity and size.
+        <http://webkit.org/b/97268>
+        <rdar://problem/12376519>
+
+        Reviewed by Sam Weinig.
+
+        Shrink Vector by 8 bytes on 64-bit by using 32-bit capacity and size.
+        Vector now inherits from VectorBuffer instead of having a VectorBuffer member;
+        this is necessary for m_size to fall into the padding after the base class members.
+
+        The WTF::Vector API still uses size_t.
+
+        Based on Blink r148313 by <[email protected]>.
+
+        * wtf/SizeLimits.cpp:
+        * wtf/Vector.h:
+        (WTF::VectorBufferBase::allocateBuffer):
+        (WTF::VectorBufferBase::tryAllocateBuffer):
+        (VectorBufferBase):
+        (WTF::VectorBuffer::shouldReallocateBuffer):
+        (Vector):
+        (WTF::Vector::Vector):
+        (WTF::Vector::capacity):
+        (WTF::Vector::at):
+        (WTF::Vector::data):
+        (WTF::Vector::swap):
+        (WTF::::Vector):
+        (WTF::::reserveCapacity):
+        (WTF::::tryReserveCapacity):
+        (WTF::::reserveInitialCapacity):
+        (WTF::::shrinkCapacity):
+        (WTF::::releaseBuffer):
+
 2013-04-21  Filip Pizlo  <[email protected]>
 
         Memory barrier support should also ensure that we always do a compiler fence

Modified: trunk/Source/WTF/wtf/SizeLimits.cpp (148890 => 148891)


--- trunk/Source/WTF/wtf/SizeLimits.cpp	2013-04-22 16:43:57 UTC (rev 148890)
+++ trunk/Source/WTF/wtf/SizeLimits.cpp	2013-04-22 17:00:17 UTC (rev 148891)
@@ -60,6 +60,7 @@
 COMPILE_ASSERT(sizeof(RefCounted<int>) == sizeof(SameSizeAsRefCounted), RefCounted_should_stay_small);
 COMPILE_ASSERT(sizeof(RefCountedCustomAllocated<int>) == sizeof(SameSizeAsRefCounted), RefCountedCustomAllocated_should_stay_small);
 COMPILE_ASSERT(sizeof(RefPtr<RefCounted<int> >) == sizeof(int*), RefPtr_should_stay_small);
-COMPILE_ASSERT(sizeof(Vector<int>) == 3 * sizeof(int*), Vector_should_stay_small);
+COMPILE_ASSERT(sizeof(Vector<int>) == sizeof(int*) + 2 * sizeof(int), Vector_should_stay_small);
+COMPILE_ASSERT(sizeof(Vector<int, 1>) == 2 * sizeof(int*) + 2 * sizeof(int), Vector_should_stay_small);
 
 }

Modified: trunk/Source/WTF/wtf/Vector.h (148890 => 148891)


--- trunk/Source/WTF/wtf/Vector.h	2013-04-22 16:43:57 UTC (rev 148890)
+++ trunk/Source/WTF/wtf/Vector.h	2013-04-22 17:00:17 UTC (rev 148891)
@@ -253,7 +253,7 @@
         void allocateBuffer(size_t newCapacity)
         {
             ASSERT(newCapacity);
-            if (newCapacity > std::numeric_limits<size_t>::max() / sizeof(T))
+            if (newCapacity > std::numeric_limits<unsigned>::max() / sizeof(T))
                 CRASH();
             size_t sizeToAllocate = fastMallocGoodSize(newCapacity * sizeof(T));
             m_capacity = sizeToAllocate / sizeof(T);
@@ -263,7 +263,7 @@
         bool tryAllocateBuffer(size_t newCapacity)
         {
             ASSERT(newCapacity);
-            if (newCapacity > std::numeric_limits<size_t>::max() / sizeof(T))
+            if (newCapacity > std::numeric_limits<unsigned>::max() / sizeof(T))
                 return false;
 
             size_t sizeToAllocate = fastMallocGoodSize(newCapacity * sizeof(T));
@@ -335,7 +335,7 @@
         }
 
         T* m_buffer;
-        size_t m_capacity;
+        unsigned m_capacity;
     };
 
     template<typename T, size_t inlineCapacity>
@@ -439,7 +439,7 @@
         bool shouldReallocateBuffer(size_t newCapacity) const
         {
             // We cannot reallocate the inline buffer.
-            return Base::shouldReallocateBuffer(newCapacity) && std::min(m_capacity, newCapacity) > inlineCapacity;
+            return Base::shouldReallocateBuffer(newCapacity) && std::min(static_cast<size_t>(m_capacity), newCapacity) > inlineCapacity;
         }
 
         void reallocateBuffer(size_t newCapacity)
@@ -506,10 +506,10 @@
     };
 
     template<typename T, size_t inlineCapacity = 0, typename OverflowHandler = CrashOnOverflow>
-    class Vector {
+    class Vector : private VectorBuffer<T, inlineCapacity> {
         WTF_MAKE_FAST_ALLOCATED;
     private:
-        typedef VectorBuffer<T, inlineCapacity> Buffer;
+        typedef VectorBuffer<T, inlineCapacity> Base;
         typedef VectorTypeOperations<T> TypeOperations;
 
     public:
@@ -520,14 +520,14 @@
         typedef std::reverse_iterator<iterator> reverse_iterator;
         typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
 
-        Vector() 
+        Vector()
             : m_size(0)
         {
         }
         
-        explicit Vector(size_t size) 
-            : m_size(size)
-            , m_buffer(size)
+        explicit Vector(size_t size)
+            : Base(size)
+            , m_size(size)
         {
             if (begin())
                 TypeOperations::initialize(begin(), end());
@@ -553,30 +553,30 @@
 #endif
 
         size_t size() const { return m_size; }
-        size_t capacity() const { return m_buffer.capacity(); }
+        size_t capacity() const { return Base::capacity(); }
         bool isEmpty() const { return !size(); }
 
-        T& at(size_t i) 
+        T& at(size_t i)
         {
             if (UNLIKELY(i >= size()))
                 OverflowHandler::overflowed();
-            return m_buffer.buffer()[i]; 
+            return Base::buffer()[i];
         }
         const T& at(size_t i) const 
         {
             if (UNLIKELY(i >= size()))
                 OverflowHandler::overflowed();
-            return m_buffer.buffer()[i]; 
+            return Base::buffer()[i];
         }
         T& at(Checked<size_t> i)
         {
             RELEASE_ASSERT(i < size());
-            return m_buffer.buffer()[i];
+            return Base::buffer()[i];
         }
         const T& at(Checked<size_t> i) const
         {
             RELEASE_ASSERT(i < size());
-            return m_buffer.buffer()[i];
+            return Base::buffer()[i];
         }
 
         T& operator[](size_t i) { return at(i); }
@@ -584,8 +584,8 @@
         T& operator[](Checked<size_t> i) { return at(i); }
         const T& operator[](Checked<size_t> i) const { return at(i); }
 
-        T* data() { return m_buffer.buffer(); }
-        const T* data() const { return m_buffer.buffer(); }
+        T* data() { return Base::buffer(); }
+        const T* data() const { return Base::buffer(); }
 
         iterator begin() { return data(); }
         iterator end() { return begin() + m_size; }
@@ -643,8 +643,8 @@
         }
 
         Vector(size_t size, const T& val)
-            : m_size(size)
-            , m_buffer(size)
+            : Base(size)
+            , m_size(size)
         {
             if (begin())
                 TypeOperations::uninitializedFill(begin(), end(), val);
@@ -660,7 +660,7 @@
         void swap(Vector<T, inlineCapacity, OverflowHandler>& other)
         {
             std::swap(m_size, other.m_size);
-            m_buffer.swap(other.m_buffer);
+            Base::swap(other);
         }
 
         void reverse();
@@ -675,14 +675,24 @@
         template<typename U> U* expandCapacity(size_t newMinCapacity, U*); 
         template<typename U> void appendSlowCase(const U&);
 
-        size_t m_size;
-        Buffer m_buffer;
+        unsigned m_size;
+
+        using Base::buffer;
+        using Base::capacity;
+        using Base::swap;
+        using Base::allocateBuffer;
+        using Base::deallocateBuffer;
+        using Base::tryAllocateBuffer;
+        using Base::shouldReallocateBuffer;
+        using Base::reallocateBuffer;
+        using Base::restoreInlineBufferIfNeeded;
+        using Base::releaseBuffer;
     };
 
     template<typename T, size_t inlineCapacity, typename OverflowHandler>
     Vector<T, inlineCapacity, OverflowHandler>::Vector(const Vector& other)
-        : m_size(other.size())
-        , m_buffer(other.capacity())
+        : Base(other.capacity())
+        , m_size(other.size())
     {
         if (begin())
             TypeOperations::uninitializedCopy(other.begin(), other.end(), begin());
@@ -691,8 +701,8 @@
     template<typename T, size_t inlineCapacity, typename OverflowHandler>
     template<size_t otherCapacity, typename otherOverflowBehaviour>
     Vector<T, inlineCapacity, OverflowHandler>::Vector(const Vector<T, otherCapacity, otherOverflowBehaviour>& other)
-        : m_size(other.size())
-        , m_buffer(other.capacity())
+        : Base(other.capacity())
+        , m_size(other.size())
     {
         if (begin())
             TypeOperations::uninitializedCopy(other.begin(), other.end(), begin());
@@ -918,10 +928,10 @@
             return;
         T* oldBuffer = begin();
         T* oldEnd = end();
-        m_buffer.allocateBuffer(newCapacity);
+        Base::allocateBuffer(newCapacity);
         if (begin())
             TypeOperations::move(oldBuffer, oldEnd, begin());
-        m_buffer.deallocateBuffer(oldBuffer);
+        Base::deallocateBuffer(oldBuffer);
     }
     
     template<typename T, size_t inlineCapacity, typename OverflowHandler>
@@ -931,11 +941,11 @@
             return true;
         T* oldBuffer = begin();
         T* oldEnd = end();
-        if (!m_buffer.tryAllocateBuffer(newCapacity))
+        if (!Base::tryAllocateBuffer(newCapacity))
             return false;
         ASSERT(begin());
         TypeOperations::move(oldBuffer, oldEnd, begin());
-        m_buffer.deallocateBuffer(oldBuffer);
+        Base::deallocateBuffer(oldBuffer);
         return true;
     }
     
@@ -945,7 +955,7 @@
         ASSERT(!m_size);
         ASSERT(capacity() == inlineCapacity);
         if (initialCapacity > inlineCapacity)
-            m_buffer.allocateBuffer(initialCapacity);
+            Base::allocateBuffer(initialCapacity);
     }
     
     template<typename T, size_t inlineCapacity, typename OverflowHandler>
@@ -959,19 +969,19 @@
 
         T* oldBuffer = begin();
         if (newCapacity > 0) {
-            if (m_buffer.shouldReallocateBuffer(newCapacity)) {
-                m_buffer.reallocateBuffer(newCapacity);
+            if (Base::shouldReallocateBuffer(newCapacity)) {
+                Base::reallocateBuffer(newCapacity);
                 return;
             }
 
             T* oldEnd = end();
-            m_buffer.allocateBuffer(newCapacity);
+            Base::allocateBuffer(newCapacity);
             if (begin() != oldBuffer)
                 TypeOperations::move(oldBuffer, oldEnd, begin());
         }
 
-        m_buffer.deallocateBuffer(oldBuffer);
-        m_buffer.restoreInlineBufferIfNeeded();
+        Base::deallocateBuffer(oldBuffer);
+        Base::restoreInlineBufferIfNeeded();
     }
 
     // Templatizing these is better than just letting the conversion happen implicitly,
@@ -1158,7 +1168,7 @@
     template<typename T, size_t inlineCapacity, typename OverflowHandler>
     inline T* Vector<T, inlineCapacity, OverflowHandler>::releaseBuffer()
     {
-        T* buffer = m_buffer.releaseBuffer();
+        T* buffer = Base::releaseBuffer();
         if (inlineCapacity && !buffer && m_size) {
             // If the vector had some data, but no buffer to release,
             // that means it was using the inline buffer. In that case,

Modified: trunk/Source/WebCore/CMakeLists.txt (148890 => 148891)


--- trunk/Source/WebCore/CMakeLists.txt	2013-04-22 16:43:57 UTC (rev 148890)
+++ trunk/Source/WebCore/CMakeLists.txt	2013-04-22 17:00:17 UTC (rev 148891)
@@ -2553,6 +2553,20 @@
     xml/parser/XMLDocumentParserScope.cpp
 )
 
+# GCC 4.6.x crashes when building this file with -O3 and -DNDEBUG.
+# References: https://bugs.webkit.org/show_bug.cgi?id=97268
+#             https://bugs.webkit.org/show_bug.cgi?id=114627
+if (CMAKE_COMPILER_IS_GNUCXX) # Can restrict based on the version.
+    string(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _CXXFLAGS_VARNAME)
+
+    string(FIND ${_CXXFLAGS_VARNAME} "-O3" _CXXFLAGS_HAS_O3)
+    if (_CXXFLAGS_HAS_O3)
+        string(REPLACE "-O3" "-O2" _CXXFLAGS ${${_CXXFLAGS_VARNAME}})
+        set_source_files_properties(Modules/websockets/WebSocketDeflater.cpp
+                                    PROPERTIES COMPILE_FLAGS "${_CXXFLAGS}")
+    endif ()
+endif ()
+
 set(WebCore_CSS_PROPERTY_NAMES
     ${WEBCORE_DIR}/css/CSSPropertyNames.in
 )

Modified: trunk/Source/WebCore/ChangeLog (148890 => 148891)


--- trunk/Source/WebCore/ChangeLog	2013-04-22 16:43:57 UTC (rev 148890)
+++ trunk/Source/WebCore/ChangeLog	2013-04-22 17:00:17 UTC (rev 148891)
@@ -1,3 +1,14 @@
+2013-04-22  Andreas Kling  <[email protected]>
+
+        Shrink baseline size of WTF::Vector on 64-bit by switching to unsigned capacity and size.
+        <http://webkit.org/b/97268>
+        <rdar://problem/12376519>
+
+        Reviewed by Sam Weinig.
+
+        * CMakeLists.txt: Add a workaround for GCC 4.6.x in Release mode so it
+        does not crash.
+
 2013-04-22  John Griggs  <[email protected]>
 
         [BlackBerry] URL decode data: URLs before passing to the platform media player.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to