| 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 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 if (num_tasks == 0) { | 701 if (num_tasks == 0) { |
| 702 // Mark everything on main thread. | 702 // Mark everything on main thread. |
| 703 SkippedCodeFunctions* skipped_code_functions = | 703 SkippedCodeFunctions* skipped_code_functions = |
| 704 collect_code ? new(zone) SkippedCodeFunctions() : NULL; | 704 collect_code ? new(zone) SkippedCodeFunctions() : NULL; |
| 705 UnsyncMarkingVisitor mark(isolate, heap_, page_space, &marking_stack, | 705 UnsyncMarkingVisitor mark(isolate, heap_, page_space, &marking_stack, |
| 706 skipped_code_functions); | 706 skipped_code_functions); |
| 707 IterateRoots(isolate, &mark, 0, 1); | 707 IterateRoots(isolate, &mark, 0, 1); |
| 708 mark.DrainMarkingStack(); | 708 mark.DrainMarkingStack(); |
| 709 { | 709 { |
| 710 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing"); | 710 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing"); |
| 711 FinalizationQueue* queue = new FinalizationQueue(); | 711 if (FLAG_background_finalization) { |
| 712 MarkingWeakVisitor mark_weak(thread, queue); | 712 FinalizationQueue* queue = new FinalizationQueue(); |
| 713 IterateWeakRoots(isolate, &mark_weak); | 713 MarkingWeakVisitor mark_weak(thread, queue); |
| 714 if (queue->length() > 0) { | 714 IterateWeakRoots(isolate, &mark_weak); |
| 715 Dart::thread_pool()->Run(new BackgroundFinalizer(isolate, queue)); | 715 if (queue->length() > 0) { |
| 716 Dart::thread_pool()->Run(new BackgroundFinalizer(isolate, queue)); |
| 717 } else { |
| 718 delete queue; |
| 719 } |
| 716 } else { | 720 } else { |
| 717 delete queue; | 721 MarkingWeakVisitor mark_weak(thread, NULL); |
| 722 IterateWeakRoots(isolate, &mark_weak); |
| 718 } | 723 } |
| 719 } | 724 } |
| 720 // All marking done; detach code, etc. | 725 // All marking done; detach code, etc. |
| 721 FinalizeResultsFrom(&mark); | 726 FinalizeResultsFrom(&mark); |
| 722 } else { | 727 } else { |
| 723 ThreadBarrier barrier(num_tasks + 1, | 728 ThreadBarrier barrier(num_tasks + 1, |
| 724 heap_->barrier(), | 729 heap_->barrier(), |
| 725 heap_->barrier_done()); | 730 heap_->barrier_done()); |
| 726 // Used to coordinate draining among tasks; all start out as 'busy'. | 731 // Used to coordinate draining among tasks; all start out as 'busy'. |
| 727 uintptr_t num_busy = num_tasks; | 732 uintptr_t num_busy = num_tasks; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 744 // Note: we need to have two barriers here because we want all markers | 749 // Note: we need to have two barriers here because we want all markers |
| 745 // and main thread to make decisions in lock step. | 750 // and main thread to make decisions in lock step. |
| 746 barrier.Sync(); | 751 barrier.Sync(); |
| 747 more_to_mark = AtomicOperations::LoadRelaxed(&num_busy) > 0; | 752 more_to_mark = AtomicOperations::LoadRelaxed(&num_busy) > 0; |
| 748 barrier.Sync(); | 753 barrier.Sync(); |
| 749 } while (more_to_mark); | 754 } while (more_to_mark); |
| 750 | 755 |
| 751 // Phase 2: Weak processing on main thread. | 756 // Phase 2: Weak processing on main thread. |
| 752 { | 757 { |
| 753 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing"); | 758 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing"); |
| 754 FinalizationQueue* queue = new FinalizationQueue(); | 759 if (FLAG_background_finalization) { |
| 755 MarkingWeakVisitor mark_weak(thread, queue); | 760 FinalizationQueue* queue = new FinalizationQueue(); |
| 756 IterateWeakRoots(isolate, &mark_weak); | 761 MarkingWeakVisitor mark_weak(thread, queue); |
| 757 if (queue->length() > 0) { | 762 IterateWeakRoots(isolate, &mark_weak); |
| 758 Dart::thread_pool()->Run(new BackgroundFinalizer(isolate, queue)); | 763 if (queue->length() > 0) { |
| 764 Dart::thread_pool()->Run(new BackgroundFinalizer(isolate, queue)); |
| 765 } else { |
| 766 delete queue; |
| 767 } |
| 759 } else { | 768 } else { |
| 760 delete queue; | 769 MarkingWeakVisitor mark_weak(thread, NULL); |
| 770 IterateWeakRoots(isolate, &mark_weak); |
| 761 } | 771 } |
| 762 } | 772 } |
| 763 barrier.Sync(); | 773 barrier.Sync(); |
| 764 | 774 |
| 765 // Phase 3: Finalize results from all markers (detach code, etc.). | 775 // Phase 3: Finalize results from all markers (detach code, etc.). |
| 766 barrier.Exit(); | 776 barrier.Exit(); |
| 767 } | 777 } |
| 768 ProcessWeakTables(page_space); | 778 ProcessWeakTables(page_space); |
| 769 ProcessObjectIdTable(isolate); | 779 ProcessObjectIdTable(isolate); |
| 770 } | 780 } |
| 771 Epilogue(isolate, invoke_api_callbacks); | 781 Epilogue(isolate, invoke_api_callbacks); |
| 772 } | 782 } |
| 773 | 783 |
| 774 } // namespace dart | 784 } // namespace dart |
| OLD | NEW |