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_debugger_api.h" | 7 #include "include/dart_debugger_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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 StackZone zone(Isolate::Current()); | 150 StackZone zone(Isolate::Current()); |
151 | 151 |
152 // Write snapshot with object content. | 152 // Write snapshot with object content. |
153 uint8_t* buffer; | 153 uint8_t* buffer; |
154 MessageWriter writer(&buffer, &zone_allocator, true); | 154 MessageWriter writer(&buffer, &zone_allocator, true); |
155 const Object& null_object = Object::Handle(); | 155 const Object& null_object = Object::Handle(); |
156 writer.WriteMessage(null_object); | 156 writer.WriteMessage(null_object); |
157 intptr_t buffer_len = writer.BytesWritten(); | 157 intptr_t buffer_len = writer.BytesWritten(); |
158 | 158 |
159 // Read object back from the snapshot. | 159 // Read object back from the snapshot. |
160 SnapshotReader reader(buffer, buffer_len, | 160 MessageSnapshotReader reader(buffer, |
161 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); | 161 buffer_len, |
| 162 Isolate::Current(), |
| 163 zone.GetZone()); |
162 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 164 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
163 EXPECT(Equals(null_object, serialized_object)); | 165 EXPECT(Equals(null_object, serialized_object)); |
164 | 166 |
165 // Read object back from the snapshot into a C structure. | 167 // Read object back from the snapshot into a C structure. |
166 ApiNativeScope scope; | 168 ApiNativeScope scope; |
167 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 169 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
168 Dart_CObject* root = api_reader.ReadMessage(); | 170 Dart_CObject* root = api_reader.ReadMessage(); |
169 EXPECT_NOTNULL(root); | 171 EXPECT_NOTNULL(root); |
170 EXPECT_EQ(Dart_CObject_kNull, root->type); | 172 EXPECT_EQ(Dart_CObject_kNull, root->type); |
171 CheckEncodeDecodeMessage(root); | 173 CheckEncodeDecodeMessage(root); |
172 } | 174 } |
173 | 175 |
174 | 176 |
175 TEST_CASE(SerializeSmi1) { | 177 TEST_CASE(SerializeSmi1) { |
176 StackZone zone(Isolate::Current()); | 178 StackZone zone(Isolate::Current()); |
177 | 179 |
178 // Write snapshot with object content. | 180 // Write snapshot with object content. |
179 uint8_t* buffer; | 181 uint8_t* buffer; |
180 MessageWriter writer(&buffer, &zone_allocator, true); | 182 MessageWriter writer(&buffer, &zone_allocator, true); |
181 const Smi& smi = Smi::Handle(Smi::New(124)); | 183 const Smi& smi = Smi::Handle(Smi::New(124)); |
182 writer.WriteMessage(smi); | 184 writer.WriteMessage(smi); |
183 intptr_t buffer_len = writer.BytesWritten(); | 185 intptr_t buffer_len = writer.BytesWritten(); |
184 | 186 |
185 // Read object back from the snapshot. | 187 // Read object back from the snapshot. |
186 SnapshotReader reader(buffer, buffer_len, | 188 MessageSnapshotReader reader(buffer, |
187 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); | 189 buffer_len, |
| 190 Isolate::Current(), |
| 191 zone.GetZone()); |
188 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 192 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
189 EXPECT(Equals(smi, serialized_object)); | 193 EXPECT(Equals(smi, serialized_object)); |
190 | 194 |
191 // Read object back from the snapshot into a C structure. | 195 // Read object back from the snapshot into a C structure. |
192 ApiNativeScope scope; | 196 ApiNativeScope scope; |
193 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 197 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
194 Dart_CObject* root = api_reader.ReadMessage(); | 198 Dart_CObject* root = api_reader.ReadMessage(); |
195 EXPECT_NOTNULL(root); | 199 EXPECT_NOTNULL(root); |
196 EXPECT_EQ(Dart_CObject_kInt32, root->type); | 200 EXPECT_EQ(Dart_CObject_kInt32, root->type); |
197 EXPECT_EQ(smi.Value(), root->value.as_int32); | 201 EXPECT_EQ(smi.Value(), root->value.as_int32); |
198 CheckEncodeDecodeMessage(root); | 202 CheckEncodeDecodeMessage(root); |
199 } | 203 } |
200 | 204 |
201 | 205 |
202 TEST_CASE(SerializeSmi2) { | 206 TEST_CASE(SerializeSmi2) { |
203 StackZone zone(Isolate::Current()); | 207 StackZone zone(Isolate::Current()); |
204 | 208 |
205 // Write snapshot with object content. | 209 // Write snapshot with object content. |
206 uint8_t* buffer; | 210 uint8_t* buffer; |
207 MessageWriter writer(&buffer, &zone_allocator, true); | 211 MessageWriter writer(&buffer, &zone_allocator, true); |
208 const Smi& smi = Smi::Handle(Smi::New(-1)); | 212 const Smi& smi = Smi::Handle(Smi::New(-1)); |
209 writer.WriteMessage(smi); | 213 writer.WriteMessage(smi); |
210 intptr_t buffer_len = writer.BytesWritten(); | 214 intptr_t buffer_len = writer.BytesWritten(); |
211 | 215 |
212 // Read object back from the snapshot. | 216 // Read object back from the snapshot. |
213 SnapshotReader reader(buffer, buffer_len, | 217 MessageSnapshotReader reader(buffer, |
214 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); | 218 buffer_len, |
| 219 Isolate::Current(), |
| 220 zone.GetZone()); |
215 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 221 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
216 EXPECT(Equals(smi, serialized_object)); | 222 EXPECT(Equals(smi, serialized_object)); |
217 | 223 |
218 // Read object back from the snapshot into a C structure. | 224 // Read object back from the snapshot into a C structure. |
219 ApiNativeScope scope; | 225 ApiNativeScope scope; |
220 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 226 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
221 Dart_CObject* root = api_reader.ReadMessage(); | 227 Dart_CObject* root = api_reader.ReadMessage(); |
222 EXPECT_NOTNULL(root); | 228 EXPECT_NOTNULL(root); |
223 EXPECT_EQ(Dart_CObject_kInt32, root->type); | 229 EXPECT_EQ(Dart_CObject_kInt32, root->type); |
224 EXPECT_EQ(smi.Value(), root->value.as_int32); | 230 EXPECT_EQ(smi.Value(), root->value.as_int32); |
225 CheckEncodeDecodeMessage(root); | 231 CheckEncodeDecodeMessage(root); |
226 } | 232 } |
227 | 233 |
228 | 234 |
229 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) { | 235 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) { |
230 // Write snapshot with object content. | 236 // Write snapshot with object content. |
231 uint8_t* buffer; | 237 uint8_t* buffer; |
232 MessageWriter writer(&buffer, &zone_allocator, true); | 238 MessageWriter writer(&buffer, &zone_allocator, true); |
233 writer.WriteMessage(mint); | 239 writer.WriteMessage(mint); |
234 intptr_t buffer_len = writer.BytesWritten(); | 240 intptr_t buffer_len = writer.BytesWritten(); |
235 | 241 |
236 // Read object back from the snapshot. | 242 // Read object back from the snapshot. |
237 SnapshotReader reader(buffer, buffer_len, | 243 MessageSnapshotReader reader(buffer, |
238 Snapshot::kMessage, Isolate::Current(), | 244 buffer_len, |
239 Thread::Current()->zone()); | 245 Isolate::Current(), |
| 246 Thread::Current()->zone()); |
240 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 247 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
241 EXPECT(serialized_object.IsMint()); | 248 EXPECT(serialized_object.IsMint()); |
242 | 249 |
243 // Read object back from the snapshot into a C structure. | 250 // Read object back from the snapshot into a C structure. |
244 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 251 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
245 Dart_CObject* root = api_reader.ReadMessage(); | 252 Dart_CObject* root = api_reader.ReadMessage(); |
246 EXPECT_NOTNULL(root); | 253 EXPECT_NOTNULL(root); |
247 CheckEncodeDecodeMessage(root); | 254 CheckEncodeDecodeMessage(root); |
248 return root; | 255 return root; |
249 } | 256 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 StackZone zone(Isolate::Current()); | 306 StackZone zone(Isolate::Current()); |
300 | 307 |
301 // Write snapshot with object content. | 308 // Write snapshot with object content. |
302 uint8_t* buffer; | 309 uint8_t* buffer; |
303 MessageWriter writer(&buffer, &zone_allocator, true); | 310 MessageWriter writer(&buffer, &zone_allocator, true); |
304 const Double& dbl = Double::Handle(Double::New(101.29)); | 311 const Double& dbl = Double::Handle(Double::New(101.29)); |
305 writer.WriteMessage(dbl); | 312 writer.WriteMessage(dbl); |
306 intptr_t buffer_len = writer.BytesWritten(); | 313 intptr_t buffer_len = writer.BytesWritten(); |
307 | 314 |
308 // Read object back from the snapshot. | 315 // Read object back from the snapshot. |
309 SnapshotReader reader(buffer, buffer_len, | 316 MessageSnapshotReader reader(buffer, |
310 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); | 317 buffer_len, |
| 318 Isolate::Current(), |
| 319 zone.GetZone()); |
311 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 320 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
312 EXPECT(Equals(dbl, serialized_object)); | 321 EXPECT(Equals(dbl, serialized_object)); |
313 | 322 |
314 // Read object back from the snapshot into a C structure. | 323 // Read object back from the snapshot into a C structure. |
315 ApiNativeScope scope; | 324 ApiNativeScope scope; |
316 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 325 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
317 Dart_CObject* root = api_reader.ReadMessage(); | 326 Dart_CObject* root = api_reader.ReadMessage(); |
318 EXPECT_NOTNULL(root); | 327 EXPECT_NOTNULL(root); |
319 EXPECT_EQ(Dart_CObject_kDouble, root->type); | 328 EXPECT_EQ(Dart_CObject_kDouble, root->type); |
320 EXPECT_EQ(dbl.value(), root->value.as_double); | 329 EXPECT_EQ(dbl.value(), root->value.as_double); |
321 CheckEncodeDecodeMessage(root); | 330 CheckEncodeDecodeMessage(root); |
322 } | 331 } |
323 | 332 |
324 | 333 |
325 TEST_CASE(SerializeTrue) { | 334 TEST_CASE(SerializeTrue) { |
326 StackZone zone(Isolate::Current()); | 335 StackZone zone(Isolate::Current()); |
327 | 336 |
328 // Write snapshot with true object. | 337 // Write snapshot with true object. |
329 uint8_t* buffer; | 338 uint8_t* buffer; |
330 MessageWriter writer(&buffer, &zone_allocator, true); | 339 MessageWriter writer(&buffer, &zone_allocator, true); |
331 const Bool& bl = Bool::True(); | 340 const Bool& bl = Bool::True(); |
332 writer.WriteMessage(bl); | 341 writer.WriteMessage(bl); |
333 intptr_t buffer_len = writer.BytesWritten(); | 342 intptr_t buffer_len = writer.BytesWritten(); |
334 | 343 |
335 // Read object back from the snapshot. | 344 // Read object back from the snapshot. |
336 SnapshotReader reader(buffer, buffer_len, | 345 MessageSnapshotReader reader(buffer, |
337 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); | 346 buffer_len, |
| 347 Isolate::Current(), |
| 348 zone.GetZone()); |
338 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 349 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
339 fprintf(stderr, "%s / %s\n", bl.ToCString(), serialized_object.ToCString()); | 350 fprintf(stderr, "%s / %s\n", bl.ToCString(), serialized_object.ToCString()); |
340 | 351 |
341 EXPECT(Equals(bl, serialized_object)); | 352 EXPECT(Equals(bl, serialized_object)); |
342 | 353 |
343 // Read object back from the snapshot into a C structure. | 354 // Read object back from the snapshot into a C structure. |
344 ApiNativeScope scope; | 355 ApiNativeScope scope; |
345 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 356 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
346 Dart_CObject* root = api_reader.ReadMessage(); | 357 Dart_CObject* root = api_reader.ReadMessage(); |
347 EXPECT_NOTNULL(root); | 358 EXPECT_NOTNULL(root); |
348 EXPECT_EQ(Dart_CObject_kBool, root->type); | 359 EXPECT_EQ(Dart_CObject_kBool, root->type); |
349 EXPECT_EQ(true, root->value.as_bool); | 360 EXPECT_EQ(true, root->value.as_bool); |
350 CheckEncodeDecodeMessage(root); | 361 CheckEncodeDecodeMessage(root); |
351 } | 362 } |
352 | 363 |
353 | 364 |
354 TEST_CASE(SerializeFalse) { | 365 TEST_CASE(SerializeFalse) { |
355 StackZone zone(Isolate::Current()); | 366 StackZone zone(Isolate::Current()); |
356 | 367 |
357 // Write snapshot with false object. | 368 // Write snapshot with false object. |
358 uint8_t* buffer; | 369 uint8_t* buffer; |
359 MessageWriter writer(&buffer, &zone_allocator, true); | 370 MessageWriter writer(&buffer, &zone_allocator, true); |
360 const Bool& bl = Bool::False(); | 371 const Bool& bl = Bool::False(); |
361 writer.WriteMessage(bl); | 372 writer.WriteMessage(bl); |
362 intptr_t buffer_len = writer.BytesWritten(); | 373 intptr_t buffer_len = writer.BytesWritten(); |
363 | 374 |
364 // Read object back from the snapshot. | 375 // Read object back from the snapshot. |
365 SnapshotReader reader(buffer, buffer_len, | 376 MessageSnapshotReader reader(buffer, |
366 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); | 377 buffer_len, |
| 378 Isolate::Current(), |
| 379 zone.GetZone()); |
367 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 380 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
368 EXPECT(Equals(bl, serialized_object)); | 381 EXPECT(Equals(bl, serialized_object)); |
369 | 382 |
370 // Read object back from the snapshot into a C structure. | 383 // Read object back from the snapshot into a C structure. |
371 ApiNativeScope scope; | 384 ApiNativeScope scope; |
372 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 385 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
373 Dart_CObject* root = api_reader.ReadMessage(); | 386 Dart_CObject* root = api_reader.ReadMessage(); |
374 EXPECT_NOTNULL(root); | 387 EXPECT_NOTNULL(root); |
375 EXPECT_EQ(Dart_CObject_kBool, root->type); | 388 EXPECT_EQ(Dart_CObject_kBool, root->type); |
376 EXPECT_EQ(false, root->value.as_bool); | 389 EXPECT_EQ(false, root->value.as_bool); |
(...skipping 13 matching lines...) Expand all Loading... |
390 uint8_t* buffer; | 403 uint8_t* buffer; |
391 MessageWriter writer(&buffer, &zone_allocator, true); | 404 MessageWriter writer(&buffer, &zone_allocator, true); |
392 const char* cstr = "0x270FFFFFFFFFFFFFD8F0"; | 405 const char* cstr = "0x270FFFFFFFFFFFFFD8F0"; |
393 const String& str = String::Handle(String::New(cstr)); | 406 const String& str = String::Handle(String::New(cstr)); |
394 Bigint& bigint = Bigint::Handle(); | 407 Bigint& bigint = Bigint::Handle(); |
395 bigint ^= Integer::NewCanonical(str); | 408 bigint ^= Integer::NewCanonical(str); |
396 writer.WriteMessage(bigint); | 409 writer.WriteMessage(bigint); |
397 intptr_t buffer_len = writer.BytesWritten(); | 410 intptr_t buffer_len = writer.BytesWritten(); |
398 | 411 |
399 // Read object back from the snapshot. | 412 // Read object back from the snapshot. |
400 SnapshotReader reader(buffer, buffer_len, | 413 MessageSnapshotReader reader(buffer, |
401 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); | 414 buffer_len, |
| 415 Isolate::Current(), |
| 416 zone.GetZone()); |
402 Bigint& obj = Bigint::Handle(); | 417 Bigint& obj = Bigint::Handle(); |
403 obj ^= reader.ReadObject(); | 418 obj ^= reader.ReadObject(); |
404 | 419 |
405 EXPECT_STREQ(bigint.ToHexCString(allocator), obj.ToHexCString(allocator)); | 420 EXPECT_STREQ(bigint.ToHexCString(allocator), obj.ToHexCString(allocator)); |
406 | 421 |
407 // Read object back from the snapshot into a C structure. | 422 // Read object back from the snapshot into a C structure. |
408 ApiNativeScope scope; | 423 ApiNativeScope scope; |
409 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 424 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
410 Dart_CObject* root = api_reader.ReadMessage(); | 425 Dart_CObject* root = api_reader.ReadMessage(); |
411 EXPECT_NOTNULL(root); | 426 EXPECT_NOTNULL(root); |
412 EXPECT_EQ(Dart_CObject_kBigint, root->type); | 427 EXPECT_EQ(Dart_CObject_kBigint, root->type); |
413 char* hex_value = TestCase::BigintToHexValue(root); | 428 char* hex_value = TestCase::BigintToHexValue(root); |
414 EXPECT_STREQ(cstr, hex_value); | 429 EXPECT_STREQ(cstr, hex_value); |
415 free(hex_value); | 430 free(hex_value); |
416 CheckEncodeDecodeMessage(root); | 431 CheckEncodeDecodeMessage(root); |
417 } | 432 } |
418 | 433 |
419 | 434 |
420 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { | 435 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { |
421 // Write snapshot with object content. | 436 // Write snapshot with object content. |
422 uint8_t* buffer; | 437 uint8_t* buffer; |
423 MessageWriter writer(&buffer, &zone_allocator, true); | 438 MessageWriter writer(&buffer, &zone_allocator, true); |
424 writer.WriteMessage(bigint); | 439 writer.WriteMessage(bigint); |
425 intptr_t buffer_len = writer.BytesWritten(); | 440 intptr_t buffer_len = writer.BytesWritten(); |
426 | 441 |
427 // Read object back from the snapshot. | 442 // Read object back from the snapshot. |
428 SnapshotReader reader(buffer, buffer_len, | 443 MessageSnapshotReader reader(buffer, |
429 Snapshot::kMessage, Isolate::Current(), | 444 buffer_len, |
430 Thread::Current()->zone()); | 445 Isolate::Current(), |
| 446 Thread::Current()->zone()); |
431 Bigint& serialized_bigint = Bigint::Handle(); | 447 Bigint& serialized_bigint = Bigint::Handle(); |
432 serialized_bigint ^= reader.ReadObject(); | 448 serialized_bigint ^= reader.ReadObject(); |
433 const char* str1 = bigint.ToHexCString(allocator); | 449 const char* str1 = bigint.ToHexCString(allocator); |
434 const char* str2 = serialized_bigint.ToHexCString(allocator); | 450 const char* str2 = serialized_bigint.ToHexCString(allocator); |
435 EXPECT_STREQ(str1, str2); | 451 EXPECT_STREQ(str1, str2); |
436 free(const_cast<char*>(str1)); | 452 free(const_cast<char*>(str1)); |
437 free(const_cast<char*>(str2)); | 453 free(const_cast<char*>(str2)); |
438 | 454 |
439 // Read object back from the snapshot into a C structure. | 455 // Read object back from the snapshot into a C structure. |
440 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 456 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 writer.WriteObject(Object::library_class()); | 499 writer.WriteObject(Object::library_class()); |
484 writer.WriteObject(Object::code_class()); | 500 writer.WriteObject(Object::code_class()); |
485 writer.WriteObject(Object::instructions_class()); | 501 writer.WriteObject(Object::instructions_class()); |
486 writer.WriteObject(Object::pc_descriptors_class()); | 502 writer.WriteObject(Object::pc_descriptors_class()); |
487 writer.WriteObject(Object::exception_handlers_class()); | 503 writer.WriteObject(Object::exception_handlers_class()); |
488 writer.WriteObject(Object::context_class()); | 504 writer.WriteObject(Object::context_class()); |
489 writer.WriteObject(Object::context_scope_class()); | 505 writer.WriteObject(Object::context_scope_class()); |
490 intptr_t buffer_len = writer.BytesWritten(); | 506 intptr_t buffer_len = writer.BytesWritten(); |
491 | 507 |
492 // Read object back from the snapshot. | 508 // Read object back from the snapshot. |
493 SnapshotReader reader(buffer, buffer_len, Snapshot::kMessage, | 509 MessageSnapshotReader reader(buffer, |
494 Isolate::Current(), Thread::Current()->zone()); | 510 buffer_len, |
| 511 Isolate::Current(), |
| 512 Thread::Current()->zone()); |
495 EXPECT(Object::class_class() == reader.ReadObject()); | 513 EXPECT(Object::class_class() == reader.ReadObject()); |
496 EXPECT(Object::type_arguments_class() == reader.ReadObject()); | 514 EXPECT(Object::type_arguments_class() == reader.ReadObject()); |
497 EXPECT(Object::function_class() == reader.ReadObject()); | 515 EXPECT(Object::function_class() == reader.ReadObject()); |
498 EXPECT(Object::field_class() == reader.ReadObject()); | 516 EXPECT(Object::field_class() == reader.ReadObject()); |
499 EXPECT(Object::token_stream_class() == reader.ReadObject()); | 517 EXPECT(Object::token_stream_class() == reader.ReadObject()); |
500 EXPECT(Object::script_class() == reader.ReadObject()); | 518 EXPECT(Object::script_class() == reader.ReadObject()); |
501 EXPECT(Object::library_class() == reader.ReadObject()); | 519 EXPECT(Object::library_class() == reader.ReadObject()); |
502 EXPECT(Object::code_class() == reader.ReadObject()); | 520 EXPECT(Object::code_class() == reader.ReadObject()); |
503 EXPECT(Object::instructions_class() == reader.ReadObject()); | 521 EXPECT(Object::instructions_class() == reader.ReadObject()); |
504 EXPECT(Object::pc_descriptors_class() == reader.ReadObject()); | 522 EXPECT(Object::pc_descriptors_class() == reader.ReadObject()); |
505 EXPECT(Object::exception_handlers_class() == reader.ReadObject()); | 523 EXPECT(Object::exception_handlers_class() == reader.ReadObject()); |
506 EXPECT(Object::context_class() == reader.ReadObject()); | 524 EXPECT(Object::context_class() == reader.ReadObject()); |
507 EXPECT(Object::context_scope_class() == reader.ReadObject()); | 525 EXPECT(Object::context_scope_class() == reader.ReadObject()); |
508 | 526 |
509 free(buffer); | 527 free(buffer); |
510 } | 528 } |
511 | 529 |
512 | 530 |
513 static void TestString(const char* cstr) { | 531 static void TestString(const char* cstr) { |
514 StackZone zone(Isolate::Current()); | 532 StackZone zone(Isolate::Current()); |
515 EXPECT(Utf8::IsValid(reinterpret_cast<const uint8_t*>(cstr), strlen(cstr))); | 533 EXPECT(Utf8::IsValid(reinterpret_cast<const uint8_t*>(cstr), strlen(cstr))); |
516 // Write snapshot with object content. | 534 // Write snapshot with object content. |
517 uint8_t* buffer; | 535 uint8_t* buffer; |
518 MessageWriter writer(&buffer, &zone_allocator, true); | 536 MessageWriter writer(&buffer, &zone_allocator, true); |
519 String& str = String::Handle(String::New(cstr)); | 537 String& str = String::Handle(String::New(cstr)); |
520 writer.WriteMessage(str); | 538 writer.WriteMessage(str); |
521 intptr_t buffer_len = writer.BytesWritten(); | 539 intptr_t buffer_len = writer.BytesWritten(); |
522 | 540 |
523 // Read object back from the snapshot. | 541 // Read object back from the snapshot. |
524 SnapshotReader reader(buffer, buffer_len, | 542 MessageSnapshotReader reader(buffer, |
525 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); | 543 buffer_len, |
| 544 Isolate::Current(), |
| 545 zone.GetZone()); |
526 String& serialized_str = String::Handle(); | 546 String& serialized_str = String::Handle(); |
527 serialized_str ^= reader.ReadObject(); | 547 serialized_str ^= reader.ReadObject(); |
528 EXPECT(str.Equals(serialized_str)); | 548 EXPECT(str.Equals(serialized_str)); |
529 | 549 |
530 // Read object back from the snapshot into a C structure. | 550 // Read object back from the snapshot into a C structure. |
531 ApiNativeScope scope; | 551 ApiNativeScope scope; |
532 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 552 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
533 Dart_CObject* root = api_reader.ReadMessage(); | 553 Dart_CObject* root = api_reader.ReadMessage(); |
534 EXPECT_EQ(Dart_CObject_kString, root->type); | 554 EXPECT_EQ(Dart_CObject_kString, root->type); |
535 EXPECT_STREQ(cstr, root->value.as_string); | 555 EXPECT_STREQ(cstr, root->value.as_string); |
(...skipping 26 matching lines...) Expand all Loading... |
562 Array& array = Array::Handle(Array::New(kArrayLength)); | 582 Array& array = Array::Handle(Array::New(kArrayLength)); |
563 Smi& smi = Smi::Handle(); | 583 Smi& smi = Smi::Handle(); |
564 for (int i = 0; i < kArrayLength; i++) { | 584 for (int i = 0; i < kArrayLength; i++) { |
565 smi ^= Smi::New(i); | 585 smi ^= Smi::New(i); |
566 array.SetAt(i, smi); | 586 array.SetAt(i, smi); |
567 } | 587 } |
568 writer.WriteMessage(array); | 588 writer.WriteMessage(array); |
569 intptr_t buffer_len = writer.BytesWritten(); | 589 intptr_t buffer_len = writer.BytesWritten(); |
570 | 590 |
571 // Read object back from the snapshot. | 591 // Read object back from the snapshot. |
572 SnapshotReader reader(buffer, buffer_len, | 592 MessageSnapshotReader reader(buffer, |
573 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); | 593 buffer_len, |
| 594 Isolate::Current(), |
| 595 zone.GetZone()); |
574 Array& serialized_array = Array::Handle(); | 596 Array& serialized_array = Array::Handle(); |
575 serialized_array ^= reader.ReadObject(); | 597 serialized_array ^= reader.ReadObject(); |
576 EXPECT(array.CanonicalizeEquals(serialized_array)); | 598 EXPECT(array.CanonicalizeEquals(serialized_array)); |
577 | 599 |
578 // Read object back from the snapshot into a C structure. | 600 // Read object back from the snapshot into a C structure. |
579 ApiNativeScope scope; | 601 ApiNativeScope scope; |
580 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 602 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
581 Dart_CObject* root = api_reader.ReadMessage(); | 603 Dart_CObject* root = api_reader.ReadMessage(); |
582 EXPECT_EQ(Dart_CObject_kArray, root->type); | 604 EXPECT_EQ(Dart_CObject_kArray, root->type); |
583 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 605 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 | 669 |
648 // Write snapshot with object content. | 670 // Write snapshot with object content. |
649 uint8_t* buffer; | 671 uint8_t* buffer; |
650 MessageWriter writer(&buffer, &zone_allocator, true); | 672 MessageWriter writer(&buffer, &zone_allocator, true); |
651 const int kArrayLength = 0; | 673 const int kArrayLength = 0; |
652 Array& array = Array::Handle(Array::New(kArrayLength)); | 674 Array& array = Array::Handle(Array::New(kArrayLength)); |
653 writer.WriteMessage(array); | 675 writer.WriteMessage(array); |
654 intptr_t buffer_len = writer.BytesWritten(); | 676 intptr_t buffer_len = writer.BytesWritten(); |
655 | 677 |
656 // Read object back from the snapshot. | 678 // Read object back from the snapshot. |
657 SnapshotReader reader(buffer, buffer_len, | 679 MessageSnapshotReader reader(buffer, |
658 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); | 680 buffer_len, |
| 681 Isolate::Current(), |
| 682 zone.GetZone()); |
659 Array& serialized_array = Array::Handle(); | 683 Array& serialized_array = Array::Handle(); |
660 serialized_array ^= reader.ReadObject(); | 684 serialized_array ^= reader.ReadObject(); |
661 EXPECT(array.CanonicalizeEquals(serialized_array)); | 685 EXPECT(array.CanonicalizeEquals(serialized_array)); |
662 | 686 |
663 // Read object back from the snapshot into a C structure. | 687 // Read object back from the snapshot into a C structure. |
664 ApiNativeScope scope; | 688 ApiNativeScope scope; |
665 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 689 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
666 Dart_CObject* root = api_reader.ReadMessage(); | 690 Dart_CObject* root = api_reader.ReadMessage(); |
667 EXPECT_EQ(Dart_CObject_kArray, root->type); | 691 EXPECT_EQ(Dart_CObject_kArray, root->type); |
668 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 692 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
(...skipping 11 matching lines...) Expand all Loading... |
680 const int kTypedDataLength = 256; | 704 const int kTypedDataLength = 256; |
681 TypedData& typed_data = TypedData::Handle( | 705 TypedData& typed_data = TypedData::Handle( |
682 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); | 706 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); |
683 for (int i = 0; i < kTypedDataLength; i++) { | 707 for (int i = 0; i < kTypedDataLength; i++) { |
684 typed_data.SetUint8(i, i); | 708 typed_data.SetUint8(i, i); |
685 } | 709 } |
686 writer.WriteMessage(typed_data); | 710 writer.WriteMessage(typed_data); |
687 intptr_t buffer_len = writer.BytesWritten(); | 711 intptr_t buffer_len = writer.BytesWritten(); |
688 | 712 |
689 // Read object back from the snapshot. | 713 // Read object back from the snapshot. |
690 SnapshotReader reader(buffer, buffer_len, | 714 MessageSnapshotReader reader(buffer, |
691 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); | 715 buffer_len, |
| 716 Isolate::Current(), |
| 717 zone.GetZone()); |
692 TypedData& serialized_typed_data = TypedData::Handle(); | 718 TypedData& serialized_typed_data = TypedData::Handle(); |
693 serialized_typed_data ^= reader.ReadObject(); | 719 serialized_typed_data ^= reader.ReadObject(); |
694 EXPECT(serialized_typed_data.IsTypedData()); | 720 EXPECT(serialized_typed_data.IsTypedData()); |
695 | 721 |
696 // Read object back from the snapshot into a C structure. | 722 // Read object back from the snapshot into a C structure. |
697 ApiNativeScope scope; | 723 ApiNativeScope scope; |
698 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 724 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
699 Dart_CObject* root = api_reader.ReadMessage(); | 725 Dart_CObject* root = api_reader.ReadMessage(); |
700 EXPECT_EQ(Dart_CObject_kTypedData, root->type); | 726 EXPECT_EQ(Dart_CObject_kTypedData, root->type); |
701 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); | 727 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); |
(...skipping 11 matching lines...) Expand all Loading... |
713 MessageWriter writer(&buffer, &zone_allocator, true); \ | 739 MessageWriter writer(&buffer, &zone_allocator, true); \ |
714 const int kArrayLength = 127; \ | 740 const int kArrayLength = 127; \ |
715 TypedData& array = TypedData::Handle( \ | 741 TypedData& array = TypedData::Handle( \ |
716 TypedData::New(kTypedData##darttype##ArrayCid, kArrayLength)); \ | 742 TypedData::New(kTypedData##darttype##ArrayCid, kArrayLength)); \ |
717 intptr_t scale = array.ElementSizeInBytes(); \ | 743 intptr_t scale = array.ElementSizeInBytes(); \ |
718 for (int i = 0; i < kArrayLength; i++) { \ | 744 for (int i = 0; i < kArrayLength; i++) { \ |
719 array.Set##darttype((i * scale), i); \ | 745 array.Set##darttype((i * scale), i); \ |
720 } \ | 746 } \ |
721 writer.WriteMessage(array); \ | 747 writer.WriteMessage(array); \ |
722 intptr_t buffer_len = writer.BytesWritten(); \ | 748 intptr_t buffer_len = writer.BytesWritten(); \ |
723 SnapshotReader reader(buffer, buffer_len, \ | 749 MessageSnapshotReader reader(buffer, buffer_len, \ |
724 Snapshot::kMessage, Isolate::Current(), \ | 750 Isolate::Current(), \ |
725 zone.GetZone()); \ | 751 zone.GetZone()); \ |
726 TypedData& serialized_array = TypedData::Handle(); \ | 752 TypedData& serialized_array = TypedData::Handle(); \ |
727 serialized_array ^= reader.ReadObject(); \ | 753 serialized_array ^= reader.ReadObject(); \ |
728 for (int i = 0; i < kArrayLength; i++) { \ | 754 for (int i = 0; i < kArrayLength; i++) { \ |
729 EXPECT_EQ(static_cast<ctype>(i), \ | 755 EXPECT_EQ(static_cast<ctype>(i), \ |
730 serialized_array.Get##darttype(i*scale)); \ | 756 serialized_array.Get##darttype(i*scale)); \ |
731 } \ | 757 } \ |
732 } | 758 } |
733 | 759 |
734 | 760 |
735 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \ | 761 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \ |
736 { \ | 762 { \ |
737 StackZone zone(Isolate::Current()); \ | 763 StackZone zone(Isolate::Current()); \ |
738 ctype data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; \ | 764 ctype data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; \ |
739 intptr_t length = ARRAY_SIZE(data); \ | 765 intptr_t length = ARRAY_SIZE(data); \ |
740 ExternalTypedData& array = ExternalTypedData::Handle( \ | 766 ExternalTypedData& array = ExternalTypedData::Handle( \ |
741 ExternalTypedData::New(kExternalTypedData##darttype##ArrayCid, \ | 767 ExternalTypedData::New(kExternalTypedData##darttype##ArrayCid, \ |
742 reinterpret_cast<uint8_t*>(data), length)); \ | 768 reinterpret_cast<uint8_t*>(data), length)); \ |
743 intptr_t scale = array.ElementSizeInBytes(); \ | 769 intptr_t scale = array.ElementSizeInBytes(); \ |
744 uint8_t* buffer; \ | 770 uint8_t* buffer; \ |
745 MessageWriter writer(&buffer, &zone_allocator, true); \ | 771 MessageWriter writer(&buffer, &zone_allocator, true); \ |
746 writer.WriteMessage(array); \ | 772 writer.WriteMessage(array); \ |
747 intptr_t buffer_len = writer.BytesWritten(); \ | 773 intptr_t buffer_len = writer.BytesWritten(); \ |
748 SnapshotReader reader(buffer, buffer_len, \ | 774 MessageSnapshotReader reader(buffer, buffer_len, \ |
749 Snapshot::kMessage, Isolate::Current(), \ | 775 Isolate::Current(), \ |
750 zone.GetZone()); \ | 776 zone.GetZone()); \ |
751 TypedData& serialized_array = TypedData::Handle(); \ | 777 TypedData& serialized_array = TypedData::Handle(); \ |
752 serialized_array ^= reader.ReadObject(); \ | 778 serialized_array ^= reader.ReadObject(); \ |
753 for (int i = 0; i < length; i++) { \ | 779 for (int i = 0; i < length; i++) { \ |
754 EXPECT_EQ(static_cast<ctype>(data[i]), \ | 780 EXPECT_EQ(static_cast<ctype>(data[i]), \ |
755 serialized_array.Get##darttype(i*scale)); \ | 781 serialized_array.Get##darttype(i*scale)); \ |
756 } \ | 782 } \ |
757 } | 783 } |
758 | 784 |
759 | 785 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 // Write snapshot with object content. | 817 // Write snapshot with object content. |
792 uint8_t* buffer; | 818 uint8_t* buffer; |
793 MessageWriter writer(&buffer, &zone_allocator, true); | 819 MessageWriter writer(&buffer, &zone_allocator, true); |
794 const int kTypedDataLength = 0; | 820 const int kTypedDataLength = 0; |
795 TypedData& typed_data = TypedData::Handle( | 821 TypedData& typed_data = TypedData::Handle( |
796 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); | 822 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); |
797 writer.WriteMessage(typed_data); | 823 writer.WriteMessage(typed_data); |
798 intptr_t buffer_len = writer.BytesWritten(); | 824 intptr_t buffer_len = writer.BytesWritten(); |
799 | 825 |
800 // Read object back from the snapshot. | 826 // Read object back from the snapshot. |
801 SnapshotReader reader(buffer, buffer_len, | 827 MessageSnapshotReader reader(buffer, |
802 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); | 828 buffer_len, |
| 829 Isolate::Current(), |
| 830 zone.GetZone()); |
803 TypedData& serialized_typed_data = TypedData::Handle(); | 831 TypedData& serialized_typed_data = TypedData::Handle(); |
804 serialized_typed_data ^= reader.ReadObject(); | 832 serialized_typed_data ^= reader.ReadObject(); |
805 EXPECT(serialized_typed_data.IsTypedData()); | 833 EXPECT(serialized_typed_data.IsTypedData()); |
806 | 834 |
807 // Read object back from the snapshot into a C structure. | 835 // Read object back from the snapshot into a C structure. |
808 ApiNativeScope scope; | 836 ApiNativeScope scope; |
809 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 837 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
810 Dart_CObject* root = api_reader.ReadMessage(); | 838 Dart_CObject* root = api_reader.ReadMessage(); |
811 EXPECT_EQ(Dart_CObject_kTypedData, root->type); | 839 EXPECT_EQ(Dart_CObject_kTypedData, root->type); |
812 EXPECT_EQ(Dart_TypedData_kUint8, root->value.as_typed_data.type); | 840 EXPECT_EQ(Dart_TypedData_kUint8, root->value.as_typed_data.type); |
813 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); | 841 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); |
814 EXPECT(root->value.as_typed_data.values == NULL); | 842 EXPECT(root->value.as_typed_data.values == NULL); |
815 CheckEncodeDecodeMessage(root); | 843 CheckEncodeDecodeMessage(root); |
816 } | 844 } |
817 | 845 |
818 | 846 |
819 class TestSnapshotWriter : public SnapshotWriter { | 847 class TestSnapshotWriter : public SnapshotWriter { |
820 public: | 848 public: |
821 static const intptr_t kInitialSize = 64 * KB; | 849 static const intptr_t kInitialSize = 64 * KB; |
822 TestSnapshotWriter(uint8_t** buffer, ReAlloc alloc) | 850 TestSnapshotWriter(uint8_t** buffer, ReAlloc alloc) |
823 : SnapshotWriter(Snapshot::kScript, buffer, alloc, kInitialSize, true) { | 851 : SnapshotWriter(Snapshot::kScript, |
| 852 buffer, |
| 853 alloc, |
| 854 kInitialSize, |
| 855 &forward_list_, |
| 856 true), |
| 857 forward_list_(SnapshotWriter::FirstObjectId()) { |
824 ASSERT(buffer != NULL); | 858 ASSERT(buffer != NULL); |
825 ASSERT(alloc != NULL); | 859 ASSERT(alloc != NULL); |
826 } | 860 } |
827 ~TestSnapshotWriter() { } | 861 ~TestSnapshotWriter() { } |
828 | 862 |
829 // Writes just a script object | 863 // Writes just a script object |
830 void WriteScript(const Script& script) { | 864 void WriteScript(const Script& script) { |
831 WriteObject(script.raw()); | 865 WriteObject(script.raw()); |
832 UnmarkAll(); | 866 UnmarkAll(); |
833 } | 867 } |
834 | 868 |
835 private: | 869 private: |
| 870 ForwardList forward_list_; |
| 871 |
836 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter); | 872 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter); |
837 }; | 873 }; |
838 | 874 |
839 | 875 |
840 static void GenerateSourceAndCheck(const Script& script) { | 876 static void GenerateSourceAndCheck(const Script& script) { |
841 // Check if we are able to generate the source from the token stream. | 877 // Check if we are able to generate the source from the token stream. |
842 // Rescan this source and compare the token stream to see if they are | 878 // Rescan this source and compare the token stream to see if they are |
843 // the same. | 879 // the same. |
844 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); | 880 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); |
845 TokenStream::Iterator expected_iterator( | 881 TokenStream::Iterator expected_iterator( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 Library& lib = Library::Handle(Library::New(lib_url)); | 958 Library& lib = Library::Handle(Library::New(lib_url)); |
923 lib.Register(); | 959 lib.Register(); |
924 EXPECT(CompilerTest::TestCompileScript(lib, script)); | 960 EXPECT(CompilerTest::TestCompileScript(lib, script)); |
925 | 961 |
926 // Write snapshot with script content. | 962 // Write snapshot with script content. |
927 uint8_t* buffer; | 963 uint8_t* buffer; |
928 TestSnapshotWriter writer(&buffer, &malloc_allocator); | 964 TestSnapshotWriter writer(&buffer, &malloc_allocator); |
929 writer.WriteScript(script); | 965 writer.WriteScript(script); |
930 | 966 |
931 // Read object back from the snapshot. | 967 // Read object back from the snapshot. |
932 SnapshotReader reader(buffer, writer.BytesWritten(), | 968 ScriptSnapshotReader reader(buffer, |
933 Snapshot::kScript, Isolate::Current(), | 969 writer.BytesWritten(), |
934 Thread::Current()->zone()); | 970 Isolate::Current(), |
| 971 Thread::Current()->zone()); |
935 Script& serialized_script = Script::Handle(); | 972 Script& serialized_script = Script::Handle(); |
936 serialized_script ^= reader.ReadObject(); | 973 serialized_script ^= reader.ReadObject(); |
937 | 974 |
938 // Check if the serialized script object matches the original script. | 975 // Check if the serialized script object matches the original script. |
939 String& expected_literal = String::Handle(); | 976 String& expected_literal = String::Handle(); |
940 String& actual_literal = String::Handle(); | 977 String& actual_literal = String::Handle(); |
941 String& str = String::Handle(); | 978 String& str = String::Handle(); |
942 str ^= serialized_script.url(); | 979 str ^= serialized_script.url(); |
943 EXPECT(url.Equals(str)); | 980 EXPECT(url.Equals(str)); |
944 | 981 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 "class FieldsTest {\n" | 1059 "class FieldsTest {\n" |
1023 " static Fields testMain() {\n" | 1060 " static Fields testMain() {\n" |
1024 " Expect.equals(true, Fields.bigint_sfld == 0xfffffffffff);\n" | 1061 " Expect.equals(true, Fields.bigint_sfld == 0xfffffffffff);\n" |
1025 " Fields obj = new Fields(10, 20);\n" | 1062 " Fields obj = new Fields(10, 20);\n" |
1026 " Expect.equals(true, obj.bigint_fld == 0xfffffffffff);\n" | 1063 " Expect.equals(true, obj.bigint_fld == 0xfffffffffff);\n" |
1027 " return obj;\n" | 1064 " return obj;\n" |
1028 " }\n" | 1065 " }\n" |
1029 "}\n"; | 1066 "}\n"; |
1030 Dart_Handle result; | 1067 Dart_Handle result; |
1031 | 1068 |
1032 uint8_t* vm_isolate_snapshot_buffer; | |
1033 uint8_t* isolate_snapshot_buffer; | 1069 uint8_t* isolate_snapshot_buffer; |
1034 | 1070 |
1035 // Start an Isolate, load a script and create a full snapshot. | 1071 // Start an Isolate, load a script and create a full snapshot. |
1036 Timer timer1(true, "Snapshot_test"); | 1072 Timer timer1(true, "Snapshot_test"); |
1037 timer1.Start(); | 1073 timer1.Start(); |
1038 { | 1074 { |
1039 TestIsolateScope __test_isolate__; | 1075 TestIsolateScope __test_isolate__; |
1040 | 1076 |
1041 Isolate* isolate = Isolate::Current(); | 1077 Isolate* isolate = Isolate::Current(); |
1042 StackZone zone(isolate); | 1078 StackZone zone(isolate); |
1043 HandleScope scope(isolate); | 1079 HandleScope scope(isolate); |
1044 | 1080 |
1045 // Create a test library and Load up a test script in it. | 1081 // Create a test library and Load up a test script in it. |
1046 TestCase::LoadTestScript(kScriptChars, NULL); | 1082 TestCase::LoadTestScript(kScriptChars, NULL); |
1047 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate)); | 1083 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate)); |
1048 timer1.Stop(); | 1084 timer1.Stop(); |
1049 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); | 1085 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); |
1050 | 1086 |
1051 // Write snapshot with object content. | 1087 // Write snapshot with object content. |
1052 FullSnapshotWriter writer(&vm_isolate_snapshot_buffer, | 1088 FullSnapshotWriter writer(NULL, |
1053 &isolate_snapshot_buffer, | 1089 &isolate_snapshot_buffer, |
1054 &malloc_allocator); | 1090 &malloc_allocator); |
1055 writer.WriteFullSnapshot(); | 1091 writer.WriteFullSnapshot(); |
1056 } | 1092 } |
1057 | 1093 |
1058 // Now Create another isolate using the snapshot and execute a method | 1094 // Now Create another isolate using the snapshot and execute a method |
1059 // from the script. | 1095 // from the script. |
1060 Timer timer2(true, "Snapshot_test"); | 1096 Timer timer2(true, "Snapshot_test"); |
1061 timer2.Start(); | 1097 timer2.Start(); |
1062 TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_buffer); | 1098 TestCase::CreateTestIsolateFromSnapshot(isolate_snapshot_buffer); |
(...skipping 16 matching lines...) Expand all Loading... |
1079 | 1115 |
1080 UNIT_TEST_CASE(FullSnapshot1) { | 1116 UNIT_TEST_CASE(FullSnapshot1) { |
1081 // This buffer has to be static for this to compile with Visual Studio. | 1117 // This buffer has to be static for this to compile with Visual Studio. |
1082 // If it is not static compilation of this file with Visual Studio takes | 1118 // If it is not static compilation of this file with Visual Studio takes |
1083 // more than 30 minutes! | 1119 // more than 30 minutes! |
1084 static const char kFullSnapshotScriptChars[] = { | 1120 static const char kFullSnapshotScriptChars[] = { |
1085 #include "snapshot_test.dat" | 1121 #include "snapshot_test.dat" |
1086 }; | 1122 }; |
1087 const char* kScriptChars = kFullSnapshotScriptChars; | 1123 const char* kScriptChars = kFullSnapshotScriptChars; |
1088 | 1124 |
1089 uint8_t* vm_isolate_snapshot_buffer; | |
1090 uint8_t* isolate_snapshot_buffer; | 1125 uint8_t* isolate_snapshot_buffer; |
1091 | 1126 |
1092 // Start an Isolate, load a script and create a full snapshot. | 1127 // Start an Isolate, load a script and create a full snapshot. |
1093 Timer timer1(true, "Snapshot_test"); | 1128 Timer timer1(true, "Snapshot_test"); |
1094 timer1.Start(); | 1129 timer1.Start(); |
1095 { | 1130 { |
1096 TestIsolateScope __test_isolate__; | 1131 TestIsolateScope __test_isolate__; |
1097 | 1132 |
1098 Isolate* isolate = Isolate::Current(); | 1133 Isolate* isolate = Isolate::Current(); |
1099 StackZone zone(isolate); | 1134 StackZone zone(isolate); |
1100 HandleScope scope(isolate); | 1135 HandleScope scope(isolate); |
1101 | 1136 |
1102 // Create a test library and Load up a test script in it. | 1137 // Create a test library and Load up a test script in it. |
1103 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1138 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
1104 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate)); | 1139 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate)); |
1105 timer1.Stop(); | 1140 timer1.Stop(); |
1106 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); | 1141 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); |
1107 | 1142 |
1108 // Write snapshot with object content. | 1143 // Write snapshot with object content. |
1109 FullSnapshotWriter writer(&vm_isolate_snapshot_buffer, | 1144 FullSnapshotWriter writer(NULL, |
1110 &isolate_snapshot_buffer, | 1145 &isolate_snapshot_buffer, |
1111 &malloc_allocator); | 1146 &malloc_allocator); |
1112 writer.WriteFullSnapshot(); | 1147 writer.WriteFullSnapshot(); |
1113 | 1148 |
1114 // Invoke a function which returns an object. | 1149 // Invoke a function which returns an object. |
1115 Dart_Handle cls = Dart_GetClass(lib, NewString("FieldsTest")); | 1150 Dart_Handle cls = Dart_GetClass(lib, NewString("FieldsTest")); |
1116 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); | 1151 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
1117 EXPECT_VALID(result); | 1152 EXPECT_VALID(result); |
1118 } | 1153 } |
1119 | 1154 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 " if (Fields.fld4 != 10) {" | 1217 " if (Fields.fld4 != 10) {" |
1183 " throw new Exception('Fields.fld4 needs to be 10');" | 1218 " throw new Exception('Fields.fld4 needs to be 10');" |
1184 " }" | 1219 " }" |
1185 " return obj;" | 1220 " return obj;" |
1186 " }" | 1221 " }" |
1187 "}"; | 1222 "}"; |
1188 Dart_Handle result; | 1223 Dart_Handle result; |
1189 | 1224 |
1190 uint8_t* buffer; | 1225 uint8_t* buffer; |
1191 intptr_t size; | 1226 intptr_t size; |
1192 uint8_t* vm_isolate_snapshot = NULL; | |
1193 intptr_t vm_isolate_snapshot_size; | 1227 intptr_t vm_isolate_snapshot_size; |
1194 uint8_t* isolate_snapshot = NULL; | 1228 uint8_t* isolate_snapshot = NULL; |
1195 intptr_t isolate_snapshot_size; | 1229 intptr_t isolate_snapshot_size; |
1196 uint8_t* full_snapshot = NULL; | 1230 uint8_t* full_snapshot = NULL; |
1197 uint8_t* script_snapshot = NULL; | 1231 uint8_t* script_snapshot = NULL; |
1198 intptr_t expected_num_libs; | 1232 intptr_t expected_num_libs; |
1199 intptr_t actual_num_libs; | 1233 intptr_t actual_num_libs; |
1200 | 1234 |
1201 { | 1235 { |
1202 // Start an Isolate, and create a full snapshot of it. | 1236 // Start an Isolate, and create a full snapshot of it. |
1203 TestIsolateScope __test_isolate__; | 1237 TestIsolateScope __test_isolate__; |
1204 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 1238 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
1205 | 1239 |
1206 // Write out the script snapshot. | 1240 // Write out the script snapshot. |
1207 result = Dart_CreateSnapshot(&vm_isolate_snapshot, | 1241 result = Dart_CreateSnapshot(NULL, |
1208 &vm_isolate_snapshot_size, | 1242 &vm_isolate_snapshot_size, |
1209 &isolate_snapshot, | 1243 &isolate_snapshot, |
1210 &isolate_snapshot_size); | 1244 &isolate_snapshot_size); |
1211 EXPECT_VALID(result); | 1245 EXPECT_VALID(result); |
1212 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); | 1246 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); |
1213 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); | 1247 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); |
1214 Dart_ExitScope(); | 1248 Dart_ExitScope(); |
1215 } | 1249 } |
1216 | 1250 |
1217 { | 1251 { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 UNIT_TEST_CASE(ScriptSnapshot1) { | 1315 UNIT_TEST_CASE(ScriptSnapshot1) { |
1282 const char* kScriptChars = | 1316 const char* kScriptChars = |
1283 "class _SimpleNumEnumerable<T extends num> {" | 1317 "class _SimpleNumEnumerable<T extends num> {" |
1284 "final Iterable<T> _source;" | 1318 "final Iterable<T> _source;" |
1285 "const _SimpleNumEnumerable(this._source) : super();" | 1319 "const _SimpleNumEnumerable(this._source) : super();" |
1286 "}"; | 1320 "}"; |
1287 | 1321 |
1288 Dart_Handle result; | 1322 Dart_Handle result; |
1289 uint8_t* buffer; | 1323 uint8_t* buffer; |
1290 intptr_t size; | 1324 intptr_t size; |
1291 uint8_t* vm_isolate_snapshot = NULL; | |
1292 intptr_t vm_isolate_snapshot_size; | 1325 intptr_t vm_isolate_snapshot_size; |
1293 uint8_t* isolate_snapshot = NULL; | 1326 uint8_t* isolate_snapshot = NULL; |
1294 intptr_t isolate_snapshot_size; | 1327 intptr_t isolate_snapshot_size; |
1295 uint8_t* full_snapshot = NULL; | 1328 uint8_t* full_snapshot = NULL; |
1296 uint8_t* script_snapshot = NULL; | 1329 uint8_t* script_snapshot = NULL; |
1297 | 1330 |
1298 { | 1331 { |
1299 // Start an Isolate, and create a full snapshot of it. | 1332 // Start an Isolate, and create a full snapshot of it. |
1300 TestIsolateScope __test_isolate__; | 1333 TestIsolateScope __test_isolate__; |
1301 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 1334 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
1302 | 1335 |
1303 // Write out the script snapshot. | 1336 // Write out the script snapshot. |
1304 result = Dart_CreateSnapshot(&vm_isolate_snapshot, | 1337 result = Dart_CreateSnapshot(NULL, |
1305 &vm_isolate_snapshot_size, | 1338 &vm_isolate_snapshot_size, |
1306 &isolate_snapshot, | 1339 &isolate_snapshot, |
1307 &isolate_snapshot_size); | 1340 &isolate_snapshot_size); |
1308 EXPECT_VALID(result); | 1341 EXPECT_VALID(result); |
1309 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); | 1342 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); |
1310 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); | 1343 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); |
1311 Dart_ExitScope(); | 1344 Dart_ExitScope(); |
1312 } | 1345 } |
1313 | 1346 |
1314 { | 1347 { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 "test_i() {" | 1398 "test_i() {" |
1366 " i;" | 1399 " i;" |
1367 "}" | 1400 "}" |
1368 "test_b() {" | 1401 "test_b() {" |
1369 " b = 0;" | 1402 " b = 0;" |
1370 "}"; | 1403 "}"; |
1371 Dart_Handle result; | 1404 Dart_Handle result; |
1372 | 1405 |
1373 uint8_t* buffer; | 1406 uint8_t* buffer; |
1374 intptr_t size; | 1407 intptr_t size; |
1375 uint8_t* vm_isolate_snapshot = NULL; | |
1376 intptr_t vm_isolate_snapshot_size; | 1408 intptr_t vm_isolate_snapshot_size; |
1377 uint8_t* isolate_snapshot = NULL; | 1409 uint8_t* isolate_snapshot = NULL; |
1378 intptr_t isolate_snapshot_size; | 1410 intptr_t isolate_snapshot_size; |
1379 uint8_t* full_snapshot = NULL; | 1411 uint8_t* full_snapshot = NULL; |
1380 uint8_t* script_snapshot = NULL; | 1412 uint8_t* script_snapshot = NULL; |
1381 | 1413 |
1382 // Force creation of snapshot in production mode. | 1414 // Force creation of snapshot in production mode. |
1383 bool saved_mode = FLAG_enable_type_checks; | 1415 bool saved_mode = FLAG_enable_type_checks; |
1384 FLAG_enable_type_checks = false; | 1416 FLAG_enable_type_checks = false; |
1385 | 1417 |
1386 { | 1418 { |
1387 // Start an Isolate, and create a full snapshot of it. | 1419 // Start an Isolate, and create a full snapshot of it. |
1388 TestIsolateScope __test_isolate__; | 1420 TestIsolateScope __test_isolate__; |
1389 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 1421 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
1390 | 1422 |
1391 // Write out the script snapshot. | 1423 // Write out the script snapshot. |
1392 result = Dart_CreateSnapshot(&vm_isolate_snapshot, | 1424 result = Dart_CreateSnapshot(NULL, |
1393 &vm_isolate_snapshot_size, | 1425 &vm_isolate_snapshot_size, |
1394 &isolate_snapshot, | 1426 &isolate_snapshot, |
1395 &isolate_snapshot_size); | 1427 &isolate_snapshot_size); |
1396 EXPECT_VALID(result); | 1428 EXPECT_VALID(result); |
1397 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); | 1429 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); |
1398 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); | 1430 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); |
1399 Dart_ExitScope(); | 1431 Dart_ExitScope(); |
1400 } | 1432 } |
1401 | 1433 |
1402 { | 1434 { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1465 uint8_t* buffer = NULL; | 1497 uint8_t* buffer = NULL; |
1466 ApiMessageWriter writer(&buffer, &zone_allocator); | 1498 ApiMessageWriter writer(&buffer, &zone_allocator); |
1467 | 1499 |
1468 static const int kArrayLength = 2; | 1500 static const int kArrayLength = 2; |
1469 intptr_t data[kArrayLength] = {1, 2}; | 1501 intptr_t data[kArrayLength] = {1, 2}; |
1470 int len = kArrayLength; | 1502 int len = kArrayLength; |
1471 writer.WriteMessage(len, data); | 1503 writer.WriteMessage(len, data); |
1472 | 1504 |
1473 // Read object back from the snapshot into a C structure. | 1505 // Read object back from the snapshot into a C structure. |
1474 ApiNativeScope scope; | 1506 ApiNativeScope scope; |
1475 ApiMessageReader api_reader(buffer, writer.BytesWritten(), &zone_allocator); | 1507 ApiMessageReader api_reader(buffer, |
| 1508 writer.BytesWritten(), |
| 1509 &zone_allocator, |
| 1510 false); |
1476 Dart_CObject* root = api_reader.ReadMessage(); | 1511 Dart_CObject* root = api_reader.ReadMessage(); |
1477 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1512 EXPECT_EQ(Dart_CObject_kArray, root->type); |
1478 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1513 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1479 for (int i = 0; i < kArrayLength; i++) { | 1514 for (int i = 0; i < kArrayLength; i++) { |
1480 Dart_CObject* element = root->value.as_array.values[i]; | 1515 Dart_CObject* element = root->value.as_array.values[i]; |
1481 EXPECT_EQ(Dart_CObject_kInt32, element->type); | 1516 EXPECT_EQ(Dart_CObject_kInt32, element->type); |
1482 EXPECT_EQ(i + 1, element->value.as_int32); | 1517 EXPECT_EQ(i + 1, element->value.as_int32); |
1483 } | 1518 } |
1484 CheckEncodeDecodeMessage(root); | 1519 CheckEncodeDecodeMessage(root); |
1485 } | 1520 } |
(...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2758 StackZone zone(Isolate::Current()); | 2793 StackZone zone(Isolate::Current()); |
2759 uint8_t* buffer; | 2794 uint8_t* buffer; |
2760 MessageWriter writer(&buffer, &zone_allocator, true); | 2795 MessageWriter writer(&buffer, &zone_allocator, true); |
2761 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 2796 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
2762 // For performance, we'd like single-byte headers when ids are omitted. | 2797 // For performance, we'd like single-byte headers when ids are omitted. |
2763 // If this starts failing, consider renumbering the snapshot ids. | 2798 // If this starts failing, consider renumbering the snapshot ids. |
2764 EXPECT_EQ(1, writer.BytesWritten()); | 2799 EXPECT_EQ(1, writer.BytesWritten()); |
2765 } | 2800 } |
2766 | 2801 |
2767 } // namespace dart | 2802 } // namespace dart |
OLD | NEW |