Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: vm/dart_api_message.cc

Issue 10834069: Do not try to serialize VM objects, these are read only canonical objects and should be referred to… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/object_store.h" 7 #include "vm/object_store.h"
8 #include "vm/symbols.h"
8 9
9 namespace dart { 10 namespace dart {
10 11
11 // TODO(sgjesse): When the external message format is done these 12 // TODO(sgjesse): When the external message format is done these
12 // duplicate constants from snapshot.cc should be removed. 13 // duplicate constants from snapshot.cc should be removed.
13 enum { 14 enum {
14 kInstanceId = ObjectStore::kMaxId, 15 kInstanceId = ObjectStore::kMaxId,
15 kMaxPredefinedObjectIds, 16 kMaxPredefinedObjectIds,
16 }; 17 };
17 static const int kNumInitialReferences = 4; 18 static const int kNumInitialReferences = 4;
(...skipping 21 matching lines...) Expand all
39 } 40 }
40 41
41 42
42 Dart_CObject* ApiMessageReader::ReadMessage() { 43 Dart_CObject* ApiMessageReader::ReadMessage() {
43 // Read the object out of the message. 44 // Read the object out of the message.
44 return ReadObject(); 45 return ReadObject();
45 } 46 }
46 47
47 48
48 intptr_t ApiMessageReader::LookupInternalClass(intptr_t class_header) { 49 intptr_t ApiMessageReader::LookupInternalClass(intptr_t class_header) {
49 SerializedHeaderType header_type = SerializedHeaderTag::decode(class_header); 50 if (IsVMIsolateObject(class_header)) {
50 ASSERT(header_type == kObjectId); 51 return GetVMIsolateObjectId(class_header);
51 intptr_t header_value = SerializedHeaderData::decode(class_header); 52 }
52 return header_value; 53 ASSERT(SerializedHeaderTag::decode(class_header) == kObjectId);
54 return SerializedHeaderData::decode(class_header);
53 } 55 }
54 56
55 57
56 Dart_CObject* ApiMessageReader::AllocateDartCObject(Dart_CObject::Type type) { 58 Dart_CObject* ApiMessageReader::AllocateDartCObject(Dart_CObject::Type type) {
57 Dart_CObject* value = 59 Dart_CObject* value =
58 reinterpret_cast<Dart_CObject*>(alloc_(NULL, 0, sizeof(Dart_CObject))); 60 reinterpret_cast<Dart_CObject*>(alloc_(NULL, 0, sizeof(Dart_CObject)));
59 ASSERT(value != NULL); 61 ASSERT(value != NULL);
60 value->type = type; 62 value->type = type;
61 return value; 63 return value;
62 } 64 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 for (int i = 0; i < len; i++) { 212 for (int i = 0; i < len; i++) {
211 value->value.as_array.values[i] = ReadObjectRef(); 213 value->value.as_array.values[i] = ReadObjectRef();
212 } 214 }
213 return value; 215 return value;
214 } 216 }
215 217
216 return ReadInternalVMObject(class_id, object_id); 218 return ReadInternalVMObject(class_id, object_id);
217 } 219 }
218 220
219 221
222 Dart_CObject* ApiMessageReader::ReadVMSymbol(intptr_t object_id) {
223 RawOneByteString* str =
224 reinterpret_cast<RawOneByteString*>(Symbols::GetVMSymbol(object_id));
225 if (str == OneByteString::null()) {
Ivan Posva 2012/08/03 00:26:50 It would be nice if we did not have to rely on the
siva 2012/08/06 21:20:56 Added a Symbols::IsVMSymbolId method which is chec
226 return AllocateDartCObjectNull();
227 }
228 intptr_t len = Smi::Value(str->ptr()->length_);
Ivan Posva 2012/08/03 00:26:50 No GC scope because we are touching ptr()->data_?
siva 2012/08/06 21:20:56 Can't do a No GC Scope here as there is no isolate
229 Dart_CObject* object = AllocateDartCObjectString(len);
230 char* p = object->value.as_string;
231 memmove(p, str->ptr()->data_, len);
232 p[len] = '\0';
233 return object;
234 }
235
236
220 Dart_CObject* ApiMessageReader::ReadObjectRef() { 237 Dart_CObject* ApiMessageReader::ReadObjectRef() {
221 int64_t value = Read<int64_t>(); 238 int64_t value = Read<int64_t>();
222 if ((value & kSmiTagMask) == 0) { 239 if ((value & kSmiTagMask) == 0) {
223 int64_t untagged_value = value >> kSmiTagShift; 240 int64_t untagged_value = value >> kSmiTagShift;
224 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) { 241 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) {
225 return AllocateDartCObjectInt32(untagged_value); 242 return AllocateDartCObjectInt32(untagged_value);
226 } else { 243 } else {
227 return AllocateDartCObjectInt64(untagged_value); 244 return AllocateDartCObjectInt64(untagged_value);
228 } 245 }
229 } 246 }
230 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); 247 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin));
231 SerializedHeaderType header_type = SerializedHeaderTag::decode(value); 248 if (IsVMIsolateObject(value)) {
232 intptr_t header_value = SerializedHeaderData::decode(value); 249 intptr_t object_id = GetVMIsolateObjectId(value);
233 250 if (object_id == Object::kNullObject) {
234 if (header_type == kObjectId) { 251 return AllocateDartCObjectNull();
235 return ReadIndexedObject(header_value); 252 }
253 return ReadVMSymbol(object_id);
236 } 254 }
237 ASSERT(header_type == kInlined); 255 if (SerializedHeaderTag::decode(value) == kObjectId) {
256 return ReadIndexedObject(SerializedHeaderData::decode(value));
257 }
258 ASSERT(SerializedHeaderTag::decode(value) == kInlined);
238 // Read the class header information and lookup the class. 259 // Read the class header information and lookup the class.
239 intptr_t class_header = ReadIntptrValue(); 260 intptr_t class_header = ReadIntptrValue();
240 261
241 // Reading of regular dart instances is not supported. 262 // Reading of regular dart instances is not supported.
242 if (SerializedHeaderData::decode(class_header) == kInstanceId) { 263 if (SerializedHeaderData::decode(class_header) == kInstanceId) {
243 return AllocateDartCObjectUnsupported(); 264 return AllocateDartCObjectUnsupported();
244 } 265 }
245 ASSERT((class_header & kSmiTagMask) != 0); 266 ASSERT((class_header & kSmiTagMask) != 0);
246 intptr_t object_id = header_value; 267 intptr_t object_id = SerializedHeaderData::decode(value);
247 intptr_t class_id = LookupInternalClass(class_header); 268 intptr_t class_id = LookupInternalClass(class_header);
248 if (class_id == ObjectStore::kArrayClass || 269 if (class_id == ObjectStore::kArrayClass ||
249 class_id == ObjectStore::kImmutableArrayClass) { 270 class_id == ObjectStore::kImmutableArrayClass) {
250 ASSERT(GetBackRef(object_id) == NULL); 271 ASSERT(GetBackRef(object_id) == NULL);
251 intptr_t len = ReadSmiValue(); 272 intptr_t len = ReadSmiValue();
252 Dart_CObject* value = AllocateDartCObjectArray(len); 273 Dart_CObject* value = AllocateDartCObjectArray(len);
253 AddBackRef(object_id, value, kIsNotDeserialized); 274 AddBackRef(object_id, value, kIsNotDeserialized);
254 return value; 275 return value;
255 } 276 }
256 intptr_t tags = ReadIntptrValue(); 277 intptr_t tags = ReadIntptrValue();
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 return object; 380 return object;
360 } 381 }
361 default: 382 default:
362 // Everything else not supported. 383 // Everything else not supported.
363 return AllocateDartCObjectUnsupported(); 384 return AllocateDartCObjectUnsupported();
364 } 385 }
365 } 386 }
366 387
367 388
368 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { 389 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) {
369 if (object_id == Object::kNullObject) {
370 return AllocateDartCObjectNull();
371 }
372 if (object_id == ObjectStore::kTrueValue) { 390 if (object_id == ObjectStore::kTrueValue) {
373 return AllocateDartCObjectBool(true); 391 return AllocateDartCObjectBool(true);
374 } 392 }
375 if (object_id == ObjectStore::kFalseValue) { 393 if (object_id == ObjectStore::kFalseValue) {
376 return AllocateDartCObjectBool(false); 394 return AllocateDartCObjectBool(false);
377 } 395 }
378 if (object_id == ObjectStore::kDynamicType || 396 if (object_id == ObjectStore::kDynamicType ||
379 object_id == ObjectStore::kDoubleInterface || 397 object_id == ObjectStore::kDoubleInterface ||
380 object_id == ObjectStore::kIntInterface || 398 object_id == ObjectStore::kIntInterface ||
381 object_id == ObjectStore::kBoolInterface || 399 object_id == ObjectStore::kBoolInterface ||
(...skipping 24 matching lines...) Expand all
406 int64_t value = Read<int64_t>(); 424 int64_t value = Read<int64_t>();
407 if ((value & kSmiTagMask) == 0) { 425 if ((value & kSmiTagMask) == 0) {
408 int64_t untagged_value = value >> kSmiTagShift; 426 int64_t untagged_value = value >> kSmiTagShift;
409 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) { 427 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) {
410 return AllocateDartCObjectInt32(untagged_value); 428 return AllocateDartCObjectInt32(untagged_value);
411 } else { 429 } else {
412 return AllocateDartCObjectInt64(untagged_value); 430 return AllocateDartCObjectInt64(untagged_value);
413 } 431 }
414 } 432 }
415 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); 433 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin));
416 SerializedHeaderType header_type = SerializedHeaderTag::decode(value); 434 if (IsVMIsolateObject(value)) {
417 intptr_t header_value = SerializedHeaderData::decode(value); 435 intptr_t object_id = GetVMIsolateObjectId(value);
418 436 if (object_id == Object::kNullObject) {
419 if (header_type == kObjectId) { 437 return AllocateDartCObjectNull();
420 return ReadIndexedObject(header_value); 438 }
439 return ReadVMSymbol(object_id);
421 } 440 }
422 ASSERT(header_type == kInlined); 441 if (SerializedHeaderTag::decode(value) == kObjectId) {
423 return ReadInlinedObject(header_value); 442 return ReadIndexedObject(SerializedHeaderData::decode(value));
443 }
444 ASSERT(SerializedHeaderTag::decode(value) == kInlined);
445 return ReadInlinedObject(SerializedHeaderData::decode(value));
424 } 446 }
425 447
426 448
427 void ApiMessageReader::AddBackRef(intptr_t id, 449 void ApiMessageReader::AddBackRef(intptr_t id,
428 Dart_CObject* obj, 450 Dart_CObject* obj,
429 DeserializeState state) { 451 DeserializeState state) {
430 intptr_t index = (id - kMaxPredefinedObjectIds); 452 intptr_t index = (id - kMaxPredefinedObjectIds);
431 ASSERT(index == backward_references_.length()); 453 ASSERT(index == backward_references_.length());
432 BackRefNode* node = AllocateBackRefNode(obj, state); 454 BackRefNode* node = AllocateBackRefNode(obj, state);
433 ASSERT(node != NULL); 455 ASSERT(node != NULL);
434 backward_references_.Add(node); 456 backward_references_.Add(node);
435 } 457 }
436 458
437 459
438 Dart_CObject* ApiMessageReader::GetBackRef(intptr_t id) { 460 Dart_CObject* ApiMessageReader::GetBackRef(intptr_t id) {
439 ASSERT(id >= kMaxPredefinedObjectIds); 461 ASSERT(id >= kMaxPredefinedObjectIds);
440 intptr_t index = (id - kMaxPredefinedObjectIds); 462 intptr_t index = (id - kMaxPredefinedObjectIds);
441 if (index < backward_references_.length()) { 463 if (index < backward_references_.length()) {
442 return backward_references_[index]->reference(); 464 return backward_references_[index]->reference();
443 } 465 }
444 return NULL; 466 return NULL;
445 } 467 }
446 468
447 469
448 void ApiMessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) { 470 void ApiMessageWriter::WriteMessage(intptr_t field_count, intptr_t *data) {
449 // Write out the serialization header value for this object. 471 // Write out the serialization header value for this object.
450 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds); 472 WriteInlinedObjectHeader(kMaxPredefinedObjectIds);
451 473
452 // Write out the class and tags information. 474 // Write out the class and tags information.
453 WriteObjectHeader(ObjectStore::kArrayClass, 0); 475 WriteIndexedObject(ObjectStore::kArrayClass);
476 WriteIntptrValue(0);
454 477
455 // Write out the length field. 478 // Write out the length field.
456 Write<RawObject*>(Smi::New(field_count)); 479 Write<RawObject*>(Smi::New(field_count));
457 480
458 // Write out the type arguments. 481 // Write out the type arguments.
459 WriteIndexedObject(Object::kNullObject); 482 WriteNullObject();
460 483
461 // Write out the individual Smis. 484 // Write out the individual Smis.
462 for (int i = 0; i < field_count; i++) { 485 for (int i = 0; i < field_count; i++) {
463 Write<RawObject*>(Integer::New(data[i])); 486 Write<RawObject*>(Integer::New(data[i]));
464 } 487 }
465 488
466 FinalizeBuffer(); 489 FinalizeBuffer();
467 } 490 }
468 491
469 492
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 forward_id_ += 1; 551 forward_id_ += 1;
529 } 552 }
530 553
531 554
532 void ApiMessageWriter::WriteSmi(int64_t value) { 555 void ApiMessageWriter::WriteSmi(int64_t value) {
533 ASSERT(Smi::IsValid64(value)); 556 ASSERT(Smi::IsValid64(value));
534 Write<RawObject*>(Smi::New(value)); 557 Write<RawObject*>(Smi::New(value));
535 } 558 }
536 559
537 560
561 void ApiMessageWriter::WriteNullObject() {
562 WriteVMIsolateObject(Object::kNullObject);
563 }
564
565
538 void ApiMessageWriter::WriteMint(Dart_CObject* object, int64_t value) { 566 void ApiMessageWriter::WriteMint(Dart_CObject* object, int64_t value) {
539 ASSERT(!Smi::IsValid64(value)); 567 ASSERT(!Smi::IsValid64(value));
540 // Write out the serialization header value for mint object. 568 // Write out the serialization header value for mint object.
541 WriteInlinedHeader(object); 569 WriteInlinedHeader(object);
542 // Write out the class and tags information. 570 // Write out the class and tags information.
543 WriteObjectHeader(ObjectStore::kMintClass, 0); 571 WriteIndexedObject(ObjectStore::kMintClass);
572 WriteIntptrValue(0);
544 // Write the 64-bit value. 573 // Write the 64-bit value.
545 Write<int64_t>(value); 574 Write<int64_t>(value);
546 } 575 }
547 576
548 577
549 void ApiMessageWriter::WriteInt32(Dart_CObject* object) { 578 void ApiMessageWriter::WriteInt32(Dart_CObject* object) {
550 int64_t value = object->value.as_int32; 579 int64_t value = object->value.as_int32;
551 if (Smi::IsValid64(value)) { 580 if (Smi::IsValid64(value)) {
552 WriteSmi(value); 581 WriteSmi(value);
553 } else { 582 } else {
554 WriteMint(object, value); 583 WriteMint(object, value);
555 } 584 }
556 } 585 }
557 586
558 587
559 void ApiMessageWriter::WriteInt64(Dart_CObject* object) { 588 void ApiMessageWriter::WriteInt64(Dart_CObject* object) {
560 int64_t value = object->value.as_int64; 589 int64_t value = object->value.as_int64;
561 if (Smi::IsValid64(value)) { 590 if (Smi::IsValid64(value)) {
562 WriteSmi(value); 591 WriteSmi(value);
563 } else { 592 } else {
564 WriteMint(object, value); 593 WriteMint(object, value);
565 } 594 }
566 } 595 }
567 596
568 597
569 void ApiMessageWriter::WriteInlinedHeader(Dart_CObject* object) { 598 void ApiMessageWriter::WriteInlinedHeader(Dart_CObject* object) {
570 // Write out the serialization header value for this object. 599 // Write out the serialization header value for this object.
571 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds + object_id_); 600 WriteInlinedObjectHeader(kMaxPredefinedObjectIds + object_id_);
572 // Mark object with its object id. 601 // Mark object with its object id.
573 MarkCObject(object, object_id_); 602 MarkCObject(object, object_id_);
574 // Advance object id. 603 // Advance object id.
575 object_id_++; 604 object_id_++;
576 } 605 }
577 606
578 607
579 void ApiMessageWriter::WriteCObject(Dart_CObject* object) { 608 void ApiMessageWriter::WriteCObject(Dart_CObject* object) {
580 if (IsCObjectMarked(object)) { 609 if (IsCObjectMarked(object)) {
581 intptr_t object_id = GetMarkedCObjectMark(object); 610 intptr_t object_id = GetMarkedCObjectMark(object);
582 WriteIndexedObject(kMaxPredefinedObjectIds + object_id); 611 WriteIndexedObject(kMaxPredefinedObjectIds + object_id);
583 return; 612 return;
584 } 613 }
585 614
586 Dart_CObject::Type type = object->type; 615 Dart_CObject::Type type = object->type;
587 if (type == Dart_CObject::kArray) { 616 if (type == Dart_CObject::kArray) {
588 // Write out the serialization header value for this object. 617 // Write out the serialization header value for this object.
589 WriteInlinedHeader(object); 618 WriteInlinedHeader(object);
590 // Write out the class and tags information. 619 // Write out the class and tags information.
591 WriteObjectHeader(ObjectStore::kArrayClass, 0); 620 WriteIndexedObject(ObjectStore::kArrayClass);
621 WriteIntptrValue(0);
622
592 WriteSmi(object->value.as_array.length); 623 WriteSmi(object->value.as_array.length);
593 // Write out the type arguments. 624 // Write out the type arguments.
594 WriteIndexedObject(Object::kNullObject); 625 WriteNullObject();
595 // Write out array elements. 626 // Write out array elements.
596 for (int i = 0; i < object->value.as_array.length; i++) { 627 for (int i = 0; i < object->value.as_array.length; i++) {
597 WriteCObjectRef(object->value.as_array.values[i]); 628 WriteCObjectRef(object->value.as_array.values[i]);
598 } 629 }
599 return; 630 return;
600 } 631 }
601 return WriteCObjectInlined(object, type); 632 return WriteCObjectInlined(object, type);
602 } 633 }
603 634
604 635
(...skipping 21 matching lines...) Expand all
626 657
627 658
628 void ApiMessageWriter::WriteForwardedCObject(Dart_CObject* object) { 659 void ApiMessageWriter::WriteForwardedCObject(Dart_CObject* object) {
629 ASSERT(IsCObjectMarked(object)); 660 ASSERT(IsCObjectMarked(object));
630 Dart_CObject::Type type = 661 Dart_CObject::Type type =
631 static_cast<Dart_CObject::Type>(object->type & kDartCObjectTypeMask); 662 static_cast<Dart_CObject::Type>(object->type & kDartCObjectTypeMask);
632 ASSERT(type == Dart_CObject::kArray); 663 ASSERT(type == Dart_CObject::kArray);
633 664
634 // Write out the serialization header value for this object. 665 // Write out the serialization header value for this object.
635 intptr_t object_id = GetMarkedCObjectMark(object); 666 intptr_t object_id = GetMarkedCObjectMark(object);
636 WriteSerializationMarker(kInlined, kMaxPredefinedObjectIds + object_id); 667 WriteInlinedObjectHeader(kMaxPredefinedObjectIds + object_id);
637 // Write out the class and tags information. 668 // Write out the class and tags information.
638 WriteObjectHeader(ObjectStore::kArrayClass, 0); 669 WriteIndexedObject(ObjectStore::kArrayClass);
670 WriteIntptrValue(0);
671
639 WriteSmi(object->value.as_array.length); 672 WriteSmi(object->value.as_array.length);
640 // Write out the type arguments. 673 // Write out the type arguments.
641 WriteIndexedObject(Object::kNullObject); 674 WriteNullObject();
642 // Write out array elements. 675 // Write out array elements.
643 for (int i = 0; i < object->value.as_array.length; i++) { 676 for (int i = 0; i < object->value.as_array.length; i++) {
644 WriteCObjectRef(object->value.as_array.values[i]); 677 WriteCObjectRef(object->value.as_array.values[i]);
645 } 678 }
646 } 679 }
647 680
648 681
649 void ApiMessageWriter::WriteCObjectInlined(Dart_CObject* object, 682 void ApiMessageWriter::WriteCObjectInlined(Dart_CObject* object,
650 Dart_CObject::Type type) { 683 Dart_CObject::Type type) {
651 switch (type) { 684 switch (type) {
652 case Dart_CObject::kNull: 685 case Dart_CObject::kNull:
653 WriteIndexedObject(Object::kNullObject); 686 WriteNullObject();
654 break; 687 break;
655 case Dart_CObject::kBool: 688 case Dart_CObject::kBool:
656 if (object->value.as_bool) { 689 if (object->value.as_bool) {
657 WriteIndexedObject(ObjectStore::kTrueValue); 690 WriteIndexedObject(ObjectStore::kTrueValue);
658 } else { 691 } else {
659 WriteIndexedObject(ObjectStore::kFalseValue); 692 WriteIndexedObject(ObjectStore::kFalseValue);
660 } 693 }
661 break; 694 break;
662 case Dart_CObject::kInt32: 695 case Dart_CObject::kInt32:
663 WriteInt32(object); 696 WriteInt32(object);
664 break; 697 break;
665 case Dart_CObject::kInt64: 698 case Dart_CObject::kInt64:
666 WriteInt64(object); 699 WriteInt64(object);
667 break; 700 break;
668 case Dart_CObject::kBigint: { 701 case Dart_CObject::kBigint: {
669 // Write out the serialization header value for this object. 702 // Write out the serialization header value for this object.
670 WriteInlinedHeader(object); 703 WriteInlinedHeader(object);
671 // Write out the class and tags information. 704 // Write out the class and tags information.
672 WriteObjectHeader(ObjectStore::kBigintClass, 0); 705 WriteIndexedObject(ObjectStore::kBigintClass);
706 WriteIntptrValue(0);
673 // Write hex string length and content 707 // Write hex string length and content
674 char* hex_string = object->value.as_bigint; 708 char* hex_string = object->value.as_bigint;
675 intptr_t len = strlen(hex_string); 709 intptr_t len = strlen(hex_string);
676 WriteIntptrValue(len); 710 WriteIntptrValue(len);
677 for (intptr_t i = 0; i < len; i++) { 711 for (intptr_t i = 0; i < len; i++) {
678 Write<uint8_t>(hex_string[i]); 712 Write<uint8_t>(hex_string[i]);
679 } 713 }
680 break; 714 break;
681 } 715 }
682 case Dart_CObject::kDouble: 716 case Dart_CObject::kDouble:
683 // Write out the serialization header value for this object. 717 // Write out the serialization header value for this object.
684 WriteInlinedHeader(object); 718 WriteInlinedHeader(object);
685 // Write out the class and tags information. 719 // Write out the class and tags information.
686 WriteObjectHeader(ObjectStore::kDoubleClass, 0); 720 WriteIndexedObject(ObjectStore::kDoubleClass);
721 WriteIntptrValue(0);
687 // Write double value. 722 // Write double value.
688 Write<double>(object->value.as_double); 723 Write<double>(object->value.as_double);
689 break; 724 break;
690 case Dart_CObject::kString: { 725 case Dart_CObject::kString: {
691 // Write out the serialization header value for this object. 726 // Write out the serialization header value for this object.
692 WriteInlinedHeader(object); 727 WriteInlinedHeader(object);
693 // Write out the class and tags information. 728 // Write out the class and tags information.
694 WriteObjectHeader(ObjectStore::kOneByteStringClass, 0); 729 WriteIndexedObject(ObjectStore::kOneByteStringClass);
730 WriteIntptrValue(0);
695 // Write string length, hash and content 731 // Write string length, hash and content
696 char* str = object->value.as_string; 732 char* str = object->value.as_string;
697 intptr_t len = strlen(str); 733 intptr_t len = strlen(str);
698 WriteSmi(len); 734 WriteSmi(len);
699 WriteSmi(0); // TODO(sgjesse): Hash - not written. 735 WriteSmi(0); // TODO(sgjesse): Hash - not written.
700 for (intptr_t i = 0; i < len; i++) { 736 for (intptr_t i = 0; i < len; i++) {
701 Write<uint8_t>(str[i]); 737 Write<uint8_t>(str[i]);
702 } 738 }
703 break; 739 break;
704 } 740 }
705 case Dart_CObject::kUint8Array: { 741 case Dart_CObject::kUint8Array: {
706 // Write out the serialization header value for this object. 742 // Write out the serialization header value for this object.
707 WriteInlinedHeader(object); 743 WriteInlinedHeader(object);
708 // Write out the class and tags information. 744 // Write out the class and tags information.
709 WriteObjectHeader(ObjectStore::kUint8ArrayClass, 0); 745 WriteIndexedObject(ObjectStore::kUint8ArrayClass);
746 WriteIntptrValue(0);
710 uint8_t* bytes = object->value.as_byte_array.values; 747 uint8_t* bytes = object->value.as_byte_array.values;
711 intptr_t len = object->value.as_byte_array.length; 748 intptr_t len = object->value.as_byte_array.length;
712 WriteSmi(len); 749 WriteSmi(len);
713 for (intptr_t i = 0; i < len; i++) { 750 for (intptr_t i = 0; i < len; i++) {
714 Write<uint8_t>(bytes[i]); 751 Write<uint8_t>(bytes[i]);
715 } 752 }
716 break; 753 break;
717 } 754 }
718 case Dart_CObject::kExternalUint8Array: { 755 case Dart_CObject::kExternalUint8Array: {
719 // TODO(ager): we are writing C pointers into the message in 756 // TODO(ager): we are writing C pointers into the message in
720 // order to post external arrays through ports. We need to make 757 // order to post external arrays through ports. We need to make
721 // sure that messages containing pointers can never be posted 758 // sure that messages containing pointers can never be posted
722 // to other processes. 759 // to other processes.
723 760
724 // Write out serialization header value for this object. 761 // Write out serialization header value for this object.
725 WriteInlinedHeader(object); 762 WriteInlinedHeader(object);
726 // Write out the class and tag information. 763 // Write out the class and tag information.
727 WriteObjectHeader(ObjectStore::kExternalUint8ArrayClass, 0); 764 WriteIndexedObject(ObjectStore::kExternalUint8ArrayClass);
765 WriteIntptrValue(0);
728 int length = object->value.as_external_byte_array.length; 766 int length = object->value.as_external_byte_array.length;
729 uint8_t* data = object->value.as_external_byte_array.data; 767 uint8_t* data = object->value.as_external_byte_array.data;
730 void* peer = object->value.as_external_byte_array.peer; 768 void* peer = object->value.as_external_byte_array.peer;
731 Dart_PeerFinalizer callback = 769 Dart_PeerFinalizer callback =
732 object->value.as_external_byte_array.callback; 770 object->value.as_external_byte_array.callback;
733 WriteSmi(length); 771 WriteSmi(length);
734 WriteIntptrValue(reinterpret_cast<intptr_t>(data)); 772 WriteIntptrValue(reinterpret_cast<intptr_t>(data));
735 WriteIntptrValue(reinterpret_cast<intptr_t>(peer)); 773 WriteIntptrValue(reinterpret_cast<intptr_t>(peer));
736 WriteIntptrValue(reinterpret_cast<intptr_t>(callback)); 774 WriteIntptrValue(reinterpret_cast<intptr_t>(callback));
737 break; 775 break;
(...skipping 10 matching lines...) Expand all
748 // not been serialized yet. These would typically be fields of arrays. 786 // not been serialized yet. These would typically be fields of arrays.
749 // NOTE: The forward list might grow as we process the list. 787 // NOTE: The forward list might grow as we process the list.
750 for (intptr_t i = 0; i < forward_id_; i++) { 788 for (intptr_t i = 0; i < forward_id_; i++) {
751 WriteForwardedCObject(forward_list_[i]); 789 WriteForwardedCObject(forward_list_[i]);
752 } 790 }
753 UnmarkAllCObjects(object); 791 UnmarkAllCObjects(object);
754 FinalizeBuffer(); 792 FinalizeBuffer();
755 } 793 }
756 794
757 } // namespace dart 795 } // namespace dart
OLDNEW
« no previous file with comments | « vm/dart_api_message.h ('k') | vm/raw_object.h » ('j') | vm/snapshot.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698