| 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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 // u4 - stack trace serial number | 393 // u4 - stack trace serial number |
| 394 // ID - class name string ID | 394 // ID - class name string ID |
| 395 void HeapProfiler::WriteLoadClass(const RawClass* raw_class) { | 395 void HeapProfiler::WriteLoadClass(const RawClass* raw_class) { |
| 396 Record record(kLoadClass, this); | 396 Record record(kLoadClass, this); |
| 397 // class serial number (always > 0) | 397 // class serial number (always > 0) |
| 398 record.Write32(1); | 398 record.Write32(1); |
| 399 // class object ID | 399 // class object ID |
| 400 record.WritePointer(raw_class); | 400 record.WritePointer(raw_class); |
| 401 // stack trace serial number | 401 // stack trace serial number |
| 402 record.Write32(0); | 402 record.Write32(0); |
| 403 ASSERT(raw_class->ptr()->name_ != String::null()); | 403 // class name string ID |
| 404 record.WritePointer(StringId(raw_class->ptr()->name_)); | 404 if (raw_class->ptr()->name_ != String::null()) { |
| 405 record.WritePointer(StringId(raw_class->ptr()->name_)); |
| 406 } else { |
| 407 const char* format = "<an unnamed class with id %d>"; |
| 408 intptr_t len = OS::SNPrint(NULL, 0, format, raw_class->ptr()->id_); |
| 409 char* str = new char[len + 1]; |
| 410 OS::SNPrint(str, len + 1, format, raw_class->ptr()->id_); |
| 411 record.WritePointer(StringId(str)); |
| 412 delete[] str; |
| 413 } |
| 405 } | 414 } |
| 406 | 415 |
| 407 | 416 |
| 408 // STACK TRACE - 0x05 | 417 // STACK TRACE - 0x05 |
| 409 // | 418 // |
| 410 // u4 - stack trace serial number | 419 // u4 - stack trace serial number |
| 411 // u4 - thread serial number | 420 // u4 - thread serial number |
| 412 // u4 - number of frames | 421 // u4 - number of frames |
| 413 // [ID]* - series of stack frame ID's | 422 // [ID]* - series of stack frame ID's |
| 414 void HeapProfiler::WriteStackTrace() { | 423 void HeapProfiler::WriteStackTrace() { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 cls != Class::null(); | 602 cls != Class::null(); |
| 594 cls = GetSuperClass(cls)) { | 603 cls = GetSuperClass(cls)) { |
| 595 RawArray* raw_array = cls->ptr()->fields_; | 604 RawArray* raw_array = cls->ptr()->fields_; |
| 596 if (raw_array != Array::null()) { | 605 if (raw_array != Array::null()) { |
| 597 intptr_t length = Smi::Value(raw_array->ptr()->length_); | 606 intptr_t length = Smi::Value(raw_array->ptr()->length_); |
| 598 uint8_t* base = reinterpret_cast<uint8_t*>(raw_obj->ptr()); | 607 uint8_t* base = reinterpret_cast<uint8_t*>(raw_obj->ptr()); |
| 599 for (intptr_t i = 0; i < length; ++i) { | 608 for (intptr_t i = 0; i < length; ++i) { |
| 600 RawField* raw_field = | 609 RawField* raw_field = |
| 601 reinterpret_cast<RawField*>(raw_array->ptr()->data()[i]); | 610 reinterpret_cast<RawField*>(raw_array->ptr()->data()[i]); |
| 602 if (!Field::StaticBit::decode(raw_field->ptr()->kind_bits_)) { | 611 if (!Field::StaticBit::decode(raw_field->ptr()->kind_bits_)) { |
| 603 intptr_t offset = | 612 intptr_t offset_in_words = |
| 604 Smi::Value(reinterpret_cast<RawSmi*>(raw_field->ptr()->value_)); | 613 Smi::Value(reinterpret_cast<RawSmi*>(raw_field->ptr()->value_)); |
| 614 intptr_t offset = offset_in_words * kWordSize; |
| 605 RawObject* ptr = *reinterpret_cast<RawObject**>(base + offset); | 615 RawObject* ptr = *reinterpret_cast<RawObject**>(base + offset); |
| 606 sub.WritePointer(ObjectId(ptr)); | 616 sub.WritePointer(ObjectId(ptr)); |
| 607 } | 617 } |
| 608 } | 618 } |
| 609 } | 619 } |
| 610 } | 620 } |
| 611 } | 621 } |
| 612 | 622 |
| 613 | 623 |
| 614 // OBJECT ARRAY DUMP - 0x22 | 624 // OBJECT ARRAY DUMP - 0x22 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 RawObject* raw_obj = handle->raw(); | 713 RawObject* raw_obj = handle->raw(); |
| 704 visitor_->VisitPointer(&raw_obj); | 714 visitor_->VisitPointer(&raw_obj); |
| 705 } | 715 } |
| 706 | 716 |
| 707 | 717 |
| 708 void HeapProfilerObjectVisitor::VisitObject(RawObject* raw_obj) { | 718 void HeapProfilerObjectVisitor::VisitObject(RawObject* raw_obj) { |
| 709 profiler_->WriteObject(raw_obj); | 719 profiler_->WriteObject(raw_obj); |
| 710 } | 720 } |
| 711 | 721 |
| 712 } // namespace dart | 722 } // namespace dart |
| OLD | NEW |