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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 #undef SNAPSHOT_READ | 430 #undef SNAPSHOT_READ |
431 default: UNREACHABLE(); break; | 431 default: UNREACHABLE(); break; |
432 } | 432 } |
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 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | |
441 return reinterpret_cast<uint8_t*>(realloc(ptr, new_size)); | |
442 } | |
443 | |
444 | |
440 CMessageReader::CMessageReader(const uint8_t* buffer, | 445 CMessageReader::CMessageReader(const uint8_t* buffer, |
441 intptr_t length, | 446 intptr_t length, |
442 ReAlloc alloc) | 447 ReAlloc alloc) |
443 : BaseReader(buffer, length), | 448 : BaseReader(buffer, length), |
444 alloc_(alloc), | 449 alloc_(alloc), |
445 backward_references_(kNumInitialReferences) { | 450 backward_references_(kNumInitialReferences), |
451 allocated_(kNumInitialReferences * 2), | |
452 original_message_(buffer), | |
453 original_message_length_(length) { | |
454 // Use default allocator if none specified. | |
455 if (alloc_ == NULL) alloc_ = allocator; | |
446 // Initialize marker objects used to handle Lists. | 456 // Initialize marker objects used to handle Lists. |
447 // TODO(sjesse): Remove this when message serialization format is | 457 // TODO(sjesse): Remove this when message serialization format is |
448 // updated. | 458 // updated. |
449 memset(&type_arguments_marker, 0, sizeof(type_arguments_marker)); | 459 memset(&type_arguments_marker, 0, sizeof(type_arguments_marker)); |
450 memset(&dynamic_type_marker, 0, sizeof(dynamic_type_marker)); | 460 memset(&dynamic_type_marker, 0, sizeof(dynamic_type_marker)); |
451 type_arguments_marker.type = | 461 type_arguments_marker.type = |
452 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kTypeArguments); | 462 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kTypeArguments); |
453 dynamic_type_marker.type = | 463 dynamic_type_marker.type = |
454 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kDynamicType); | 464 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kDynamicType); |
455 } | 465 } |
456 | 466 |
457 | 467 |
468 Dart_CMessage* CMessageReader::ReadMessage() { | |
469 // Read the object out of the message. | |
470 Dart_CObject* object = ReadObject(); | |
471 | |
472 intptr_t size = | |
473 sizeof(Dart_CMessage) + allocated_.length() * sizeof(Dart_CObject*); // N OLINT | |
474 Dart_CMessage* message = | |
475 reinterpret_cast<Dart_CMessage*>(alloc_(NULL, 0, size)); | |
476 message->allocated = reinterpret_cast<Dart_CObject**>(message + 1); | |
477 if (message == NULL) return NULL; | |
siva
2012/02/01 01:48:36
The null check for message should happen before me
Søren Gjesse
2012/02/01 12:12:23
Done.
| |
478 message->object = object; | |
479 message->allocated_length = allocated_.length(); | |
480 for (int i = 0; i < allocated_.length(); i++) { | |
481 message->allocated[i] = allocated_[i]; | |
482 } | |
siva
2012/02/01 01:48:36
Not sure if we need to do this copying over here.
Søren Gjesse
2012/02/01 12:12:23
Only needed if pointing back into the message and
| |
483 message->original_message = const_cast<uint8_t*>(original_message_); | |
484 message->original_message_length = original_message_length_; | |
485 return message; | |
486 } | |
487 | |
458 intptr_t CMessageReader::LookupInternalClass(intptr_t class_header) { | 488 intptr_t CMessageReader::LookupInternalClass(intptr_t class_header) { |
459 SerializedHeaderType header_type = SerializedHeaderTag::decode(class_header); | 489 SerializedHeaderType header_type = SerializedHeaderTag::decode(class_header); |
460 ASSERT(header_type == kObjectId); | 490 ASSERT(header_type == kObjectId); |
461 intptr_t header_value = SerializedHeaderData::decode(class_header); | 491 intptr_t header_value = SerializedHeaderData::decode(class_header); |
462 return header_value; | 492 return header_value; |
463 } | 493 } |
464 | 494 |
465 | 495 |
466 Dart_CObject* CMessageReader::AllocateDartCObject(Dart_CObject::Type type) { | 496 Dart_CObject* CMessageReader::AllocateDartCObject(Dart_CObject::Type type) { |
467 Dart_CObject* value = | 497 Dart_CObject* value = |
468 reinterpret_cast<Dart_CObject*>( | 498 reinterpret_cast<Dart_CObject*>( |
469 alloc_(NULL, 0, sizeof(Dart_CObject))); | 499 alloc_(NULL, 0, sizeof(Dart_CObject))); |
500 allocated_.Add(value); | |
470 value->type = type; | 501 value->type = type; |
471 return value; | 502 return value; |
472 } | 503 } |
473 | 504 |
474 | 505 |
475 Dart_CObject* CMessageReader::AllocateDartCObjectNull() { | 506 Dart_CObject* CMessageReader::AllocateDartCObjectNull() { |
476 return AllocateDartCObject(Dart_CObject::kNull); | 507 return AllocateDartCObject(Dart_CObject::kNull); |
477 } | 508 } |
478 | 509 |
479 | 510 |
(...skipping 18 matching lines...) Expand all Loading... | |
498 } | 529 } |
499 | 530 |
500 | 531 |
501 Dart_CObject* CMessageReader::AllocateDartCObjectString(intptr_t length) { | 532 Dart_CObject* CMessageReader::AllocateDartCObjectString(intptr_t length) { |
502 // Allocate a Dart_CObject structure followed by an array of chars | 533 // Allocate a Dart_CObject structure followed by an array of chars |
503 // for the string content. The pointer to the string content is set | 534 // for the string content. The pointer to the string content is set |
504 // up to this area. | 535 // up to this area. |
505 Dart_CObject* value = | 536 Dart_CObject* value = |
506 reinterpret_cast<Dart_CObject*>( | 537 reinterpret_cast<Dart_CObject*>( |
507 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); | 538 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); |
539 allocated_.Add(value); | |
508 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value); | 540 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value); |
509 value->type = Dart_CObject::kString; | 541 value->type = Dart_CObject::kString; |
510 return value; | 542 return value; |
511 } | 543 } |
512 | 544 |
513 | 545 |
514 Dart_CObject* CMessageReader::AllocateDartCObjectArray(intptr_t length) { | 546 Dart_CObject* CMessageReader::AllocateDartCObjectArray(intptr_t length) { |
515 // Allocate a Dart_CObject structure followed by an array of | 547 // Allocate a Dart_CObject structure followed by an array of |
516 // pointers to Dart_CObject structures. The pointer to the array | 548 // pointers to Dart_CObject structures. The pointer to the array |
517 // content is set up to this area. | 549 // content is set up to this area. |
518 Dart_CObject* value = | 550 Dart_CObject* value = |
519 reinterpret_cast<Dart_CObject*>( | 551 reinterpret_cast<Dart_CObject*>( |
520 alloc_(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value))); | 552 alloc_(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value))); |
553 allocated_.Add(value); | |
521 value->type = Dart_CObject::kArray; | 554 value->type = Dart_CObject::kArray; |
522 value->value.as_array.length = length; | 555 value->value.as_array.length = length; |
523 if (length > 0) { | 556 if (length > 0) { |
524 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); | 557 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); |
525 } else { | 558 } else { |
526 value->value.as_array.values = NULL; | 559 value->value.as_array.values = NULL; |
527 } | 560 } |
528 return value; | 561 return value; |
529 } | 562 } |
530 | 563 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
895 | 928 |
896 | 929 |
897 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { | 930 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { |
898 for (RawObject** current = first; current <= last; current++) { | 931 for (RawObject** current = first; current <= last; current++) { |
899 RawObject* raw_obj = *current; | 932 RawObject* raw_obj = *current; |
900 writer_->WriteObject(raw_obj); | 933 writer_->WriteObject(raw_obj); |
901 } | 934 } |
902 } | 935 } |
903 | 936 |
904 } // namespace dart | 937 } // namespace dart |
OLD | NEW |