Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: third_party/WebKit/Source/platform/heap/CallbackStack.cpp

Issue 2619493003: Replace ASSERTs in platform/heap/ with DCHECKs
Patch Set: temp Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/PtrUtil.h" 6 #include "wtf/PtrUtil.h"
7 #include "wtf/allocator/Partitions.h" 7 #include "wtf/allocator/Partitions.h"
8 8
9 namespace blink { 9 namespace blink {
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 return; 60 return;
61 } 61 }
62 // Otherwise, return the memory back to the free list. 62 // Otherwise, return the memory back to the free list.
63 DCHECK_EQ(m_freeListNext[index], -1); 63 DCHECK_EQ(m_freeListNext[index], -1);
64 m_freeListNext[index] = m_freeListFirst; 64 m_freeListNext[index] = m_freeListFirst;
65 m_freeListFirst = index; 65 m_freeListFirst = index;
66 } 66 }
67 67
68 CallbackStack::Block::Block(Block* next) { 68 CallbackStack::Block::Block(Block* next) {
69 m_buffer = CallbackStackMemoryPool::instance().allocate(); 69 m_buffer = CallbackStackMemoryPool::instance().allocate();
70 #if ENABLE(ASSERT) 70 #if DCHECK_IS_ON()
71 clear(); 71 clear();
72 #endif 72 #endif
73 73
74 m_limit = &(m_buffer[CallbackStackMemoryPool::kBlockSize]); 74 m_limit = &(m_buffer[CallbackStackMemoryPool::kBlockSize]);
75 m_current = &(m_buffer[0]); 75 m_current = &(m_buffer[0]);
76 m_next = next; 76 m_next = next;
77 } 77 }
78 78
79 CallbackStack::Block::~Block() { 79 CallbackStack::Block::~Block() {
80 CallbackStackMemoryPool::instance().free(m_buffer); 80 CallbackStackMemoryPool::instance().free(m_buffer);
81 m_buffer = nullptr; 81 m_buffer = nullptr;
82 m_limit = nullptr; 82 m_limit = nullptr;
83 m_current = nullptr; 83 m_current = nullptr;
84 m_next = nullptr; 84 m_next = nullptr;
85 } 85 }
86 86
87 #if ENABLE(ASSERT) 87 #if DCHECK_IS_ON()
88 void CallbackStack::Block::clear() { 88 void CallbackStack::Block::clear() {
89 for (size_t i = 0; i < CallbackStackMemoryPool::kBlockSize; i++) 89 for (size_t i = 0; i < CallbackStackMemoryPool::kBlockSize; i++)
90 m_buffer[i] = Item(0, 0); 90 m_buffer[i] = Item(0, 0);
91 } 91 }
92 #endif 92 #endif
93 93
94 void CallbackStack::Block::invokeEphemeronCallbacks(Visitor* visitor) { 94 void CallbackStack::Block::invokeEphemeronCallbacks(Visitor* visitor) {
95 // This loop can tolerate entries being added by the callbacks after 95 // This loop can tolerate entries being added by the callbacks after
96 // iteration starts. 96 // iteration starts.
97 for (unsigned i = 0; m_buffer + i < m_current; i++) { 97 for (unsigned i = 0; m_buffer + i < m_current; i++) {
98 Item& item = m_buffer[i]; 98 Item& item = m_buffer[i];
99 item.call(visitor); 99 item.call(visitor);
100 } 100 }
101 } 101 }
102 102
103 #if ENABLE(ASSERT) 103 #if DCHECK_IS_ON()
104 bool CallbackStack::Block::hasCallbackForObject(const void* object) { 104 bool CallbackStack::Block::hasCallbackForObject(const void* object) {
105 for (unsigned i = 0; m_buffer + i < m_current; i++) { 105 for (unsigned i = 0; m_buffer + i < m_current; i++) {
106 Item* item = &m_buffer[i]; 106 Item* item = &m_buffer[i];
107 if (item->object() == object) 107 if (item->object() == object)
108 return true; 108 return true;
109 } 109 }
110 return false; 110 return false;
111 } 111 }
112 #endif 112 #endif
113 113
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return m_first->allocateEntry(); 152 return m_first->allocateEntry();
153 } 153 }
154 154
155 CallbackStack::Item* CallbackStack::popSlow() { 155 CallbackStack::Item* CallbackStack::popSlow() {
156 DCHECK(m_first); 156 DCHECK(m_first);
157 DCHECK(m_first->isEmptyBlock()); 157 DCHECK(m_first->isEmptyBlock());
158 158
159 for (;;) { 159 for (;;) {
160 Block* next = m_first->next(); 160 Block* next = m_first->next();
161 if (!next) { 161 if (!next) {
162 #if ENABLE(ASSERT) 162 #if DCHECK_IS_ON()
163 m_first->clear(); 163 m_first->clear();
164 #endif 164 #endif
165 return nullptr; 165 return nullptr;
166 } 166 }
167 delete m_first; 167 delete m_first;
168 m_first = next; 168 m_first = next;
169 if (Item* item = m_first->pop()) 169 if (Item* item = m_first->pop())
170 return item; 170 return item;
171 } 171 }
172 } 172 }
(...skipping 24 matching lines...) Expand all
197 // Recurse first so we get to the newly added entries last. 197 // Recurse first so we get to the newly added entries last.
198 invokeOldestCallbacks(from->next(), upto, visitor); 198 invokeOldestCallbacks(from->next(), upto, visitor);
199 from->invokeEphemeronCallbacks(visitor); 199 from->invokeEphemeronCallbacks(visitor);
200 } 200 }
201 201
202 bool CallbackStack::hasJustOneBlock() const { 202 bool CallbackStack::hasJustOneBlock() const {
203 DCHECK(m_first); 203 DCHECK(m_first);
204 return !m_first->next(); 204 return !m_first->next();
205 } 205 }
206 206
207 #if ENABLE(ASSERT) 207 #if DCHECK_IS_ON()
208 bool CallbackStack::hasCallbackForObject(const void* object) { 208 bool CallbackStack::hasCallbackForObject(const void* object) {
209 for (Block* current = m_first; current; current = current->next()) { 209 for (Block* current = m_first; current; current = current->next()) {
210 if (current->hasCallbackForObject(object)) 210 if (current->hasCallbackForObject(object))
211 return true; 211 return true;
212 } 212 }
213 return false; 213 return false;
214 } 214 }
215 #endif 215 #endif
216 216
217 } // namespace blink 217 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698