| 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/heap_histogram.h" | 10 #include "vm/heap_histogram.h" |
| 11 #include "vm/heap_profiler.h" | |
| 12 #include "vm/isolate.h" | 11 #include "vm/isolate.h" |
| 13 #include "vm/object.h" | 12 #include "vm/object.h" |
| 14 #include "vm/object_set.h" | 13 #include "vm/object_set.h" |
| 15 #include "vm/os.h" | 14 #include "vm/os.h" |
| 16 #include "vm/pages.h" | 15 #include "vm/pages.h" |
| 17 #include "vm/raw_object.h" | 16 #include "vm/raw_object.h" |
| 18 #include "vm/scavenger.h" | 17 #include "vm/scavenger.h" |
| 19 #include "vm/stack_frame.h" | 18 #include "vm/stack_frame.h" |
| 20 #include "vm/verifier.h" | 19 #include "vm/verifier.h" |
| 21 #include "vm/virtual_memory.h" | 20 #include "vm/virtual_memory.h" |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 return space == kNew ? new_space_->UsedInWords() : old_space_->UsedInWords(); | 313 return space == kNew ? new_space_->UsedInWords() : old_space_->UsedInWords(); |
| 315 } | 314 } |
| 316 | 315 |
| 317 | 316 |
| 318 intptr_t Heap::CapacityInWords(Space space) const { | 317 intptr_t Heap::CapacityInWords(Space space) const { |
| 319 return space == kNew ? new_space_->CapacityInWords() : | 318 return space == kNew ? new_space_->CapacityInWords() : |
| 320 old_space_->CapacityInWords(); | 319 old_space_->CapacityInWords(); |
| 321 } | 320 } |
| 322 | 321 |
| 323 | 322 |
| 324 void Heap::Profile(Dart_FileWriteCallback callback, void* stream) const { | |
| 325 HeapProfiler profiler(callback, stream); | |
| 326 | |
| 327 // Dump the root set. | |
| 328 HeapProfilerRootVisitor root_visitor(&profiler); | |
| 329 Isolate* isolate = Isolate::Current(); | |
| 330 Isolate* vm_isolate = Dart::vm_isolate(); | |
| 331 isolate->VisitObjectPointers(&root_visitor, false, | |
| 332 StackFrameIterator::kDontValidateFrames); | |
| 333 HeapProfilerWeakRootVisitor weak_root_visitor(&root_visitor); | |
| 334 isolate->VisitWeakPersistentHandles(&weak_root_visitor, true); | |
| 335 | |
| 336 // Dump the current and VM isolate heaps. | |
| 337 HeapProfilerObjectVisitor object_visitor(isolate, &profiler); | |
| 338 isolate->heap()->IterateObjects(&object_visitor); | |
| 339 vm_isolate->heap()->IterateObjects(&object_visitor); | |
| 340 } | |
| 341 | |
| 342 | |
| 343 void Heap::ProfileToFile(const char* reason) const { | |
| 344 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); | |
| 345 ASSERT(file_open != NULL); | |
| 346 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); | |
| 347 ASSERT(file_write != NULL); | |
| 348 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); | |
| 349 ASSERT(file_close != NULL); | |
| 350 Isolate* isolate = Isolate::Current(); | |
| 351 const char* format = "%s-%s.hprof"; | |
| 352 intptr_t len = OS::SNPrint(NULL, 0, format, isolate->name(), reason); | |
| 353 char* filename = isolate->current_zone()->Alloc<char>(len + 1); | |
| 354 OS::SNPrint(filename, len + 1, format, isolate->name(), reason); | |
| 355 void* file = (*file_open)(filename, true); | |
| 356 if (file != NULL) { | |
| 357 Profile(file_write, file); | |
| 358 (*file_close)(file); | |
| 359 } | |
| 360 } | |
| 361 | |
| 362 | |
| 363 const char* Heap::GCReasonToString(GCReason gc_reason) { | 323 const char* Heap::GCReasonToString(GCReason gc_reason) { |
| 364 switch (gc_reason) { | 324 switch (gc_reason) { |
| 365 case kNewSpace: | 325 case kNewSpace: |
| 366 return "new space"; | 326 return "new space"; |
| 367 case kPromotionFailure: | 327 case kPromotionFailure: |
| 368 return "promotion failure"; | 328 return "promotion failure"; |
| 369 case kOldSpace: | 329 case kOldSpace: |
| 370 return "old space"; | 330 return "old space"; |
| 371 case kFull: | 331 case kFull: |
| 372 return "full"; | 332 return "full"; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 heap->DisableGrowthControl(); | 472 heap->DisableGrowthControl(); |
| 513 } | 473 } |
| 514 | 474 |
| 515 | 475 |
| 516 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { | 476 NoHeapGrowthControlScope::~NoHeapGrowthControlScope() { |
| 517 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); | 477 Heap* heap = reinterpret_cast<Isolate*>(isolate())->heap(); |
| 518 heap->SetGrowthControlState(current_growth_controller_state_); | 478 heap->SetGrowthControlState(current_growth_controller_state_); |
| 519 } | 479 } |
| 520 | 480 |
| 521 } // namespace dart | 481 } // namespace dart |
| OLD | NEW |