| 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 #ifndef VM_SNAPSHOT_H_ | 5 #ifndef VM_SNAPSHOT_H_ |
| 6 #define VM_SNAPSHOT_H_ | 6 #define VM_SNAPSHOT_H_ |
| 7 | 7 |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 #include "vm/bitfield.h" | 10 #include "vm/bitfield.h" |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 String& str_; // Temporary String handle. | 397 String& str_; // Temporary String handle. |
| 398 Library& library_; // Temporary library handle. | 398 Library& library_; // Temporary library handle. |
| 399 AbstractType& type_; // Temporary type handle. | 399 AbstractType& type_; // Temporary type handle. |
| 400 AbstractTypeArguments& type_arguments_; // Temporary type argument handle. | 400 AbstractTypeArguments& type_arguments_; // Temporary type argument handle. |
| 401 GrowableArray<Object*> backward_references_; | 401 GrowableArray<Object*> backward_references_; |
| 402 | 402 |
| 403 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); | 403 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); |
| 404 }; | 404 }; |
| 405 | 405 |
| 406 | 406 |
| 407 // Use this C structure for reading internal objects in the serialized | |
| 408 // data. These are objects that we need to process in order to | |
| 409 // generate the Dart_CObject graph but that we don't want to expose in | |
| 410 // that graph. | |
| 411 // TODO(sjesse): Remove this when message serialization format is | |
| 412 // updated. | |
| 413 struct Dart_CObject_Internal : public Dart_CObject { | |
| 414 enum Type { | |
| 415 kTypeArguments = Dart_CObject::kNumberOfTypes, | |
| 416 kDynamicType, | |
| 417 }; | |
| 418 }; | |
| 419 | |
| 420 | |
| 421 // Reads a message snapshot into C structure. | |
| 422 class CMessageReader : public BaseReader { | |
| 423 public: | |
| 424 CMessageReader(const uint8_t* buffer, intptr_t length, ReAlloc alloc); | |
| 425 ~CMessageReader() { } | |
| 426 | |
| 427 Dart_CObject* ReadMessage(); | |
| 428 | |
| 429 private: | |
| 430 // Allocates a Dart_CObject object on the C heap. | |
| 431 Dart_CObject* AllocateDartCObject(); | |
| 432 // Allocates a Dart_CObject object with the specified type on the C heap. | |
| 433 Dart_CObject* AllocateDartCObject(Dart_CObject::Type type); | |
| 434 // Allocates a Dart_CObject object for the null object on the C heap. | |
| 435 Dart_CObject* AllocateDartCObjectNull(); | |
| 436 // Allocates a Dart_CObject object for a boolean object on the C heap. | |
| 437 Dart_CObject* AllocateDartCObjectBool(bool value); | |
| 438 // Allocates a Dart_CObject object for for a 32-bit integer on the C heap. | |
| 439 Dart_CObject* AllocateDartCObjectInt32(int32_t value); | |
| 440 // Allocates a Dart_CObject object for a double on the C heap. | |
| 441 Dart_CObject* AllocateDartCObjectDouble(double value); | |
| 442 // Allocates a Dart_CObject object for string data on the C heap. | |
| 443 Dart_CObject* AllocateDartCObjectString(intptr_t length); | |
| 444 // Allocates a C array of Dart_CObject objects on the C heap. | |
| 445 Dart_CObject* AllocateDartCObjectArray(intptr_t length); | |
| 446 | |
| 447 intptr_t LookupInternalClass(intptr_t class_header); | |
| 448 Dart_CObject* ReadInlinedObject(intptr_t object_id); | |
| 449 Dart_CObject* ReadObjectImpl(intptr_t header); | |
| 450 Dart_CObject* ReadIndexedObject(intptr_t object_id); | |
| 451 Dart_CObject* ReadObject(); | |
| 452 | |
| 453 // Add object to backward references. | |
| 454 void AddBackwardReference(intptr_t id, Dart_CObject* obj); | |
| 455 | |
| 456 Dart_CObject_Internal* AsInternal(Dart_CObject* object) { | |
| 457 ASSERT(object->type >= Dart_CObject::kNumberOfTypes); | |
| 458 return reinterpret_cast<Dart_CObject_Internal*>(object); | |
| 459 } | |
| 460 | |
| 461 ReAlloc alloc_; | |
| 462 GrowableArray<Dart_CObject*> backward_references_; | |
| 463 | |
| 464 Dart_CObject type_arguments_marker; | |
| 465 Dart_CObject dynamic_type_marker; | |
| 466 }; | |
| 467 | |
| 468 | |
| 469 class BaseWriter { | 407 class BaseWriter { |
| 470 public: | 408 public: |
| 471 // Size of the snapshot. | 409 // Size of the snapshot. |
| 472 intptr_t BytesWritten() const { return stream_.bytes_written(); } | 410 intptr_t BytesWritten() const { return stream_.bytes_written(); } |
| 473 | 411 |
| 474 // Writes raw data to the stream (basic type). | 412 // Writes raw data to the stream (basic type). |
| 475 // sizeof(T) must be in {1,2,4,8}. | 413 // sizeof(T) must be in {1,2,4,8}. |
| 476 template <typename T> | 414 template <typename T> |
| 477 void Write(T value) { | 415 void Write(T value) { |
| 478 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); | 416 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 | 593 |
| 656 private: | 594 private: |
| 657 SnapshotWriter* writer_; | 595 SnapshotWriter* writer_; |
| 658 | 596 |
| 659 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 597 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
| 660 }; | 598 }; |
| 661 | 599 |
| 662 } // namespace dart | 600 } // namespace dart |
| 663 | 601 |
| 664 #endif // VM_SNAPSHOT_H_ | 602 #endif // VM_SNAPSHOT_H_ |
| OLD | NEW |