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 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 | 645 |
646 | 646 |
647 void GCMarker::MarkObjects(Isolate* isolate, | 647 void GCMarker::MarkObjects(Isolate* isolate, |
648 PageSpace* page_space, | 648 PageSpace* page_space, |
649 bool invoke_api_callbacks, | 649 bool invoke_api_callbacks, |
650 bool collect_code) { | 650 bool collect_code) { |
651 Prologue(isolate, invoke_api_callbacks); | 651 Prologue(isolate, invoke_api_callbacks); |
652 // The API prologue/epilogue may create/destroy zones, so we must not | 652 // The API prologue/epilogue may create/destroy zones, so we must not |
653 // depend on zone allocations surviving beyond the epilogue callback. | 653 // depend on zone allocations surviving beyond the epilogue callback. |
654 { | 654 { |
655 StackZone stack_zone(Thread::Current()); | 655 Thread* thread = Thread::Current(); |
| 656 StackZone stack_zone(thread); |
656 Zone* zone = stack_zone.GetZone(); | 657 Zone* zone = stack_zone.GetZone(); |
657 MarkingStack marking_stack; | 658 MarkingStack marking_stack; |
658 marked_bytes_ = 0; | 659 marked_bytes_ = 0; |
659 const int num_tasks = FLAG_marker_tasks; | 660 const int num_tasks = FLAG_marker_tasks; |
660 if (num_tasks == 0) { | 661 if (num_tasks == 0) { |
661 // Mark everything on main thread. | 662 // Mark everything on main thread. |
662 SkippedCodeFunctions* skipped_code_functions = | 663 SkippedCodeFunctions* skipped_code_functions = |
663 collect_code ? new(zone) SkippedCodeFunctions() : NULL; | 664 collect_code ? new(zone) SkippedCodeFunctions() : NULL; |
664 UnsyncMarkingVisitor mark(isolate, heap_, page_space, &marking_stack, | 665 UnsyncMarkingVisitor mark(isolate, heap_, page_space, &marking_stack, |
665 skipped_code_functions); | 666 skipped_code_functions); |
666 IterateRoots(isolate, &mark, 0, 1); | 667 IterateRoots(isolate, &mark, 0, 1); |
667 mark.DrainMarkingStack(); | 668 mark.DrainMarkingStack(); |
668 MarkingWeakVisitor mark_weak; | 669 { |
669 IterateWeakRoots(isolate, &mark_weak); | 670 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing"); |
| 671 MarkingWeakVisitor mark_weak; |
| 672 IterateWeakRoots(isolate, &mark_weak); |
| 673 } |
670 // All marking done; detach code, etc. | 674 // All marking done; detach code, etc. |
671 FinalizeResultsFrom(&mark); | 675 FinalizeResultsFrom(&mark); |
672 } else { | 676 } else { |
673 ThreadBarrier barrier(num_tasks + 1, | 677 ThreadBarrier barrier(num_tasks + 1, |
674 heap_->barrier(), | 678 heap_->barrier(), |
675 heap_->barrier_done()); | 679 heap_->barrier_done()); |
676 // Used to coordinate draining among tasks; all start out as 'busy'. | 680 // Used to coordinate draining among tasks; all start out as 'busy'. |
677 uintptr_t num_busy = num_tasks; | 681 uintptr_t num_busy = num_tasks; |
678 // Phase 1: Iterate over roots and drain marking stack in tasks. | 682 // Phase 1: Iterate over roots and drain marking stack in tasks. |
679 for (intptr_t i = 0; i < num_tasks; ++i) { | 683 for (intptr_t i = 0; i < num_tasks; ++i) { |
680 MarkTask* mark_task = | 684 MarkTask* mark_task = |
681 new MarkTask(this, isolate, heap_, page_space, &marking_stack, | 685 new MarkTask(this, isolate, heap_, page_space, &marking_stack, |
682 &barrier, collect_code, | 686 &barrier, collect_code, |
683 i, num_tasks, &num_busy); | 687 i, num_tasks, &num_busy); |
684 ThreadPool* pool = Dart::thread_pool(); | 688 ThreadPool* pool = Dart::thread_pool(); |
685 pool->Run(mark_task); | 689 pool->Run(mark_task); |
686 } | 690 } |
687 barrier.Sync(); | 691 barrier.Sync(); |
688 | 692 |
689 // Phase 2: Weak processing on main thread. | 693 // Phase 2: Weak processing on main thread. |
690 MarkingWeakVisitor mark_weak; | 694 { |
691 IterateWeakRoots(isolate, &mark_weak); | 695 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing"); |
| 696 MarkingWeakVisitor mark_weak; |
| 697 IterateWeakRoots(isolate, &mark_weak); |
| 698 } |
692 barrier.Sync(); | 699 barrier.Sync(); |
693 | 700 |
694 // Phase 3: Finalize results from all markers (detach code, etc.). | 701 // Phase 3: Finalize results from all markers (detach code, etc.). |
695 barrier.Exit(); | 702 barrier.Exit(); |
696 } | 703 } |
697 ProcessWeakTables(page_space); | 704 ProcessWeakTables(page_space); |
698 ProcessObjectIdTable(isolate); | 705 ProcessObjectIdTable(isolate); |
699 } | 706 } |
700 Epilogue(isolate, invoke_api_callbacks); | 707 Epilogue(isolate, invoke_api_callbacks); |
701 } | 708 } |
702 | 709 |
703 } // namespace dart | 710 } // namespace dart |
OLD | NEW |