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 |
407 // Reads a message snapshot into C structure. | 421 // Reads a message snapshot into C structure. |
408 class CMessageReader : public BaseReader { | 422 class CMessageReader : public BaseReader { |
409 public: | 423 public: |
410 CMessageReader(const uint8_t* buffer, intptr_t length, ReAlloc alloc); | 424 CMessageReader(const uint8_t* buffer, intptr_t length, ReAlloc alloc); |
411 ~CMessageReader() { } | 425 ~CMessageReader() { } |
412 | 426 |
413 Dart_CObject* ReadObject(); | 427 Dart_CObject* ReadObject(); |
414 | 428 |
415 private: | 429 private: |
416 // Allocates a Dart_CObject object on the C heap. | 430 // Allocates a Dart_CObject object on the C heap. |
417 Dart_CObject* AllocateDartValue(); | 431 Dart_CObject* AllocateDartCObject(); |
418 // Allocates a Dart_CObject object with the specified type on the C heap. | 432 // Allocates a Dart_CObject object with the specified type on the C heap. |
419 Dart_CObject* AllocateDartValue(Dart_CObject::Type type); | 433 Dart_CObject* AllocateDartCObject(Dart_CObject::Type type); |
420 // Allocates a Dart_CObject object for the null object on the C heap. | 434 // Allocates a Dart_CObject object for the null object on the C heap. |
421 Dart_CObject* AllocateDartValueNull(); | 435 Dart_CObject* AllocateDartCObjectNull(); |
422 // Allocates a Dart_CObject object for a boolean object on the C heap. | 436 // Allocates a Dart_CObject object for a boolean object on the C heap. |
423 Dart_CObject* AllocateDartValueBool(bool value); | 437 Dart_CObject* AllocateDartCObjectBool(bool value); |
424 // Allocates a Dart_CObject object for for a 32-bit integer on the C heap. | 438 // Allocates a Dart_CObject object for for a 32-bit integer on the C heap. |
425 Dart_CObject* AllocateDartValueInt32(int32_t value); | 439 Dart_CObject* AllocateDartCObjectInt32(int32_t value); |
426 // Allocates a Dart_CObject object for a double on the C heap. | 440 // Allocates a Dart_CObject object for a double on the C heap. |
427 Dart_CObject* AllocateDartValueDouble(double value); | 441 Dart_CObject* AllocateDartCObjectDouble(double value); |
428 // Allocates a Dart_CObject object for string data on the C heap. | 442 // Allocates a Dart_CObject object for string data on the C heap. |
429 Dart_CObject* AllocateDartValueString(intptr_t length); | 443 Dart_CObject* AllocateDartCObjectString(intptr_t length); |
430 // Allocates a C array of Dart_CObject objects on the C heap. | 444 // Allocates a C array of Dart_CObject objects on the C heap. |
431 Dart_CObject* AllocateDartValueArray(intptr_t length); | 445 Dart_CObject* AllocateDartCObjectArray(intptr_t length); |
432 | 446 |
433 intptr_t LookupInternalClass(intptr_t class_header); | 447 intptr_t LookupInternalClass(intptr_t class_header); |
434 Dart_CObject* ReadInlinedObject(intptr_t object_id); | 448 Dart_CObject* ReadInlinedObject(intptr_t object_id); |
435 Dart_CObject* ReadObjectImpl(intptr_t header); | 449 Dart_CObject* ReadObjectImpl(intptr_t header); |
436 Dart_CObject* ReadIndexedObject(intptr_t object_id); | 450 Dart_CObject* ReadIndexedObject(intptr_t object_id); |
437 | 451 |
| 452 // Add object to backward references. |
| 453 void AddBackwardReference(intptr_t id, Dart_CObject* obj); |
| 454 |
| 455 Dart_CObject_Internal* AsInternal(Dart_CObject* object) { |
| 456 ASSERT(object->type >= Dart_CObject::kNumberOfTypes); |
| 457 return reinterpret_cast<Dart_CObject_Internal*>(object); |
| 458 } |
| 459 |
438 ReAlloc alloc_; | 460 ReAlloc alloc_; |
| 461 GrowableArray<Dart_CObject*> backward_references_; |
| 462 |
| 463 Dart_CObject type_arguments_marker; |
| 464 Dart_CObject dynamic_type_marker; |
439 }; | 465 }; |
440 | 466 |
441 | 467 |
442 class BaseWriter { | 468 class BaseWriter { |
443 public: | 469 public: |
444 // Size of the snapshot. | 470 // Size of the snapshot. |
445 intptr_t BytesWritten() const { return stream_.bytes_written(); } | 471 intptr_t BytesWritten() const { return stream_.bytes_written(); } |
446 | 472 |
447 // Writes raw data to the stream (basic type). | 473 // Writes raw data to the stream (basic type). |
448 // sizeof(T) must be in {1,2,4,8}. | 474 // sizeof(T) must be in {1,2,4,8}. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 | 633 |
608 private: | 634 private: |
609 SnapshotWriter* writer_; | 635 SnapshotWriter* writer_; |
610 | 636 |
611 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 637 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
612 }; | 638 }; |
613 | 639 |
614 } // namespace dart | 640 } // namespace dart |
615 | 641 |
616 #endif // VM_SNAPSHOT_H_ | 642 #endif // VM_SNAPSHOT_H_ |
OLD | NEW |