| 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_profiler.h" | 5 #include "vm/heap_profiler.h" |
| 6 | 6 |
| 7 #include "vm/dart_api_state.h" | 7 #include "vm/dart_api_state.h" |
| 8 #include "vm/object.h" | 8 #include "vm/object.h" |
| 9 #include "vm/raw_object.h" | 9 #include "vm/raw_object.h" |
| 10 #include "vm/stack_frame.h" | 10 #include "vm/stack_frame.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 record_->WriteObjectId(value); | 112 record_->WriteObjectId(value); |
| 113 } | 113 } |
| 114 | 114 |
| 115 | 115 |
| 116 HeapProfiler::HeapProfiler(Dart_FileWriteCallback callback, void* stream) | 116 HeapProfiler::HeapProfiler(Dart_FileWriteCallback callback, void* stream) |
| 117 : write_callback_(callback), | 117 : write_callback_(callback), |
| 118 output_stream_(stream), | 118 output_stream_(stream), |
| 119 heap_dump_record_(NULL) { | 119 heap_dump_record_(NULL) { |
| 120 WriteHeader(); | 120 WriteHeader(); |
| 121 WriteStackTrace(); | 121 WriteStackTrace(); |
| 122 WriteFakeLoadClass(kJavaLangClass, "java.lang.Class"); |
| 123 WriteFakeLoadClass(kJavaLangClassLoader, "java.lang.ClassLoader"); |
| 124 WriteFakeLoadClass(kJavaLangObject, "java.lang.Object"); |
| 125 WriteFakeLoadClass(kJavaLangString, "java.lang.String"); |
| 126 WriteFakeLoadClass(kArrayObject, "Object[]"); |
| 127 WriteFakeLoadClass(kArrayBoolean, "bool[]"); |
| 128 WriteFakeLoadClass(kArrayChar, "char[]"); |
| 129 WriteFakeLoadClass(kArrayFloat, "float[]"); |
| 130 WriteFakeLoadClass(kArrayDouble, "double[]"); |
| 131 WriteFakeLoadClass(kArrayByte, "byte[]"); |
| 132 WriteFakeLoadClass(kArrayShort, "short[]"); |
| 133 WriteFakeLoadClass(kArrayInt, "int[]"); |
| 134 WriteFakeLoadClass(kArrayLong, "long[]"); |
| 122 heap_dump_record_ = new Record(kHeapDump, this); | 135 heap_dump_record_ = new Record(kHeapDump, this); |
| 136 WriteFakeClassDump(kJavaLangClass, static_cast<FakeClass>(0)); |
| 137 WriteFakeClassDump(kJavaLangClassLoader, kJavaLangObject); |
| 138 WriteFakeClassDump(kJavaLangObject, static_cast<FakeClass>(0)); |
| 139 WriteFakeClassDump(kJavaLangString, kJavaLangObject); |
| 123 } | 140 } |
| 124 | 141 |
| 125 | 142 |
| 126 HeapProfiler::~HeapProfiler() { | 143 HeapProfiler::~HeapProfiler() { |
| 127 delete heap_dump_record_; | 144 delete heap_dump_record_; |
| 128 } | 145 } |
| 129 | 146 |
| 130 | 147 |
| 131 const RawObject* HeapProfiler::ObjectId(const RawObject* raw_obj) { | 148 const RawObject* HeapProfiler::ObjectId(const RawObject* raw_obj) { |
| 132 if (!raw_obj->IsHeapObject()) { | 149 if (!raw_obj->IsHeapObject()) { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 const char* format = "<an unnamed class with id %d>"; | 424 const char* format = "<an unnamed class with id %d>"; |
| 408 intptr_t len = OS::SNPrint(NULL, 0, format, raw_class->ptr()->id_); | 425 intptr_t len = OS::SNPrint(NULL, 0, format, raw_class->ptr()->id_); |
| 409 char* str = new char[len + 1]; | 426 char* str = new char[len + 1]; |
| 410 OS::SNPrint(str, len + 1, format, raw_class->ptr()->id_); | 427 OS::SNPrint(str, len + 1, format, raw_class->ptr()->id_); |
| 411 record.WriteObjectId(StringId(str)); | 428 record.WriteObjectId(StringId(str)); |
| 412 delete[] str; | 429 delete[] str; |
| 413 } | 430 } |
| 414 } | 431 } |
| 415 | 432 |
| 416 | 433 |
| 434 void HeapProfiler::WriteFakeLoadClass(FakeClass fake_class, |
| 435 const char* class_name) { |
| 436 Record record(kLoadClass, this); |
| 437 // class serial number (always > 0) |
| 438 record.Write32(1); |
| 439 // class object ID |
| 440 record.WriteObjectId(reinterpret_cast<void*>(fake_class)); |
| 441 // stack trace serial number |
| 442 record.Write32(0); |
| 443 // class name string ID |
| 444 record.WriteObjectId(StringId(class_name)); |
| 445 } |
| 446 |
| 447 |
| 417 // STACK TRACE - 0x05 | 448 // STACK TRACE - 0x05 |
| 418 // | 449 // |
| 419 // u4 - stack trace serial number | 450 // u4 - stack trace serial number |
| 420 // u4 - thread serial number | 451 // u4 - thread serial number |
| 421 // u4 - number of frames | 452 // u4 - number of frames |
| 422 // [ID]* - series of stack frame ID's | 453 // [ID]* - series of stack frame ID's |
| 423 void HeapProfiler::WriteStackTrace() { | 454 void HeapProfiler::WriteStackTrace() { |
| 424 Record record(kStackTrace, this); | 455 Record record(kStackTrace, this); |
| 425 // stack trace serial number | 456 // stack trace serial number |
| 426 record.Write32(0); | 457 record.Write32(0); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 ASSERT(raw_field->ptr()->name_ != String::null()); | 590 ASSERT(raw_field->ptr()->name_ != String::null()); |
| 560 // field name string ID | 591 // field name string ID |
| 561 sub.WriteObjectId(StringId(raw_field->ptr()->name_)); | 592 sub.WriteObjectId(StringId(raw_field->ptr()->name_)); |
| 562 // type of field | 593 // type of field |
| 563 sub.Write8(kObject); | 594 sub.Write8(kObject); |
| 564 } | 595 } |
| 565 } | 596 } |
| 566 } | 597 } |
| 567 } | 598 } |
| 568 | 599 |
| 600 void HeapProfiler::WriteFakeClassDump(FakeClass fake_class, |
| 601 FakeClass fake_super_class) { |
| 602 SubRecord sub(kClassDump, this); |
| 603 // class object ID |
| 604 sub.WriteObjectId(reinterpret_cast<void*>(fake_class)); |
| 605 // stack trace serial number |
| 606 sub.Write32(0); |
| 607 // super class object ID |
| 608 sub.WriteObjectId(reinterpret_cast<void*>(fake_super_class)); |
| 609 // class loader object ID |
| 610 sub.WriteObjectId(NULL); |
| 611 // signers object ID |
| 612 sub.WriteObjectId(NULL); |
| 613 // protection domain object ID |
| 614 sub.WriteObjectId(NULL); |
| 615 // reserved |
| 616 sub.WriteObjectId(NULL); |
| 617 // reserved |
| 618 sub.WriteObjectId(NULL); |
| 619 // instance size (in bytes) |
| 620 sub.Write32(0); |
| 621 // size of constant pool and number of records that follow: |
| 622 sub.Write16(0); |
| 623 // Number of static fields |
| 624 sub.Write16(0); |
| 625 // Number of instance fields (not include super class's) |
| 626 sub.Write16(0); |
| 627 } |
| 628 |
| 629 |
| 569 | 630 |
| 570 // INSTANCE DUMP - 0x21 | 631 // INSTANCE DUMP - 0x21 |
| 571 // | 632 // |
| 572 // Format: | 633 // Format: |
| 573 // ID - object ID | 634 // ID - object ID |
| 574 // u4 - stack trace serial number | 635 // u4 - stack trace serial number |
| 575 // ID - class object ID | 636 // ID - class object ID |
| 576 // u4 - number of bytes that follow | 637 // u4 - number of bytes that follow |
| 577 // [value]* - instance field values (this class, followed by super class, etc) | 638 // [value]* - instance field values (this class, followed by super class, etc) |
| 578 void HeapProfiler::WriteInstanceDump(const RawObject* raw_obj) { | 639 void HeapProfiler::WriteInstanceDump(const RawObject* raw_obj) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 void HeapProfiler::WriteObjectArrayDump(const RawArray* raw_array) { | 699 void HeapProfiler::WriteObjectArrayDump(const RawArray* raw_array) { |
| 639 SubRecord sub(kObjectArrayDump, this); | 700 SubRecord sub(kObjectArrayDump, this); |
| 640 // array object ID | 701 // array object ID |
| 641 sub.WriteObjectId(raw_array); | 702 sub.WriteObjectId(raw_array); |
| 642 // stack trace serial number | 703 // stack trace serial number |
| 643 sub.Write32(0); | 704 sub.Write32(0); |
| 644 // number of elements | 705 // number of elements |
| 645 intptr_t length = Smi::Value(raw_array->ptr()->length_); | 706 intptr_t length = Smi::Value(raw_array->ptr()->length_); |
| 646 sub.Write32(length); | 707 sub.Write32(length); |
| 647 // array class object ID | 708 // array class object ID |
| 648 sub.WriteObjectId(NULL); | 709 sub.WriteObjectId(reinterpret_cast<void*>(kArrayObject)); |
| 649 // elements | 710 // elements |
| 650 for (intptr_t i = 0; i < length; ++i) { | 711 for (intptr_t i = 0; i < length; ++i) { |
| 651 sub.WriteObjectId(ObjectId(raw_array->ptr()->data()[i])); | 712 sub.WriteObjectId(ObjectId(raw_array->ptr()->data()[i])); |
| 652 } | 713 } |
| 653 } | 714 } |
| 654 | 715 |
| 655 | 716 |
| 656 // PRIMITIVE ARRAY DUMP - 0x23 | 717 // PRIMITIVE ARRAY DUMP - 0x23 |
| 657 // | 718 // |
| 658 // Format: | 719 // Format: |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 RawObject* raw_obj = handle->raw(); | 780 RawObject* raw_obj = handle->raw(); |
| 720 visitor_->VisitPointer(&raw_obj); | 781 visitor_->VisitPointer(&raw_obj); |
| 721 } | 782 } |
| 722 | 783 |
| 723 | 784 |
| 724 void HeapProfilerObjectVisitor::VisitObject(RawObject* raw_obj) { | 785 void HeapProfilerObjectVisitor::VisitObject(RawObject* raw_obj) { |
| 725 profiler_->WriteObject(raw_obj); | 786 profiler_->WriteObject(raw_obj); |
| 726 } | 787 } |
| 727 | 788 |
| 728 } // namespace dart | 789 } // namespace dart |
| OLD | NEW |