| 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_sweeper.h" | 5 #include "vm/gc_sweeper.h" |
| 6 | 6 |
| 7 #include "vm/freelist.h" | 7 #include "vm/freelist.h" |
| 8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
| 9 #include "vm/heap.h" | 9 #include "vm/heap.h" |
| 10 #include "vm/lockers.h" | 10 #include "vm/lockers.h" |
| 11 #include "vm/pages.h" | 11 #include "vm/pages.h" |
| 12 #include "vm/safepoint.h" |
| 12 #include "vm/thread_pool.h" | 13 #include "vm/thread_pool.h" |
| 13 #include "vm/thread_registry.h" | |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 bool GCSweeper::SweepPage(HeapPage* page, FreeList* freelist, bool locked) { | 17 bool GCSweeper::SweepPage(HeapPage* page, FreeList* freelist, bool locked) { |
| 18 // Keep track whether this page is still in use. | 18 // Keep track whether this page is still in use. |
| 19 bool in_use = false; | 19 bool in_use = false; |
| 20 | 20 |
| 21 bool is_executable = (page->type() == HeapPage::kExecutable); | 21 bool is_executable = (page->type() == HeapPage::kExecutable); |
| 22 uword start = page->object_start(); | 22 uword start = page->object_start(); |
| 23 uword end = page->object_end(); | 23 uword end = page->object_end(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 ASSERT(last_ != NULL); | 109 ASSERT(last_ != NULL); |
| 110 ASSERT(freelist_ != NULL); | 110 ASSERT(freelist_ != NULL); |
| 111 MonitorLocker ml(old_space_->tasks_lock()); | 111 MonitorLocker ml(old_space_->tasks_lock()); |
| 112 old_space_->set_tasks(old_space_->tasks() + 1); | 112 old_space_->set_tasks(old_space_->tasks() + 1); |
| 113 ml.Notify(); | 113 ml.Notify(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 virtual void Run() { | 116 virtual void Run() { |
| 117 bool result = Thread::EnterIsolateAsHelper(task_isolate_); | 117 bool result = Thread::EnterIsolateAsHelper(task_isolate_); |
| 118 ASSERT(result); | 118 ASSERT(result); |
| 119 Thread* thread = Thread::Current(); |
| 119 GCSweeper sweeper; | 120 GCSweeper sweeper; |
| 120 | 121 |
| 121 HeapPage* page = first_; | 122 HeapPage* page = first_; |
| 122 HeapPage* prev_page = NULL; | 123 HeapPage* prev_page = NULL; |
| 123 | 124 |
| 124 while (page != NULL) { | 125 while (page != NULL) { |
| 125 task_isolate_->thread_registry()->CheckSafepoint(); | 126 thread->CheckForSafepoint(); |
| 126 HeapPage* next_page = page->next(); | 127 HeapPage* next_page = page->next(); |
| 127 ASSERT(page->type() == HeapPage::kData); | 128 ASSERT(page->type() == HeapPage::kData); |
| 128 bool page_in_use = sweeper.SweepPage(page, freelist_, false); | 129 bool page_in_use = sweeper.SweepPage(page, freelist_, false); |
| 129 if (page_in_use) { | 130 if (page_in_use) { |
| 130 prev_page = page; | 131 prev_page = page; |
| 131 } else { | 132 } else { |
| 132 old_space_->FreePage(page, prev_page); | 133 old_space_->FreePage(page, prev_page); |
| 133 } | 134 } |
| 134 { | 135 { |
| 135 // Notify the mutator thread that we have added elements to the free | 136 // Notify the mutator thread that we have added elements to the free |
| (...skipping 30 matching lines...) Expand all Loading... |
| 166 SweeperTask* task = | 167 SweeperTask* task = |
| 167 new SweeperTask(isolate, | 168 new SweeperTask(isolate, |
| 168 isolate->heap()->old_space(), | 169 isolate->heap()->old_space(), |
| 169 first, last, | 170 first, last, |
| 170 freelist); | 171 freelist); |
| 171 ThreadPool* pool = Dart::thread_pool(); | 172 ThreadPool* pool = Dart::thread_pool(); |
| 172 pool->Run(task); | 173 pool->Run(task); |
| 173 } | 174 } |
| 174 | 175 |
| 175 } // namespace dart | 176 } // namespace dart |
| OLD | NEW |