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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 } | 415 } |
416 if (!raw_obj->IsOldObject()) { | 416 if (!raw_obj->IsOldObject()) { |
417 return false; | 417 return false; |
418 } | 418 } |
419 return !raw_obj->IsMarked(); | 419 return !raw_obj->IsMarked(); |
420 } | 420 } |
421 | 421 |
422 | 422 |
423 class MarkingWeakVisitor : public HandleVisitor { | 423 class MarkingWeakVisitor : public HandleVisitor { |
424 public: | 424 public: |
425 MarkingWeakVisitor(Thread* thread, FinalizationQueue* queue) : | 425 MarkingWeakVisitor() : HandleVisitor(Thread::Current()) { |
426 HandleVisitor(thread), queue_(queue) { } | 426 } |
427 | 427 |
428 void VisitHandle(uword addr) { | 428 void VisitHandle(uword addr) { |
429 FinalizablePersistentHandle* handle = | 429 FinalizablePersistentHandle* handle = |
430 reinterpret_cast<FinalizablePersistentHandle*>(addr); | 430 reinterpret_cast<FinalizablePersistentHandle*>(addr); |
431 RawObject* raw_obj = handle->raw(); | 431 RawObject* raw_obj = handle->raw(); |
432 if (IsUnreachable(raw_obj)) { | 432 if (IsUnreachable(raw_obj)) { |
433 handle->UpdateUnreachable(thread()->isolate(), queue_); | 433 handle->UpdateUnreachable(thread()->isolate()); |
434 } | 434 } |
435 } | 435 } |
436 | 436 |
437 private: | 437 private: |
438 FinalizationQueue* queue_; | |
439 | |
440 DISALLOW_COPY_AND_ASSIGN(MarkingWeakVisitor); | 438 DISALLOW_COPY_AND_ASSIGN(MarkingWeakVisitor); |
441 }; | 439 }; |
442 | 440 |
443 | 441 |
444 void GCMarker::Prologue(Isolate* isolate, bool invoke_api_callbacks) { | 442 void GCMarker::Prologue(Isolate* isolate, bool invoke_api_callbacks) { |
445 if (invoke_api_callbacks && (isolate->gc_prologue_callback() != NULL)) { | 443 if (invoke_api_callbacks && (isolate->gc_prologue_callback() != NULL)) { |
446 (isolate->gc_prologue_callback())(); | 444 (isolate->gc_prologue_callback())(); |
447 } | 445 } |
448 isolate->PrepareForGC(); | 446 isolate->PrepareForGC(); |
449 // The store buffers will be rebuilt as part of marking, reset them now. | 447 // The store buffers will be rebuilt as part of marking, reset them now. |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 if (num_tasks == 0) { | 661 if (num_tasks == 0) { |
664 // Mark everything on main thread. | 662 // Mark everything on main thread. |
665 SkippedCodeFunctions* skipped_code_functions = | 663 SkippedCodeFunctions* skipped_code_functions = |
666 collect_code ? new(zone) SkippedCodeFunctions() : NULL; | 664 collect_code ? new(zone) SkippedCodeFunctions() : NULL; |
667 UnsyncMarkingVisitor mark(isolate, heap_, page_space, &marking_stack, | 665 UnsyncMarkingVisitor mark(isolate, heap_, page_space, &marking_stack, |
668 skipped_code_functions); | 666 skipped_code_functions); |
669 IterateRoots(isolate, &mark, 0, 1); | 667 IterateRoots(isolate, &mark, 0, 1); |
670 mark.DrainMarkingStack(); | 668 mark.DrainMarkingStack(); |
671 { | 669 { |
672 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing"); | 670 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing"); |
673 FinalizationQueue* queue = new FinalizationQueue(); | 671 MarkingWeakVisitor mark_weak; |
674 MarkingWeakVisitor mark_weak(thread, queue); | |
675 IterateWeakRoots(isolate, &mark_weak); | 672 IterateWeakRoots(isolate, &mark_weak); |
676 if (queue->length() > 0) { | |
677 Dart::thread_pool()->Run(new BackgroundFinalizer(isolate, queue)); | |
678 } else { | |
679 delete queue; | |
680 } | |
681 } | 673 } |
682 // All marking done; detach code, etc. | 674 // All marking done; detach code, etc. |
683 FinalizeResultsFrom(&mark); | 675 FinalizeResultsFrom(&mark); |
684 } else { | 676 } else { |
685 ThreadBarrier barrier(num_tasks + 1, | 677 ThreadBarrier barrier(num_tasks + 1, |
686 heap_->barrier(), | 678 heap_->barrier(), |
687 heap_->barrier_done()); | 679 heap_->barrier_done()); |
688 // Used to coordinate draining among tasks; all start out as 'busy'. | 680 // Used to coordinate draining among tasks; all start out as 'busy'. |
689 uintptr_t num_busy = num_tasks; | 681 uintptr_t num_busy = num_tasks; |
690 // Phase 1: Iterate over roots and drain marking stack in tasks. | 682 // Phase 1: Iterate over roots and drain marking stack in tasks. |
691 for (intptr_t i = 0; i < num_tasks; ++i) { | 683 for (intptr_t i = 0; i < num_tasks; ++i) { |
692 MarkTask* mark_task = | 684 MarkTask* mark_task = |
693 new MarkTask(this, isolate, heap_, page_space, &marking_stack, | 685 new MarkTask(this, isolate, heap_, page_space, &marking_stack, |
694 &barrier, collect_code, | 686 &barrier, collect_code, |
695 i, num_tasks, &num_busy); | 687 i, num_tasks, &num_busy); |
696 ThreadPool* pool = Dart::thread_pool(); | 688 ThreadPool* pool = Dart::thread_pool(); |
697 pool->Run(mark_task); | 689 pool->Run(mark_task); |
698 } | 690 } |
699 barrier.Sync(); | 691 barrier.Sync(); |
700 | 692 |
701 // Phase 2: Weak processing on main thread. | 693 // Phase 2: Weak processing on main thread. |
702 { | 694 { |
703 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing"); | 695 TIMELINE_FUNCTION_GC_DURATION(thread, "WeakHandleProcessing"); |
704 FinalizationQueue* queue = new FinalizationQueue(); | 696 MarkingWeakVisitor mark_weak; |
705 MarkingWeakVisitor mark_weak(thread, queue); | |
706 IterateWeakRoots(isolate, &mark_weak); | 697 IterateWeakRoots(isolate, &mark_weak); |
707 if (queue->length() > 0) { | |
708 Dart::thread_pool()->Run(new BackgroundFinalizer(isolate, queue)); | |
709 } else { | |
710 delete queue; | |
711 } | |
712 } | 698 } |
713 barrier.Sync(); | 699 barrier.Sync(); |
714 | 700 |
715 // Phase 3: Finalize results from all markers (detach code, etc.). | 701 // Phase 3: Finalize results from all markers (detach code, etc.). |
716 barrier.Exit(); | 702 barrier.Exit(); |
717 } | 703 } |
718 ProcessWeakTables(page_space); | 704 ProcessWeakTables(page_space); |
719 ProcessObjectIdTable(isolate); | 705 ProcessObjectIdTable(isolate); |
720 } | 706 } |
721 Epilogue(isolate, invoke_api_callbacks); | 707 Epilogue(isolate, invoke_api_callbacks); |
722 } | 708 } |
723 | 709 |
724 } // namespace dart | 710 } // namespace dart |
OLD | NEW |