| 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/compiler_stats.h" | 9 #include "vm/compiler_stats.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| 11 #include "vm/heap_profiler.h" |
| 11 #include "vm/isolate.h" | 12 #include "vm/isolate.h" |
| 12 #include "vm/object.h" | 13 #include "vm/object.h" |
| 13 #include "vm/os.h" | 14 #include "vm/os.h" |
| 14 #include "vm/pages.h" | 15 #include "vm/pages.h" |
| 15 #include "vm/scavenger.h" | 16 #include "vm/scavenger.h" |
| 17 #include "vm/stack_frame.h" |
| 16 #include "vm/verifier.h" | 18 #include "vm/verifier.h" |
| 17 #include "vm/virtual_memory.h" | 19 #include "vm/virtual_memory.h" |
| 18 | 20 |
| 19 namespace dart { | 21 namespace dart { |
| 20 | 22 |
| 21 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); | 23 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); |
| 22 DEFINE_FLAG(bool, verify_before_gc, false, | 24 DEFINE_FLAG(bool, verify_before_gc, false, |
| 23 "Enables heap verification before GC."); | 25 "Enables heap verification before GC."); |
| 24 DEFINE_FLAG(bool, verify_after_gc, false, | 26 DEFINE_FLAG(bool, verify_after_gc, false, |
| 25 "Enables heap verification after GC."); | 27 "Enables heap verification after GC."); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 void Heap::PrintSizes() const { | 208 void Heap::PrintSizes() const { |
| 207 OS::PrintErr("New space (%dk of %dk) " | 209 OS::PrintErr("New space (%dk of %dk) " |
| 208 "Old space (%dk of %dk) " | 210 "Old space (%dk of %dk) " |
| 209 "Code space (%dk of %dk)\n", | 211 "Code space (%dk of %dk)\n", |
| 210 (new_space_->in_use() / KB), (new_space_->capacity() / KB), | 212 (new_space_->in_use() / KB), (new_space_->capacity() / KB), |
| 211 (old_space_->in_use() / KB), (old_space_->capacity() / KB), | 213 (old_space_->in_use() / KB), (old_space_->capacity() / KB), |
| 212 (code_space_->in_use() / KB), (code_space_->capacity() / KB)); | 214 (code_space_->in_use() / KB), (code_space_->capacity() / KB)); |
| 213 } | 215 } |
| 214 | 216 |
| 215 | 217 |
| 218 void Heap::Profile(Dart_HeapProfileWriteCallback callback, void* stream) const { |
| 219 HeapProfiler profiler(callback, stream); |
| 220 |
| 221 // Dump the root set. |
| 222 HeapProfilerRootVisitor root_visitor(&profiler); |
| 223 Isolate* isolate = Isolate::Current(); |
| 224 Isolate* vm_isolate = Dart::vm_isolate(); |
| 225 isolate->VisitObjectPointers(&root_visitor, false, |
| 226 StackFrameIterator::kDontValidateFrames); |
| 227 HeapProfilerWeakRootVisitor weak_root_visitor(&root_visitor); |
| 228 isolate->VisitWeakPersistentHandles(&weak_root_visitor, true); |
| 229 |
| 230 // Dump the current and VM isolate heaps. |
| 231 HeapProfilerObjectVisitor object_visitor(&profiler); |
| 232 isolate->heap()->new_space_->VisitObjects(&object_visitor); |
| 233 isolate->heap()->old_space_->VisitObjects(&object_visitor); |
| 234 isolate->heap()->code_space_->VisitObjects(&object_visitor); |
| 235 vm_isolate->heap()->new_space_->VisitObjects(&object_visitor); |
| 236 vm_isolate->heap()->old_space_->VisitObjects(&object_visitor); |
| 237 } |
| 238 |
| 239 |
| 216 #if defined(DEBUG) | 240 #if defined(DEBUG) |
| 217 NoGCScope::NoGCScope() : StackResource(Isolate::Current()) { | 241 NoGCScope::NoGCScope() : StackResource(Isolate::Current()) { |
| 218 isolate()->IncrementNoGCScopeDepth(); | 242 isolate()->IncrementNoGCScopeDepth(); |
| 219 } | 243 } |
| 220 | 244 |
| 221 | 245 |
| 222 NoGCScope::~NoGCScope() { | 246 NoGCScope::~NoGCScope() { |
| 223 isolate()->DecrementNoGCScopeDepth(); | 247 isolate()->DecrementNoGCScopeDepth(); |
| 224 } | 248 } |
| 225 #endif // defined(DEBUG) | 249 #endif // defined(DEBUG) |
| 226 | 250 |
| 227 } // namespace dart | 251 } // namespace dart |
| OLD | NEW |