| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 MarkingStackChunk* empty_chunks_; | 109 MarkingStackChunk* empty_chunks_; |
| 110 RawObject** marking_stack_; | 110 RawObject** marking_stack_; |
| 111 uint32_t top_; | 111 uint32_t top_; |
| 112 | 112 |
| 113 DISALLOW_COPY_AND_ASSIGN(MarkingStack); | 113 DISALLOW_COPY_AND_ASSIGN(MarkingStack); |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 | 116 |
| 117 class MarkingVisitor : public ObjectPointerVisitor { | 117 class MarkingVisitor : public ObjectPointerVisitor { |
| 118 public: | 118 public: |
| 119 MarkingVisitor(Heap* heap, PageSpace* page_space, MarkingStack* marking_stack) | 119 MarkingVisitor(Isolate* isolate, |
| 120 : heap_(heap), | 120 Heap* heap, |
| 121 PageSpace* page_space, |
| 122 MarkingStack* marking_stack) |
| 123 : isolate_(isolate), |
| 124 heap_(heap), |
| 121 vm_heap_(Dart::vm_isolate()->heap()), | 125 vm_heap_(Dart::vm_isolate()->heap()), |
| 122 page_space_(page_space), | 126 page_space_(page_space), |
| 123 marking_stack_(marking_stack) { | 127 marking_stack_(marking_stack) { |
| 124 ASSERT(heap_ != vm_heap_); | 128 ASSERT(heap_ != vm_heap_); |
| 125 } | 129 } |
| 126 | 130 |
| 127 MarkingStack* marking_stack() const { return marking_stack_; } | 131 MarkingStack* marking_stack() const { return marking_stack_; } |
| 128 | 132 |
| 129 void VisitPointers(RawObject** first, RawObject** last) { | 133 void VisitPointers(RawObject** first, RawObject** last) { |
| 130 for (RawObject** current = first; current <= last; current++) { | 134 for (RawObject** current = first; current <= last; current++) { |
| 131 MarkObject(*current); | 135 MarkObject(*current); |
| 132 } | 136 } |
| 133 } | 137 } |
| 134 | 138 |
| 135 private: | 139 private: |
| 136 void MarkAndPush(RawObject* raw_obj) { | 140 void MarkAndPush(RawObject* raw_obj) { |
| 137 ASSERT(raw_obj->IsHeapObject()); | 141 ASSERT(raw_obj->IsHeapObject()); |
| 138 ASSERT(page_space_->Contains(RawObject::ToAddr(raw_obj))); | 142 ASSERT(page_space_->Contains(RawObject::ToAddr(raw_obj))); |
| 139 | 143 |
| 140 // Mark the object and push it on the marking stack. | 144 // Mark the object and push it on the marking stack. |
| 141 ASSERT(!raw_obj->IsMarked()); | 145 ASSERT(!raw_obj->IsMarked()); |
| 142 RawClass* raw_class = raw_obj->ptr()->class_; | 146 RawClass* raw_class = isolate_->class_table()->At(raw_obj->GetClassIndex()); |
| 143 raw_obj->SetMarkBit(); | 147 raw_obj->SetMarkBit(); |
| 144 marking_stack_->Push(raw_obj); | 148 marking_stack_->Push(raw_obj); |
| 145 | 149 |
| 146 // Update the number of used bytes on this page for fast accounting. | 150 // Update the number of used bytes on this page for fast accounting. |
| 147 HeapPage* page = PageSpace::PageFor(raw_obj); | 151 HeapPage* page = PageSpace::PageFor(raw_obj); |
| 148 page->AddUsed(raw_obj->Size()); | 152 page->AddUsed(raw_obj->Size()); |
| 149 | 153 |
| 150 // TODO(iposva): Should we mark the classes early? | 154 // TODO(iposva): Should we mark the classes early? |
| 151 MarkObject(raw_class); | 155 MarkObject(raw_class); |
| 152 } | 156 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 167 uword raw_addr = RawObject::ToAddr(raw_obj); | 171 uword raw_addr = RawObject::ToAddr(raw_obj); |
| 168 // TODO(iposva): Premark vm_isolate objects, to avoid this extra check here. | 172 // TODO(iposva): Premark vm_isolate objects, to avoid this extra check here. |
| 169 if (vm_heap_->Contains(raw_addr)) { | 173 if (vm_heap_->Contains(raw_addr)) { |
| 170 return; | 174 return; |
| 171 } | 175 } |
| 172 // TODO(iposva): merge old and code spaces. | 176 // TODO(iposva): merge old and code spaces. |
| 173 ASSERT(page_space_->Contains(raw_addr)); | 177 ASSERT(page_space_->Contains(raw_addr)); |
| 174 MarkAndPush(raw_obj); | 178 MarkAndPush(raw_obj); |
| 175 } | 179 } |
| 176 | 180 |
| 181 Isolate* isolate_; |
| 177 Heap* heap_; | 182 Heap* heap_; |
| 178 Heap* vm_heap_; | 183 Heap* vm_heap_; |
| 179 PageSpace* page_space_; | 184 PageSpace* page_space_; |
| 180 MarkingStack* marking_stack_; | 185 MarkingStack* marking_stack_; |
| 181 | 186 |
| 182 DISALLOW_IMPLICIT_CONSTRUCTORS(MarkingVisitor); | 187 DISALLOW_IMPLICIT_CONSTRUCTORS(MarkingVisitor); |
| 183 }; | 188 }; |
| 184 | 189 |
| 185 | 190 |
| 186 bool IsUnreachable(const RawObject* raw_obj) { | 191 bool IsUnreachable(const RawObject* raw_obj) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 raw_obj->VisitPointers(visitor); | 312 raw_obj->VisitPointers(visitor); |
| 308 } | 313 } |
| 309 } | 314 } |
| 310 | 315 |
| 311 | 316 |
| 312 void GCMarker::MarkObjects(Isolate* isolate, | 317 void GCMarker::MarkObjects(Isolate* isolate, |
| 313 PageSpace* page_space, | 318 PageSpace* page_space, |
| 314 bool invoke_api_callbacks) { | 319 bool invoke_api_callbacks) { |
| 315 MarkingStack marking_stack; | 320 MarkingStack marking_stack; |
| 316 Prologue(isolate, invoke_api_callbacks); | 321 Prologue(isolate, invoke_api_callbacks); |
| 317 MarkingVisitor mark(heap_, page_space, &marking_stack); | 322 MarkingVisitor mark(isolate, heap_, page_space, &marking_stack); |
| 318 IterateRoots(isolate, &mark, !invoke_api_callbacks); | 323 IterateRoots(isolate, &mark, !invoke_api_callbacks); |
| 319 DrainMarkingStack(isolate, &mark); | 324 DrainMarkingStack(isolate, &mark); |
| 320 IterateWeakReferences(isolate, &mark); | 325 IterateWeakReferences(isolate, &mark); |
| 321 MarkingWeakVisitor mark_weak; | 326 MarkingWeakVisitor mark_weak; |
| 322 IterateWeakRoots(isolate, &mark_weak, invoke_api_callbacks); | 327 IterateWeakRoots(isolate, &mark_weak, invoke_api_callbacks); |
| 323 Epilogue(isolate, invoke_api_callbacks); | 328 Epilogue(isolate, invoke_api_callbacks); |
| 324 } | 329 } |
| 325 | 330 |
| 326 } // namespace dart | 331 } // namespace dart |
| OLD | NEW |