| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 241 |
| 242 // Write out all the object pointer fields. | 242 // Write out all the object pointer fields. |
| 243 visitor.VisitPointers(from(), to()); | 243 visitor.VisitPointers(from(), to()); |
| 244 } | 244 } |
| 245 | 245 |
| 246 | 246 |
| 247 RawInstantiatedType* InstantiatedType::ReadFrom(SnapshotReader* reader, | 247 RawInstantiatedType* InstantiatedType::ReadFrom(SnapshotReader* reader, |
| 248 intptr_t object_id, | 248 intptr_t object_id, |
| 249 Snapshot::Kind kind) { | 249 Snapshot::Kind kind) { |
| 250 ASSERT(reader != NULL); | 250 ASSERT(reader != NULL); |
| 251 ASSERT(kind == Snapshot::kMessage); |
| 251 | 252 |
| 252 // Allocate instantiated type object. | 253 // Allocate instantiated type object. |
| 253 InstantiatedType& instantiated_type = | 254 InstantiatedType& instantiated_type = |
| 254 InstantiatedType::ZoneHandle(InstantiatedType::New()); | 255 InstantiatedType::ZoneHandle(InstantiatedType::New()); |
| 255 reader->AddBackwardReference(object_id, &instantiated_type); | 256 reader->AddBackwardReference(object_id, &instantiated_type); |
| 256 | 257 |
| 257 // Now set all the object fields. | 258 // Now set all the object fields. |
| 258 // TODO(5411462): Need to assert No GC can happen here, even though | 259 // TODO(5411462): Need to assert No GC can happen here, even though |
| 259 // allocations may happen. | 260 // allocations may happen. |
| 260 intptr_t num_flds = (instantiated_type.raw()->to() - | 261 intptr_t num_flds = (instantiated_type.raw()->to() - |
| 261 instantiated_type.raw()->from()); | 262 instantiated_type.raw()->from()); |
| 262 for (intptr_t i = 0; i <= num_flds; i++) { | 263 for (intptr_t i = 0; i <= num_flds; i++) { |
| 263 *(instantiated_type.raw()->from() + i) = reader->ReadObject(); | 264 *(instantiated_type.raw()->from() + i) = reader->ReadObject(); |
| 264 } | 265 } |
| 265 return instantiated_type.raw(); | 266 return instantiated_type.raw(); |
| 266 } | 267 } |
| 267 | 268 |
| 268 | 269 |
| 269 void RawInstantiatedType::WriteTo(SnapshotWriter* writer, | 270 void RawInstantiatedType::WriteTo(SnapshotWriter* writer, |
| 270 intptr_t object_id, | 271 intptr_t object_id, |
| 271 Snapshot::Kind kind) { | 272 Snapshot::Kind kind) { |
| 272 ASSERT(writer != NULL); | 273 ASSERT(writer != NULL); |
| 274 ASSERT(kind == Snapshot::kMessage); |
| 273 SnapshotWriterVisitor visitor(writer); | 275 SnapshotWriterVisitor visitor(writer); |
| 274 | 276 |
| 275 // Write out the serialization header value for this object. | 277 // Write out the serialization header value for this object. |
| 276 writer->WriteObjectHeader(kInlined, object_id); | 278 writer->WriteObjectHeader(kInlined, object_id); |
| 277 | 279 |
| 278 // Write out the class information. | 280 // Write out the class information. |
| 279 writer->WriteObjectHeader(kObjectId, Object::kInstantiatedTypeClass); | 281 writer->WriteObjectHeader(kObjectId, Object::kInstantiatedTypeClass); |
| 280 | 282 |
| 281 // Write out all the object pointer fields. | 283 // Write out all the object pointer fields. |
| 282 visitor.VisitPointers(from(), to()); | 284 visitor.VisitPointers(from(), to()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 writer->WriteObject(ptr()->types_[i]); | 346 writer->WriteObject(ptr()->types_[i]); |
| 345 } | 347 } |
| 346 } | 348 } |
| 347 | 349 |
| 348 | 350 |
| 349 RawInstantiatedTypeArguments* InstantiatedTypeArguments::ReadFrom( | 351 RawInstantiatedTypeArguments* InstantiatedTypeArguments::ReadFrom( |
| 350 SnapshotReader* reader, | 352 SnapshotReader* reader, |
| 351 intptr_t object_id, | 353 intptr_t object_id, |
| 352 Snapshot::Kind kind) { | 354 Snapshot::Kind kind) { |
| 353 ASSERT(reader != NULL); | 355 ASSERT(reader != NULL); |
| 356 ASSERT(kind == Snapshot::kMessage); |
| 354 | 357 |
| 355 // Allocate instantiated types object. | 358 // Allocate instantiated types object. |
| 356 InstantiatedTypeArguments& instantiated_type_arguments = | 359 InstantiatedTypeArguments& instantiated_type_arguments = |
| 357 InstantiatedTypeArguments::ZoneHandle(InstantiatedTypeArguments::New()); | 360 InstantiatedTypeArguments::ZoneHandle(InstantiatedTypeArguments::New()); |
| 358 reader->AddBackwardReference(object_id, &instantiated_type_arguments); | 361 reader->AddBackwardReference(object_id, &instantiated_type_arguments); |
| 359 | 362 |
| 360 // Set all the object fields. | 363 // Set all the object fields. |
| 361 // TODO(5411462): Need to assert No GC can happen here, even though | 364 // TODO(5411462): Need to assert No GC can happen here, even though |
| 362 // allocations may happen. | 365 // allocations may happen. |
| 363 intptr_t num_flds = (instantiated_type_arguments.raw()->to() - | 366 intptr_t num_flds = (instantiated_type_arguments.raw()->to() - |
| 364 instantiated_type_arguments.raw()->from()); | 367 instantiated_type_arguments.raw()->from()); |
| 365 for (intptr_t i = 0; i <= num_flds; i++) { | 368 for (intptr_t i = 0; i <= num_flds; i++) { |
| 366 *(instantiated_type_arguments.raw()->from() + i) = reader->ReadObject(); | 369 *(instantiated_type_arguments.raw()->from() + i) = reader->ReadObject(); |
| 367 } | 370 } |
| 368 return instantiated_type_arguments.raw(); | 371 return instantiated_type_arguments.raw(); |
| 369 } | 372 } |
| 370 | 373 |
| 371 | 374 |
| 372 void RawInstantiatedTypeArguments::WriteTo(SnapshotWriter* writer, | 375 void RawInstantiatedTypeArguments::WriteTo(SnapshotWriter* writer, |
| 373 intptr_t object_id, | 376 intptr_t object_id, |
| 374 Snapshot::Kind kind) { | 377 Snapshot::Kind kind) { |
| 375 ASSERT(writer != NULL); | 378 ASSERT(writer != NULL); |
| 379 ASSERT(kind == Snapshot::kMessage); |
| 376 SnapshotWriterVisitor visitor(writer); | 380 SnapshotWriterVisitor visitor(writer); |
| 377 | 381 |
| 378 // Write out the serialization header value for this object. | 382 // Write out the serialization header value for this object. |
| 379 writer->WriteObjectHeader(kInlined, object_id); | 383 writer->WriteObjectHeader(kInlined, object_id); |
| 380 | 384 |
| 381 // Write out the class information. | 385 // Write out the class information. |
| 382 writer->WriteObjectHeader(kObjectId, Object::kInstantiatedTypeArgumentsClass); | 386 writer->WriteObjectHeader(kObjectId, Object::kInstantiatedTypeArgumentsClass); |
| 383 | 387 |
| 384 // Write out all the object pointer fields. | 388 // Write out all the object pointer fields. |
| 385 visitor.VisitPointers(from(), to()); | 389 visitor.VisitPointers(from(), to()); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 | 795 |
| 792 // Write out all the object pointer fields. | 796 // Write out all the object pointer fields. |
| 793 visitor.VisitPointers(from(), to(ptr()->num_variables_)); | 797 visitor.VisitPointers(from(), to(ptr()->num_variables_)); |
| 794 } | 798 } |
| 795 | 799 |
| 796 | 800 |
| 797 RawContextScope* ContextScope::ReadFrom(SnapshotReader* reader, | 801 RawContextScope* ContextScope::ReadFrom(SnapshotReader* reader, |
| 798 intptr_t object_id, | 802 intptr_t object_id, |
| 799 Snapshot::Kind kind) { | 803 Snapshot::Kind kind) { |
| 800 ASSERT(reader != NULL); | 804 ASSERT(reader != NULL); |
| 805 ASSERT(kind == Snapshot::kMessage); |
| 801 | 806 |
| 802 // Allocate context scope object. | 807 // Allocate context scope object. |
| 803 intptr_t num_vars = reader->Read<intptr_t>(); | 808 intptr_t num_vars = reader->Read<intptr_t>(); |
| 804 ContextScope& scope = ContextScope::ZoneHandle(ContextScope::New(num_vars)); | 809 ContextScope& scope = ContextScope::ZoneHandle(ContextScope::New(num_vars)); |
| 805 reader->AddBackwardReference(object_id, &scope); | 810 reader->AddBackwardReference(object_id, &scope); |
| 806 | 811 |
| 807 // Set all the object fields. | 812 // Set all the object fields. |
| 808 // TODO(5411462): Need to assert No GC can happen here, even though | 813 // TODO(5411462): Need to assert No GC can happen here, even though |
| 809 // allocations may happen. | 814 // allocations may happen. |
| 810 intptr_t num_flds = (scope.raw()->to(num_vars) - scope.raw()->from()); | 815 intptr_t num_flds = (scope.raw()->to(num_vars) - scope.raw()->from()); |
| 811 for (intptr_t i = 0; i <= num_flds; i++) { | 816 for (intptr_t i = 0; i <= num_flds; i++) { |
| 812 *(scope.raw()->from() + i) = reader->ReadObject(); | 817 *(scope.raw()->from() + i) = reader->ReadObject(); |
| 813 } | 818 } |
| 814 | 819 |
| 815 return scope.raw(); | 820 return scope.raw(); |
| 816 } | 821 } |
| 817 | 822 |
| 818 | 823 |
| 819 void RawContextScope::WriteTo(SnapshotWriter* writer, | 824 void RawContextScope::WriteTo(SnapshotWriter* writer, |
| 820 intptr_t object_id, | 825 intptr_t object_id, |
| 821 Snapshot::Kind kind) { | 826 Snapshot::Kind kind) { |
| 822 ASSERT(writer != NULL); | 827 ASSERT(writer != NULL); |
| 828 ASSERT(kind == Snapshot::kMessage); |
| 823 SnapshotWriterVisitor visitor(writer); | 829 SnapshotWriterVisitor visitor(writer); |
| 824 | 830 |
| 825 // Write out the serialization header value for this object. | 831 // Write out the serialization header value for this object. |
| 826 writer->WriteObjectHeader(kInlined, object_id); | 832 writer->WriteObjectHeader(kInlined, object_id); |
| 827 | 833 |
| 828 // Write out the class information. | 834 // Write out the class information. |
| 829 writer->WriteObjectHeader(kObjectId, Object::kContextScopeClass); | 835 writer->WriteObjectHeader(kObjectId, Object::kContextScopeClass); |
| 830 | 836 |
| 831 // Serialize number of variables. | 837 // Serialize number of variables. |
| 832 writer->Write<intptr_t>(ptr()->num_variables_); | 838 writer->Write<intptr_t>(ptr()->num_variables_); |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 intptr_t object_id, | 1343 intptr_t object_id, |
| 1338 Snapshot::Kind kind) { | 1344 Snapshot::Kind kind) { |
| 1339 UNIMPLEMENTED(); | 1345 UNIMPLEMENTED(); |
| 1340 } | 1346 } |
| 1341 | 1347 |
| 1342 | 1348 |
| 1343 RawJSRegExp* JSRegExp::ReadFrom(SnapshotReader* reader, | 1349 RawJSRegExp* JSRegExp::ReadFrom(SnapshotReader* reader, |
| 1344 intptr_t object_id, | 1350 intptr_t object_id, |
| 1345 Snapshot::Kind kind) { | 1351 Snapshot::Kind kind) { |
| 1346 ASSERT(reader != NULL); | 1352 ASSERT(reader != NULL); |
| 1353 ASSERT(kind == Snapshot::kMessage); |
| 1347 | 1354 |
| 1348 // Read the length so that we can determine instance size to allocate. | 1355 // Read the length so that we can determine instance size to allocate. |
| 1349 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); | 1356 RawSmi* smi_len = GetSmi(reader->Read<intptr_t>()); |
| 1350 intptr_t len = Smi::Value(smi_len); | 1357 intptr_t len = Smi::Value(smi_len); |
| 1351 | 1358 |
| 1352 // Allocate JSRegExp object. | 1359 // Allocate JSRegExp object. |
| 1353 JSRegExp& regex = JSRegExp::ZoneHandle( | 1360 JSRegExp& regex = JSRegExp::ZoneHandle( |
| 1354 JSRegExp::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); | 1361 JSRegExp::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); |
| 1355 reader->AddBackwardReference(object_id, ®ex); | 1362 reader->AddBackwardReference(object_id, ®ex); |
| 1356 | 1363 |
| 1357 // Read and Set all the other fields. | 1364 // Read and Set all the other fields. |
| 1358 regex.raw_ptr()->num_bracket_expressions_ = GetSmi(reader->Read<intptr_t>()); | 1365 regex.raw_ptr()->num_bracket_expressions_ = GetSmi(reader->Read<intptr_t>()); |
| 1359 String& pattern = String::Handle(); | 1366 String& pattern = String::Handle(); |
| 1360 pattern ^= reader->ReadObject(); | 1367 pattern ^= reader->ReadObject(); |
| 1361 regex.raw_ptr()->pattern_ = pattern.raw(); | 1368 regex.raw_ptr()->pattern_ = pattern.raw(); |
| 1362 regex.raw_ptr()->type_ = reader->Read<intptr_t>(); | 1369 regex.raw_ptr()->type_ = reader->Read<intptr_t>(); |
| 1363 regex.raw_ptr()->flags_ = reader->Read<intptr_t>(); | 1370 regex.raw_ptr()->flags_ = reader->Read<intptr_t>(); |
| 1364 | 1371 |
| 1365 // TODO(5411462): Need to implement a way of recompiling the regex. | 1372 // TODO(5411462): Need to implement a way of recompiling the regex. |
| 1366 | 1373 |
| 1367 return regex.raw(); | 1374 return regex.raw(); |
| 1368 } | 1375 } |
| 1369 | 1376 |
| 1370 | 1377 |
| 1371 void RawJSRegExp::WriteTo(SnapshotWriter* writer, | 1378 void RawJSRegExp::WriteTo(SnapshotWriter* writer, |
| 1372 intptr_t object_id, | 1379 intptr_t object_id, |
| 1373 Snapshot::Kind kind) { | 1380 Snapshot::Kind kind) { |
| 1374 ASSERT(writer != NULL); | 1381 ASSERT(writer != NULL); |
| 1382 ASSERT(kind == Snapshot::kMessage); |
| 1375 | 1383 |
| 1376 // Write out the serialization header value for this object. | 1384 // Write out the serialization header value for this object. |
| 1377 writer->WriteObjectHeader(kInlined, object_id); | 1385 writer->WriteObjectHeader(kInlined, object_id); |
| 1378 | 1386 |
| 1379 // Write out the class information. | 1387 // Write out the class information. |
| 1380 writer->WriteObjectHeader(kObjectId, ObjectStore::kJSRegExpClass); | 1388 writer->WriteObjectHeader(kObjectId, ObjectStore::kJSRegExpClass); |
| 1381 | 1389 |
| 1382 // Write out the data length field. | 1390 // Write out the data length field. |
| 1383 writer->Write<RawObject*>(ptr()->data_length_); | 1391 writer->Write<RawObject*>(ptr()->data_length_); |
| 1384 | 1392 |
| 1385 // Write out all the other fields. | 1393 // Write out all the other fields. |
| 1386 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); | 1394 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); |
| 1387 writer->WriteObject(ptr()->pattern_); | 1395 writer->WriteObject(ptr()->pattern_); |
| 1388 writer->Write<intptr_t>(ptr()->type_); | 1396 writer->Write<intptr_t>(ptr()->type_); |
| 1389 writer->Write<intptr_t>(ptr()->flags_); | 1397 writer->Write<intptr_t>(ptr()->flags_); |
| 1390 | 1398 |
| 1391 // Do not write out the data part which is native. | 1399 // Do not write out the data part which is native. |
| 1392 } | 1400 } |
| 1393 | 1401 |
| 1394 } // namespace dart | 1402 } // namespace dart |
| OLD | NEW |