| 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 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1619 } | 1619 } |
| 1620 | 1620 |
| 1621 | 1621 |
| 1622 void RawString::WriteTo(SnapshotWriter* writer, | 1622 void RawString::WriteTo(SnapshotWriter* writer, |
| 1623 intptr_t object_id, | 1623 intptr_t object_id, |
| 1624 Snapshot::Kind kind) { | 1624 Snapshot::Kind kind) { |
| 1625 UNREACHABLE(); // String is an abstract class. | 1625 UNREACHABLE(); // String is an abstract class. |
| 1626 } | 1626 } |
| 1627 | 1627 |
| 1628 | 1628 |
| 1629 template<typename HandleType, typename CharacterType> | 1629 template<typename StringType, typename CharacterType> |
| 1630 void String::ReadFromImpl(SnapshotReader* reader, | 1630 void String::ReadFromImpl(SnapshotReader* reader, |
| 1631 HandleType* str_obj, | 1631 String* str_obj, |
| 1632 intptr_t len, | 1632 intptr_t len, |
| 1633 intptr_t tags, | 1633 intptr_t tags, |
| 1634 Snapshot::Kind kind) { | 1634 Snapshot::Kind kind) { |
| 1635 ASSERT(reader != NULL); | 1635 ASSERT(reader != NULL); |
| 1636 if (RawObject::IsCanonical(tags)) { | 1636 if (RawObject::IsCanonical(tags)) { |
| 1637 // Set up canonical string object. | 1637 // Set up canonical string object. |
| 1638 ASSERT(reader != NULL); | 1638 ASSERT(reader != NULL); |
| 1639 CharacterType* ptr = | 1639 CharacterType* ptr = |
| 1640 Isolate::Current()->current_zone()->Alloc<CharacterType>(len); | 1640 Isolate::Current()->current_zone()->Alloc<CharacterType>(len); |
| 1641 for (intptr_t i = 0; i < len; i++) { | 1641 for (intptr_t i = 0; i < len; i++) { |
| 1642 ptr[i] = reader->Read<CharacterType>(); | 1642 ptr[i] = reader->Read<CharacterType>(); |
| 1643 } | 1643 } |
| 1644 *str_obj ^= Symbols::New(ptr, len); | 1644 *str_obj ^= Symbols::New(ptr, len); |
| 1645 } else { | 1645 } else { |
| 1646 // Set up the string object. | 1646 // Set up the string object. |
| 1647 *str_obj = HandleType::New(len, HEAP_SPACE(kind)); | 1647 *str_obj = StringType::New(len, HEAP_SPACE(kind)); |
| 1648 str_obj->set_tags(tags); | 1648 str_obj->set_tags(tags); |
| 1649 str_obj->SetHash(0); // Will get computed when needed. | 1649 str_obj->SetHash(0); // Will get computed when needed. |
| 1650 for (intptr_t i = 0; i < len; i++) { | 1650 for (intptr_t i = 0; i < len; i++) { |
| 1651 *str_obj->CharAddr(i) = reader->Read<CharacterType>(); | 1651 *StringType::CharAddr(*str_obj, i) = reader->Read<CharacterType>(); |
| 1652 } | 1652 } |
| 1653 } | 1653 } |
| 1654 } | 1654 } |
| 1655 | 1655 |
| 1656 | 1656 |
| 1657 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, | 1657 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, |
| 1658 intptr_t object_id, | 1658 intptr_t object_id, |
| 1659 intptr_t tags, | 1659 intptr_t tags, |
| 1660 Snapshot::Kind kind) { | 1660 Snapshot::Kind kind) { |
| 1661 // Read the length so that we can determine instance size to allocate. | 1661 // Read the length so that we can determine instance size to allocate. |
| 1662 ASSERT(reader != NULL); | 1662 ASSERT(reader != NULL); |
| 1663 intptr_t len = reader->ReadSmiValue(); | 1663 intptr_t len = reader->ReadSmiValue(); |
| 1664 intptr_t hash = reader->ReadSmiValue(); | 1664 intptr_t hash = reader->ReadSmiValue(); |
| 1665 OneByteString& str_obj = OneByteString::ZoneHandle(reader->isolate(), | 1665 String& str_obj = String::Handle(reader->isolate(), String::null()); |
| 1666 OneByteString::null()); | |
| 1667 | 1666 |
| 1668 if (kind == Snapshot::kFull) { | 1667 if (kind == Snapshot::kFull) { |
| 1669 ASSERT(reader->isolate()->no_gc_scope_depth() != 0); | 1668 ASSERT(reader->isolate()->no_gc_scope_depth() != 0); |
| 1670 RawOneByteString* obj = reader->NewOneByteString(len); | 1669 RawOneByteString* obj = reader->NewOneByteString(len); |
| 1671 str_obj = obj; | 1670 str_obj = obj; |
| 1672 str_obj.set_tags(tags); | 1671 str_obj.set_tags(tags); |
| 1673 obj->ptr()->hash_ = Smi::New(hash); | 1672 obj->ptr()->hash_ = Smi::New(hash); |
| 1674 if (len > 0) { | 1673 if (len > 0) { |
| 1675 uint8_t* raw_ptr = str_obj.CharAddr(0); | 1674 uint8_t* raw_ptr = CharAddr(str_obj, 0); |
| 1676 reader->ReadBytes(raw_ptr, len); | 1675 reader->ReadBytes(raw_ptr, len); |
| 1677 } | 1676 } |
| 1678 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash)); | 1677 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash)); |
| 1679 } else { | 1678 } else { |
| 1680 ReadFromImpl<OneByteString, uint8_t>(reader, &str_obj, len, tags, kind); | 1679 String::ReadFromImpl<OneByteString, uint8_t>( |
| 1680 reader, &str_obj, len, tags, kind); |
| 1681 } | 1681 } |
| 1682 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); | 1682 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); |
| 1683 return str_obj.raw(); | 1683 return raw(str_obj); |
| 1684 } | 1684 } |
| 1685 | 1685 |
| 1686 | 1686 |
| 1687 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, | 1687 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, |
| 1688 intptr_t object_id, | 1688 intptr_t object_id, |
| 1689 intptr_t tags, | 1689 intptr_t tags, |
| 1690 Snapshot::Kind kind) { | 1690 Snapshot::Kind kind) { |
| 1691 // Read the length so that we can determine instance size to allocate. | 1691 // Read the length so that we can determine instance size to allocate. |
| 1692 ASSERT(reader != NULL); | 1692 ASSERT(reader != NULL); |
| 1693 intptr_t len = reader->ReadSmiValue(); | 1693 intptr_t len = reader->ReadSmiValue(); |
| 1694 intptr_t hash = reader->ReadSmiValue(); | 1694 intptr_t hash = reader->ReadSmiValue(); |
| 1695 TwoByteString& str_obj = TwoByteString::ZoneHandle(reader->isolate(), | 1695 String& str_obj = String::Handle(reader->isolate(), String::null()); |
| 1696 TwoByteString::null()); | |
| 1697 | 1696 |
| 1698 if (kind == Snapshot::kFull) { | 1697 if (kind == Snapshot::kFull) { |
| 1699 RawTwoByteString* obj = reader->NewTwoByteString(len); | 1698 RawTwoByteString* obj = reader->NewTwoByteString(len); |
| 1700 str_obj = obj; | 1699 str_obj = obj; |
| 1701 str_obj.set_tags(tags); | 1700 str_obj.set_tags(tags); |
| 1702 obj->ptr()->hash_ = Smi::New(hash); | 1701 obj->ptr()->hash_ = Smi::New(hash); |
| 1703 uint16_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; | 1702 uint16_t* raw_ptr = (len > 0)? CharAddr(str_obj, 0) : NULL; |
| 1704 for (intptr_t i = 0; i < len; i++) { | 1703 for (intptr_t i = 0; i < len; i++) { |
| 1705 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. | 1704 ASSERT(CharAddr(str_obj, i) == raw_ptr); // Will trigger assertions. |
| 1706 *raw_ptr = reader->Read<uint16_t>(); | 1705 *raw_ptr = reader->Read<uint16_t>(); |
| 1707 raw_ptr += 1; | 1706 raw_ptr += 1; |
| 1708 } | 1707 } |
| 1709 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); | 1708 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); |
| 1710 } else { | 1709 } else { |
| 1711 ReadFromImpl<TwoByteString, uint16_t>(reader, &str_obj, len, tags, kind); | 1710 String::ReadFromImpl<TwoByteString, uint16_t>( |
| 1711 reader, &str_obj, len, tags, kind); |
| 1712 } | 1712 } |
| 1713 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); | 1713 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); |
| 1714 return str_obj.raw(); | 1714 return raw(str_obj); |
| 1715 } | 1715 } |
| 1716 | 1716 |
| 1717 | 1717 |
| 1718 template<typename T> | 1718 template<typename T> |
| 1719 static void StringWriteTo(SnapshotWriter* writer, | 1719 static void StringWriteTo(SnapshotWriter* writer, |
| 1720 intptr_t object_id, | 1720 intptr_t object_id, |
| 1721 Snapshot::Kind kind, | 1721 Snapshot::Kind kind, |
| 1722 intptr_t class_id, | 1722 intptr_t class_id, |
| 1723 intptr_t tags, | 1723 intptr_t tags, |
| 1724 RawSmi* length, | 1724 RawSmi* length, |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2234 // Write out the class and tags information. | 2234 // Write out the class and tags information. |
| 2235 writer->WriteIndexedObject(kWeakPropertyCid); | 2235 writer->WriteIndexedObject(kWeakPropertyCid); |
| 2236 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2236 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2237 | 2237 |
| 2238 // Write out all the other fields. | 2238 // Write out all the other fields. |
| 2239 writer->Write<RawObject*>(ptr()->key_); | 2239 writer->Write<RawObject*>(ptr()->key_); |
| 2240 writer->Write<RawObject*>(ptr()->value_); | 2240 writer->Write<RawObject*>(ptr()->value_); |
| 2241 } | 2241 } |
| 2242 | 2242 |
| 2243 } // namespace dart | 2243 } // namespace dart |
| OLD | NEW |