| 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 1584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1595 } | 1595 } |
| 1596 | 1596 |
| 1597 | 1597 |
| 1598 void RawString::WriteTo(SnapshotWriter* writer, | 1598 void RawString::WriteTo(SnapshotWriter* writer, |
| 1599 intptr_t object_id, | 1599 intptr_t object_id, |
| 1600 Snapshot::Kind kind) { | 1600 Snapshot::Kind kind) { |
| 1601 UNREACHABLE(); // String is an abstract class. | 1601 UNREACHABLE(); // String is an abstract class. |
| 1602 } | 1602 } |
| 1603 | 1603 |
| 1604 | 1604 |
| 1605 template<typename StringType, typename CharacterType> | 1605 template<typename StringType, typename CharacterType, typename CallbackType> |
| 1606 void String::ReadFromImpl(SnapshotReader* reader, | 1606 void String::ReadFromImpl(SnapshotReader* reader, |
| 1607 String* str_obj, | 1607 String* str_obj, |
| 1608 intptr_t len, | 1608 intptr_t len, |
| 1609 intptr_t tags, | 1609 intptr_t tags, |
| 1610 CallbackType new_symbol, |
| 1610 Snapshot::Kind kind) { | 1611 Snapshot::Kind kind) { |
| 1611 ASSERT(reader != NULL); | 1612 ASSERT(reader != NULL); |
| 1612 if (RawObject::IsCanonical(tags)) { | 1613 if (RawObject::IsCanonical(tags)) { |
| 1613 // Set up canonical string object. | 1614 // Set up canonical string object. |
| 1614 ASSERT(reader != NULL); | 1615 ASSERT(reader != NULL); |
| 1615 CharacterType* ptr = | 1616 CharacterType* ptr = |
| 1616 Isolate::Current()->current_zone()->Alloc<CharacterType>(len); | 1617 Isolate::Current()->current_zone()->Alloc<CharacterType>(len); |
| 1617 for (intptr_t i = 0; i < len; i++) { | 1618 for (intptr_t i = 0; i < len; i++) { |
| 1618 ptr[i] = reader->Read<CharacterType>(); | 1619 ptr[i] = reader->Read<CharacterType>(); |
| 1619 } | 1620 } |
| 1620 *str_obj ^= Symbols::NewSymbol(ptr, len); | 1621 *str_obj ^= (*new_symbol)(ptr, len); |
| 1621 } else { | 1622 } else { |
| 1622 // Set up the string object. | 1623 // Set up the string object. |
| 1623 *str_obj = StringType::New(len, HEAP_SPACE(kind)); | 1624 *str_obj = StringType::New(len, HEAP_SPACE(kind)); |
| 1624 str_obj->set_tags(tags); | 1625 str_obj->set_tags(tags); |
| 1625 str_obj->SetHash(0); // Will get computed when needed. | 1626 str_obj->SetHash(0); // Will get computed when needed. |
| 1626 for (intptr_t i = 0; i < len; i++) { | 1627 for (intptr_t i = 0; i < len; i++) { |
| 1627 *StringType::CharAddr(*str_obj, i) = reader->Read<CharacterType>(); | 1628 *StringType::CharAddr(*str_obj, i) = reader->Read<CharacterType>(); |
| 1628 } | 1629 } |
| 1629 } | 1630 } |
| 1630 } | 1631 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1646 str_obj = obj; | 1647 str_obj = obj; |
| 1647 str_obj.set_tags(tags); | 1648 str_obj.set_tags(tags); |
| 1648 obj->ptr()->hash_ = Smi::New(hash); | 1649 obj->ptr()->hash_ = Smi::New(hash); |
| 1649 if (len > 0) { | 1650 if (len > 0) { |
| 1650 uint8_t* raw_ptr = CharAddr(str_obj, 0); | 1651 uint8_t* raw_ptr = CharAddr(str_obj, 0); |
| 1651 reader->ReadBytes(raw_ptr, len); | 1652 reader->ReadBytes(raw_ptr, len); |
| 1652 } | 1653 } |
| 1653 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash)); | 1654 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash)); |
| 1654 } else { | 1655 } else { |
| 1655 String::ReadFromImpl<OneByteString, uint8_t>( | 1656 String::ReadFromImpl<OneByteString, uint8_t>( |
| 1656 reader, &str_obj, len, tags, kind); | 1657 reader, &str_obj, len, tags, Symbols::FromLatin1, kind); |
| 1657 } | 1658 } |
| 1658 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); | 1659 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); |
| 1659 return raw(str_obj); | 1660 return raw(str_obj); |
| 1660 } | 1661 } |
| 1661 | 1662 |
| 1662 | 1663 |
| 1663 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, | 1664 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, |
| 1664 intptr_t object_id, | 1665 intptr_t object_id, |
| 1665 intptr_t tags, | 1666 intptr_t tags, |
| 1666 Snapshot::Kind kind) { | 1667 Snapshot::Kind kind) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1677 obj->ptr()->hash_ = Smi::New(hash); | 1678 obj->ptr()->hash_ = Smi::New(hash); |
| 1678 uint16_t* raw_ptr = (len > 0)? CharAddr(str_obj, 0) : NULL; | 1679 uint16_t* raw_ptr = (len > 0)? CharAddr(str_obj, 0) : NULL; |
| 1679 for (intptr_t i = 0; i < len; i++) { | 1680 for (intptr_t i = 0; i < len; i++) { |
| 1680 ASSERT(CharAddr(str_obj, i) == raw_ptr); // Will trigger assertions. | 1681 ASSERT(CharAddr(str_obj, i) == raw_ptr); // Will trigger assertions. |
| 1681 *raw_ptr = reader->Read<uint16_t>(); | 1682 *raw_ptr = reader->Read<uint16_t>(); |
| 1682 raw_ptr += 1; | 1683 raw_ptr += 1; |
| 1683 } | 1684 } |
| 1684 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); | 1685 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); |
| 1685 } else { | 1686 } else { |
| 1686 String::ReadFromImpl<TwoByteString, uint16_t>( | 1687 String::ReadFromImpl<TwoByteString, uint16_t>( |
| 1687 reader, &str_obj, len, tags, kind); | 1688 reader, &str_obj, len, tags, Symbols::FromUTF16, kind); |
| 1688 } | 1689 } |
| 1689 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); | 1690 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); |
| 1690 return raw(str_obj); | 1691 return raw(str_obj); |
| 1691 } | 1692 } |
| 1692 | 1693 |
| 1693 | 1694 |
| 1694 template<typename T> | 1695 template<typename T> |
| 1695 static void StringWriteTo(SnapshotWriter* writer, | 1696 static void StringWriteTo(SnapshotWriter* writer, |
| 1696 intptr_t object_id, | 1697 intptr_t object_id, |
| 1697 Snapshot::Kind kind, | 1698 Snapshot::Kind kind, |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2210 // Write out the class and tags information. | 2211 // Write out the class and tags information. |
| 2211 writer->WriteIndexedObject(kWeakPropertyCid); | 2212 writer->WriteIndexedObject(kWeakPropertyCid); |
| 2212 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2213 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2213 | 2214 |
| 2214 // Write out all the other fields. | 2215 // Write out all the other fields. |
| 2215 writer->Write<RawObject*>(ptr()->key_); | 2216 writer->Write<RawObject*>(ptr()->key_); |
| 2216 writer->Write<RawObject*>(ptr()->value_); | 2217 writer->Write<RawObject*>(ptr()->value_); |
| 2217 } | 2218 } |
| 2218 | 2219 |
| 2219 } // namespace dart | 2220 } // namespace dart |
| OLD | NEW |