| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/assert.h" | 9 #include "vm/assert.h" |
| 10 #include "vm/bitfield.h" | 10 #include "vm/bitfield.h" |
| 11 #include "vm/globals.h" | 11 #include "vm/globals.h" |
| 12 #include "vm/growable_array.h" | 12 #include "vm/growable_array.h" |
| 13 #include "vm/isolate.h" | 13 #include "vm/isolate.h" |
| 14 #include "vm/visitor.h" | 14 #include "vm/visitor.h" |
| 15 | 15 |
| 16 namespace dart { | 16 namespace dart { |
| 17 | 17 |
| 18 // Forward declarations. | 18 // Forward declarations. |
| 19 class AbstractType; |
| 20 class AbstractTypeArguments; |
| 21 class Class; |
| 19 class Heap; | 22 class Heap; |
| 20 class Library; | 23 class Library; |
| 21 class Object; | 24 class Object; |
| 22 class ObjectStore; | 25 class ObjectStore; |
| 23 class RawClass; | 26 class RawClass; |
| 24 class RawObject; | 27 class RawObject; |
| 28 class String; |
| 25 | 29 |
| 26 static const int8_t kSerializedBitsPerByte = 7; | 30 static const int8_t kSerializedBitsPerByte = 7; |
| 27 static const int8_t kMaxSerializedUnsignedValuePerByte = 127; | 31 static const int8_t kMaxSerializedUnsignedValuePerByte = 127; |
| 28 static const int8_t kMaxSerializedValuePerByte = 63; | 32 static const int8_t kMaxSerializedValuePerByte = 63; |
| 29 static const int8_t kMinSerializedValuePerByte = -64; | 33 static const int8_t kMinSerializedValuePerByte = -64; |
| 30 static const uint8_t kEndByteMarker = (255 - kMaxSerializedValuePerByte); | 34 static const uint8_t kEndByteMarker = (255 - kMaxSerializedValuePerByte); |
| 31 static const int8_t kSerializedByteMask = (1 << kSerializedBitsPerByte) - 1; | 35 static const int8_t kSerializedByteMask = (1 << kSerializedBitsPerByte) - 1; |
| 32 | 36 |
| 33 // Serialized object header encoding is as follows: | 37 // Serialized object header encoding is as follows: |
| 34 // - Smi: the Smi value is written as is (last bit is not tagged). | 38 // - Smi: the Smi value is written as is (last bit is not tagged). |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 // MessageWriter and SnapshotWriter needs access to the private Raw | 276 // MessageWriter and SnapshotWriter needs access to the private Raw |
| 273 // classes. | 277 // classes. |
| 274 friend class BaseWriter; | 278 friend class BaseWriter; |
| 275 DISALLOW_COPY_AND_ASSIGN(WriteStream); | 279 DISALLOW_COPY_AND_ASSIGN(WriteStream); |
| 276 }; | 280 }; |
| 277 | 281 |
| 278 | 282 |
| 279 // Reads a snapshot into objects. | 283 // Reads a snapshot into objects. |
| 280 class SnapshotReader { | 284 class SnapshotReader { |
| 281 public: | 285 public: |
| 282 SnapshotReader(const Snapshot* snapshot, Isolate* isolate) | 286 SnapshotReader(const Snapshot* snapshot, Isolate* isolate); |
| 283 : stream_(snapshot->content(), snapshot->length()), | |
| 284 kind_(snapshot->kind()), | |
| 285 isolate_(isolate), | |
| 286 backward_references_() { } | |
| 287 ~SnapshotReader() { } | 287 ~SnapshotReader() { } |
| 288 | 288 |
| 289 // Reads raw data (for basic types). | 289 // Reads raw data (for basic types). |
| 290 // sizeof(T) must be in {1,2,4,8}. | 290 // sizeof(T) must be in {1,2,4,8}. |
| 291 template <typename T> | 291 template <typename T> |
| 292 T Read() { | 292 T Read() { |
| 293 return ReadStream::Raw<sizeof(T), T>::Read(&stream_); | 293 return ReadStream::Raw<sizeof(T), T>::Read(&stream_); |
| 294 } | 294 } |
| 295 | 295 |
| 296 // Reads an intptr_t type value. | 296 // Reads an intptr_t type value. |
| 297 intptr_t ReadIntptrValue() { | 297 intptr_t ReadIntptrValue() { |
| 298 int64_t value = Read<int64_t>(); | 298 int64_t value = Read<int64_t>(); |
| 299 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); | 299 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); |
| 300 return value; | 300 return value; |
| 301 } | 301 } |
| 302 | 302 |
| 303 Isolate* isolate() const { return isolate_; } | 303 Isolate* isolate() const { return isolate_; } |
| 304 Heap* heap() const { return isolate_->heap(); } | 304 Heap* heap() const { return isolate_->heap(); } |
| 305 ObjectStore* object_store() const { return isolate_->object_store(); } | 305 ObjectStore* object_store() const { return isolate_->object_store(); } |
| 306 Object* ObjectHandle() { return &obj_; } |
| 307 String* StringHandle() { return &str_; } |
| 308 AbstractType* TypeHandle() { return &type_; } |
| 309 AbstractTypeArguments* TypeArgumentsHandle() { return &type_arguments_; } |
| 306 | 310 |
| 307 // Reads an object. | 311 // Reads an object. |
| 308 RawObject* ReadObject(); | 312 RawObject* ReadObject(); |
| 309 | 313 |
| 310 RawClass* ReadClassId(intptr_t object_id); | 314 RawClass* ReadClassId(intptr_t object_id); |
| 311 | 315 |
| 312 // Add object to backward references. | 316 // Add object to backward references. |
| 313 void AddBackwardReference(intptr_t id, Object* obj); | 317 void AddBackwardReference(intptr_t id, Object* obj); |
| 314 | 318 |
| 315 // Read a full snap shot. | 319 // Read a full snap shot. |
| 316 void ReadFullSnapshot(); | 320 void ReadFullSnapshot(); |
| 317 | 321 |
| 318 private: | 322 private: |
| 319 // Internal implementation of ReadObject once the header value is read. | 323 // Internal implementation of ReadObject once the header value is read. |
| 320 RawObject* ReadObjectImpl(intptr_t header); | 324 RawObject* ReadObjectImpl(intptr_t header); |
| 321 | 325 |
| 322 // Read an object that was serialized as an Id (singleton, object store, | 326 // Read an object that was serialized as an Id (singleton, object store, |
| 323 // or an object that was already serialized before). | 327 // or an object that was already serialized before). |
| 324 RawObject* ReadIndexedObject(intptr_t object_id); | 328 RawObject* ReadIndexedObject(intptr_t object_id); |
| 325 | 329 |
| 326 // Read an inlined object from the stream. | 330 // Read an inlined object from the stream. |
| 327 RawObject* ReadInlinedObject(intptr_t object_id); | 331 RawObject* ReadInlinedObject(intptr_t object_id); |
| 328 | 332 |
| 329 // Based on header field check to see if it is an internal VM class. | 333 // Based on header field check to see if it is an internal VM class. |
| 330 RawClass* LookupInternalClass(intptr_t class_header); | 334 RawClass* LookupInternalClass(intptr_t class_header); |
| 331 | 335 |
| 332 ReadStream stream_; // input stream. | 336 ReadStream stream_; // input stream. |
| 333 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). | 337 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). |
| 334 Isolate* isolate_; // Current isolate. | 338 Isolate* isolate_; // Current isolate. |
| 339 Class& cls_; // Temporary Class handle. |
| 340 Object& obj_; // Temporary Object handle. |
| 341 String& str_; // Temporary String handle. |
| 342 Library& library_; // Temporary library handle. |
| 343 AbstractType& type_; // Temporary type handle. |
| 344 AbstractTypeArguments& type_arguments_; // Temporary type argument handle. |
| 335 GrowableArray<Object*> backward_references_; | 345 GrowableArray<Object*> backward_references_; |
| 336 | 346 |
| 337 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); | 347 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); |
| 338 }; | 348 }; |
| 339 | 349 |
| 340 | 350 |
| 341 class BaseWriter { | 351 class BaseWriter { |
| 342 public: | 352 public: |
| 343 // Size of the snapshot. | 353 // Size of the snapshot. |
| 344 intptr_t BytesWritten() const { return stream_.bytes_written(); } | 354 intptr_t BytesWritten() const { return stream_.bytes_written(); } |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 | 516 |
| 507 private: | 517 private: |
| 508 SnapshotWriter* writer_; | 518 SnapshotWriter* writer_; |
| 509 | 519 |
| 510 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 520 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
| 511 }; | 521 }; |
| 512 | 522 |
| 513 } // namespace dart | 523 } // namespace dart |
| 514 | 524 |
| 515 #endif // VM_SNAPSHOT_H_ | 525 #endif // VM_SNAPSHOT_H_ |
| OLD | NEW |