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