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 "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "include/dart_tools_api.h" | 7 #include "include/dart_tools_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 class TestSnapshotWriter : public SnapshotWriter { | 856 class TestSnapshotWriter : public SnapshotWriter { |
857 public: | 857 public: |
858 static const intptr_t kInitialSize = 64 * KB; | 858 static const intptr_t kInitialSize = 64 * KB; |
859 TestSnapshotWriter(uint8_t** buffer, ReAlloc alloc) | 859 TestSnapshotWriter(uint8_t** buffer, ReAlloc alloc) |
860 : SnapshotWriter(Snapshot::kScript, | 860 : SnapshotWriter(Snapshot::kScript, |
861 buffer, | 861 buffer, |
862 alloc, | 862 alloc, |
863 kInitialSize, | 863 kInitialSize, |
864 &forward_list_, | 864 &forward_list_, |
865 true), | 865 true), |
866 forward_list_(SnapshotWriter::FirstObjectId()) { | 866 forward_list_(kMaxPredefinedObjectIds) { |
867 ASSERT(buffer != NULL); | 867 ASSERT(buffer != NULL); |
868 ASSERT(alloc != NULL); | 868 ASSERT(alloc != NULL); |
869 } | 869 } |
870 ~TestSnapshotWriter() { } | 870 ~TestSnapshotWriter() { } |
871 | 871 |
872 // Writes just a script object | 872 // Writes just a script object |
873 void WriteScript(const Script& script) { | 873 void WriteScript(const Script& script) { |
874 WriteObject(script.raw()); | 874 WriteObject(script.raw()); |
875 UnmarkAll(); | 875 UnmarkAll(); |
876 } | 876 } |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1575 | 1575 |
1576 static const int kArrayLength = 2; | 1576 static const int kArrayLength = 2; |
1577 intptr_t data[kArrayLength] = {1, 2}; | 1577 intptr_t data[kArrayLength] = {1, 2}; |
1578 int len = kArrayLength; | 1578 int len = kArrayLength; |
1579 writer.WriteMessage(len, data); | 1579 writer.WriteMessage(len, data); |
1580 | 1580 |
1581 // Read object back from the snapshot into a C structure. | 1581 // Read object back from the snapshot into a C structure. |
1582 ApiNativeScope scope; | 1582 ApiNativeScope scope; |
1583 ApiMessageReader api_reader(buffer, | 1583 ApiMessageReader api_reader(buffer, |
1584 writer.BytesWritten(), | 1584 writer.BytesWritten(), |
1585 &zone_allocator, | 1585 &zone_allocator); |
1586 false); | |
1587 Dart_CObject* root = api_reader.ReadMessage(); | 1586 Dart_CObject* root = api_reader.ReadMessage(); |
1588 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1587 EXPECT_EQ(Dart_CObject_kArray, root->type); |
1589 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1588 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1590 for (int i = 0; i < kArrayLength; i++) { | 1589 for (int i = 0; i < kArrayLength; i++) { |
1591 Dart_CObject* element = root->value.as_array.values[i]; | 1590 Dart_CObject* element = root->value.as_array.values[i]; |
1592 EXPECT_EQ(Dart_CObject_kInt32, element->type); | 1591 EXPECT_EQ(Dart_CObject_kInt32, element->type); |
1593 EXPECT_EQ(i + 1, element->value.as_int32); | 1592 EXPECT_EQ(i + 1, element->value.as_int32); |
1594 } | 1593 } |
1595 CheckEncodeDecodeMessage(root); | 1594 CheckEncodeDecodeMessage(root); |
1596 } | 1595 } |
(...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2907 StackZone zone(Isolate::Current()); | 2906 StackZone zone(Isolate::Current()); |
2908 uint8_t* buffer; | 2907 uint8_t* buffer; |
2909 MessageWriter writer(&buffer, &zone_allocator, true); | 2908 MessageWriter writer(&buffer, &zone_allocator, true); |
2910 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 2909 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
2911 // For performance, we'd like single-byte headers when ids are omitted. | 2910 // For performance, we'd like single-byte headers when ids are omitted. |
2912 // If this starts failing, consider renumbering the snapshot ids. | 2911 // If this starts failing, consider renumbering the snapshot ids. |
2913 EXPECT_EQ(1, writer.BytesWritten()); | 2912 EXPECT_EQ(1, writer.BytesWritten()); |
2914 } | 2913 } |
2915 | 2914 |
2916 } // namespace dart | 2915 } // namespace dart |
OLD | NEW |