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/snapshot.h" | 5 #include "vm/snapshot.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/bootstrap.h" | 8 #include "vm/bootstrap.h" |
9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
10 #include "vm/heap.h" | 10 #include "vm/heap.h" |
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 | 718 |
719 // Write out the individual Smis. | 719 // Write out the individual Smis. |
720 for (int i = 0; i < field_count; i++) { | 720 for (int i = 0; i < field_count; i++) { |
721 Write<RawObject*>(Integer::New(data[i])); | 721 Write<RawObject*>(Integer::New(data[i])); |
722 } | 722 } |
723 | 723 |
724 FinalizeBuffer(); | 724 FinalizeBuffer(); |
725 } | 725 } |
726 | 726 |
727 | 727 |
| 728 void MessageWriter::WriteSmi(int32_t value) { |
| 729 Write<RawObject*>(Smi::New(value)); |
| 730 } |
| 731 |
| 732 |
| 733 void MessageWriter::WriteCObject(Dart_CObject* object) { |
| 734 switch (object->type) { |
| 735 case Dart_CObject::kNull: |
| 736 WriteIndexedObject(Object::kNullObject); |
| 737 break; |
| 738 case Dart_CObject::kBool: |
| 739 if (object->value.as_bool) { |
| 740 WriteIndexedObject(ObjectStore::kTrueValue); |
| 741 } else { |
| 742 WriteIndexedObject(ObjectStore::kFalseValue); |
| 743 } |
| 744 break; |
| 745 case Dart_CObject::kInt32: { |
| 746 WriteSmi(object->value.as_int32); |
| 747 break; |
| 748 } |
| 749 case Dart_CObject::kDouble: |
| 750 // Write out the serialization header value for this object. |
| 751 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds + object_id_); |
| 752 object_id_++; |
| 753 // Write out the class and tags information. |
| 754 WriteObjectHeader(ObjectStore::kDoubleClass, 0); |
| 755 Write<double>(object->value.as_double); |
| 756 break; |
| 757 case Dart_CObject::kString: { |
| 758 // Write out the serialization header value for this object. |
| 759 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds + object_id_); |
| 760 object_id_++; |
| 761 char* str = object->value.as_string; |
| 762 intptr_t len = strlen(str); |
| 763 // Write out the class and tags information. |
| 764 WriteObjectHeader(ObjectStore::kOneByteStringClass, 0); |
| 765 WriteSmi(len); |
| 766 WriteSmi(0); // Hash - not written. |
| 767 for (intptr_t i = 0; i < len; i++) { |
| 768 Write<uint8_t>(str[i]); |
| 769 } |
| 770 break; |
| 771 } |
| 772 case Dart_CObject::kArray: |
| 773 // Write out the serialization header value for this object. |
| 774 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds + object_id_); |
| 775 object_id_++; |
| 776 // Write out the class and tags information. |
| 777 WriteObjectHeader(ObjectStore::kArrayClass, 0); |
| 778 WriteSmi(object->value.as_array.length); |
| 779 // Write out the type arguments. |
| 780 WriteIndexedObject(Object::kNullObject); |
| 781 for (int i = 0; i < object->value.as_array.length; i++) { |
| 782 WriteCObject(object->value.as_array.values[i]); |
| 783 } |
| 784 break; |
| 785 default: |
| 786 UNREACHABLE(); |
| 787 } |
| 788 } |
| 789 |
| 790 |
| 791 void MessageWriter::WriteCMessage(Dart_CObject* object) { |
| 792 WriteCObject(object); |
| 793 FinalizeBuffer(); |
| 794 } |
| 795 |
| 796 |
728 void SnapshotWriter::WriteObject(RawObject* rawobj) { | 797 void SnapshotWriter::WriteObject(RawObject* rawobj) { |
729 // An object is written in one of the following ways: | 798 // An object is written in one of the following ways: |
730 // - Smi: the Smi value is written as is (last bit is not tagged). | 799 // - Smi: the Smi value is written as is (last bit is not tagged). |
731 // - VM internal class (from VM isolate): (index of class in vm isolate | 0x3) | 800 // - VM internal class (from VM isolate): (index of class in vm isolate | 0x3) |
732 // - Object that has already been written: (negative id in stream | 0x3) | 801 // - Object that has already been written: (negative id in stream | 0x3) |
733 // - Object that is seen for the first time (inlined as follows): | 802 // - Object that is seen for the first time (inlined as follows): |
734 // (object size in multiples of kObjectAlignment | 0x1) | 803 // (object size in multiples of kObjectAlignment | 0x1) |
735 // serialized fields of the object | 804 // serialized fields of the object |
736 // ...... | 805 // ...... |
737 | 806 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 | 997 |
929 | 998 |
930 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { | 999 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { |
931 for (RawObject** current = first; current <= last; current++) { | 1000 for (RawObject** current = first; current <= last; current++) { |
932 RawObject* raw_obj = *current; | 1001 RawObject* raw_obj = *current; |
933 writer_->WriteObject(raw_obj); | 1002 writer_->WriteObject(raw_obj); |
934 } | 1003 } |
935 } | 1004 } |
936 | 1005 |
937 } // namespace dart | 1006 } // namespace dart |
OLD | NEW |