OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_VM_HANDLES_IMPL_H_ | 5 #ifndef RUNTIME_VM_HANDLES_IMPL_H_ |
6 #define RUNTIME_VM_HANDLES_IMPL_H_ | 6 #define RUNTIME_VM_HANDLES_IMPL_H_ |
7 | 7 |
8 #include "vm/heap.h" | 8 #include "vm/heap.h" |
9 #include "vm/thread.h" | 9 #include "vm/thread.h" |
10 #include "vm/visitor.h" | 10 #include "vm/visitor.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 14 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
15 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 15 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
16 VisitObjectPointers(ObjectPointerVisitor* visitor) { | 16 VisitObjectPointers(ObjectPointerVisitor* visitor) { |
17 // Visit all zone handles. | 17 // Visit all zone handles. |
18 HandlesBlock* block = zone_blocks_; | 18 HandlesBlock* block = zone_blocks_; |
19 while (block != NULL) { | 19 while (block != NULL) { |
20 block->VisitObjectPointers(visitor); | 20 block->VisitObjectPointers(visitor); |
21 block = block->next_block(); | 21 block = block->next_block(); |
22 } | 22 } |
23 | 23 |
24 // Visit all scoped handles. | 24 // Visit all scoped handles. |
25 VisitScopedHandles(visitor); | 25 VisitScopedHandles(visitor); |
26 } | 26 } |
27 | 27 |
28 | |
29 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 28 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
30 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 29 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
31 VisitScopedHandles(ObjectPointerVisitor* visitor) { | 30 VisitScopedHandles(ObjectPointerVisitor* visitor) { |
32 HandlesBlock* block = &first_scoped_block_; | 31 HandlesBlock* block = &first_scoped_block_; |
33 do { | 32 do { |
34 block->VisitObjectPointers(visitor); | 33 block->VisitObjectPointers(visitor); |
35 if (block == scoped_blocks_) { | 34 if (block == scoped_blocks_) { |
36 return; | 35 return; |
37 } | 36 } |
38 block = block->next_block(); | 37 block = block->next_block(); |
39 } while (block != NULL); | 38 } while (block != NULL); |
40 UNREACHABLE(); | 39 UNREACHABLE(); |
41 } | 40 } |
42 | 41 |
43 | |
44 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 42 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
45 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::Visit( | 43 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::Visit( |
46 HandleVisitor* visitor) { | 44 HandleVisitor* visitor) { |
47 // Visit all zone handles. | 45 // Visit all zone handles. |
48 HandlesBlock* block = zone_blocks_; | 46 HandlesBlock* block = zone_blocks_; |
49 while (block != NULL) { | 47 while (block != NULL) { |
50 block->Visit(visitor); | 48 block->Visit(visitor); |
51 block = block->next_block(); | 49 block = block->next_block(); |
52 } | 50 } |
53 | 51 |
54 // Visit all scoped handles. | 52 // Visit all scoped handles. |
55 block = &first_scoped_block_; | 53 block = &first_scoped_block_; |
56 do { | 54 do { |
57 block->Visit(visitor); | 55 block->Visit(visitor); |
58 block = block->next_block(); | 56 block = block->next_block(); |
59 } while (block != NULL); | 57 } while (block != NULL); |
60 } | 58 } |
61 | 59 |
62 | |
63 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 60 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
64 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::Reset() { | 61 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::Reset() { |
65 // Delete all the extra zone handle blocks allocated and reinit the first | 62 // Delete all the extra zone handle blocks allocated and reinit the first |
66 // zone block. | 63 // zone block. |
67 if (zone_blocks_ != NULL) { | 64 if (zone_blocks_ != NULL) { |
68 DeleteHandleBlocks(zone_blocks_->next_block()); | 65 DeleteHandleBlocks(zone_blocks_->next_block()); |
69 zone_blocks_->ReInit(); | 66 zone_blocks_->ReInit(); |
70 } | 67 } |
71 | 68 |
72 // Delete all the extra scoped handle blocks allocated and reinit the first | 69 // Delete all the extra scoped handle blocks allocated and reinit the first |
73 // scoped block. | 70 // scoped block. |
74 DeleteHandleBlocks(first_scoped_block_.next_block()); | 71 DeleteHandleBlocks(first_scoped_block_.next_block()); |
75 first_scoped_block_.ReInit(); | 72 first_scoped_block_.ReInit(); |
76 scoped_blocks_ = &first_scoped_block_; | 73 scoped_blocks_ = &first_scoped_block_; |
77 } | 74 } |
78 | 75 |
79 | |
80 // Figure out the current handle scope using the current Zone and | 76 // Figure out the current handle scope using the current Zone and |
81 // allocate a handle in that scope. The function assumes that a | 77 // allocate a handle in that scope. The function assumes that a |
82 // current handle scope exists. It asserts for this appropriately. | 78 // current handle scope exists. It asserts for this appropriately. |
83 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 79 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
84 uword Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 80 uword Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
85 AllocateHandle(Zone* zone) { | 81 AllocateHandle(Zone* zone) { |
86 #if defined(DEBUG) | 82 #if defined(DEBUG) |
87 Thread* thread = Thread::Current(); | 83 Thread* thread = Thread::Current(); |
88 ASSERT(thread->top_handle_scope() != NULL); | 84 ASSERT(thread->top_handle_scope() != NULL); |
89 ASSERT(thread->no_handle_scope_depth() == 0); | 85 ASSERT(thread->no_handle_scope_depth() == 0); |
90 #endif // DEBUG | 86 #endif // DEBUG |
91 Handles* handles = zone->handles(); | 87 Handles* handles = zone->handles(); |
92 ASSERT(handles != NULL); | 88 ASSERT(handles != NULL); |
93 return handles->AllocateScopedHandle(); | 89 return handles->AllocateScopedHandle(); |
94 } | 90 } |
95 | 91 |
96 | |
97 // The function assumes that 'zone' is the current zone and asserts for | 92 // The function assumes that 'zone' is the current zone and asserts for |
98 // this appropriately. | 93 // this appropriately. |
99 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 94 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
100 uword Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 95 uword Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
101 AllocateZoneHandle(Zone* zone) { | 96 AllocateZoneHandle(Zone* zone) { |
102 #if defined(DEBUG) | 97 #if defined(DEBUG) |
103 Thread* thread = Thread::Current(); | 98 Thread* thread = Thread::Current(); |
104 ASSERT(thread->zone() == zone); | 99 ASSERT(thread->zone() == zone); |
105 ASSERT(thread->no_handle_scope_depth() == 0); | 100 ASSERT(thread->no_handle_scope_depth() == 0); |
106 #endif // DEBUG | 101 #endif // DEBUG |
107 Handles* handles = zone->handles(); | 102 Handles* handles = zone->handles(); |
108 ASSERT(handles != NULL); | 103 ASSERT(handles != NULL); |
109 uword address = handles->AllocateHandleInZone(); | 104 uword address = handles->AllocateHandleInZone(); |
110 return address; | 105 return address; |
111 } | 106 } |
112 | 107 |
113 | |
114 // Figure out the current zone using the current Thread and | 108 // Figure out the current zone using the current Thread and |
115 // check if the specified handle has been allocated in this zone. | 109 // check if the specified handle has been allocated in this zone. |
116 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 110 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
117 bool Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 111 bool Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
118 IsZoneHandle(uword handle) { | 112 IsZoneHandle(uword handle) { |
119 // TODO(5411412): Accessing the current thread is a performance problem, | 113 // TODO(5411412): Accessing the current thread is a performance problem, |
120 // consider passing it down as a parameter. | 114 // consider passing it down as a parameter. |
121 Thread* thread = Thread::Current(); | 115 Thread* thread = Thread::Current(); |
122 ASSERT(thread != NULL); | 116 ASSERT(thread != NULL); |
123 ASSERT(thread->zone() != NULL); | 117 ASSERT(thread->zone() != NULL); |
124 Handles* handles = thread->zone()->handles(); | 118 Handles* handles = thread->zone()->handles(); |
125 ASSERT(handles != NULL); | 119 ASSERT(handles != NULL); |
126 return handles->IsValidZoneHandle(handle); | 120 return handles->IsValidZoneHandle(handle); |
127 } | 121 } |
128 | 122 |
129 | |
130 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 123 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
131 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 124 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
132 DeleteAll() { | 125 DeleteAll() { |
133 // Delete all the zone allocated handle blocks. | 126 // Delete all the zone allocated handle blocks. |
134 // GCTrace does not need to trace this call to DeleteHandleBlocks, | 127 // GCTrace does not need to trace this call to DeleteHandleBlocks, |
135 // since the individual zone deletions will be caught | 128 // since the individual zone deletions will be caught |
136 // by instrumentation in the BaseZone destructor. | 129 // by instrumentation in the BaseZone destructor. |
137 DeleteHandleBlocks(zone_blocks_); | 130 DeleteHandleBlocks(zone_blocks_); |
138 zone_blocks_ = NULL; | 131 zone_blocks_ = NULL; |
139 | 132 |
140 // Delete all the scoped handle blocks. | 133 // Delete all the scoped handle blocks. |
141 scoped_blocks_ = first_scoped_block_.next_block(); | 134 scoped_blocks_ = first_scoped_block_.next_block(); |
142 DeleteHandleBlocks(scoped_blocks_); | 135 DeleteHandleBlocks(scoped_blocks_); |
143 first_scoped_block_.ReInit(); | 136 first_scoped_block_.ReInit(); |
144 scoped_blocks_ = &first_scoped_block_; | 137 scoped_blocks_ = &first_scoped_block_; |
145 } | 138 } |
146 | 139 |
147 | |
148 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 140 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
149 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 141 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
150 DeleteHandleBlocks(HandlesBlock* blocks) { | 142 DeleteHandleBlocks(HandlesBlock* blocks) { |
151 while (blocks != NULL) { | 143 while (blocks != NULL) { |
152 HandlesBlock* block = blocks; | 144 HandlesBlock* block = blocks; |
153 blocks = blocks->next_block(); | 145 blocks = blocks->next_block(); |
154 delete block; | 146 delete block; |
155 } | 147 } |
156 } | 148 } |
157 | 149 |
158 | |
159 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 150 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
160 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 151 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
161 SetupNextScopeBlock() { | 152 SetupNextScopeBlock() { |
162 if (FLAG_trace_handles) { | 153 if (FLAG_trace_handles) { |
163 OS::PrintErr("*** Handle Counts for (0x%" Px "):Zone = %d,Scoped = %d\n", | 154 OS::PrintErr("*** Handle Counts for (0x%" Px "):Zone = %d,Scoped = %d\n", |
164 reinterpret_cast<intptr_t>(this), CountZoneHandles(), | 155 reinterpret_cast<intptr_t>(this), CountZoneHandles(), |
165 CountScopedHandles()); | 156 CountScopedHandles()); |
166 } | 157 } |
167 if (scoped_blocks_->next_block() == NULL) { | 158 if (scoped_blocks_->next_block() == NULL) { |
168 scoped_blocks_->set_next_block(new HandlesBlock(NULL)); | 159 scoped_blocks_->set_next_block(new HandlesBlock(NULL)); |
169 } | 160 } |
170 scoped_blocks_ = scoped_blocks_->next_block(); | 161 scoped_blocks_ = scoped_blocks_->next_block(); |
171 scoped_blocks_->set_next_handle_slot(0); | 162 scoped_blocks_->set_next_handle_slot(0); |
172 #if defined(DEBUG) | 163 #if defined(DEBUG) |
173 scoped_blocks_->ZapFreeHandles(); | 164 scoped_blocks_->ZapFreeHandles(); |
174 #endif | 165 #endif |
175 } | 166 } |
176 | 167 |
177 | |
178 // Validation of the handle involves iterating through all the | 168 // Validation of the handle involves iterating through all the |
179 // handle blocks to check if the handle is valid, please | 169 // handle blocks to check if the handle is valid, please |
180 // use this only in ASSERT code for verification purposes. | 170 // use this only in ASSERT code for verification purposes. |
181 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 171 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
182 bool Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 172 bool Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
183 IsValidScopedHandle(uword handle) const { | 173 IsValidScopedHandle(uword handle) const { |
184 const HandlesBlock* iterator = &first_scoped_block_; | 174 const HandlesBlock* iterator = &first_scoped_block_; |
185 while (iterator != NULL) { | 175 while (iterator != NULL) { |
186 if (iterator->IsValidHandle(handle)) { | 176 if (iterator->IsValidHandle(handle)) { |
187 return true; | 177 return true; |
188 } | 178 } |
189 iterator = iterator->next_block(); | 179 iterator = iterator->next_block(); |
190 } | 180 } |
191 return false; | 181 return false; |
192 } | 182 } |
193 | 183 |
194 | |
195 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 184 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
196 bool Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 185 bool Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
197 IsValidZoneHandle(uword handle) const { | 186 IsValidZoneHandle(uword handle) const { |
198 const HandlesBlock* iterator = zone_blocks_; | 187 const HandlesBlock* iterator = zone_blocks_; |
199 while (iterator != NULL) { | 188 while (iterator != NULL) { |
200 if (iterator->IsValidHandle(handle)) { | 189 if (iterator->IsValidHandle(handle)) { |
201 return true; | 190 return true; |
202 } | 191 } |
203 iterator = iterator->next_block(); | 192 iterator = iterator->next_block(); |
204 } | 193 } |
205 return false; | 194 return false; |
206 } | 195 } |
207 | 196 |
208 | |
209 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 197 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
210 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 198 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
211 SetupNextZoneBlock() { | 199 SetupNextZoneBlock() { |
212 if (FLAG_trace_handles) { | 200 if (FLAG_trace_handles) { |
213 OS::PrintErr("*** Handle Counts for (0x%" Px "):Zone = %d,Scoped = %d\n", | 201 OS::PrintErr("*** Handle Counts for (0x%" Px "):Zone = %d,Scoped = %d\n", |
214 reinterpret_cast<intptr_t>(this), CountZoneHandles(), | 202 reinterpret_cast<intptr_t>(this), CountZoneHandles(), |
215 CountScopedHandles()); | 203 CountScopedHandles()); |
216 } | 204 } |
217 zone_blocks_ = new HandlesBlock(zone_blocks_); | 205 zone_blocks_ = new HandlesBlock(zone_blocks_); |
218 ASSERT(zone_blocks_ != NULL); | 206 ASSERT(zone_blocks_ != NULL); |
219 } | 207 } |
220 | 208 |
221 | |
222 #if defined(DEBUG) | 209 #if defined(DEBUG) |
223 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 210 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
224 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 211 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
225 VerifyScopedHandleState() { | 212 VerifyScopedHandleState() { |
226 HandlesBlock* block = &first_scoped_block_; | 213 HandlesBlock* block = &first_scoped_block_; |
227 const intptr_t end_index = (kHandleSizeInWords * kHandlesPerChunk); | 214 const intptr_t end_index = (kHandleSizeInWords * kHandlesPerChunk); |
228 do { | 215 do { |
229 if (scoped_blocks_ == block && block->next_handle_slot() <= end_index) { | 216 if (scoped_blocks_ == block && block->next_handle_slot() <= end_index) { |
230 return; | 217 return; |
231 } | 218 } |
232 block = block->next_block(); | 219 block = block->next_block(); |
233 } while (block != NULL); | 220 } while (block != NULL); |
234 ASSERT(false); | 221 ASSERT(false); |
235 } | 222 } |
236 | 223 |
237 | |
238 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 224 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
239 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 225 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
240 ZapFreeScopedHandles() { | 226 ZapFreeScopedHandles() { |
241 HandlesBlock* block = scoped_blocks_; | 227 HandlesBlock* block = scoped_blocks_; |
242 while (block != NULL) { | 228 while (block != NULL) { |
243 block->ZapFreeHandles(); | 229 block->ZapFreeHandles(); |
244 block = block->next_block(); | 230 block = block->next_block(); |
245 } | 231 } |
246 } | 232 } |
247 #endif | 233 #endif |
248 | 234 |
249 | |
250 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 235 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
251 int Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 236 int Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
252 CountScopedHandles() const { | 237 CountScopedHandles() const { |
253 int count = 0; | 238 int count = 0; |
254 const HandlesBlock* block = &first_scoped_block_; | 239 const HandlesBlock* block = &first_scoped_block_; |
255 do { | 240 do { |
256 count += block->HandleCount(); | 241 count += block->HandleCount(); |
257 if (block == scoped_blocks_) { | 242 if (block == scoped_blocks_) { |
258 return count; | 243 return count; |
259 } | 244 } |
260 block = block->next_block(); | 245 block = block->next_block(); |
261 } while (block != NULL); | 246 } while (block != NULL); |
262 UNREACHABLE(); | 247 UNREACHABLE(); |
263 return 0; | 248 return 0; |
264 } | 249 } |
265 | 250 |
266 | |
267 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 251 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
268 int Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 252 int Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
269 CountZoneHandles() const { | 253 CountZoneHandles() const { |
270 int count = 0; | 254 int count = 0; |
271 const HandlesBlock* block = zone_blocks_; | 255 const HandlesBlock* block = zone_blocks_; |
272 while (block != NULL) { | 256 while (block != NULL) { |
273 count += block->HandleCount(); | 257 count += block->HandleCount(); |
274 block = block->next_block(); | 258 block = block->next_block(); |
275 } | 259 } |
276 return count; | 260 return count; |
277 } | 261 } |
278 | 262 |
279 | |
280 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 263 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
281 Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::HandlesBlock:: | 264 Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::HandlesBlock:: |
282 ~HandlesBlock() { | 265 ~HandlesBlock() { |
283 #if defined(DEBUG) | 266 #if defined(DEBUG) |
284 ReInit(); | 267 ReInit(); |
285 #endif | 268 #endif |
286 } | 269 } |
287 | 270 |
288 | |
289 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 271 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
290 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 272 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
291 HandlesBlock::ReInit() { | 273 HandlesBlock::ReInit() { |
292 next_handle_slot_ = 0; | 274 next_handle_slot_ = 0; |
293 next_block_ = NULL; | 275 next_block_ = NULL; |
294 #if defined(DEBUG) | 276 #if defined(DEBUG) |
295 ZapFreeHandles(); | 277 ZapFreeHandles(); |
296 #endif | 278 #endif |
297 } | 279 } |
298 | 280 |
299 | |
300 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 281 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
301 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 282 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
302 HandlesBlock::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 283 HandlesBlock::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
303 ASSERT(visitor != NULL); | 284 ASSERT(visitor != NULL); |
304 for (intptr_t i = 0; i < next_handle_slot_; i += kHandleSizeInWords) { | 285 for (intptr_t i = 0; i < next_handle_slot_; i += kHandleSizeInWords) { |
305 visitor->VisitPointer( | 286 visitor->VisitPointer( |
306 reinterpret_cast<RawObject**>(&data_[i + kOffsetOfRawPtr / kWordSize])); | 287 reinterpret_cast<RawObject**>(&data_[i + kOffsetOfRawPtr / kWordSize])); |
307 } | 288 } |
308 } | 289 } |
309 | 290 |
310 | |
311 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 291 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
312 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 292 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
313 HandlesBlock::Visit(HandleVisitor* visitor) { | 293 HandlesBlock::Visit(HandleVisitor* visitor) { |
314 ASSERT(visitor != NULL); | 294 ASSERT(visitor != NULL); |
315 for (intptr_t i = 0; i < next_handle_slot_; i += kHandleSizeInWords) { | 295 for (intptr_t i = 0; i < next_handle_slot_; i += kHandleSizeInWords) { |
316 visitor->VisitHandle(reinterpret_cast<uword>(&data_[i])); | 296 visitor->VisitHandle(reinterpret_cast<uword>(&data_[i])); |
317 } | 297 } |
318 } | 298 } |
319 | 299 |
320 | |
321 #if defined(DEBUG) | 300 #if defined(DEBUG) |
322 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 301 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
323 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 302 void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
324 HandlesBlock::ZapFreeHandles() { | 303 HandlesBlock::ZapFreeHandles() { |
325 // Reinitialize the handle area to some uninitialized value. | 304 // Reinitialize the handle area to some uninitialized value. |
326 for (intptr_t i = next_handle_slot_; | 305 for (intptr_t i = next_handle_slot_; |
327 i < (kHandleSizeInWords * kHandlesPerChunk); i++) { | 306 i < (kHandleSizeInWords * kHandlesPerChunk); i++) { |
328 data_[i] = kZapUninitializedWord; | 307 data_[i] = kZapUninitializedWord; |
329 } | 308 } |
330 } | 309 } |
331 #endif | 310 #endif |
332 | 311 |
333 | |
334 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> | 312 template <int kHandleSizeInWords, int kHandlesPerChunk, int kOffsetOfRawPtr> |
335 int Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: | 313 int Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>:: |
336 HandlesBlock::HandleCount() const { | 314 HandlesBlock::HandleCount() const { |
337 return (next_handle_slot_ / kHandleSizeInWords); | 315 return (next_handle_slot_ / kHandleSizeInWords); |
338 } | 316 } |
339 | 317 |
340 } // namespace dart | 318 } // namespace dart |
341 | 319 |
342 #endif // RUNTIME_VM_HANDLES_IMPL_H_ | 320 #endif // RUNTIME_VM_HANDLES_IMPL_H_ |
OLD | NEW |