| 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 #include "vm/native_entry.h" | 5 #include "vm/native_entry.h" |
| 6 #include "vm/object.h" | 6 #include "vm/object.h" |
| 7 #include "vm/object_store.h" | 7 #include "vm/object_store.h" |
| 8 #include "vm/snapshot.h" | 8 #include "vm/snapshot.h" |
| 9 #include "vm/stub_code.h" | 9 #include "vm/stub_code.h" |
| 10 #include "vm/symbols.h" | 10 #include "vm/symbols.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 cls.set_next_field_offset_in_words(reader->Read<int32_t>()); | 71 cls.set_next_field_offset_in_words(reader->Read<int32_t>()); |
| 72 } | 72 } |
| 73 cls.set_type_arguments_field_offset_in_words(reader->Read<int32_t>()); | 73 cls.set_type_arguments_field_offset_in_words(reader->Read<int32_t>()); |
| 74 cls.set_num_type_arguments(reader->Read<int16_t>()); | 74 cls.set_num_type_arguments(reader->Read<int16_t>()); |
| 75 cls.set_num_own_type_arguments(reader->Read<int16_t>()); | 75 cls.set_num_own_type_arguments(reader->Read<int16_t>()); |
| 76 cls.set_num_native_fields(reader->Read<uint16_t>()); | 76 cls.set_num_native_fields(reader->Read<uint16_t>()); |
| 77 cls.set_token_pos(TokenPosition::SnapshotDecode(reader->Read<int32_t>())); | 77 cls.set_token_pos(TokenPosition::SnapshotDecode(reader->Read<int32_t>())); |
| 78 cls.set_state_bits(reader->Read<uint16_t>()); | 78 cls.set_state_bits(reader->Read<uint16_t>()); |
| 79 | 79 |
| 80 // Set all the object fields. | 80 // Set all the object fields. |
| 81 READ_OBJECT_FIELDS(cls, cls.raw()->from(), cls.raw()->to(), kAsReference); | 81 READ_OBJECT_FIELDS(cls, |
| 82 cls.raw()->from(), |
| 83 cls.raw()->to_snapshot(kind), |
| 84 kAsReference); |
| 85 cls.StorePointer(&cls.raw_ptr()->dependent_code_, Array::null()); |
| 82 ASSERT(!cls.IsInFullSnapshot() || (Snapshot::IsFull(kind))); | 86 ASSERT(!cls.IsInFullSnapshot() || (Snapshot::IsFull(kind))); |
| 83 } else { | 87 } else { |
| 84 cls ^= reader->ReadClassId(object_id); | 88 cls ^= reader->ReadClassId(object_id); |
| 85 ASSERT((kind == Snapshot::kMessage) || cls.IsInFullSnapshot()); | 89 ASSERT((kind == Snapshot::kMessage) || cls.IsInFullSnapshot()); |
| 86 } | 90 } |
| 87 return cls.raw(); | 91 return cls.raw(); |
| 88 } | 92 } |
| 89 | 93 |
| 90 | 94 |
| 91 void RawClass::WriteTo(SnapshotWriter* writer, | 95 void RawClass::WriteTo(SnapshotWriter* writer, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 127 } |
| 124 writer->Write<int32_t>(ptr()->type_arguments_field_offset_in_words_); | 128 writer->Write<int32_t>(ptr()->type_arguments_field_offset_in_words_); |
| 125 writer->Write<uint16_t>(ptr()->num_type_arguments_); | 129 writer->Write<uint16_t>(ptr()->num_type_arguments_); |
| 126 writer->Write<uint16_t>(ptr()->num_own_type_arguments_); | 130 writer->Write<uint16_t>(ptr()->num_own_type_arguments_); |
| 127 writer->Write<uint16_t>(ptr()->num_native_fields_); | 131 writer->Write<uint16_t>(ptr()->num_native_fields_); |
| 128 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode()); | 132 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode()); |
| 129 writer->Write<uint16_t>(ptr()->state_bits_); | 133 writer->Write<uint16_t>(ptr()->state_bits_); |
| 130 | 134 |
| 131 // Write out all the object pointer fields. | 135 // Write out all the object pointer fields. |
| 132 SnapshotWriterVisitor visitor(writer, kAsReference); | 136 SnapshotWriterVisitor visitor(writer, kAsReference); |
| 133 visitor.VisitPointers(from(), to()); | 137 visitor.VisitPointers(from(), to_snapshot(kind)); |
| 134 } else { | 138 } else { |
| 135 if (writer->can_send_any_object() || | 139 if (writer->can_send_any_object() || |
| 136 writer->AllowObjectsInDartLibrary(ptr()->library_)) { | 140 writer->AllowObjectsInDartLibrary(ptr()->library_)) { |
| 137 writer->WriteClassId(this); | 141 writer->WriteClassId(this); |
| 138 } else { | 142 } else { |
| 139 // We do not allow regular dart instances in isolate messages. | 143 // We do not allow regular dart instances in isolate messages. |
| 140 writer->SetWriteException(Exceptions::kArgument, | 144 writer->SetWriteException(Exceptions::kArgument, |
| 141 "Illegal argument in isolate message" | 145 "Illegal argument in isolate message" |
| 142 " : (object is a regular Dart Instance)"); | 146 " : (object is a regular Dart Instance)"); |
| 143 } | 147 } |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 Snapshot::Kind kind, | 850 Snapshot::Kind kind, |
| 847 bool as_reference) { | 851 bool as_reference) { |
| 848 ASSERT(reader != NULL); | 852 ASSERT(reader != NULL); |
| 849 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); | 853 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); |
| 850 | 854 |
| 851 // Allocate field object. | 855 // Allocate field object. |
| 852 Field& field = Field::ZoneHandle(reader->zone(), NEW_OBJECT(Field)); | 856 Field& field = Field::ZoneHandle(reader->zone(), NEW_OBJECT(Field)); |
| 853 reader->AddBackRef(object_id, &field, kIsDeserialized); | 857 reader->AddBackRef(object_id, &field, kIsDeserialized); |
| 854 | 858 |
| 855 // Set all non object fields. | 859 // Set all non object fields. |
| 856 if (Snapshot::IncludesCode(kind)) { | 860 if (kind == Snapshot::kAppNoJIT) { |
| 857 field.set_token_pos(TokenPosition::kNoSource); | 861 field.set_token_pos(TokenPosition::kNoSource); |
| 858 ASSERT(!FLAG_use_field_guards); | 862 ASSERT(!FLAG_use_field_guards); |
| 859 } else { | 863 } else { |
| 860 field.set_token_pos( | 864 field.set_token_pos( |
| 861 TokenPosition::SnapshotDecode(reader->Read<int32_t>())); | 865 TokenPosition::SnapshotDecode(reader->Read<int32_t>())); |
| 862 field.set_guarded_cid(reader->Read<int32_t>()); | 866 field.set_guarded_cid(reader->Read<int32_t>()); |
| 863 field.set_is_nullable(reader->Read<int32_t>()); | 867 field.set_is_nullable(reader->Read<int32_t>()); |
| 864 } | 868 } |
| 865 field.set_kind_bits(reader->Read<uint8_t>()); | 869 field.set_kind_bits(reader->Read<uint8_t>()); |
| 866 | 870 |
| 867 // Set all the object fields. | 871 // Set all the object fields. |
| 868 READ_OBJECT_FIELDS(field, | 872 READ_OBJECT_FIELDS(field, |
| 869 field.raw()->from(), | 873 field.raw()->from(), |
| 870 field.raw()->to_snapshot(kind), | 874 field.raw()->to_snapshot(kind), |
| 871 kAsReference); | 875 kAsReference); |
| 876 field.StorePointer(&field.raw_ptr()->dependent_code_, Array::null()); |
| 872 | 877 |
| 873 if (!FLAG_use_field_guards) { | 878 if (!FLAG_use_field_guards) { |
| 874 field.set_guarded_cid(kDynamicCid); | 879 field.set_guarded_cid(kDynamicCid); |
| 875 field.set_is_nullable(true); | 880 field.set_is_nullable(true); |
| 876 field.set_guarded_list_length(Field::kNoFixedLength); | 881 field.set_guarded_list_length(Field::kNoFixedLength); |
| 877 field.set_guarded_list_length_in_object_offset(Field::kUnknownLengthOffset); | 882 field.set_guarded_list_length_in_object_offset(Field::kUnknownLengthOffset); |
| 878 } else { | 883 } else { |
| 879 field.InitializeGuardedListLengthInObjectOffset(); | 884 field.InitializeGuardedListLengthInObjectOffset(); |
| 880 } | 885 } |
| 881 | 886 |
| 882 return field.raw(); | 887 return field.raw(); |
| 883 } | 888 } |
| 884 | 889 |
| 885 | 890 |
| 886 void RawField::WriteTo(SnapshotWriter* writer, | 891 void RawField::WriteTo(SnapshotWriter* writer, |
| 887 intptr_t object_id, | 892 intptr_t object_id, |
| 888 Snapshot::Kind kind, | 893 Snapshot::Kind kind, |
| 889 bool as_reference) { | 894 bool as_reference) { |
| 890 ASSERT(writer != NULL); | 895 ASSERT(writer != NULL); |
| 891 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); | 896 ASSERT((kind == Snapshot::kScript) || (Snapshot::IsFull(kind))); |
| 892 | 897 |
| 893 // Write out the serialization header value for this object. | 898 // Write out the serialization header value for this object. |
| 894 writer->WriteInlinedObjectHeader(object_id); | 899 writer->WriteInlinedObjectHeader(object_id); |
| 895 | 900 |
| 896 // Write out the class and tags information. | 901 // Write out the class and tags information. |
| 897 writer->WriteVMIsolateObject(kFieldCid); | 902 writer->WriteVMIsolateObject(kFieldCid); |
| 898 writer->WriteTags(writer->GetObjectTags(this)); | 903 writer->WriteTags(writer->GetObjectTags(this)); |
| 899 | 904 |
| 900 // Write out all the non object fields. | 905 // Write out all the non object fields. |
| 901 if (!Snapshot::IncludesCode(kind)) { | 906 if (kind != Snapshot::kAppNoJIT) { |
| 902 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode()); | 907 writer->Write<int32_t>(ptr()->token_pos_.SnapshotEncode()); |
| 903 writer->Write<int32_t>(ptr()->guarded_cid_); | 908 writer->Write<int32_t>(ptr()->guarded_cid_); |
| 904 writer->Write<int32_t>(ptr()->is_nullable_); | 909 writer->Write<int32_t>(ptr()->is_nullable_); |
| 905 } | 910 } |
| 906 writer->Write<uint8_t>(ptr()->kind_bits_); | 911 writer->Write<uint8_t>(ptr()->kind_bits_); |
| 907 | 912 |
| 908 // Write out the name. | 913 // Write out the name. |
| 909 writer->WriteObjectImpl(ptr()->name_, kAsReference); | 914 writer->WriteObjectImpl(ptr()->name_, kAsReference); |
| 910 // Write out the owner. | 915 // Write out the owner. |
| 911 writer->WriteObjectImpl(ptr()->owner_, kAsReference); | 916 writer->WriteObjectImpl(ptr()->owner_, kAsReference); |
| 912 // Write out the type. | 917 // Write out the type. |
| 913 writer->WriteObjectImpl(ptr()->type_, kAsReference); | 918 writer->WriteObjectImpl(ptr()->type_, kAsReference); |
| 914 // Write out the initial static value or field offset. | 919 // Write out the initial static value or field offset. |
| 915 if (Field::StaticBit::decode(ptr()->kind_bits_)) { | 920 if (Field::StaticBit::decode(ptr()->kind_bits_)) { |
| 916 if (Snapshot::IncludesCode(kind)) { | 921 if (kind == Snapshot::kAppNoJIT) { |
| 917 // For precompiled static fields, the value was already reset and | 922 // For precompiled static fields, the value was already reset and |
| 918 // initializer_ now contains a Function. | 923 // initializer_ now contains a Function. |
| 919 writer->WriteObjectImpl(ptr()->value_.static_value_, kAsReference); | 924 writer->WriteObjectImpl(ptr()->value_.static_value_, kAsReference); |
| 920 } else { | 925 } else { |
| 921 // Otherwise, for static fields we write out the initial static value. | 926 // Otherwise, for static fields we write out the initial static value. |
| 922 writer->WriteObjectImpl(ptr()->initializer_.saved_value_, kAsReference); | 927 writer->WriteObjectImpl(ptr()->initializer_.saved_value_, kAsReference); |
| 923 } | 928 } |
| 924 } else { | 929 } else { |
| 925 writer->WriteObjectImpl(ptr()->value_.offset_, kAsReference); | 930 writer->WriteObjectImpl(ptr()->value_.offset_, kAsReference); |
| 926 } | 931 } |
| 927 // Write out the initializer function or saved initial value. | 932 // Write out the initializer function or saved initial value. |
| 928 if (Snapshot::IncludesCode(kind)) { | 933 if (kind == Snapshot::kAppNoJIT) { |
| 929 writer->WriteObjectImpl(ptr()->initializer_.precompiled_, kAsReference); | 934 writer->WriteObjectImpl(ptr()->initializer_.precompiled_, kAsReference); |
| 930 } else { | 935 } else { |
| 931 writer->WriteObjectImpl(ptr()->initializer_.saved_value_, kAsReference); | 936 writer->WriteObjectImpl(ptr()->initializer_.saved_value_, kAsReference); |
| 932 } | 937 } |
| 933 if (!Snapshot::IncludesCode(kind)) { | 938 if (kind != Snapshot::kAppNoJIT) { |
| 934 // Write out the dependent code. | |
| 935 writer->WriteObjectImpl(ptr()->dependent_code_, kAsReference); | |
| 936 // Write out the guarded list length. | 939 // Write out the guarded list length. |
| 937 writer->WriteObjectImpl(ptr()->guarded_list_length_, kAsReference); | 940 writer->WriteObjectImpl(ptr()->guarded_list_length_, kAsReference); |
| 938 } | 941 } |
| 939 } | 942 } |
| 940 | 943 |
| 941 | 944 |
| 942 RawLiteralToken* LiteralToken::ReadFrom(SnapshotReader* reader, | 945 RawLiteralToken* LiteralToken::ReadFrom(SnapshotReader* reader, |
| 943 intptr_t object_id, | 946 intptr_t object_id, |
| 944 intptr_t tags, | 947 intptr_t tags, |
| 945 Snapshot::Kind kind, | 948 Snapshot::Kind kind, |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 reader->Read<int16_t>()); | 1249 reader->Read<int16_t>()); |
| 1247 prefix.StoreNonPointer(&prefix.raw_ptr()->is_deferred_load_, | 1250 prefix.StoreNonPointer(&prefix.raw_ptr()->is_deferred_load_, |
| 1248 reader->Read<bool>()); | 1251 reader->Read<bool>()); |
| 1249 prefix.StoreNonPointer(&prefix.raw_ptr()->is_loaded_, reader->Read<bool>()); | 1252 prefix.StoreNonPointer(&prefix.raw_ptr()->is_loaded_, reader->Read<bool>()); |
| 1250 | 1253 |
| 1251 // Set all the object fields. | 1254 // Set all the object fields. |
| 1252 READ_OBJECT_FIELDS(prefix, | 1255 READ_OBJECT_FIELDS(prefix, |
| 1253 prefix.raw()->from(), | 1256 prefix.raw()->from(), |
| 1254 prefix.raw()->to_snapshot(kind), | 1257 prefix.raw()->to_snapshot(kind), |
| 1255 kAsReference); | 1258 kAsReference); |
| 1256 if (Snapshot::IncludesCode(kind)) { | 1259 if (kind == Snapshot::kAppNoJIT) { |
| 1257 prefix.StorePointer(&prefix.raw_ptr()->imports_, | 1260 prefix.StorePointer(&prefix.raw_ptr()->imports_, |
| 1258 Array::null()); | 1261 Array::null()); |
| 1259 prefix.StorePointer(&prefix.raw_ptr()->dependent_code_, | |
| 1260 Array::null()); | |
| 1261 } | 1262 } |
| 1263 prefix.StorePointer(&prefix.raw_ptr()->dependent_code_, |
| 1264 Array::null()); |
| 1262 | 1265 |
| 1263 return prefix.raw(); | 1266 return prefix.raw(); |
| 1264 } | 1267 } |
| 1265 | 1268 |
| 1266 | 1269 |
| 1267 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer, | 1270 void RawLibraryPrefix::WriteTo(SnapshotWriter* writer, |
| 1268 intptr_t object_id, | 1271 intptr_t object_id, |
| 1269 Snapshot::Kind kind, | 1272 Snapshot::Kind kind, |
| 1270 bool as_reference) { | 1273 bool as_reference) { |
| 1271 ASSERT(writer != NULL); | 1274 ASSERT(writer != NULL); |
| (...skipping 2423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3695 // We do not allow objects with native fields in an isolate message. | 3698 // We do not allow objects with native fields in an isolate message. |
| 3696 writer->SetWriteException(Exceptions::kArgument, | 3699 writer->SetWriteException(Exceptions::kArgument, |
| 3697 "Illegal argument in isolate message" | 3700 "Illegal argument in isolate message" |
| 3698 " : (object is a UserTag)"); | 3701 " : (object is a UserTag)"); |
| 3699 } else { | 3702 } else { |
| 3700 UNREACHABLE(); | 3703 UNREACHABLE(); |
| 3701 } | 3704 } |
| 3702 } | 3705 } |
| 3703 | 3706 |
| 3704 } // namespace dart | 3707 } // namespace dart |
| OLD | NEW |