OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/heap.h" | 5 #include "vm/heap.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 return old_space_.Contains(addr, HeapPage::kExecutable); | 193 return old_space_.Contains(addr, HeapPage::kExecutable); |
194 } | 194 } |
195 | 195 |
196 | 196 |
197 void Heap::VisitObjects(ObjectVisitor* visitor) const { | 197 void Heap::VisitObjects(ObjectVisitor* visitor) const { |
198 new_space_.VisitObjects(visitor); | 198 new_space_.VisitObjects(visitor); |
199 old_space_.VisitObjects(visitor); | 199 old_space_.VisitObjects(visitor); |
200 } | 200 } |
201 | 201 |
202 | 202 |
203 HeapIterationScope::HeapIterationScope() | 203 HeapIterationScope::HeapIterationScope(bool writable) |
204 : StackResource(Thread::Current()), | 204 : StackResource(Thread::Current()), |
205 old_space_(isolate()->heap()->old_space()) { | 205 old_space_(isolate()->heap()->old_space()), |
206 // It's not yet safe to iterate over a paged space while it's concurrently | 206 writable_(writable) { |
207 // sweeping, so wait for any such task to complete first. | 207 { |
208 MonitorLocker ml(old_space_->tasks_lock()); | 208 // It's not yet safe to iterate over a paged space while it's concurrently |
| 209 // sweeping, so wait for any such task to complete first. |
| 210 MonitorLocker ml(old_space_->tasks_lock()); |
209 #if defined(DEBUG) | 211 #if defined(DEBUG) |
210 // We currently don't support nesting of HeapIterationScopes. | 212 // We currently don't support nesting of HeapIterationScopes. |
211 ASSERT(old_space_->iterating_thread_ != thread()); | 213 ASSERT(old_space_->iterating_thread_ != thread()); |
212 #endif | 214 #endif |
213 while (old_space_->tasks() > 0) { | 215 while (old_space_->tasks() > 0) { |
214 ml.WaitWithSafepointCheck(thread()); | 216 ml.WaitWithSafepointCheck(thread()); |
| 217 } |
| 218 #if defined(DEBUG) |
| 219 ASSERT(old_space_->iterating_thread_ == NULL); |
| 220 old_space_->iterating_thread_ = thread(); |
| 221 #endif |
| 222 old_space_->set_tasks(1); |
215 } | 223 } |
216 #if defined(DEBUG) | 224 |
217 ASSERT(old_space_->iterating_thread_ == NULL); | 225 if (writable_) { |
218 old_space_->iterating_thread_ = thread(); | 226 thread()->heap()->WriteProtectCode(false); |
219 #endif | 227 } |
220 old_space_->set_tasks(1); | |
221 } | 228 } |
222 | 229 |
223 | 230 |
224 HeapIterationScope::~HeapIterationScope() { | 231 HeapIterationScope::~HeapIterationScope() { |
| 232 if (writable_) { |
| 233 thread()->heap()->WriteProtectCode(true); |
| 234 } |
| 235 |
225 MonitorLocker ml(old_space_->tasks_lock()); | 236 MonitorLocker ml(old_space_->tasks_lock()); |
226 #if defined(DEBUG) | 237 #if defined(DEBUG) |
227 ASSERT(old_space_->iterating_thread_ == thread()); | 238 ASSERT(old_space_->iterating_thread_ == thread()); |
228 old_space_->iterating_thread_ = NULL; | 239 old_space_->iterating_thread_ = NULL; |
229 #endif | 240 #endif |
230 ASSERT(old_space_->tasks() == 1); | 241 ASSERT(old_space_->tasks() == 1); |
231 old_space_->set_tasks(0); | 242 old_space_->set_tasks(0); |
232 ml.NotifyAll(); | 243 ml.NotifyAll(); |
233 } | 244 } |
234 | 245 |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 Dart::vm_isolate()->heap()->WriteProtect(false); | 843 Dart::vm_isolate()->heap()->WriteProtect(false); |
833 } | 844 } |
834 | 845 |
835 | 846 |
836 WritableVMIsolateScope::~WritableVMIsolateScope() { | 847 WritableVMIsolateScope::~WritableVMIsolateScope() { |
837 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); | 848 ASSERT(Dart::vm_isolate()->heap()->UsedInWords(Heap::kNew) == 0); |
838 Dart::vm_isolate()->heap()->WriteProtect(true); | 849 Dart::vm_isolate()->heap()->WriteProtect(true); |
839 } | 850 } |
840 | 851 |
841 } // namespace dart | 852 } // namespace dart |
OLD | NEW |