Chromium Code Reviews| 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 MessageReader; | |
| 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 snapshot into C structure. | |
| 408 class MessageReader : public BaseReader { | |
|
turnidge
2012/01/26 19:48:30
Maybe name this CMessageReader?
Søren Gjesse
2012/01/27 14:40:03
Done.
| |
| 409 public: | |
| 410 MessageReader(const uint8_t* buffer, intptr_t length); | |
| 411 ~MessageReader() { } | |
| 412 | |
| 413 Dart_Value* ReadObject(); | |
| 414 | |
| 415 private: | |
| 416 // Allocate a Dart_Value object on the C heap. | |
|
turnidge
2012/01/26 19:48:30
s/Allocate/Allocates/
Søren Gjesse
2012/01/27 14:40:03
Done.
| |
| 417 Dart_Value* AllocateDartValue(); | |
| 418 // Allocate a Dart_Value object with the specified type on the C heap. | |
| 419 Dart_Value* AllocateDartValue(Dart_Value::Type type); | |
| 420 // Allocate a Dart_Value object for the null object on the C heap. | |
| 421 Dart_Value* AllocateDartValueNull(); | |
| 422 // Allocate a Dart_Value object for a boolean object on the C heap. | |
| 423 Dart_Value* AllocateDartValueBool(bool value); | |
| 424 // Allocate a Dart_Value object for for a 32-bit integer on the C heap. | |
| 425 Dart_Value* AllocateDartValueInt32(int32_t value); | |
| 426 // Allocate a Dart_Value object for a double on the C heap. | |
| 427 Dart_Value* AllocateDartValueDouble(double value); | |
| 428 // Allocate a Dart_Value object for string data on the C heap. | |
| 429 Dart_Value* AllocateDartValueString(intptr_t length); | |
| 430 // Allocate a C array of Dart_Value objects on the C heap. | |
| 431 Dart_Value* AllocateDartValueArray(intptr_t length); | |
| 432 | |
| 433 intptr_t LookupInternalClass(intptr_t class_header); | |
| 434 Dart_Value* ReadInlinedObject(intptr_t object_id); | |
| 435 Dart_Value* ReadObjectImpl(intptr_t header); | |
| 436 Dart_Value* ReadIndexedObject(intptr_t object_id); | |
| 437 }; | |
| 438 | |
| 439 | |
| 395 class BaseWriter { | 440 class BaseWriter { |
| 396 public: | 441 public: |
| 397 // Size of the snapshot. | 442 // Size of the snapshot. |
| 398 intptr_t BytesWritten() const { return stream_.bytes_written(); } | 443 intptr_t BytesWritten() const { return stream_.bytes_written(); } |
| 399 | 444 |
| 400 // Writes raw data to the stream (basic type). | 445 // Writes raw data to the stream (basic type). |
| 401 // sizeof(T) must be in {1,2,4,8}. | 446 // sizeof(T) must be in {1,2,4,8}. |
| 402 template <typename T> | 447 template <typename T> |
| 403 void Write(T value) { | 448 void Write(T value) { |
| 404 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); | 449 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 | 605 |
| 561 private: | 606 private: |
| 562 SnapshotWriter* writer_; | 607 SnapshotWriter* writer_; |
| 563 | 608 |
| 564 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 609 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
| 565 }; | 610 }; |
| 566 | 611 |
| 567 } // namespace dart | 612 } // namespace dart |
| 568 | 613 |
| 569 #endif // VM_SNAPSHOT_H_ | 614 #endif // VM_SNAPSHOT_H_ |
| OLD | NEW |