| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // (a unique id for this object | 0x1) | 92 // (a unique id for this object | 0x1) |
| 93 enum SerializedHeaderType { | 93 enum SerializedHeaderType { |
| 94 kInlined = 0x1, | 94 kInlined = 0x1, |
| 95 kObjectId = 0x3, | 95 kObjectId = 0x3, |
| 96 }; | 96 }; |
| 97 static const int8_t kHeaderTagBits = 2; | 97 static const int8_t kHeaderTagBits = 2; |
| 98 static const int8_t kObjectIdBits = (kBitsPerInt32 - (kHeaderTagBits + 1)); | 98 static const int8_t kObjectIdBits = (kBitsPerInt32 - (kHeaderTagBits + 1)); |
| 99 static const intptr_t kMaxObjectId = (kMaxUint32 >> (kHeaderTagBits + 1)); | 99 static const intptr_t kMaxObjectId = (kMaxUint32 >> (kHeaderTagBits + 1)); |
| 100 static const bool kAsReference = true; | 100 static const bool kAsReference = true; |
| 101 static const bool kAsInlinedObject = false; | 101 static const bool kAsInlinedObject = false; |
| 102 static const intptr_t kInvalidPatchIndex = -1; |
| 102 | 103 |
| 103 | 104 |
| 104 class SerializedHeaderTag : public BitField<enum SerializedHeaderType, | 105 class SerializedHeaderTag : public BitField<enum SerializedHeaderType, |
| 105 0, | 106 0, |
| 106 kHeaderTagBits> { | 107 kHeaderTagBits> { |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 | 110 |
| 110 class SerializedHeaderData : public BitField<intptr_t, | 111 class SerializedHeaderData : public BitField<intptr_t, |
| 111 kHeaderTagBits, | 112 kHeaderTagBits, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 return SerializedHeaderData::decode(value); | 244 return SerializedHeaderData::decode(value); |
| 244 } | 245 } |
| 245 | 246 |
| 246 private: | 247 private: |
| 247 ReadStream stream_; // input stream. | 248 ReadStream stream_; // input stream. |
| 248 }; | 249 }; |
| 249 | 250 |
| 250 | 251 |
| 251 class BackRefNode : public ValueObject { | 252 class BackRefNode : public ValueObject { |
| 252 public: | 253 public: |
| 253 BackRefNode(Object* reference, DeserializeState state) | 254 BackRefNode(Object* reference, |
| 254 : reference_(reference), state_(state) {} | 255 DeserializeState state, |
| 256 bool defer_canonicalization) |
| 257 : reference_(reference), |
| 258 state_(state), |
| 259 defer_canonicalization_(defer_canonicalization), |
| 260 patch_records_(NULL) {} |
| 255 Object* reference() const { return reference_; } | 261 Object* reference() const { return reference_; } |
| 256 bool is_deserialized() const { return state_ == kIsDeserialized; } | 262 bool is_deserialized() const { return state_ == kIsDeserialized; } |
| 257 void set_state(DeserializeState state) { state_ = state; } | 263 void set_state(DeserializeState state) { state_ = state; } |
| 264 bool defer_canonicalization() const { return defer_canonicalization_; } |
| 265 ZoneGrowableArray<intptr_t>* patch_records() const { return patch_records_; } |
| 258 | 266 |
| 259 BackRefNode& operator=(const BackRefNode& other) { | 267 BackRefNode& operator=(const BackRefNode& other) { |
| 260 reference_ = other.reference_; | 268 reference_ = other.reference_; |
| 261 state_ = other.state_; | 269 state_ = other.state_; |
| 270 defer_canonicalization_ = other.defer_canonicalization_; |
| 271 patch_records_ = other.patch_records_; |
| 262 return *this; | 272 return *this; |
| 263 } | 273 } |
| 264 | 274 |
| 275 void AddPatchRecord(intptr_t patch_object_id, intptr_t patch_offset) { |
| 276 if (defer_canonicalization_) { |
| 277 if (patch_records_ == NULL) { |
| 278 patch_records_ = new ZoneGrowableArray<intptr_t>(); |
| 279 } |
| 280 patch_records_->Add(patch_object_id); |
| 281 patch_records_->Add(patch_offset); |
| 282 } |
| 283 } |
| 284 |
| 265 private: | 285 private: |
| 266 Object* reference_; | 286 Object* reference_; |
| 267 DeserializeState state_; | 287 DeserializeState state_; |
| 288 bool defer_canonicalization_; |
| 289 ZoneGrowableArray<intptr_t>* patch_records_; |
| 268 }; | 290 }; |
| 269 | 291 |
| 270 | 292 |
| 271 // Reads a snapshot into objects. | 293 // Reads a snapshot into objects. |
| 272 class SnapshotReader : public BaseReader { | 294 class SnapshotReader : public BaseReader { |
| 273 public: | 295 public: |
| 274 Zone* zone() const { return zone_; } | 296 Zone* zone() const { return zone_; } |
| 275 Isolate* isolate() const { return isolate_; } | 297 Isolate* isolate() const { return isolate_; } |
| 276 Heap* heap() const { return heap_; } | 298 Heap* heap() const { return heap_; } |
| 277 ObjectStore* object_store() const { return isolate_->object_store(); } | 299 ObjectStore* object_store() const { return isolate_->object_store(); } |
| 278 ClassTable* class_table() const { return isolate_->class_table(); } | 300 ClassTable* class_table() const { return isolate_->class_table(); } |
| 279 PassiveObject* PassiveObjectHandle() { return &pobj_; } | 301 PassiveObject* PassiveObjectHandle() { return &pobj_; } |
| 280 Array* ArrayHandle() { return &array_; } | 302 Array* ArrayHandle() { return &array_; } |
| 281 String* StringHandle() { return &str_; } | 303 String* StringHandle() { return &str_; } |
| 282 AbstractType* TypeHandle() { return &type_; } | 304 AbstractType* TypeHandle() { return &type_; } |
| 283 TypeArguments* TypeArgumentsHandle() { return &type_arguments_; } | 305 TypeArguments* TypeArgumentsHandle() { return &type_arguments_; } |
| 284 Array* TokensHandle() { return &tokens_; } | 306 Array* TokensHandle() { return &tokens_; } |
| 285 TokenStream* StreamHandle() { return &stream_; } | 307 TokenStream* StreamHandle() { return &stream_; } |
| 286 ExternalTypedData* DataHandle() { return &data_; } | 308 ExternalTypedData* DataHandle() { return &data_; } |
| 287 TypedData* TypedDataHandle() { return &typed_data_; } | 309 TypedData* TypedDataHandle() { return &typed_data_; } |
| 288 Snapshot::Kind kind() const { return kind_; } | 310 Snapshot::Kind kind() const { return kind_; } |
| 289 bool allow_code() const { return false; } | 311 bool allow_code() const { return false; } |
| 290 | 312 |
| 291 // Reads an object. | 313 // Reads an object. |
| 292 RawObject* ReadObject(); | 314 RawObject* ReadObject(); |
| 293 | 315 |
| 294 // Add object to backward references. | 316 // Add object to backward references. |
| 295 void AddBackRef(intptr_t id, Object* obj, DeserializeState state); | 317 void AddBackRef(intptr_t id, |
| 318 Object* obj, |
| 319 DeserializeState state, |
| 320 bool defer_canonicalization = false); |
| 296 | 321 |
| 297 // Get an object from the backward references list. | 322 // Get an object from the backward references list. |
| 298 Object* GetBackRef(intptr_t id); | 323 Object* GetBackRef(intptr_t id); |
| 299 | 324 |
| 300 // Read a full snap shot. | 325 // Read a full snap shot. |
| 301 RawApiError* ReadFullSnapshot(); | 326 RawApiError* ReadFullSnapshot(); |
| 302 | 327 |
| 303 // Read a script snap shot. | 328 // Read a script snap shot. |
| 304 RawObject* ReadScriptSnapshot(); | 329 RawObject* ReadScriptSnapshot(); |
| 305 | 330 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 PageSpace* old_space() const { return old_space_; } | 389 PageSpace* old_space() const { return old_space_; } |
| 365 | 390 |
| 366 private: | 391 private: |
| 367 // Allocate uninitialized objects, this is used when reading a full snapshot. | 392 // Allocate uninitialized objects, this is used when reading a full snapshot. |
| 368 RawObject* AllocateUninitialized(intptr_t class_id, intptr_t size); | 393 RawObject* AllocateUninitialized(intptr_t class_id, intptr_t size); |
| 369 | 394 |
| 370 RawClass* ReadClassId(intptr_t object_id); | 395 RawClass* ReadClassId(intptr_t object_id); |
| 371 RawObject* ReadStaticImplicitClosure(intptr_t object_id, intptr_t cls_header); | 396 RawObject* ReadStaticImplicitClosure(intptr_t object_id, intptr_t cls_header); |
| 372 | 397 |
| 373 // Implementation to read an object. | 398 // Implementation to read an object. |
| 374 RawObject* ReadObjectImpl(bool as_reference); | 399 RawObject* ReadObjectImpl(bool as_reference, |
| 375 RawObject* ReadObjectImpl(intptr_t header, bool as_reference); | 400 intptr_t patch_object_id = kInvalidPatchIndex, |
| 401 intptr_t patch_offset = 0); |
| 402 RawObject* ReadObjectImpl(intptr_t header, |
| 403 bool as_reference, |
| 404 intptr_t patch_object_id, |
| 405 intptr_t patch_offset); |
| 376 | 406 |
| 377 // Read an object reference from the stream. | 407 // Read an object reference from the stream. |
| 378 RawObject* ReadObjectRef(intptr_t object_id, | 408 RawObject* ReadObjectRef(intptr_t object_id, |
| 379 intptr_t class_header, | 409 intptr_t class_header, |
| 380 intptr_t tags); | 410 intptr_t tags, |
| 411 intptr_t patch_object_id = kInvalidPatchIndex, |
| 412 intptr_t patch_offset = 0); |
| 381 | 413 |
| 382 // Read an inlined object from the stream. | 414 // Read an inlined object from the stream. |
| 383 RawObject* ReadInlinedObject(intptr_t object_id, | 415 RawObject* ReadInlinedObject(intptr_t object_id, |
| 384 intptr_t class_header, | 416 intptr_t class_header, |
| 385 intptr_t tags); | 417 intptr_t tags, |
| 418 intptr_t patch_object_id, |
| 419 intptr_t patch_offset); |
| 386 | 420 |
| 387 // Read a VM isolate object that was serialized as an Id. | 421 // Read a VM isolate object that was serialized as an Id. |
| 388 RawObject* ReadVMIsolateObject(intptr_t object_id); | 422 RawObject* ReadVMIsolateObject(intptr_t object_id); |
| 389 | 423 |
| 390 // Read an object that was serialized as an Id (singleton in object store, | 424 // Read an object that was serialized as an Id (singleton in object store, |
| 391 // or an object that was already serialized before). | 425 // or an object that was already serialized before). |
| 392 RawObject* ReadIndexedObject(intptr_t object_id); | 426 RawObject* ReadIndexedObject(intptr_t object_id, |
| 427 intptr_t patch_object_id, |
| 428 intptr_t patch_offset); |
| 429 |
| 430 // Add a patch record for the object so that objects whose canonicalization |
| 431 // is deferred can be back patched after they are canonicalized. |
| 432 void AddPatchRecord(intptr_t object_id, |
| 433 intptr_t patch_object_id, |
| 434 intptr_t patch_offset); |
| 435 |
| 436 // Process all the deferred canonicalization entries and patch all references. |
| 437 void ProcessDeferredCanonicalizations(); |
| 393 | 438 |
| 394 // Decode class id from the header field. | 439 // Decode class id from the header field. |
| 395 intptr_t LookupInternalClass(intptr_t class_header); | 440 intptr_t LookupInternalClass(intptr_t class_header); |
| 396 | 441 |
| 397 void ArrayReadFrom(const Array& result, intptr_t len, intptr_t tags); | 442 void ArrayReadFrom(intptr_t object_id, |
| 443 const Array& result, |
| 444 intptr_t len, |
| 445 intptr_t tags); |
| 398 | 446 |
| 399 intptr_t NextAvailableObjectId() const; | 447 intptr_t NextAvailableObjectId() const; |
| 400 | 448 |
| 401 void SetReadException(const char* msg); | 449 void SetReadException(const char* msg); |
| 402 | 450 |
| 403 RawObject* VmIsolateSnapshotObject(intptr_t index) const; | 451 RawObject* VmIsolateSnapshotObject(intptr_t index) const; |
| 404 | 452 |
| 405 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). | 453 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). |
| 406 Isolate* isolate_; // Current isolate. | 454 Isolate* isolate_; // Current isolate. |
| 407 Zone* zone_; // Zone for allocations while reading snapshot. | 455 Zone* zone_; // Zone for allocations while reading snapshot. |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 private: | 932 private: |
| 885 SnapshotWriter* writer_; | 933 SnapshotWriter* writer_; |
| 886 bool as_references_; | 934 bool as_references_; |
| 887 | 935 |
| 888 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 936 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
| 889 }; | 937 }; |
| 890 | 938 |
| 891 } // namespace dart | 939 } // namespace dart |
| 892 | 940 |
| 893 #endif // VM_SNAPSHOT_H_ | 941 #endif // VM_SNAPSHOT_H_ |
| OLD | NEW |