OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #include "vm/gc_marker.h" | 5 #include "vm/gc_marker.h" |
6 | 6 |
7 #include "vm/allocation.h" | 7 #include "vm/allocation.h" |
8 #include "vm/dart_api_state.h" | 8 #include "vm/dart_api_state.h" |
9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
10 #include "vm/pages.h" | 10 #include "vm/pages.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 return !raw_obj->IsMarked(); | 198 return !raw_obj->IsMarked(); |
199 } | 199 } |
200 | 200 |
201 | 201 |
202 class MarkingWeakVisitor : public HandleVisitor { | 202 class MarkingWeakVisitor : public HandleVisitor { |
203 public: | 203 public: |
204 MarkingWeakVisitor() { | 204 MarkingWeakVisitor() { |
205 } | 205 } |
206 | 206 |
207 void VisitHandle(uword addr) { | 207 void VisitHandle(uword addr) { |
208 WeakPersistentHandle* handle = | 208 FinalizablePersistentHandle* handle = |
209 reinterpret_cast<WeakPersistentHandle*>(addr); | 209 reinterpret_cast<FinalizablePersistentHandle*>(addr); |
210 RawObject* raw_obj = handle->raw(); | 210 RawObject* raw_obj = handle->raw(); |
211 if (IsUnreachable(raw_obj)) { | 211 if (IsUnreachable(raw_obj)) { |
212 WeakPersistentHandle::Finalize(handle); | 212 FinalizablePersistentHandle::Finalize(handle); |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 private: | 216 private: |
217 DISALLOW_COPY_AND_ASSIGN(MarkingWeakVisitor); | 217 DISALLOW_COPY_AND_ASSIGN(MarkingWeakVisitor); |
218 }; | 218 }; |
219 | 219 |
220 | 220 |
221 void GCMarker::Prologue(Isolate* isolate) { | 221 void GCMarker::Prologue(Isolate* isolate, bool invoke_api_callbacks) { |
222 // Always invoke the prologue callbacks. | 222 if (invoke_api_callbacks) { |
223 isolate->gc_prologue_callbacks().Invoke(); | 223 isolate->gc_prologue_callbacks().Invoke(); |
| 224 } |
224 } | 225 } |
225 | 226 |
226 | 227 |
227 void GCMarker::Epilogue(Isolate* isolate) { | 228 void GCMarker::Epilogue(Isolate* isolate, bool invoke_api_callbacks) { |
228 // Always invoke the epilogue callbacks. | 229 if (invoke_api_callbacks) { |
229 isolate->gc_epilogue_callbacks().Invoke(); | 230 isolate->gc_epilogue_callbacks().Invoke(); |
| 231 } |
230 } | 232 } |
231 | 233 |
232 | 234 |
233 void GCMarker::IterateRoots(Isolate* isolate, ObjectPointerVisitor* visitor) { | 235 void GCMarker::IterateRoots(Isolate* isolate, |
| 236 ObjectPointerVisitor* visitor, |
| 237 bool visit_prologue_weak_persistent_handles) { |
234 isolate->VisitObjectPointers(visitor, | 238 isolate->VisitObjectPointers(visitor, |
| 239 visit_prologue_weak_persistent_handles, |
235 StackFrameIterator::kDontValidateFrames); | 240 StackFrameIterator::kDontValidateFrames); |
236 heap_->IterateNewPointers(visitor); | 241 heap_->IterateNewPointers(visitor); |
237 heap_->IterateCodePointers(visitor); | 242 heap_->IterateCodePointers(visitor); |
238 } | 243 } |
239 | 244 |
240 | 245 |
241 void GCMarker::IterateWeakRoots(Isolate* isolate, HandleVisitor* visitor) { | 246 void GCMarker::IterateWeakRoots(Isolate* isolate, |
242 isolate->VisitWeakPersistentHandles(visitor); | 247 HandleVisitor* visitor, |
| 248 bool visit_prologue_weak_persistent_handles) { |
| 249 ApiState* state = isolate->api_state(); |
| 250 ASSERT(state != NULL); |
| 251 isolate->VisitWeakPersistentHandles(visitor, |
| 252 visit_prologue_weak_persistent_handles); |
243 } | 253 } |
244 | 254 |
245 | 255 |
246 void GCMarker::IterateWeakReferences(Isolate* isolate, | 256 void GCMarker::IterateWeakReferences(Isolate* isolate, |
247 MarkingVisitor* visitor) { | 257 MarkingVisitor* visitor) { |
248 ApiState* state = isolate->api_state(); | 258 ApiState* state = isolate->api_state(); |
249 ASSERT(state != NULL); | 259 ASSERT(state != NULL); |
250 while (true) { | 260 while (true) { |
251 WeakReference* queue = state->delayed_weak_references(); | 261 WeakReference* queue = state->delayed_weak_references(); |
252 if (queue == NULL) { | 262 if (queue == NULL) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 307 |
298 void GCMarker::DrainMarkingStack(Isolate* isolate, | 308 void GCMarker::DrainMarkingStack(Isolate* isolate, |
299 MarkingVisitor* visitor) { | 309 MarkingVisitor* visitor) { |
300 while (!visitor->marking_stack()->IsEmpty()) { | 310 while (!visitor->marking_stack()->IsEmpty()) { |
301 RawObject* raw_obj = visitor->marking_stack()->Pop(); | 311 RawObject* raw_obj = visitor->marking_stack()->Pop(); |
302 raw_obj->VisitPointers(visitor); | 312 raw_obj->VisitPointers(visitor); |
303 } | 313 } |
304 } | 314 } |
305 | 315 |
306 | 316 |
307 void GCMarker::MarkObjects(Isolate* isolate, PageSpace* page_space) { | 317 void GCMarker::MarkObjects(Isolate* isolate, |
| 318 PageSpace* page_space, |
| 319 bool invoke_api_callbacks) { |
308 MarkingStack marking_stack; | 320 MarkingStack marking_stack; |
309 Prologue(isolate); | 321 Prologue(isolate, invoke_api_callbacks); |
310 MarkingVisitor mark(heap_, page_space, &marking_stack); | 322 MarkingVisitor mark(heap_, page_space, &marking_stack); |
311 IterateRoots(isolate, &mark); | 323 IterateRoots(isolate, &mark, !invoke_api_callbacks); |
312 DrainMarkingStack(isolate, &mark); | 324 DrainMarkingStack(isolate, &mark); |
313 IterateWeakReferences(isolate, &mark); | 325 IterateWeakReferences(isolate, &mark); |
314 MarkingWeakVisitor mark_weak; | 326 MarkingWeakVisitor mark_weak; |
315 IterateWeakRoots(isolate, &mark_weak); | 327 IterateWeakRoots(isolate, &mark_weak, invoke_api_callbacks); |
316 Epilogue(isolate); | 328 Epilogue(isolate, invoke_api_callbacks); |
317 } | 329 } |
318 | 330 |
319 } // namespace dart | 331 } // namespace dart |
OLD | NEW |