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/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/symbols.h" | 9 #include "vm/symbols.h" |
10 #include "vm/visitor.h" | 10 #include "vm/visitor.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 #define NEW_OBJECT(type) \ | 14 #define NEW_OBJECT(type) \ |
15 ((kind == Snapshot::kFull) ? reader->New##type() : type::New()) | 15 ((kind == Snapshot::kFull) ? reader->New##type() : type::New()) |
16 | 16 |
17 #define NEW_OBJECT_WITH_LEN(type, len) \ | 17 #define NEW_OBJECT_WITH_LEN(type, len) \ |
18 ((kind == Snapshot::kFull) ? reader->New##type(len) : type::New(len)) | 18 ((kind == Snapshot::kFull) ? reader->New##type(len) : type::New(len)) |
19 | 19 |
20 #define NEW_OBJECT_WITH_LEN_SPACE(type, len, kind) \ | |
21 ((kind == Snapshot::kFull) ? \ | |
22 reader->New##type(len) : type::New(len, space(kind))) | |
23 | |
20 | 24 |
21 static uword BigintAllocator(intptr_t size) { | 25 static uword BigintAllocator(intptr_t size) { |
22 Zone* zone = Isolate::Current()->current_zone(); | 26 Zone* zone = Isolate::Current()->current_zone(); |
23 return zone->AllocUnsafe(size); | 27 return zone->AllocUnsafe(size); |
24 } | 28 } |
25 | 29 |
26 | 30 |
31 static Heap::Space space(Snapshot::Kind kind) { | |
32 return (kind == Snapshot::kMessage) ? Heap::kNew : Heap::kOld; | |
33 } | |
34 | |
35 | |
27 RawClass* Class::ReadFrom(SnapshotReader* reader, | 36 RawClass* Class::ReadFrom(SnapshotReader* reader, |
28 intptr_t object_id, | 37 intptr_t object_id, |
29 intptr_t tags, | 38 intptr_t tags, |
30 Snapshot::Kind kind) { | 39 Snapshot::Kind kind) { |
31 ASSERT(reader != NULL); | 40 ASSERT(reader != NULL); |
32 | 41 |
33 Class& cls = Class::ZoneHandle(reader->isolate(), Class::null()); | 42 Class& cls = Class::ZoneHandle(reader->isolate(), Class::null()); |
34 if ((kind == Snapshot::kFull) || | 43 if ((kind == Snapshot::kFull) || |
35 (kind == Snapshot::kScript && !RawObject::IsCreatedFromSnapshot(tags))) { | 44 (kind == Snapshot::kScript && !RawObject::IsCreatedFromSnapshot(tags))) { |
36 // Read in the base information. | 45 // Read in the base information. |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 RawTypeArguments* TypeArguments::ReadFrom(SnapshotReader* reader, | 319 RawTypeArguments* TypeArguments::ReadFrom(SnapshotReader* reader, |
311 intptr_t object_id, | 320 intptr_t object_id, |
312 intptr_t tags, | 321 intptr_t tags, |
313 Snapshot::Kind kind) { | 322 Snapshot::Kind kind) { |
314 ASSERT(reader != NULL); | 323 ASSERT(reader != NULL); |
315 | 324 |
316 // Read the length so that we can determine instance size to allocate. | 325 // Read the length so that we can determine instance size to allocate. |
317 intptr_t len = reader->ReadSmiValue(); | 326 intptr_t len = reader->ReadSmiValue(); |
318 | 327 |
319 TypeArguments& type_arguments = TypeArguments::ZoneHandle( | 328 TypeArguments& type_arguments = TypeArguments::ZoneHandle( |
320 reader->isolate(), NEW_OBJECT_WITH_LEN(TypeArguments, len)); | 329 reader->isolate(), NEW_OBJECT_WITH_LEN_SPACE(TypeArguments, len, kind)); |
321 reader->AddBackRef(object_id, &type_arguments, kIsDeserialized); | 330 reader->AddBackRef(object_id, &type_arguments, kIsDeserialized); |
322 | 331 |
323 // Now set all the object fields. | 332 // Now set all the object fields. |
324 for (intptr_t i = 0; i < len; i++) { | 333 for (intptr_t i = 0; i < len; i++) { |
325 *reader->TypeHandle() ^= reader->ReadObjectImpl(); | 334 *reader->TypeHandle() ^= reader->ReadObjectImpl(); |
326 type_arguments.SetTypeAt(i, *reader->TypeHandle()); | 335 type_arguments.SetTypeAt(i, *reader->TypeHandle()); |
327 } | 336 } |
328 | 337 |
329 // Set the object tags (This is done after setting the object fields | 338 // Set the object tags (This is done after setting the object fields |
330 // because 'SetTypeAt' has an assertion to check if the object is not | 339 // because 'SetTypeAt' has an assertion to check if the object is not |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 RawInstantiatedTypeArguments* InstantiatedTypeArguments::ReadFrom( | 374 RawInstantiatedTypeArguments* InstantiatedTypeArguments::ReadFrom( |
366 SnapshotReader* reader, | 375 SnapshotReader* reader, |
367 intptr_t object_id, | 376 intptr_t object_id, |
368 intptr_t tags, | 377 intptr_t tags, |
369 Snapshot::Kind kind) { | 378 Snapshot::Kind kind) { |
370 ASSERT(reader != NULL); | 379 ASSERT(reader != NULL); |
371 ASSERT(kind == Snapshot::kMessage); | 380 ASSERT(kind == Snapshot::kMessage); |
372 | 381 |
373 // Allocate instantiated types object. | 382 // Allocate instantiated types object. |
374 InstantiatedTypeArguments& instantiated_type_arguments = | 383 InstantiatedTypeArguments& instantiated_type_arguments = |
375 InstantiatedTypeArguments::ZoneHandle(reader->isolate(), | 384 InstantiatedTypeArguments::ZoneHandle( |
cshapiro
2012/08/25 03:30:11
Perhaps I have missed something subtle, but the ch
siva
2012/08/27 17:15:21
Done.
| |
376 InstantiatedTypeArguments::New()); | 385 reader->isolate(), InstantiatedTypeArguments::New()); |
377 reader->AddBackRef(object_id, &instantiated_type_arguments, kIsDeserialized); | 386 reader->AddBackRef(object_id, &instantiated_type_arguments, kIsDeserialized); |
378 | 387 |
379 // Set the object tags. | 388 // Set the object tags. |
380 instantiated_type_arguments.set_tags(tags); | 389 instantiated_type_arguments.set_tags(tags); |
381 | 390 |
382 // Set all the object fields. | 391 // Set all the object fields. |
383 // TODO(5411462): Need to assert No GC can happen here, even though | 392 // TODO(5411462): Need to assert No GC can happen here, even though |
384 // allocations may happen. | 393 // allocations may happen. |
385 intptr_t num_flds = (instantiated_type_arguments.raw()->to() - | 394 intptr_t num_flds = (instantiated_type_arguments.raw()->to() - |
386 instantiated_type_arguments.raw()->from()); | 395 instantiated_type_arguments.raw()->from()); |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1005 intptr_t tags, | 1014 intptr_t tags, |
1006 Snapshot::Kind kind) { | 1015 Snapshot::Kind kind) { |
1007 ASSERT(reader != NULL); | 1016 ASSERT(reader != NULL); |
1008 | 1017 |
1009 // Allocate context object. | 1018 // Allocate context object. |
1010 intptr_t num_vars = reader->ReadIntptrValue(); | 1019 intptr_t num_vars = reader->ReadIntptrValue(); |
1011 Context& context = Context::ZoneHandle(reader->isolate(), Context::null()); | 1020 Context& context = Context::ZoneHandle(reader->isolate(), Context::null()); |
1012 if (kind == Snapshot::kFull) { | 1021 if (kind == Snapshot::kFull) { |
1013 context = reader->NewContext(num_vars); | 1022 context = reader->NewContext(num_vars); |
1014 } else { | 1023 } else { |
1015 context = Context::New(num_vars); | 1024 context = Context::New(num_vars, space(kind)); |
1016 } | 1025 } |
1017 reader->AddBackRef(object_id, &context, kIsDeserialized); | 1026 reader->AddBackRef(object_id, &context, kIsDeserialized); |
1018 | 1027 |
1019 // Set the object tags. | 1028 // Set the object tags. |
1020 context.set_tags(tags); | 1029 context.set_tags(tags); |
1021 | 1030 |
1022 // Set the isolate implicitly. | 1031 // Set the isolate implicitly. |
1023 context.set_isolate(Isolate::Current()); | 1032 context.set_isolate(Isolate::Current()); |
1024 | 1033 |
1025 // Set all the object fields. | 1034 // Set all the object fields. |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1302 int64_t value = reader->Read<int64_t>(); | 1311 int64_t value = reader->Read<int64_t>(); |
1303 | 1312 |
1304 // Create a Mint object or get canonical one if it is a canonical constant. | 1313 // Create a Mint object or get canonical one if it is a canonical constant. |
1305 Mint& mint = Mint::ZoneHandle(reader->isolate(), Mint::null()); | 1314 Mint& mint = Mint::ZoneHandle(reader->isolate(), Mint::null()); |
1306 if (kind == Snapshot::kFull) { | 1315 if (kind == Snapshot::kFull) { |
1307 mint = reader->NewMint(value); | 1316 mint = reader->NewMint(value); |
1308 } else { | 1317 } else { |
1309 if (RawObject::IsCanonical(tags)) { | 1318 if (RawObject::IsCanonical(tags)) { |
1310 mint = Mint::NewCanonical(value); | 1319 mint = Mint::NewCanonical(value); |
1311 } else { | 1320 } else { |
1312 mint = Mint::New(value, Heap::kNew); | 1321 mint = Mint::New(value, space(kind)); |
1313 } | 1322 } |
1314 } | 1323 } |
1315 reader->AddBackRef(object_id, &mint, kIsDeserialized); | 1324 reader->AddBackRef(object_id, &mint, kIsDeserialized); |
1316 | 1325 |
1317 // Set the object tags. | 1326 // Set the object tags. |
1318 mint.set_tags(tags); | 1327 mint.set_tags(tags); |
1319 | 1328 |
1320 return mint.raw(); | 1329 return mint.raw(); |
1321 } | 1330 } |
1322 | 1331 |
(...skipping 23 matching lines...) Expand all Loading... | |
1346 | 1355 |
1347 // Read in the HexCString representation of the bigint. | 1356 // Read in the HexCString representation of the bigint. |
1348 intptr_t len = reader->ReadIntptrValue(); | 1357 intptr_t len = reader->ReadIntptrValue(); |
1349 char* str = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | 1358 char* str = Isolate::Current()->current_zone()->Alloc<char>(len + 1); |
1350 str[len] = '\0'; | 1359 str[len] = '\0'; |
1351 reader->ReadBytes(reinterpret_cast<uint8_t*>(str), len); | 1360 reader->ReadBytes(reinterpret_cast<uint8_t*>(str), len); |
1352 | 1361 |
1353 // Create a Bigint object from HexCString. | 1362 // Create a Bigint object from HexCString. |
1354 Bigint& obj = Bigint::ZoneHandle( | 1363 Bigint& obj = Bigint::ZoneHandle( |
1355 reader->isolate(), | 1364 reader->isolate(), |
1356 (kind == Snapshot::kFull) ? reader->NewBigint(str) : | 1365 ((kind == Snapshot::kFull) ? reader->NewBigint(str) : |
1357 BigintOperations::FromHexCString(str)); | 1366 BigintOperations::FromHexCString(str, space(kind)))); |
1358 | 1367 |
1359 // If it is a canonical constant make it one. | 1368 // If it is a canonical constant make it one. |
1360 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) { | 1369 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) { |
1361 obj ^= obj.Canonicalize(); | 1370 obj ^= obj.Canonicalize(); |
1362 } | 1371 } |
1363 reader->AddBackRef(object_id, &obj, kIsDeserialized); | 1372 reader->AddBackRef(object_id, &obj, kIsDeserialized); |
1364 | 1373 |
1365 // Set the object tags. | 1374 // Set the object tags. |
1366 obj.set_tags(tags); | 1375 obj.set_tags(tags); |
1367 | 1376 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1420 double value = reader->Read<double>(); | 1429 double value = reader->Read<double>(); |
1421 | 1430 |
1422 // Create a Double object or get canonical one if it is a canonical constant. | 1431 // Create a Double object or get canonical one if it is a canonical constant. |
1423 Double& dbl = Double::ZoneHandle(reader->isolate(), Double::null()); | 1432 Double& dbl = Double::ZoneHandle(reader->isolate(), Double::null()); |
1424 if (kind == Snapshot::kFull) { | 1433 if (kind == Snapshot::kFull) { |
1425 dbl = reader->NewDouble(value); | 1434 dbl = reader->NewDouble(value); |
1426 } else { | 1435 } else { |
1427 if (RawObject::IsCanonical(tags)) { | 1436 if (RawObject::IsCanonical(tags)) { |
1428 dbl = Double::NewCanonical(value); | 1437 dbl = Double::NewCanonical(value); |
1429 } else { | 1438 } else { |
1430 dbl = Double::New(value, Heap::kNew); | 1439 dbl = Double::New(value, space(kind)); |
1431 } | 1440 } |
1432 } | 1441 } |
1433 reader->AddBackRef(object_id, &dbl, kIsDeserialized); | 1442 reader->AddBackRef(object_id, &dbl, kIsDeserialized); |
1434 | 1443 |
1435 // Set the object tags. | 1444 // Set the object tags. |
1436 dbl.set_tags(tags); | 1445 dbl.set_tags(tags); |
1437 | 1446 |
1438 return dbl.raw(); | 1447 return dbl.raw(); |
1439 } | 1448 } |
1440 | 1449 |
(...skipping 28 matching lines...) Expand all Loading... | |
1469 intptr_t object_id, | 1478 intptr_t object_id, |
1470 Snapshot::Kind kind) { | 1479 Snapshot::Kind kind) { |
1471 UNREACHABLE(); // String is an abstract class. | 1480 UNREACHABLE(); // String is an abstract class. |
1472 } | 1481 } |
1473 | 1482 |
1474 | 1483 |
1475 template<typename HandleType, typename CharacterType> | 1484 template<typename HandleType, typename CharacterType> |
1476 void String::ReadFromImpl(SnapshotReader* reader, | 1485 void String::ReadFromImpl(SnapshotReader* reader, |
1477 HandleType* str_obj, | 1486 HandleType* str_obj, |
1478 intptr_t len, | 1487 intptr_t len, |
1479 intptr_t tags) { | 1488 intptr_t tags, |
1489 Snapshot::Kind kind) { | |
1480 ASSERT(reader != NULL); | 1490 ASSERT(reader != NULL); |
1481 if (RawObject::IsCanonical(tags)) { | 1491 if (RawObject::IsCanonical(tags)) { |
1482 // Set up canonical string object. | 1492 // Set up canonical string object. |
1483 ASSERT(reader != NULL); | 1493 ASSERT(reader != NULL); |
1484 CharacterType* ptr = | 1494 CharacterType* ptr = |
1485 Isolate::Current()->current_zone()->Alloc<CharacterType>(len); | 1495 Isolate::Current()->current_zone()->Alloc<CharacterType>(len); |
1486 for (intptr_t i = 0; i < len; i++) { | 1496 for (intptr_t i = 0; i < len; i++) { |
1487 ptr[i] = reader->Read<CharacterType>(); | 1497 ptr[i] = reader->Read<CharacterType>(); |
1488 } | 1498 } |
1489 *str_obj ^= Symbols::New(ptr, len); | 1499 *str_obj ^= Symbols::New(ptr, len); |
1490 } else { | 1500 } else { |
1491 // Set up the string object. | 1501 // Set up the string object. |
1492 *str_obj = HandleType::New(len, Heap::kNew); | 1502 *str_obj = HandleType::New(len, space(kind)); |
1493 str_obj->set_tags(tags); | 1503 str_obj->set_tags(tags); |
1494 str_obj->SetHash(0); // Will get computed when needed. | 1504 str_obj->SetHash(0); // Will get computed when needed. |
1495 for (intptr_t i = 0; i < len; i++) { | 1505 for (intptr_t i = 0; i < len; i++) { |
1496 *str_obj->CharAddr(i) = reader->Read<CharacterType>(); | 1506 *str_obj->CharAddr(i) = reader->Read<CharacterType>(); |
1497 } | 1507 } |
1498 } | 1508 } |
1499 } | 1509 } |
1500 | 1510 |
1501 | 1511 |
1502 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, | 1512 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, |
(...skipping 12 matching lines...) Expand all Loading... | |
1515 RawOneByteString* obj = reader->NewOneByteString(len); | 1525 RawOneByteString* obj = reader->NewOneByteString(len); |
1516 str_obj = obj; | 1526 str_obj = obj; |
1517 str_obj.set_tags(tags); | 1527 str_obj.set_tags(tags); |
1518 obj->ptr()->hash_ = Smi::New(hash); | 1528 obj->ptr()->hash_ = Smi::New(hash); |
1519 if (len > 0) { | 1529 if (len > 0) { |
1520 uint8_t* raw_ptr = str_obj.CharAddr(0); | 1530 uint8_t* raw_ptr = str_obj.CharAddr(0); |
1521 reader->ReadBytes(raw_ptr, len); | 1531 reader->ReadBytes(raw_ptr, len); |
1522 } | 1532 } |
1523 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash)); | 1533 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash)); |
1524 } else { | 1534 } else { |
1525 ReadFromImpl<OneByteString, uint8_t>(reader, &str_obj, len, tags); | 1535 ReadFromImpl<OneByteString, uint8_t>(reader, &str_obj, len, tags, kind); |
1526 } | 1536 } |
1527 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); | 1537 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); |
1528 return str_obj.raw(); | 1538 return str_obj.raw(); |
1529 } | 1539 } |
1530 | 1540 |
1531 | 1541 |
1532 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, | 1542 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, |
1533 intptr_t object_id, | 1543 intptr_t object_id, |
1534 intptr_t tags, | 1544 intptr_t tags, |
1535 Snapshot::Kind kind) { | 1545 Snapshot::Kind kind) { |
(...skipping 10 matching lines...) Expand all Loading... | |
1546 str_obj.set_tags(tags); | 1556 str_obj.set_tags(tags); |
1547 obj->ptr()->hash_ = Smi::New(hash); | 1557 obj->ptr()->hash_ = Smi::New(hash); |
1548 uint16_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; | 1558 uint16_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; |
1549 for (intptr_t i = 0; i < len; i++) { | 1559 for (intptr_t i = 0; i < len; i++) { |
1550 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. | 1560 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. |
1551 *raw_ptr = reader->Read<uint16_t>(); | 1561 *raw_ptr = reader->Read<uint16_t>(); |
1552 raw_ptr += 1; | 1562 raw_ptr += 1; |
1553 } | 1563 } |
1554 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); | 1564 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); |
1555 } else { | 1565 } else { |
1556 ReadFromImpl<TwoByteString, uint16_t>(reader, &str_obj, len, tags); | 1566 ReadFromImpl<TwoByteString, uint16_t>(reader, &str_obj, len, tags, kind); |
1557 } | 1567 } |
1558 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); | 1568 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); |
1559 return str_obj.raw(); | 1569 return str_obj.raw(); |
1560 } | 1570 } |
1561 | 1571 |
1562 | 1572 |
1563 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, | 1573 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, |
1564 intptr_t object_id, | 1574 intptr_t object_id, |
1565 intptr_t tags, | 1575 intptr_t tags, |
1566 Snapshot::Kind kind) { | 1576 Snapshot::Kind kind) { |
(...skipping 10 matching lines...) Expand all Loading... | |
1577 str_obj.set_tags(tags); | 1587 str_obj.set_tags(tags); |
1578 obj->ptr()->hash_ = Smi::New(hash); | 1588 obj->ptr()->hash_ = Smi::New(hash); |
1579 uint32_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; | 1589 uint32_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; |
1580 for (intptr_t i = 0; i < len; i++) { | 1590 for (intptr_t i = 0; i < len; i++) { |
1581 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. | 1591 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. |
1582 *raw_ptr = reader->Read<uint32_t>(); | 1592 *raw_ptr = reader->Read<uint32_t>(); |
1583 raw_ptr += 1; | 1593 raw_ptr += 1; |
1584 } | 1594 } |
1585 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); | 1595 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); |
1586 } else { | 1596 } else { |
1587 ReadFromImpl<FourByteString, uint32_t>(reader, &str_obj, len, tags); | 1597 ReadFromImpl<FourByteString, uint32_t>(reader, &str_obj, len, tags, kind); |
1588 } | 1598 } |
1589 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); | 1599 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); |
1590 return str_obj.raw(); | 1600 return str_obj.raw(); |
1591 } | 1601 } |
1592 | 1602 |
1593 | 1603 |
1594 template<typename T> | 1604 template<typename T> |
1595 static void StringWriteTo(SnapshotWriter* writer, | 1605 static void StringWriteTo(SnapshotWriter* writer, |
1596 intptr_t object_id, | 1606 intptr_t object_id, |
1597 Snapshot::Kind kind, | 1607 Snapshot::Kind kind, |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1767 intptr_t tags, | 1777 intptr_t tags, |
1768 Snapshot::Kind kind) { | 1778 Snapshot::Kind kind) { |
1769 ASSERT(reader != NULL); | 1779 ASSERT(reader != NULL); |
1770 | 1780 |
1771 // Read the length so that we can determine instance size to allocate. | 1781 // Read the length so that we can determine instance size to allocate. |
1772 intptr_t len = reader->ReadSmiValue(); | 1782 intptr_t len = reader->ReadSmiValue(); |
1773 Array* array = reinterpret_cast<Array*>( | 1783 Array* array = reinterpret_cast<Array*>( |
1774 reader->GetBackRef(object_id)); | 1784 reader->GetBackRef(object_id)); |
1775 if (array == NULL) { | 1785 if (array == NULL) { |
1776 array = &(Array::ZoneHandle(reader->isolate(), | 1786 array = &(Array::ZoneHandle(reader->isolate(), |
1777 NEW_OBJECT_WITH_LEN(Array, len))); | 1787 NEW_OBJECT_WITH_LEN_SPACE(Array, len, kind))); |
1778 reader->AddBackRef(object_id, array, kIsDeserialized); | 1788 reader->AddBackRef(object_id, array, kIsDeserialized); |
1779 } | 1789 } |
1780 reader->ArrayReadFrom(*array, len, tags); | 1790 reader->ArrayReadFrom(*array, len, tags); |
1781 return array->raw(); | 1791 return array->raw(); |
1782 } | 1792 } |
1783 | 1793 |
1784 | 1794 |
1785 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, | 1795 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, |
1786 intptr_t object_id, | 1796 intptr_t object_id, |
1787 intptr_t tags, | 1797 intptr_t tags, |
1788 Snapshot::Kind kind) { | 1798 Snapshot::Kind kind) { |
1789 ASSERT(reader != NULL); | 1799 ASSERT(reader != NULL); |
1790 | 1800 |
1791 // Read the length so that we can determine instance size to allocate. | 1801 // Read the length so that we can determine instance size to allocate. |
1792 intptr_t len = reader->ReadSmiValue(); | 1802 intptr_t len = reader->ReadSmiValue(); |
1793 ImmutableArray* array = reinterpret_cast<ImmutableArray*>( | 1803 ImmutableArray* array = reinterpret_cast<ImmutableArray*>( |
1794 reader->GetBackRef(object_id)); | 1804 reader->GetBackRef(object_id)); |
1795 if (array == NULL) { | 1805 if (array == NULL) { |
1796 array = &(ImmutableArray::ZoneHandle( | 1806 array = &(ImmutableArray::ZoneHandle( |
1797 reader->isolate(), NEW_OBJECT_WITH_LEN(ImmutableArray, len))); | 1807 reader->isolate(), |
1808 NEW_OBJECT_WITH_LEN_SPACE(ImmutableArray, len, kind))); | |
1798 reader->AddBackRef(object_id, array, kIsDeserialized); | 1809 reader->AddBackRef(object_id, array, kIsDeserialized); |
1799 } | 1810 } |
1800 reader->ArrayReadFrom(*array, len, tags); | 1811 reader->ArrayReadFrom(*array, len, tags); |
1801 return array->raw(); | 1812 return array->raw(); |
1802 } | 1813 } |
1803 | 1814 |
1804 | 1815 |
1805 void RawArray::WriteTo(SnapshotWriter* writer, | 1816 void RawArray::WriteTo(SnapshotWriter* writer, |
1806 intptr_t object_id, | 1817 intptr_t object_id, |
1807 Snapshot::Kind kind) { | 1818 Snapshot::Kind kind) { |
(...skipping 23 matching lines...) Expand all Loading... | |
1831 intptr_t tags, | 1842 intptr_t tags, |
1832 Snapshot::Kind kind) { | 1843 Snapshot::Kind kind) { |
1833 ASSERT(reader != NULL); | 1844 ASSERT(reader != NULL); |
1834 | 1845 |
1835 // Read the length so that we can determine instance size to allocate. | 1846 // Read the length so that we can determine instance size to allocate. |
1836 GrowableObjectArray& array = GrowableObjectArray::ZoneHandle( | 1847 GrowableObjectArray& array = GrowableObjectArray::ZoneHandle( |
1837 reader->isolate(), GrowableObjectArray::null()); | 1848 reader->isolate(), GrowableObjectArray::null()); |
1838 if (kind == Snapshot::kFull) { | 1849 if (kind == Snapshot::kFull) { |
1839 array = reader->NewGrowableObjectArray(); | 1850 array = reader->NewGrowableObjectArray(); |
1840 } else { | 1851 } else { |
1841 array = GrowableObjectArray::New(0); | 1852 array = GrowableObjectArray::New(0, space(kind)); |
1842 } | 1853 } |
1843 reader->AddBackRef(object_id, &array, kIsDeserialized); | 1854 reader->AddBackRef(object_id, &array, kIsDeserialized); |
1844 intptr_t length = reader->ReadSmiValue(); | 1855 intptr_t length = reader->ReadSmiValue(); |
1845 array.SetLength(length); | 1856 array.SetLength(length); |
1846 Array& contents = Array::Handle(); | 1857 Array& contents = Array::Handle(); |
1847 contents ^= reader->ReadObjectImpl(); | 1858 contents ^= reader->ReadObjectImpl(); |
1848 array.SetData(contents); | 1859 array.SetData(contents); |
1849 const AbstractTypeArguments& type_arguments = | 1860 const AbstractTypeArguments& type_arguments = |
1850 AbstractTypeArguments::Handle(contents.GetTypeArguments()); | 1861 AbstractTypeArguments::Handle(contents.GetTypeArguments()); |
1851 array.SetTypeArguments(type_arguments); | 1862 array.SetTypeArguments(type_arguments); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1883 | 1894 |
1884 | 1895 |
1885 template<typename HandleT, typename RawT, typename ElementT> | 1896 template<typename HandleT, typename RawT, typename ElementT> |
1886 RawT* ByteArray::ReadFromImpl(SnapshotReader* reader, | 1897 RawT* ByteArray::ReadFromImpl(SnapshotReader* reader, |
1887 intptr_t object_id, | 1898 intptr_t object_id, |
1888 intptr_t tags, | 1899 intptr_t tags, |
1889 Snapshot::Kind kind) { | 1900 Snapshot::Kind kind) { |
1890 ASSERT(reader != NULL); | 1901 ASSERT(reader != NULL); |
1891 | 1902 |
1892 intptr_t len = reader->ReadSmiValue(); | 1903 intptr_t len = reader->ReadSmiValue(); |
1893 Heap::Space space = (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew; | 1904 HandleT& result = HandleT::ZoneHandle( |
1894 HandleT& result = | 1905 reader->isolate(), HandleT::New(len, space(kind))); |
1895 HandleT::ZoneHandle(reader->isolate(), HandleT::New(len, space)); | |
1896 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1906 reader->AddBackRef(object_id, &result, kIsDeserialized); |
1897 | 1907 |
1898 // Set the object tags. | 1908 // Set the object tags. |
1899 result.set_tags(tags); | 1909 result.set_tags(tags); |
1900 | 1910 |
1901 // Setup the array elements. | 1911 // Setup the array elements. |
1902 for (intptr_t i = 0; i < len; ++i) { | 1912 for (intptr_t i = 0; i < len; ++i) { |
1903 result.SetAt(i, reader->Read<ElementT>()); | 1913 result.SetAt(i, reader->Read<ElementT>()); |
1904 } | 1914 } |
1905 return result.raw(); | 1915 return result.raw(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1943 Snapshot::Kind kind) { \ | 1953 Snapshot::Kind kind) { \ |
1944 ASSERT(kind != Snapshot::kFull); \ | 1954 ASSERT(kind != Snapshot::kFull); \ |
1945 intptr_t length = reader->ReadSmiValue(); \ | 1955 intptr_t length = reader->ReadSmiValue(); \ |
1946 type* data = reinterpret_cast<type*>(reader->ReadIntptrValue()); \ | 1956 type* data = reinterpret_cast<type*>(reader->ReadIntptrValue()); \ |
1947 void* peer = reinterpret_cast<void*>(reader->ReadIntptrValue()); \ | 1957 void* peer = reinterpret_cast<void*>(reader->ReadIntptrValue()); \ |
1948 Dart_PeerFinalizer callback = \ | 1958 Dart_PeerFinalizer callback = \ |
1949 reinterpret_cast<Dart_PeerFinalizer>(reader->ReadIntptrValue()); \ | 1959 reinterpret_cast<Dart_PeerFinalizer>(reader->ReadIntptrValue()); \ |
1950 const Class& cls = Class::Handle( \ | 1960 const Class& cls = Class::Handle( \ |
1951 reader->isolate()->object_store()->external_##lname##_array_class()); \ | 1961 reader->isolate()->object_store()->external_##lname##_array_class()); \ |
1952 return NewExternalImpl<External##name##Array, RawExternal##name##Array>( \ | 1962 return NewExternalImpl<External##name##Array, RawExternal##name##Array>( \ |
1953 cls, data, length, peer, callback, Heap::kNew); \ | 1963 cls, data, length, peer, callback, space(kind)); \ |
1954 } \ | 1964 } \ |
1955 | 1965 |
1956 | 1966 |
1957 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_READ_FROM) | 1967 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_READ_FROM) |
1958 #undef EXTERNALARRAY_READ_FROM | 1968 #undef EXTERNALARRAY_READ_FROM |
1959 | 1969 |
1960 | 1970 |
1961 static void ByteArrayWriteTo(SnapshotWriter* writer, | 1971 static void ByteArrayWriteTo(SnapshotWriter* writer, |
1962 intptr_t object_id, | 1972 intptr_t object_id, |
1963 Snapshot::Kind kind, | 1973 Snapshot::Kind kind, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2082 intptr_t tags, | 2092 intptr_t tags, |
2083 Snapshot::Kind kind) { | 2093 Snapshot::Kind kind) { |
2084 ASSERT(reader != NULL); | 2094 ASSERT(reader != NULL); |
2085 ASSERT(kind == Snapshot::kMessage); | 2095 ASSERT(kind == Snapshot::kMessage); |
2086 | 2096 |
2087 // Read the length so that we can determine instance size to allocate. | 2097 // Read the length so that we can determine instance size to allocate. |
2088 intptr_t len = reader->ReadSmiValue(); | 2098 intptr_t len = reader->ReadSmiValue(); |
2089 | 2099 |
2090 // Allocate JSRegExp object. | 2100 // Allocate JSRegExp object. |
2091 JSRegExp& regex = JSRegExp::ZoneHandle( | 2101 JSRegExp& regex = JSRegExp::ZoneHandle( |
2092 reader->isolate(), | 2102 reader->isolate(), JSRegExp::New(len, space(kind))); |
2093 JSRegExp::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); | |
2094 reader->AddBackRef(object_id, ®ex, kIsDeserialized); | 2103 reader->AddBackRef(object_id, ®ex, kIsDeserialized); |
2095 | 2104 |
2096 // Set the object tags. | 2105 // Set the object tags. |
2097 regex.set_tags(tags); | 2106 regex.set_tags(tags); |
2098 | 2107 |
2099 // Read and Set all the other fields. | 2108 // Read and Set all the other fields. |
2100 regex.raw_ptr()->num_bracket_expressions_ = reader->ReadAsSmi(); | 2109 regex.raw_ptr()->num_bracket_expressions_ = reader->ReadAsSmi(); |
2101 *reader->StringHandle() ^= reader->ReadObjectImpl(); | 2110 *reader->StringHandle() ^= reader->ReadObjectImpl(); |
2102 regex.raw_ptr()->pattern_ = (*reader->StringHandle()).raw(); | 2111 regex.raw_ptr()->pattern_ = (*reader->StringHandle()).raw(); |
2103 regex.raw_ptr()->type_ = reader->ReadIntptrValue(); | 2112 regex.raw_ptr()->type_ = reader->ReadIntptrValue(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2136 | 2145 |
2137 | 2146 |
2138 RawWeakProperty* WeakProperty::ReadFrom(SnapshotReader* reader, | 2147 RawWeakProperty* WeakProperty::ReadFrom(SnapshotReader* reader, |
2139 intptr_t object_id, | 2148 intptr_t object_id, |
2140 intptr_t tags, | 2149 intptr_t tags, |
2141 Snapshot::Kind kind) { | 2150 Snapshot::Kind kind) { |
2142 ASSERT(reader != NULL); | 2151 ASSERT(reader != NULL); |
2143 | 2152 |
2144 // Allocate the weak property object. | 2153 // Allocate the weak property object. |
2145 WeakProperty& weak_property = WeakProperty::ZoneHandle( | 2154 WeakProperty& weak_property = WeakProperty::ZoneHandle( |
2146 reader->isolate(), | 2155 reader->isolate(), WeakProperty::New(space(kind))); |
2147 WeakProperty::New((kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); | |
2148 reader->AddBackRef(object_id, &weak_property, kIsDeserialized); | 2156 reader->AddBackRef(object_id, &weak_property, kIsDeserialized); |
2149 | 2157 |
2150 // Set the object tags. | 2158 // Set the object tags. |
2151 weak_property.set_tags(tags); | 2159 weak_property.set_tags(tags); |
2152 | 2160 |
2153 // Set all the object fields. | 2161 // Set all the object fields. |
2154 weak_property.raw_ptr()->key_ = reader->ReadObjectRef(); | 2162 weak_property.raw_ptr()->key_ = reader->ReadObjectRef(); |
2155 weak_property.raw_ptr()->value_ = reader->ReadObjectRef(); | 2163 weak_property.raw_ptr()->value_ = reader->ReadObjectRef(); |
2156 | 2164 |
2157 return weak_property.raw(); | 2165 return weak_property.raw(); |
(...skipping 11 matching lines...) Expand all Loading... | |
2169 // Write out the class and tags information. | 2177 // Write out the class and tags information. |
2170 writer->WriteIndexedObject(kWeakPropertyCid); | 2178 writer->WriteIndexedObject(kWeakPropertyCid); |
2171 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2179 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
2172 | 2180 |
2173 // Write out all the other fields. | 2181 // Write out all the other fields. |
2174 writer->Write<RawObject*>(ptr()->key_); | 2182 writer->Write<RawObject*>(ptr()->key_); |
2175 writer->Write<RawObject*>(ptr()->value_); | 2183 writer->Write<RawObject*>(ptr()->value_); |
2176 } | 2184 } |
2177 | 2185 |
2178 } // namespace dart | 2186 } // namespace dart |
OLD | NEW |