Diff
Modified: trunk/Source/WTF/ChangeLog (195140 => 195141)
--- trunk/Source/WTF/ChangeLog 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WTF/ChangeLog 2016-01-15 20:01:42 UTC (rev 195141)
@@ -1,3 +1,91 @@
+2016-01-15 Andreas Kling <[email protected]>
+
+ Fragmentation-free allocator for timeless and/or coupled allocations.
+ <https://webkit.org/b/152696>
+
+ Reviewed by Antti Koivisto.
+
+ Introduce BumpArena, a space-efficient memory allocator for situations where
+ you feel pretty confident betting on allocation lifetimes.
+
+ Basic design:
+
+ - Reserves 128MB range of memory at startup.
+ - Allocates 4kB-aligned blocks of 4kB from VM at a time.
+ - Bump-pointer allocates out of a block until it reaches end.
+ - Each allocation increments the ref-count of its block.
+ - Each deallocation decrements the ref-count of its block.
+ - Transparently falls back to fastMalloc()/fastFree() when needed.
+
+ Interface:
+
+ - BumpArena::create()
+
+ Create your very own BumpArena!
+
+ - BumpArena::allocate(BumpArena* arena, size_t size)
+
+ Allocates 'size' bytes of memory from 'arena'.
+ If 'arena' is null, falls back to fastMalloc().
+
+ - BumpArena::deallocate(void* ptr)
+
+ If 'ptr' is BumpArena allocation, decrements block ref-count.
+ If 'ptr' is FastMalloc allocation, calls fastFree() on it.
+
+ - WTF_MAKE_BUMPARENA_ALLOCATED;
+
+ Macro that gives a class or struct custom operators new and delete
+ for allocation out of BumpArena. Just like WTF_MAKE_FAST_ALLOCATED;
+
+ Note that while the name of this patch says "fragmentation-free allocator"
+ it will only be fragmentation-free when used for appropriate things.
+ This is not meant to be a general-purpose allocator. Only use it for sets of
+ allocations that are known to die roughly at the same time.
+
+ BumpArena will never resume allocating from a block that has been filled,
+ so it's even more important than usual that everything gets deallocated.
+
+ BumpArena redirects allocations to FastMalloc in three cases:
+
+ - When invoked with a null BumpArena*
+ - When allocation request is larger than BumpArena's block size (4kB)
+ - When BumpArena has exhausted all of its pre-reserved VM. (128MB)
+
+ The VM allocator will eagerly return blocks of VM to the kernel by calling
+ madvise(). Average time spent in madvise is around 0.007ms on my box.
+
+ * WTF.vcxproj/WTF.vcxproj:
+ * WTF.vcxproj/WTF.vcxproj.filters:
+ * WTF.xcodeproj/project.pbxproj:
+ * wtf/BumpArena.cpp: Added.
+ (WTF::BumpArena::Block::capacity):
+ (WTF::BumpArena::Block::arena):
+ (WTF::BumpArena::Block::payloadStart):
+ (WTF::arenas):
+ (WTF::BumpArena::Block::Block):
+ (WTF::BumpArena::Block::~Block):
+ (WTF::BumpArena::Block::ref):
+ (WTF::BlockAllocator::BlockAllocator):
+ (WTF::BlockAllocator::isAllocation):
+ (WTF::blockAllocator):
+ (WTF::BlockAllocator::allocateBlock):
+ (WTF::BlockAllocator::deallocateBlock):
+ (WTF::BumpArena::Block::deref):
+ (WTF::BumpArena::Block::create):
+ (WTF::BumpArena::Block::dump):
+ (WTF::BumpArena::dump):
+ (WTF::BumpArena::create):
+ (WTF::BumpArena::BumpArena):
+ (WTF::BumpArena::~BumpArena):
+ (WTF::BumpArena::allocateSlow):
+ (WTF::BumpArena::allocate):
+ (WTF::BumpArena::deallocate):
+ (WTF::BumpArena::Block::blockFor):
+ (WTF::BumpArena::arenaFor):
+ * wtf/BumpArena.h: Added.
+ * wtf/CMakeLists.txt:
+
2016-01-15 Konstantin Tokarev <[email protected]>
[EFL] WorkQueue methods should be defined inside WTF namespace.
Modified: trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj (195140 => 195141)
--- trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj 2016-01-15 20:01:42 UTC (rev 195141)
@@ -53,6 +53,7 @@
<ItemGroup>
<ClCompile Include="..\wtf\Assertions.cpp" />
<ClCompile Include="..\wtf\BitVector.cpp" />
+ <ClCompile Include="..\wtf\BumpArena.cpp" />
<ClCompile Include="..\wtf\CompilationThread.cpp" />
<ClCompile Include="..\wtf\CryptographicUtilities.cpp" />
<ClCompile Include="..\wtf\CryptographicallyRandomNumber.cpp" />
Modified: trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters (195140 => 195141)
--- trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters 2016-01-15 20:01:42 UTC (rev 195141)
@@ -120,6 +120,9 @@
<ClCompile Include="..\wtf\BitVector.cpp">
<Filter>wtf</Filter>
</ClCompile>
+ <ClCompile Include="..\wtf\BumpArena.cpp">
+ <Filter>wtf</Filter>
+ </ClCompile>
<ClCompile Include="..\wtf\CryptographicUtilities.cpp">
<Filter>wtf</Filter>
</ClCompile>
Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (195140 => 195141)
--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj 2016-01-15 20:01:42 UTC (rev 195141)
@@ -287,6 +287,8 @@
A8A47486151A825B004123FF /* WTFThreadData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8A4737A151A825B004123FF /* WTFThreadData.cpp */; };
A8A47487151A825B004123FF /* WTFThreadData.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A4737B151A825B004123FF /* WTFThreadData.h */; };
A8A4748C151A8264004123FF /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A4748B151A8264004123FF /* config.h */; };
+ AD9C50C11C3C1D5D005FBF1E /* BumpArena.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AD9C50BF1C3C1D5D005FBF1E /* BumpArena.cpp */; };
+ AD9C50C21C3C1D5D005FBF1E /* BumpArena.h in Headers */ = {isa = PBXBuildFile; fileRef = AD9C50C01C3C1D5D005FBF1E /* BumpArena.h */; settings = {ATTRIBUTES = (Private, ); }; };
B38FD7BD168953E80065C969 /* FeatureDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = B38FD7BC168953E80065C969 /* FeatureDefines.h */; };
C4F8A93719C65EB400B2B15D /* Stopwatch.h in Headers */ = {isa = PBXBuildFile; fileRef = C4F8A93619C65EB400B2B15D /* Stopwatch.h */; };
CD5497AC15857D0300B5BC30 /* MediaTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD5497AA15857D0300B5BC30 /* MediaTime.cpp */; };
@@ -600,6 +602,8 @@
A8A4737A151A825B004123FF /* WTFThreadData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WTFThreadData.cpp; sourceTree = "<group>"; };
A8A4737B151A825B004123FF /* WTFThreadData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WTFThreadData.h; sourceTree = "<group>"; };
A8A4748B151A8264004123FF /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
+ AD9C50BF1C3C1D5D005FBF1E /* BumpArena.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BumpArena.cpp; sourceTree = "<group>"; };
+ AD9C50C01C3C1D5D005FBF1E /* BumpArena.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BumpArena.h; sourceTree = "<group>"; };
B38FD7BC168953E80065C969 /* FeatureDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FeatureDefines.h; sourceTree = "<group>"; };
C4F8A93619C65EB400B2B15D /* Stopwatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Stopwatch.h; sourceTree = "<group>"; };
CD5497AA15857D0300B5BC30 /* MediaTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaTime.cpp; sourceTree = "<group>"; };
@@ -757,6 +761,8 @@
A8A47265151A825A004123FF /* BloomFilter.h */,
0F93274A1C17F4B700CF6564 /* Box.h */,
0F4570441BE834410062A629 /* BubbleSort.h */,
+ AD9C50BF1C3C1D5D005FBF1E /* BumpArena.cpp */,
+ AD9C50C01C3C1D5D005FBF1E /* BumpArena.h */,
A8A47267151A825A004123FF /* BumpPointerAllocator.h */,
EB95E1EF161A72410089A2F5 /* ByteOrder.h */,
A8A4726A151A825A004123FF /* CheckedArithmetic.h */,
@@ -1261,6 +1267,7 @@
A8A4742C151A825B004123FF /* StringExtras.h in Headers */,
A8A4743F151A825B004123FF /* StringHash.h in Headers */,
A748745417A0BDAE00FA04CB /* StringHashDumpContext.h in Headers */,
+ AD9C50C21C3C1D5D005FBF1E /* BumpArena.h in Headers */,
A8A47441151A825B004123FF /* StringImpl.h in Headers */,
A8A47442151A825B004123FF /* StringOperators.h in Headers */,
0FDDBFA81666DFA300C55FEF /* StringPrintStream.h in Headers */,
@@ -1404,6 +1411,7 @@
A5BA15FA182435A600A82E69 /* AtomicStringImplCF.cpp in Sources */,
9BC70F05176C379D00101DEC /* AtomicStringTable.cpp in Sources */,
1469419D16EAB10A0024E146 /* AutodrainedPoolMac.mm in Sources */,
+ AD9C50C11C3C1D5D005FBF1E /* BumpArena.cpp in Sources */,
8134013815B092FD001FF0B8 /* Base64.cpp in Sources */,
A8A473A8151A825B004123FF /* bignum-dtoa.cc in Sources */,
A8A473AA151A825B004123FF /* bignum.cc in Sources */,
Added: trunk/Source/WTF/wtf/BumpArena.cpp (0 => 195141)
--- trunk/Source/WTF/wtf/BumpArena.cpp (rev 0)
+++ trunk/Source/WTF/wtf/BumpArena.cpp 2016-01-15 20:01:42 UTC (rev 195141)
@@ -0,0 +1,368 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "BumpArena.h"
+
+#include <wtf/HashSet.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/Vector.h>
+
+#if OS(UNIX)
+#define USE_BUMPARENA 1
+#include <sys/mman.h>
+#else
+#define USE_BUMPARENA 0
+#endif
+
+#if OS(DARWIN)
+#include <mach/vm_statistics.h>
+// FIXME: Figure out which VM tag to use.
+#define BUMPARENA_VM_TAG VM_MAKE_TAG(VM_MEMORY_APPLICATION_SPECIFIC_1)
+#else
+#define BUMPARENA_VM_TAG -1
+#endif
+
+#if DEBUG_BUMPARENA
+#include <notify.h>
+#endif
+
+namespace WTF {
+
+#if USE(BUMPARENA)
+
+static const size_t blockSize = 4096;
+static const size_t blockMask = ~(blockSize - 1);
+
+class BumpArena::Block {
+public:
+ static constexpr size_t capacity() { return blockSize - sizeof(Block); }
+
+ static RefPtr<Block> create(BumpArena&);
+ ~Block();
+
+ void ref();
+ void deref();
+
+ BumpArena& arena() { return m_arena.get(); }
+
+ static Block& blockFor(const void*);
+
+ char* payloadStart() { return reinterpret_cast<char*>(&m_data); }
+
+#if DEBUG_BUMPARENA
+ void dump();
+#endif
+
+private:
+ friend class BumpArena;
+ explicit Block(BumpArena&);
+
+ Ref<BumpArena> m_arena;
+
+ unsigned m_refCount { 1 };
+
+#if DEBUG_BUMPARENA
+ size_t m_bytesAvailable { 0 };
+#endif
+
+#if COMPILER(MSVC)
+#pragma warning(push)
+#pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning
+#endif
+ char* m_data[0];
+#if COMPILER(MSVC)
+#pragma warning(pop)
+#endif
+};
+
+#if DEBUG_BUMPARENA
+static HashSet<BumpArena*>& arenas()
+{
+ static NeverDestroyed<HashSet<BumpArena*>> set;
+ return set;
+}
+#endif
+
+BumpArena::Block::Block(BumpArena& arena)
+ : m_arena(arena)
+{
+#if DEBUG_BUMPARENA
+ m_arena->m_liveBlocks.add(this);
+#endif
+}
+
+BumpArena::Block::~Block()
+{
+#if DEBUG_BUMPARENA
+ m_arena->m_liveBlocks.remove(this);
+#endif
+}
+
+void BumpArena::Block::ref()
+{
+ ++m_refCount;
+}
+
+struct BlockAllocator {
+ static const size_t vmSize = 128 * MB;
+
+ BlockAllocator();
+
+ void* allocateBlock();
+ void deallocateBlock(void*);
+
+ bool isAllocation(const void* p) const;
+
+ char* vmBase;
+ char* vmEnd;
+ char* nextBlock;
+ Vector<void*> freeList;
+};
+
+BlockAllocator::BlockAllocator()
+{
+ vmBase = reinterpret_cast<char*>(mmap(0, vmSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, BUMPARENA_VM_TAG, 0));
+ RELEASE_ASSERT(vmBase != MAP_FAILED);
+ vmEnd = vmBase + vmSize;
+ nextBlock = reinterpret_cast<char*>(roundUpToMultipleOf<blockSize>(reinterpret_cast<uintptr_t>(vmBase)));
+}
+
+bool BlockAllocator::isAllocation(const void* p) const
+{
+ return p >= vmBase && p <= vmEnd;
+}
+
+static BlockAllocator& blockAllocator()
+{
+ static NeverDestroyed<BlockAllocator> allocator;
+ return allocator;
+}
+
+void* BlockAllocator::allocateBlock()
+{
+ if (!freeList.isEmpty()) {
+ void* block = freeList.takeLast();
+#if OS(DARWIN)
+ while (madvise(block, blockSize, MADV_FREE_REUSE) == -1 && errno == EAGAIN) { }
+#else
+ while (madvise(block, blockSize, MADV_NORMAL) == -1 && errno == EAGAIN) { }
+#endif
+ return block;
+ }
+ char* newNextBlock = nextBlock + blockSize;
+ if (newNextBlock >= vmEnd)
+ return nullptr;
+ void* block = nextBlock;
+ nextBlock += blockSize;
+ return block;
+}
+
+void BlockAllocator::deallocateBlock(void* block)
+{
+#if OS(DARWIN)
+ while (madvise(block, blockSize, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
+#else
+ while (madvise(block, blockSize, MADV_DONTNEED) == -1 && errno == EAGAIN) { }
+#endif
+ freeList.append(block);
+}
+
+void BumpArena::Block::deref()
+{
+ --m_refCount;
+
+ if (!m_refCount) {
+ this->~Block();
+ blockAllocator().deallocateBlock(this);
+ } else if (m_refCount == 1 && m_arena->m_currentBlock == this) {
+ m_arena->m_currentPayloadEnd = nullptr;
+ m_arena->m_currentRemaining = 0;
+ // Break the ref-cycle between BumpArena and this Block.
+ m_arena->m_currentBlock = nullptr;
+ }
+}
+
+RefPtr<BumpArena::Block> BumpArena::Block::create(BumpArena& arena)
+{
+ void* allocation = blockAllocator().allocateBlock();
+ if (!allocation)
+ return nullptr;
+ return adoptRef(*new (NotNull, allocation) Block(arena));
+}
+
+#if DEBUG_BUMPARENA
+void BumpArena::Block::dump()
+{
+ WTFLogAlways(" %10s %p - %3u, %8lu bytes available\n", m_arena->m_currentBlock == this ? "[current]" : "", this, m_refCount, m_bytesAvailable);
+}
+
+void BumpArena::dump()
+{
+ WTFLogAlways("BumpArena{%p}", this);
+ WTFLogAlways(" refCount: %u\n", refCount());
+ WTFLogAlways(" Blocks (%d)\n", m_liveBlocks.size());
+ for (Block* block : m_liveBlocks) {
+ if (block == m_currentBlock)
+ continue;
+ block->dump();
+ }
+ if (m_currentBlock)
+ m_currentBlock->dump();
+}
+#endif
+
+Ref<BumpArena> BumpArena::create()
+{
+ return adoptRef(*new BumpArena);
+}
+
+BumpArena::BumpArena()
+{
+#if DEBUG_BUMPARENA
+ arenas().add(this);
+ static std::once_flag once;
+ std::call_once(once, [] {
+ int d;
+ notify_register_dispatch("com.apple.WebKit.BumpArena.Dump", &d, dispatch_get_main_queue(), ^(int) {
+ for (BumpArena* arena : arenas())
+ arena->dump();
+ });
+ });
+#endif
+}
+
+BumpArena::~BumpArena()
+{
+#if DEBUG_BUMPARENA
+ arenas().remove(this);
+#endif
+}
+
+void* BumpArena::allocateSlow(size_t size)
+{
+ if (size > Block::capacity())
+ return fastMalloc(size);
+
+ m_currentBlock = Block::create(*this);
+ if (!m_currentBlock) {
+ m_currentPayloadEnd = nullptr;
+ m_currentRemaining = 0;
+ return fastMalloc(size);
+ }
+
+ m_currentPayloadEnd = m_currentBlock->payloadStart() + Block::capacity();
+ m_currentRemaining = Block::capacity() - size;
+#if DEBUG_BUMPARENA
+ m_currentBlock->m_bytesAvailable = m_currentRemaining;
+#endif
+ m_currentBlock->ref();
+ return m_currentPayloadEnd - m_currentRemaining - size;
+}
+
+void* BumpArena::allocate(size_t size)
+{
+ size = roundUpToMultipleOf<8>(size);
+ size_t currentRemaining = m_currentRemaining;
+ if (size > currentRemaining)
+ return allocateSlow(size);
+ currentRemaining -= size;
+ m_currentRemaining = currentRemaining;
+#if DEBUG_BUMPARENA
+ m_currentBlock->m_bytesAvailable = m_currentRemaining;
+#endif
+ m_currentBlock->ref();
+ return m_currentPayloadEnd - currentRemaining - size;
+}
+
+void BumpArena::deallocate(void* p)
+{
+ if (!p)
+ return;
+ if (blockAllocator().isAllocation(p))
+ Block::blockFor(p).deref();
+ else
+ fastFree(p);
+}
+
+BumpArena::Block& BumpArena::Block::blockFor(const void* p)
+{
+ return *reinterpret_cast<Block*>(reinterpret_cast<uintptr_t>(p) & blockMask);
+}
+
+BumpArena* BumpArena::arenaFor(const void* p)
+{
+ ASSERT(p);
+ if (!blockAllocator().isAllocation(p))
+ return nullptr;
+ return &Block::blockFor(p).arena();
+}
+
+void* BumpArena::allocate(BumpArena* arena, size_t size)
+{
+ if (arena)
+ return arena->allocate(size);
+ return fastMalloc(size);
+}
+
+#else // !USE(BUMPARENA) below
+
+class BumpArena::Block {
+public:
+ void ref() { }
+ void deref() { }
+};
+
+Ref<BumpArena> BumpArena::create()
+{
+ return adoptRef(*new BumpArena);
+}
+
+BumpArena::BumpArena()
+{
+}
+
+BumpArena::~BumpArena()
+{
+}
+
+BumpArena* BumpArena::arenaFor(const void*)
+{
+ return nullptr;
+}
+
+void* BumpArena::allocate(BumpArena*, size_t size)
+{
+ return fastMalloc(size);
+}
+
+void BumpArena::deallocate(void* p)
+{
+ fastFree(p);
+}
+
+#endif
+
+} // namespace WTF
Added: trunk/Source/WTF/wtf/BumpArena.h (0 => 195141)
--- trunk/Source/WTF/wtf/BumpArena.h (rev 0)
+++ trunk/Source/WTF/wtf/BumpArena.h 2016-01-15 20:01:42 UTC (rev 195141)
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef BumpArena_h
+#define BumpArena_h
+
+#include <wtf/HashSet.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+#define DEBUG_BUMPARENA 0
+
+namespace WTF {
+
+class BumpArena : public RefCounted<BumpArena> {
+public:
+ WTF_EXPORT_PRIVATE static Ref<BumpArena> create();
+ WTF_EXPORT_PRIVATE ~BumpArena();
+
+ WTF_EXPORT_PRIVATE static void* allocate(BumpArena*, size_t);
+ WTF_EXPORT_PRIVATE static void deallocate(void*);
+
+ WTF_EXPORT_PRIVATE static BumpArena* arenaFor(const void*);
+
+private:
+ BumpArena();
+ void* allocate(size_t);
+ void* allocateSlow(size_t);
+
+ class Block;
+ friend class Block;
+ RefPtr<Block> m_currentBlock;
+
+ char* m_currentPayloadEnd { nullptr };
+ size_t m_currentRemaining { 0 };
+
+#if DEBUG_BUMPARENA
+ void dump();
+ HashSet<Block*> m_liveBlocks;
+#endif
+};
+
+#define WTF_MAKE_BUMPARENA_ALLOCATED \
+public: \
+ void* operator new(size_t, void* p) { return p; } \
+ void* operator new[](size_t, void* p) { return p; } \
+ \
+ void* operator new(size_t size) \
+ { \
+ return ::WTF::BumpArena::allocate(nullptr, size); \
+ } \
+ void* operator new(size_t size, BumpArena* arena) \
+ { \
+ return ::WTF::BumpArena::allocate(arena, size); \
+ } \
+ void operator delete(void* p) \
+ { \
+ ::WTF::BumpArena::deallocate(p); \
+ } \
+ \
+ void* operator new[](size_t size) \
+ { \
+ return ::WTF::BumpArena::allocate(nullptr, size); \
+ } \
+ \
+ void operator delete[](void* p) \
+ { \
+ ::WTF::BumpArena::deallocate(p); \
+ } \
+ void* operator new(size_t, NotNullTag, void* location) \
+ { \
+ ASSERT(location); \
+ return location; \
+ } \
+private: \
+typedef int __thisIsHereToForceASemicolonAfterThisMacro
+
+} // namespace WTF
+
+using WTF::BumpArena;
+
+#endif
Modified: trunk/Source/WTF/wtf/CMakeLists.txt (195140 => 195141)
--- trunk/Source/WTF/wtf/CMakeLists.txt 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WTF/wtf/CMakeLists.txt 2016-01-15 20:01:42 UTC (rev 195141)
@@ -7,6 +7,7 @@
BitVector.h
Bitmap.h
BubbleSort.h
+ BumpArena.h
BumpPointerAllocator.h
ByteOrder.h
CompilationThread.h
@@ -153,6 +154,7 @@
Assertions.cpp
Atomics.cpp
BitVector.cpp
+ BumpArena.cpp
CompilationThread.cpp
CryptographicUtilities.cpp
CryptographicallyRandomNumber.cpp
Modified: trunk/Source/WebCore/ChangeLog (195140 => 195141)
--- trunk/Source/WebCore/ChangeLog 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/ChangeLog 2016-01-15 20:01:42 UTC (rev 195141)
@@ -1,3 +1,83 @@
+2016-01-15 Andreas Kling <[email protected]>
+
+ Use BumpArena for style sheet object tree.
+ <https://webkit.org/b/152696>
+
+ Reviewed by Antti Koivisto.
+
+ Give each StyleSheetContents its own BumpArena, and plumb it down through CSSParser
+ to allocate StyleRule, StyleProperties and CSSSelectorList's selector arrays there.
+
+ This basically means that most objects that make up a given style sheet will end up
+ in one (or a few) contiguous region(s) of memory, instead of being scattered all
+ over the malloc heap.
+
+ In the common case (no CSSOM manipulation), the lifetimes of these objects are very
+ predictable: everything tends to die when the StyleSheetContents dies.
+ This dramatically improves space-efficiency in those cases, and allows us to return
+ contiguous chunks of memory to the system once a style sheet is no longer needed.
+
+ One-off CSS parses that don't work within a StyleSheetContents context will have
+ their StyleRules & co allocated through FastMalloc just like before.
+
+ Bonus: give SelectorQueryCache a dedicated BumpArena as well, since it has very
+ predictable lifetime.
+
+ * css/CSSGrammar.y.in:
+ * css/CSSKeyframesRule.h:
+ (WebCore::StyleRuleKeyframes::create):
+ * css/CSSParser.cpp:
+ (WebCore::CSSParser::createStyleProperties):
+ (WebCore::CSSParser::createMediaRule):
+ (WebCore::CSSParser::createSupportsRule):
+ (WebCore::CSSParser::createKeyframesRule):
+ (WebCore::CSSParser::setArena):
+ (WebCore::CSSParser::arena):
+ (WebCore::CSSParser::createStyleRule):
+ (WebCore::CSSParser::createFontFaceRule):
+ (WebCore::CSSParser::createPageRule):
+ (WebCore::CSSParser::createRegionRule):
+ (WebCore::CSSParser::createViewportRule):
+ * css/CSSParser.h:
+ * css/CSSParserValues.cpp:
+ (WebCore::CSSParserSelector::parsePseudoElementCueFunctionSelector):
+ (WebCore::CSSParserSelector::adoptSelectorVector):
+ * css/CSSParserValues.h:
+ * css/CSSSelectorList.cpp:
+ (WebCore::CSSSelectorList::CSSSelectorList):
+ (WebCore::CSSSelectorList::adoptSelectorVector):
+ (WebCore::CSSSelectorList::deleteSelectors):
+ * css/CSSSelectorList.h:
+ * css/StyleProperties.cpp:
+ (WebCore::ImmutableStyleProperties::create):
+ (WebCore::StyleProperties::immutableCopyIfNeeded):
+ * css/StyleProperties.h:
+ * css/StyleRule.cpp:
+ (WebCore::StyleRule::create):
+ (WebCore::StyleRule::splitIntoMultipleRulesWithMaximumSelectorComponentCount):
+ (WebCore::StyleRuleRegion::StyleRuleRegion):
+ * css/StyleRule.h:
+ (WebCore::StyleRule::create):
+ (WebCore::StyleRule::parserAdoptSelectorVector):
+ (WebCore::StyleRuleFontFace::create):
+ (WebCore::StyleRulePage::create):
+ (WebCore::StyleRulePage::parserAdoptSelectorVector):
+ (WebCore::StyleRuleMedia::create):
+ (WebCore::StyleRuleSupports::create):
+ (WebCore::StyleRuleRegion::create):
+ (WebCore::StyleRuleViewport::create):
+ * css/StyleSheetContents.cpp:
+ (WebCore::StyleSheetContents::StyleSheetContents):
+ (WebCore::StyleSheetContents::parseAuthorStyleSheet):
+ (WebCore::StyleSheetContents::parseStringAtPosition):
+ * css/StyleSheetContents.h:
+ * dom/SelectorQuery.cpp:
+ (WebCore::SelectorQueryCache::SelectorQueryCache):
+ (WebCore::SelectorQueryCache::add):
+ * dom/SelectorQuery.h:
+ * svg/SVGFontFaceElement.cpp:
+ (WebCore::SVGFontFaceElement::SVGFontFaceElement):
+
2016-01-15 Dave Hyatt <[email protected]>
Avoid downloading the wrong image for <picture> elements.
Modified: trunk/Source/WebCore/css/CSSGrammar.y.in (195140 => 195141)
--- trunk/Source/WebCore/css/CSSGrammar.y.in 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/CSSGrammar.y.in 2016-01-15 20:01:42 UTC (rev 195141)
@@ -403,7 +403,7 @@
WEBKIT_SELECTOR_SYM '{' maybe_space selector_list '}' {
if ($4) {
if (parser->m_selectorListForParseSelector)
- parser->m_selectorListForParseSelector->adoptSelectorVector(*$4);
+ parser->m_selectorListForParseSelector->adoptSelectorVector(parser->arena(), *$4);
parser->recycleSelectorVector(std::unique_ptr<Vector<std::unique_ptr<CSSParserSelector>>>($4));
}
}
@@ -1353,7 +1353,7 @@
#if ENABLE_VIDEO_TRACK
// used by ::cue(:past/:future)
| ':' ':' CUEFUNCTION maybe_space simple_selector_list maybe_space ')' {
- $$ = CSSParserSelector::parsePseudoElementCueFunctionSelector($3, $5);
+ $$ = CSSParserSelector::parsePseudoElementCueFunctionSelector(parser->arena(), $3, $5);
}
#endif
// use by :-webkit-any.
@@ -1366,7 +1366,7 @@
if ($4) {
auto selector = std::make_unique<CSSParserSelector>();
selector->setMatch(CSSSelector::PseudoClass);
- selector->adoptSelectorVector(*std::unique_ptr<Vector<std::unique_ptr<CSSParserSelector>>>($4));
+ selector->adoptSelectorVector(parser->arena(), *std::unique_ptr<Vector<std::unique_ptr<CSSParserSelector>>>($4));
selector->setPseudoClassValue($2);
if (selector->pseudoClassType() == CSSSelector::PseudoClassAny)
$$ = selector.release();
@@ -1377,7 +1377,7 @@
if ($4) {
auto selector = std::make_unique<CSSParserSelector>();
selector->setMatch(CSSSelector::PseudoClass);
- selector->adoptSelectorVector(*std::unique_ptr<Vector<std::unique_ptr<CSSParserSelector>>>($4));
+ selector->adoptSelectorVector(parser->arena(), *std::unique_ptr<Vector<std::unique_ptr<CSSParserSelector>>>($4));
selector->setPseudoClassValue($2);
if (selector->pseudoClassType() == CSSSelector::PseudoClassMatches)
$$ = selector.release();
@@ -1427,7 +1427,7 @@
selector->setArgument($4);
selector->setPseudoClassValue($2);
if (ending)
- selector->adoptSelectorVector(*ending);
+ selector->adoptSelectorVector(parser->arena(), *ending);
CSSSelector::PseudoClassType pseudoClassType = selector->pseudoClassType();
if (pseudoClassType == CSSSelector::PseudoClassNthChild || pseudoClassType == CSSSelector::PseudoClassNthLastChild)
$$ = selector.release();
@@ -1442,7 +1442,7 @@
selector->setArgument(AtomicString::number($4 * $5));
selector->setPseudoClassValue($2);
if (ending)
- selector->adoptSelectorVector(*ending);
+ selector->adoptSelectorVector(parser->arena(), *ending);
CSSSelector::PseudoClassType pseudoClassType = selector->pseudoClassType();
if (pseudoClassType == CSSSelector::PseudoClassNthChild || pseudoClassType == CSSSelector::PseudoClassNthLastChild)
$$ = selector.release();
@@ -1457,7 +1457,7 @@
selector->setArgument($4);
selector->setPseudoClassValue($2);
if (ending)
- selector->adoptSelectorVector(*ending);
+ selector->adoptSelectorVector(parser->arena(), *ending);
CSSSelector::PseudoClassType pseudoClassType = selector->pseudoClassType();
if (pseudoClassType == CSSSelector::PseudoClassNthChild || pseudoClassType == CSSSelector::PseudoClassNthLastChild)
$$ = selector.release();
@@ -1511,7 +1511,7 @@
auto selector = std::make_unique<CSSParserSelector>();
selector->setMatch(CSSSelector::PseudoClass);
selector->setPseudoClassValue($2);
- selector->adoptSelectorVector(*list);
+ selector->adoptSelectorVector(parser->arena(), *list);
if (selector->pseudoClassType() == CSSSelector::PseudoClassNot)
$$ = selector.release();
}
Modified: trunk/Source/WebCore/css/CSSKeyframesRule.h (195140 => 195141)
--- trunk/Source/WebCore/css/CSSKeyframesRule.h 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/CSSKeyframesRule.h 2016-01-15 20:01:42 UTC (rev 195141)
@@ -40,7 +40,7 @@
class StyleRuleKeyframes : public StyleRuleBase {
public:
- static Ref<StyleRuleKeyframes> create() { return adoptRef(*new StyleRuleKeyframes()); }
+ static Ref<StyleRuleKeyframes> create(BumpArena* arena) { return adoptRef(*new (arena) StyleRuleKeyframes); }
~StyleRuleKeyframes();
Modified: trunk/Source/WebCore/css/CSSParser.cpp (195140 => 195141)
--- trunk/Source/WebCore/css/CSSParser.cpp 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/CSSParser.cpp 2016-01-15 20:01:42 UTC (rev 195141)
@@ -1644,7 +1644,7 @@
if (unusedEntries)
results.remove(0, unusedEntries);
- return ImmutableStyleProperties::create(results.data(), results.size(), m_context.mode);
+ return ImmutableStyleProperties::create(arena(), results.data(), results.size(), m_context.mode);
}
void CSSParser::addPropertyWithPrefixingVariant(CSSPropertyID propId, PassRefPtr<CSSValue> value, bool important, bool implicit)
@@ -12701,9 +12701,9 @@
if (!media) {
// To comply with w3c test suite expectation, create an empty media query
// even when it is syntactically incorrect.
- rule = StyleRuleMedia::create(MediaQuerySet::create(), emptyRules);
+ rule = StyleRuleMedia::create(arena(), MediaQuerySet::create(), emptyRules);
} else
- rule = StyleRuleMedia::create(media, rules ? *rules : emptyRules);
+ rule = StyleRuleMedia::create(arena(), media, rules ? *rules : emptyRules);
processAndAddNewRuleToSourceTreeIfNeeded();
return rule;
}
@@ -12729,10 +12729,10 @@
conditionText = String(m_dataStart16.get() + conditionOffset, conditionLength).stripWhiteSpace();
if (rules)
- rule = StyleRuleSupports::create(conditionText, conditionIsSupported, *rules);
+ rule = StyleRuleSupports::create(arena(), conditionText, conditionIsSupported, *rules);
else {
RuleList emptyRules;
- rule = StyleRuleSupports::create(conditionText, conditionIsSupported, emptyRules);
+ rule = StyleRuleSupports::create(arena(), conditionText, conditionIsSupported, emptyRules);
}
processAndAddNewRuleToSourceTreeIfNeeded();
@@ -12841,7 +12841,7 @@
{
std::unique_ptr<Vector<RefPtr<StyleKeyframe>>> keyframes = WTFMove(popKeyframes);
m_allowImportRules = m_allowNamespaceDeclarations = false;
- RefPtr<StyleRuleKeyframes> rule = StyleRuleKeyframes::create();
+ RefPtr<StyleRuleKeyframes> rule = StyleRuleKeyframes::create(arena());
for (size_t i = 0; i < keyframes->size(); ++i)
rule->parserAppendKeyframe(keyframes->at(i));
rule->setName(name);
@@ -12849,14 +12849,24 @@
return rule;
}
+void CSSParser::setArena(BumpArena& arena)
+{
+ m_arena = &arena;
+}
+
+BumpArena* CSSParser::arena()
+{
+ return m_arena.get();
+}
+
RefPtr<StyleRuleBase> CSSParser::createStyleRule(Vector<std::unique_ptr<CSSParserSelector>>* selectors)
{
RefPtr<StyleRule> rule;
if (selectors) {
m_allowImportRules = false;
m_allowNamespaceDeclarations = false;
- rule = StyleRule::create(m_lastSelectorLineNumber, createStyleProperties());
- rule->parserAdoptSelectorVector(*selectors);
+ rule = StyleRule::create(arena(), m_lastSelectorLineNumber, createStyleProperties());
+ rule->parserAdoptSelectorVector(arena(), *selectors);
processAndAddNewRuleToSourceTreeIfNeeded();
} else
popRuleData();
@@ -12879,7 +12889,7 @@
return nullptr;
}
}
- RefPtr<StyleRuleFontFace> rule = StyleRuleFontFace::create(createStyleProperties());
+ RefPtr<StyleRuleFontFace> rule = StyleRuleFontFace::create(arena(), createStyleProperties());
clearProperties();
processAndAddNewRuleToSourceTreeIfNeeded();
return rule;
@@ -12963,10 +12973,10 @@
m_allowImportRules = m_allowNamespaceDeclarations = false;
RefPtr<StyleRulePage> rule;
if (pageSelector) {
- rule = StyleRulePage::create(createStyleProperties());
+ rule = StyleRulePage::create(arena(), createStyleProperties());
Vector<std::unique_ptr<CSSParserSelector>> selectorVector;
selectorVector.append(WTFMove(pageSelector));
- rule->parserAdoptSelectorVector(selectorVector);
+ rule->parserAdoptSelectorVector(arena(), selectorVector);
processAndAddNewRuleToSourceTreeIfNeeded();
} else
popRuleData();
@@ -12998,7 +13008,7 @@
m_allowImportRules = m_allowNamespaceDeclarations = false;
- RefPtr<StyleRuleRegion> regionRule = StyleRuleRegion::create(regionSelector, *rules);
+ RefPtr<StyleRuleRegion> regionRule = StyleRuleRegion::create(arena(), regionSelector, *rules);
if (isExtractingSourceData())
addNewRuleToSourceTree(CSSRuleSourceData::createUnknown());
@@ -13272,7 +13282,7 @@
{
m_allowImportRules = m_allowNamespaceDeclarations = false;
- RefPtr<StyleRuleViewport> rule = StyleRuleViewport::create(createStyleProperties());
+ RefPtr<StyleRuleViewport> rule = StyleRuleViewport::create(arena(), createStyleProperties());
clearProperties();
processAndAddNewRuleToSourceTreeIfNeeded();
Modified: trunk/Source/WebCore/css/CSSParser.h (195140 => 195141)
--- trunk/Source/WebCore/css/CSSParser.h 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/CSSParser.h 2016-01-15 20:01:42 UTC (rev 195141)
@@ -36,6 +36,7 @@
#include "SourceSizeList.h"
#include "WebKitCSSFilterValue.h"
#include <memory>
+#include <wtf/BumpArena.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/Vector.h>
@@ -114,6 +115,8 @@
WEBCORE_EXPORT CSSParser(const CSSParserContext&);
WEBCORE_EXPORT ~CSSParser();
+ void setArena(BumpArena&);
+
void parseSheet(StyleSheetContents*, const String&, const TextPosition&, RuleSourceDataList*, bool logErrors);
RefPtr<StyleRuleBase> parseRule(StyleSheetContents*, const String&);
RefPtr<StyleKeyframe> parseKeyframeRule(StyleSheetContents*, const String&);
@@ -397,6 +400,8 @@
CSSParserContext m_context;
+ BumpArena* arena();
+ RefPtr<BumpArena> m_arena;
bool m_important;
CSSPropertyID m_id;
AtomicString m_customPropertyName;
Modified: trunk/Source/WebCore/css/CSSParserValues.cpp (195140 => 195141)
--- trunk/Source/WebCore/css/CSSParserValues.cpp 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/CSSParserValues.cpp 2016-01-15 20:01:42 UTC (rev 195141)
@@ -214,7 +214,7 @@
}
#if ENABLE(VIDEO_TRACK)
-CSSParserSelector* CSSParserSelector::parsePseudoElementCueFunctionSelector(const CSSParserString& functionIdentifier, Vector<std::unique_ptr<CSSParserSelector>>* parsedSelectorVector)
+CSSParserSelector* CSSParserSelector::parsePseudoElementCueFunctionSelector(BumpArena* arena, const CSSParserString& functionIdentifier, Vector<std::unique_ptr<CSSParserSelector>>* parsedSelectorVector)
{
ASSERT_UNUSED(functionIdentifier, String(functionIdentifier) == "cue(");
@@ -226,7 +226,7 @@
auto selector = std::make_unique<CSSParserSelector>();
selector->m_selector->setMatch(CSSSelector::PseudoElement);
selector->m_selector->setPseudoElementType(CSSSelector::PseudoElementCue);
- selector->adoptSelectorVector(*selectorVector);
+ selector->adoptSelectorVector(arena, *selectorVector);
return selector.release();
}
#endif
@@ -279,10 +279,10 @@
}
}
-void CSSParserSelector::adoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectorVector)
+void CSSParserSelector::adoptSelectorVector(BumpArena* arena, Vector<std::unique_ptr<CSSParserSelector>>& selectorVector)
{
auto selectorList = std::make_unique<CSSSelectorList>();
- selectorList->adoptSelectorVector(selectorVector);
+ selectorList->adoptSelectorVector(arena, selectorVector);
m_selector->setSelectorList(WTFMove(selectorList));
}
Modified: trunk/Source/WebCore/css/CSSParserValues.h (195140 => 195141)
--- trunk/Source/WebCore/css/CSSParserValues.h 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/CSSParserValues.h 2016-01-15 20:01:42 UTC (rev 195141)
@@ -24,6 +24,7 @@
#include "CSSSelector.h"
#include "CSSValueKeywords.h"
#include "CSSValueList.h"
+#include <wtf/BumpArena.h>
#include <wtf/text/AtomicString.h>
#include <wtf/text/AtomicStringHash.h>
#include <wtf/text/WTFString.h>
@@ -211,7 +212,7 @@
public:
static CSSParserSelector* parsePagePseudoSelector(const CSSParserString& pseudoTypeString);
static CSSParserSelector* parsePseudoElementSelector(CSSParserString& pseudoTypeString);
- static CSSParserSelector* parsePseudoElementCueFunctionSelector(const CSSParserString& functionIdentifier, Vector<std::unique_ptr<CSSParserSelector>>* selectorVector);
+ static CSSParserSelector* parsePseudoElementCueFunctionSelector(BumpArena*, const CSSParserString& functionIdentifier, Vector<std::unique_ptr<CSSParserSelector>>* selectorVector);
static CSSParserSelector* parsePseudoClassAndCompatibilityElementSelector(CSSParserString& pseudoTypeString);
CSSParserSelector();
@@ -228,7 +229,7 @@
void setRelation(CSSSelector::Relation value) { m_selector->setRelation(value); }
void setForPage() { m_selector->setForPage(); }
- void adoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectorVector);
+ void adoptSelectorVector(BumpArena*, Vector<std::unique_ptr<CSSParserSelector>>& selectorVector);
void setLangArgumentList(const Vector<CSSParserString>& stringVector);
void setPseudoClassValue(const CSSParserString& pseudoClassString);
Modified: trunk/Source/WebCore/css/CSSSelectorList.cpp (195140 => 195141)
--- trunk/Source/WebCore/css/CSSSelectorList.cpp 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/CSSSelectorList.cpp 2016-01-15 20:01:42 UTC (rev 195141)
@@ -37,7 +37,7 @@
unsigned otherComponentCount = other.componentCount();
ASSERT_WITH_SECURITY_IMPLICATION(otherComponentCount);
- m_selectorArray = reinterpret_cast<CSSSelector*>(fastMalloc(sizeof(CSSSelector) * otherComponentCount));
+ m_selectorArray = reinterpret_cast<CSSSelector*>(BumpArena::allocate(BumpArena::arenaFor(other.m_selectorArray), sizeof(CSSSelector) * otherComponentCount));
for (unsigned i = 0; i < otherComponentCount; ++i)
new (NotNull, &m_selectorArray[i]) CSSSelector(other.m_selectorArray[i]);
}
@@ -49,7 +49,7 @@
other.m_selectorArray = nullptr;
}
-void CSSSelectorList::adoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectorVector)
+void CSSSelectorList::adoptSelectorVector(BumpArena* arena, Vector<std::unique_ptr<CSSParserSelector>>& selectorVector)
{
ASSERT_WITH_SECURITY_IMPLICATION(!selectorVector.isEmpty());
@@ -60,7 +60,7 @@
++flattenedSize;
}
ASSERT(flattenedSize);
- m_selectorArray = reinterpret_cast<CSSSelector*>(fastMalloc(sizeof(CSSSelector) * flattenedSize));
+ m_selectorArray = reinterpret_cast<CSSSelector*>(BumpArena::allocate(arena, sizeof(CSSSelector) * flattenedSize));
size_t arrayIndex = 0;
for (size_t i = 0; i < selectorVector.size(); ++i) {
CSSParserSelector* current = selectorVector[i].get();
@@ -119,7 +119,7 @@
isLastSelector = s->isLastInSelectorList();
s->~CSSSelector();
}
- fastFree(selectorArray);
+ BumpArena::deallocate(selectorArray);
}
String CSSSelectorList::selectorsText() const
Modified: trunk/Source/WebCore/css/CSSSelectorList.h (195140 => 195141)
--- trunk/Source/WebCore/css/CSSSelectorList.h 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/CSSSelectorList.h 2016-01-15 20:01:42 UTC (rev 195141)
@@ -28,6 +28,7 @@
#include "CSSSelector.h"
#include <memory>
+#include <wtf/BumpArena.h>
namespace WebCore {
@@ -42,7 +43,7 @@
~CSSSelectorList() { deleteSelectors(); }
- void adoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectorVector);
+ void adoptSelectorVector(BumpArena*, Vector<std::unique_ptr<CSSParserSelector>>&);
void adoptSelectorArray(CSSSelector* selectors) { ASSERT(!m_selectorArray); m_selectorArray = selectors; }
bool isValid() const { return !!m_selectorArray; }
Modified: trunk/Source/WebCore/css/StyleProperties.cpp (195140 => 195141)
--- trunk/Source/WebCore/css/StyleProperties.cpp 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/StyleProperties.cpp 2016-01-15 20:01:42 UTC (rev 195141)
@@ -55,9 +55,9 @@
return value.length() == 7 && (value == "initial" || value == "inherit");
}
-Ref<ImmutableStyleProperties> ImmutableStyleProperties::create(const CSSProperty* properties, unsigned count, CSSParserMode cssParserMode)
+Ref<ImmutableStyleProperties> ImmutableStyleProperties::create(BumpArena* arena, const CSSProperty* properties, unsigned count, CSSParserMode cssParserMode)
{
- void* slot = WTF::fastMalloc(sizeForImmutableStylePropertiesWithPropertyCount(count));
+ void* slot = BumpArena::allocate(arena, sizeForImmutableStylePropertiesWithPropertyCount(count));
return adoptRef(*new (NotNull, slot) ImmutableStyleProperties(properties, count, cssParserMode));
}
@@ -66,7 +66,7 @@
if (is<ImmutableStyleProperties>(*this))
return downcast<ImmutableStyleProperties>(const_cast<StyleProperties&>(*this));
const MutableStyleProperties& mutableThis = downcast<MutableStyleProperties>(*this);
- return ImmutableStyleProperties::create(mutableThis.m_propertyVector.data(), mutableThis.m_propertyVector.size(), cssParserMode());
+ return ImmutableStyleProperties::create(BumpArena::arenaFor(this), mutableThis.m_propertyVector.data(), mutableThis.m_propertyVector.size(), cssParserMode());
}
MutableStyleProperties::MutableStyleProperties(CSSParserMode cssParserMode)
Modified: trunk/Source/WebCore/css/StyleProperties.h (195140 => 195141)
--- trunk/Source/WebCore/css/StyleProperties.h 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/StyleProperties.h 2016-01-15 20:01:42 UTC (rev 195141)
@@ -29,6 +29,7 @@
#include "CSSPropertyNames.h"
#include "CSSValueKeywords.h"
#include <memory>
+#include <wtf/BumpArena.h>
#include <wtf/ListHashSet.h>
#include <wtf/TypeCasts.h>
#include <wtf/Vector.h>
@@ -46,7 +47,8 @@
class StylePropertyShorthand;
class StyleSheetContents;
-class StyleProperties : public RefCounted<StyleProperties> {
+class StyleProperties : public WTF::RefCountedBase {
+ WTF_MAKE_BUMPARENA_ALLOCATED;
friend class PropertyReference;
public:
// Override RefCounted's deref() to ensure operator delete is called on
@@ -161,7 +163,7 @@
class ImmutableStyleProperties : public StyleProperties {
public:
WEBCORE_EXPORT ~ImmutableStyleProperties();
- static Ref<ImmutableStyleProperties> create(const CSSProperty* properties, unsigned count, CSSParserMode);
+ static Ref<ImmutableStyleProperties> create(BumpArena*, const CSSProperty* properties, unsigned count, CSSParserMode);
unsigned propertyCount() const { return m_arraySize; }
bool isEmpty() const { return !propertyCount(); }
Modified: trunk/Source/WebCore/css/StyleRule.cpp (195140 => 195141)
--- trunk/Source/WebCore/css/StyleRule.cpp 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/StyleRule.cpp 2016-01-15 20:01:42 UTC (rev 195141)
@@ -219,14 +219,14 @@
return downcast<MutableStyleProperties>(m_properties.get());
}
-Ref<StyleRule> StyleRule::create(int sourceLine, const Vector<const CSSSelector*>& selectors, Ref<StyleProperties>&& properties)
+Ref<StyleRule> StyleRule::create(BumpArena* arena, int sourceLine, const Vector<const CSSSelector*>& selectors, Ref<StyleProperties>&& properties)
{
ASSERT_WITH_SECURITY_IMPLICATION(!selectors.isEmpty());
- CSSSelector* selectorListArray = reinterpret_cast<CSSSelector*>(fastMalloc(sizeof(CSSSelector) * selectors.size()));
+ CSSSelector* selectorListArray = reinterpret_cast<CSSSelector*>(BumpArena::allocate(arena, sizeof(CSSSelector) * selectors.size()));
for (unsigned i = 0; i < selectors.size(); ++i)
new (NotNull, &selectorListArray[i]) CSSSelector(*selectors.at(i));
selectorListArray[selectors.size() - 1].setLastInSelectorList();
- auto rule = StyleRule::create(sourceLine, WTFMove(properties));
+ auto rule = StyleRule::create(arena, sourceLine, WTFMove(properties));
rule.get().parserAdoptSelectorArray(selectorListArray);
return rule;
}
@@ -244,7 +244,7 @@
componentsInThisSelector.append(component);
if (componentsInThisSelector.size() + componentsSinceLastSplit.size() > maxCount && !componentsSinceLastSplit.isEmpty()) {
- rules.append(create(sourceLine(), componentsSinceLastSplit, const_cast<StyleProperties&>(m_properties.get())));
+ rules.append(create(BumpArena::arenaFor(this), sourceLine(), componentsSinceLastSplit, const_cast<StyleProperties&>(m_properties.get())));
componentsSinceLastSplit.clear();
}
@@ -252,7 +252,7 @@
}
if (!componentsSinceLastSplit.isEmpty())
- rules.append(create(sourceLine(), componentsSinceLastSplit, const_cast<StyleProperties&>(m_properties.get())));
+ rules.append(create(BumpArena::arenaFor(this), sourceLine(), componentsSinceLastSplit, const_cast<StyleProperties&>(m_properties.get())));
return rules;
}
@@ -360,7 +360,7 @@
StyleRuleRegion::StyleRuleRegion(Vector<std::unique_ptr<CSSParserSelector>>* selectors, Vector<RefPtr<StyleRuleBase>>& adoptRules)
: StyleRuleGroup(Region, adoptRules)
{
- m_selectorList.adoptSelectorVector(*selectors);
+ m_selectorList.adoptSelectorVector(BumpArena::arenaFor(this), *selectors);
}
StyleRuleRegion::StyleRuleRegion(const StyleRuleRegion& o)
Modified: trunk/Source/WebCore/css/StyleRule.h (195140 => 195141)
--- trunk/Source/WebCore/css/StyleRule.h 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/StyleRule.h 2016-01-15 20:01:42 UTC (rev 195141)
@@ -25,6 +25,7 @@
#include "CSSSelectorList.h"
#include "MediaList.h"
#include "StyleProperties.h"
+#include <wtf/BumpArena.h>
#include <wtf/RefPtr.h>
#include <wtf/TypeCasts.h>
@@ -37,7 +38,7 @@
class StyleProperties;
class StyleRuleBase : public WTF::RefCountedBase {
- WTF_MAKE_FAST_ALLOCATED;
+ WTF_MAKE_BUMPARENA_ALLOCATED;
public:
enum Type {
Unknown, // Not used.
@@ -101,11 +102,10 @@
};
class StyleRule : public StyleRuleBase {
- WTF_MAKE_FAST_ALLOCATED;
public:
- static Ref<StyleRule> create(int sourceLine, Ref<StyleProperties>&& properties)
+ static Ref<StyleRule> create(BumpArena* arena, int sourceLine, Ref<StyleProperties>&& properties)
{
- return adoptRef(*new StyleRule(sourceLine, WTFMove(properties)));
+ return adoptRef(*new (arena) StyleRule(sourceLine, WTFMove(properties)));
}
~StyleRule();
@@ -114,7 +114,7 @@
const StyleProperties& properties() const { return m_properties; }
MutableStyleProperties& mutableProperties();
- void parserAdoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectors) { m_selectorList.adoptSelectorVector(selectors); }
+ void parserAdoptSelectorVector(BumpArena* arena, Vector<std::unique_ptr<CSSParserSelector>>& selectors) { m_selectorList.adoptSelectorVector(arena, selectors); }
void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList = WTFMove(selectors); }
void parserAdoptSelectorArray(CSSSelector* selectors) { m_selectorList.adoptSelectorArray(selectors); }
@@ -128,7 +128,7 @@
StyleRule(int sourceLine, Ref<StyleProperties>&&);
StyleRule(const StyleRule&);
- static Ref<StyleRule> create(int sourceLine, const Vector<const CSSSelector*>&, Ref<StyleProperties>&&);
+ static Ref<StyleRule> create(BumpArena*, int sourceLine, const Vector<const CSSSelector*>&, Ref<StyleProperties>&&);
Ref<StyleProperties> m_properties;
CSSSelectorList m_selectorList;
@@ -136,7 +136,7 @@
class StyleRuleFontFace : public StyleRuleBase {
public:
- static Ref<StyleRuleFontFace> create(Ref<StyleProperties>&& properties) { return adoptRef(*new StyleRuleFontFace(WTFMove(properties))); }
+ static Ref<StyleRuleFontFace> create(BumpArena* arena, Ref<StyleProperties>&& properties) { return adoptRef(*new (arena) StyleRuleFontFace(WTFMove(properties))); }
~StyleRuleFontFace();
@@ -155,7 +155,7 @@
class StyleRulePage : public StyleRuleBase {
public:
- static Ref<StyleRulePage> create(Ref<StyleProperties>&& properties) { return adoptRef(*new StyleRulePage(WTFMove(properties))); }
+ static Ref<StyleRulePage> create(BumpArena* arena, Ref<StyleProperties>&& properties) { return adoptRef(*new (arena) StyleRulePage(WTFMove(properties))); }
~StyleRulePage();
@@ -163,7 +163,7 @@
const StyleProperties& properties() const { return m_properties; }
MutableStyleProperties& mutableProperties();
- void parserAdoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectors) { m_selectorList.adoptSelectorVector(selectors); }
+ void parserAdoptSelectorVector(BumpArena* arena, Vector<std::unique_ptr<CSSParserSelector>>& selectors) { m_selectorList.adoptSelectorVector(arena, selectors); }
void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList = WTFMove(selectors); }
Ref<StyleRulePage> copy() const { return adoptRef(*new StyleRulePage(*this)); }
@@ -193,9 +193,9 @@
class StyleRuleMedia : public StyleRuleGroup {
public:
- static Ref<StyleRuleMedia> create(PassRefPtr<MediaQuerySet> media, Vector<RefPtr<StyleRuleBase>>& adoptRules)
+ static Ref<StyleRuleMedia> create(BumpArena* arena, PassRefPtr<MediaQuerySet> media, Vector<RefPtr<StyleRuleBase>>& adoptRules)
{
- return adoptRef(*new StyleRuleMedia(media, adoptRules));
+ return adoptRef(*new (arena) StyleRuleMedia(media, adoptRules));
}
MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
@@ -211,9 +211,9 @@
class StyleRuleSupports : public StyleRuleGroup {
public:
- static Ref<StyleRuleSupports> create(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>& adoptRules)
+ static Ref<StyleRuleSupports> create(BumpArena* arena, const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>& adoptRules)
{
- return adoptRef(*new StyleRuleSupports(conditionText, conditionIsSupported, adoptRules));
+ return adoptRef(*new (arena) StyleRuleSupports(conditionText, conditionIsSupported, adoptRules));
}
String conditionText() const { return m_conditionText; }
@@ -230,9 +230,9 @@
class StyleRuleRegion : public StyleRuleGroup {
public:
- static Ref<StyleRuleRegion> create(Vector<std::unique_ptr<CSSParserSelector>>* selectors, Vector<RefPtr<StyleRuleBase>>& adoptRules)
+ static Ref<StyleRuleRegion> create(BumpArena* arena, Vector<std::unique_ptr<CSSParserSelector>>* selectors, Vector<RefPtr<StyleRuleBase>>& adoptRules)
{
- return adoptRef(*new StyleRuleRegion(selectors, adoptRules));
+ return adoptRef(*new (arena) StyleRuleRegion(selectors, adoptRules));
}
const CSSSelectorList& selectorList() const { return m_selectorList; }
@@ -249,7 +249,7 @@
#if ENABLE(CSS_DEVICE_ADAPTATION)
class StyleRuleViewport : public StyleRuleBase {
public:
- static Ref<StyleRuleViewport> create(Ref<StyleProperties>&& properties) { return adoptRef(*new StyleRuleViewport(WTFMove(properties))); }
+ static Ref<StyleRuleViewport> create(BumpArena* arena, Ref<StyleProperties>&& properties) { return adoptRef(*new (arena) StyleRuleViewport(WTFMove(properties))); }
~StyleRuleViewport();
Modified: trunk/Source/WebCore/css/StyleSheetContents.cpp (195140 => 195141)
--- trunk/Source/WebCore/css/StyleSheetContents.cpp 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/StyleSheetContents.cpp 2016-01-15 20:01:42 UTC (rev 195141)
@@ -71,6 +71,7 @@
, m_isMutable(false)
, m_isInMemoryCache(false)
, m_parserContext(context)
+ , m_arena(BumpArena::create())
{
}
@@ -91,6 +92,7 @@
, m_isMutable(false)
, m_isInMemoryCache(false)
, m_parserContext(o.m_parserContext)
+ , m_arena(BumpArena::create())
{
ASSERT(o.isCacheable());
@@ -313,6 +315,7 @@
}
CSSParser p(parserContext());
+ p.setArena(m_arena.get());
p.parseSheet(this, sheetText, TextPosition(), nullptr, true);
if (m_parserContext.needsSiteSpecificQuirks && isStrictParserMode(m_parserContext.mode)) {
@@ -334,6 +337,7 @@
bool StyleSheetContents::parseStringAtPosition(const String& sheetText, const TextPosition& textPosition, bool createdByParser)
{
CSSParser p(parserContext());
+ p.setArena(m_arena.get());
p.parseSheet(this, sheetText, textPosition, nullptr, createdByParser);
return true;
}
Modified: trunk/Source/WebCore/css/StyleSheetContents.h (195140 => 195141)
--- trunk/Source/WebCore/css/StyleSheetContents.h 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/css/StyleSheetContents.h 2016-01-15 20:01:42 UTC (rev 195141)
@@ -24,6 +24,7 @@
#include "CSSParserMode.h"
#include "CachePolicy.h"
#include "URL.h"
+#include <wtf/BumpArena.h>
#include <wtf/HashMap.h>
#include <wtf/ListHashSet.h>
#include <wtf/RefCounted.h>
@@ -173,6 +174,8 @@
CSSParserContext m_parserContext;
Vector<CSSStyleSheet*> m_clients;
+
+ Ref<BumpArena> m_arena;
};
} // namespace
Modified: trunk/Source/WebCore/dom/SelectorQuery.cpp (195140 => 195141)
--- trunk/Source/WebCore/dom/SelectorQuery.cpp 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/dom/SelectorQuery.cpp 2016-01-15 20:01:42 UTC (rev 195141)
@@ -609,6 +609,11 @@
{
}
+SelectorQueryCache::SelectorQueryCache()
+ : m_arena(BumpArena::create())
+{
+}
+
SelectorQuery* SelectorQueryCache::add(const String& selectors, Document& document, ExceptionCode& ec)
{
auto it = m_entries.find(selectors);
@@ -616,6 +621,7 @@
return it->value.get();
CSSParser parser(document);
+ parser.setArena(m_arena.get());
CSSSelectorList selectorList;
parser.parseSelector(selectors, selectorList);
Modified: trunk/Source/WebCore/dom/SelectorQuery.h (195140 => 195141)
--- trunk/Source/WebCore/dom/SelectorQuery.h 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/dom/SelectorQuery.h 2016-01-15 20:01:42 UTC (rev 195141)
@@ -29,6 +29,7 @@
#include "CSSSelectorList.h"
#include "NodeList.h"
#include "SelectorCompiler.h"
+#include <wtf/BumpArena.h>
#include <wtf/HashMap.h>
#include <wtf/Vector.h>
#include <wtf/text/AtomicStringHash.h>
@@ -132,10 +133,12 @@
WTF_MAKE_FAST_ALLOCATED;
public:
+ SelectorQueryCache();
SelectorQuery* add(const String&, Document&, ExceptionCode&);
private:
HashMap<String, std::unique_ptr<SelectorQuery>> m_entries;
+ Ref<BumpArena> m_arena;
};
inline bool SelectorQuery::matches(Element& element) const
Modified: trunk/Source/WebCore/svg/SVGFontFaceElement.cpp (195140 => 195141)
--- trunk/Source/WebCore/svg/SVGFontFaceElement.cpp 2016-01-15 19:55:19 UTC (rev 195140)
+++ trunk/Source/WebCore/svg/SVGFontFaceElement.cpp 2016-01-15 20:01:42 UTC (rev 195141)
@@ -49,7 +49,7 @@
inline SVGFontFaceElement::SVGFontFaceElement(const QualifiedName& tagName, Document& document)
: SVGElement(tagName, document)
- , m_fontFaceRule(StyleRuleFontFace::create(MutableStyleProperties::create(CSSStrictMode)))
+ , m_fontFaceRule(StyleRuleFontFace::create(nullptr, MutableStyleProperties::create(CSSStrictMode)))
, m_fontElement(nullptr)
{
ASSERT(hasTagName(font_faceTag));