| 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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 sub.WritePointer(NULL); | 510 sub.WritePointer(NULL); |
| 511 | 511 |
| 512 intptr_t num_static_fields = 0; | 512 intptr_t num_static_fields = 0; |
| 513 intptr_t num_instance_fields = 0; | 513 intptr_t num_instance_fields = 0; |
| 514 | 514 |
| 515 RawArray* raw_array = raw_class->ptr()->fields_; | 515 RawArray* raw_array = raw_class->ptr()->fields_; |
| 516 if (raw_array != Array::null()) { | 516 if (raw_array != Array::null()) { |
| 517 for (intptr_t i = 0; i < Smi::Value(raw_array->ptr()->length_); ++i) { | 517 for (intptr_t i = 0; i < Smi::Value(raw_array->ptr()->length_); ++i) { |
| 518 RawField* raw_field = | 518 RawField* raw_field = |
| 519 reinterpret_cast<RawField*>(raw_array->ptr()->data()[i]); | 519 reinterpret_cast<RawField*>(raw_array->ptr()->data()[i]); |
| 520 if (raw_field->ptr()->is_static_) { | 520 if (Field::StaticBit::decode(raw_field->ptr()->kind_bits_)) { |
| 521 ++num_static_fields; | 521 ++num_static_fields; |
| 522 } else { | 522 } else { |
| 523 ++num_instance_fields; | 523 ++num_instance_fields; |
| 524 } | 524 } |
| 525 } | 525 } |
| 526 } | 526 } |
| 527 // instance size (in bytes) | 527 // instance size (in bytes) |
| 528 // TODO(cshapiro): properly account for variable sized objects | 528 // TODO(cshapiro): properly account for variable sized objects |
| 529 sub.Write32(raw_class->ptr()->instance_size_); | 529 sub.Write32(raw_class->ptr()->instance_size_); |
| 530 // size of constant pool and number of records that follow: | 530 // size of constant pool and number of records that follow: |
| 531 sub.Write16(0); | 531 sub.Write16(0); |
| 532 // Number of static fields | 532 // Number of static fields |
| 533 sub.Write16(num_static_fields); | 533 sub.Write16(num_static_fields); |
| 534 // Static fields: | 534 // Static fields: |
| 535 if (raw_array != Array::null()) { | 535 if (raw_array != Array::null()) { |
| 536 for (intptr_t i = 0; i < Smi::Value(raw_array->ptr()->length_); ++i) { | 536 for (intptr_t i = 0; i < Smi::Value(raw_array->ptr()->length_); ++i) { |
| 537 RawField* raw_field = | 537 RawField* raw_field = |
| 538 reinterpret_cast<RawField*>(raw_array->ptr()->data()[i]); | 538 reinterpret_cast<RawField*>(raw_array->ptr()->data()[i]); |
| 539 if (raw_field->ptr()->is_static_) { | 539 if (Field::StaticBit::decode(raw_field->ptr()->kind_bits_)) { |
| 540 ASSERT(raw_field->ptr()->name_ != String::null()); | 540 ASSERT(raw_field->ptr()->name_ != String::null()); |
| 541 // static field name string ID | 541 // static field name string ID |
| 542 sub.WritePointer(StringId(raw_field->ptr()->name_)); | 542 sub.WritePointer(StringId(raw_field->ptr()->name_)); |
| 543 // type of static field | 543 // type of static field |
| 544 sub.Write8(kObject); | 544 sub.Write8(kObject); |
| 545 // value of entry | 545 // value of entry |
| 546 sub.WritePointer(ObjectId(raw_field->ptr()->value_)); | 546 sub.WritePointer(ObjectId(raw_field->ptr()->value_)); |
| 547 } | 547 } |
| 548 } | 548 } |
| 549 } | 549 } |
| 550 // Number of instance fields (not include super class's) | 550 // Number of instance fields (not include super class's) |
| 551 sub.Write16(num_instance_fields); | 551 sub.Write16(num_instance_fields); |
| 552 // Instance fields: | 552 // Instance fields: |
| 553 if (raw_array != Array::null()) { | 553 if (raw_array != Array::null()) { |
| 554 for (intptr_t i = 0; i < Smi::Value(raw_array->ptr()->length_); ++i) { | 554 for (intptr_t i = 0; i < Smi::Value(raw_array->ptr()->length_); ++i) { |
| 555 RawField* raw_field = | 555 RawField* raw_field = |
| 556 reinterpret_cast<RawField*>(raw_array->ptr()->data()[i]); | 556 reinterpret_cast<RawField*>(raw_array->ptr()->data()[i]); |
| 557 if (!raw_field->ptr()->is_static_) { | 557 if (!Field::StaticBit::decode(raw_field->ptr()->kind_bits_)) { |
| 558 ASSERT(raw_field->ptr()->name_ != String::null()); | 558 ASSERT(raw_field->ptr()->name_ != String::null()); |
| 559 // field name string ID | 559 // field name string ID |
| 560 sub.WritePointer(StringId(raw_field->ptr()->name_)); | 560 sub.WritePointer(StringId(raw_field->ptr()->name_)); |
| 561 // type of field | 561 // type of field |
| 562 sub.Write8(kObject); | 562 sub.Write8(kObject); |
| 563 } | 563 } |
| 564 } | 564 } |
| 565 } | 565 } |
| 566 } | 566 } |
| 567 | 567 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 586 intptr_t num_instance_fields = 0; | 586 intptr_t num_instance_fields = 0; |
| 587 for (const RawClass* cls = GetClass(raw_obj); | 587 for (const RawClass* cls = GetClass(raw_obj); |
| 588 cls != Class::null(); | 588 cls != Class::null(); |
| 589 cls = GetSuperClass(cls)) { | 589 cls = GetSuperClass(cls)) { |
| 590 RawArray* raw_array = cls->ptr()->fields_; | 590 RawArray* raw_array = cls->ptr()->fields_; |
| 591 if (raw_array != Array::null()) { | 591 if (raw_array != Array::null()) { |
| 592 intptr_t length = Smi::Value(raw_array->ptr()->length_); | 592 intptr_t length = Smi::Value(raw_array->ptr()->length_); |
| 593 for (intptr_t i = 0; i < length; ++i) { | 593 for (intptr_t i = 0; i < length; ++i) { |
| 594 RawField* raw_field = | 594 RawField* raw_field = |
| 595 reinterpret_cast<RawField*>(raw_array->ptr()->data()[i]); | 595 reinterpret_cast<RawField*>(raw_array->ptr()->data()[i]); |
| 596 if (!raw_field->ptr()->is_static_) { | 596 if (!Field::StaticBit::decode(raw_field->ptr()->kind_bits_)) { |
| 597 ++num_instance_fields; | 597 ++num_instance_fields; |
| 598 } | 598 } |
| 599 } | 599 } |
| 600 } | 600 } |
| 601 } | 601 } |
| 602 sub.Write32(num_instance_fields * kWordSize); | 602 sub.Write32(num_instance_fields * kWordSize); |
| 603 // instance field values (this class, followed by super class, etc) | 603 // instance field values (this class, followed by super class, etc) |
| 604 for (const RawClass* cls = GetClass(raw_obj); | 604 for (const RawClass* cls = GetClass(raw_obj); |
| 605 cls != Class::null(); | 605 cls != Class::null(); |
| 606 cls = GetSuperClass(cls)) { | 606 cls = GetSuperClass(cls)) { |
| 607 RawArray* raw_array = cls->ptr()->fields_; | 607 RawArray* raw_array = cls->ptr()->fields_; |
| 608 if (raw_array != Array::null()) { | 608 if (raw_array != Array::null()) { |
| 609 intptr_t length = Smi::Value(raw_array->ptr()->length_); | 609 intptr_t length = Smi::Value(raw_array->ptr()->length_); |
| 610 uint8_t* base = reinterpret_cast<uint8_t*>(raw_obj->ptr()); | 610 uint8_t* base = reinterpret_cast<uint8_t*>(raw_obj->ptr()); |
| 611 for (intptr_t i = 0; i < length; ++i) { | 611 for (intptr_t i = 0; i < length; ++i) { |
| 612 RawField* raw_field = | 612 RawField* raw_field = |
| 613 reinterpret_cast<RawField*>(raw_array->ptr()->data()[i]); | 613 reinterpret_cast<RawField*>(raw_array->ptr()->data()[i]); |
| 614 if (!raw_field->ptr()->is_static_) { | 614 if (!Field::StaticBit::decode(raw_field->ptr()->kind_bits_)) { |
| 615 intptr_t offset = | 615 intptr_t offset = |
| 616 Smi::Value(reinterpret_cast<RawSmi*>(raw_field->ptr()->value_)); | 616 Smi::Value(reinterpret_cast<RawSmi*>(raw_field->ptr()->value_)); |
| 617 RawObject* ptr = *reinterpret_cast<RawObject**>(base + offset); | 617 RawObject* ptr = *reinterpret_cast<RawObject**>(base + offset); |
| 618 sub.WritePointer(ObjectId(ptr)); | 618 sub.WritePointer(ObjectId(ptr)); |
| 619 } | 619 } |
| 620 } | 620 } |
| 621 } | 621 } |
| 622 } | 622 } |
| 623 } | 623 } |
| 624 | 624 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 RawObject* raw_obj = handle->raw(); | 715 RawObject* raw_obj = handle->raw(); |
| 716 visitor_->VisitPointer(&raw_obj); | 716 visitor_->VisitPointer(&raw_obj); |
| 717 } | 717 } |
| 718 | 718 |
| 719 | 719 |
| 720 void HeapProfilerObjectVisitor::VisitObject(RawObject* raw_obj) { | 720 void HeapProfilerObjectVisitor::VisitObject(RawObject* raw_obj) { |
| 721 profiler_->WriteObject(raw_obj); | 721 profiler_->WriteObject(raw_obj); |
| 722 } | 722 } |
| 723 | 723 |
| 724 } // namespace dart | 724 } // namespace dart |
| OLD | NEW |