| 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" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 198 |
| 199 // Set all the object fields. | 199 // Set all the object fields. |
| 200 // TODO(5411462): Need to assert No GC can happen here, even though | 200 // TODO(5411462): Need to assert No GC can happen here, even though |
| 201 // allocations may happen. | 201 // allocations may happen. |
| 202 intptr_t num_flds = (type.raw()->to() - type.raw()->from()); | 202 intptr_t num_flds = (type.raw()->to() - type.raw()->from()); |
| 203 for (intptr_t i = 0; i <= num_flds; i++) { | 203 for (intptr_t i = 0; i <= num_flds; i++) { |
| 204 type.StorePointer((type.raw()->from() + i), reader->ReadObjectRef()); | 204 type.StorePointer((type.raw()->from() + i), reader->ReadObjectRef()); |
| 205 } | 205 } |
| 206 | 206 |
| 207 // If object needs to be a canonical object, Canonicalize it. | 207 // If object needs to be a canonical object, Canonicalize it. |
| 208 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) { | 208 // When reading a full snapshot we don't need to canonicalize the object |
| 209 // as it would already be a canonical object. |
| 210 // When reading a script snapshot we need to canonicalize only those object |
| 211 // references that are objects from the core library (loaded from a |
| 212 // full snapshot). Objects that are only in the script need not be |
| 213 // canonicalized as they are already canonical. |
| 214 // When reading a message snapshot we always have to canonicalize the object. |
| 215 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags) && |
| 216 (RawObject::IsCreatedFromSnapshot(tags) || |
| 217 (kind == Snapshot::kMessage))) { |
| 209 type ^= type.Canonicalize(); | 218 type ^= type.Canonicalize(); |
| 210 } | 219 } |
| 211 | 220 |
| 212 // Set the object tags (This is done after 'Canonicalize', which | 221 // Set the object tags (This is done after 'Canonicalize', which |
| 213 // does not canonicalize a type already marked as canonical). | 222 // does not canonicalize a type already marked as canonical). |
| 214 type.set_tags(tags); | 223 type.set_tags(tags); |
| 215 | 224 |
| 216 return type.raw(); | 225 return type.raw(); |
| 217 } | 226 } |
| 218 | 227 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 reader->isolate(), NEW_OBJECT_WITH_LEN_SPACE(TypeArguments, len, kind)); | 460 reader->isolate(), NEW_OBJECT_WITH_LEN_SPACE(TypeArguments, len, kind)); |
| 452 reader->AddBackRef(object_id, &type_arguments, kIsDeserialized); | 461 reader->AddBackRef(object_id, &type_arguments, kIsDeserialized); |
| 453 | 462 |
| 454 // Now set all the object fields. | 463 // Now set all the object fields. |
| 455 for (intptr_t i = 0; i < len; i++) { | 464 for (intptr_t i = 0; i < len; i++) { |
| 456 *reader->TypeHandle() ^= reader->ReadObjectImpl(); | 465 *reader->TypeHandle() ^= reader->ReadObjectImpl(); |
| 457 type_arguments.SetTypeAt(i, *reader->TypeHandle()); | 466 type_arguments.SetTypeAt(i, *reader->TypeHandle()); |
| 458 } | 467 } |
| 459 | 468 |
| 460 // If object needs to be a canonical object, Canonicalize it. | 469 // If object needs to be a canonical object, Canonicalize it. |
| 461 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) { | 470 // When reading a full snapshot we don't need to canonicalize the object |
| 471 // as it would already be a canonical object. |
| 472 // When reading a script snapshot we need to canonicalize only those object |
| 473 // references that are objects from the core library (loaded from a |
| 474 // full snapshot). Objects that are only in the script need not be |
| 475 // canonicalized as they are already canonical. |
| 476 // When reading a message snapshot we always have to canonicalize the object. |
| 477 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags) && |
| 478 (RawObject::IsCreatedFromSnapshot(tags) || |
| 479 (kind == Snapshot::kMessage))) { |
| 462 type_arguments ^= type_arguments.Canonicalize(); | 480 type_arguments ^= type_arguments.Canonicalize(); |
| 463 } | 481 } |
| 464 | 482 |
| 465 // Set the object tags (This is done after setting the object fields | 483 // Set the object tags (This is done after setting the object fields |
| 466 // because 'SetTypeAt' has an assertion to check if the object is not | 484 // because 'SetTypeAt' has an assertion to check if the object is not |
| 467 // already canonical. Also, this is done after 'Canonicalize', which | 485 // already canonical. Also, this is done after 'Canonicalize', which |
| 468 // does not canonicalize a type already marked as canonical). | 486 // does not canonicalize a type already marked as canonical). |
| 469 type_arguments.set_tags(tags); | 487 type_arguments.set_tags(tags); |
| 470 | 488 |
| 471 return type_arguments.raw(); | 489 return type_arguments.raw(); |
| (...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 ASSERT(reader != NULL); | 1608 ASSERT(reader != NULL); |
| 1591 | 1609 |
| 1592 // Read the 64 bit value for the object. | 1610 // Read the 64 bit value for the object. |
| 1593 int64_t value = reader->Read<int64_t>(); | 1611 int64_t value = reader->Read<int64_t>(); |
| 1594 | 1612 |
| 1595 // Create a Mint object or get canonical one if it is a canonical constant. | 1613 // Create a Mint object or get canonical one if it is a canonical constant. |
| 1596 Mint& mint = Mint::ZoneHandle(reader->isolate(), Mint::null()); | 1614 Mint& mint = Mint::ZoneHandle(reader->isolate(), Mint::null()); |
| 1597 if (kind == Snapshot::kFull) { | 1615 if (kind == Snapshot::kFull) { |
| 1598 mint = reader->NewMint(value); | 1616 mint = reader->NewMint(value); |
| 1599 } else { | 1617 } else { |
| 1600 if (RawObject::IsCanonical(tags)) { | 1618 // When reading a script snapshot we need to canonicalize only those object |
| 1619 // references that are objects from the core library (loaded from a |
| 1620 // full snapshot). Objects that are only in the script need not be |
| 1621 // canonicalized as they are already canonical. |
| 1622 // When reading a message snapshot we always have to canonicalize. |
| 1623 if (RawObject::IsCanonical(tags) && |
| 1624 (RawObject::IsCreatedFromSnapshot(tags) || |
| 1625 (kind == Snapshot::kMessage))) { |
| 1601 mint = Mint::NewCanonical(value); | 1626 mint = Mint::NewCanonical(value); |
| 1602 } else { | 1627 } else { |
| 1603 mint = Mint::New(value, HEAP_SPACE(kind)); | 1628 mint = Mint::New(value, HEAP_SPACE(kind)); |
| 1604 } | 1629 } |
| 1605 } | 1630 } |
| 1606 reader->AddBackRef(object_id, &mint, kIsDeserialized); | 1631 reader->AddBackRef(object_id, &mint, kIsDeserialized); |
| 1607 | 1632 |
| 1608 // Set the object tags. | 1633 // Set the object tags. |
| 1609 mint.set_tags(tags); | 1634 mint.set_tags(tags); |
| 1610 | 1635 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1641 str[len] = '\0'; | 1666 str[len] = '\0'; |
| 1642 reader->ReadBytes(reinterpret_cast<uint8_t*>(str), len); | 1667 reader->ReadBytes(reinterpret_cast<uint8_t*>(str), len); |
| 1643 | 1668 |
| 1644 // Create a Bigint object from HexCString. | 1669 // Create a Bigint object from HexCString. |
| 1645 Bigint& obj = Bigint::ZoneHandle( | 1670 Bigint& obj = Bigint::ZoneHandle( |
| 1646 reader->isolate(), | 1671 reader->isolate(), |
| 1647 ((kind == Snapshot::kFull) ? reader->NewBigint(str) : | 1672 ((kind == Snapshot::kFull) ? reader->NewBigint(str) : |
| 1648 BigintOperations::FromHexCString(str, HEAP_SPACE(kind)))); | 1673 BigintOperations::FromHexCString(str, HEAP_SPACE(kind)))); |
| 1649 | 1674 |
| 1650 // If it is a canonical constant make it one. | 1675 // If it is a canonical constant make it one. |
| 1651 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags)) { | 1676 // When reading a full snapshot we don't need to canonicalize the object |
| 1677 // as it would already be a canonical object. |
| 1678 // When reading a script snapshot we need to canonicalize only those object |
| 1679 // references that are objects from the core library (loaded from a |
| 1680 // full snapshot). Objects that are only in the script need not be |
| 1681 // canonicalized as they are already canonical. |
| 1682 // When reading a message snapshot we always have to canonicalize the object. |
| 1683 if ((kind != Snapshot::kFull) && RawObject::IsCanonical(tags) && |
| 1684 (RawObject::IsCreatedFromSnapshot(tags) || |
| 1685 (kind == Snapshot::kMessage))) { |
| 1652 obj ^= obj.Canonicalize(); | 1686 obj ^= obj.Canonicalize(); |
| 1653 } | 1687 } |
| 1654 reader->AddBackRef(object_id, &obj, kIsDeserialized); | 1688 reader->AddBackRef(object_id, &obj, kIsDeserialized); |
| 1655 | 1689 |
| 1656 // Set the object tags. | 1690 // Set the object tags. |
| 1657 obj.set_tags(tags); | 1691 obj.set_tags(tags); |
| 1658 | 1692 |
| 1659 return obj.raw(); | 1693 return obj.raw(); |
| 1660 } | 1694 } |
| 1661 | 1695 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1708 Snapshot::Kind kind) { | 1742 Snapshot::Kind kind) { |
| 1709 ASSERT(reader != NULL); | 1743 ASSERT(reader != NULL); |
| 1710 // Read the double value for the object. | 1744 // Read the double value for the object. |
| 1711 double value = reader->Read<double>(); | 1745 double value = reader->Read<double>(); |
| 1712 | 1746 |
| 1713 // Create a Double object or get canonical one if it is a canonical constant. | 1747 // Create a Double object or get canonical one if it is a canonical constant. |
| 1714 Double& dbl = Double::ZoneHandle(reader->isolate(), Double::null()); | 1748 Double& dbl = Double::ZoneHandle(reader->isolate(), Double::null()); |
| 1715 if (kind == Snapshot::kFull) { | 1749 if (kind == Snapshot::kFull) { |
| 1716 dbl = reader->NewDouble(value); | 1750 dbl = reader->NewDouble(value); |
| 1717 } else { | 1751 } else { |
| 1718 if (RawObject::IsCanonical(tags)) { | 1752 // When reading a script snapshot we need to canonicalize only those object |
| 1753 // references that are objects from the core library (loaded from a |
| 1754 // full snapshot). Objects that are only in the script need not be |
| 1755 // canonicalized as they are already canonical. |
| 1756 // When reading a message snapshot we always have to canonicalize. |
| 1757 if (RawObject::IsCanonical(tags) && |
| 1758 (RawObject::IsCreatedFromSnapshot(tags) || |
| 1759 (kind == Snapshot::kMessage))) { |
| 1719 dbl = Double::NewCanonical(value); | 1760 dbl = Double::NewCanonical(value); |
| 1720 } else { | 1761 } else { |
| 1721 dbl = Double::New(value, HEAP_SPACE(kind)); | 1762 dbl = Double::New(value, HEAP_SPACE(kind)); |
| 1722 } | 1763 } |
| 1723 } | 1764 } |
| 1724 reader->AddBackRef(object_id, &dbl, kIsDeserialized); | 1765 reader->AddBackRef(object_id, &dbl, kIsDeserialized); |
| 1725 | 1766 |
| 1726 // Set the object tags. | 1767 // Set the object tags. |
| 1727 dbl.set_tags(tags); | 1768 dbl.set_tags(tags); |
| 1728 | 1769 |
| (...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2796 // Write out the class and tags information. | 2837 // Write out the class and tags information. |
| 2797 writer->WriteIndexedObject(kWeakPropertyCid); | 2838 writer->WriteIndexedObject(kWeakPropertyCid); |
| 2798 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2839 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2799 | 2840 |
| 2800 // Write out all the other fields. | 2841 // Write out all the other fields. |
| 2801 writer->Write<RawObject*>(ptr()->key_); | 2842 writer->Write<RawObject*>(ptr()->key_); |
| 2802 writer->Write<RawObject*>(ptr()->value_); | 2843 writer->Write<RawObject*>(ptr()->value_); |
| 2803 } | 2844 } |
| 2804 | 2845 |
| 2805 } // namespace dart | 2846 } // namespace dart |
| OLD | NEW |