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" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 return words_to_end; | 89 return words_to_end; |
90 } | 90 } |
91 | 91 |
92 | 92 |
93 class SweeperTask : public ThreadPool::Task { | 93 class SweeperTask : public ThreadPool::Task { |
94 public: | 94 public: |
95 SweeperTask(Isolate* isolate, | 95 SweeperTask(Isolate* isolate, |
96 PageSpace* old_space, | 96 PageSpace* old_space, |
97 HeapPage* first, | 97 HeapPage* first, |
98 HeapPage* last, | 98 HeapPage* last, |
99 FreeList* freelist) | 99 FreeList* freelist, |
100 Monitor* started_monitor, | |
101 bool* started_flag, | |
102 SafepointId pass_safepoint) | |
100 : task_isolate_(isolate), | 103 : task_isolate_(isolate), |
101 old_space_(old_space), | 104 old_space_(old_space), |
102 first_(first), | 105 first_(first), |
103 last_(last), | 106 last_(last), |
104 freelist_(freelist) { | 107 freelist_(freelist), |
108 started_monitor_(started_monitor), | |
109 started_flag_(started_flag), | |
110 pass_safepoint_(pass_safepoint) { | |
105 ASSERT(task_isolate_ != NULL); | 111 ASSERT(task_isolate_ != NULL); |
106 ASSERT(first_ != NULL); | 112 ASSERT(first_ != NULL); |
107 ASSERT(old_space_ != NULL); | 113 ASSERT(old_space_ != NULL); |
108 ASSERT(last_ != NULL); | 114 ASSERT(last_ != NULL); |
109 ASSERT(freelist_ != NULL); | 115 ASSERT(freelist_ != NULL); |
110 MonitorLocker ml(old_space_->tasks_lock()); | 116 MonitorLocker ml(old_space_->tasks_lock()); |
111 old_space_->set_tasks(old_space_->tasks() + 1); | 117 old_space_->set_tasks(old_space_->tasks() + 1); |
112 ml.Notify(); | 118 ml.Notify(); |
113 } | 119 } |
114 | 120 |
115 virtual void Run() { | 121 virtual void Run() { |
116 Thread::EnterIsolateAsHelper(task_isolate_); | 122 Thread::EnterIsolateAsHelper(task_isolate_, pass_safepoint_); |
123 { | |
124 MonitorLocker ml(started_monitor_); | |
125 ASSERT(!*started_flag_); | |
126 *started_flag_ = true; | |
127 ml.Notify(); | |
128 } | |
117 GCSweeper sweeper; | 129 GCSweeper sweeper; |
118 | 130 |
119 HeapPage* page = first_; | 131 HeapPage* page = first_; |
120 HeapPage* prev_page = NULL; | 132 HeapPage* prev_page = NULL; |
121 | 133 |
122 while (page != NULL) { | 134 while (page != NULL) { |
123 HeapPage* next_page = page->next(); | 135 HeapPage* next_page = page->next(); |
124 ASSERT(page->type() == HeapPage::kData); | 136 ASSERT(page->type() == HeapPage::kData); |
125 bool page_in_use = sweeper.SweepPage(page, freelist_, false); | 137 bool page_in_use = sweeper.SweepPage(page, freelist_, false); |
126 if (page_in_use) { | 138 if (page_in_use) { |
(...skipping 19 matching lines...) Expand all Loading... | |
146 ml.Notify(); | 158 ml.Notify(); |
147 } | 159 } |
148 } | 160 } |
149 | 161 |
150 private: | 162 private: |
151 Isolate* task_isolate_; | 163 Isolate* task_isolate_; |
152 PageSpace* old_space_; | 164 PageSpace* old_space_; |
153 HeapPage* first_; | 165 HeapPage* first_; |
154 HeapPage* last_; | 166 HeapPage* last_; |
155 FreeList* freelist_; | 167 FreeList* freelist_; |
168 Monitor* started_monitor_; | |
169 bool* started_flag_; | |
170 SafepointId pass_safepoint_; | |
156 }; | 171 }; |
157 | 172 |
158 | 173 |
159 void GCSweeper::SweepConcurrent(Isolate* isolate, | 174 void GCSweeper::SweepConcurrent(Isolate* isolate, |
160 HeapPage* first, | 175 HeapPage* first, |
161 HeapPage* last, | 176 HeapPage* last, |
162 FreeList* freelist) { | 177 FreeList* freelist, |
178 SafepointId pass_safepoint) { | |
179 Monitor started_monitor; | |
180 bool started_flag = false; | |
163 SweeperTask* task = | 181 SweeperTask* task = |
164 new SweeperTask(isolate, | 182 new SweeperTask(isolate, |
165 isolate->heap()->old_space(), | 183 isolate->heap()->old_space(), |
166 first, last, | 184 first, last, |
167 freelist); | 185 freelist, |
186 &started_monitor, | |
187 &started_flag, | |
188 pass_safepoint); | |
168 ThreadPool* pool = Dart::thread_pool(); | 189 ThreadPool* pool = Dart::thread_pool(); |
169 pool->Run(task); | 190 pool->Run(task); |
191 { | |
192 MonitorLocker ml(&started_monitor); | |
Ivan Posva
2015/08/19 08:00:04
I don't expect it to be needed to wait for the swe
| |
193 while (!started_flag) { | |
194 ml.Wait(); | |
195 } | |
196 } | |
170 } | 197 } |
171 | 198 |
172 } // namespace dart | 199 } // namespace dart |
OLD | NEW |