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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 !raw_key->IsMarked()) { | 372 !raw_key->IsMarked()) { |
373 // Key is white. Delay the weak property. | 373 // Key is white. Delay the weak property. |
374 visitor->DelayWeakProperty(raw_weak); | 374 visitor->DelayWeakProperty(raw_weak); |
375 } else { | 375 } else { |
376 // Key is gray or black. Make the weak property black. | 376 // Key is gray or black. Make the weak property black. |
377 raw_weak->VisitPointers(visitor); | 377 raw_weak->VisitPointers(visitor); |
378 } | 378 } |
379 } | 379 } |
380 | 380 |
381 | 381 |
382 void GCMarker::ProcessPeerReferents(PageSpace* page_space) { | 382 void GCMarker::ProcessWeakTables(PageSpace* page_space) { |
383 PageSpace::PeerTable* peer_table = page_space->GetPeerTable(); | 383 for (int sel = 0; |
384 PageSpace::PeerTable::iterator it = peer_table->begin(); | 384 sel < Heap::kNumWeakSelectors; |
385 while (it != peer_table->end()) { | 385 sel++) { |
386 RawObject* raw_obj = it->first; | 386 WeakTable* table = heap_->GetWeakTable( |
387 ASSERT(raw_obj->IsHeapObject()); | 387 Heap::kOld, static_cast<Heap::WeakSelector>(sel)); |
388 if (raw_obj->IsMarked()) { | 388 intptr_t size = table->size(); |
389 // The object has survived. Do nothing. | 389 for (intptr_t i = 0; i < size; i++) { |
390 ++it; | 390 if (table->IsValidEntryAt(i)) { |
391 } else { | 391 RawObject* raw_obj = table->ObjectAt(i); |
392 // The object has become garbage. Remove its record. | 392 ASSERT(raw_obj->IsHeapObject()); |
393 peer_table->erase(it++); | 393 if (!raw_obj->IsMarked()) { |
| 394 table->InvalidateAt(i); |
| 395 } |
| 396 } |
394 } | 397 } |
395 } | 398 } |
396 } | 399 } |
397 | 400 |
398 | 401 |
399 void GCMarker::MarkObjects(Isolate* isolate, | 402 void GCMarker::MarkObjects(Isolate* isolate, |
400 PageSpace* page_space, | 403 PageSpace* page_space, |
401 bool invoke_api_callbacks) { | 404 bool invoke_api_callbacks) { |
402 MarkingStack marking_stack; | 405 MarkingStack marking_stack; |
403 Prologue(isolate, invoke_api_callbacks); | 406 Prologue(isolate, invoke_api_callbacks); |
404 MarkingVisitor mark(isolate, heap_, page_space, &marking_stack); | 407 MarkingVisitor mark(isolate, heap_, page_space, &marking_stack); |
405 IterateRoots(isolate, &mark, !invoke_api_callbacks); | 408 IterateRoots(isolate, &mark, !invoke_api_callbacks); |
406 DrainMarkingStack(isolate, &mark); | 409 DrainMarkingStack(isolate, &mark); |
407 IterateWeakReferences(isolate, &mark); | 410 IterateWeakReferences(isolate, &mark); |
408 MarkingWeakVisitor mark_weak; | 411 MarkingWeakVisitor mark_weak; |
409 IterateWeakRoots(isolate, &mark_weak, invoke_api_callbacks); | 412 IterateWeakRoots(isolate, &mark_weak, invoke_api_callbacks); |
410 mark.Finalize(); | 413 mark.Finalize(); |
411 ProcessPeerReferents(page_space); | 414 ProcessWeakTables(page_space); |
412 Epilogue(isolate, invoke_api_callbacks); | 415 Epilogue(isolate, invoke_api_callbacks); |
413 } | 416 } |
414 | 417 |
415 } // namespace dart | 418 } // namespace dart |
OLD | NEW |