| 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 #include "vm/bigint_operations.h" | 5 #include "vm/bigint_operations.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/visitor.h" | 9 #include "vm/visitor.h" |
| 10 | 10 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 bool classes_serialized) { | 306 bool classes_serialized) { |
| 307 ASSERT(reader != NULL); | 307 ASSERT(reader != NULL); |
| 308 | 308 |
| 309 // Read the length so that we can determine instance size to allocate. | 309 // Read the length so that we can determine instance size to allocate. |
| 310 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | 310 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); |
| 311 intptr_t len = Smi::Value(smi_len); | 311 intptr_t len = Smi::Value(smi_len); |
| 312 | 312 |
| 313 TypeArray& type_array = TypeArray::Handle(TypeArray::New(len)); | 313 TypeArray& type_array = TypeArray::Handle(TypeArray::New(len)); |
| 314 reader->AddBackwardReference(object_id, &type_array); | 314 reader->AddBackwardReference(object_id, &type_array); |
| 315 Type& type = Type::Handle(); | 315 Type& type = Type::Handle(); |
| 316 for (int i = 0; i < len; i++) { | 316 for (intptr_t i = 0; i < len; i++) { |
| 317 type ^= reader->ReadObject(); | 317 type ^= reader->ReadObject(); |
| 318 type_array.SetTypeAt(i, type); | 318 type_array.SetTypeAt(i, type); |
| 319 } | 319 } |
| 320 return type_array.raw(); | 320 return type_array.raw(); |
| 321 } | 321 } |
| 322 | 322 |
| 323 | 323 |
| 324 void RawTypeArray::WriteTo(SnapshotWriter* writer, | 324 void RawTypeArray::WriteTo(SnapshotWriter* writer, |
| 325 intptr_t object_id, | 325 intptr_t object_id, |
| 326 bool serialize_classes) { | 326 bool serialize_classes) { |
| 327 ASSERT(writer != NULL); | 327 ASSERT(writer != NULL); |
| 328 | 328 |
| 329 // Write out the serialization header value for this object. | 329 // Write out the serialization header value for this object. |
| 330 writer->WriteObjectHeader(kInlined, object_id); | 330 writer->WriteObjectHeader(kInlined, object_id); |
| 331 | 331 |
| 332 // Write out the class information. | 332 // Write out the class information. |
| 333 writer->WriteObjectHeader(kObjectId, Object::kTypeArrayClass); | 333 writer->WriteObjectHeader(kObjectId, Object::kTypeArrayClass); |
| 334 | 334 |
| 335 // Write out the length field. | 335 // Write out the length field. |
| 336 writer->Write<RawObject*>(ptr()->length_); | 336 writer->Write<RawObject*>(ptr()->length_); |
| 337 | 337 |
| 338 // Write out the individual types. | 338 // Write out the individual types. |
| 339 intptr_t len = Smi::Value(ptr()->length_); | 339 intptr_t len = Smi::Value(ptr()->length_); |
| 340 for (int i = 0; i < len; i++) { | 340 for (intptr_t i = 0; i < len; i++) { |
| 341 writer->WriteObject(ptr()->types_[i]); | 341 writer->WriteObject(ptr()->types_[i]); |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 | 344 |
| 345 | 345 |
| 346 RawInstantiatedTypeArguments* InstantiatedTypeArguments::ReadFrom( | 346 RawInstantiatedTypeArguments* InstantiatedTypeArguments::ReadFrom( |
| 347 SnapshotReader* reader, | 347 SnapshotReader* reader, |
| 348 intptr_t object_id, | 348 intptr_t object_id, |
| 349 bool classes_serialized) { | 349 bool classes_serialized) { |
| 350 ASSERT(reader != NULL); | 350 ASSERT(reader != NULL); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 // Read the length so that we can determine number of tokens to read. | 500 // Read the length so that we can determine number of tokens to read. |
| 501 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | 501 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); |
| 502 intptr_t len = Smi::Value(smi_len); | 502 intptr_t len = Smi::Value(smi_len); |
| 503 | 503 |
| 504 // Create the token stream object. | 504 // Create the token stream object. |
| 505 TokenStream& token_stream = TokenStream::ZoneHandle(TokenStream::New(len)); | 505 TokenStream& token_stream = TokenStream::ZoneHandle(TokenStream::New(len)); |
| 506 reader->AddBackwardReference(object_id, &token_stream); | 506 reader->AddBackwardReference(object_id, &token_stream); |
| 507 | 507 |
| 508 // Read the token stream into the TokenStream. | 508 // Read the token stream into the TokenStream. |
| 509 String& literal = String::Handle(); | 509 String& literal = String::Handle(); |
| 510 for (int i = 0; i < len; i++) { | 510 for (intptr_t i = 0; i < len; i++) { |
| 511 Token::Kind kind = static_cast<Token::Kind>( | 511 Token::Kind kind = static_cast<Token::Kind>( |
| 512 Smi::Value(GetSmi(reader->Read<intptr_t>()))); | 512 Smi::Value(GetSmi(reader->Read<intptr_t>()))); |
| 513 literal ^= reader->ReadObject(); | 513 literal ^= reader->ReadObject(); |
| 514 token_stream.SetTokenAt(i, kind, literal); | 514 token_stream.SetTokenAt(i, kind, literal); |
| 515 } | 515 } |
| 516 return token_stream.raw(); | 516 return token_stream.raw(); |
| 517 } | 517 } |
| 518 | 518 |
| 519 | 519 |
| 520 void RawTokenStream::WriteTo(SnapshotWriter* writer, | 520 void RawTokenStream::WriteTo(SnapshotWriter* writer, |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 // Write out the class information. | 1025 // Write out the class information. |
| 1026 writer->WriteObjectHeader(kObjectId, ObjectStore::kOneByteStringClass); | 1026 writer->WriteObjectHeader(kObjectId, ObjectStore::kOneByteStringClass); |
| 1027 | 1027 |
| 1028 // Write out the length field. | 1028 // Write out the length field. |
| 1029 writer->Write<RawObject*>(ptr()->length_); | 1029 writer->Write<RawObject*>(ptr()->length_); |
| 1030 | 1030 |
| 1031 // Write out the hash field. | 1031 // Write out the hash field. |
| 1032 writer->Write<RawObject*>(ptr()->hash_); | 1032 writer->Write<RawObject*>(ptr()->hash_); |
| 1033 | 1033 |
| 1034 // Write out the string. | 1034 // Write out the string. |
| 1035 for (int i = 0; i < len; i++) { | 1035 for (intptr_t i = 0; i < len; i++) { |
| 1036 writer->Write<uint8_t>(ptr()->data_[i]); | 1036 writer->Write<uint8_t>(ptr()->data_[i]); |
| 1037 } | 1037 } |
| 1038 } | 1038 } |
| 1039 | 1039 |
| 1040 | 1040 |
| 1041 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, | 1041 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, |
| 1042 intptr_t object_id, | 1042 intptr_t object_id, |
| 1043 bool classes_serialized) { | 1043 bool classes_serialized) { |
| 1044 ASSERT(reader != NULL); | 1044 ASSERT(reader != NULL); |
| 1045 // Read the length so that we can determine instance size to allocate. | 1045 // Read the length so that we can determine instance size to allocate. |
| 1046 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | 1046 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); |
| 1047 intptr_t len = Smi::Value(smi_len); | 1047 intptr_t len = Smi::Value(smi_len); |
| 1048 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>()); | 1048 RawSmi* smi_hash = GetSmi(reader->Read<intptr_t>()); |
| 1049 | 1049 |
| 1050 // Set up the two byte string object. | 1050 // Set up the two byte string object. |
| 1051 TwoByteString& str_obj = TwoByteString::ZoneHandle( | 1051 TwoByteString& str_obj = TwoByteString::ZoneHandle( |
| 1052 TwoByteString::New(len, classes_serialized ? Heap::kOld : Heap::kNew)); | 1052 TwoByteString::New(len, classes_serialized ? Heap::kOld : Heap::kNew)); |
| 1053 for (int i = 0; i < len; i++) { | 1053 for (intptr_t i = 0; i < len; i++) { |
| 1054 *str_obj.CharAddr(i) = reader->Read<uint16_t>(); | 1054 *str_obj.CharAddr(i) = reader->Read<uint16_t>(); |
| 1055 } | 1055 } |
| 1056 | 1056 |
| 1057 reader->AddBackwardReference(object_id, &str_obj); | 1057 reader->AddBackwardReference(object_id, &str_obj); |
| 1058 RawTwoByteString* raw_str = str_obj.raw(); | 1058 RawTwoByteString* raw_str = str_obj.raw(); |
| 1059 raw_str->ptr()->hash_ = smi_hash; | 1059 raw_str->ptr()->hash_ = smi_hash; |
| 1060 return str_obj.raw(); | 1060 return str_obj.raw(); |
| 1061 } | 1061 } |
| 1062 | 1062 |
| 1063 | 1063 |
| 1064 void RawTwoByteString::WriteTo(SnapshotWriter* writer, | 1064 void RawTwoByteString::WriteTo(SnapshotWriter* writer, |
| 1065 intptr_t object_id, | 1065 intptr_t object_id, |
| 1066 bool serialize_classes) { | 1066 bool serialize_classes) { |
| 1067 ASSERT(writer != NULL); | 1067 ASSERT(writer != NULL); |
| 1068 intptr_t len = Smi::Value(ptr()->length_); | 1068 intptr_t len = Smi::Value(ptr()->length_); |
| 1069 | 1069 |
| 1070 // Write out the serialization header value for this object. | 1070 // Write out the serialization header value for this object. |
| 1071 writer->WriteObjectHeader(kInlined, object_id); | 1071 writer->WriteObjectHeader(kInlined, object_id); |
| 1072 | 1072 |
| 1073 // Write out the class information. | 1073 // Write out the class information. |
| 1074 writer->WriteObjectHeader(kObjectId, ObjectStore::kTwoByteStringClass); | 1074 writer->WriteObjectHeader(kObjectId, ObjectStore::kTwoByteStringClass); |
| 1075 | 1075 |
| 1076 // Write out the length field. | 1076 // Write out the length field. |
| 1077 writer->Write<RawObject*>(ptr()->length_); | 1077 writer->Write<RawObject*>(ptr()->length_); |
| 1078 | 1078 |
| 1079 // Write out the hash field. | 1079 // Write out the hash field. |
| 1080 writer->Write<RawObject*>(ptr()->hash_); | 1080 writer->Write<RawObject*>(ptr()->hash_); |
| 1081 | 1081 |
| 1082 // Write out the string. | 1082 // Write out the string. |
| 1083 for (int i = 0; i < len; i++) { | 1083 for (intptr_t i = 0; i < len; i++) { |
| 1084 writer->Write<uint16_t>(ptr()->data_[i]); | 1084 writer->Write<uint16_t>(ptr()->data_[i]); |
| 1085 } | 1085 } |
| 1086 } | 1086 } |
| 1087 | 1087 |
| 1088 | 1088 |
| 1089 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, | 1089 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, |
| 1090 intptr_t object_id, | 1090 intptr_t object_id, |
| 1091 bool classes_serialized) { | 1091 bool classes_serialized) { |
| 1092 ASSERT(reader != NULL); | 1092 ASSERT(reader != NULL); |
| 1093 // Read the length so that we can determine instance size to allocate. | 1093 // Read the length so that we can determine instance size to allocate. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1121 // Write out the class information. | 1121 // Write out the class information. |
| 1122 writer->WriteObjectHeader(kObjectId, ObjectStore::kFourByteStringClass); | 1122 writer->WriteObjectHeader(kObjectId, ObjectStore::kFourByteStringClass); |
| 1123 | 1123 |
| 1124 // Write out the length field. | 1124 // Write out the length field. |
| 1125 writer->Write<RawObject*>(ptr()->length_); | 1125 writer->Write<RawObject*>(ptr()->length_); |
| 1126 | 1126 |
| 1127 // Write out the hash field. | 1127 // Write out the hash field. |
| 1128 writer->Write<RawObject*>(ptr()->hash_); | 1128 writer->Write<RawObject*>(ptr()->hash_); |
| 1129 | 1129 |
| 1130 // Write out the string. | 1130 // Write out the string. |
| 1131 for (int i = 0; i < len; i++) { | 1131 for (intptr_t i = 0; i < len; i++) { |
| 1132 writer->Write<uint32_t>(ptr()->data_[i]); | 1132 writer->Write<uint32_t>(ptr()->data_[i]); |
| 1133 } | 1133 } |
| 1134 } | 1134 } |
| 1135 | 1135 |
| 1136 | 1136 |
| 1137 RawBool* Bool::ReadFrom(SnapshotReader* reader, | 1137 RawBool* Bool::ReadFrom(SnapshotReader* reader, |
| 1138 intptr_t object_id, | 1138 intptr_t object_id, |
| 1139 bool classes_serialized) { | 1139 bool classes_serialized) { |
| 1140 UNREACHABLE(); | 1140 UNREACHABLE(); |
| 1141 return Bool::null(); | 1141 return Bool::null(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1160 intptr_t len = Smi::Value(smi_len); | 1160 intptr_t len = Smi::Value(smi_len); |
| 1161 T& result = T::Handle(T::New(len, | 1161 T& result = T::Handle(T::New(len, |
| 1162 classes_serialized ? Heap::kOld : Heap::kNew)); | 1162 classes_serialized ? Heap::kOld : Heap::kNew)); |
| 1163 reader->AddBackwardReference(object_id, &result); | 1163 reader->AddBackwardReference(object_id, &result); |
| 1164 | 1164 |
| 1165 TypeArguments& type_arguments = TypeArguments::Handle(); | 1165 TypeArguments& type_arguments = TypeArguments::Handle(); |
| 1166 type_arguments ^= reader->ReadObject(); | 1166 type_arguments ^= reader->ReadObject(); |
| 1167 result.SetTypeArguments(type_arguments); | 1167 result.SetTypeArguments(type_arguments); |
| 1168 | 1168 |
| 1169 Object& obj = Object::Handle(); | 1169 Object& obj = Object::Handle(); |
| 1170 for (int i = 0; i < len; i++) { | 1170 for (intptr_t i = 0; i < len; i++) { |
| 1171 obj = reader->ReadObject(); | 1171 obj = reader->ReadObject(); |
| 1172 result.SetAt(i, obj); | 1172 result.SetAt(i, obj); |
| 1173 } | 1173 } |
| 1174 return result.raw(); | 1174 return result.raw(); |
| 1175 } | 1175 } |
| 1176 | 1176 |
| 1177 | 1177 |
| 1178 RawArray* Array::ReadFrom(SnapshotReader* reader, | 1178 RawArray* Array::ReadFrom(SnapshotReader* reader, |
| 1179 intptr_t object_id, | 1179 intptr_t object_id, |
| 1180 bool classes_serialized) { | 1180 bool classes_serialized) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1208 // Write out the class information. | 1208 // Write out the class information. |
| 1209 writer->WriteObjectHeader(kObjectId, kind); | 1209 writer->WriteObjectHeader(kObjectId, kind); |
| 1210 | 1210 |
| 1211 // Write out the length field. | 1211 // Write out the length field. |
| 1212 writer->Write<RawObject*>(length); | 1212 writer->Write<RawObject*>(length); |
| 1213 | 1213 |
| 1214 // Write out the type arguments. | 1214 // Write out the type arguments. |
| 1215 writer->WriteObject(type_arguments); | 1215 writer->WriteObject(type_arguments); |
| 1216 | 1216 |
| 1217 // Write out the individual objects. | 1217 // Write out the individual objects. |
| 1218 for (int i = 0; i < len; i++) { | 1218 for (intptr_t i = 0; i < len; i++) { |
| 1219 writer->WriteObject(data[i]); | 1219 writer->WriteObject(data[i]); |
| 1220 } | 1220 } |
| 1221 } | 1221 } |
| 1222 | 1222 |
| 1223 | 1223 |
| 1224 void RawArray::WriteTo(SnapshotWriter* writer, | 1224 void RawArray::WriteTo(SnapshotWriter* writer, |
| 1225 intptr_t object_id, | 1225 intptr_t object_id, |
| 1226 bool serialize_classes) { | 1226 bool serialize_classes) { |
| 1227 ArrayWriteTo(writer, | 1227 ArrayWriteTo(writer, |
| 1228 object_id, | 1228 object_id, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 // Write out all the other fields. | 1322 // Write out all the other fields. |
| 1323 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); | 1323 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); |
| 1324 writer->WriteObject(ptr()->pattern_); | 1324 writer->WriteObject(ptr()->pattern_); |
| 1325 writer->Write<intptr_t>(ptr()->type_); | 1325 writer->Write<intptr_t>(ptr()->type_); |
| 1326 writer->Write<intptr_t>(ptr()->flags_); | 1326 writer->Write<intptr_t>(ptr()->flags_); |
| 1327 | 1327 |
| 1328 // Do not write out the data part which is native. | 1328 // Do not write out the data part which is native. |
| 1329 } | 1329 } |
| 1330 | 1330 |
| 1331 } // namespace dart | 1331 } // namespace dart |
| OLD | NEW |