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

Side by Side Diff: vm/snapshot_test.cc

Issue 9124012: - Pass in the isolate parameter when creating handles. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' 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
« no previous file with comments | « vm/snapshot.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/snapshot.h" 5 #include "vm/snapshot.h"
6 6
7 #include "vm/assert.h" 7 #include "vm/assert.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 uint8_t* buffer; 46 uint8_t* buffer;
47 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator); 47 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
48 const Object& null_object = Object::Handle(); 48 const Object& null_object = Object::Handle();
49 writer.WriteObject(null_object.raw()); 49 writer.WriteObject(null_object.raw());
50 writer.FinalizeBuffer(); 50 writer.FinalizeBuffer();
51 51
52 // Create a snapshot object using the buffer. 52 // Create a snapshot object using the buffer.
53 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 53 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
54 54
55 // Read object back from the snapshot. 55 // Read object back from the snapshot.
56 Isolate* isolate= Isolate::Current(); 56 SnapshotReader reader(snapshot, Isolate::Current());
57 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
58 const Object& serialized_object = Object::Handle(reader.ReadObject()); 57 const Object& serialized_object = Object::Handle(reader.ReadObject());
59 EXPECT(Equals(null_object, serialized_object)); 58 EXPECT(Equals(null_object, serialized_object));
60 } 59 }
61 60
62 61
63 TEST_CASE(SerializeSmi1) { 62 TEST_CASE(SerializeSmi1) {
64 // Write snapshot with object content. 63 // Write snapshot with object content.
65 uint8_t* buffer; 64 uint8_t* buffer;
66 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator); 65 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
67 const Smi& smi = Smi::Handle(Smi::New(124)); 66 const Smi& smi = Smi::Handle(Smi::New(124));
68 writer.WriteObject(smi.raw()); 67 writer.WriteObject(smi.raw());
69 writer.FinalizeBuffer(); 68 writer.FinalizeBuffer();
70 69
71 // Create a snapshot object using the buffer. 70 // Create a snapshot object using the buffer.
72 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 71 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
73 72
74 // Read object back from the snapshot. 73 // Read object back from the snapshot.
75 Isolate* isolate= Isolate::Current(); 74 SnapshotReader reader(snapshot, Isolate::Current());
76 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
77 const Object& serialized_object = Object::Handle(reader.ReadObject()); 75 const Object& serialized_object = Object::Handle(reader.ReadObject());
78 EXPECT(Equals(smi, serialized_object)); 76 EXPECT(Equals(smi, serialized_object));
79 } 77 }
80 78
81 79
82 TEST_CASE(SerializeSmi2) { 80 TEST_CASE(SerializeSmi2) {
83 // Write snapshot with object content. 81 // Write snapshot with object content.
84 uint8_t* buffer; 82 uint8_t* buffer;
85 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator); 83 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
86 const Smi& smi = Smi::Handle(Smi::New(-1)); 84 const Smi& smi = Smi::Handle(Smi::New(-1));
87 writer.WriteObject(smi.raw()); 85 writer.WriteObject(smi.raw());
88 writer.FinalizeBuffer(); 86 writer.FinalizeBuffer();
89 87
90 // Create a snapshot object using the buffer. 88 // Create a snapshot object using the buffer.
91 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 89 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
92 90
93 // Read object back from the snapshot. 91 // Read object back from the snapshot.
94 Isolate* isolate= Isolate::Current(); 92 SnapshotReader reader(snapshot, Isolate::Current());
95 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
96 const Object& serialized_object = Object::Handle(reader.ReadObject()); 93 const Object& serialized_object = Object::Handle(reader.ReadObject());
97 EXPECT(Equals(smi, serialized_object)); 94 EXPECT(Equals(smi, serialized_object));
98 } 95 }
99 96
100 97
101 TEST_CASE(SerializeDouble) { 98 TEST_CASE(SerializeDouble) {
102 // Write snapshot with object content. 99 // Write snapshot with object content.
103 uint8_t* buffer; 100 uint8_t* buffer;
104 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator); 101 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
105 const Double& dbl = Double::Handle(Double::New(101.29)); 102 const Double& dbl = Double::Handle(Double::New(101.29));
106 writer.WriteObject(dbl.raw()); 103 writer.WriteObject(dbl.raw());
107 writer.FinalizeBuffer(); 104 writer.FinalizeBuffer();
108 105
109 // Create a snapshot object using the buffer. 106 // Create a snapshot object using the buffer.
110 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 107 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
111 108
112 // Read object back from the snapshot. 109 // Read object back from the snapshot.
113 Isolate* isolate= Isolate::Current(); 110 SnapshotReader reader(snapshot, Isolate::Current());
114 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
115 const Object& serialized_object = Object::Handle(reader.ReadObject()); 111 const Object& serialized_object = Object::Handle(reader.ReadObject());
116 EXPECT(Equals(dbl, serialized_object)); 112 EXPECT(Equals(dbl, serialized_object));
117 } 113 }
118 114
119 115
120 TEST_CASE(SerializeBool) { 116 TEST_CASE(SerializeBool) {
121 // Write snapshot with object content. 117 // Write snapshot with object content.
122 uint8_t* buffer; 118 uint8_t* buffer;
123 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator); 119 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
124 const Bool& bool1 = Bool::Handle(Bool::True()); 120 const Bool& bool1 = Bool::Handle(Bool::True());
125 const Bool& bool2 = Bool::Handle(Bool::False()); 121 const Bool& bool2 = Bool::Handle(Bool::False());
126 writer.WriteObject(bool1.raw()); 122 writer.WriteObject(bool1.raw());
127 writer.WriteObject(bool2.raw()); 123 writer.WriteObject(bool2.raw());
128 writer.FinalizeBuffer(); 124 writer.FinalizeBuffer();
129 125
130 // Create a snapshot object using the buffer. 126 // Create a snapshot object using the buffer.
131 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 127 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
132 128
133 // Read object back from the snapshot. 129 // Read object back from the snapshot.
134 Isolate* isolate= Isolate::Current(); 130 SnapshotReader reader(snapshot, Isolate::Current());
135 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
136 EXPECT(Bool::True() == reader.ReadObject()); 131 EXPECT(Bool::True() == reader.ReadObject());
137 EXPECT(Bool::False() == reader.ReadObject()); 132 EXPECT(Bool::False() == reader.ReadObject());
138 } 133 }
139 134
140 135
141 TEST_CASE(SerializeBigint) { 136 TEST_CASE(SerializeBigint) {
142 // Write snapshot with object content. 137 // Write snapshot with object content.
143 uint8_t* buffer; 138 uint8_t* buffer;
144 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator); 139 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
145 const Bigint& bigint = Bigint::Handle(Bigint::New(0xfffffffffLL)); 140 const Bigint& bigint = Bigint::Handle(Bigint::New(0xfffffffffLL));
146 writer.WriteObject(bigint.raw()); 141 writer.WriteObject(bigint.raw());
147 writer.FinalizeBuffer(); 142 writer.FinalizeBuffer();
148 143
149 // Create a snapshot object using the buffer. 144 // Create a snapshot object using the buffer.
150 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 145 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
151 146
152 // Read object back from the snapshot. 147 // Read object back from the snapshot.
153 Isolate* isolate= Isolate::Current(); 148 SnapshotReader reader(snapshot, Isolate::Current());
154 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
155 Bigint& obj = Bigint::Handle(); 149 Bigint& obj = Bigint::Handle();
156 obj ^= reader.ReadObject(); 150 obj ^= reader.ReadObject();
157 OS::Print("%lld", BigintOperations::ToInt64(obj)); 151 OS::Print("%lld", BigintOperations::ToInt64(obj));
158 EXPECT_EQ(BigintOperations::ToInt64(bigint), BigintOperations::ToInt64(obj)); 152 EXPECT_EQ(BigintOperations::ToInt64(bigint), BigintOperations::ToInt64(obj));
159 } 153 }
160 154
161 155
162 TEST_CASE(SerializeSingletons) { 156 TEST_CASE(SerializeSingletons) {
163 // Write snapshot with object content. 157 // Write snapshot with object content.
164 uint8_t* buffer; 158 uint8_t* buffer;
(...skipping 16 matching lines...) Expand all
181 writer.WriteObject(Object::pc_descriptors_class()); 175 writer.WriteObject(Object::pc_descriptors_class());
182 writer.WriteObject(Object::exception_handlers_class()); 176 writer.WriteObject(Object::exception_handlers_class());
183 writer.WriteObject(Object::context_class()); 177 writer.WriteObject(Object::context_class());
184 writer.WriteObject(Object::context_scope_class()); 178 writer.WriteObject(Object::context_scope_class());
185 writer.FinalizeBuffer(); 179 writer.FinalizeBuffer();
186 180
187 // Create a snapshot object using the buffer. 181 // Create a snapshot object using the buffer.
188 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 182 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
189 183
190 // Read object back from the snapshot. 184 // Read object back from the snapshot.
191 Isolate* isolate= Isolate::Current(); 185 SnapshotReader reader(snapshot, Isolate::Current());
192 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
193 EXPECT(Object::class_class() == reader.ReadObject()); 186 EXPECT(Object::class_class() == reader.ReadObject());
194 EXPECT(Object::null_class() == reader.ReadObject()); 187 EXPECT(Object::null_class() == reader.ReadObject());
195 EXPECT(Object::type_class() == reader.ReadObject()); 188 EXPECT(Object::type_class() == reader.ReadObject());
196 EXPECT(Object::type_parameter_class() == reader.ReadObject()); 189 EXPECT(Object::type_parameter_class() == reader.ReadObject());
197 EXPECT(Object::instantiated_type_class() == reader.ReadObject()); 190 EXPECT(Object::instantiated_type_class() == reader.ReadObject());
198 EXPECT(Object::abstract_type_arguments_class() == reader.ReadObject()); 191 EXPECT(Object::abstract_type_arguments_class() == reader.ReadObject());
199 EXPECT(Object::type_arguments_class() == reader.ReadObject()); 192 EXPECT(Object::type_arguments_class() == reader.ReadObject());
200 EXPECT(Object::instantiated_type_arguments_class() == reader.ReadObject()); 193 EXPECT(Object::instantiated_type_arguments_class() == reader.ReadObject());
201 EXPECT(Object::function_class() == reader.ReadObject()); 194 EXPECT(Object::function_class() == reader.ReadObject());
202 EXPECT(Object::field_class() == reader.ReadObject()); 195 EXPECT(Object::field_class() == reader.ReadObject());
(...skipping 14 matching lines...) Expand all
217 uint8_t* buffer; 210 uint8_t* buffer;
218 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator); 211 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
219 String& str = String::Handle(String::New("This string shall be serialized")); 212 String& str = String::Handle(String::New("This string shall be serialized"));
220 writer.WriteObject(str.raw()); 213 writer.WriteObject(str.raw());
221 writer.FinalizeBuffer(); 214 writer.FinalizeBuffer();
222 215
223 // Create a snapshot object using the buffer. 216 // Create a snapshot object using the buffer.
224 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 217 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
225 218
226 // Read object back from the snapshot. 219 // Read object back from the snapshot.
227 Isolate* isolate= Isolate::Current(); 220 SnapshotReader reader(snapshot, Isolate::Current());
228 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
229 String& serialized_str = String::Handle(); 221 String& serialized_str = String::Handle();
230 serialized_str ^= reader.ReadObject(); 222 serialized_str ^= reader.ReadObject();
231 EXPECT(str.Equals(serialized_str)); 223 EXPECT(str.Equals(serialized_str));
232 } 224 }
233 225
234 226
235 TEST_CASE(SerializeArray) { 227 TEST_CASE(SerializeArray) {
236 // Write snapshot with object content. 228 // Write snapshot with object content.
237 uint8_t* buffer; 229 uint8_t* buffer;
238 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator); 230 SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
239 const int kArrayLength = 10; 231 const int kArrayLength = 10;
240 Array& array = Array::Handle(Array::New(kArrayLength)); 232 Array& array = Array::Handle(Array::New(kArrayLength));
241 Smi& smi = Smi::Handle(); 233 Smi& smi = Smi::Handle();
242 for (int i = 0; i < kArrayLength; i++) { 234 for (int i = 0; i < kArrayLength; i++) {
243 smi ^= Smi::New(i); 235 smi ^= Smi::New(i);
244 array.SetAt(i, smi); 236 array.SetAt(i, smi);
245 } 237 }
246 writer.WriteObject(array.raw()); 238 writer.WriteObject(array.raw());
247 writer.FinalizeBuffer(); 239 writer.FinalizeBuffer();
248 240
249 // Create a snapshot object using the buffer. 241 // Create a snapshot object using the buffer.
250 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 242 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
251 243
252 // Read object back from the snapshot. 244 // Read object back from the snapshot.
253 Isolate* isolate= Isolate::Current(); 245 SnapshotReader reader(snapshot, Isolate::Current());
254 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
255 Array& serialized_array = Array::Handle(); 246 Array& serialized_array = Array::Handle();
256 serialized_array ^= reader.ReadObject(); 247 serialized_array ^= reader.ReadObject();
257 EXPECT(array.Equals(serialized_array)); 248 EXPECT(array.Equals(serialized_array));
258 } 249 }
259 250
260 251
261 TEST_CASE(SerializeScript) { 252 TEST_CASE(SerializeScript) {
262 const char* kScriptChars = 253 const char* kScriptChars =
263 "class A {\n" 254 "class A {\n"
264 " static bar() { return 42; }\n" 255 " static bar() { return 42; }\n"
(...skipping 11 matching lines...) Expand all
276 // Write snapshot with object content. 267 // Write snapshot with object content.
277 uint8_t* buffer; 268 uint8_t* buffer;
278 SnapshotWriter writer(Snapshot::kScript, &buffer, &allocator); 269 SnapshotWriter writer(Snapshot::kScript, &buffer, &allocator);
279 writer.WriteObject(script.raw()); 270 writer.WriteObject(script.raw());
280 writer.FinalizeBuffer(); 271 writer.FinalizeBuffer();
281 272
282 // Create a snapshot object using the buffer. 273 // Create a snapshot object using the buffer.
283 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); 274 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer);
284 275
285 // Read object back from the snapshot. 276 // Read object back from the snapshot.
286 Isolate* isolate= Isolate::Current(); 277 SnapshotReader reader(snapshot, Isolate::Current());
287 SnapshotReader reader(snapshot, isolate->heap(), isolate->object_store());
288 Script& serialized_script = Script::Handle(); 278 Script& serialized_script = Script::Handle();
289 serialized_script ^= reader.ReadObject(); 279 serialized_script ^= reader.ReadObject();
290 280
291 // Check if the serialized script object matches the original script. 281 // Check if the serialized script object matches the original script.
292 String& str = String::Handle(); 282 String& str = String::Handle();
293 str ^= serialized_script.source(); 283 str ^= serialized_script.source();
294 EXPECT(source.Equals(str)); 284 EXPECT(source.Equals(str));
295 str ^= serialized_script.url(); 285 str ^= serialized_script.url();
296 EXPECT(url.Equals(str)); 286 EXPECT(url.Equals(str));
297 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); 287 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens());
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 Dart_ExitScope(); 520 Dart_ExitScope();
531 } 521 }
532 Dart_ShutdownIsolate(); 522 Dart_ShutdownIsolate();
533 free(full_snapshot); 523 free(full_snapshot);
534 free(script_snapshot); 524 free(script_snapshot);
535 } 525 }
536 526
537 #endif // TARGET_ARCH_IA32. 527 #endif // TARGET_ARCH_IA32.
538 528
539 } // namespace dart 529 } // namespace dart
OLDNEW
« no previous file with comments | « vm/snapshot.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698