| 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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 PassiveObject* PassiveObjectHandle() { return &pobj_; } | 405 PassiveObject* PassiveObjectHandle() { return &pobj_; } |
| 406 Array* ArrayHandle() { return &array_; } | 406 Array* ArrayHandle() { return &array_; } |
| 407 Class* ClassHandle() { return &cls_; } | 407 Class* ClassHandle() { return &cls_; } |
| 408 String* StringHandle() { return &str_; } | 408 String* StringHandle() { return &str_; } |
| 409 AbstractType* TypeHandle() { return &type_; } | 409 AbstractType* TypeHandle() { return &type_; } |
| 410 TypeArguments* TypeArgumentsHandle() { return &type_arguments_; } | 410 TypeArguments* TypeArgumentsHandle() { return &type_arguments_; } |
| 411 GrowableObjectArray* TokensHandle() { return &tokens_; } | 411 GrowableObjectArray* TokensHandle() { return &tokens_; } |
| 412 TokenStream* StreamHandle() { return &stream_; } | 412 TokenStream* StreamHandle() { return &stream_; } |
| 413 ExternalTypedData* DataHandle() { return &data_; } | 413 ExternalTypedData* DataHandle() { return &data_; } |
| 414 TypedData* TypedDataHandle() { return &typed_data_; } | 414 TypedData* TypedDataHandle() { return &typed_data_; } |
| 415 Code* CodeHandle() { return &code_; } | |
| 416 Function* FunctionHandle() { return &function_; } | 415 Function* FunctionHandle() { return &function_; } |
| 417 MegamorphicCache* MegamorphicCacheHandle() { return &megamorphic_cache_; } | |
| 418 Snapshot::Kind kind() const { return kind_; } | 416 Snapshot::Kind kind() const { return kind_; } |
| 419 | 417 |
| 420 // Reads an object. | 418 // Reads an object. |
| 421 RawObject* ReadObject(); | 419 RawObject* ReadObject(); |
| 422 | 420 |
| 423 // Add object to backward references. | 421 // Add object to backward references. |
| 424 void AddBackRef(intptr_t id, | 422 void AddBackRef(intptr_t id, |
| 425 Object* obj, | 423 Object* obj, |
| 426 DeserializeState state, | 424 DeserializeState state, |
| 427 bool defer_canonicalization = false); | 425 bool defer_canonicalization = false); |
| 428 | 426 |
| 429 // Get an object from the backward references list. | 427 // Get an object from the backward references list. |
| 430 Object* GetBackRef(intptr_t id); | 428 Object* GetBackRef(intptr_t id); |
| 431 | 429 |
| 432 // Read a script snapshot. | 430 // Read a script snapshot. |
| 433 RawObject* ReadScriptSnapshot(); | 431 RawObject* ReadScriptSnapshot(); |
| 434 | 432 |
| 435 // Read version number of snapshot and verify. | 433 // Read version number of snapshot and verify. |
| 436 RawApiError* VerifyVersionAndFeatures(); | 434 RawApiError* VerifyVersionAndFeatures(); |
| 437 | 435 |
| 438 // Helper functions for creating uninitialized versions | |
| 439 // of various object types. These are used when reading a | |
| 440 // full snapshot. | |
| 441 RawArray* NewArray(intptr_t len); | |
| 442 RawImmutableArray* NewImmutableArray(intptr_t len); | |
| 443 RawOneByteString* NewOneByteString(intptr_t len); | |
| 444 RawTwoByteString* NewTwoByteString(intptr_t len); | |
| 445 RawTypeArguments* NewTypeArguments(intptr_t len); | |
| 446 RawTokenStream* NewTokenStream(intptr_t len); | |
| 447 RawContext* NewContext(intptr_t num_variables); | |
| 448 RawClass* NewClass(intptr_t class_id); | |
| 449 RawInstance* NewInstance(); | |
| 450 RawMint* NewMint(int64_t value); | |
| 451 RawBigint* NewBigint(); | |
| 452 RawTypedData* NewTypedData(intptr_t class_id, intptr_t len); | |
| 453 RawDouble* NewDouble(double value); | |
| 454 RawUnresolvedClass* NewUnresolvedClass(); | |
| 455 RawType* NewType(); | |
| 456 RawTypeRef* NewTypeRef(); | |
| 457 RawTypeParameter* NewTypeParameter(); | |
| 458 RawBoundedType* NewBoundedType(); | |
| 459 RawMixinAppType* NewMixinAppType(); | |
| 460 RawPatchClass* NewPatchClass(); | |
| 461 RawClosure* NewClosure(); | |
| 462 RawClosureData* NewClosureData(); | |
| 463 RawRedirectionData* NewRedirectionData(); | |
| 464 RawFunction* NewFunction(); | |
| 465 RawCode* NewCode(intptr_t pointer_offsets_length); | |
| 466 RawObjectPool* NewObjectPool(intptr_t length); | |
| 467 RawPcDescriptors* NewPcDescriptors(intptr_t length); | |
| 468 RawCodeSourceMap* NewCodeSourceMap(intptr_t length); | |
| 469 RawLocalVarDescriptors* NewLocalVarDescriptors(intptr_t num_entries); | |
| 470 RawExceptionHandlers* NewExceptionHandlers(intptr_t num_entries); | |
| 471 RawStackmap* NewStackmap(intptr_t length); | |
| 472 RawContextScope* NewContextScope(intptr_t num_variables); | |
| 473 RawICData* NewICData(); | |
| 474 RawMegamorphicCache* NewMegamorphicCache(); | |
| 475 RawSubtypeTestCache* NewSubtypeTestCache(); | |
| 476 RawLinkedHashMap* NewLinkedHashMap(); | |
| 477 RawField* NewField(); | |
| 478 RawLibrary* NewLibrary(); | |
| 479 RawLibraryPrefix* NewLibraryPrefix(); | |
| 480 RawNamespace* NewNamespace(); | |
| 481 RawScript* NewScript(); | |
| 482 RawLiteralToken* NewLiteralToken(); | |
| 483 RawGrowableObjectArray* NewGrowableObjectArray(); | |
| 484 RawFloat32x4* NewFloat32x4(float v0, float v1, float v2, float v3); | |
| 485 RawInt32x4* NewInt32x4(uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3); | |
| 486 RawFloat64x2* NewFloat64x2(double v0, double v1); | |
| 487 RawApiError* NewApiError(); | |
| 488 RawLanguageError* NewLanguageError(); | |
| 489 RawUnhandledException* NewUnhandledException(); | |
| 490 RawObject* NewInteger(int64_t value); | 436 RawObject* NewInteger(int64_t value); |
| 491 RawStacktrace* NewStacktrace(); | |
| 492 RawWeakProperty* NewWeakProperty(); | |
| 493 RawRegExp* NewRegExp(); | |
| 494 | |
| 495 uword GetInstructionsAt(int32_t offset) { | |
| 496 return instructions_reader_->GetInstructionsAt(offset); | |
| 497 } | |
| 498 | |
| 499 RawObject* GetObjectAt(int32_t offset) { | |
| 500 return instructions_reader_->GetObjectAt(offset); | |
| 501 } | |
| 502 | |
| 503 const uint8_t* instructions_buffer_; | |
| 504 const uint8_t* data_buffer_; | |
| 505 | 437 |
| 506 protected: | 438 protected: |
| 507 SnapshotReader(const uint8_t* buffer, | 439 SnapshotReader(const uint8_t* buffer, |
| 508 intptr_t size, | 440 intptr_t size, |
| 509 const uint8_t* instructions_buffer, | |
| 510 const uint8_t* data_buffer, | |
| 511 Snapshot::Kind kind, | 441 Snapshot::Kind kind, |
| 512 ZoneGrowableArray<BackRefNode>* backward_references, | 442 ZoneGrowableArray<BackRefNode>* backward_references, |
| 513 Thread* thread); | 443 Thread* thread); |
| 514 ~SnapshotReader() { } | 444 ~SnapshotReader() { } |
| 515 | 445 |
| 516 ZoneGrowableArray<BackRefNode>* GetBackwardReferenceTable() const { | 446 ZoneGrowableArray<BackRefNode>* GetBackwardReferenceTable() const { |
| 517 return backward_references_; | 447 return backward_references_; |
| 518 } | 448 } |
| 519 void ResetBackwardReferenceTable() { backward_references_ = NULL; } | 449 void ResetBackwardReferenceTable() { backward_references_ = NULL; } |
| 520 PageSpace* old_space() const { return old_space_; } | 450 PageSpace* old_space() const { return old_space_; } |
| 521 | 451 |
| 522 private: | 452 private: |
| 523 // Allocate uninitialized objects, this is used when reading a full snapshot. | |
| 524 RawObject* AllocateUninitialized(intptr_t class_id, intptr_t size); | |
| 525 | |
| 526 RawClass* ReadClassId(intptr_t object_id); | 453 RawClass* ReadClassId(intptr_t object_id); |
| 527 RawFunction* ReadFunctionId(intptr_t object_id); | 454 RawFunction* ReadFunctionId(intptr_t object_id); |
| 528 RawObject* ReadStaticImplicitClosure(intptr_t object_id, intptr_t cls_header); | 455 RawObject* ReadStaticImplicitClosure(intptr_t object_id, intptr_t cls_header); |
| 529 | 456 |
| 530 // Implementation to read an object. | 457 // Implementation to read an object. |
| 531 RawObject* ReadObjectImpl(bool as_reference, | 458 RawObject* ReadObjectImpl(bool as_reference, |
| 532 intptr_t patch_object_id = kInvalidPatchIndex, | 459 intptr_t patch_object_id = kInvalidPatchIndex, |
| 533 intptr_t patch_offset = 0); | 460 intptr_t patch_offset = 0); |
| 534 RawObject* ReadObjectImpl(intptr_t header, | 461 RawObject* ReadObjectImpl(intptr_t header, |
| 535 bool as_reference, | 462 bool as_reference, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 Array& array_; // Temporary Array handle. | 513 Array& array_; // Temporary Array handle. |
| 587 Field& field_; // Temporary Field handle. | 514 Field& field_; // Temporary Field handle. |
| 588 String& str_; // Temporary String handle. | 515 String& str_; // Temporary String handle. |
| 589 Library& library_; // Temporary library handle. | 516 Library& library_; // Temporary library handle. |
| 590 AbstractType& type_; // Temporary type handle. | 517 AbstractType& type_; // Temporary type handle. |
| 591 TypeArguments& type_arguments_; // Temporary type argument handle. | 518 TypeArguments& type_arguments_; // Temporary type argument handle. |
| 592 GrowableObjectArray& tokens_; // Temporary tokens handle. | 519 GrowableObjectArray& tokens_; // Temporary tokens handle. |
| 593 TokenStream& stream_; // Temporary token stream handle. | 520 TokenStream& stream_; // Temporary token stream handle. |
| 594 ExternalTypedData& data_; // Temporary stream data handle. | 521 ExternalTypedData& data_; // Temporary stream data handle. |
| 595 TypedData& typed_data_; // Temporary typed data handle. | 522 TypedData& typed_data_; // Temporary typed data handle. |
| 596 Code& code_; // Temporary code handle. | |
| 597 Function& function_; // Temporary function handle. | 523 Function& function_; // Temporary function handle. |
| 598 MegamorphicCache& megamorphic_cache_; // Temporary megamorphic cache handle. | |
| 599 UnhandledException& error_; // Error handle. | 524 UnhandledException& error_; // Error handle. |
| 600 intptr_t max_vm_isolate_object_id_; | 525 intptr_t max_vm_isolate_object_id_; |
| 601 ZoneGrowableArray<BackRefNode>* backward_references_; | 526 ZoneGrowableArray<BackRefNode>* backward_references_; |
| 602 InstructionsReader* instructions_reader_; | |
| 603 | 527 |
| 604 friend class ApiError; | 528 friend class ApiError; |
| 605 friend class Array; | 529 friend class Array; |
| 606 friend class Bigint; | 530 friend class Bigint; |
| 607 friend class BoundedType; | 531 friend class BoundedType; |
| 608 friend class Class; | 532 friend class Class; |
| 609 friend class Closure; | 533 friend class Closure; |
| 610 friend class ClosureData; | 534 friend class ClosureData; |
| 611 friend class Code; | |
| 612 friend class Context; | 535 friend class Context; |
| 613 friend class ContextScope; | 536 friend class ContextScope; |
| 614 friend class ExceptionHandlers; | 537 friend class ExceptionHandlers; |
| 615 friend class Field; | 538 friend class Field; |
| 616 friend class Function; | 539 friend class Function; |
| 617 friend class GrowableObjectArray; | 540 friend class GrowableObjectArray; |
| 618 friend class ICData; | 541 friend class ICData; |
| 619 friend class ImmutableArray; | 542 friend class ImmutableArray; |
| 620 friend class Instructions; | |
| 621 friend class RegExp; | 543 friend class RegExp; |
| 622 friend class LanguageError; | 544 friend class LanguageError; |
| 623 friend class Library; | 545 friend class Library; |
| 624 friend class LibraryPrefix; | 546 friend class LibraryPrefix; |
| 625 friend class LinkedHashMap; | 547 friend class LinkedHashMap; |
| 626 friend class LiteralToken; | 548 friend class LiteralToken; |
| 627 friend class LocalVarDescriptors; | |
| 628 friend class MegamorphicCache; | |
| 629 friend class MirrorReference; | 549 friend class MirrorReference; |
| 630 friend class MixinAppType; | 550 friend class MixinAppType; |
| 631 friend class Namespace; | 551 friend class Namespace; |
| 632 friend class ObjectPool; | |
| 633 friend class PatchClass; | 552 friend class PatchClass; |
| 634 friend class RedirectionData; | 553 friend class RedirectionData; |
| 635 friend class Script; | 554 friend class Script; |
| 636 friend class Stacktrace; | |
| 637 friend class SubtypeTestCache; | 555 friend class SubtypeTestCache; |
| 638 friend class TokenStream; | 556 friend class TokenStream; |
| 639 friend class Type; | 557 friend class Type; |
| 640 friend class TypeArguments; | 558 friend class TypeArguments; |
| 641 friend class TypeParameter; | 559 friend class TypeParameter; |
| 642 friend class TypeRef; | 560 friend class TypeRef; |
| 643 friend class UnhandledException; | 561 friend class UnhandledException; |
| 644 friend class UnresolvedClass; | 562 friend class UnresolvedClass; |
| 645 friend class WeakProperty; | 563 friend class WeakProperty; |
| 646 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); | 564 DISALLOW_COPY_AND_ASSIGN(SnapshotReader); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 | 856 |
| 939 | 857 |
| 940 class SnapshotWriter : public BaseWriter { | 858 class SnapshotWriter : public BaseWriter { |
| 941 protected: | 859 protected: |
| 942 SnapshotWriter(Thread* thread, | 860 SnapshotWriter(Thread* thread, |
| 943 Snapshot::Kind kind, | 861 Snapshot::Kind kind, |
| 944 uint8_t** buffer, | 862 uint8_t** buffer, |
| 945 ReAlloc alloc, | 863 ReAlloc alloc, |
| 946 intptr_t initial_size, | 864 intptr_t initial_size, |
| 947 ForwardList* forward_list, | 865 ForwardList* forward_list, |
| 948 InstructionsWriter* instructions_writer, | 866 bool can_send_any_object); |
| 949 bool can_send_any_object, | |
| 950 bool writing_vm_isolate = false); | |
| 951 | 867 |
| 952 public: | 868 public: |
| 953 // Snapshot kind. | 869 // Snapshot kind. |
| 954 Snapshot::Kind kind() const { return kind_; } | 870 Snapshot::Kind kind() const { return kind_; } |
| 955 Thread* thread() const { return thread_; } | 871 Thread* thread() const { return thread_; } |
| 956 Zone* zone() const { return thread_->zone(); } | 872 Zone* zone() const { return thread_->zone(); } |
| 957 Isolate* isolate() const { return thread_->isolate(); } | 873 Isolate* isolate() const { return thread_->isolate(); } |
| 958 Heap* heap() const { return isolate()->heap(); } | 874 Heap* heap() const { return isolate()->heap(); } |
| 959 | 875 |
| 960 // Serialize an object into the buffer. | 876 // Serialize an object into the buffer. |
| 961 void WriteObject(RawObject* raw); | 877 void WriteObject(RawObject* raw); |
| 962 | 878 |
| 963 uword GetObjectTags(RawObject* raw); | 879 uword GetObjectTags(RawObject* raw); |
| 964 | 880 |
| 965 Exceptions::ExceptionType exception_type() const { | 881 Exceptions::ExceptionType exception_type() const { |
| 966 return exception_type_; | 882 return exception_type_; |
| 967 } | 883 } |
| 968 void set_exception_type(Exceptions::ExceptionType type) { | 884 void set_exception_type(Exceptions::ExceptionType type) { |
| 969 exception_type_ = type; | 885 exception_type_ = type; |
| 970 } | 886 } |
| 971 const char* exception_msg() const { return exception_msg_; } | 887 const char* exception_msg() const { return exception_msg_; } |
| 972 void set_exception_msg(const char* msg) { | 888 void set_exception_msg(const char* msg) { |
| 973 exception_msg_ = msg; | 889 exception_msg_ = msg; |
| 974 } | 890 } |
| 975 bool can_send_any_object() const { return can_send_any_object_; } | 891 bool can_send_any_object() const { return can_send_any_object_; } |
| 976 bool writing_vm_isolate() const { return writing_vm_isolate_; } | |
| 977 void ThrowException(Exceptions::ExceptionType type, const char* msg); | 892 void ThrowException(Exceptions::ExceptionType type, const char* msg); |
| 978 | 893 |
| 979 // Write a version string for the snapshot. | 894 // Write a version string for the snapshot. |
| 980 void WriteVersionAndFeatures(); | 895 void WriteVersionAndFeatures(); |
| 981 | 896 |
| 982 int32_t GetInstructionsId(RawInstructions* instructions, RawCode* code) { | |
| 983 return instructions_writer_->GetOffsetFor(instructions, code); | |
| 984 } | |
| 985 | |
| 986 int32_t GetObjectId(RawObject* raw) { | |
| 987 return instructions_writer_->GetObjectOffsetFor(raw); | |
| 988 } | |
| 989 | |
| 990 void WriteFunctionId(RawFunction* func, bool owner_is_class); | 897 void WriteFunctionId(RawFunction* func, bool owner_is_class); |
| 991 | 898 |
| 992 RawFunction* IsSerializableClosure(RawClosure* closure); | 899 RawFunction* IsSerializableClosure(RawClosure* closure); |
| 993 | 900 |
| 994 void WriteStaticImplicitClosure(intptr_t object_id, | 901 void WriteStaticImplicitClosure(intptr_t object_id, |
| 995 RawFunction* func, | 902 RawFunction* func, |
| 996 intptr_t tags); | 903 intptr_t tags); |
| 997 | 904 |
| 998 protected: | 905 protected: |
| 999 bool CheckAndWritePredefinedObject(RawObject* raw); | 906 bool CheckAndWritePredefinedObject(RawObject* raw); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1025 intptr_t FindVmSnapshotObject(RawObject* rawobj); | 932 intptr_t FindVmSnapshotObject(RawObject* rawobj); |
| 1026 | 933 |
| 1027 ObjectStore* object_store() const { return object_store_; } | 934 ObjectStore* object_store() const { return object_store_; } |
| 1028 | 935 |
| 1029 private: | 936 private: |
| 1030 Thread* thread_; | 937 Thread* thread_; |
| 1031 Snapshot::Kind kind_; | 938 Snapshot::Kind kind_; |
| 1032 ObjectStore* object_store_; // Object store for common classes. | 939 ObjectStore* object_store_; // Object store for common classes. |
| 1033 ClassTable* class_table_; // Class table for the class index to class lookup. | 940 ClassTable* class_table_; // Class table for the class index to class lookup. |
| 1034 ForwardList* forward_list_; | 941 ForwardList* forward_list_; |
| 1035 InstructionsWriter* instructions_writer_; | |
| 1036 Exceptions::ExceptionType exception_type_; // Exception type. | 942 Exceptions::ExceptionType exception_type_; // Exception type. |
| 1037 const char* exception_msg_; // Message associated with exception. | 943 const char* exception_msg_; // Message associated with exception. |
| 1038 bool unmarked_objects_; // True if marked objects have been unmarked. | |
| 1039 bool can_send_any_object_; // True if any Dart instance can be sent. | 944 bool can_send_any_object_; // True if any Dart instance can be sent. |
| 1040 bool writing_vm_isolate_; | |
| 1041 | 945 |
| 1042 friend class RawArray; | 946 friend class RawArray; |
| 1043 friend class RawClass; | 947 friend class RawClass; |
| 1044 friend class RawClosureData; | 948 friend class RawClosureData; |
| 1045 friend class RawCode; | 949 friend class RawCode; |
| 1046 friend class RawContextScope; | 950 friend class RawContextScope; |
| 1047 friend class RawExceptionHandlers; | 951 friend class RawExceptionHandlers; |
| 1048 friend class RawField; | 952 friend class RawField; |
| 1049 friend class RawFunction; | 953 friend class RawFunction; |
| 1050 friend class RawGrowableObjectArray; | 954 friend class RawGrowableObjectArray; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 private: | 1021 private: |
| 1118 SnapshotWriter* writer_; | 1022 SnapshotWriter* writer_; |
| 1119 bool as_references_; | 1023 bool as_references_; |
| 1120 | 1024 |
| 1121 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); | 1025 DISALLOW_COPY_AND_ASSIGN(SnapshotWriterVisitor); |
| 1122 }; | 1026 }; |
| 1123 | 1027 |
| 1124 } // namespace dart | 1028 } // namespace dart |
| 1125 | 1029 |
| 1126 #endif // VM_SNAPSHOT_H_ | 1030 #endif // VM_SNAPSHOT_H_ |
| OLD | NEW |