| 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 record.Write32(1); |
| 438 record.WriteObjectId(reinterpret_cast<void*>(fake_class)); |
| 439 record.Write32(0); |
| 440 record.WriteObjectId(StringId(class_name)); |
| 441 } |
| 442 |
| 443 |
| 417 // STACK TRACE - 0x05 | 444 // STACK TRACE - 0x05 |
| 418 // | 445 // |
| 419 // u4 - stack trace serial number | 446 // u4 - stack trace serial number |
| 420 // u4 - thread serial number | 447 // u4 - thread serial number |
| 421 // u4 - number of frames | 448 // u4 - number of frames |
| 422 // [ID]* - series of stack frame ID's | 449 // [ID]* - series of stack frame ID's |
| 423 void HeapProfiler::WriteStackTrace() { | 450 void HeapProfiler::WriteStackTrace() { |
| 424 Record record(kStackTrace, this); | 451 Record record(kStackTrace, this); |
| 425 // stack trace serial number | 452 // stack trace serial number |
| 426 record.Write32(0); | 453 record.Write32(0); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 ASSERT(raw_field->ptr()->name_ != String::null()); | 586 ASSERT(raw_field->ptr()->name_ != String::null()); |
| 560 // field name string ID | 587 // field name string ID |
| 561 sub.WriteObjectId(StringId(raw_field->ptr()->name_)); | 588 sub.WriteObjectId(StringId(raw_field->ptr()->name_)); |
| 562 // type of field | 589 // type of field |
| 563 sub.Write8(kObject); | 590 sub.Write8(kObject); |
| 564 } | 591 } |
| 565 } | 592 } |
| 566 } | 593 } |
| 567 } | 594 } |
| 568 | 595 |
| 596 void HeapProfiler::WriteFakeClassDump(FakeClass fake_class, |
| 597 FakeClass fake_super_class) { |
| 598 SubRecord sub(kClassDump, this); |
| 599 // class object ID |
| 600 sub.WriteObjectId(reinterpret_cast<void*>(fake_class)); |
| 601 // stack trace serial number |
| 602 sub.Write32(0); |
| 603 // super class object ID |
| 604 sub.WriteObjectId(reinterpret_cast<void*>(fake_super_class)); |
| 605 // class loader object ID |
| 606 sub.WriteObjectId(NULL); |
| 607 // signers object ID |
| 608 sub.WriteObjectId(NULL); |
| 609 // protection domain object ID |
| 610 sub.WriteObjectId(NULL); |
| 611 // reserved |
| 612 sub.WriteObjectId(NULL); |
| 613 // reserved |
| 614 sub.WriteObjectId(NULL); |
| 615 // instance size (in bytes) |
| 616 sub.Write32(0); |
| 617 // size of constant pool and number of records that follow: |
| 618 sub.Write16(0); |
| 619 // Number of static fields |
| 620 sub.Write16(0); |
| 621 // Number of instance fields (not include super class's) |
| 622 sub.Write16(0); |
| 623 } |
| 624 |
| 625 |
| 569 | 626 |
| 570 // INSTANCE DUMP - 0x21 | 627 // INSTANCE DUMP - 0x21 |
| 571 // | 628 // |
| 572 // Format: | 629 // Format: |
| 573 // ID - object ID | 630 // ID - object ID |
| 574 // u4 - stack trace serial number | 631 // u4 - stack trace serial number |
| 575 // ID - class object ID | 632 // ID - class object ID |
| 576 // u4 - number of bytes that follow | 633 // u4 - number of bytes that follow |
| 577 // [value]* - instance field values (this class, followed by super class, etc) | 634 // [value]* - instance field values (this class, followed by super class, etc) |
| 578 void HeapProfiler::WriteInstanceDump(const RawObject* raw_obj) { | 635 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) { | 695 void HeapProfiler::WriteObjectArrayDump(const RawArray* raw_array) { |
| 639 SubRecord sub(kObjectArrayDump, this); | 696 SubRecord sub(kObjectArrayDump, this); |
| 640 // array object ID | 697 // array object ID |
| 641 sub.WriteObjectId(raw_array); | 698 sub.WriteObjectId(raw_array); |
| 642 // stack trace serial number | 699 // stack trace serial number |
| 643 sub.Write32(0); | 700 sub.Write32(0); |
| 644 // number of elements | 701 // number of elements |
| 645 intptr_t length = Smi::Value(raw_array->ptr()->length_); | 702 intptr_t length = Smi::Value(raw_array->ptr()->length_); |
| 646 sub.Write32(length); | 703 sub.Write32(length); |
| 647 // array class object ID | 704 // array class object ID |
| 648 sub.WriteObjectId(NULL); | 705 sub.WriteObjectId(reinterpret_cast<void*>(kArrayObject)); |
| 649 // elements | 706 // elements |
| 650 for (intptr_t i = 0; i < length; ++i) { | 707 for (intptr_t i = 0; i < length; ++i) { |
| 651 sub.WriteObjectId(ObjectId(raw_array->ptr()->data()[i])); | 708 sub.WriteObjectId(ObjectId(raw_array->ptr()->data()[i])); |
| 652 } | 709 } |
| 653 } | 710 } |
| 654 | 711 |
| 655 | 712 |
| 656 // PRIMITIVE ARRAY DUMP - 0x23 | 713 // PRIMITIVE ARRAY DUMP - 0x23 |
| 657 // | 714 // |
| 658 // Format: | 715 // Format: |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 RawObject* raw_obj = handle->raw(); | 776 RawObject* raw_obj = handle->raw(); |
| 720 visitor_->VisitPointer(&raw_obj); | 777 visitor_->VisitPointer(&raw_obj); |
| 721 } | 778 } |
| 722 | 779 |
| 723 | 780 |
| 724 void HeapProfilerObjectVisitor::VisitObject(RawObject* raw_obj) { | 781 void HeapProfilerObjectVisitor::VisitObject(RawObject* raw_obj) { |
| 725 profiler_->WriteObject(raw_obj); | 782 profiler_->WriteObject(raw_obj); |
| 726 } | 783 } |
| 727 | 784 |
| 728 } // namespace dart | 785 } // namespace dart |
| OLD | NEW |