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/heap_profiler.h" |
12 #include "vm/isolate.h" | 12 #include "vm/isolate.h" |
13 #include "vm/object.h" | 13 #include "vm/object.h" |
| 14 #include "vm/object_set.h" |
14 #include "vm/os.h" | 15 #include "vm/os.h" |
15 #include "vm/pages.h" | 16 #include "vm/pages.h" |
16 #include "vm/scavenger.h" | 17 #include "vm/scavenger.h" |
17 #include "vm/stack_frame.h" | 18 #include "vm/stack_frame.h" |
18 #include "vm/verifier.h" | 19 #include "vm/verifier.h" |
19 #include "vm/virtual_memory.h" | 20 #include "vm/virtual_memory.h" |
20 | 21 |
21 namespace dart { | 22 namespace dart { |
22 | 23 |
23 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); | 24 DEFINE_FLAG(bool, verbose_gc, false, "Enables verbose GC."); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 old_space_->Contains(addr) || | 108 old_space_->Contains(addr) || |
108 code_space_->Contains(addr); | 109 code_space_->Contains(addr); |
109 } | 110 } |
110 | 111 |
111 | 112 |
112 bool Heap::CodeContains(uword addr) const { | 113 bool Heap::CodeContains(uword addr) const { |
113 return code_space_->Contains(addr); | 114 return code_space_->Contains(addr); |
114 } | 115 } |
115 | 116 |
116 | 117 |
| 118 void Heap::IterateObjects(ObjectVisitor* visitor) { |
| 119 new_space_->VisitObjects(visitor); |
| 120 old_space_->VisitObjects(visitor); |
| 121 code_space_->VisitObjects(visitor); |
| 122 } |
| 123 |
| 124 |
| 125 void Heap::IteratePointers(ObjectPointerVisitor* visitor) { |
| 126 new_space_->VisitObjectPointers(visitor); |
| 127 old_space_->VisitObjectPointers(visitor); |
| 128 code_space_->VisitObjectPointers(visitor); |
| 129 } |
| 130 |
| 131 |
117 void Heap::IterateNewPointers(ObjectPointerVisitor* visitor) { | 132 void Heap::IterateNewPointers(ObjectPointerVisitor* visitor) { |
118 new_space_->VisitObjectPointers(visitor); | 133 new_space_->VisitObjectPointers(visitor); |
119 } | 134 } |
120 | 135 |
121 | 136 |
122 void Heap::IterateOldPointers(ObjectPointerVisitor* visitor) { | 137 void Heap::IterateOldPointers(ObjectPointerVisitor* visitor) { |
123 old_space_->VisitObjectPointers(visitor); | 138 old_space_->VisitObjectPointers(visitor); |
124 code_space_->VisitObjectPointers(visitor); | 139 code_space_->VisitObjectPointers(visitor); |
125 } | 140 } |
126 | 141 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 226 } |
212 | 227 |
213 | 228 |
214 void Heap::Init(Isolate* isolate) { | 229 void Heap::Init(Isolate* isolate) { |
215 ASSERT(isolate->heap() == NULL); | 230 ASSERT(isolate->heap() == NULL); |
216 Heap* heap = new Heap(); | 231 Heap* heap = new Heap(); |
217 isolate->set_heap(heap); | 232 isolate->set_heap(heap); |
218 } | 233 } |
219 | 234 |
220 | 235 |
| 236 void Heap::StartEndAddress(uword* start, uword* end) const { |
| 237 ASSERT(new_space_->capacity() != 0); |
| 238 new_space_->StartEndAddress(start, end); |
| 239 if (old_space_->capacity() != 0) { |
| 240 uword old_start; |
| 241 uword old_end; |
| 242 old_space_->StartEndAddress(&old_start, &old_end); |
| 243 *start = Utils::Minimum(old_start, *start); |
| 244 *end = Utils::Maximum(old_end, *end); |
| 245 } |
| 246 if (code_space_->capacity() != 0) { |
| 247 uword code_start; |
| 248 uword code_end; |
| 249 code_space_->StartEndAddress(&code_start, &code_end); |
| 250 *start = Utils::Minimum(code_start, *start); |
| 251 *end = Utils::Maximum(code_end, *end); |
| 252 } |
| 253 ASSERT(*start <= *end); |
| 254 } |
| 255 |
| 256 |
| 257 ObjectSet* Heap::CreateAllocatedObjectSet() const { |
| 258 Isolate* isolate = Isolate::Current(); |
| 259 uword start, end; |
| 260 isolate->heap()->StartEndAddress(&start, &end); |
| 261 |
| 262 Isolate* vm_isolate = Dart::vm_isolate(); |
| 263 uword vm_start, vm_end; |
| 264 vm_isolate->heap()->StartEndAddress(&vm_start, &vm_end); |
| 265 |
| 266 ObjectSet* allocated_set = new ObjectSet(Utils::Minimum(start, vm_start), |
| 267 Utils::Maximum(end, vm_end)); |
| 268 |
| 269 VerifyObjectVisitor object_visitor(isolate, allocated_set); |
| 270 isolate->heap()->IterateObjects(&object_visitor); |
| 271 vm_isolate->heap()->IterateObjects(&object_visitor); |
| 272 |
| 273 return allocated_set; |
| 274 } |
| 275 |
| 276 |
221 bool Heap::Verify() const { | 277 bool Heap::Verify() const { |
222 VerifyPointersVisitor visitor(Isolate::Current()); | 278 Isolate* isolate = Isolate::Current(); |
223 new_space_->VisitObjectPointers(&visitor); | 279 ObjectSet* allocated_set = isolate->heap()->CreateAllocatedObjectSet(); |
224 old_space_->VisitObjectPointers(&visitor); | 280 VerifyPointersVisitor visitor(isolate, allocated_set); |
225 code_space_->VisitObjectPointers(&visitor); | 281 isolate->heap()->IteratePointers(&visitor); |
| 282 delete allocated_set; |
226 // Only returning a value so that Heap::Validate can be called from an ASSERT. | 283 // Only returning a value so that Heap::Validate can be called from an ASSERT. |
227 return true; | 284 return true; |
228 } | 285 } |
229 | 286 |
230 | 287 |
231 void Heap::PrintSizes() const { | 288 void Heap::PrintSizes() const { |
232 OS::PrintErr("New space (%dk of %dk) " | 289 OS::PrintErr("New space (%dk of %dk) " |
233 "Old space (%dk of %dk) " | 290 "Old space (%dk of %dk) " |
234 "Code space (%dk of %dk)\n", | 291 "Code space (%dk of %dk)\n", |
235 (new_space_->in_use() / KB), (new_space_->capacity() / KB), | 292 (new_space_->in_use() / KB), (new_space_->capacity() / KB), |
236 (old_space_->in_use() / KB), (old_space_->capacity() / KB), | 293 (old_space_->in_use() / KB), (old_space_->capacity() / KB), |
237 (code_space_->in_use() / KB), (code_space_->capacity() / KB)); | 294 (code_space_->in_use() / KB), (code_space_->capacity() / KB)); |
238 } | 295 } |
239 | 296 |
240 | 297 |
241 void Heap::Profile(Dart_HeapProfileWriteCallback callback, void* stream) const { | 298 void Heap::Profile(Dart_HeapProfileWriteCallback callback, void* stream) const { |
242 HeapProfiler profiler(callback, stream); | 299 HeapProfiler profiler(callback, stream); |
243 | 300 |
244 // Dump the root set. | 301 // Dump the root set. |
245 HeapProfilerRootVisitor root_visitor(&profiler); | 302 HeapProfilerRootVisitor root_visitor(&profiler); |
246 Isolate* isolate = Isolate::Current(); | 303 Isolate* isolate = Isolate::Current(); |
247 Isolate* vm_isolate = Dart::vm_isolate(); | 304 Isolate* vm_isolate = Dart::vm_isolate(); |
248 isolate->VisitObjectPointers(&root_visitor, false, | 305 isolate->VisitObjectPointers(&root_visitor, false, |
249 StackFrameIterator::kDontValidateFrames); | 306 StackFrameIterator::kDontValidateFrames); |
250 HeapProfilerWeakRootVisitor weak_root_visitor(&root_visitor); | 307 HeapProfilerWeakRootVisitor weak_root_visitor(&root_visitor); |
251 isolate->VisitWeakPersistentHandles(&weak_root_visitor, true); | 308 isolate->VisitWeakPersistentHandles(&weak_root_visitor, true); |
252 | 309 |
253 // Dump the current and VM isolate heaps. | 310 // Dump the current and VM isolate heaps. |
254 HeapProfilerObjectVisitor object_visitor(&profiler); | 311 HeapProfilerObjectVisitor object_visitor(isolate, &profiler); |
255 isolate->heap()->new_space_->VisitObjects(&object_visitor); | 312 isolate->heap()->IterateObjects(&object_visitor); |
256 isolate->heap()->old_space_->VisitObjects(&object_visitor); | 313 vm_isolate->heap()->IterateObjects(&object_visitor); |
257 isolate->heap()->code_space_->VisitObjects(&object_visitor); | |
258 vm_isolate->heap()->new_space_->VisitObjects(&object_visitor); | |
259 vm_isolate->heap()->old_space_->VisitObjects(&object_visitor); | |
260 } | 314 } |
261 | 315 |
262 | 316 |
263 #if defined(DEBUG) | 317 #if defined(DEBUG) |
264 NoGCScope::NoGCScope() : StackResource(Isolate::Current()) { | 318 NoGCScope::NoGCScope() : StackResource(Isolate::Current()) { |
265 isolate()->IncrementNoGCScopeDepth(); | 319 isolate()->IncrementNoGCScopeDepth(); |
266 } | 320 } |
267 | 321 |
268 | 322 |
269 NoGCScope::~NoGCScope() { | 323 NoGCScope::~NoGCScope() { |
270 isolate()->DecrementNoGCScopeDepth(); | 324 isolate()->DecrementNoGCScopeDepth(); |
271 } | 325 } |
272 #endif // defined(DEBUG) | 326 #endif // defined(DEBUG) |
273 | 327 |
274 } // namespace dart | 328 } // namespace dart |
OLD | NEW |