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

Side by Side Diff: runtime/vm/snapshot.cc

Issue 9325022: Decode the Dart message into a Dart_CMessage structure before calling the native port callback (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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/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
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), 443 : BaseReader(buffer, length),
444 zone_(NULL),
444 alloc_(alloc), 445 alloc_(alloc),
445 backward_references_(kNumInitialReferences) { 446 backward_references_(kNumInitialReferences) {
447 // When no explicit zone is used ensure that there is a current
448 // isolate zone as backward_references_ needs an isolate zone for
449 // allocation.
450 ASSERT(Isolate::Current() != NULL);
451 ASSERT(Isolate::Current()->current_zone() != NULL);
452 Init();
453 }
454
455
456 CMessageReader::CMessageReader(const uint8_t* buffer,
457 intptr_t length,
458 Zone* zone)
459 : BaseReader(buffer, length),
460 zone_(zone),
461 alloc_(NULL),
462 backward_references_(kNumInitialReferences, zone) {
463 ASSERT(zone != NULL);
464 Init();
465 }
466
467
468 void CMessageReader::Init() {
446 // Initialize marker objects used to handle Lists. 469 // Initialize marker objects used to handle Lists.
447 // TODO(sjesse): Remove this when message serialization format is 470 // TODO(sjesse): Remove this when message serialization format is
448 // updated. 471 // updated.
449 memset(&type_arguments_marker, 0, sizeof(type_arguments_marker)); 472 memset(&type_arguments_marker, 0, sizeof(type_arguments_marker));
450 memset(&dynamic_type_marker, 0, sizeof(dynamic_type_marker)); 473 memset(&dynamic_type_marker, 0, sizeof(dynamic_type_marker));
451 type_arguments_marker.type = 474 type_arguments_marker.type =
452 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kTypeArguments); 475 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kTypeArguments);
453 dynamic_type_marker.type = 476 dynamic_type_marker.type =
454 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kDynamicType); 477 static_cast<Dart_CObject::Type>(Dart_CObject_Internal::kDynamicType);
455 } 478 }
456 479
457 480
458 Dart_CMessage* CMessageReader::ReadMessage() { 481 Dart_CMessage* CMessageReader::ReadMessage() {
459 // Read the object out of the message. 482 // Read the object out of the message.
460 Dart_CObject* object = ReadObject(); 483 Dart_CObject* object = ReadObject();
461 484
462 Dart_CMessage* message = 485 Dart_CMessage* message =
463 reinterpret_cast<Dart_CMessage*>(alloc_(NULL, 0, sizeof(Dart_CMessage))); 486 reinterpret_cast<Dart_CMessage*>(
487 Allocate(NULL, 0, sizeof(Dart_CMessage)));
464 if (message == NULL) return NULL; 488 if (message == NULL) return NULL;
465 message->root = object; 489 message->root = object;
466 return message; 490 return message;
467 } 491 }
468 492
469 intptr_t CMessageReader::LookupInternalClass(intptr_t class_header) { 493 intptr_t CMessageReader::LookupInternalClass(intptr_t class_header) {
470 SerializedHeaderType header_type = SerializedHeaderTag::decode(class_header); 494 SerializedHeaderType header_type = SerializedHeaderTag::decode(class_header);
471 ASSERT(header_type == kObjectId); 495 ASSERT(header_type == kObjectId);
472 intptr_t header_value = SerializedHeaderData::decode(class_header); 496 intptr_t header_value = SerializedHeaderData::decode(class_header);
473 return header_value; 497 return header_value;
474 } 498 }
475 499
500 uint8_t* CMessageReader::Allocate(uint8_t* ptr,
501 intptr_t old_size,
502 intptr_t new_size) {
503 if (alloc_ != NULL) {
504 return alloc_(ptr, old_size, new_size);
505 } else {
506 return reinterpret_cast<uint8_t*>(
507 zone_->Reallocate(reinterpret_cast<uword>(ptr), old_size, new_size));
508 }
509 }
476 510
477 Dart_CObject* CMessageReader::AllocateDartCObject(Dart_CObject::Type type) { 511 Dart_CObject* CMessageReader::AllocateDartCObject(Dart_CObject::Type type) {
478 Dart_CObject* value = 512 Dart_CObject* value =
479 reinterpret_cast<Dart_CObject*>( 513 reinterpret_cast<Dart_CObject*>(
480 alloc_(NULL, 0, sizeof(Dart_CObject))); 514 Allocate(NULL, 0, sizeof(Dart_CObject)));
481 value->type = type; 515 value->type = type;
482 return value; 516 return value;
483 } 517 }
484 518
485 519
486 Dart_CObject* CMessageReader::AllocateDartCObjectNull() { 520 Dart_CObject* CMessageReader::AllocateDartCObjectNull() {
487 return AllocateDartCObject(Dart_CObject::kNull); 521 return AllocateDartCObject(Dart_CObject::kNull);
488 } 522 }
489 523
490 524
(...skipping 17 matching lines...) Expand all
508 return value; 542 return value;
509 } 543 }
510 544
511 545
512 Dart_CObject* CMessageReader::AllocateDartCObjectString(intptr_t length) { 546 Dart_CObject* CMessageReader::AllocateDartCObjectString(intptr_t length) {
513 // Allocate a Dart_CObject structure followed by an array of chars 547 // Allocate a Dart_CObject structure followed by an array of chars
514 // for the string content. The pointer to the string content is set 548 // for the string content. The pointer to the string content is set
515 // up to this area. 549 // up to this area.
516 Dart_CObject* value = 550 Dart_CObject* value =
517 reinterpret_cast<Dart_CObject*>( 551 reinterpret_cast<Dart_CObject*>(
518 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); 552 Allocate(NULL, 0, sizeof(Dart_CObject) + length + 1));
519 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value); 553 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value);
520 value->type = Dart_CObject::kString; 554 value->type = Dart_CObject::kString;
521 return value; 555 return value;
522 } 556 }
523 557
524 558
525 Dart_CObject* CMessageReader::AllocateDartCObjectArray(intptr_t length) { 559 Dart_CObject* CMessageReader::AllocateDartCObjectArray(intptr_t length) {
526 // Allocate a Dart_CObject structure followed by an array of 560 // Allocate a Dart_CObject structure followed by an array of
527 // pointers to Dart_CObject structures. The pointer to the array 561 // pointers to Dart_CObject structures. The pointer to the array
528 // content is set up to this area. 562 // content is set up to this area.
529 Dart_CObject* value = 563 Dart_CObject* value =
530 reinterpret_cast<Dart_CObject*>( 564 reinterpret_cast<Dart_CObject*>(
531 alloc_(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value))); 565 Allocate(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value)));
532 value->type = Dart_CObject::kArray; 566 value->type = Dart_CObject::kArray;
533 value->value.as_array.length = length; 567 value->value.as_array.length = length;
534 if (length > 0) { 568 if (length > 0) {
535 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); 569 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1);
536 } else { 570 } else {
537 value->value.as_array.values = NULL; 571 value->value.as_array.values = NULL;
538 } 572 }
539 return value; 573 return value;
540 } 574 }
541 575
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 938
905 939
906 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) { 940 void SnapshotWriterVisitor::VisitPointers(RawObject** first, RawObject** last) {
907 for (RawObject** current = first; current <= last; current++) { 941 for (RawObject** current = first; current <= last; current++) {
908 RawObject* raw_obj = *current; 942 RawObject* raw_obj = *current;
909 writer_->WriteObject(raw_obj); 943 writer_->WriteObject(raw_obj);
910 } 944 }
911 } 945 }
912 946
913 } // namespace dart 947 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698