| 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 | 9 |
| 10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 void MarkAndPush(RawObject* raw_obj) { | 168 void MarkAndPush(RawObject* raw_obj) { |
| 169 ASSERT(raw_obj->IsHeapObject()); | 169 ASSERT(raw_obj->IsHeapObject()); |
| 170 ASSERT((FLAG_verify_before_gc || FLAG_verify_before_gc) ? | 170 ASSERT((FLAG_verify_before_gc || FLAG_verify_before_gc) ? |
| 171 page_space_->Contains(RawObject::ToAddr(raw_obj)) : | 171 page_space_->Contains(RawObject::ToAddr(raw_obj)) : |
| 172 true); | 172 true); |
| 173 | 173 |
| 174 // Mark the object and push it on the marking stack. | 174 // Mark the object and push it on the marking stack. |
| 175 ASSERT(!raw_obj->IsMarked()); | 175 ASSERT(!raw_obj->IsMarked()); |
| 176 RawClass* raw_class = isolate()->class_table()->At(raw_obj->GetClassId()); | 176 RawClass* raw_class = isolate()->class_table()->At(raw_obj->GetClassId()); |
| 177 raw_obj->SetMarkBit(); | 177 raw_obj->SetMarkBit(); |
| 178 raw_obj->ClearRememberedBit(); |
| 178 if (raw_obj->IsWatched()) { | 179 if (raw_obj->IsWatched()) { |
| 179 std::pair<DelaySet::iterator, DelaySet::iterator> ret; | 180 std::pair<DelaySet::iterator, DelaySet::iterator> ret; |
| 180 // Visit all elements with a key equal to raw_obj. | 181 // Visit all elements with a key equal to raw_obj. |
| 181 ret = delay_set_.equal_range(raw_obj); | 182 ret = delay_set_.equal_range(raw_obj); |
| 182 for (DelaySet::iterator it = ret.first; it != ret.second; ++it) { | 183 for (DelaySet::iterator it = ret.first; it != ret.second; ++it) { |
| 183 it->second->VisitPointers(this); | 184 it->second->VisitPointers(this); |
| 184 } | 185 } |
| 185 delay_set_.erase(ret.first, ret.second); | 186 delay_set_.erase(ret.first, ret.second); |
| 186 raw_obj->ClearWatchedBit(); | 187 raw_obj->ClearWatchedBit(); |
| 187 } | 188 } |
| 188 marking_stack_->Push(raw_obj); | 189 marking_stack_->Push(raw_obj); |
| 189 | 190 |
| 190 // TODO(iposva): Should we mark the classes early? | 191 // TODO(iposva): Should we mark the classes early? |
| 191 MarkObject(raw_class, NULL); | 192 MarkObject(raw_class, NULL); |
| 192 } | 193 } |
| 193 | 194 |
| 194 void MarkObject(RawObject* raw_obj, RawObject** p) { | 195 void MarkObject(RawObject* raw_obj, RawObject** p) { |
| 195 // Fast exit if the raw object is a Smi. | 196 // Fast exit if the raw object is a Smi. |
| 196 if (!raw_obj->IsHeapObject()) return; | 197 if (!raw_obj->IsHeapObject()) return; |
| 197 | 198 |
| 198 // Fast exit if the raw object is marked. | 199 // Fast exit if the raw object is marked. |
| 199 if (raw_obj->IsMarked()) return; | 200 if (raw_obj->IsMarked()) return; |
| 200 | 201 |
| 201 // Skip over new objects, but verify consistency of heap while at it. | 202 // Skip over new objects, but verify consistency of heap while at it. |
| 202 if (raw_obj->IsNewObject()) { | 203 if (raw_obj->IsNewObject()) { |
| 203 // TODO(iposva): Add consistency check. | 204 // TODO(iposva): Add consistency check. |
| 204 if (visiting_old_object_ != NULL) { | 205 if ((visiting_old_object_ != NULL) && |
| 206 !visiting_old_object_->IsRemembered()) { |
| 205 ASSERT(p != NULL); | 207 ASSERT(p != NULL); |
| 206 isolate()->store_buffer()->AddPointer( | 208 visiting_old_object_->SetRememberedBit(); |
| 207 reinterpret_cast<uword>(visiting_old_object_)); | 209 isolate()->store_buffer()->AddObjectGC(visiting_old_object_); |
| 208 } | 210 } |
| 209 return; | 211 return; |
| 210 } | 212 } |
| 211 | 213 |
| 212 MarkAndPush(raw_obj); | 214 MarkAndPush(raw_obj); |
| 213 } | 215 } |
| 214 | 216 |
| 215 Heap* heap_; | 217 Heap* heap_; |
| 216 Heap* vm_heap_; | 218 Heap* vm_heap_; |
| 217 PageSpace* page_space_; | 219 PageSpace* page_space_; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 DISALLOW_COPY_AND_ASSIGN(MarkingWeakVisitor); | 258 DISALLOW_COPY_AND_ASSIGN(MarkingWeakVisitor); |
| 257 }; | 259 }; |
| 258 | 260 |
| 259 | 261 |
| 260 void GCMarker::Prologue(Isolate* isolate, bool invoke_api_callbacks) { | 262 void GCMarker::Prologue(Isolate* isolate, bool invoke_api_callbacks) { |
| 261 if (invoke_api_callbacks) { | 263 if (invoke_api_callbacks) { |
| 262 isolate->gc_prologue_callbacks().Invoke(); | 264 isolate->gc_prologue_callbacks().Invoke(); |
| 263 } | 265 } |
| 264 // The store buffers will be rebuilt as part of marking, reset them now. | 266 // The store buffers will be rebuilt as part of marking, reset them now. |
| 265 isolate->store_buffer()->Reset(); | 267 isolate->store_buffer()->Reset(); |
| 266 isolate->store_buffer_block()->Reset(); | |
| 267 } | 268 } |
| 268 | 269 |
| 269 | 270 |
| 270 void GCMarker::Epilogue(Isolate* isolate, bool invoke_api_callbacks) { | 271 void GCMarker::Epilogue(Isolate* isolate, bool invoke_api_callbacks) { |
| 271 if (invoke_api_callbacks) { | 272 if (invoke_api_callbacks) { |
| 272 isolate->gc_epilogue_callbacks().Invoke(); | 273 isolate->gc_epilogue_callbacks().Invoke(); |
| 273 } | 274 } |
| 274 } | 275 } |
| 275 | 276 |
| 276 | 277 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 DrainMarkingStack(isolate, &mark); | 406 DrainMarkingStack(isolate, &mark); |
| 406 IterateWeakReferences(isolate, &mark); | 407 IterateWeakReferences(isolate, &mark); |
| 407 MarkingWeakVisitor mark_weak; | 408 MarkingWeakVisitor mark_weak; |
| 408 IterateWeakRoots(isolate, &mark_weak, invoke_api_callbacks); | 409 IterateWeakRoots(isolate, &mark_weak, invoke_api_callbacks); |
| 409 mark.Finalize(); | 410 mark.Finalize(); |
| 410 ProcessPeerReferents(page_space); | 411 ProcessPeerReferents(page_space); |
| 411 Epilogue(isolate, invoke_api_callbacks); | 412 Epilogue(isolate, invoke_api_callbacks); |
| 412 } | 413 } |
| 413 | 414 |
| 414 } // namespace dart | 415 } // namespace dart |
| OLD | NEW |