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/log.h" | 10 #include "vm/log.h" |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 } | 603 } |
604 | 604 |
605 // If no tasks are busy, there will never be more work. | 605 // If no tasks are busy, there will never be more work. |
606 if (AtomicOperations::LoadRelaxed(num_busy_) == 0) break; | 606 if (AtomicOperations::LoadRelaxed(num_busy_) == 0) break; |
607 | 607 |
608 // I saw some work; get busy and compete for it. | 608 // I saw some work; get busy and compete for it. |
609 AtomicOperations::FetchAndIncrement(num_busy_); | 609 AtomicOperations::FetchAndIncrement(num_busy_); |
610 } while (true); | 610 } while (true); |
611 // Wait for all markers to stop. | 611 // Wait for all markers to stop. |
612 barrier_->Sync(); | 612 barrier_->Sync(); |
| 613 #if defined(DEBUG) |
613 ASSERT(AtomicOperations::LoadRelaxed(num_busy_) == 0); | 614 ASSERT(AtomicOperations::LoadRelaxed(num_busy_) == 0); |
614 | 615 // Caveat: must not allow any marker to continue past the barrier |
| 616 // before we checked num_busy, otherwise one of them might rush |
| 617 // ahead and increment it. |
| 618 barrier_->Sync(); |
| 619 #endif |
615 // Check if we have any pending properties with marked keys. | 620 // Check if we have any pending properties with marked keys. |
616 // Those might have been marked by another marker. | 621 // Those might have been marked by another marker. |
617 more_to_mark = visitor.ProcessPendingWeakProperties(); | 622 more_to_mark = visitor.ProcessPendingWeakProperties(); |
618 if (more_to_mark) { | 623 if (more_to_mark) { |
619 // We have more work to do. Notify others. | 624 // We have more work to do. Notify others. |
620 AtomicOperations::FetchAndIncrement(num_busy_); | 625 AtomicOperations::FetchAndIncrement(num_busy_); |
621 } | 626 } |
622 | 627 |
623 // Wait for all other markers to finish processing their pending | 628 // Wait for all other markers to finish processing their pending |
624 // weak properties and decide if they need to continue marking. | 629 // weak properties and decide if they need to continue marking. |
625 // Caveat: we need two barriers here to make this decision in lock step | 630 // Caveat: we need two barriers here to make this decision in lock step |
626 // between all markers and the main thread. | 631 // between all markers and the main thread. |
627 barrier_->Sync(); | 632 barrier_->Sync(); |
628 if (!more_to_mark && (AtomicOperations::LoadRelaxed(num_busy_) > 0)) { | 633 if (!more_to_mark && (AtomicOperations::LoadRelaxed(num_busy_) > 0)) { |
629 // All markers continue to marker as long as any single marker has | 634 // All markers continue to mark as long as any single marker has |
630 // some work to do. | 635 // some work to do. |
631 AtomicOperations::FetchAndIncrement(num_busy_); | 636 AtomicOperations::FetchAndIncrement(num_busy_); |
632 more_to_mark = true; | 637 more_to_mark = true; |
633 } | 638 } |
634 barrier_->Sync(); | 639 barrier_->Sync(); |
635 } while (more_to_mark); | 640 } while (more_to_mark); |
636 | 641 |
637 // Phase 2: Weak processing and follow-up marking on main thread. | 642 // Phase 2: Weak processing and follow-up marking on main thread. |
638 barrier_->Sync(); | 643 barrier_->Sync(); |
639 | 644 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 new MarkTask(this, isolate, heap_, page_space, &marking_stack, | 745 new MarkTask(this, isolate, heap_, page_space, &marking_stack, |
741 &barrier, collect_code, | 746 &barrier, collect_code, |
742 i, num_tasks, &num_busy); | 747 i, num_tasks, &num_busy); |
743 ThreadPool* pool = Dart::thread_pool(); | 748 ThreadPool* pool = Dart::thread_pool(); |
744 pool->Run(mark_task); | 749 pool->Run(mark_task); |
745 } | 750 } |
746 bool more_to_mark = false; | 751 bool more_to_mark = false; |
747 do { | 752 do { |
748 // Wait for all markers to stop. | 753 // Wait for all markers to stop. |
749 barrier.Sync(); | 754 barrier.Sync(); |
| 755 #if defined(DEBUG) |
| 756 ASSERT(AtomicOperations::LoadRelaxed(&num_busy) == 0); |
| 757 // Caveat: must not allow any marker to continue past the barrier |
| 758 // before we checked num_busy, otherwise one of them might rush |
| 759 // ahead and increment it. |
| 760 barrier.Sync(); |
| 761 #endif |
750 | 762 |
751 // Wait for all markers to go through weak properties and verify | 763 // Wait for all markers to go through weak properties and verify |
752 // that there are no more objects to mark. | 764 // that there are no more objects to mark. |
753 // Note: we need to have two barriers here because we want all markers | 765 // Note: we need to have two barriers here because we want all markers |
754 // and main thread to make decisions in lock step. | 766 // and main thread to make decisions in lock step. |
755 barrier.Sync(); | 767 barrier.Sync(); |
756 more_to_mark = AtomicOperations::LoadRelaxed(&num_busy) > 0; | 768 more_to_mark = AtomicOperations::LoadRelaxed(&num_busy) > 0; |
757 barrier.Sync(); | 769 barrier.Sync(); |
758 } while (more_to_mark); | 770 } while (more_to_mark); |
759 | 771 |
(...skipping 19 matching lines...) Expand all Loading... |
779 // Phase 3: Finalize results from all markers (detach code, etc.). | 791 // Phase 3: Finalize results from all markers (detach code, etc.). |
780 barrier.Exit(); | 792 barrier.Exit(); |
781 } | 793 } |
782 ProcessWeakTables(page_space); | 794 ProcessWeakTables(page_space); |
783 ProcessObjectIdTable(isolate); | 795 ProcessObjectIdTable(isolate); |
784 } | 796 } |
785 Epilogue(isolate, invoke_api_callbacks); | 797 Epilogue(isolate, invoke_api_callbacks); |
786 } | 798 } |
787 | 799 |
788 } // namespace dart | 800 } // namespace dart |
OLD | NEW |