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 #ifndef CallbackStack_h | 5 #ifndef CallbackStack_h |
6 #define CallbackStack_h | 6 #define CallbackStack_h |
7 | 7 |
8 #include "platform/heap/ThreadState.h" | 8 #include "platform/heap/ThreadState.h" |
| 9 #include "wtf/Assertions.h" |
9 | 10 |
10 namespace blink { | 11 namespace blink { |
11 | 12 |
12 // The CallbackStack contains all the visitor callbacks used to trace and mark | 13 // The CallbackStack contains all the visitor callbacks used to trace and mark |
13 // objects. A specific CallbackStack instance contains at most bufferSize elemen
ts. | 14 // objects. A specific CallbackStack instance contains at most bufferSize elemen
ts. |
14 // If more space is needed a new CallbackStack instance is created and chained | 15 // If more space is needed a new CallbackStack instance is created and chained |
15 // together with the former instance. I.e. a logical CallbackStack can be made o
f | 16 // together with the former instance. I.e. a logical CallbackStack can be made o
f |
16 // multiple chained CallbackStack object instances. | 17 // multiple chained CallbackStack object instances. |
17 class CallbackStack { | 18 class CallbackStack { |
18 public: | 19 public: |
(...skipping 23 matching lines...) Expand all Loading... |
42 Item* pop(); | 43 Item* pop(); |
43 | 44 |
44 bool isEmpty() const; | 45 bool isEmpty() const; |
45 | 46 |
46 void invokeEphemeronCallbacks(Visitor*); | 47 void invokeEphemeronCallbacks(Visitor*); |
47 | 48 |
48 #if ENABLE(ASSERT) | 49 #if ENABLE(ASSERT) |
49 bool hasCallbackForObject(const void*); | 50 bool hasCallbackForObject(const void*); |
50 #endif | 51 #endif |
51 | 52 |
| 53 private: |
52 static const size_t blockSize = 8192; | 54 static const size_t blockSize = 8192; |
53 | 55 |
54 private: | |
55 class Block { | 56 class Block { |
56 public: | 57 public: |
57 explicit Block(Block* next) | 58 explicit Block(Block* next) |
58 : m_limit(&(m_buffer[blockSize])) | 59 : m_limit(&(m_buffer[blockSize])) |
59 , m_current(&(m_buffer[0])) | 60 , m_current(&(m_buffer[0])) |
60 , m_next(next) | 61 , m_next(next) |
61 { | 62 { |
62 clearUnused(); | 63 clearUnused(); |
63 } | 64 } |
64 | 65 |
(...skipping 14 matching lines...) Expand all Loading... |
79 | 80 |
80 size_t size() const | 81 size_t size() const |
81 { | 82 { |
82 return blockSize - (m_limit - m_current); | 83 return blockSize - (m_limit - m_current); |
83 } | 84 } |
84 | 85 |
85 Item* allocateEntry() | 86 Item* allocateEntry() |
86 { | 87 { |
87 if (LIKELY(m_current < m_limit)) | 88 if (LIKELY(m_current < m_limit)) |
88 return m_current++; | 89 return m_current++; |
89 return 0; | 90 return nullptr; |
90 } | 91 } |
91 | 92 |
92 Item* pop() | 93 Item* pop() |
93 { | 94 { |
94 if (UNLIKELY(isEmptyBlock())) | 95 if (UNLIKELY(isEmptyBlock())) |
95 return 0; | 96 return nullptr; |
96 return --m_current; | 97 return --m_current; |
97 } | 98 } |
98 | 99 |
99 void invokeEphemeronCallbacks(Visitor*); | 100 void invokeEphemeronCallbacks(Visitor*); |
100 #if ENABLE(ASSERT) | 101 #if ENABLE(ASSERT) |
101 bool hasCallbackForObject(const void*); | 102 bool hasCallbackForObject(const void*); |
102 #endif | 103 #endif |
103 | 104 |
104 private: | 105 private: |
105 void clearUnused(); | 106 void clearUnused(); |
106 | 107 |
107 Item m_buffer[blockSize]; | 108 Item m_buffer[blockSize]; |
108 Item* m_limit; | 109 Item* m_limit; |
109 Item* m_current; | 110 Item* m_current; |
110 Block* m_next; | 111 Block* m_next; |
111 }; | 112 }; |
112 | 113 |
113 Item* popSlow(); | 114 Item* popSlow(); |
114 Item* allocateEntrySlow(); | 115 Item* allocateEntrySlow(); |
115 void invokeOldestCallbacks(Block*, Block*, Visitor*); | 116 void invokeOldestCallbacks(Block*, Block*, Visitor*); |
116 bool hasJustOneBlock() const; | 117 bool hasJustOneBlock() const; |
117 void swap(CallbackStack* other); | |
118 | 118 |
119 Block* m_first; | 119 Block* m_first; |
120 Block* m_last; | 120 Block* m_last; |
121 }; | 121 }; |
122 | 122 |
123 ALWAYS_INLINE CallbackStack::Item* CallbackStack::allocateEntry() | 123 ALWAYS_INLINE CallbackStack::Item* CallbackStack::allocateEntry() |
124 { | 124 { |
125 Item* item = m_first->allocateEntry(); | 125 Item* item = m_first->allocateEntry(); |
126 if (LIKELY(!!item)) | 126 if (LIKELY(!!item)) |
127 return item; | 127 return item; |
128 | 128 |
129 return allocateEntrySlow(); | 129 return allocateEntrySlow(); |
130 } | 130 } |
131 | 131 |
132 ALWAYS_INLINE CallbackStack::Item* CallbackStack::pop() | 132 ALWAYS_INLINE CallbackStack::Item* CallbackStack::pop() |
133 { | 133 { |
134 Item* item = m_first->pop(); | 134 Item* item = m_first->pop(); |
135 if (LIKELY(!!item)) | 135 if (LIKELY(!!item)) |
136 return item; | 136 return item; |
137 | 137 |
138 return popSlow(); | 138 return popSlow(); |
139 } | 139 } |
140 | 140 |
141 } // namespace blink | 141 } // namespace blink |
142 | 142 |
143 #endif // CallbackStack_h | 143 #endif // CallbackStack_h |
OLD | NEW |