Chromium Code Reviews| 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 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 HandleType, 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 = HandleType::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 CharacterType* dst_chars = | |
| 1651 const_cast<CharacterType*>(HandleType::CharAddr(*str_obj, 0)); | |
| 1650 for (intptr_t i = 0; i < len; i++) { | 1652 for (intptr_t i = 0; i < len; i++) { |
| 1651 *str_obj->CharAddr(i) = reader->Read<CharacterType>(); | 1653 dst_chars[i] = reader->Read<CharacterType>(); |
|
siva
2012/11/02 01:15:25
dst_chars is pointing to a raw pointer and we are
Tom Ball
2012/11/02 23:31:50
Restored original loop, updated it.
| |
| 1652 } | 1654 } |
| 1653 } | 1655 } |
| 1654 } | 1656 } |
| 1655 | 1657 |
| 1656 | 1658 |
| 1657 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, | 1659 RawOneByteString* OneByteString::ReadFrom(SnapshotReader* reader, |
| 1658 intptr_t object_id, | 1660 intptr_t object_id, |
| 1659 intptr_t tags, | 1661 intptr_t tags, |
| 1660 Snapshot::Kind kind) { | 1662 Snapshot::Kind kind) { |
| 1661 // Read the length so that we can determine instance size to allocate. | 1663 // Read the length so that we can determine instance size to allocate. |
| 1662 ASSERT(reader != NULL); | 1664 ASSERT(reader != NULL); |
| 1663 intptr_t len = reader->ReadSmiValue(); | 1665 intptr_t len = reader->ReadSmiValue(); |
| 1664 intptr_t hash = reader->ReadSmiValue(); | 1666 intptr_t hash = reader->ReadSmiValue(); |
| 1665 OneByteString& str_obj = OneByteString::ZoneHandle(reader->isolate(), | 1667 String& str_obj = OneByteString::ZoneHandle(reader->isolate(), |
|
siva
2012/11/02 01:15:25
Should be String::ZoneHandle(.....);
Tom Ball
2012/11/02 23:31:50
Done.
| |
| 1666 OneByteString::null()); | 1668 String::null()); |
| 1667 | 1669 |
| 1668 if (kind == Snapshot::kFull) { | 1670 if (kind == Snapshot::kFull) { |
| 1669 ASSERT(reader->isolate()->no_gc_scope_depth() != 0); | 1671 ASSERT(reader->isolate()->no_gc_scope_depth() != 0); |
| 1670 RawOneByteString* obj = reader->NewOneByteString(len); | 1672 RawOneByteString* obj = reader->NewOneByteString(len); |
| 1671 str_obj = obj; | 1673 str_obj = obj; |
| 1672 str_obj.set_tags(tags); | 1674 str_obj.set_tags(tags); |
| 1673 obj->ptr()->hash_ = Smi::New(hash); | 1675 obj->ptr()->hash_ = Smi::New(hash); |
| 1674 if (len > 0) { | 1676 if (len > 0) { |
| 1675 uint8_t* raw_ptr = str_obj.CharAddr(0); | 1677 uint8_t* raw_ptr = |
| 1678 const_cast<uint8_t*>(OneByteString::CharAddr(str_obj, 0)); | |
|
siva
2012/11/02 01:15:25
why is this const_cast needed?
Tom Ball
2012/11/02 23:31:50
Removed.
| |
| 1676 reader->ReadBytes(raw_ptr, len); | 1679 reader->ReadBytes(raw_ptr, len); |
| 1677 } | 1680 } |
| 1678 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash)); | 1681 ASSERT((hash == 0) || (String::Hash(str_obj, 0, str_obj.Length()) == hash)); |
| 1679 } else { | 1682 } else { |
| 1680 ReadFromImpl<OneByteString, uint8_t>(reader, &str_obj, len, tags, kind); | 1683 ReadFromImpl<OneByteString, uint8_t>(reader, &str_obj, len, tags, kind); |
| 1681 } | 1684 } |
| 1682 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); | 1685 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); |
| 1683 return str_obj.raw(); | 1686 return reinterpret_cast<RawOneByteString*>(str_obj.raw()); |
|
siva
2012/11/02 01:15:25
I am not sure how many places you are having to do
Tom Ball
2012/11/02 23:31:50
Good idea -- done.
| |
| 1684 } | 1687 } |
| 1685 | 1688 |
| 1686 | 1689 |
| 1687 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, | 1690 RawTwoByteString* TwoByteString::ReadFrom(SnapshotReader* reader, |
| 1688 intptr_t object_id, | 1691 intptr_t object_id, |
| 1689 intptr_t tags, | 1692 intptr_t tags, |
| 1690 Snapshot::Kind kind) { | 1693 Snapshot::Kind kind) { |
| 1691 // Read the length so that we can determine instance size to allocate. | 1694 // Read the length so that we can determine instance size to allocate. |
| 1692 ASSERT(reader != NULL); | 1695 ASSERT(reader != NULL); |
| 1693 intptr_t len = reader->ReadSmiValue(); | 1696 intptr_t len = reader->ReadSmiValue(); |
| 1694 intptr_t hash = reader->ReadSmiValue(); | 1697 intptr_t hash = reader->ReadSmiValue(); |
| 1695 TwoByteString& str_obj = TwoByteString::ZoneHandle(reader->isolate(), | 1698 String& str_obj = TwoByteString::ZoneHandle(reader->isolate(), |
|
siva
2012/11/02 01:15:25
Should be String::ZoneHandle(...);
Tom Ball
2012/11/02 23:31:50
Done.
| |
| 1696 TwoByteString::null()); | 1699 String::null()); |
| 1697 | 1700 |
| 1698 if (kind == Snapshot::kFull) { | 1701 if (kind == Snapshot::kFull) { |
| 1699 RawTwoByteString* obj = reader->NewTwoByteString(len); | 1702 RawTwoByteString* obj = reader->NewTwoByteString(len); |
| 1700 str_obj = obj; | 1703 str_obj = obj; |
| 1701 str_obj.set_tags(tags); | 1704 str_obj.set_tags(tags); |
| 1702 obj->ptr()->hash_ = Smi::New(hash); | 1705 obj->ptr()->hash_ = Smi::New(hash); |
| 1703 uint16_t* raw_ptr = (len > 0)? str_obj.CharAddr(0) : NULL; | 1706 uint16_t* raw_ptr = (len > 0)? |
| 1707 const_cast<uint16_t*>(TwoByteString::CharAddr(str_obj, 0)) : NULL; | |
|
siva
2012/11/02 01:15:25
Why is this const_cast needed?
Tom Ball
2012/11/02 23:31:50
Removed.
| |
| 1704 for (intptr_t i = 0; i < len; i++) { | 1708 for (intptr_t i = 0; i < len; i++) { |
| 1705 ASSERT(str_obj.CharAddr(i) == raw_ptr); // Will trigger assertions. | 1709 // Will trigger assertions. |
| 1710 ASSERT(TwoByteString::CharAddr(str_obj, i) == raw_ptr); | |
| 1706 *raw_ptr = reader->Read<uint16_t>(); | 1711 *raw_ptr = reader->Read<uint16_t>(); |
| 1707 raw_ptr += 1; | 1712 raw_ptr += 1; |
| 1708 } | 1713 } |
| 1709 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); | 1714 ASSERT(String::Hash(str_obj, 0, str_obj.Length()) == hash); |
| 1710 } else { | 1715 } else { |
| 1711 ReadFromImpl<TwoByteString, uint16_t>(reader, &str_obj, len, tags, kind); | 1716 ReadFromImpl<TwoByteString, uint16_t>(reader, &str_obj, len, tags, kind); |
| 1712 } | 1717 } |
| 1713 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); | 1718 reader->AddBackRef(object_id, &str_obj, kIsDeserialized); |
| 1714 return str_obj.raw(); | 1719 return reinterpret_cast<RawTwoByteString*>(str_obj.raw()); |
|
siva
2012/11/02 01:15:25
Ditto comment for TwoByteString::raw(str_obj);
Tom Ball
2012/11/02 23:31:50
Done.
| |
| 1715 } | 1720 } |
| 1716 | 1721 |
| 1717 | 1722 |
| 1718 template<typename T> | 1723 template<typename T> |
| 1719 static void StringWriteTo(SnapshotWriter* writer, | 1724 static void StringWriteTo(SnapshotWriter* writer, |
| 1720 intptr_t object_id, | 1725 intptr_t object_id, |
| 1721 Snapshot::Kind kind, | 1726 Snapshot::Kind kind, |
| 1722 intptr_t class_id, | 1727 intptr_t class_id, |
| 1723 intptr_t tags, | 1728 intptr_t tags, |
| 1724 RawSmi* length, | 1729 RawSmi* length, |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2234 // Write out the class and tags information. | 2239 // Write out the class and tags information. |
| 2235 writer->WriteIndexedObject(kWeakPropertyCid); | 2240 writer->WriteIndexedObject(kWeakPropertyCid); |
| 2236 writer->WriteIntptrValue(writer->GetObjectTags(this)); | 2241 writer->WriteIntptrValue(writer->GetObjectTags(this)); |
| 2237 | 2242 |
| 2238 // Write out all the other fields. | 2243 // Write out all the other fields. |
| 2239 writer->Write<RawObject*>(ptr()->key_); | 2244 writer->Write<RawObject*>(ptr()->key_); |
| 2240 writer->Write<RawObject*>(ptr()->value_); | 2245 writer->Write<RawObject*>(ptr()->value_); |
| 2241 } | 2246 } |
| 2242 | 2247 |
| 2243 } // namespace dart | 2248 } // namespace dart |
| OLD | NEW |