OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/heap/CallbackStack.h" | 5 #include "platform/heap/CallbackStack.h" |
6 #include "wtf/allocator/PageAllocator.h" | 6 #include "wtf/allocator/PageAllocator.h" |
7 | 7 |
8 namespace blink { | 8 namespace blink { |
9 | 9 |
10 size_t const CallbackStack::kMinimalBlockSize = WTF::kPageAllocationGranularity
/ sizeof(CallbackStack::Item); | 10 size_t const CallbackStack::kMinimalBlockSize = WTF::kPageAllocationGranularity
/ sizeof(CallbackStack::Item); |
(...skipping 27 matching lines...) Expand all Loading... |
38 #if ENABLE(ASSERT) | 38 #if ENABLE(ASSERT) |
39 void CallbackStack::Block::clear() | 39 void CallbackStack::Block::clear() |
40 { | 40 { |
41 for (size_t i = 0; i < m_blockSize; i++) | 41 for (size_t i = 0; i < m_blockSize; i++) |
42 m_buffer[i] = Item(0, 0); | 42 m_buffer[i] = Item(0, 0); |
43 } | 43 } |
44 #endif | 44 #endif |
45 | 45 |
46 void CallbackStack::Block::decommit() | 46 void CallbackStack::Block::decommit() |
47 { | 47 { |
| 48 reset(); |
| 49 WTF::discardSystemPages(m_buffer, m_blockSize * sizeof(Item)); |
| 50 } |
| 51 |
| 52 void CallbackStack::Block::reset() |
| 53 { |
48 #if ENABLE(ASSERT) | 54 #if ENABLE(ASSERT) |
49 clear(); | 55 clear(); |
50 #endif | 56 #endif |
51 WTF::discardSystemPages(m_buffer, m_blockSize * sizeof(Item)); | |
52 | |
53 m_current = &m_buffer[0]; | 57 m_current = &m_buffer[0]; |
54 m_next = nullptr; | 58 m_next = nullptr; |
55 } | 59 } |
56 | 60 |
57 void CallbackStack::Block::invokeEphemeronCallbacks(Visitor* visitor) | 61 void CallbackStack::Block::invokeEphemeronCallbacks(Visitor* visitor) |
58 { | 62 { |
59 // This loop can tolerate entries being added by the callbacks after | 63 // This loop can tolerate entries being added by the callbacks after |
60 // iteration starts. | 64 // iteration starts. |
61 for (unsigned i = 0; m_buffer + i < m_current; i++) { | 65 for (unsigned i = 0; m_buffer + i < m_current; i++) { |
62 Item& item = m_buffer[i]; | 66 Item& item = m_buffer[i]; |
(...skipping 20 matching lines...) Expand all Loading... |
83 } | 87 } |
84 | 88 |
85 CallbackStack::~CallbackStack() | 89 CallbackStack::~CallbackStack() |
86 { | 90 { |
87 RELEASE_ASSERT(isEmpty()); | 91 RELEASE_ASSERT(isEmpty()); |
88 delete m_first; | 92 delete m_first; |
89 m_first = nullptr; | 93 m_first = nullptr; |
90 m_last = nullptr; | 94 m_last = nullptr; |
91 } | 95 } |
92 | 96 |
| 97 void CallbackStack::clear() |
| 98 { |
| 99 Block* next; |
| 100 for (Block* current = m_first->next(); current; current = next) { |
| 101 next = current->next(); |
| 102 delete current; |
| 103 } |
| 104 m_first->reset(); |
| 105 m_last = m_first; |
| 106 } |
| 107 |
93 void CallbackStack::decommit() | 108 void CallbackStack::decommit() |
94 { | 109 { |
95 Block* next; | 110 Block* next; |
96 for (Block* current = m_first->next(); current; current = next) { | 111 for (Block* current = m_first->next(); current; current = next) { |
97 next = current->next(); | 112 next = current->next(); |
98 delete current; | 113 delete current; |
99 } | 114 } |
100 m_first->decommit(); | 115 m_first->decommit(); |
101 m_last = m_first; | 116 m_last = m_first; |
102 } | 117 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 { | 185 { |
171 for (Block* current = m_first; current; current = current->next()) { | 186 for (Block* current = m_first; current; current = current->next()) { |
172 if (current->hasCallbackForObject(object)) | 187 if (current->hasCallbackForObject(object)) |
173 return true; | 188 return true; |
174 } | 189 } |
175 return false; | 190 return false; |
176 } | 191 } |
177 #endif | 192 #endif |
178 | 193 |
179 } // namespace blink | 194 } // namespace blink |
OLD | NEW |