| 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 19 matching lines...) Expand all Loading... |
| 30 class RawField; | 30 class RawField; |
| 31 class RawFourByteString; | 31 class RawFourByteString; |
| 32 class RawFunction; | 32 class RawFunction; |
| 33 class RawImmutableArray; | 33 class RawImmutableArray; |
| 34 class RawLibrary; | 34 class RawLibrary; |
| 35 class RawLibraryPrefix; | 35 class RawLibraryPrefix; |
| 36 class RawMint; | 36 class RawMint; |
| 37 class RawObject; | 37 class RawObject; |
| 38 class RawOneByteString; | 38 class RawOneByteString; |
| 39 class RawScript; | 39 class RawScript; |
| 40 class RawSmi; |
| 40 class RawTokenStream; | 41 class RawTokenStream; |
| 41 class RawType; | 42 class RawType; |
| 42 class RawTypeParameter; | 43 class RawTypeParameter; |
| 43 class RawTypeArguments; | 44 class RawTypeArguments; |
| 44 class RawTwoByteString; | 45 class RawTwoByteString; |
| 45 class RawUnresolvedClass; | 46 class RawUnresolvedClass; |
| 46 class String; | 47 class String; |
| 47 | 48 |
| 48 static const int8_t kSerializedBitsPerByte = 7; | 49 static const int8_t kSerializedBitsPerByte = 7; |
| 49 static const int8_t kMaxSerializedUnsignedValuePerByte = 127; | 50 static const int8_t kMaxSerializedUnsignedValuePerByte = 127; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 return *current_++; | 187 return *current_++; |
| 187 } | 188 } |
| 188 | 189 |
| 189 private: | 190 private: |
| 190 const uint8_t* buffer_; | 191 const uint8_t* buffer_; |
| 191 const uint8_t* current_; | 192 const uint8_t* current_; |
| 192 const uint8_t* end_; | 193 const uint8_t* end_; |
| 193 | 194 |
| 194 // SnapshotReader needs access to the private Raw classes. | 195 // SnapshotReader needs access to the private Raw classes. |
| 195 friend class SnapshotReader; | 196 friend class SnapshotReader; |
| 197 friend class CMessageReader; |
| 196 DISALLOW_COPY_AND_ASSIGN(ReadStream); | 198 DISALLOW_COPY_AND_ASSIGN(ReadStream); |
| 197 }; | 199 }; |
| 198 | 200 |
| 199 | 201 |
| 200 // Stream for writing various types into a buffer. | 202 // Stream for writing various types into a buffer. |
| 201 class WriteStream : public ValueObject { | 203 class WriteStream : public ValueObject { |
| 202 public: | 204 public: |
| 203 static const int kBufferIncrementSize = 64 * KB; | 205 static const int kBufferIncrementSize = 64 * KB; |
| 204 | 206 |
| 205 WriteStream(uint8_t** buffer, ReAlloc alloc) : | 207 WriteStream(uint8_t** buffer, ReAlloc alloc) : |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 intptr_t current_size_; | 293 intptr_t current_size_; |
| 292 ReAlloc alloc_; | 294 ReAlloc alloc_; |
| 293 | 295 |
| 294 // MessageWriter and SnapshotWriter needs access to the private Raw | 296 // MessageWriter and SnapshotWriter needs access to the private Raw |
| 295 // classes. | 297 // classes. |
| 296 friend class BaseWriter; | 298 friend class BaseWriter; |
| 297 DISALLOW_COPY_AND_ASSIGN(WriteStream); | 299 DISALLOW_COPY_AND_ASSIGN(WriteStream); |
| 298 }; | 300 }; |
| 299 | 301 |
| 300 | 302 |
| 301 // Reads a snapshot into objects. | 303 class BaseReader { |
| 302 class SnapshotReader { | |
| 303 public: | 304 public: |
| 304 SnapshotReader(const Snapshot* snapshot, Isolate* isolate); | 305 BaseReader(const uint8_t* buffer, intptr_t size) : stream_(buffer, size) {} |
| 305 ~SnapshotReader() { } | |
| 306 | |
| 307 // Reads raw data (for basic types). | 306 // Reads raw data (for basic types). |
| 308 // sizeof(T) must be in {1,2,4,8}. | 307 // sizeof(T) must be in {1,2,4,8}. |
| 309 template <typename T> | 308 template <typename T> |
| 310 T Read() { | 309 T Read() { |
| 311 return ReadStream::Raw<sizeof(T), T>::Read(&stream_); | 310 return ReadStream::Raw<sizeof(T), T>::Read(&stream_); |
| 312 } | 311 } |
| 313 | 312 |
| 314 // Reads an intptr_t type value. | 313 // Reads an intptr_t type value. |
| 315 intptr_t ReadIntptrValue() { | 314 intptr_t ReadIntptrValue() { |
| 316 int64_t value = Read<int64_t>(); | 315 int64_t value = Read<int64_t>(); |
| 317 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); | 316 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); |
| 318 return value; | 317 return value; |
| 319 } | 318 } |
| 320 | 319 |
| 320 RawSmi* ReadAsSmi(); |
| 321 intptr_t ReadSmiValue(); |
| 322 |
| 323 private: |
| 324 ReadStream stream_; // input stream. |
| 325 }; |
| 326 |
| 327 |
| 328 // Reads a snapshot into objects. |
| 329 class SnapshotReader : public BaseReader { |
| 330 public: |
| 331 SnapshotReader(const Snapshot* snapshot, Isolate* isolate); |
| 332 ~SnapshotReader() { } |
| 333 |
| 321 Isolate* isolate() const { return isolate_; } | 334 Isolate* isolate() const { return isolate_; } |
| 322 Heap* heap() const { return isolate_->heap(); } | 335 Heap* heap() const { return isolate_->heap(); } |
| 323 ObjectStore* object_store() const { return isolate_->object_store(); } | 336 ObjectStore* object_store() const { return isolate_->object_store(); } |
| 324 Object* ObjectHandle() { return &obj_; } | 337 Object* ObjectHandle() { return &obj_; } |
| 325 String* StringHandle() { return &str_; } | 338 String* StringHandle() { return &str_; } |
| 326 AbstractType* TypeHandle() { return &type_; } | 339 AbstractType* TypeHandle() { return &type_; } |
| 327 AbstractTypeArguments* TypeArgumentsHandle() { return &type_arguments_; } | 340 AbstractTypeArguments* TypeArgumentsHandle() { return &type_arguments_; } |
| 328 | 341 |
| 329 // Reads an object. | 342 // Reads an object. |
| 330 RawObject* ReadObject(); | 343 RawObject* ReadObject(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 // Read an object that was serialized as an Id (singleton, object store, | 383 // Read an object that was serialized as an Id (singleton, object store, |
| 371 // or an object that was already serialized before). | 384 // or an object that was already serialized before). |
| 372 RawObject* ReadIndexedObject(intptr_t object_id); | 385 RawObject* ReadIndexedObject(intptr_t object_id); |
| 373 | 386 |
| 374 // Read an inlined object from the stream. | 387 // Read an inlined object from the stream. |
| 375 RawObject* ReadInlinedObject(intptr_t object_id); | 388 RawObject* ReadInlinedObject(intptr_t object_id); |
| 376 | 389 |
| 377 // Based on header field check to see if it is an internal VM class. | 390 // Based on header field check to see if it is an internal VM class. |
| 378 RawClass* LookupInternalClass(intptr_t class_header); | 391 RawClass* LookupInternalClass(intptr_t class_header); |
| 379 | 392 |
| 380 ReadStream stream_; // input stream. | |
| 381 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). | 393 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). |
| 382 Isolate* isolate_; // Current isolate. | 394 Isolate* isolate_; // Current isolate. |
| 383 Class& cls_; // Temporary Class handle. | 395 Class& cls_; // Temporary Class handle. |
| 384 Object& obj_; // Temporary Object handle. | 396 Object& obj_; // Temporary Object handle. |
| 385 String& str_; // Temporary String handle. | 397 String& str_; // Temporary String handle. |
| 386 Library& library_; // Temporary library handle. | 398 Library& library_; // Temporary library handle. |
| 387 AbstractType& type_; // Temporary type handle. | 399 AbstractType& type_; // Temporary type handle. |
| 388 AbstractTypeArguments& type_arguments_; // Temporary type argument handle. | 400 AbstractTypeArguments& type_arguments_; // Temporary type argument handle. |
| 389 GrowableArray<Object*> backward_references_; | 401 GrowableArray<Object*> backward_references_; |
| 390 | 402 |
| 391 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); | 403 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); |
| 392 }; | 404 }; |
| 393 | 405 |
| 394 | 406 |
| 407 // Reads a message snapshot into C structure. |
| 408 class CMessageReader : public BaseReader { |
| 409 public: |
| 410 CMessageReader(const uint8_t* buffer, intptr_t length, ReAlloc alloc); |
| 411 ~CMessageReader() { } |
| 412 |
| 413 Dart_CObject* ReadObject(); |
| 414 |
| 415 private: |
| 416 // Allocates a Dart_CObject object on the C heap. |
| 417 Dart_CObject* AllocateDartValue(); |
| 418 // Allocates a Dart_CObject object with the specified type on the C heap. |
| 419 Dart_CObject* AllocateDartValue(Dart_CObject::Type type); |
| 420 // Allocates a Dart_CObject object for the null object on the C heap. |
| 421 Dart_CObject* AllocateDartValueNull(); |
| 422 // Allocates a Dart_CObject object for a boolean object on the C heap. |
| 423 Dart_CObject* AllocateDartValueBool(bool value); |
| 424 // Allocates a Dart_CObject object for for a 32-bit integer on the C heap. |
| 425 Dart_CObject* AllocateDartValueInt32(int32_t value); |
| 426 // Allocates a Dart_CObject object for a double on the C heap. |
| 427 Dart_CObject* AllocateDartValueDouble(double value); |
| 428 // Allocates a Dart_CObject object for string data on the C heap. |
| 429 Dart_CObject* AllocateDartValueString(intptr_t length); |
| 430 // Allocates a C array of Dart_CObject objects on the C heap. |
| 431 Dart_CObject* AllocateDartValueArray(intptr_t length); |
| 432 |
| 433 intptr_t LookupInternalClass(intptr_t class_header); |
| 434 Dart_CObject* ReadInlinedObject(intptr_t object_id); |
| 435 Dart_CObject* ReadObjectImpl(intptr_t header); |
| 436 Dart_CObject* ReadIndexedObject(intptr_t object_id); |
| 437 |
| 438 ReAlloc alloc_; |
| 439 }; |
| 440 |
| 441 |
| 395 class BaseWriter { | 442 class BaseWriter { |
| 396 public: | 443 public: |
| 397 // Size of the snapshot. | 444 // Size of the snapshot. |
| 398 intptr_t BytesWritten() const { return stream_.bytes_written(); } | 445 intptr_t BytesWritten() const { return stream_.bytes_written(); } |
| 399 | 446 |
| 400 // Writes raw data to the stream (basic type). | 447 // Writes raw data to the stream (basic type). |
| 401 // sizeof(T) must be in {1,2,4,8}. | 448 // sizeof(T) must be in {1,2,4,8}. |
| 402 template <typename T> | 449 template <typename T> |
| 403 void Write(T value) { | 450 void Write(T value) { |
| 404 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); | 451 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 | 607 |
| 561 private: | 608 private: |
| 562 SnapshotWriter* writer_; | 609 SnapshotWriter* writer_; |
| 563 | 610 |
| 564 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 611 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
| 565 }; | 612 }; |
| 566 | 613 |
| 567 } // namespace dart | 614 } // namespace dart |
| 568 | 615 |
| 569 #endif // VM_SNAPSHOT_H_ | 616 #endif // VM_SNAPSHOT_H_ |
| OLD | NEW |