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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 if (kind_ == Snapshot::kFull) { | 433 if (kind_ == Snapshot::kFull) { |
434 obj_.SetCreatedFromSnapshot(); | 434 obj_.SetCreatedFromSnapshot(); |
435 } | 435 } |
436 return obj_.raw(); | 436 return obj_.raw(); |
437 } | 437 } |
438 | 438 |
439 | 439 |
440 CMessageReader::CMessageReader(const uint8_t* buffer, | 440 CMessageReader::CMessageReader(const uint8_t* buffer, |
441 intptr_t length, | 441 intptr_t length, |
442 ReAlloc alloc) | 442 ReAlloc alloc) |
443 : BaseReader(buffer, length), alloc_(alloc) { | 443 : BaseReader(buffer, length), |
444 alloc_(alloc), | |
445 backward_references_(kNumInitialReferences) { | |
444 // Initialize marker objects used to handle Lists. | 446 // Initialize marker objects used to handle Lists. |
445 // TODO(sjesse): Remove this when message serialization format is | 447 // TODO(sjesse): Remove this when message serialization format is |
446 // updated. | 448 // updated. |
447 memset(&type_arguments_marker, 0, sizeof(type_arguments_marker)); | 449 memset(&type_arguments_marker, 0, sizeof(type_arguments_marker)); |
448 memset(&dynamic_type_marker, 0, sizeof(dynamic_type_marker)); | 450 memset(&dynamic_type_marker, 0, sizeof(dynamic_type_marker)); |
449 type_arguments_marker.type = | 451 type_arguments_marker.type = |
450 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kTypeArguments); | 452 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kTypeArguments); |
451 dynamic_type_marker.type = | 453 dynamic_type_marker.type = |
452 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kDynamicType); | 454 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kDynamicType); |
453 } | 455 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 | 543 |
542 ASSERT((class_header & kSmiTagMask) != 0); | 544 ASSERT((class_header & kSmiTagMask) != 0); |
543 class_id = LookupInternalClass(class_header); | 545 class_id = LookupInternalClass(class_header); |
544 switch (class_id) { | 546 switch (class_id) { |
545 case Object::kClassClass: { | 547 case Object::kClassClass: { |
546 return NULL; | 548 return NULL; |
547 } | 549 } |
548 case Object::kTypeArgumentsClass: { | 550 case Object::kTypeArgumentsClass: { |
549 // TODO(sjesse): Remove this when message serialization format is | 551 // TODO(sjesse): Remove this when message serialization format is |
550 // updated (currently length is leaked). | 552 // updated (currently length is leaked). |
553 AddBackwardReference(object_id, NULL); | |
551 Dart_CObject* length = ReadObject(); | 554 Dart_CObject* length = ReadObject(); |
552 ASSERT(length->type == Dart_CObject::kInt32); | 555 ASSERT(length->type == Dart_CObject::kInt32); |
553 for (int i = 0; i < length->value.as_int32; i++) { | 556 for (int i = 0; i < length->value.as_int32; i++) { |
554 Dart_CObject* type = ReadObject(); | 557 Dart_CObject* type = ReadObject(); |
555 if (type != &dynamic_type_marker) return NULL; | 558 if (type != &dynamic_type_marker) return NULL; |
556 } | 559 } |
557 return &type_arguments_marker; | 560 return &type_arguments_marker; |
558 break; | 561 break; |
559 } | 562 } |
560 case ObjectStore::kArrayClass: { | 563 case ObjectStore::kArrayClass: { |
561 intptr_t len = ReadSmiValue(); | 564 intptr_t len = ReadSmiValue(); |
565 Dart_CObject* value = AllocateDartCObjectArray(len); | |
566 AddBackwardReference(object_id, value); | |
562 // Skip type arguments. | 567 // Skip type arguments. |
563 // TODO(sjesse): Remove this when message serialization format is | 568 // TODO(sjesse): Remove this when message serialization format is |
564 // updated (currently type_arguments is leaked). | 569 // updated (currently type_arguments is leaked). |
565 Dart_CObject* type_arguments = ReadObject(); | 570 Dart_CObject* type_arguments = ReadObject(); |
566 if (type_arguments != &type_arguments_marker && | 571 if (type_arguments != &type_arguments_marker && |
567 type_arguments->type != Dart_CObject::kNull) { | 572 type_arguments->type != Dart_CObject::kNull) { |
568 return NULL; | 573 return NULL; |
569 } | 574 } |
570 Dart_CObject* value = AllocateDartCObjectArray(len); | |
571 for (int i = 0; i < len; i++) { | 575 for (int i = 0; i < len; i++) { |
572 value->value.as_array.values[i] = ReadObject(); | 576 value->value.as_array.values[i] = ReadObject(); |
573 } | 577 } |
574 return value; | 578 return value; |
575 break; | 579 break; |
576 } | 580 } |
577 case ObjectStore::kDoubleClass: { | 581 case ObjectStore::kDoubleClass: { |
578 // Read the double value for the object. | 582 // Read the double value for the object. |
579 return AllocateDartCObjectDouble(Read<double>()); | 583 Dart_CObject* object = AllocateDartCObjectDouble(Read<double>()); |
584 AddBackwardReference(object_id, object); | |
585 return object; | |
580 break; | 586 break; |
581 } | 587 } |
582 case ObjectStore::kOneByteStringClass: { | 588 case ObjectStore::kOneByteStringClass: { |
583 intptr_t len = ReadSmiValue(); | 589 intptr_t len = ReadSmiValue(); |
584 intptr_t hash = ReadSmiValue(); | 590 intptr_t hash = ReadSmiValue(); |
585 USE(hash); | 591 USE(hash); |
586 Dart_CObject* value = AllocateDartCObjectString(len); | 592 Dart_CObject* object = AllocateDartCObjectString(len); |
587 char* p = value->value.as_string; | 593 AddBackwardReference(object_id, object); |
594 char* p = object->value.as_string; | |
588 for (intptr_t i = 0; i < len; i++) { | 595 for (intptr_t i = 0; i < len; i++) { |
589 *p = Read<uint8_t>(); | 596 *p = Read<uint8_t>(); |
590 p++; | 597 p++; |
591 } | 598 } |
592 *p = '\0'; | 599 *p = '\0'; |
593 return value; | 600 return object; |
594 break; | 601 break; |
595 } | 602 } |
596 case ObjectStore::kTwoByteStringClass: | 603 case ObjectStore::kTwoByteStringClass: |
597 // Two byte strings not supported. | 604 // Two byte strings not supported. |
598 return NULL; | 605 return NULL; |
599 break; | 606 break; |
600 case ObjectStore::kFourByteStringClass: | 607 case ObjectStore::kFourByteStringClass: |
601 // Four byte strings not supported. | 608 // Four byte strings not supported. |
602 return NULL; | 609 return NULL; |
603 break; | 610 break; |
(...skipping 12 matching lines...) Expand all Loading... | |
616 } else if (object_id == ObjectStore::kFalseValue) { | 623 } else if (object_id == ObjectStore::kFalseValue) { |
617 return AllocateDartCObjectBool(false); | 624 return AllocateDartCObjectBool(false); |
618 } else if (object_id == ObjectStore::kDynamicType || | 625 } else if (object_id == ObjectStore::kDynamicType || |
619 object_id == ObjectStore::kDoubleInterface || | 626 object_id == ObjectStore::kDoubleInterface || |
620 object_id == ObjectStore::kIntInterface || | 627 object_id == ObjectStore::kIntInterface || |
621 object_id == ObjectStore::kBoolInterface || | 628 object_id == ObjectStore::kBoolInterface || |
622 object_id == ObjectStore::kStringInterface) { | 629 object_id == ObjectStore::kStringInterface) { |
623 // Always return dynamic type (this is only a marker). | 630 // Always return dynamic type (this is only a marker). |
624 return &dynamic_type_marker; | 631 return &dynamic_type_marker; |
625 } else { | 632 } else { |
626 // TODO(sgjesse): Handle back-references. | 633 // TODO(sgjesse): Handle back-references. |
siva
2012/02/02 04:01:57
You are handling backward references now, the TODO
Søren Gjesse
2012/02/02 09:59:49
Done.
| |
627 printf("Indexed object %d\n", object_id); | 634 intptr_t index = object_id - kMaxPredefinedObjectIds; |
635 ASSERT(index < backward_references_.length()); | |
636 ASSERT(backward_references_[index] != NULL); | |
637 return backward_references_[index]; | |
628 UNREACHABLE(); | 638 UNREACHABLE(); |
siva
2012/02/02 04:01:57
Is the UNREACHABLE needed?
Søren Gjesse
2012/02/02 09:59:49
No, removed.
| |
629 } | 639 } |
630 return NULL; | 640 return NULL; |
631 } | 641 } |
632 | 642 |
633 | 643 |
634 Dart_CObject* CMessageReader::ReadObjectImpl(intptr_t header) { | 644 Dart_CObject* CMessageReader::ReadObjectImpl(intptr_t header) { |
635 SerializedHeaderType header_type = SerializedHeaderTag::decode(header); | 645 SerializedHeaderType header_type = SerializedHeaderTag::decode(header); |
636 intptr_t header_value = SerializedHeaderData::decode(header); | 646 intptr_t header_value = SerializedHeaderData::decode(header); |
637 | 647 |
638 if (header_type == kObjectId) { | 648 if (header_type == kObjectId) { |
639 return ReadIndexedObject(header_value); | 649 return ReadIndexedObject(header_value); |
640 } | 650 } |
641 ASSERT(header_type == kInlined); | 651 ASSERT(header_type == kInlined); |
642 return ReadInlinedObject(header_value); | 652 return ReadInlinedObject(header_value); |
643 } | 653 } |
644 | 654 |
645 | 655 |
646 Dart_CObject* CMessageReader::ReadObject() { | 656 Dart_CObject* CMessageReader::ReadObject() { |
647 int64_t value = Read<int64_t>(); | 657 int64_t value = Read<int64_t>(); |
648 if ((value & kSmiTagMask) == 0) { | 658 if ((value & kSmiTagMask) == 0) { |
649 Dart_CObject* dart_value = AllocateDartCObjectInt32(value >> kSmiTagShift); | 659 Dart_CObject* dart_value = AllocateDartCObjectInt32(value >> kSmiTagShift); |
650 return dart_value; | 660 return dart_value; |
651 } | 661 } |
652 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); | 662 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); |
653 return ReadObjectImpl(value); | 663 return ReadObjectImpl(value); |
654 } | 664 } |
655 | 665 |
656 | 666 |
667 void CMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) { | |
668 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length()); | |
669 backward_references_.Add(obj); | |
670 } | |
671 | |
672 | |
657 void MessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { | 673 void MessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { |
658 // Write out the serialization header value for this object. | 674 // Write out the serialization header value for this object. |
659 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds); | 675 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds); |
660 | 676 |
661 // Write out the class and tags information. | 677 // Write out the class and tags information. |
662 WriteObjectHeader(ObjectStore::kArrayClass, 0); | 678 WriteObjectHeader(ObjectStore::kArrayClass, 0); |
663 | 679 |
664 // Write out the length field. | 680 // Write out the length field. |
665 Write<RawObject*>(Smi::New(field_count)); | 681 Write<RawObject*>(Smi::New(field_count)); |
666 | 682 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
879 | 895 |
880 | 896 |
881 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { | 897 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { |
882 for (RawObject** current = first; current <= last; current++) { | 898 for (RawObject** current = first; current <= last; current++) { |
883 RawObject* raw_obj = *current; | 899 RawObject* raw_obj = *current; |
884 writer_->WriteObject(raw_obj); | 900 writer_->WriteObject(raw_obj); |
885 } | 901 } |
886 } | 902 } |
887 | 903 |
888 } // namespace dart | 904 } // namespace dart |
OLD | NEW |