| 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 intptr_t value = -header_val; // Header is negative for VM isolate objects. | 232 intptr_t value = -header_val; // Header is negative for VM isolate objects. |
| 233 ASSERT(SerializedHeaderTag::decode(value) == kObjectId); | 233 ASSERT(SerializedHeaderTag::decode(value) == kObjectId); |
| 234 return SerializedHeaderData::decode(value); | 234 return SerializedHeaderData::decode(value); |
| 235 } | 235 } |
| 236 | 236 |
| 237 private: | 237 private: |
| 238 ReadStream stream_; // input stream. | 238 ReadStream stream_; // input stream. |
| 239 }; | 239 }; |
| 240 | 240 |
| 241 | 241 |
| 242 class BackRefNode : public ValueObject { |
| 243 public: |
| 244 BackRefNode(Object* reference, DeserializeState state) |
| 245 : reference_(reference), state_(state) {} |
| 246 Object* reference() const { return reference_; } |
| 247 bool is_deserialized() const { return state_ == kIsDeserialized; } |
| 248 void set_state(DeserializeState state) { state_ = state; } |
| 249 |
| 250 BackRefNode& operator=(const BackRefNode& other) { |
| 251 reference_ = other.reference_; |
| 252 state_ = other.state_; |
| 253 return *this; |
| 254 } |
| 255 |
| 256 private: |
| 257 Object* reference_; |
| 258 DeserializeState state_; |
| 259 }; |
| 260 |
| 261 |
| 242 // Reads a snapshot into objects. | 262 // Reads a snapshot into objects. |
| 243 class SnapshotReader : public BaseReader { | 263 class SnapshotReader : public BaseReader { |
| 244 public: | 264 public: |
| 245 SnapshotReader(const uint8_t* buffer, | |
| 246 intptr_t size, | |
| 247 Snapshot::Kind kind, | |
| 248 Isolate* isolate, | |
| 249 Zone* zone); | |
| 250 ~SnapshotReader() { } | |
| 251 | |
| 252 Zone* zone() const { return zone_; } | 265 Zone* zone() const { return zone_; } |
| 253 Isolate* isolate() const { return isolate_; } | 266 Isolate* isolate() const { return isolate_; } |
| 254 Heap* heap() const { return heap_; } | 267 Heap* heap() const { return heap_; } |
| 255 ObjectStore* object_store() const { return isolate_->object_store(); } | 268 ObjectStore* object_store() const { return isolate_->object_store(); } |
| 256 ClassTable* class_table() const { return isolate_->class_table(); } | 269 ClassTable* class_table() const { return isolate_->class_table(); } |
| 257 PassiveObject* PassiveObjectHandle() { return &pobj_; } | 270 PassiveObject* PassiveObjectHandle() { return &pobj_; } |
| 258 Array* ArrayHandle() { return &array_; } | 271 Array* ArrayHandle() { return &array_; } |
| 259 String* StringHandle() { return &str_; } | 272 String* StringHandle() { return &str_; } |
| 260 AbstractType* TypeHandle() { return &type_; } | 273 AbstractType* TypeHandle() { return &type_; } |
| 261 TypeArguments* TypeArgumentsHandle() { return &type_arguments_; } | 274 TypeArguments* TypeArgumentsHandle() { return &type_arguments_; } |
| 262 Array* TokensHandle() { return &tokens_; } | 275 Array* TokensHandle() { return &tokens_; } |
| 263 TokenStream* StreamHandle() { return &stream_; } | 276 TokenStream* StreamHandle() { return &stream_; } |
| 264 ExternalTypedData* DataHandle() { return &data_; } | 277 ExternalTypedData* DataHandle() { return &data_; } |
| 278 Snapshot::Kind kind() const { return kind_; } |
| 265 | 279 |
| 266 // Reads an object. | 280 // Reads an object. |
| 267 RawObject* ReadObject(); | 281 RawObject* ReadObject(); |
| 268 | 282 |
| 269 // Add object to backward references. | 283 // Add object to backward references. |
| 270 void AddBackRef(intptr_t id, Object* obj, DeserializeState state); | 284 void AddBackRef(intptr_t id, Object* obj, DeserializeState state); |
| 271 | 285 |
| 272 // Get an object from the backward references list. | 286 // Get an object from the backward references list. |
| 273 Object* GetBackRef(intptr_t id); | 287 Object* GetBackRef(intptr_t id); |
| 274 | 288 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 RawGrowableObjectArray* NewGrowableObjectArray(); | 330 RawGrowableObjectArray* NewGrowableObjectArray(); |
| 317 RawFloat32x4* NewFloat32x4(float v0, float v1, float v2, float v3); | 331 RawFloat32x4* NewFloat32x4(float v0, float v1, float v2, float v3); |
| 318 RawInt32x4* NewInt32x4(uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3); | 332 RawInt32x4* NewInt32x4(uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3); |
| 319 RawFloat64x2* NewFloat64x2(double v0, double v1); | 333 RawFloat64x2* NewFloat64x2(double v0, double v1); |
| 320 RawApiError* NewApiError(); | 334 RawApiError* NewApiError(); |
| 321 RawLanguageError* NewLanguageError(); | 335 RawLanguageError* NewLanguageError(); |
| 322 RawUnhandledException* NewUnhandledException(); | 336 RawUnhandledException* NewUnhandledException(); |
| 323 RawObject* NewInteger(int64_t value); | 337 RawObject* NewInteger(int64_t value); |
| 324 RawStacktrace* NewStacktrace(); | 338 RawStacktrace* NewStacktrace(); |
| 325 | 339 |
| 326 private: | 340 protected: |
| 327 class BackRefNode : public ValueObject { | 341 SnapshotReader(const uint8_t* buffer, |
| 328 public: | 342 intptr_t size, |
| 329 BackRefNode(Object* reference, DeserializeState state) | 343 Snapshot::Kind kind, |
| 330 : reference_(reference), state_(state) {} | 344 ZoneGrowableArray<BackRefNode>* backward_references, |
| 331 Object* reference() const { return reference_; } | 345 Isolate* isolate, |
| 332 bool is_deserialized() const { return state_ == kIsDeserialized; } | 346 Zone* zone); |
| 333 void set_state(DeserializeState state) { state_ = state; } | 347 ~SnapshotReader() { } |
| 334 | 348 |
| 335 BackRefNode& operator=(const BackRefNode& other) { | 349 ZoneGrowableArray<BackRefNode>* GetBackwardReferenceTable() const { |
| 336 reference_ = other.reference_; | 350 return backward_references_; |
| 337 state_ = other.state_; | 351 } |
| 338 return *this; | 352 void ResetBackwardReferenceTable() { backward_references_ = NULL; } |
| 339 } | |
| 340 | |
| 341 private: | |
| 342 Object* reference_; | |
| 343 DeserializeState state_; | |
| 344 }; | |
| 345 | |
| 346 PageSpace* old_space() const { return old_space_; } | 353 PageSpace* old_space() const { return old_space_; } |
| 347 | 354 |
| 355 private: |
| 348 // Allocate uninitialized objects, this is used when reading a full snapshot. | 356 // Allocate uninitialized objects, this is used when reading a full snapshot. |
| 349 RawObject* AllocateUninitialized(intptr_t class_id, intptr_t size); | 357 RawObject* AllocateUninitialized(intptr_t class_id, intptr_t size); |
| 350 | 358 |
| 351 RawClass* ReadClassId(intptr_t object_id); | 359 RawClass* ReadClassId(intptr_t object_id); |
| 352 RawObject* ReadStaticImplicitClosure(intptr_t object_id, intptr_t cls_header); | 360 RawObject* ReadStaticImplicitClosure(intptr_t object_id, intptr_t cls_header); |
| 353 RawObject* ReadObjectImpl(); | 361 RawObject* ReadObjectImpl(); |
| 354 RawObject* ReadObjectImpl(intptr_t header); | 362 RawObject* ReadObjectImpl(intptr_t header); |
| 355 RawObject* ReadObjectRef(); | 363 RawObject* ReadObjectRef(); |
| 356 | 364 |
| 357 // Read a VM isolate object that was serialized as an Id. | 365 // Read a VM isolate object that was serialized as an Id. |
| 358 RawObject* ReadVMIsolateObject(intptr_t object_id); | 366 RawObject* ReadVMIsolateObject(intptr_t object_id); |
| 359 | 367 |
| 360 // Read an object that was serialized as an Id (singleton in object store, | 368 // Read an object that was serialized as an Id (singleton in object store, |
| 361 // or an object that was already serialized before). | 369 // or an object that was already serialized before). |
| 362 RawObject* ReadIndexedObject(intptr_t object_id); | 370 RawObject* ReadIndexedObject(intptr_t object_id); |
| 363 | 371 |
| 364 // Read an inlined object from the stream. | 372 // Read an inlined object from the stream. |
| 365 RawObject* ReadInlinedObject(intptr_t object_id); | 373 RawObject* ReadInlinedObject(intptr_t object_id); |
| 366 | 374 |
| 367 // Decode class id from the header field. | 375 // Decode class id from the header field. |
| 368 intptr_t LookupInternalClass(intptr_t class_header); | 376 intptr_t LookupInternalClass(intptr_t class_header); |
| 369 | 377 |
| 370 void ArrayReadFrom(const Array& result, intptr_t len, intptr_t tags); | 378 void ArrayReadFrom(const Array& result, intptr_t len, intptr_t tags); |
| 371 | 379 |
| 372 intptr_t NextAvailableObjectId() const; | 380 intptr_t NextAvailableObjectId() const; |
| 373 | 381 |
| 374 void SetReadException(const char* msg); | 382 void SetReadException(const char* msg); |
| 375 | 383 |
| 384 RawObject* VmIsolateSnapshotObject(intptr_t index) const; |
| 385 |
| 376 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). | 386 Snapshot::Kind kind_; // Indicates type of snapshot(full, script, message). |
| 377 Isolate* isolate_; // Current isolate. | 387 Isolate* isolate_; // Current isolate. |
| 378 Zone* zone_; // Zone for allocations while reading snapshot. | 388 Zone* zone_; // Zone for allocations while reading snapshot. |
| 379 Heap* heap_; // Heap of the current isolate. | 389 Heap* heap_; // Heap of the current isolate. |
| 380 PageSpace* old_space_; // Old space of the current isolate. | 390 PageSpace* old_space_; // Old space of the current isolate. |
| 381 Class& cls_; // Temporary Class handle. | 391 Class& cls_; // Temporary Class handle. |
| 382 Object& obj_; // Temporary Object handle. | 392 Object& obj_; // Temporary Object handle. |
| 383 PassiveObject& pobj_; // Temporary PassiveObject handle. | 393 PassiveObject& pobj_; // Temporary PassiveObject handle. |
| 384 Array& array_; // Temporary Array handle. | 394 Array& array_; // Temporary Array handle. |
| 385 Field& field_; // Temporary Field handle. | 395 Field& field_; // Temporary Field handle. |
| 386 String& str_; // Temporary String handle. | 396 String& str_; // Temporary String handle. |
| 387 Library& library_; // Temporary library handle. | 397 Library& library_; // Temporary library handle. |
| 388 AbstractType& type_; // Temporary type handle. | 398 AbstractType& type_; // Temporary type handle. |
| 389 TypeArguments& type_arguments_; // Temporary type argument handle. | 399 TypeArguments& type_arguments_; // Temporary type argument handle. |
| 390 Array& tokens_; // Temporary tokens handle. | 400 Array& tokens_; // Temporary tokens handle. |
| 391 TokenStream& stream_; // Temporary token stream handle. | 401 TokenStream& stream_; // Temporary token stream handle. |
| 392 ExternalTypedData& data_; // Temporary stream data handle. | 402 ExternalTypedData& data_; // Temporary stream data handle. |
| 393 UnhandledException& error_; // Error handle. | 403 UnhandledException& error_; // Error handle. |
| 394 GrowableArray<BackRefNode> backward_references_; | 404 intptr_t max_vm_isolate_object_id_; |
| 405 ZoneGrowableArray<BackRefNode>* backward_references_; |
| 395 | 406 |
| 396 friend class ApiError; | 407 friend class ApiError; |
| 397 friend class Array; | 408 friend class Array; |
| 398 friend class BoundedType; | 409 friend class BoundedType; |
| 399 friend class MixinAppType; | 410 friend class MixinAppType; |
| 400 friend class Class; | 411 friend class Class; |
| 401 friend class Context; | 412 friend class Context; |
| 402 friend class ContextScope; | 413 friend class ContextScope; |
| 403 friend class Field; | 414 friend class Field; |
| 404 friend class ClosureData; | 415 friend class ClosureData; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 423 friend class TypeParameter; | 434 friend class TypeParameter; |
| 424 friend class TypeRef; | 435 friend class TypeRef; |
| 425 friend class UnresolvedClass; | 436 friend class UnresolvedClass; |
| 426 friend class UnhandledException; | 437 friend class UnhandledException; |
| 427 friend class WeakProperty; | 438 friend class WeakProperty; |
| 428 friend class MirrorReference; | 439 friend class MirrorReference; |
| 429 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); | 440 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); |
| 430 }; | 441 }; |
| 431 | 442 |
| 432 | 443 |
| 444 class VmIsolateSnapshotReader : public SnapshotReader { |
| 445 public: |
| 446 VmIsolateSnapshotReader(const uint8_t* buffer, intptr_t size, Zone* zone); |
| 447 ~VmIsolateSnapshotReader(); |
| 448 |
| 449 RawApiError* ReadVmIsolateSnapshot(); |
| 450 |
| 451 private: |
| 452 DISALLOW_COPY_AND_ASSIGN(VmIsolateSnapshotReader); |
| 453 }; |
| 454 |
| 455 |
| 456 class IsolateSnapshotReader : public SnapshotReader { |
| 457 public: |
| 458 IsolateSnapshotReader(const uint8_t* buffer, |
| 459 intptr_t size, |
| 460 Isolate* isolate, |
| 461 Zone* zone); |
| 462 ~IsolateSnapshotReader(); |
| 463 |
| 464 private: |
| 465 DISALLOW_COPY_AND_ASSIGN(IsolateSnapshotReader); |
| 466 }; |
| 467 |
| 468 |
| 469 class ScriptSnapshotReader : public SnapshotReader { |
| 470 public: |
| 471 ScriptSnapshotReader(const uint8_t* buffer, |
| 472 intptr_t size, |
| 473 Isolate* isolate, |
| 474 Zone* zone); |
| 475 ~ScriptSnapshotReader(); |
| 476 |
| 477 private: |
| 478 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotReader); |
| 479 }; |
| 480 |
| 481 |
| 482 class MessageSnapshotReader : public SnapshotReader { |
| 483 public: |
| 484 MessageSnapshotReader(const uint8_t* buffer, |
| 485 intptr_t size, |
| 486 Isolate* isolate, |
| 487 Zone* zone); |
| 488 ~MessageSnapshotReader(); |
| 489 |
| 490 private: |
| 491 DISALLOW_COPY_AND_ASSIGN(MessageSnapshotReader); |
| 492 }; |
| 493 |
| 494 |
| 433 class BaseWriter : public StackResource { | 495 class BaseWriter : public StackResource { |
| 434 public: | 496 public: |
| 435 // Size of the snapshot. | 497 // Size of the snapshot. |
| 436 intptr_t BytesWritten() const { return stream_.bytes_written(); } | 498 intptr_t BytesWritten() const { return stream_.bytes_written(); } |
| 437 | 499 |
| 438 // Writes raw data to the stream (basic type). | 500 // Writes raw data to the stream (basic type). |
| 439 // sizeof(T) must be in {1,2,4,8}. | 501 // sizeof(T) must be in {1,2,4,8}. |
| 440 template <typename T> | 502 template <typename T> |
| 441 void Write(T value) { | 503 void Write(T value) { |
| 442 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); | 504 WriteStream::Raw<sizeof(T), T>::Write(&stream_, value); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 void UnmarkAll() const; | 620 void UnmarkAll() const; |
| 559 | 621 |
| 560 private: | 622 private: |
| 561 intptr_t first_object_id() const { return first_object_id_; } | 623 intptr_t first_object_id() const { return first_object_id_; } |
| 562 intptr_t next_object_id() const { return nodes_.length() + first_object_id_; } | 624 intptr_t next_object_id() const { return nodes_.length() + first_object_id_; } |
| 563 | 625 |
| 564 const intptr_t first_object_id_; | 626 const intptr_t first_object_id_; |
| 565 GrowableArray<Node*> nodes_; | 627 GrowableArray<Node*> nodes_; |
| 566 intptr_t first_unprocessed_object_id_; | 628 intptr_t first_unprocessed_object_id_; |
| 567 | 629 |
| 630 friend class FullSnapshotWriter; |
| 568 DISALLOW_COPY_AND_ASSIGN(ForwardList); | 631 DISALLOW_COPY_AND_ASSIGN(ForwardList); |
| 569 }; | 632 }; |
| 570 | 633 |
| 571 | 634 |
| 572 class SnapshotWriter : public BaseWriter { | 635 class SnapshotWriter : public BaseWriter { |
| 573 protected: | 636 protected: |
| 574 SnapshotWriter(Snapshot::Kind kind, | 637 SnapshotWriter(Snapshot::Kind kind, |
| 575 uint8_t** buffer, | 638 uint8_t** buffer, |
| 576 ReAlloc alloc, | 639 ReAlloc alloc, |
| 577 intptr_t initial_size, | 640 intptr_t initial_size, |
| 641 ForwardList* forward_list, |
| 578 bool can_send_any_object); | 642 bool can_send_any_object); |
| 579 | 643 |
| 580 public: | 644 public: |
| 581 // Snapshot kind. | 645 // Snapshot kind. |
| 582 Snapshot::Kind kind() const { return kind_; } | 646 Snapshot::Kind kind() const { return kind_; } |
| 583 | 647 |
| 584 // Serialize an object into the buffer. | 648 // Serialize an object into the buffer. |
| 585 void WriteObject(RawObject* raw); | 649 void WriteObject(RawObject* raw); |
| 586 | 650 |
| 587 uword GetObjectTags(RawObject* raw); | 651 uword GetObjectTags(RawObject* raw); |
| 588 | 652 |
| 589 Exceptions::ExceptionType exception_type() const { | 653 Exceptions::ExceptionType exception_type() const { |
| 590 return exception_type_; | 654 return exception_type_; |
| 591 } | 655 } |
| 592 void set_exception_type(Exceptions::ExceptionType type) { | 656 void set_exception_type(Exceptions::ExceptionType type) { |
| 593 exception_type_ = type; | 657 exception_type_ = type; |
| 594 } | 658 } |
| 595 const char* exception_msg() const { return exception_msg_; } | 659 const char* exception_msg() const { return exception_msg_; } |
| 596 void set_exception_msg(const char* msg) { | 660 void set_exception_msg(const char* msg) { |
| 597 exception_msg_ = msg; | 661 exception_msg_ = msg; |
| 598 } | 662 } |
| 599 bool can_send_any_object() const { return can_send_any_object_; } | 663 bool can_send_any_object() const { return can_send_any_object_; } |
| 600 void ThrowException(Exceptions::ExceptionType type, const char* msg); | 664 void ThrowException(Exceptions::ExceptionType type, const char* msg); |
| 601 | 665 |
| 602 // Write a version string for the snapshot. | 666 // Write a version string for the snapshot. |
| 603 void WriteVersion(); | 667 void WriteVersion(); |
| 604 | 668 |
| 669 static intptr_t FirstObjectId(); |
| 670 |
| 605 protected: | 671 protected: |
| 606 void UnmarkAll() { | 672 void UnmarkAll() { |
| 607 if (!unmarked_objects_) { | 673 if (!unmarked_objects_ && forward_list_ != NULL) { |
| 608 forward_list_.UnmarkAll(); | 674 forward_list_->UnmarkAll(); |
| 609 unmarked_objects_ = true; | 675 unmarked_objects_ = true; |
| 610 } | 676 } |
| 611 } | 677 } |
| 612 | 678 |
| 613 bool CheckAndWritePredefinedObject(RawObject* raw); | 679 bool CheckAndWritePredefinedObject(RawObject* raw); |
| 614 void HandleVMIsolateObject(RawObject* raw); | 680 void HandleVMIsolateObject(RawObject* raw); |
| 615 | 681 |
| 616 void WriteObjectRef(RawObject* raw); | 682 void WriteObjectRef(RawObject* raw); |
| 617 void WriteClassId(RawClass* cls); | 683 void WriteClassId(RawClass* cls); |
| 618 void WriteStaticImplicitClosure(intptr_t object_id, | 684 void WriteStaticImplicitClosure(intptr_t object_id, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 630 RawFunction* IsSerializableClosure(RawClass* cls, RawObject* obj); | 696 RawFunction* IsSerializableClosure(RawClass* cls, RawObject* obj); |
| 631 RawClass* GetFunctionOwner(RawFunction* func); | 697 RawClass* GetFunctionOwner(RawFunction* func); |
| 632 void CheckForNativeFields(RawClass* cls); | 698 void CheckForNativeFields(RawClass* cls); |
| 633 void SetWriteException(Exceptions::ExceptionType type, const char* msg); | 699 void SetWriteException(Exceptions::ExceptionType type, const char* msg); |
| 634 void WriteInstance(intptr_t object_id, | 700 void WriteInstance(intptr_t object_id, |
| 635 RawObject* raw, | 701 RawObject* raw, |
| 636 RawClass* cls, | 702 RawClass* cls, |
| 637 intptr_t tags); | 703 intptr_t tags); |
| 638 void WriteInstanceRef(RawObject* raw, RawClass* cls); | 704 void WriteInstanceRef(RawObject* raw, RawClass* cls); |
| 639 bool AllowObjectsInDartLibrary(RawLibrary* library); | 705 bool AllowObjectsInDartLibrary(RawLibrary* library); |
| 706 intptr_t FindVmSnapshotObject(RawObject* rawobj); |
| 707 |
| 708 void InitializeForwardList(ForwardList* forward_list) { |
| 709 ASSERT(forward_list_ == NULL); |
| 710 forward_list_ = forward_list; |
| 711 } |
| 712 void ResetForwardList() { |
| 713 ASSERT(forward_list_ != NULL); |
| 714 forward_list_ = NULL; |
| 715 } |
| 640 | 716 |
| 641 Isolate* isolate() const { return isolate_; } | 717 Isolate* isolate() const { return isolate_; } |
| 642 ObjectStore* object_store() const { return object_store_; } | 718 ObjectStore* object_store() const { return object_store_; } |
| 643 | 719 |
| 644 private: | 720 private: |
| 645 Snapshot::Kind kind_; | 721 Snapshot::Kind kind_; |
| 646 Isolate* isolate_; | 722 Isolate* isolate_; |
| 647 ObjectStore* object_store_; // Object store for common classes. | 723 ObjectStore* object_store_; // Object store for common classes. |
| 648 ClassTable* class_table_; // Class table for the class index to class lookup. | 724 ClassTable* class_table_; // Class table for the class index to class lookup. |
| 649 ForwardList forward_list_; | 725 ForwardList* forward_list_; |
| 650 Exceptions::ExceptionType exception_type_; // Exception type. | 726 Exceptions::ExceptionType exception_type_; // Exception type. |
| 651 const char* exception_msg_; // Message associated with exception. | 727 const char* exception_msg_; // Message associated with exception. |
| 652 bool unmarked_objects_; // True if marked objects have been unmarked. | 728 bool unmarked_objects_; // True if marked objects have been unmarked. |
| 653 bool can_send_any_object_; // True if any Dart instance can be sent. | 729 bool can_send_any_object_; // True if any Dart instance can be sent. |
| 654 | 730 |
| 731 friend class FullSnapshotWriter; |
| 655 friend class RawArray; | 732 friend class RawArray; |
| 656 friend class RawClass; | 733 friend class RawClass; |
| 657 friend class RawClosureData; | 734 friend class RawClosureData; |
| 658 friend class RawGrowableObjectArray; | 735 friend class RawGrowableObjectArray; |
| 659 friend class RawLinkedHashMap; | 736 friend class RawLinkedHashMap; |
| 660 friend class RawImmutableArray; | 737 friend class RawImmutableArray; |
| 661 friend class RawJSRegExp; | 738 friend class RawJSRegExp; |
| 662 friend class RawLibrary; | 739 friend class RawLibrary; |
| 663 friend class RawLiteralToken; | 740 friend class RawLiteralToken; |
| 664 friend class RawMirrorReference; | 741 friend class RawMirrorReference; |
| 665 friend class RawReceivePort; | 742 friend class RawReceivePort; |
| 666 friend class RawScript; | 743 friend class RawScript; |
| 667 friend class RawStacktrace; | 744 friend class RawStacktrace; |
| 668 friend class RawTokenStream; | 745 friend class RawTokenStream; |
| 669 friend class RawTypeArguments; | 746 friend class RawTypeArguments; |
| 670 friend class RawUserTag; | 747 friend class RawUserTag; |
| 671 friend class SnapshotWriterVisitor; | 748 friend class SnapshotWriterVisitor; |
| 672 friend class WriteInlinedObjectVisitor; | 749 friend class WriteInlinedObjectVisitor; |
| 673 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); | 750 DISALLOW_COPY_AND_ASSIGN(SnapshotWriter); |
| 674 }; | 751 }; |
| 675 | 752 |
| 676 | 753 |
| 677 class FullSnapshotWriter : public SnapshotWriter { | 754 class FullSnapshotWriter { |
| 678 public: | 755 public: |
| 679 static const intptr_t kInitialSize = 64 * KB; | 756 static const intptr_t kInitialSize = 64 * KB; |
| 680 FullSnapshotWriter(uint8_t** vm_isolate_snapshot_buffer, | 757 FullSnapshotWriter(uint8_t** vm_isolate_snapshot_buffer, |
| 681 uint8_t** isolate_snapshot_buffer, | 758 uint8_t** isolate_snapshot_buffer, |
| 682 ReAlloc alloc) | 759 ReAlloc alloc); |
| 683 : SnapshotWriter(Snapshot::kFull, | 760 ~FullSnapshotWriter() { } |
| 684 isolate_snapshot_buffer, | 761 |
| 685 alloc, | 762 uint8_t** vm_isolate_snapshot_buffer() { |
| 686 kInitialSize, | 763 return vm_isolate_snapshot_buffer_; |
| 687 true) { | |
| 688 ASSERT(vm_isolate_snapshot_buffer != NULL); | |
| 689 ASSERT(isolate_snapshot_buffer != NULL); | |
| 690 ASSERT(alloc != NULL); | |
| 691 } | 764 } |
| 692 ~FullSnapshotWriter() { } | 765 |
| 766 uint8_t** isolate_snapshot_buffer() { |
| 767 return isolate_snapshot_buffer_; |
| 768 } |
| 693 | 769 |
| 694 // Writes a full snapshot of the Isolate. | 770 // Writes a full snapshot of the Isolate. |
| 695 void WriteFullSnapshot(); | 771 void WriteFullSnapshot(); |
| 696 | 772 |
| 697 intptr_t VmIsolateSnapshotSize() const { return 0; } | 773 intptr_t VmIsolateSnapshotSize() const { |
| 698 intptr_t IsolateSnapshotSize() const { return BytesWritten(); } | 774 return vm_isolate_snapshot_size_; |
| 775 } |
| 776 intptr_t IsolateSnapshotSize() const { |
| 777 return isolate_snapshot_size_; |
| 778 } |
| 699 | 779 |
| 700 private: | 780 private: |
| 781 // Writes a snapshot of the VM Isolate. |
| 782 void WriteVmIsolateSnapshot(); |
| 783 |
| 784 // Writes a full snapshot of a regular Dart Isolate. |
| 785 void WriteIsolateFullSnapshot(); |
| 786 |
| 787 uint8_t** vm_isolate_snapshot_buffer_; |
| 788 uint8_t** isolate_snapshot_buffer_; |
| 789 ReAlloc alloc_; |
| 790 intptr_t vm_isolate_snapshot_size_; |
| 791 intptr_t isolate_snapshot_size_; |
| 792 ForwardList forward_list_; |
| 793 |
| 701 DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter); | 794 DISALLOW_COPY_AND_ASSIGN(FullSnapshotWriter); |
| 702 }; | 795 }; |
| 703 | 796 |
| 704 | 797 |
| 705 class ScriptSnapshotWriter : public SnapshotWriter { | 798 class ScriptSnapshotWriter : public SnapshotWriter { |
| 706 public: | 799 public: |
| 707 static const intptr_t kInitialSize = 64 * KB; | 800 static const intptr_t kInitialSize = 64 * KB; |
| 708 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc) | 801 ScriptSnapshotWriter(uint8_t** buffer, ReAlloc alloc); |
| 709 : SnapshotWriter(Snapshot::kScript, buffer, alloc, kInitialSize, true) { | |
| 710 ASSERT(buffer != NULL); | |
| 711 ASSERT(alloc != NULL); | |
| 712 } | |
| 713 ~ScriptSnapshotWriter() { } | 802 ~ScriptSnapshotWriter() { } |
| 714 | 803 |
| 715 // Writes a partial snapshot of the script. | 804 // Writes a partial snapshot of the script. |
| 716 void WriteScriptSnapshot(const Library& lib); | 805 void WriteScriptSnapshot(const Library& lib); |
| 717 | 806 |
| 718 private: | 807 private: |
| 808 ForwardList forward_list_; |
| 809 |
| 719 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); | 810 DISALLOW_COPY_AND_ASSIGN(ScriptSnapshotWriter); |
| 720 }; | 811 }; |
| 721 | 812 |
| 722 | 813 |
| 723 class MessageWriter : public SnapshotWriter { | 814 class MessageWriter : public SnapshotWriter { |
| 724 public: | 815 public: |
| 725 static const intptr_t kInitialSize = 512; | 816 static const intptr_t kInitialSize = 512; |
| 726 MessageWriter(uint8_t** buffer, ReAlloc alloc, bool can_send_any_object) | 817 MessageWriter(uint8_t** buffer, ReAlloc alloc, bool can_send_any_object); |
| 727 : SnapshotWriter(Snapshot::kMessage, | |
| 728 buffer, | |
| 729 alloc, | |
| 730 kInitialSize, | |
| 731 can_send_any_object) { | |
| 732 ASSERT(buffer != NULL); | |
| 733 ASSERT(alloc != NULL); | |
| 734 } | |
| 735 ~MessageWriter() { } | 818 ~MessageWriter() { } |
| 736 | 819 |
| 737 void WriteMessage(const Object& obj); | 820 void WriteMessage(const Object& obj); |
| 738 | 821 |
| 739 private: | 822 private: |
| 823 ForwardList forward_list_; |
| 824 |
| 740 DISALLOW_COPY_AND_ASSIGN(MessageWriter); | 825 DISALLOW_COPY_AND_ASSIGN(MessageWriter); |
| 741 }; | 826 }; |
| 742 | 827 |
| 743 | 828 |
| 744 // An object pointer visitor implementation which writes out | 829 // An object pointer visitor implementation which writes out |
| 745 // objects to a snap shot. | 830 // objects to a snap shot. |
| 746 class SnapshotWriterVisitor : public ObjectPointerVisitor { | 831 class SnapshotWriterVisitor : public ObjectPointerVisitor { |
| 747 public: | 832 public: |
| 748 explicit SnapshotWriterVisitor(SnapshotWriter* writer) | 833 explicit SnapshotWriterVisitor(SnapshotWriter* writer) |
| 749 : ObjectPointerVisitor(Isolate::Current()), | 834 : ObjectPointerVisitor(Isolate::Current()), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 760 private: | 845 private: |
| 761 SnapshotWriter* writer_; | 846 SnapshotWriter* writer_; |
| 762 bool as_references_; | 847 bool as_references_; |
| 763 | 848 |
| 764 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 849 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
| 765 }; | 850 }; |
| 766 | 851 |
| 767 } // namespace dart | 852 } // namespace dart |
| 768 | 853 |
| 769 #endif // VM_SNAPSHOT_H_ | 854 #endif // VM_SNAPSHOT_H_ |
| OLD | NEW |