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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 // TODO(sjesse): Remove this when message serialization format is | 411 // TODO(sjesse): Remove this when message serialization format is |
412 // updated. | 412 // updated. |
413 struct Dart_CObject_Internal : public Dart_CObject { | 413 struct Dart_CObject_Internal : public Dart_CObject { |
414 enum Type { | 414 enum Type { |
415 kTypeArguments = Dart_CObject::kNumberOfTypes, | 415 kTypeArguments = Dart_CObject::kNumberOfTypes, |
416 kDynamicType, | 416 kDynamicType, |
417 }; | 417 }; |
418 }; | 418 }; |
419 | 419 |
420 | 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 { | 421 class BaseWriter { |
470 public: | 422 public: |
471 // Size of the snapshot. | 423 // Size of the snapshot. |
472 intptr_t BytesWritten() const { return stream_.bytes_written(); } | 424 intptr_t BytesWritten() const { return stream_.bytes_written(); } |
473 | 425 |
474 // Writes raw data to the stream (basic type). | 426 // Writes raw data to the stream (basic type). |
475 // sizeof(T) must be in {1,2,4,8}. | 427 // sizeof(T) must be in {1,2,4,8}. |
476 template <typename T> | 428 template <typename T> |
477 void Write(T value) { | 429 void Write(T value) { |
478 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); | 430 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 | 607 |
656 private: | 608 private: |
657 SnapshotWriter* writer_; | 609 SnapshotWriter* writer_; |
658 | 610 |
659 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 611 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
660 }; | 612 }; |
661 | 613 |
662 } // namespace dart | 614 } // namespace dart |
663 | 615 |
664 #endif // VM_SNAPSHOT_H_ | 616 #endif // VM_SNAPSHOT_H_ |
OLD | NEW |