| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 224 |
| 225 | 225 |
| 226 HeapIterationScope::HeapIterationScope() | 226 HeapIterationScope::HeapIterationScope() |
| 227 : StackResource(Thread::Current()), | 227 : StackResource(Thread::Current()), |
| 228 old_space_(isolate()->heap()->old_space()) { | 228 old_space_(isolate()->heap()->old_space()) { |
| 229 // It's not yet safe to iterate over a paged space while it's concurrently | 229 // It's not yet safe to iterate over a paged space while it's concurrently |
| 230 // sweeping, so wait for any such task to complete first. | 230 // sweeping, so wait for any such task to complete first. |
| 231 MonitorLocker ml(old_space_->tasks_lock()); | 231 MonitorLocker ml(old_space_->tasks_lock()); |
| 232 #if defined(DEBUG) | 232 #if defined(DEBUG) |
| 233 // We currently don't support nesting of HeapIterationScopes. | 233 // We currently don't support nesting of HeapIterationScopes. |
| 234 ASSERT(!old_space_->is_iterating_); | 234 ASSERT(old_space_->iterating_thread_ != thread()); |
| 235 old_space_->is_iterating_ = true; | |
| 236 #endif | 235 #endif |
| 237 while (old_space_->tasks() > 0) { | 236 while (old_space_->tasks() > 0) { |
| 238 ml.Wait(); | 237 ml.Wait(); |
| 239 } | 238 } |
| 239 #if defined(DEBUG) |
| 240 ASSERT(old_space_->iterating_thread_ == NULL); |
| 241 old_space_->iterating_thread_ = thread(); |
| 242 #endif |
| 240 old_space_->set_tasks(1); | 243 old_space_->set_tasks(1); |
| 241 } | 244 } |
| 242 | 245 |
| 243 | 246 |
| 244 HeapIterationScope::~HeapIterationScope() { | 247 HeapIterationScope::~HeapIterationScope() { |
| 245 MonitorLocker ml(old_space_->tasks_lock()); | 248 MonitorLocker ml(old_space_->tasks_lock()); |
| 246 #if defined(DEBUG) | 249 #if defined(DEBUG) |
| 247 ASSERT(old_space_->is_iterating_); | 250 ASSERT(old_space_->iterating_thread_ == thread()); |
| 248 old_space_->is_iterating_ = false; | 251 old_space_->iterating_thread_ = NULL; |
| 249 #endif | 252 #endif |
| 250 ASSERT(old_space_->tasks() == 1); | 253 ASSERT(old_space_->tasks() == 1); |
| 251 old_space_->set_tasks(0); | 254 old_space_->set_tasks(0); |
| 252 ml.Notify(); | 255 ml.Notify(); |
| 253 } | 256 } |
| 254 | 257 |
| 255 | 258 |
| 256 void Heap::IterateObjects(ObjectVisitor* visitor) const { | 259 void Heap::IterateObjects(ObjectVisitor* visitor) const { |
| 257 // The visitor must not allocate from the heap. | 260 // The visitor must not allocate from the heap. |
| 258 NoSafepointScope no_safepoint_scope_; | 261 NoSafepointScope no_safepoint_scope_; |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 heap->DisableGrowthControl(); | 790 heap->DisableGrowthControl(); |
| 788 } | 791 } |
| 789 | 792 |
| 790 | 793 |
| 791 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 794 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
| 792 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 795 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 793 heap->SetGrowthControlState(current_growth_controller_state_); | 796 heap->SetGrowthControlState(current_growth_controller_state_); |
| 794 } | 797 } |
| 795 | 798 |
| 796 } // namespace dart | 799 } // namespace dart |
| OLD | NEW |