Index: third_party/WebKit/Source/platform/heap/CallbackStack.cpp |
diff --git a/third_party/WebKit/Source/platform/heap/CallbackStack.cpp b/third_party/WebKit/Source/platform/heap/CallbackStack.cpp |
index 48823846abdabb8d8e30471327d1629f12560ac8..86657664cf84c69addcb60a8d4eddc757cf86b17 100644 |
--- a/third_party/WebKit/Source/platform/heap/CallbackStack.cpp |
+++ b/third_party/WebKit/Source/platform/heap/CallbackStack.cpp |
@@ -3,14 +3,51 @@ |
// found in the LICENSE file. |
#include "platform/heap/CallbackStack.h" |
+#include "wtf/PageAllocator.h" |
namespace blink { |
+CallbackStack::Block::Block(Block* next) |
+{ |
+ static_assert((blockSize * sizeof(Item)) % WTF::kPageAllocationGranularity == 0, "CallbackStack::blockSize * sizeof(Item) must be a multiple of WTF::kPageAllocationGranularity"); |
+ m_buffer = static_cast<Item*>(WTF::allocPages(nullptr, blockSize * sizeof(Item), WTF::kPageAllocationGranularity, WTF::PageAccessible)); |
+ RELEASE_ASSERT(m_buffer); |
+ |
+#if ENABLE(ASSERT) |
+ clear(); |
+#endif |
+ |
+ m_limit = &(m_buffer[blockSize]); |
+ m_current = &(m_buffer[0]); |
+ m_next = next; |
+} |
+ |
+CallbackStack::Block::~Block() |
+{ |
+ WTF::freePages(m_buffer, blockSize * sizeof(Item)); |
+ m_buffer = nullptr; |
+ m_limit = nullptr; |
+ m_current = nullptr; |
+ m_next = nullptr; |
+} |
+ |
+#if ENABLE(ASSERT) |
void CallbackStack::Block::clear() |
{ |
+ for (size_t i = 0; i < blockSize; i++) |
+ m_buffer[i] = Item(0, 0); |
+} |
+#endif |
+ |
+void CallbackStack::Block::decommit() |
+{ |
+#if ENABLE(ASSERT) |
+ clear(); |
+#endif |
+ WTF::discardSystemPages(m_buffer, blockSize * sizeof(Item)); |
+ |
m_current = &m_buffer[0]; |
m_next = nullptr; |
- clearUnused(); |
} |
void CallbackStack::Block::invokeEphemeronCallbacks(Visitor* visitor) |
@@ -35,34 +72,28 @@ bool CallbackStack::Block::hasCallbackForObject(const void* object) |
} |
#endif |
-void CallbackStack::Block::clearUnused() |
-{ |
-#if ENABLE(ASSERT) |
- for (size_t i = 0; i < blockSize; i++) |
- m_buffer[i] = Item(0, 0); |
-#endif |
-} |
- |
-CallbackStack::CallbackStack() : m_first(new Block(0)), m_last(m_first) |
+CallbackStack::CallbackStack() |
+ : m_first(new Block(0)) |
+ , m_last(m_first) |
{ |
} |
CallbackStack::~CallbackStack() |
{ |
- clear(); |
+ RELEASE_ASSERT(isEmpty()); |
delete m_first; |
m_first = nullptr; |
m_last = nullptr; |
} |
-void CallbackStack::clear() |
+void CallbackStack::decommit() |
{ |
Block* next; |
for (Block* current = m_first->next(); current; current = next) { |
next = current->next(); |
delete current; |
} |
- m_first->clear(); |
+ m_first->decommit(); |
m_last = m_first; |
} |