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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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), alloc_(alloc) { |
| 444 // Initialize marker objects used to handle Lists. |
| 445 // TODO(sjesse): Remove this when message serialization format is |
| 446 // updated. |
| 447 memset(&type_arguments_marker, 0, sizeof(type_arguments_marker)); |
| 448 memset(&dynamic_type_marker, 0, sizeof(dynamic_type_marker)); |
| 449 type_arguments_marker.type = |
| 450 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kTypeArguments); |
| 451 dynamic_type_marker.type = |
| 452 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kDynamicType); |
444 } | 453 } |
445 | 454 |
446 | 455 |
447 intptr_t CMessageReader::LookupInternalClass(intptr_t class_header) { | 456 intptr_t CMessageReader::LookupInternalClass(intptr_t class_header) { |
448 SerializedHeaderType header_type = SerializedHeaderTag::decode(class_header); | 457 SerializedHeaderType header_type = SerializedHeaderTag::decode(class_header); |
449 ASSERT(header_type == kObjectId); | 458 ASSERT(header_type == kObjectId); |
450 intptr_t header_value = SerializedHeaderData::decode(class_header); | 459 intptr_t header_value = SerializedHeaderData::decode(class_header); |
451 return header_value; | 460 return header_value; |
452 } | 461 } |
453 | 462 |
454 | 463 |
455 Dart_CObject* CMessageReader::AllocateDartValue(Dart_CObject::Type type) { | 464 Dart_CObject* CMessageReader::AllocateDartCObject(Dart_CObject::Type type) { |
456 Dart_CObject* value = | 465 Dart_CObject* value = |
457 reinterpret_cast<Dart_CObject*>( | 466 reinterpret_cast<Dart_CObject*>( |
458 alloc_(NULL, 0, sizeof(Dart_CObject))); | 467 alloc_(NULL, 0, sizeof(Dart_CObject))); |
459 value->type = type; | 468 value->type = type; |
460 return value; | 469 return value; |
461 } | 470 } |
462 | 471 |
463 | 472 |
464 Dart_CObject* CMessageReader::AllocateDartValueNull() { | 473 Dart_CObject* CMessageReader::AllocateDartCObjectNull() { |
465 return AllocateDartValue(Dart_CObject::kNull); | 474 return AllocateDartCObject(Dart_CObject::kNull); |
466 } | 475 } |
467 | 476 |
468 | 477 |
469 Dart_CObject* CMessageReader::AllocateDartValueBool(bool val) { | 478 Dart_CObject* CMessageReader::AllocateDartCObjectBool(bool val) { |
470 Dart_CObject* value = AllocateDartValue(Dart_CObject::kBool); | 479 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kBool); |
471 value->value.as_bool = val; | 480 value->value.as_bool = val; |
472 return value; | 481 return value; |
473 } | 482 } |
474 | 483 |
475 | 484 |
476 Dart_CObject* CMessageReader::AllocateDartValueInt32(int32_t val) { | 485 Dart_CObject* CMessageReader::AllocateDartCObjectInt32(int32_t val) { |
477 Dart_CObject* value = AllocateDartValue(Dart_CObject::kInt32); | 486 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kInt32); |
478 value->value.as_int32 = val; | 487 value->value.as_int32 = val; |
479 return value; | 488 return value; |
480 } | 489 } |
481 | 490 |
482 | 491 |
483 Dart_CObject* CMessageReader::AllocateDartValueDouble(double val) { | 492 Dart_CObject* CMessageReader::AllocateDartCObjectDouble(double val) { |
484 Dart_CObject* value = AllocateDartValue(Dart_CObject::kDouble); | 493 Dart_CObject* value = AllocateDartCObject(Dart_CObject::kDouble); |
485 value->value.as_double = val; | 494 value->value.as_double = val; |
486 return value; | 495 return value; |
487 } | 496 } |
488 | 497 |
489 | 498 |
490 Dart_CObject* CMessageReader::AllocateDartValueString(intptr_t length) { | 499 Dart_CObject* CMessageReader::AllocateDartCObjectString(intptr_t length) { |
491 // Allocate a Dart_CObject structure followed by an array of chars | 500 // Allocate a Dart_CObject structure followed by an array of chars |
492 // for the string content. The pointer to the string content is set | 501 // for the string content. The pointer to the string content is set |
493 // up to this area. | 502 // up to this area. |
494 Dart_CObject* value = | 503 Dart_CObject* value = |
495 reinterpret_cast<Dart_CObject*>( | 504 reinterpret_cast<Dart_CObject*>( |
496 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); | 505 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); |
497 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value); | 506 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value); |
498 value->type = Dart_CObject::kString; | 507 value->type = Dart_CObject::kString; |
499 return value; | 508 return value; |
500 } | 509 } |
501 | 510 |
502 | 511 |
503 Dart_CObject* CMessageReader::AllocateDartValueArray(intptr_t length) { | 512 Dart_CObject* CMessageReader::AllocateDartCObjectArray(intptr_t length) { |
504 // Allocate a Dart_CObject structure followed by an array of | 513 // Allocate a Dart_CObject structure followed by an array of |
505 // pointers to Dart_CObject structures. The pointer to the array | 514 // pointers to Dart_CObject structures. The pointer to the array |
506 // content is set up to this area. | 515 // content is set up to this area. |
507 Dart_CObject* value = | 516 Dart_CObject* value = |
508 reinterpret_cast<Dart_CObject*>( | 517 reinterpret_cast<Dart_CObject*>( |
509 alloc_(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value))); | 518 alloc_(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value))); |
510 value->type = Dart_CObject::kArray; | 519 value->type = Dart_CObject::kArray; |
511 value->value.as_array.length = length; | 520 value->value.as_array.length = length; |
512 if (length > 0) { | 521 if (length > 0) { |
513 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); | 522 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); |
(...skipping 15 matching lines...) Expand all Loading... |
529 if (SerializedHeaderData::decode(class_header) == kInstanceId) { | 538 if (SerializedHeaderData::decode(class_header) == kInstanceId) { |
530 return NULL; | 539 return NULL; |
531 } | 540 } |
532 | 541 |
533 ASSERT((class_header & kSmiTagMask) != 0); | 542 ASSERT((class_header & kSmiTagMask) != 0); |
534 class_id = LookupInternalClass(class_header); | 543 class_id = LookupInternalClass(class_header); |
535 switch (class_id) { | 544 switch (class_id) { |
536 case Object::kClassClass: { | 545 case Object::kClassClass: { |
537 return NULL; | 546 return NULL; |
538 } | 547 } |
| 548 case Object::kTypeArgumentsClass: { |
| 549 // TODO(sjesse): Remove this when message serialization format is |
| 550 // updated (currently length is leaked). |
| 551 Dart_CObject* length = ReadObject(); |
| 552 ASSERT(length->type == Dart_CObject::kInt32); |
| 553 for (int i = 0; i < length->value.as_int32; i++) { |
| 554 Dart_CObject* type = ReadObject(); |
| 555 if (type != &dynamic_type_marker) return NULL; |
| 556 } |
| 557 return &type_arguments_marker; |
| 558 break; |
| 559 } |
539 case ObjectStore::kArrayClass: { | 560 case ObjectStore::kArrayClass: { |
540 intptr_t len = ReadSmiValue(); | 561 intptr_t len = ReadSmiValue(); |
541 // Skip type arguments. | 562 // Skip type arguments. |
| 563 // TODO(sjesse): Remove this when message serialization format is |
| 564 // updated (currently type_arguments is leaked). |
542 Dart_CObject* type_arguments = ReadObject(); | 565 Dart_CObject* type_arguments = ReadObject(); |
543 if (type_arguments == NULL || | 566 if (type_arguments != &type_arguments_marker && |
544 type_arguments->type != Dart_CObject::kNull) { | 567 type_arguments->type != Dart_CObject::kNull) { |
545 return NULL; | 568 return NULL; |
546 } | 569 } |
547 Dart_CObject* value = AllocateDartValueArray(len); | 570 Dart_CObject* value = AllocateDartCObjectArray(len); |
548 for (int i = 0; i < len; i++) { | 571 for (int i = 0; i < len; i++) { |
549 value->value.as_array.values[i] = ReadObject(); | 572 value->value.as_array.values[i] = ReadObject(); |
550 } | 573 } |
551 return value; | 574 return value; |
552 break; | 575 break; |
553 } | 576 } |
554 case ObjectStore::kDoubleClass: { | 577 case ObjectStore::kDoubleClass: { |
555 // Read the double value for the object. | 578 // Read the double value for the object. |
556 return AllocateDartValueDouble(Read<double>()); | 579 return AllocateDartCObjectDouble(Read<double>()); |
557 break; | 580 break; |
558 } | 581 } |
559 case ObjectStore::kOneByteStringClass: { | 582 case ObjectStore::kOneByteStringClass: { |
560 intptr_t len = ReadSmiValue(); | 583 intptr_t len = ReadSmiValue(); |
561 intptr_t hash = ReadSmiValue(); | 584 intptr_t hash = ReadSmiValue(); |
562 USE(hash); | 585 USE(hash); |
563 Dart_CObject* value = AllocateDartValueString(len); | 586 Dart_CObject* value = AllocateDartCObjectString(len); |
564 char* p = value->value.as_string; | 587 char* p = value->value.as_string; |
565 for (intptr_t i = 0; i < len; i++) { | 588 for (intptr_t i = 0; i < len; i++) { |
566 *p = Read<uint8_t>(); | 589 *p = Read<uint8_t>(); |
567 p++; | 590 p++; |
568 } | 591 } |
569 *p = '\0'; | 592 *p = '\0'; |
570 return value; | 593 return value; |
571 break; | 594 break; |
572 } | 595 } |
573 case ObjectStore::kTwoByteStringClass: | 596 case ObjectStore::kTwoByteStringClass: |
574 // Two byte strings not supported. | 597 // Two byte strings not supported. |
575 return NULL; | 598 return NULL; |
576 break; | 599 break; |
577 case ObjectStore::kFourByteStringClass: | 600 case ObjectStore::kFourByteStringClass: |
578 // Four byte strings not supported. | 601 // Four byte strings not supported. |
579 return NULL; | 602 return NULL; |
580 break; | 603 break; |
581 default: | 604 default: |
582 // Everything else not supported. | 605 // Everything else not supported. |
583 return NULL; | 606 return NULL; |
584 } | 607 } |
585 } | 608 } |
586 | 609 |
587 | 610 |
588 Dart_CObject* CMessageReader::ReadIndexedObject(intptr_t object_id) { | 611 Dart_CObject* CMessageReader::ReadIndexedObject(intptr_t object_id) { |
589 if (object_id == Object::kNullObject) { | 612 if (object_id == Object::kNullObject) { |
590 return AllocateDartValueNull(); | 613 return AllocateDartCObjectNull(); |
591 } else if (object_id == ObjectStore::kTrueValue) { | 614 } else if (object_id == ObjectStore::kTrueValue) { |
592 return AllocateDartValueBool(true); | 615 return AllocateDartCObjectBool(true); |
593 } else if (object_id == ObjectStore::kFalseValue) { | 616 } else if (object_id == ObjectStore::kFalseValue) { |
594 return AllocateDartValueBool(false); | 617 return AllocateDartCObjectBool(false); |
| 618 } else if (object_id == ObjectStore::kDynamicType || |
| 619 object_id == ObjectStore::kDoubleInterface || |
| 620 object_id == ObjectStore::kIntInterface || |
| 621 object_id == ObjectStore::kBoolInterface || |
| 622 object_id == ObjectStore::kStringInterface) { |
| 623 // Always return dynamic type (this is only a marker). |
| 624 return &dynamic_type_marker; |
595 } else { | 625 } else { |
596 // TODO(sgjesse): Handle back-references. | 626 // TODO(sgjesse): Handle back-references. |
| 627 printf("Indexed object %d\n", object_id); |
597 UNREACHABLE(); | 628 UNREACHABLE(); |
598 } | 629 } |
599 return NULL; | 630 return NULL; |
600 } | 631 } |
601 | 632 |
602 | 633 |
603 Dart_CObject* CMessageReader::ReadObjectImpl(intptr_t header) { | 634 Dart_CObject* CMessageReader::ReadObjectImpl(intptr_t header) { |
604 SerializedHeaderType header_type = SerializedHeaderTag::decode(header); | 635 SerializedHeaderType header_type = SerializedHeaderTag::decode(header); |
605 intptr_t header_value = SerializedHeaderData::decode(header); | 636 intptr_t header_value = SerializedHeaderData::decode(header); |
606 | 637 |
607 if (header_type == kObjectId) { | 638 if (header_type == kObjectId) { |
608 return ReadIndexedObject(header_value); | 639 return ReadIndexedObject(header_value); |
609 } | 640 } |
610 ASSERT(header_type == kInlined); | 641 ASSERT(header_type == kInlined); |
611 return ReadInlinedObject(header_value); | 642 return ReadInlinedObject(header_value); |
612 } | 643 } |
613 | 644 |
614 | 645 |
615 Dart_CObject* CMessageReader::ReadObject() { | 646 Dart_CObject* CMessageReader::ReadObject() { |
616 int64_t value = Read<int64_t>(); | 647 int64_t value = Read<int64_t>(); |
617 if ((value & kSmiTagMask) == 0) { | 648 if ((value & kSmiTagMask) == 0) { |
618 Dart_CObject* dart_value = AllocateDartValueInt32(value >> kSmiTagShift); | 649 Dart_CObject* dart_value = AllocateDartCObjectInt32(value >> kSmiTagShift); |
619 return dart_value; | 650 return dart_value; |
620 } | 651 } |
621 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); | 652 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); |
622 return ReadObjectImpl(value); | 653 return ReadObjectImpl(value); |
623 } | 654 } |
624 | 655 |
625 | 656 |
626 void MessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { | 657 void MessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { |
627 // Write out the serialization header value for this object. | 658 // Write out the serialization header value for this object. |
628 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds); | 659 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 | 879 |
849 | 880 |
850 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { | 881 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { |
851 for (RawObject** current = first; current <= last; current++) { | 882 for (RawObject** current = first; current <= last; current++) { |
852 RawObject* raw_obj = *current; | 883 RawObject* raw_obj = *current; |
853 writer_->WriteObject(raw_obj); | 884 writer_->WriteObject(raw_obj); |
854 } | 885 } |
855 } | 886 } |
856 | 887 |
857 } // namespace dart | 888 } // namespace dart |
OLD | NEW |