Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Side by Side Diff: runtime/vm/raw_object_snapshot.cc

Issue 9195031: Add ByteArray interface and provide internal and external implementations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fewer templates Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« runtime/vm/object.cc ('K') | « runtime/vm/raw_object.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/visitor.h" 9 #include "vm/visitor.h"
10 10
(...skipping 1619 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 object_id, 1630 object_id,
1631 kind, 1631 kind,
1632 ObjectStore::kImmutableArrayClass, 1632 ObjectStore::kImmutableArrayClass,
1633 ptr()->tags_, 1633 ptr()->tags_,
1634 ptr()->length_, 1634 ptr()->length_,
1635 ptr()->type_arguments_, 1635 ptr()->type_arguments_,
1636 ptr()->data()); 1636 ptr()->data());
1637 } 1637 }
1638 1638
1639 1639
1640 RawByteBuffer* ByteBuffer::ReadFrom(SnapshotReader* reader, 1640 RawByteArray* ByteArray::ReadFrom(SnapshotReader* reader,
1641 intptr_t object_id, 1641 intptr_t object_id,
1642 intptr_t tags, 1642 intptr_t tags,
1643 Snapshot::Kind kind) { 1643 Snapshot::Kind kind) {
1644 UNIMPLEMENTED(); 1644 UNREACHABLE(); // ByteArray is an abstract class.
1645 return ByteBuffer::null(); 1645 return ByteArray::null();
1646 } 1646 }
1647 1647
1648 1648
1649 void RawByteBuffer::WriteTo(SnapshotWriter* writer, 1649 RawInternalByteArray* InternalByteArray::ReadFrom(SnapshotReader* reader,
1650 intptr_t object_id, 1650 intptr_t object_id,
1651 Snapshot::Kind kind) { 1651 intptr_t tags,
1652 UNIMPLEMENTED(); 1652 Snapshot::Kind kind) {
1653 ASSERT(reader != NULL);
1654
1655 // Read the length so that we can determine instance size to allocate.
1656 intptr_t len = GetSmiValue(reader->ReadIntptrValue());
1657 Heap::Space space = (kind == Snapshot::kFull) ? Heap::kOld : Heap::kNew;
1658 InternalByteArray& result =
1659 InternalByteArray::ZoneHandle(reader->isolate(),
1660 InternalByteArray::New(len, space));
1661 reader->AddBackwardReference(object_id, &result);
1662
1663 // Set the object tags.
1664 result.set_tags(tags);
1665
1666 // Setup the array elements.
1667 for (intptr_t i = 0; i < len; i++) {
1668 result.SetAt<uint8_t>(i, reader->Read<uint8_t>());
1669 }
1670 return result.raw();
1653 } 1671 }
1654 1672
1655 1673
1674 RawExternalByteArray* ExternalByteArray::ReadFrom(SnapshotReader* reader,
1675 intptr_t object_id,
1676 intptr_t tags,
1677 Snapshot::Kind kind) {
1678 UNREACHABLE();
1679 return ExternalByteArray::null();
1680 }
1681
1682
1683 static void ByteArrayWriteTo(SnapshotWriter* writer,
1684 intptr_t object_id,
1685 Snapshot::Kind kind,
1686 intptr_t byte_array_kind,
1687 intptr_t tags,
1688 RawSmi* length,
1689 uint8_t* data) {
1690 ASSERT(writer != NULL);
1691 intptr_t len = Smi::Value(length);
1692
1693 // Write out the serialization header value for this object.
1694 writer->WriteSerializationMarker(kInlined, object_id);
1695
1696 // Write out the class and tags information.
1697 writer->WriteObjectHeader(byte_array_kind, tags);
1698
1699 // Write out the length field.
1700 writer->Write<RawObject*>(length);
1701
1702 // Write out the array elements.
1703 for (intptr_t i = 0; i < len; i++) {
1704 writer->Write(data[i]);
1705 }
1706 }
1707
1708
1709 void RawByteArray::WriteTo(SnapshotWriter* writer,
1710 intptr_t object_id,
1711 Snapshot::Kind kind) {
1712 UNREACHABLE(); // ByteArray is an abstract class
1713 }
1714
1715
1716 void RawInternalByteArray::WriteTo(SnapshotWriter* writer,
1717 intptr_t object_id,
1718 Snapshot::Kind kind) {
1719 ByteArrayWriteTo(writer,
1720 object_id,
1721 kind,
1722 ObjectStore::kInternalByteArrayClass,
1723 ptr()->tags_,
1724 ptr()->length_,
1725 ptr()->data());
1726 }
1727
1728
1729 void RawExternalByteArray::WriteTo(SnapshotWriter* writer,
1730 intptr_t object_id,
1731 Snapshot::Kind kind) {
1732 // Serialize as an internal byte array.
1733 ByteArrayWriteTo(writer,
1734 object_id,
1735 kind,
1736 ObjectStore::kInternalByteArrayClass,
1737 ptr()->tags_,
1738 ptr()->length_,
1739 ptr()->data_);
1740 }
1741
1742
1656 RawClosure* Closure::ReadFrom(SnapshotReader* reader, 1743 RawClosure* Closure::ReadFrom(SnapshotReader* reader,
1657 intptr_t object_id, 1744 intptr_t object_id,
1658 intptr_t tags, 1745 intptr_t tags,
1659 Snapshot::Kind kind) { 1746 Snapshot::Kind kind) {
1660 UNIMPLEMENTED(); 1747 UNIMPLEMENTED();
1661 return Closure::null(); 1748 return Closure::null();
1662 } 1749 }
1663 1750
1664 1751
1665 void RawClosure::WriteTo(SnapshotWriter* writer, 1752 void RawClosure::WriteTo(SnapshotWriter* writer,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 // Write out all the other fields. 1822 // Write out all the other fields.
1736 writer->Write<RawObject*>(ptr()->num_bracket_expressions_); 1823 writer->Write<RawObject*>(ptr()->num_bracket_expressions_);
1737 writer->WriteObject(ptr()->pattern_); 1824 writer->WriteObject(ptr()->pattern_);
1738 writer->WriteIntptrValue(ptr()->type_); 1825 writer->WriteIntptrValue(ptr()->type_);
1739 writer->WriteIntptrValue(ptr()->flags_); 1826 writer->WriteIntptrValue(ptr()->flags_);
1740 1827
1741 // Do not write out the data part which is native. 1828 // Do not write out the data part which is native.
1742 } 1829 }
1743 1830
1744 } // namespace dart 1831 } // namespace dart
OLDNEW
« runtime/vm/object.cc ('K') | « runtime/vm/raw_object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698