Commit 8db55015 authored by akling@apple.com's avatar akling@apple.com

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/JavaScriptCore:

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 <cevans@chromium.org>.

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

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@148891 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 602619f9
2013-04-22 Andreas Kling <akling@apple.com>
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 <oliver@apple.com>
JS Lexer and Parser should be more informative when they encounter errors
......@@ -154,11 +154,11 @@ else
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
......
2013-04-22 Andreas Kling <akling@apple.com>
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 <cevans@chromium.org>.
* 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 <fpizlo@apple.com>
Memory barrier support should also ensure that we always do a compiler fence
......
......@@ -60,6 +60,7 @@ COMPILE_ASSERT(sizeof(PassRefPtr<RefCounted<int> >) == sizeof(int*), PassRefPtr_
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);
}
......@@ -253,7 +253,7 @@ namespace WTF {
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 @@ namespace WTF {
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 @@ namespace WTF {
}
T* m_buffer;
size_t m_capacity;
unsigned m_capacity;
};
template<typename T, size_t inlineCapacity>
......@@ -439,7 +439,7 @@ namespace WTF {
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 @@ namespace WTF {
};
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 @@ namespace WTF {
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 @@ namespace WTF {
#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 @@ namespace WTF {
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 @@ namespace WTF {
}
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 @@ namespace WTF {
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 @@ namespace WTF {
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 @@ namespace WTF {
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 @@ namespace WTF {
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 @@ namespace WTF {
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 @@ namespace WTF {
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 @@ namespace WTF {
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 @@ namespace WTF {
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,
......
......@@ -2553,6 +2553,20 @@ set(WebCore_SOURCES
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
)
......
2013-04-22 Andreas Kling <akling@apple.com>
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 <jgriggs@blackberry.com>
[BlackBerry] URL decode data: URLs before passing to the platform media player.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment