| 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 <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> |
| 9 | 10 |
| 10 #include "vm/allocation.h" | 11 #include "vm/allocation.h" |
| 11 #include "vm/dart_api_state.h" | 12 #include "vm/dart_api_state.h" |
| 12 #include "vm/isolate.h" | 13 #include "vm/isolate.h" |
| 13 #include "vm/pages.h" | 14 #include "vm/pages.h" |
| 14 #include "vm/raw_object.h" | 15 #include "vm/raw_object.h" |
| 15 #include "vm/stack_frame.h" | 16 #include "vm/stack_frame.h" |
| 16 #include "vm/visitor.h" | 17 #include "vm/visitor.h" |
| 17 #include "vm/object_id_ring.h" | 18 #include "vm/object_id_ring.h" |
| 18 | 19 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 186 |
| 186 // Mark the object and push it on the marking stack. | 187 // Mark the object and push it on the marking stack. |
| 187 ASSERT(!raw_obj->IsMarked()); | 188 ASSERT(!raw_obj->IsMarked()); |
| 188 RawClass* raw_class = isolate()->class_table()->At(raw_obj->GetClassId()); | 189 RawClass* raw_class = isolate()->class_table()->At(raw_obj->GetClassId()); |
| 189 raw_obj->SetMarkBit(); | 190 raw_obj->SetMarkBit(); |
| 190 raw_obj->ClearRememberedBit(); | 191 raw_obj->ClearRememberedBit(); |
| 191 if (raw_obj->IsWatched()) { | 192 if (raw_obj->IsWatched()) { |
| 192 std::pair<DelaySet::iterator, DelaySet::iterator> ret; | 193 std::pair<DelaySet::iterator, DelaySet::iterator> ret; |
| 193 // Visit all elements with a key equal to raw_obj. | 194 // Visit all elements with a key equal to raw_obj. |
| 194 ret = delay_set_.equal_range(raw_obj); | 195 ret = delay_set_.equal_range(raw_obj); |
| 195 for (DelaySet::iterator it = ret.first; it != ret.second; ++it) { | 196 // Create a copy of the range in a temporary vector to iterate over it |
| 197 // while delay_set_ may be modified. |
| 198 std::vector<DelaySetEntry> temp_copy(ret.first, ret.second); |
| 199 delay_set_.erase(ret.first, ret.second); |
| 200 for (std::vector<DelaySetEntry>::iterator it = temp_copy.begin(); |
| 201 it != temp_copy.end(); ++it) { |
| 196 it->second->VisitPointers(this); | 202 it->second->VisitPointers(this); |
| 197 } | 203 } |
| 198 delay_set_.erase(ret.first, ret.second); | |
| 199 raw_obj->ClearWatchedBit(); | 204 raw_obj->ClearWatchedBit(); |
| 200 } | 205 } |
| 201 marking_stack_->Push(raw_obj); | 206 marking_stack_->Push(raw_obj); |
| 202 | 207 |
| 203 // TODO(iposva): Should we mark the classes early? | 208 // TODO(iposva): Should we mark the classes early? |
| 204 MarkObject(raw_class, NULL); | 209 MarkObject(raw_class, NULL); |
| 205 } | 210 } |
| 206 | 211 |
| 207 void MarkObject(RawObject* raw_obj, RawObject** p) { | 212 void MarkObject(RawObject* raw_obj, RawObject** p) { |
| 208 // Fast exit if the raw object is a Smi. | 213 // Fast exit if the raw object is a Smi. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 } | 259 } |
| 255 } | 260 } |
| 256 } | 261 } |
| 257 | 262 |
| 258 Heap* heap_; | 263 Heap* heap_; |
| 259 Heap* vm_heap_; | 264 Heap* vm_heap_; |
| 260 PageSpace* page_space_; | 265 PageSpace* page_space_; |
| 261 MarkingStack* marking_stack_; | 266 MarkingStack* marking_stack_; |
| 262 RawObject* visiting_old_object_; | 267 RawObject* visiting_old_object_; |
| 263 typedef std::multimap<RawObject*, RawWeakProperty*> DelaySet; | 268 typedef std::multimap<RawObject*, RawWeakProperty*> DelaySet; |
| 269 typedef std::pair<RawObject*, RawWeakProperty*> DelaySetEntry; |
| 264 DelaySet delay_set_; | 270 DelaySet delay_set_; |
| 265 const bool visit_function_code_; | 271 const bool visit_function_code_; |
| 266 GrowableArray<RawFunction*> skipped_code_functions_; | 272 GrowableArray<RawFunction*> skipped_code_functions_; |
| 267 | 273 |
| 268 DISALLOW_IMPLICIT_CONSTRUCTORS(MarkingVisitor); | 274 DISALLOW_IMPLICIT_CONSTRUCTORS(MarkingVisitor); |
| 269 }; | 275 }; |
| 270 | 276 |
| 271 | 277 |
| 272 bool IsUnreachable(const RawObject* raw_obj) { | 278 bool IsUnreachable(const RawObject* raw_obj) { |
| 273 if (!raw_obj->IsHeapObject()) { | 279 if (!raw_obj->IsHeapObject()) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 MarkingWeakVisitor mark_weak; | 490 MarkingWeakVisitor mark_weak; |
| 485 IterateWeakRoots(isolate, &mark_weak, invoke_api_callbacks); | 491 IterateWeakRoots(isolate, &mark_weak, invoke_api_callbacks); |
| 486 mark.Finalize(); | 492 mark.Finalize(); |
| 487 ProcessWeakTables(page_space); | 493 ProcessWeakTables(page_space); |
| 488 ProcessObjectIdTable(isolate); | 494 ProcessObjectIdTable(isolate); |
| 489 | 495 |
| 490 Epilogue(isolate, invoke_api_callbacks); | 496 Epilogue(isolate, invoke_api_callbacks); |
| 491 } | 497 } |
| 492 | 498 |
| 493 } // namespace dart | 499 } // namespace dart |
| OLD | NEW |