| 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/dart_api_message.h" | 5 #include "vm/dart_api_message.h" |
| 6 #include "vm/object.h" | 6 #include "vm/object.h" |
| 7 #include "vm/snapshot_ids.h" | 7 #include "vm/snapshot_ids.h" |
| 8 #include "vm/symbols.h" | 8 #include "vm/symbols.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 // Write out the length field. | 471 // Write out the length field. |
| 472 Write<RawObject*>(Smi::New(field_count)); | 472 Write<RawObject*>(Smi::New(field_count)); |
| 473 | 473 |
| 474 // Write out the type arguments. | 474 // Write out the type arguments. |
| 475 WriteNullObject(); | 475 WriteNullObject(); |
| 476 | 476 |
| 477 // Write out the individual Smis. | 477 // Write out the individual Smis. |
| 478 for (int i = 0; i < field_count; i++) { | 478 for (int i = 0; i < field_count; i++) { |
| 479 Write<RawObject*>(Integer::New(data[i])); | 479 Write<RawObject*>(Integer::New(data[i])); |
| 480 } | 480 } |
| 481 | |
| 482 FinalizeBuffer(); | |
| 483 } | 481 } |
| 484 | 482 |
| 485 | 483 |
| 486 void ApiMessageWriter::MarkCObject(Dart_CObject* object, intptr_t object_id) { | 484 void ApiMessageWriter::MarkCObject(Dart_CObject* object, intptr_t object_id) { |
| 487 // Mark the object as serialized by adding the object id to the | 485 // Mark the object as serialized by adding the object id to the |
| 488 // upper bits of the type field in the Dart_CObject structure. Add | 486 // upper bits of the type field in the Dart_CObject structure. Add |
| 489 // an offset for making marking of object id 0 possible. | 487 // an offset for making marking of object id 0 possible. |
| 490 ASSERT(!IsCObjectMarked(object)); | 488 ASSERT(!IsCObjectMarked(object)); |
| 491 intptr_t mark_value = object_id + kDartCObjectMarkOffset; | 489 intptr_t mark_value = object_id + kDartCObjectMarkOffset; |
| 492 object->type = static_cast<Dart_CObject::Type>( | 490 object->type = static_cast<Dart_CObject::Type>( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 | 613 |
| 616 WriteSmi(object->value.as_array.length); | 614 WriteSmi(object->value.as_array.length); |
| 617 // Write out the type arguments. | 615 // Write out the type arguments. |
| 618 WriteNullObject(); | 616 WriteNullObject(); |
| 619 // Write out array elements. | 617 // Write out array elements. |
| 620 for (int i = 0; i < object->value.as_array.length; i++) { | 618 for (int i = 0; i < object->value.as_array.length; i++) { |
| 621 WriteCObjectRef(object->value.as_array.values[i]); | 619 WriteCObjectRef(object->value.as_array.values[i]); |
| 622 } | 620 } |
| 623 return; | 621 return; |
| 624 } | 622 } |
| 625 return WriteCObjectInlined(object, type); | 623 WriteCObjectInlined(object, type); |
| 626 } | 624 } |
| 627 | 625 |
| 628 | 626 |
| 629 void ApiMessageWriter::WriteCObjectRef(Dart_CObject* object) { | 627 void ApiMessageWriter::WriteCObjectRef(Dart_CObject* object) { |
| 630 if (IsCObjectMarked(object)) { | 628 if (IsCObjectMarked(object)) { |
| 631 intptr_t object_id = GetMarkedCObjectMark(object); | 629 intptr_t object_id = GetMarkedCObjectMark(object); |
| 632 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); | 630 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); |
| 633 return; | 631 return; |
| 634 } | 632 } |
| 635 | 633 |
| 636 Dart_CObject::Type type = object->type; | 634 Dart_CObject::Type type = object->type; |
| 637 if (type == Dart_CObject::kArray) { | 635 if (type == Dart_CObject::kArray) { |
| 638 // Write out the serialization header value for this object. | 636 // Write out the serialization header value for this object. |
| 639 WriteInlinedHeader(object); | 637 WriteInlinedHeader(object); |
| 640 // Write out the class information. | 638 // Write out the class information. |
| 641 WriteIndexedObject(kArrayCid); | 639 WriteIndexedObject(kArrayCid); |
| 642 // Write out the length information. | 640 // Write out the length information. |
| 643 WriteSmi(object->value.as_array.length); | 641 WriteSmi(object->value.as_array.length); |
| 644 // Add object to forward list so that this object is serialized later. | 642 // Add object to forward list so that this object is serialized later. |
| 645 AddToForwardList(object); | 643 AddToForwardList(object); |
| 646 return; | 644 return; |
| 647 } | 645 } |
| 648 return WriteCObjectInlined(object, type); | 646 WriteCObjectInlined(object, type); |
| 649 } | 647 } |
| 650 | 648 |
| 651 | 649 |
| 652 void ApiMessageWriter::WriteForwardedCObject(Dart_CObject* object) { | 650 void ApiMessageWriter::WriteForwardedCObject(Dart_CObject* object) { |
| 653 ASSERT(IsCObjectMarked(object)); | 651 ASSERT(IsCObjectMarked(object)); |
| 654 Dart_CObject::Type type = | 652 Dart_CObject::Type type = |
| 655 static_cast<Dart_CObject::Type>(object->type & kDartCObjectTypeMask); | 653 static_cast<Dart_CObject::Type>(object->type & kDartCObjectTypeMask); |
| 656 ASSERT(type == Dart_CObject::kArray); | 654 ASSERT(type == Dart_CObject::kArray); |
| 657 | 655 |
| 658 // Write out the serialization header value for this object. | 656 // Write out the serialization header value for this object. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 | 773 |
| 776 void ApiMessageWriter::WriteCMessage(Dart_CObject* object) { | 774 void ApiMessageWriter::WriteCMessage(Dart_CObject* object) { |
| 777 WriteCObject(object); | 775 WriteCObject(object); |
| 778 // Write out all objects that were added to the forward list and have | 776 // Write out all objects that were added to the forward list and have |
| 779 // not been serialized yet. These would typically be fields of arrays. | 777 // not been serialized yet. These would typically be fields of arrays. |
| 780 // NOTE: The forward list might grow as we process the list. | 778 // NOTE: The forward list might grow as we process the list. |
| 781 for (intptr_t i = 0; i < forward_id_; i++) { | 779 for (intptr_t i = 0; i < forward_id_; i++) { |
| 782 WriteForwardedCObject(forward_list_[i]); | 780 WriteForwardedCObject(forward_list_[i]); |
| 783 } | 781 } |
| 784 UnmarkAllCObjects(object); | 782 UnmarkAllCObjects(object); |
| 785 FinalizeBuffer(); | |
| 786 } | 783 } |
| 787 | 784 |
| 788 } // namespace dart | 785 } // namespace dart |
| OLD | NEW |