| 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, HEAP_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 |
| 27 RawClass* Class::ReadFrom(SnapshotReader* reader, | 31 RawClass* Class::ReadFrom(SnapshotReader* reader, |
| 28 intptr_t object_id, | 32 intptr_t object_id, |
| 29 intptr_t tags, | 33 intptr_t tags, |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 RawTypeArguments* TypeArguments::ReadFrom(SnapshotReader* reader, | 314 RawTypeArguments* TypeArguments::ReadFrom(SnapshotReader* reader, |
| 311 intptr_t object_id, | 315 intptr_t object_id, |
| 312 intptr_t tags, | 316 intptr_t tags, |
| 313 Snapshot::Kind kind) { | 317 Snapshot::Kind kind) { |
| 314 ASSERT(reader != NULL); | 318 ASSERT(reader != NULL); |
| 315 | 319 |
| 316 // Read the length so that we can determine instance size to allocate. | 320 // Read the length so that we can determine instance size to allocate. |
| 317 intptr_t len = reader->ReadSmiValue(); | 321 intptr_t len = reader->ReadSmiValue(); |
| 318 | 322 |
| 319 TypeArguments& type_arguments = TypeArguments::ZoneHandle( | 323 TypeArguments& type_arguments = TypeArguments::ZoneHandle( |
| 320 reader->isolate(), NEW_OBJECT_WITH_LEN(TypeArguments, len)); | 324 reader->isolate(), NEW_OBJECT_WITH_LEN_SPACE(TypeArguments, len, kind)); |
| 321 reader->AddBackRef(object_id, &type_arguments, kIsDeserialized); | 325 reader->AddBackRef(object_id, &type_arguments, kIsDeserialized); |
| 322 | 326 |
| 323 // Now set all the object fields. | 327 // Now set all the object fields. |
| 324 for (intptr_t i = 0; i < len; i++) { | 328 for (intptr_t i = 0; i < len; i++) { |
| 325 *reader->TypeHandle() ^= reader->ReadObjectImpl(); | 329 *reader->TypeHandle() ^= reader->ReadObjectImpl(); |
| 326 type_arguments.SetTypeAt(i, *reader->TypeHandle()); | 330 type_arguments.SetTypeAt(i, *reader->TypeHandle()); |
| 327 } | 331 } |
| 328 | 332 |
| 329 // Set the object tags (This is done after setting the object fields | 333 // 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 | 334 // because 'SetTypeAt' has an assertion to check if the object is not |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 intptr_t tags, | 1009 intptr_t tags, |
| 1006 Snapshot::Kind kind) { | 1010 Snapshot::Kind kind) { |
| 1007 ASSERT(reader != NULL); | 1011 ASSERT(reader != NULL); |
| 1008 | 1012 |
| 1009 // Allocate context object. | 1013 // Allocate context object. |
| 1010 intptr_t num_vars = reader->ReadIntptrValue(); | 1014 intptr_t num_vars = reader->ReadIntptrValue(); |
| 1011 Context& context = Context::ZoneHandle(reader->isolate(), Context::null()); | 1015 Context& context = Context::ZoneHandle(reader->isolate(), Context::null()); |
| 1012 if (kind == Snapshot::kFull) { | 1016 if (kind == Snapshot::kFull) { |
| 1013 context = reader->NewContext(num_vars); | 1017 context = reader->NewContext(num_vars); |
| 1014 } else { | 1018 } else { |
| 1015 context = Context::New(num_vars); | 1019 context = Context::New(num_vars, HEAP_SPACE(kind)); |
| 1016 } | 1020 } |
| 1017 reader->AddBackRef(object_id, &context, kIsDeserialized); | 1021 reader->AddBackRef(object_id, &context, kIsDeserialized); |
| 1018 | 1022 |
| 1019 // Set the object tags. | 1023 // Set the object tags. |
| 1020 context.set_tags(tags); | 1024 context.set_tags(tags); |
| 1021 | 1025 |
| 1022 // Set the isolate implicitly. | 1026 // Set the isolate implicitly. |
| 1023 context.set_isolate(Isolate::Current()); | 1027 context.set_isolate(Isolate::Current()); |
| 1024 | 1028 |
| 1025 // Set all the object fields. | 1029 // 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>(); | 1306 int64_t value = reader->Read<int64_t>(); |
| 1303 | 1307 |
| 1304 // Create a Mint object or get canonical one if it is a canonical constant. | 1308 // Create a Mint object or get canonical one if it is a canonical constant. |
| 1305 Mint& mint = Mint::ZoneHandle(reader->isolate(), Mint::null()); | 1309 Mint& mint = Mint::ZoneHandle(reader->isolate(), Mint::null()); |
| 1306 if (kind == Snapshot::kFull) { | 1310 if (kind == Snapshot::kFull) { |
| 1307 mint = reader->NewMint(value); | 1311 mint = reader->NewMint(value); |
| 1308 } else { | 1312 } else { |
| 1309 if (RawObject::IsCanonical(tags)) { | 1313 if (RawObject::IsCanonical(tags)) { |
| 1310 mint = Mint::NewCanonical(value); | 1314 mint = Mint::NewCanonical(value); |
| 1311 } else { | 1315 } else { |
| 1312 mint = Mint::New(value, Heap::kNew); | 1316 mint = Mint::New(value, HEAP_SPACE(kind)); |
| 1313 } | 1317 } |
| 1314 } | 1318 } |
| 1315 reader->AddBackRef(object_id, &mint, kIsDeserialized); | 1319 reader->AddBackRef(object_id, &mint, kIsDeserialized); |
| 1316 | 1320 |
| 1317 // Set the object tags. | 1321 // Set the object tags. |
| 1318 mint.set_tags(tags); | 1322 mint.set_tags(tags); |
| 1319 | 1323 |
| 1320 return mint.raw(); | 1324 return mint.raw(); |
| 1321 } | 1325 } |
| 1322 | 1326 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1346 | 1350 |
| 1347 // Read in the HexCString representation of the bigint. | 1351 // Read in the HexCString representation of the bigint. |
| 1348 intptr_t len = reader->ReadIntptrValue(); | 1352 intptr_t len = reader->ReadIntptrValue(); |
| 1349 char* str = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | 1353 char* str = Isolate::Current()->current_zone()->Alloc<char>(len + 1); |
| 1350 str[len] = '\0'; | 1354 str[len] = '\0'; |
| 1351 reader->ReadBytes(reinterpret_cast<uint8_t*>(str), len); | 1355 reader->ReadBytes(reinterpret_cast<uint8_t*>(str), len); |
| 1352 | 1356 |
| 1353 // Create a Bigint object from HexCString. | 1357 // Create a Bigint object from HexCString. |
| 1354 Bigint& obj = Bigint::ZoneHandle( | 1358 Bigint& obj = Bigint::ZoneHandle( |
| 1355 reader->isolate(), | 1359 reader->isolate(), |
| 1356 (kind == Snapshot::kFull) ? reader->NewBigint(str) : | 1360 ((kind == Snapshot::kFull) ? reader->NewBigint(str) : |
| 1357 BigintOperations::FromHexCString(str)); | 1361 BigintOperations::FromHexCString(str, HEAP_SPACE(kind)))); |
| 1358 | 1362 |
| 1359 // If it is a canonical constant make it one. | 1363 // If it is a canonical constant make it one. |
| 1360 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) { | 1364 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) { |
| 1361 obj ^= obj.Canonicalize(); | 1365 obj ^= obj.Canonicalize(); |
| 1362 } | 1366 } |
| 1363 reader->AddBackRef(object_id, &obj, kIsDeserialized); | 1367 reader->AddBackRef(object_id, &obj, kIsDeserialized); |
| 1364 | 1368 |
| 1365 // Set the object tags. | 1369 // Set the object tags. |
| 1366 obj.set_tags(tags); | 1370 obj.set_tags(tags); |
| 1367 | 1371 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1420 double value = reader->Read<double>(); | 1424 double value = reader->Read<double>(); |
| 1421 | 1425 |
| 1422 // Create a Double object or get canonical one if it is a canonical constant. | 1426 // Create a Double object or get canonical one if it is a canonical constant. |
| 1423 Double& dbl = Double::ZoneHandle(reader->isolate(), Double::null()); | 1427 Double& dbl = Double::ZoneHandle(reader->isolate(), Double::null()); |
| 1424 if (kind == Snapshot::kFull) { | 1428 if (kind == Snapshot::kFull) { |
| 1425 dbl = reader->NewDouble(value); | 1429 dbl = reader->NewDouble(value); |
| 1426 } else { | 1430 } else { |
| 1427 if (RawObject::IsCanonical(tags)) { | 1431 if (RawObject::IsCanonical(tags)) { |
| 1428 dbl = Double::NewCanonical(value); | 1432 dbl = Double::NewCanonical(value); |
| 1429 } else { | 1433 } else { |
| 1430 dbl = Double::New(value, Heap::kNew); | 1434 dbl = Double::New(value, HEAP_SPACE(kind)); |
| 1431 } | 1435 } |
| 1432 } | 1436 } |
| 1433 reader->AddBackRef(object_id, &dbl, kIsDeserialized); | 1437 reader->AddBackRef(object_id, &dbl, kIsDeserialized); |
| 1434 | 1438 |
| 1435 // Set the object tags. | 1439 // Set the object tags. |
| 1436 dbl.set_tags(tags); | 1440 dbl.set_tags(tags); |
| 1437 | 1441 |
| 1438 return dbl.raw(); | 1442 return dbl.raw(); |
| 1439 } | 1443 } |
| 1440 | 1444 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1469 intptr_t object_id, | 1473 intptr_t object_id, |
| 1470 Snapshot::Kind kind) { | 1474 Snapshot::Kind kind) { |
| 1471 UNREACHABLE(); // String is an abstract class. | 1475 UNREACHABLE(); // String is an abstract class. |
| 1472 } | 1476 } |
| 1473 | 1477 |
| 1474 | 1478 |
| 1475 template<typename HandleType, typename CharacterType> | 1479 template<typename HandleType, typename CharacterType> |
| 1476 void String::ReadFromImpl(SnapshotReader* reader, | 1480 void String::ReadFromImpl(SnapshotReader* reader, |
| 1477 HandleType* str_obj, | 1481 HandleType* str_obj, |
| 1478 intptr_t len, | 1482 intptr_t len, |
| 1479 intptr_t tags) { | 1483 intptr_t tags, |
| 1484 Snapshot::Kind kind) { |
| 1480 ASSERT(reader != NULL); | 1485 ASSERT(reader != NULL); |
| 1481 if (RawObject::IsCanonical(tags)) { | 1486 if (RawObject::IsCanonical(tags)) { |
| 1482 // Set up canonical string object. | 1487 // Set up canonical string object. |
| 1483 ASSERT(reader != NULL); | 1488 ASSERT(reader != NULL); |
| 1484 CharacterType* ptr = | 1489 CharacterType* ptr = |
| 1485 Isolate::Current()->current_zone()->Alloc<CharacterType>(len); | 1490 Isolate::Current()->current_zone()->Alloc<CharacterType>(len); |
| 1486 for (intptr_t i = 0; i < len; i++) { | 1491 for (intptr_t i = 0; i < len; i++) { |
| 1487 ptr[i] = reader->Read<CharacterType>(); | 1492 ptr[i] = reader->Read<CharacterType>(); |
| 1488 } | 1493 } |
| 1489 *str_obj ^= Symbols::New(ptr, len); | 1494 *str_obj ^= Symbols::New(ptr, len); |
| 1490 } else { | 1495 } else { |
| 1491 // Set up the string object. | 1496 // Set up the string object. |
| 1492 *str_obj = HandleType::New(len, Heap::kNew); | 1497 *str_obj = HandleType::New(len, HEAP_SPACE(kind)); |
| 1493 str_obj->set_tags(tags); | 1498 str_obj->set_tags(tags); |
| 1494 str_obj->SetHash(0); // Will get computed when needed. | 1499 str_obj->SetHash(0); // Will get computed when needed. |
| 1495 for (intptr_t i = 0; i < len; i++) { | 1500 for (intptr_t i = 0; i < len; i++) { |
| 1496 *str_obj->CharAddr(i) = reader->Read<CharacterType>(); | 1501 *str_obj->CharAddr(i) = reader->Read<CharacterType>(); |
| 1497 } | 1502 } |
| 1498 } | 1503 } |
| 1499 } | 1504 } |
| 1500 | 1505 |
| 1501 | 1506 |
| 1502 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, | 1507 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1515 RawOneByteString* obj = reader->NewOneByteString(len); | 1520 RawOneByteString* obj = reader->NewOneByteString(len); |
| 1516 str_obj = obj; | 1521 str_obj = obj; |
| 1517 str_obj.set_tags(tags); | 1522 str_obj.set_tags(tags); |
| 1518 obj->ptr()->hash_ = Smi::New(hash); | 1523 obj->ptr()->hash_ = Smi::New(hash); |
| 1519 if (len > 0) { | 1524 if (len > 0) { |
| 1520 uint8_t* raw_ptr = str_obj.CharAddr(0); | 1525 uint8_t* raw_ptr = str_obj.CharAddr(0); |
| 1521 reader->ReadBytes(raw_ptr, len); | 1526 reader->ReadBytes(raw_ptr, len); |
| 1522 } | 1527 } |
| 1523 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash)); | 1528 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash)); |
| 1524 } else { | 1529 } else { |
| 1525 ReadFromImpl<OneByteString, uint8_t>(reader, &str_obj, len, tags); | 1530 ReadFromImpl<OneByteString, uint8_t>(reader, &str_obj, len, tags, kind); |
| 1526 } | 1531 } |
| 1527 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); | 1532 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); |
| 1528 return str_obj.raw(); | 1533 return str_obj.raw(); |
| 1529 } | 1534 } |
| 1530 | 1535 |
| 1531 | 1536 |
| 1532 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, | 1537 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, |
| 1533 intptr_t object_id, | 1538 intptr_t object_id, |
| 1534 intptr_t tags, | 1539 intptr_t tags, |
| 1535 Snapshot::Kind kind) { | 1540 Snapshot::Kind kind) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1546 str_obj.set_tags(tags); | 1551 str_obj.set_tags(tags); |
| 1547 obj->ptr()->hash_ = Smi::New(hash); | 1552 obj->ptr()->hash_ = Smi::New(hash); |
| 1548 uint16_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; | 1553 uint16_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; |
| 1549 for (intptr_t i = 0; i < len; i++) { | 1554 for (intptr_t i = 0; i < len; i++) { |
| 1550 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. | 1555 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. |
| 1551 *raw_ptr = reader->Read<uint16_t>(); | 1556 *raw_ptr = reader->Read<uint16_t>(); |
| 1552 raw_ptr += 1; | 1557 raw_ptr += 1; |
| 1553 } | 1558 } |
| 1554 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); | 1559 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); |
| 1555 } else { | 1560 } else { |
| 1556 ReadFromImpl<TwoByteString, uint16_t>(reader, &str_obj, len, tags); | 1561 ReadFromImpl<TwoByteString, uint16_t>(reader, &str_obj, len, tags, kind); |
| 1557 } | 1562 } |
| 1558 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); | 1563 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); |
| 1559 return str_obj.raw(); | 1564 return str_obj.raw(); |
| 1560 } | 1565 } |
| 1561 | 1566 |
| 1562 | 1567 |
| 1563 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, | 1568 RawFourByteString* FourByteString::ReadFrom(SnapshotReader* reader, |
| 1564 intptr_t object_id, | 1569 intptr_t object_id, |
| 1565 intptr_t tags, | 1570 intptr_t tags, |
| 1566 Snapshot::Kind kind) { | 1571 Snapshot::Kind kind) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1577 str_obj.set_tags(tags); | 1582 str_obj.set_tags(tags); |
| 1578 obj->ptr()->hash_ = Smi::New(hash); | 1583 obj->ptr()->hash_ = Smi::New(hash); |
| 1579 uint32_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; | 1584 uint32_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; |
| 1580 for (intptr_t i = 0; i < len; i++) { | 1585 for (intptr_t i = 0; i < len; i++) { |
| 1581 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. | 1586 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. |
| 1582 *raw_ptr = reader->Read<uint32_t>(); | 1587 *raw_ptr = reader->Read<uint32_t>(); |
| 1583 raw_ptr += 1; | 1588 raw_ptr += 1; |
| 1584 } | 1589 } |
| 1585 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); | 1590 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); |
| 1586 } else { | 1591 } else { |
| 1587 ReadFromImpl<FourByteString, uint32_t>(reader, &str_obj, len, tags); | 1592 ReadFromImpl<FourByteString, uint32_t>(reader, &str_obj, len, tags, kind); |
| 1588 } | 1593 } |
| 1589 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); | 1594 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); |
| 1590 return str_obj.raw(); | 1595 return str_obj.raw(); |
| 1591 } | 1596 } |
| 1592 | 1597 |
| 1593 | 1598 |
| 1594 template<typename T> | 1599 template<typename T> |
| 1595 static void StringWriteTo(SnapshotWriter* writer, | 1600 static void StringWriteTo(SnapshotWriter* writer, |
| 1596 intptr_t object_id, | 1601 intptr_t object_id, |
| 1597 Snapshot::Kind kind, | 1602 Snapshot::Kind kind, |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1767 intptr_t tags, | 1772 intptr_t tags, |
| 1768 Snapshot::Kind kind) { | 1773 Snapshot::Kind kind) { |
| 1769 ASSERT(reader != NULL); | 1774 ASSERT(reader != NULL); |
| 1770 | 1775 |
| 1771 // Read the length so that we can determine instance size to allocate. | 1776 // Read the length so that we can determine instance size to allocate. |
| 1772 intptr_t len = reader->ReadSmiValue(); | 1777 intptr_t len = reader->ReadSmiValue(); |
| 1773 Array* array = reinterpret_cast<Array*>( | 1778 Array* array = reinterpret_cast<Array*>( |
| 1774 reader->GetBackRef(object_id)); | 1779 reader->GetBackRef(object_id)); |
| 1775 if (array == NULL) { | 1780 if (array == NULL) { |
| 1776 array = &(Array::ZoneHandle(reader->isolate(), | 1781 array = &(Array::ZoneHandle(reader->isolate(), |
| 1777 NEW_OBJECT_WITH_LEN(Array, len))); | 1782 NEW_OBJECT_WITH_LEN_SPACE(Array, len, kind))); |
| 1778 reader->AddBackRef(object_id, array, kIsDeserialized); | 1783 reader->AddBackRef(object_id, array, kIsDeserialized); |
| 1779 } | 1784 } |
| 1780 reader->ArrayReadFrom(*array, len, tags); | 1785 reader->ArrayReadFrom(*array, len, tags); |
| 1781 return array->raw(); | 1786 return array->raw(); |
| 1782 } | 1787 } |
| 1783 | 1788 |
| 1784 | 1789 |
| 1785 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, | 1790 RawImmutableArray* ImmutableArray::ReadFrom(SnapshotReader* reader, |
| 1786 intptr_t object_id, | 1791 intptr_t object_id, |
| 1787 intptr_t tags, | 1792 intptr_t tags, |
| 1788 Snapshot::Kind kind) { | 1793 Snapshot::Kind kind) { |
| 1789 ASSERT(reader != NULL); | 1794 ASSERT(reader != NULL); |
| 1790 | 1795 |
| 1791 // Read the length so that we can determine instance size to allocate. | 1796 // Read the length so that we can determine instance size to allocate. |
| 1792 intptr_t len = reader->ReadSmiValue(); | 1797 intptr_t len = reader->ReadSmiValue(); |
| 1793 ImmutableArray* array = reinterpret_cast<ImmutableArray*>( | 1798 ImmutableArray* array = reinterpret_cast<ImmutableArray*>( |
| 1794 reader->GetBackRef(object_id)); | 1799 reader->GetBackRef(object_id)); |
| 1795 if (array == NULL) { | 1800 if (array == NULL) { |
| 1796 array = &(ImmutableArray::ZoneHandle( | 1801 array = &(ImmutableArray::ZoneHandle( |
| 1797 reader->isolate(), NEW_OBJECT_WITH_LEN(ImmutableArray, len))); | 1802 reader->isolate(), |
| 1803 NEW_OBJECT_WITH_LEN_SPACE(ImmutableArray, len, kind))); |
| 1798 reader->AddBackRef(object_id, array, kIsDeserialized); | 1804 reader->AddBackRef(object_id, array, kIsDeserialized); |
| 1799 } | 1805 } |
| 1800 reader->ArrayReadFrom(*array, len, tags); | 1806 reader->ArrayReadFrom(*array, len, tags); |
| 1801 return array->raw(); | 1807 return array->raw(); |
| 1802 } | 1808 } |
| 1803 | 1809 |
| 1804 | 1810 |
| 1805 void RawArray::WriteTo(SnapshotWriter* writer, | 1811 void RawArray::WriteTo(SnapshotWriter* writer, |
| 1806 intptr_t object_id, | 1812 intptr_t object_id, |
| 1807 Snapshot::Kind kind) { | 1813 Snapshot::Kind kind) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1831 intptr_t tags, | 1837 intptr_t tags, |
| 1832 Snapshot::Kind kind) { | 1838 Snapshot::Kind kind) { |
| 1833 ASSERT(reader != NULL); | 1839 ASSERT(reader != NULL); |
| 1834 | 1840 |
| 1835 // Read the length so that we can determine instance size to allocate. | 1841 // Read the length so that we can determine instance size to allocate. |
| 1836 GrowableObjectArray& array = GrowableObjectArray::ZoneHandle( | 1842 GrowableObjectArray& array = GrowableObjectArray::ZoneHandle( |
| 1837 reader->isolate(), GrowableObjectArray::null()); | 1843 reader->isolate(), GrowableObjectArray::null()); |
| 1838 if (kind == Snapshot::kFull) { | 1844 if (kind == Snapshot::kFull) { |
| 1839 array = reader->NewGrowableObjectArray(); | 1845 array = reader->NewGrowableObjectArray(); |
| 1840 } else { | 1846 } else { |
| 1841 array = GrowableObjectArray::New(0); | 1847 array = GrowableObjectArray::New(0, HEAP_SPACE(kind)); |
| 1842 } | 1848 } |
| 1843 reader->AddBackRef(object_id, &array, kIsDeserialized); | 1849 reader->AddBackRef(object_id, &array, kIsDeserialized); |
| 1844 intptr_t length = reader->ReadSmiValue(); | 1850 intptr_t length = reader->ReadSmiValue(); |
| 1845 array.SetLength(length); | 1851 array.SetLength(length); |
| 1846 Array& contents = Array::Handle(); | 1852 Array& contents = Array::Handle(); |
| 1847 contents ^= reader->ReadObjectImpl(); | 1853 contents ^= reader->ReadObjectImpl(); |
| 1848 array.SetData(contents); | 1854 array.SetData(contents); |
| 1849 const AbstractTypeArguments& type_arguments = | 1855 const AbstractTypeArguments& type_arguments = |
| 1850 AbstractTypeArguments::Handle(contents.GetTypeArguments()); | 1856 AbstractTypeArguments::Handle(contents.GetTypeArguments()); |
| 1851 array.SetTypeArguments(type_arguments); | 1857 array.SetTypeArguments(type_arguments); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1883 | 1889 |
| 1884 | 1890 |
| 1885 template<typename HandleT, typename RawT, typename ElementT> | 1891 template<typename HandleT, typename RawT, typename ElementT> |
| 1886 RawT* ByteArray::ReadFromImpl(SnapshotReader* reader, | 1892 RawT* ByteArray::ReadFromImpl(SnapshotReader* reader, |
| 1887 intptr_t object_id, | 1893 intptr_t object_id, |
| 1888 intptr_t tags, | 1894 intptr_t tags, |
| 1889 Snapshot::Kind kind) { | 1895 Snapshot::Kind kind) { |
| 1890 ASSERT(reader != NULL); | 1896 ASSERT(reader != NULL); |
| 1891 | 1897 |
| 1892 intptr_t len = reader->ReadSmiValue(); | 1898 intptr_t len = reader->ReadSmiValue(); |
| 1893 Heap::Space space = (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew; | 1899 HandleT& result = HandleT::ZoneHandle( |
| 1894 HandleT& result = | 1900 reader->isolate(), HandleT::New(len, HEAP_SPACE(kind))); |
| 1895 HandleT::ZoneHandle(reader->isolate(), HandleT::New(len, space)); | |
| 1896 reader->AddBackRef(object_id, &result, kIsDeserialized); | 1901 reader->AddBackRef(object_id, &result, kIsDeserialized); |
| 1897 | 1902 |
| 1898 // Set the object tags. | 1903 // Set the object tags. |
| 1899 result.set_tags(tags); | 1904 result.set_tags(tags); |
| 1900 | 1905 |
| 1901 // Setup the array elements. | 1906 // Setup the array elements. |
| 1902 for (intptr_t i = 0; i < len; ++i) { | 1907 for (intptr_t i = 0; i < len; ++i) { |
| 1903 result.SetAt(i, reader->Read<ElementT>()); | 1908 result.SetAt(i, reader->Read<ElementT>()); |
| 1904 } | 1909 } |
| 1905 return result.raw(); | 1910 return result.raw(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1943 Snapshot::Kind kind) { \ | 1948 Snapshot::Kind kind) { \ |
| 1944 ASSERT(kind != Snapshot::kFull); \ | 1949 ASSERT(kind != Snapshot::kFull); \ |
| 1945 intptr_t length = reader->ReadSmiValue(); \ | 1950 intptr_t length = reader->ReadSmiValue(); \ |
| 1946 type* data = reinterpret_cast<type*>(reader->ReadIntptrValue()); \ | 1951 type* data = reinterpret_cast<type*>(reader->ReadIntptrValue()); \ |
| 1947 void* peer = reinterpret_cast<void*>(reader->ReadIntptrValue()); \ | 1952 void* peer = reinterpret_cast<void*>(reader->ReadIntptrValue()); \ |
| 1948 Dart_PeerFinalizer callback = \ | 1953 Dart_PeerFinalizer callback = \ |
| 1949 reinterpret_cast<Dart_PeerFinalizer>(reader->ReadIntptrValue()); \ | 1954 reinterpret_cast<Dart_PeerFinalizer>(reader->ReadIntptrValue()); \ |
| 1950 const Class& cls = Class::Handle( \ | 1955 const Class& cls = Class::Handle( \ |
| 1951 reader->isolate()->object_store()->external_##lname##_array_class()); \ | 1956 reader->isolate()->object_store()->external_##lname##_array_class()); \ |
| 1952 return NewExternalImpl<External##name##Array, RawExternal##name##Array>( \ | 1957 return NewExternalImpl<External##name##Array, RawExternal##name##Array>( \ |
| 1953 cls, data, length, peer, callback, Heap::kNew); \ | 1958 cls, data, length, peer, callback, HEAP_SPACE(kind)); \ |
| 1954 } \ | 1959 } \ |
| 1955 | 1960 |
| 1956 | 1961 |
| 1957 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_READ_FROM) | 1962 BYTEARRAY_TYPE_LIST(EXTERNALARRAY_READ_FROM) |
| 1958 #undef EXTERNALARRAY_READ_FROM | 1963 #undef EXTERNALARRAY_READ_FROM |
| 1959 | 1964 |
| 1960 | 1965 |
| 1961 static void ByteArrayWriteTo(SnapshotWriter* writer, | 1966 static void ByteArrayWriteTo(SnapshotWriter* writer, |
| 1962 intptr_t object_id, | 1967 intptr_t object_id, |
| 1963 Snapshot::Kind kind, | 1968 Snapshot::Kind kind, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2082 intptr_t tags, | 2087 intptr_t tags, |
| 2083 Snapshot::Kind kind) { | 2088 Snapshot::Kind kind) { |
| 2084 ASSERT(reader != NULL); | 2089 ASSERT(reader != NULL); |
| 2085 ASSERT(kind == Snapshot::kMessage); | 2090 ASSERT(kind == Snapshot::kMessage); |
| 2086 | 2091 |
| 2087 // Read the length so that we can determine instance size to allocate. | 2092 // Read the length so that we can determine instance size to allocate. |
| 2088 intptr_t len = reader->ReadSmiValue(); | 2093 intptr_t len = reader->ReadSmiValue(); |
| 2089 | 2094 |
| 2090 // Allocate JSRegExp object. | 2095 // Allocate JSRegExp object. |
| 2091 JSRegExp& regex = JSRegExp::ZoneHandle( | 2096 JSRegExp& regex = JSRegExp::ZoneHandle( |
| 2092 reader->isolate(), | 2097 reader->isolate(), JSRegExp::New(len, HEAP_SPACE(kind))); |
| 2093 JSRegExp::New(len, (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); | |
| 2094 reader->AddBackRef(object_id, ®ex, kIsDeserialized); | 2098 reader->AddBackRef(object_id, ®ex, kIsDeserialized); |
| 2095 | 2099 |
| 2096 // Set the object tags. | 2100 // Set the object tags. |
| 2097 regex.set_tags(tags); | 2101 regex.set_tags(tags); |
| 2098 | 2102 |
| 2099 // Read and Set all the other fields. | 2103 // Read and Set all the other fields. |
| 2100 regex.raw_ptr()->num_bracket_expressions_ = reader->ReadAsSmi(); | 2104 regex.raw_ptr()->num_bracket_expressions_ = reader->ReadAsSmi(); |
| 2101 *reader->StringHandle() ^= reader->ReadObjectImpl(); | 2105 *reader->StringHandle() ^= reader->ReadObjectImpl(); |
| 2102 regex.raw_ptr()->pattern_ = (*reader->StringHandle()).raw(); | 2106 regex.raw_ptr()->pattern_ = (*reader->StringHandle()).raw(); |
| 2103 regex.raw_ptr()->type_ = reader->ReadIntptrValue(); | 2107 regex.raw_ptr()->type_ = reader->ReadIntptrValue(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2136 | 2140 |
| 2137 | 2141 |
| 2138 RawWeakProperty* WeakProperty::ReadFrom(SnapshotReader* reader, | 2142 RawWeakProperty* WeakProperty::ReadFrom(SnapshotReader* reader, |
| 2139 intptr_t object_id, | 2143 intptr_t object_id, |
| 2140 intptr_t tags, | 2144 intptr_t tags, |
| 2141 Snapshot::Kind kind) { | 2145 Snapshot::Kind kind) { |
| 2142 ASSERT(reader != NULL); | 2146 ASSERT(reader != NULL); |
| 2143 | 2147 |
| 2144 // Allocate the weak property object. | 2148 // Allocate the weak property object. |
| 2145 WeakProperty& weak_property = WeakProperty::ZoneHandle( | 2149 WeakProperty& weak_property = WeakProperty::ZoneHandle( |
| 2146 reader->isolate(), | 2150 reader->isolate(), WeakProperty::New(HEAP_SPACE(kind))); |
| 2147 WeakProperty::New((kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew)); | |
| 2148 reader->AddBackRef(object_id, &weak_property, kIsDeserialized); | 2151 reader->AddBackRef(object_id, &weak_property, kIsDeserialized); |
| 2149 | 2152 |
| 2150 // Set the object tags. | 2153 // Set the object tags. |
| 2151 weak_property.set_tags(tags); | 2154 weak_property.set_tags(tags); |
| 2152 | 2155 |
| 2153 // Set all the object fields. | 2156 // Set all the object fields. |
| 2154 weak_property.raw_ptr()->key_ = reader->ReadObjectRef(); | 2157 weak_property.raw_ptr()->key_ = reader->ReadObjectRef(); |
| 2155 weak_property.raw_ptr()->value_ = reader->ReadObjectRef(); | 2158 weak_property.raw_ptr()->value_ = reader->ReadObjectRef(); |
| 2156 | 2159 |
| 2157 return weak_property.raw(); | 2160 return weak_property.raw(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2169 // Write out the class and tags information. | 2172 // Write out the class and tags information. |
| 2170 writer->WriteIndexedObject(kWeakPropertyCid); | 2173 writer->WriteIndexedObject(kWeakPropertyCid); |
| 2171 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2174 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2172 | 2175 |
| 2173 // Write out all the other fields. | 2176 // Write out all the other fields. |
| 2174 writer->Write<RawObject*>(ptr()->key_); | 2177 writer->Write<RawObject*>(ptr()->key_); |
| 2175 writer->Write<RawObject*>(ptr()->value_); | 2178 writer->Write<RawObject*>(ptr()->value_); |
| 2176 } | 2179 } |
| 2177 | 2180 |
| 2178 } // namespace dart | 2181 } // namespace dart |
| OLD | NEW |