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

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

Issue 1310463005: - Ensure that HandleScope is initialized with a thread. (Remove (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
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 "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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 145
146 static void ExpectEncodeFail(Dart_CObject* root) { 146 static void ExpectEncodeFail(Dart_CObject* root) {
147 uint8_t* buffer = NULL; 147 uint8_t* buffer = NULL;
148 ApiMessageWriter writer(&buffer, &malloc_allocator); 148 ApiMessageWriter writer(&buffer, &malloc_allocator);
149 const bool result = writer.WriteCMessage(root); 149 const bool result = writer.WriteCMessage(root);
150 EXPECT_EQ(false, result); 150 EXPECT_EQ(false, result);
151 } 151 }
152 152
153 153
154 TEST_CASE(SerializeNull) { 154 TEST_CASE(SerializeNull) {
155 StackZone zone(Thread::Current()); 155 StackZone zone(thread);
156 156
157 // Write snapshot with object content. 157 // Write snapshot with object content.
158 const Object& null_object = Object::Handle(); 158 const Object& null_object = Object::Handle();
159 uint8_t* buffer; 159 uint8_t* buffer;
160 MessageWriter writer(&buffer, &zone_allocator, true); 160 MessageWriter writer(&buffer, &zone_allocator, true);
161 writer.WriteMessage(null_object); 161 writer.WriteMessage(null_object);
162 intptr_t buffer_len = writer.BytesWritten(); 162 intptr_t buffer_len = writer.BytesWritten();
163 163
164 // Read object back from the snapshot. 164 // Read object back from the snapshot.
165 MessageSnapshotReader reader(buffer, 165 MessageSnapshotReader reader(buffer, buffer_len, thread);
166 buffer_len,
167 Isolate::Current(),
168 zone.GetZone());
169 const Object& serialized_object = Object::Handle(reader.ReadObject()); 166 const Object& serialized_object = Object::Handle(reader.ReadObject());
170 EXPECT(Equals(null_object, serialized_object)); 167 EXPECT(Equals(null_object, serialized_object));
171 168
172 // Read object back from the snapshot into a C structure. 169 // Read object back from the snapshot into a C structure.
173 ApiNativeScope scope; 170 ApiNativeScope scope;
174 ApiMessageReader api_reader(buffer, buffer_len); 171 ApiMessageReader api_reader(buffer, buffer_len);
175 Dart_CObject* root = api_reader.ReadMessage(); 172 Dart_CObject* root = api_reader.ReadMessage();
176 EXPECT_NOTNULL(root); 173 EXPECT_NOTNULL(root);
177 EXPECT_EQ(Dart_CObject_kNull, root->type); 174 EXPECT_EQ(Dart_CObject_kNull, root->type);
178 CheckEncodeDecodeMessage(root); 175 CheckEncodeDecodeMessage(root);
179 } 176 }
180 177
181 178
182 TEST_CASE(SerializeSmi1) { 179 TEST_CASE(SerializeSmi1) {
183 StackZone zone(Thread::Current()); 180 StackZone zone(thread);
184 181
185 // Write snapshot with object content. 182 // Write snapshot with object content.
186 const Smi& smi = Smi::Handle(Smi::New(124)); 183 const Smi& smi = Smi::Handle(Smi::New(124));
187 uint8_t* buffer; 184 uint8_t* buffer;
188 MessageWriter writer(&buffer, &zone_allocator, true); 185 MessageWriter writer(&buffer, &zone_allocator, true);
189 writer.WriteMessage(smi); 186 writer.WriteMessage(smi);
190 intptr_t buffer_len = writer.BytesWritten(); 187 intptr_t buffer_len = writer.BytesWritten();
191 188
192 // Read object back from the snapshot. 189 // Read object back from the snapshot.
193 MessageSnapshotReader reader(buffer, 190 MessageSnapshotReader reader(buffer, buffer_len, thread);
194 buffer_len,
195 Isolate::Current(),
196 zone.GetZone());
197 const Object& serialized_object = Object::Handle(reader.ReadObject()); 191 const Object& serialized_object = Object::Handle(reader.ReadObject());
198 EXPECT(Equals(smi, serialized_object)); 192 EXPECT(Equals(smi, serialized_object));
199 193
200 // Read object back from the snapshot into a C structure. 194 // Read object back from the snapshot into a C structure.
201 ApiNativeScope scope; 195 ApiNativeScope scope;
202 ApiMessageReader api_reader(buffer, buffer_len); 196 ApiMessageReader api_reader(buffer, buffer_len);
203 Dart_CObject* root = api_reader.ReadMessage(); 197 Dart_CObject* root = api_reader.ReadMessage();
204 EXPECT_NOTNULL(root); 198 EXPECT_NOTNULL(root);
205 EXPECT_EQ(Dart_CObject_kInt32, root->type); 199 EXPECT_EQ(Dart_CObject_kInt32, root->type);
206 EXPECT_EQ(smi.Value(), root->value.as_int32); 200 EXPECT_EQ(smi.Value(), root->value.as_int32);
207 CheckEncodeDecodeMessage(root); 201 CheckEncodeDecodeMessage(root);
208 } 202 }
209 203
210 204
211 TEST_CASE(SerializeSmi2) { 205 TEST_CASE(SerializeSmi2) {
212 StackZone zone(Thread::Current()); 206 StackZone zone(thread);
213 207
214 // Write snapshot with object content. 208 // Write snapshot with object content.
215 const Smi& smi = Smi::Handle(Smi::New(-1)); 209 const Smi& smi = Smi::Handle(Smi::New(-1));
216 uint8_t* buffer; 210 uint8_t* buffer;
217 MessageWriter writer(&buffer, &zone_allocator, true); 211 MessageWriter writer(&buffer, &zone_allocator, true);
218 writer.WriteMessage(smi); 212 writer.WriteMessage(smi);
219 intptr_t buffer_len = writer.BytesWritten(); 213 intptr_t buffer_len = writer.BytesWritten();
220 214
221 // Read object back from the snapshot. 215 // Read object back from the snapshot.
222 MessageSnapshotReader reader(buffer, 216 MessageSnapshotReader reader(buffer, buffer_len, thread);
223 buffer_len,
224 Isolate::Current(),
225 zone.GetZone());
226 const Object& serialized_object = Object::Handle(reader.ReadObject()); 217 const Object& serialized_object = Object::Handle(reader.ReadObject());
227 EXPECT(Equals(smi, serialized_object)); 218 EXPECT(Equals(smi, serialized_object));
228 219
229 // Read object back from the snapshot into a C structure. 220 // Read object back from the snapshot into a C structure.
230 ApiNativeScope scope; 221 ApiNativeScope scope;
231 ApiMessageReader api_reader(buffer, buffer_len); 222 ApiMessageReader api_reader(buffer, buffer_len);
232 Dart_CObject* root = api_reader.ReadMessage(); 223 Dart_CObject* root = api_reader.ReadMessage();
233 EXPECT_NOTNULL(root); 224 EXPECT_NOTNULL(root);
234 EXPECT_EQ(Dart_CObject_kInt32, root->type); 225 EXPECT_EQ(Dart_CObject_kInt32, root->type);
235 EXPECT_EQ(smi.Value(), root->value.as_int32); 226 EXPECT_EQ(smi.Value(), root->value.as_int32);
236 CheckEncodeDecodeMessage(root); 227 CheckEncodeDecodeMessage(root);
237 } 228 }
238 229
239 230
240 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) { 231 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) {
241 // Write snapshot with object content. 232 // Write snapshot with object content.
242 uint8_t* buffer; 233 uint8_t* buffer;
243 MessageWriter writer(&buffer, &zone_allocator, true); 234 MessageWriter writer(&buffer, &zone_allocator, true);
244 writer.WriteMessage(mint); 235 writer.WriteMessage(mint);
245 intptr_t buffer_len = writer.BytesWritten(); 236 intptr_t buffer_len = writer.BytesWritten();
246 237
247 { 238 {
248 // Switch to a regular zone, where VM handle allocation is allowed. 239 // Switch to a regular zone, where VM handle allocation is allowed.
249 StackZone zone(Thread::Current()); 240 Thread* thread = Thread::Current();
241 StackZone zone(thread);
250 // Read object back from the snapshot. 242 // Read object back from the snapshot.
251 MessageSnapshotReader reader(buffer, 243 MessageSnapshotReader reader(buffer, buffer_len, thread);
252 buffer_len,
253 Isolate::Current(),
254 Thread::Current()->zone());
255 const Object& serialized_object = Object::Handle(reader.ReadObject()); 244 const Object& serialized_object = Object::Handle(reader.ReadObject());
256 EXPECT(serialized_object.IsMint()); 245 EXPECT(serialized_object.IsMint());
257 } 246 }
258 247
259 // Read object back from the snapshot into a C structure. 248 // Read object back from the snapshot into a C structure.
260 ApiMessageReader api_reader(buffer, buffer_len); 249 ApiMessageReader api_reader(buffer, buffer_len);
261 Dart_CObject* root = api_reader.ReadMessage(); 250 Dart_CObject* root = api_reader.ReadMessage();
262 EXPECT_NOTNULL(root); 251 EXPECT_NOTNULL(root);
263 CheckEncodeDecodeMessage(root); 252 CheckEncodeDecodeMessage(root);
264 return root; 253 return root;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // Max positive mint - 1. 294 // Max positive mint - 1.
306 CheckMint(kMaxInt64 - 1); 295 CheckMint(kMaxInt64 - 1);
307 // Min negative mint. 296 // Min negative mint.
308 CheckMint(kMinInt64); 297 CheckMint(kMinInt64);
309 // Min negative mint + 1. 298 // Min negative mint + 1.
310 CheckMint(kMinInt64 + 1); 299 CheckMint(kMinInt64 + 1);
311 } 300 }
312 301
313 302
314 TEST_CASE(SerializeDouble) { 303 TEST_CASE(SerializeDouble) {
315 StackZone zone(Thread::Current()); 304 StackZone zone(thread);
316 305
317 // Write snapshot with object content. 306 // Write snapshot with object content.
318 const Double& dbl = Double::Handle(Double::New(101.29)); 307 const Double& dbl = Double::Handle(Double::New(101.29));
319 uint8_t* buffer; 308 uint8_t* buffer;
320 MessageWriter writer(&buffer, &zone_allocator, true); 309 MessageWriter writer(&buffer, &zone_allocator, true);
321 writer.WriteMessage(dbl); 310 writer.WriteMessage(dbl);
322 intptr_t buffer_len = writer.BytesWritten(); 311 intptr_t buffer_len = writer.BytesWritten();
323 312
324 // Read object back from the snapshot. 313 // Read object back from the snapshot.
325 MessageSnapshotReader reader(buffer, 314 MessageSnapshotReader reader(buffer, buffer_len, thread);
326 buffer_len,
327 Isolate::Current(),
328 zone.GetZone());
329 const Object& serialized_object = Object::Handle(reader.ReadObject()); 315 const Object& serialized_object = Object::Handle(reader.ReadObject());
330 EXPECT(Equals(dbl, serialized_object)); 316 EXPECT(Equals(dbl, serialized_object));
331 317
332 // Read object back from the snapshot into a C structure. 318 // Read object back from the snapshot into a C structure.
333 ApiNativeScope scope; 319 ApiNativeScope scope;
334 ApiMessageReader api_reader(buffer, buffer_len); 320 ApiMessageReader api_reader(buffer, buffer_len);
335 Dart_CObject* root = api_reader.ReadMessage(); 321 Dart_CObject* root = api_reader.ReadMessage();
336 EXPECT_NOTNULL(root); 322 EXPECT_NOTNULL(root);
337 EXPECT_EQ(Dart_CObject_kDouble, root->type); 323 EXPECT_EQ(Dart_CObject_kDouble, root->type);
338 EXPECT_EQ(dbl.value(), root->value.as_double); 324 EXPECT_EQ(dbl.value(), root->value.as_double);
339 CheckEncodeDecodeMessage(root); 325 CheckEncodeDecodeMessage(root);
340 } 326 }
341 327
342 328
343 TEST_CASE(SerializeTrue) { 329 TEST_CASE(SerializeTrue) {
344 StackZone zone(Thread::Current()); 330 StackZone zone(thread);
345 331
346 // Write snapshot with true object. 332 // Write snapshot with true object.
347 const Bool& bl = Bool::True(); 333 const Bool& bl = Bool::True();
348 uint8_t* buffer; 334 uint8_t* buffer;
349 MessageWriter writer(&buffer, &zone_allocator, true); 335 MessageWriter writer(&buffer, &zone_allocator, true);
350 writer.WriteMessage(bl); 336 writer.WriteMessage(bl);
351 intptr_t buffer_len = writer.BytesWritten(); 337 intptr_t buffer_len = writer.BytesWritten();
352 338
353 // Read object back from the snapshot. 339 // Read object back from the snapshot.
354 MessageSnapshotReader reader(buffer, 340 MessageSnapshotReader reader(buffer, buffer_len, thread);
355 buffer_len,
356 Isolate::Current(),
357 zone.GetZone());
358 const Object& serialized_object = Object::Handle(reader.ReadObject()); 341 const Object& serialized_object = Object::Handle(reader.ReadObject());
359 fprintf(stderr, "%s / %s\n", bl.ToCString(), serialized_object.ToCString()); 342 fprintf(stderr, "%s / %s\n", bl.ToCString(), serialized_object.ToCString());
360 343
361 EXPECT(Equals(bl, serialized_object)); 344 EXPECT(Equals(bl, serialized_object));
362 345
363 // Read object back from the snapshot into a C structure. 346 // Read object back from the snapshot into a C structure.
364 ApiNativeScope scope; 347 ApiNativeScope scope;
365 ApiMessageReader api_reader(buffer, buffer_len); 348 ApiMessageReader api_reader(buffer, buffer_len);
366 Dart_CObject* root = api_reader.ReadMessage(); 349 Dart_CObject* root = api_reader.ReadMessage();
367 EXPECT_NOTNULL(root); 350 EXPECT_NOTNULL(root);
368 EXPECT_EQ(Dart_CObject_kBool, root->type); 351 EXPECT_EQ(Dart_CObject_kBool, root->type);
369 EXPECT_EQ(true, root->value.as_bool); 352 EXPECT_EQ(true, root->value.as_bool);
370 CheckEncodeDecodeMessage(root); 353 CheckEncodeDecodeMessage(root);
371 } 354 }
372 355
373 356
374 TEST_CASE(SerializeFalse) { 357 TEST_CASE(SerializeFalse) {
375 StackZone zone(Thread::Current()); 358 StackZone zone(thread);
376 359
377 // Write snapshot with false object. 360 // Write snapshot with false object.
378 const Bool& bl = Bool::False(); 361 const Bool& bl = Bool::False();
379 uint8_t* buffer; 362 uint8_t* buffer;
380 MessageWriter writer(&buffer, &zone_allocator, true); 363 MessageWriter writer(&buffer, &zone_allocator, true);
381 writer.WriteMessage(bl); 364 writer.WriteMessage(bl);
382 intptr_t buffer_len = writer.BytesWritten(); 365 intptr_t buffer_len = writer.BytesWritten();
383 366
384 // Read object back from the snapshot. 367 // Read object back from the snapshot.
385 MessageSnapshotReader reader(buffer, 368 MessageSnapshotReader reader(buffer, buffer_len, thread);
386 buffer_len,
387 Isolate::Current(),
388 zone.GetZone());
389 const Object& serialized_object = Object::Handle(reader.ReadObject()); 369 const Object& serialized_object = Object::Handle(reader.ReadObject());
390 EXPECT(Equals(bl, serialized_object)); 370 EXPECT(Equals(bl, serialized_object));
391 371
392 // Read object back from the snapshot into a C structure. 372 // Read object back from the snapshot into a C structure.
393 ApiNativeScope scope; 373 ApiNativeScope scope;
394 ApiMessageReader api_reader(buffer, buffer_len); 374 ApiMessageReader api_reader(buffer, buffer_len);
395 Dart_CObject* root = api_reader.ReadMessage(); 375 Dart_CObject* root = api_reader.ReadMessage();
396 EXPECT_NOTNULL(root); 376 EXPECT_NOTNULL(root);
397 EXPECT_EQ(Dart_CObject_kBool, root->type); 377 EXPECT_EQ(Dart_CObject_kBool, root->type);
398 EXPECT_EQ(false, root->value.as_bool); 378 EXPECT_EQ(false, root->value.as_bool);
399 CheckEncodeDecodeMessage(root); 379 CheckEncodeDecodeMessage(root);
400 } 380 }
401 381
402 382
403 static uword allocator(intptr_t size) { 383 static uword allocator(intptr_t size) {
404 return reinterpret_cast<uword>(malloc(size)); 384 return reinterpret_cast<uword>(malloc(size));
405 } 385 }
406 386
407 387
408 TEST_CASE(SerializeCapability) { 388 TEST_CASE(SerializeCapability) {
409 StackZone zone(Thread::Current());
410
411 // Write snapshot with object content. 389 // Write snapshot with object content.
412 const Capability& capability = Capability::Handle(Capability::New(12345)); 390 const Capability& capability = Capability::Handle(Capability::New(12345));
413 uint8_t* buffer; 391 uint8_t* buffer;
414 MessageWriter writer(&buffer, &zone_allocator, true); 392 MessageWriter writer(&buffer, &zone_allocator, true);
415 writer.WriteMessage(capability); 393 writer.WriteMessage(capability);
416 intptr_t buffer_len = writer.BytesWritten(); 394 intptr_t buffer_len = writer.BytesWritten();
417 395
418 // Read object back from the snapshot. 396 // Read object back from the snapshot.
419 MessageSnapshotReader reader(buffer, 397 MessageSnapshotReader reader(buffer, buffer_len, thread);
420 buffer_len,
421 Isolate::Current(),
422 zone.GetZone());
423 Capability& obj = Capability::Handle(); 398 Capability& obj = Capability::Handle();
424 obj ^= reader.ReadObject(); 399 obj ^= reader.ReadObject();
425 400
426 EXPECT_STREQ(12345, obj.Id()); 401 EXPECT_STREQ(12345, obj.Id());
427 402
428 // Read object back from the snapshot into a C structure. 403 // Read object back from the snapshot into a C structure.
429 ApiNativeScope scope; 404 ApiNativeScope scope;
430 ApiMessageReader api_reader(buffer, buffer_len); 405 ApiMessageReader api_reader(buffer, buffer_len);
431 Dart_CObject* root = api_reader.ReadMessage(); 406 Dart_CObject* root = api_reader.ReadMessage();
432 EXPECT_NOTNULL(root); 407 EXPECT_NOTNULL(root);
433 EXPECT_EQ(Dart_CObject_kCapability, root->type); 408 EXPECT_EQ(Dart_CObject_kCapability, root->type);
434 int64_t id = root->value.as_capability.id; 409 int64_t id = root->value.as_capability.id;
435 EXPECT_EQ(12345, id); 410 EXPECT_EQ(12345, id);
436 CheckEncodeDecodeMessage(root); 411 CheckEncodeDecodeMessage(root);
437 } 412 }
438 413
439 414
440 TEST_CASE(SerializeBigint) { 415 TEST_CASE(SerializeBigint) {
441 StackZone zone(Thread::Current());
442
443 // Write snapshot with object content. 416 // Write snapshot with object content.
444 const char* cstr = "0x270FFFFFFFFFFFFFD8F0"; 417 const char* cstr = "0x270FFFFFFFFFFFFFD8F0";
445 const String& str = String::Handle(String::New(cstr)); 418 const String& str = String::Handle(String::New(cstr));
446 Bigint& bigint = Bigint::Handle(); 419 Bigint& bigint = Bigint::Handle();
447 bigint ^= Integer::NewCanonical(str); 420 bigint ^= Integer::NewCanonical(str);
448 uint8_t* buffer; 421 uint8_t* buffer;
449 MessageWriter writer(&buffer, &zone_allocator, true); 422 MessageWriter writer(&buffer, &zone_allocator, true);
450 writer.WriteMessage(bigint); 423 writer.WriteMessage(bigint);
451 intptr_t buffer_len = writer.BytesWritten(); 424 intptr_t buffer_len = writer.BytesWritten();
452 425
453 // Read object back from the snapshot. 426 // Read object back from the snapshot.
454 MessageSnapshotReader reader(buffer, 427 MessageSnapshotReader reader(buffer, buffer_len, thread);
455 buffer_len,
456 Isolate::Current(),
457 zone.GetZone());
458 Bigint& obj = Bigint::Handle(); 428 Bigint& obj = Bigint::Handle();
459 obj ^= reader.ReadObject(); 429 obj ^= reader.ReadObject();
460 430
461 EXPECT_STREQ(bigint.ToHexCString(allocator), obj.ToHexCString(allocator)); 431 EXPECT_STREQ(bigint.ToHexCString(allocator), obj.ToHexCString(allocator));
462 432
463 // Read object back from the snapshot into a C structure. 433 // Read object back from the snapshot into a C structure.
464 ApiNativeScope scope; 434 ApiNativeScope scope;
465 ApiMessageReader api_reader(buffer, buffer_len); 435 ApiMessageReader api_reader(buffer, buffer_len);
466 Dart_CObject* root = api_reader.ReadMessage(); 436 Dart_CObject* root = api_reader.ReadMessage();
467 EXPECT_NOTNULL(root); 437 EXPECT_NOTNULL(root);
468 EXPECT_EQ(Dart_CObject_kBigint, root->type); 438 EXPECT_EQ(Dart_CObject_kBigint, root->type);
469 char* hex_value = TestCase::BigintToHexValue(root); 439 char* hex_value = TestCase::BigintToHexValue(root);
470 EXPECT_STREQ(cstr, hex_value); 440 EXPECT_STREQ(cstr, hex_value);
471 free(hex_value); 441 free(hex_value);
472 CheckEncodeDecodeMessage(root); 442 CheckEncodeDecodeMessage(root);
473 } 443 }
474 444
475 445
476 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { 446 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) {
477 // Write snapshot with object content. 447 // Write snapshot with object content.
478 uint8_t* buffer; 448 uint8_t* buffer;
479 MessageWriter writer(&buffer, &zone_allocator, true); 449 MessageWriter writer(&buffer, &zone_allocator, true);
480 writer.WriteMessage(bigint); 450 writer.WriteMessage(bigint);
481 intptr_t buffer_len = writer.BytesWritten(); 451 intptr_t buffer_len = writer.BytesWritten();
482 452
483 { 453 {
484 // Switch to a regular zone, where VM handle allocation is allowed. 454 // Switch to a regular zone, where VM handle allocation is allowed.
485 StackZone zone(Thread::Current()); 455 Thread* thread = Thread::Current();
456 StackZone zone(thread);
486 // Read object back from the snapshot. 457 // Read object back from the snapshot.
487 MessageSnapshotReader reader(buffer, 458 MessageSnapshotReader reader(buffer, buffer_len, thread);
488 buffer_len,
489 Isolate::Current(),
490 Thread::Current()->zone());
491 Bigint& serialized_bigint = Bigint::Handle(); 459 Bigint& serialized_bigint = Bigint::Handle();
492 serialized_bigint ^= reader.ReadObject(); 460 serialized_bigint ^= reader.ReadObject();
493 const char* str1 = bigint.ToHexCString(allocator); 461 const char* str1 = bigint.ToHexCString(allocator);
494 const char* str2 = serialized_bigint.ToHexCString(allocator); 462 const char* str2 = serialized_bigint.ToHexCString(allocator);
495 EXPECT_STREQ(str1, str2); 463 EXPECT_STREQ(str1, str2);
496 free(const_cast<char*>(str1)); 464 free(const_cast<char*>(str1));
497 free(const_cast<char*>(str2)); 465 free(const_cast<char*>(str2));
498 } 466 }
499 467
500 // Read object back from the snapshot into a C structure. 468 // Read object back from the snapshot into a C structure.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 writer.WriteObject(Object::library_class()); 511 writer.WriteObject(Object::library_class());
544 writer.WriteObject(Object::code_class()); 512 writer.WriteObject(Object::code_class());
545 writer.WriteObject(Object::instructions_class()); 513 writer.WriteObject(Object::instructions_class());
546 writer.WriteObject(Object::pc_descriptors_class()); 514 writer.WriteObject(Object::pc_descriptors_class());
547 writer.WriteObject(Object::exception_handlers_class()); 515 writer.WriteObject(Object::exception_handlers_class());
548 writer.WriteObject(Object::context_class()); 516 writer.WriteObject(Object::context_class());
549 writer.WriteObject(Object::context_scope_class()); 517 writer.WriteObject(Object::context_scope_class());
550 intptr_t buffer_len = writer.BytesWritten(); 518 intptr_t buffer_len = writer.BytesWritten();
551 519
552 // Read object back from the snapshot. 520 // Read object back from the snapshot.
553 MessageSnapshotReader reader(buffer, 521 MessageSnapshotReader reader(buffer, buffer_len, thread);
554 buffer_len,
555 Isolate::Current(),
556 Thread::Current()->zone());
557 EXPECT(Object::class_class() == reader.ReadObject()); 522 EXPECT(Object::class_class() == reader.ReadObject());
558 EXPECT(Object::type_arguments_class() == reader.ReadObject()); 523 EXPECT(Object::type_arguments_class() == reader.ReadObject());
559 EXPECT(Object::function_class() == reader.ReadObject()); 524 EXPECT(Object::function_class() == reader.ReadObject());
560 EXPECT(Object::field_class() == reader.ReadObject()); 525 EXPECT(Object::field_class() == reader.ReadObject());
561 EXPECT(Object::token_stream_class() == reader.ReadObject()); 526 EXPECT(Object::token_stream_class() == reader.ReadObject());
562 EXPECT(Object::script_class() == reader.ReadObject()); 527 EXPECT(Object::script_class() == reader.ReadObject());
563 EXPECT(Object::library_class() == reader.ReadObject()); 528 EXPECT(Object::library_class() == reader.ReadObject());
564 EXPECT(Object::code_class() == reader.ReadObject()); 529 EXPECT(Object::code_class() == reader.ReadObject());
565 EXPECT(Object::instructions_class() == reader.ReadObject()); 530 EXPECT(Object::instructions_class() == reader.ReadObject());
566 EXPECT(Object::pc_descriptors_class() == reader.ReadObject()); 531 EXPECT(Object::pc_descriptors_class() == reader.ReadObject());
567 EXPECT(Object::exception_handlers_class() == reader.ReadObject()); 532 EXPECT(Object::exception_handlers_class() == reader.ReadObject());
568 EXPECT(Object::context_class() == reader.ReadObject()); 533 EXPECT(Object::context_class() == reader.ReadObject());
569 EXPECT(Object::context_scope_class() == reader.ReadObject()); 534 EXPECT(Object::context_scope_class() == reader.ReadObject());
570 535
571 free(buffer); 536 free(buffer);
572 } 537 }
573 538
574 539
575 static void TestString(const char* cstr) { 540 static void TestString(const char* cstr) {
576 StackZone zone(Thread::Current()); 541 Thread* thread = Thread::Current();
577 EXPECT(Utf8::IsValid(reinterpret_cast<const uint8_t*>(cstr), strlen(cstr))); 542 EXPECT(Utf8::IsValid(reinterpret_cast<const uint8_t*>(cstr), strlen(cstr)));
578 // Write snapshot with object content. 543 // Write snapshot with object content.
579 String& str = String::Handle(String::New(cstr)); 544 String& str = String::Handle(String::New(cstr));
580 uint8_t* buffer; 545 uint8_t* buffer;
581 MessageWriter writer(&buffer, &zone_allocator, true); 546 MessageWriter writer(&buffer, &zone_allocator, true);
582 writer.WriteMessage(str); 547 writer.WriteMessage(str);
583 intptr_t buffer_len = writer.BytesWritten(); 548 intptr_t buffer_len = writer.BytesWritten();
584 549
585 // Read object back from the snapshot. 550 // Read object back from the snapshot.
586 MessageSnapshotReader reader(buffer, 551 MessageSnapshotReader reader(buffer, buffer_len, thread);
587 buffer_len,
588 Isolate::Current(),
589 zone.GetZone());
590 String& serialized_str = String::Handle(); 552 String& serialized_str = String::Handle();
591 serialized_str ^= reader.ReadObject(); 553 serialized_str ^= reader.ReadObject();
592 EXPECT(str.Equals(serialized_str)); 554 EXPECT(str.Equals(serialized_str));
593 555
594 // Read object back from the snapshot into a C structure. 556 // Read object back from the snapshot into a C structure.
595 ApiNativeScope scope; 557 ApiNativeScope scope;
596 ApiMessageReader api_reader(buffer, buffer_len); 558 ApiMessageReader api_reader(buffer, buffer_len);
597 Dart_CObject* root = api_reader.ReadMessage(); 559 Dart_CObject* root = api_reader.ReadMessage();
598 EXPECT_EQ(Dart_CObject_kString, root->type); 560 EXPECT_EQ(Dart_CObject_kString, root->type);
599 EXPECT_STREQ(cstr, root->value.as_string); 561 EXPECT_STREQ(cstr, root->value.as_string);
(...skipping 10 matching lines...) Expand all
610 "\xDF\xBF" // U+07FF 572 "\xDF\xBF" // U+07FF
611 "\xE0\xA0\x80" // U+0800 573 "\xE0\xA0\x80" // U+0800
612 "\xEF\xBF\xBF"; // U+FFFF 574 "\xEF\xBF\xBF"; // U+FFFF
613 575
614 TestString(data); 576 TestString(data);
615 // TODO(sgjesse): Add tests with non-BMP characters. 577 // TODO(sgjesse): Add tests with non-BMP characters.
616 } 578 }
617 579
618 580
619 TEST_CASE(SerializeArray) { 581 TEST_CASE(SerializeArray) {
620 StackZone zone(Thread::Current());
621
622 // Write snapshot with object content. 582 // Write snapshot with object content.
623 const int kArrayLength = 10; 583 const int kArrayLength = 10;
624 Array& array = Array::Handle(Array::New(kArrayLength)); 584 Array& array = Array::Handle(Array::New(kArrayLength));
625 Smi& smi = Smi::Handle(); 585 Smi& smi = Smi::Handle();
626 for (int i = 0; i < kArrayLength; i++) { 586 for (int i = 0; i < kArrayLength; i++) {
627 smi ^= Smi::New(i); 587 smi ^= Smi::New(i);
628 array.SetAt(i, smi); 588 array.SetAt(i, smi);
629 } 589 }
630 uint8_t* buffer; 590 uint8_t* buffer;
631 MessageWriter writer(&buffer, &zone_allocator, true); 591 MessageWriter writer(&buffer, &zone_allocator, true);
632 writer.WriteMessage(array); 592 writer.WriteMessage(array);
633 intptr_t buffer_len = writer.BytesWritten(); 593 intptr_t buffer_len = writer.BytesWritten();
634 594
635 // Read object back from the snapshot. 595 // Read object back from the snapshot.
636 MessageSnapshotReader reader(buffer, 596 MessageSnapshotReader reader(buffer, buffer_len, thread);
637 buffer_len,
638 Isolate::Current(),
639 zone.GetZone());
640 Array& serialized_array = Array::Handle(); 597 Array& serialized_array = Array::Handle();
641 serialized_array ^= reader.ReadObject(); 598 serialized_array ^= reader.ReadObject();
642 EXPECT(array.CanonicalizeEquals(serialized_array)); 599 EXPECT(array.CanonicalizeEquals(serialized_array));
643 600
644 // Read object back from the snapshot into a C structure. 601 // Read object back from the snapshot into a C structure.
645 ApiNativeScope scope; 602 ApiNativeScope scope;
646 ApiMessageReader api_reader(buffer, buffer_len); 603 ApiMessageReader api_reader(buffer, buffer_len);
647 Dart_CObject* root = api_reader.ReadMessage(); 604 Dart_CObject* root = api_reader.ReadMessage();
648 EXPECT_EQ(Dart_CObject_kArray, root->type); 605 EXPECT_EQ(Dart_CObject_kArray, root->type);
649 EXPECT_EQ(kArrayLength, root->value.as_array.length); 606 EXPECT_EQ(kArrayLength, root->value.as_array.length);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 TEST_CASE(FailSerializeLargeExternalTypedData) { 659 TEST_CASE(FailSerializeLargeExternalTypedData) {
703 Dart_CObject root; 660 Dart_CObject root;
704 root.type = Dart_CObject_kExternalTypedData; 661 root.type = Dart_CObject_kExternalTypedData;
705 root.value.as_typed_data.length = 662 root.value.as_typed_data.length =
706 ExternalTypedData::MaxElements(kExternalTypedDataUint8ArrayCid) + 1; 663 ExternalTypedData::MaxElements(kExternalTypedDataUint8ArrayCid) + 1;
707 ExpectEncodeFail(&root); 664 ExpectEncodeFail(&root);
708 } 665 }
709 666
710 667
711 TEST_CASE(SerializeEmptyArray) { 668 TEST_CASE(SerializeEmptyArray) {
712 StackZone zone(Thread::Current());
713
714 // Write snapshot with object content. 669 // Write snapshot with object content.
715 const int kArrayLength = 0; 670 const int kArrayLength = 0;
716 Array& array = Array::Handle(Array::New(kArrayLength)); 671 Array& array = Array::Handle(Array::New(kArrayLength));
717 uint8_t* buffer; 672 uint8_t* buffer;
718 MessageWriter writer(&buffer, &zone_allocator, true); 673 MessageWriter writer(&buffer, &zone_allocator, true);
719 writer.WriteMessage(array); 674 writer.WriteMessage(array);
720 intptr_t buffer_len = writer.BytesWritten(); 675 intptr_t buffer_len = writer.BytesWritten();
721 676
722 // Read object back from the snapshot. 677 // Read object back from the snapshot.
723 MessageSnapshotReader reader(buffer, 678 MessageSnapshotReader reader(buffer, buffer_len, thread);
724 buffer_len,
725 Isolate::Current(),
726 zone.GetZone());
727 Array& serialized_array = Array::Handle(); 679 Array& serialized_array = Array::Handle();
728 serialized_array ^= reader.ReadObject(); 680 serialized_array ^= reader.ReadObject();
729 EXPECT(array.CanonicalizeEquals(serialized_array)); 681 EXPECT(array.CanonicalizeEquals(serialized_array));
730 682
731 // Read object back from the snapshot into a C structure. 683 // Read object back from the snapshot into a C structure.
732 ApiNativeScope scope; 684 ApiNativeScope scope;
733 ApiMessageReader api_reader(buffer, buffer_len); 685 ApiMessageReader api_reader(buffer, buffer_len);
734 Dart_CObject* root = api_reader.ReadMessage(); 686 Dart_CObject* root = api_reader.ReadMessage();
735 EXPECT_EQ(Dart_CObject_kArray, root->type); 687 EXPECT_EQ(Dart_CObject_kArray, root->type);
736 EXPECT_EQ(kArrayLength, root->value.as_array.length); 688 EXPECT_EQ(kArrayLength, root->value.as_array.length);
737 EXPECT(root->value.as_array.values == NULL); 689 EXPECT(root->value.as_array.values == NULL);
738 CheckEncodeDecodeMessage(root); 690 CheckEncodeDecodeMessage(root);
739 } 691 }
740 692
741 693
742 TEST_CASE(SerializeByteArray) { 694 TEST_CASE(SerializeByteArray) {
743 StackZone zone(Thread::Current());
744
745 // Write snapshot with object content. 695 // Write snapshot with object content.
746 const int kTypedDataLength = 256; 696 const int kTypedDataLength = 256;
747 TypedData& typed_data = TypedData::Handle( 697 TypedData& typed_data = TypedData::Handle(
748 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); 698 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength));
749 for (int i = 0; i < kTypedDataLength; i++) { 699 for (int i = 0; i < kTypedDataLength; i++) {
750 typed_data.SetUint8(i, i); 700 typed_data.SetUint8(i, i);
751 } 701 }
752 uint8_t* buffer; 702 uint8_t* buffer;
753 MessageWriter writer(&buffer, &zone_allocator, true); 703 MessageWriter writer(&buffer, &zone_allocator, true);
754 writer.WriteMessage(typed_data); 704 writer.WriteMessage(typed_data);
755 intptr_t buffer_len = writer.BytesWritten(); 705 intptr_t buffer_len = writer.BytesWritten();
756 706
757 // Read object back from the snapshot. 707 // Read object back from the snapshot.
758 MessageSnapshotReader reader(buffer, 708 MessageSnapshotReader reader(buffer, buffer_len, thread);
759 buffer_len,
760 Isolate::Current(),
761 zone.GetZone());
762 TypedData& serialized_typed_data = TypedData::Handle(); 709 TypedData& serialized_typed_data = TypedData::Handle();
763 serialized_typed_data ^= reader.ReadObject(); 710 serialized_typed_data ^= reader.ReadObject();
764 EXPECT(serialized_typed_data.IsTypedData()); 711 EXPECT(serialized_typed_data.IsTypedData());
765 712
766 // Read object back from the snapshot into a C structure. 713 // Read object back from the snapshot into a C structure.
767 ApiNativeScope scope; 714 ApiNativeScope scope;
768 ApiMessageReader api_reader(buffer, buffer_len); 715 ApiMessageReader api_reader(buffer, buffer_len);
769 Dart_CObject* root = api_reader.ReadMessage(); 716 Dart_CObject* root = api_reader.ReadMessage();
770 EXPECT_EQ(Dart_CObject_kTypedData, root->type); 717 EXPECT_EQ(Dart_CObject_kTypedData, root->type);
771 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); 718 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length);
772 for (int i = 0; i < kTypedDataLength; i++) { 719 for (int i = 0; i < kTypedDataLength; i++) {
773 EXPECT(root->value.as_typed_data.values[i] == i); 720 EXPECT(root->value.as_typed_data.values[i] == i);
774 } 721 }
775 CheckEncodeDecodeMessage(root); 722 CheckEncodeDecodeMessage(root);
776 } 723 }
777 724
778 725
779 #define TEST_TYPED_ARRAY(darttype, ctype) \ 726 #define TEST_TYPED_ARRAY(darttype, ctype) \
780 { \ 727 { \
siva 2015/09/01 23:38:16 Why did you get rid of the StackZone here?
Ivan Posva 2015/09/02 00:03:33 Reverted.
781 StackZone zone(Thread::Current()); \ 728 const int kArrayLength = 127; \
782 const int kArrayLength = 127; \ 729 TypedData& array = TypedData::Handle( \
783 TypedData& array = TypedData::Handle( \ 730 TypedData::New(kTypedData##darttype##ArrayCid, kArrayLength)); \
784 TypedData::New(kTypedData##darttype##ArrayCid, kArrayLength)); \ 731 intptr_t scale = array.ElementSizeInBytes(); \
785 intptr_t scale = array.ElementSizeInBytes(); \ 732 for (int i = 0; i < kArrayLength; i++) { \
786 for (int i = 0; i < kArrayLength; i++) { \ 733 array.Set##darttype((i * scale), i); \
787 array.Set##darttype((i * scale), i); \ 734 } \
788 } \ 735 uint8_t* buffer; \
789 uint8_t* buffer; \ 736 MessageWriter writer(&buffer, &zone_allocator, true); \
790 MessageWriter writer(&buffer, &zone_allocator, true); \ 737 writer.WriteMessage(array); \
791 writer.WriteMessage(array); \ 738 intptr_t buffer_len = writer.BytesWritten(); \
792 intptr_t buffer_len = writer.BytesWritten(); \ 739 MessageSnapshotReader reader(buffer, buffer_len, thread); \
793 MessageSnapshotReader reader(buffer, buffer_len, \ 740 TypedData& serialized_array = TypedData::Handle(); \
794 Isolate::Current(), \ 741 serialized_array ^= reader.ReadObject(); \
795 zone.GetZone()); \ 742 for (int i = 0; i < kArrayLength; i++) { \
796 TypedData& serialized_array = TypedData::Handle(); \ 743 EXPECT_EQ(static_cast<ctype>(i), \
797 serialized_array ^= reader.ReadObject(); \ 744 serialized_array.Get##darttype(i*scale)); \
798 for (int i = 0; i < kArrayLength; i++) { \ 745 } \
799 EXPECT_EQ(static_cast<ctype>(i), \
800 serialized_array.Get##darttype(i*scale)); \
801 } \
802 } 746 }
803 747
804 748
805 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \ 749 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \
806 { \ 750 { \
siva 2015/09/01 23:38:16 Ditto question.
Ivan Posva 2015/09/02 00:03:33 ditto.
807 StackZone zone(Thread::Current()); \ 751 ctype data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; \
808 ctype data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; \ 752 intptr_t length = ARRAY_SIZE(data); \
809 intptr_t length = ARRAY_SIZE(data); \ 753 ExternalTypedData& array = ExternalTypedData::Handle( \
810 ExternalTypedData& array = ExternalTypedData::Handle( \ 754 ExternalTypedData::New(kExternalTypedData##darttype##ArrayCid, \
811 ExternalTypedData::New(kExternalTypedData##darttype##ArrayCid, \ 755 reinterpret_cast<uint8_t*>(data), length)); \
812 reinterpret_cast<uint8_t*>(data), length)); \ 756 intptr_t scale = array.ElementSizeInBytes(); \
813 intptr_t scale = array.ElementSizeInBytes(); \ 757 uint8_t* buffer; \
814 uint8_t* buffer; \ 758 MessageWriter writer(&buffer, &zone_allocator, true); \
815 MessageWriter writer(&buffer, &zone_allocator, true); \ 759 writer.WriteMessage(array); \
816 writer.WriteMessage(array); \ 760 intptr_t buffer_len = writer.BytesWritten(); \
817 intptr_t buffer_len = writer.BytesWritten(); \ 761 MessageSnapshotReader reader(buffer, buffer_len, thread); \
818 MessageSnapshotReader reader(buffer, buffer_len, \ 762 TypedData& serialized_array = TypedData::Handle(); \
819 Isolate::Current(), \ 763 serialized_array ^= reader.ReadObject(); \
820 zone.GetZone()); \ 764 for (int i = 0; i < length; i++) { \
821 TypedData& serialized_array = TypedData::Handle(); \ 765 EXPECT_EQ(static_cast<ctype>(data[i]), \
822 serialized_array ^= reader.ReadObject(); \ 766 serialized_array.Get##darttype(i*scale)); \
823 for (int i = 0; i < length; i++) { \ 767 } \
824 EXPECT_EQ(static_cast<ctype>(data[i]), \
825 serialized_array.Get##darttype(i*scale)); \
826 } \
827 } 768 }
828 769
829 770
830 TEST_CASE(SerializeTypedArray) { 771 TEST_CASE(SerializeTypedArray) {
831 TEST_TYPED_ARRAY(Int8, int8_t); 772 TEST_TYPED_ARRAY(Int8, int8_t);
832 TEST_TYPED_ARRAY(Uint8, uint8_t); 773 TEST_TYPED_ARRAY(Uint8, uint8_t);
833 TEST_TYPED_ARRAY(Int16, int16_t); 774 TEST_TYPED_ARRAY(Int16, int16_t);
834 TEST_TYPED_ARRAY(Uint16, uint16_t); 775 TEST_TYPED_ARRAY(Uint16, uint16_t);
835 TEST_TYPED_ARRAY(Int32, int32_t); 776 TEST_TYPED_ARRAY(Int32, int32_t);
836 TEST_TYPED_ARRAY(Uint32, uint32_t); 777 TEST_TYPED_ARRAY(Uint32, uint32_t);
(...skipping 12 matching lines...) Expand all
849 TEST_EXTERNAL_TYPED_ARRAY(Int32, int32_t); 790 TEST_EXTERNAL_TYPED_ARRAY(Int32, int32_t);
850 TEST_EXTERNAL_TYPED_ARRAY(Uint32, uint32_t); 791 TEST_EXTERNAL_TYPED_ARRAY(Uint32, uint32_t);
851 TEST_EXTERNAL_TYPED_ARRAY(Int64, int64_t); 792 TEST_EXTERNAL_TYPED_ARRAY(Int64, int64_t);
852 TEST_EXTERNAL_TYPED_ARRAY(Uint64, uint64_t); 793 TEST_EXTERNAL_TYPED_ARRAY(Uint64, uint64_t);
853 TEST_EXTERNAL_TYPED_ARRAY(Float32, float); 794 TEST_EXTERNAL_TYPED_ARRAY(Float32, float);
854 TEST_EXTERNAL_TYPED_ARRAY(Float64, double); 795 TEST_EXTERNAL_TYPED_ARRAY(Float64, double);
855 } 796 }
856 797
857 798
858 TEST_CASE(SerializeEmptyByteArray) { 799 TEST_CASE(SerializeEmptyByteArray) {
859 StackZone zone(Thread::Current());
860
861 // Write snapshot with object content. 800 // Write snapshot with object content.
862 const int kTypedDataLength = 0; 801 const int kTypedDataLength = 0;
863 TypedData& typed_data = TypedData::Handle( 802 TypedData& typed_data = TypedData::Handle(
864 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); 803 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength));
865 uint8_t* buffer; 804 uint8_t* buffer;
866 MessageWriter writer(&buffer, &zone_allocator, true); 805 MessageWriter writer(&buffer, &zone_allocator, true);
867 writer.WriteMessage(typed_data); 806 writer.WriteMessage(typed_data);
868 intptr_t buffer_len = writer.BytesWritten(); 807 intptr_t buffer_len = writer.BytesWritten();
869 808
870 // Read object back from the snapshot. 809 // Read object back from the snapshot.
871 MessageSnapshotReader reader(buffer, 810 MessageSnapshotReader reader(buffer, buffer_len, thread);
872 buffer_len,
873 Isolate::Current(),
874 zone.GetZone());
875 TypedData& serialized_typed_data = TypedData::Handle(); 811 TypedData& serialized_typed_data = TypedData::Handle();
876 serialized_typed_data ^= reader.ReadObject(); 812 serialized_typed_data ^= reader.ReadObject();
877 EXPECT(serialized_typed_data.IsTypedData()); 813 EXPECT(serialized_typed_data.IsTypedData());
878 814
879 // Read object back from the snapshot into a C structure. 815 // Read object back from the snapshot into a C structure.
880 ApiNativeScope scope; 816 ApiNativeScope scope;
881 ApiMessageReader api_reader(buffer, buffer_len); 817 ApiMessageReader api_reader(buffer, buffer_len);
882 Dart_CObject* root = api_reader.ReadMessage(); 818 Dart_CObject* root = api_reader.ReadMessage();
883 EXPECT_EQ(Dart_CObject_kTypedData, root->type); 819 EXPECT_EQ(Dart_CObject_kTypedData, root->type);
884 EXPECT_EQ(Dart_TypedData_kUint8, root->value.as_typed_data.type); 820 EXPECT_EQ(Dart_TypedData_kUint8, root->value.as_typed_data.type);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 Library& lib = Library::Handle(Library::New(lib_url)); 939 Library& lib = Library::Handle(Library::New(lib_url));
1004 lib.Register(); 940 lib.Register();
1005 EXPECT(CompilerTest::TestCompileScript(lib, script)); 941 EXPECT(CompilerTest::TestCompileScript(lib, script));
1006 942
1007 // Write snapshot with script content. 943 // Write snapshot with script content.
1008 uint8_t* buffer; 944 uint8_t* buffer;
1009 TestSnapshotWriter writer(&buffer, &malloc_allocator); 945 TestSnapshotWriter writer(&buffer, &malloc_allocator);
1010 writer.WriteScript(script); 946 writer.WriteScript(script);
1011 947
1012 // Read object back from the snapshot. 948 // Read object back from the snapshot.
1013 ScriptSnapshotReader reader(buffer, 949 ScriptSnapshotReader reader(buffer, writer.BytesWritten(), thread);
1014 writer.BytesWritten(), 950 Script& serialized_script = Script::Handle(thread->zone());
1015 Isolate::Current(),
1016 Thread::Current()->zone());
1017 Script& serialized_script = Script::Handle();
1018 serialized_script ^= reader.ReadObject(); 951 serialized_script ^= reader.ReadObject();
1019 952
1020 // Check if the serialized script object matches the original script. 953 // Check if the serialized script object matches the original script.
1021 String& expected_literal = String::Handle(); 954 String& expected_literal = String::Handle();
1022 String& actual_literal = String::Handle(); 955 String& actual_literal = String::Handle();
1023 String& str = String::Handle(); 956 String& str = String::Handle();
1024 str ^= serialized_script.url(); 957 str ^= serialized_script.url();
1025 EXPECT(url.Equals(str)); 958 EXPECT(url.Equals(str));
1026 959
1027 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); 960 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens());
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 uint8_t* isolate_snapshot_buffer; 1159 uint8_t* isolate_snapshot_buffer;
1227 1160
1228 // Start an Isolate, load a script and create a full snapshot. 1161 // Start an Isolate, load a script and create a full snapshot.
1229 Timer timer1(true, "Snapshot_test"); 1162 Timer timer1(true, "Snapshot_test");
1230 timer1.Start(); 1163 timer1.Start();
1231 { 1164 {
1232 TestIsolateScope __test_isolate__; 1165 TestIsolateScope __test_isolate__;
1233 1166
1234 Isolate* isolate = Isolate::Current(); 1167 Isolate* isolate = Isolate::Current();
1235 StackZone zone(isolate); 1168 StackZone zone(isolate);
1236 HandleScope scope(isolate); 1169 HandleScope scope(Thread::Current());
1237 1170
1238 // Create a test library and Load up a test script in it. 1171 // Create a test library and Load up a test script in it.
1239 TestCase::LoadTestScript(kScriptChars, NULL); 1172 TestCase::LoadTestScript(kScriptChars, NULL);
1240 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate)); 1173 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate));
1241 timer1.Stop(); 1174 timer1.Stop();
1242 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); 1175 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime());
1243 1176
1244 // Write snapshot with object content. 1177 // Write snapshot with object content.
1245 { 1178 {
1246 FullSnapshotWriter writer(NULL, 1179 FullSnapshotWriter writer(NULL,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 uint8_t* isolate_snapshot_buffer; 1218 uint8_t* isolate_snapshot_buffer;
1286 1219
1287 // Start an Isolate, load a script and create a full snapshot. 1220 // Start an Isolate, load a script and create a full snapshot.
1288 Timer timer1(true, "Snapshot_test"); 1221 Timer timer1(true, "Snapshot_test");
1289 timer1.Start(); 1222 timer1.Start();
1290 { 1223 {
1291 TestIsolateScope __test_isolate__; 1224 TestIsolateScope __test_isolate__;
1292 1225
1293 Isolate* isolate = Isolate::Current(); 1226 Isolate* isolate = Isolate::Current();
1294 StackZone zone(isolate); 1227 StackZone zone(isolate);
1295 HandleScope scope(isolate); 1228 HandleScope scope(Thread::Current());
1296 1229
1297 // Create a test library and Load up a test script in it. 1230 // Create a test library and Load up a test script in it.
1298 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1231 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1299 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate)); 1232 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate));
1300 timer1.Stop(); 1233 timer1.Stop();
1301 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); 1234 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime());
1302 1235
1303 // Write snapshot with object content. 1236 // Write snapshot with object content.
1304 { 1237 {
1305 FullSnapshotWriter writer(NULL, 1238 FullSnapshotWriter writer(NULL,
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 EXPECT_VALID(surrogates_string_result); 1823 EXPECT_VALID(surrogates_string_result);
1891 EXPECT(Dart_IsString(surrogates_string_result)); 1824 EXPECT(Dart_IsString(surrogates_string_result));
1892 1825
1893 Dart_Handle crappy_string_result; 1826 Dart_Handle crappy_string_result;
1894 crappy_string_result = 1827 crappy_string_result =
1895 Dart_Invoke(lib, NewString("getCrappyString"), 0, NULL); 1828 Dart_Invoke(lib, NewString("getCrappyString"), 0, NULL);
1896 EXPECT_VALID(crappy_string_result); 1829 EXPECT_VALID(crappy_string_result);
1897 EXPECT(Dart_IsString(crappy_string_result)); 1830 EXPECT(Dart_IsString(crappy_string_result));
1898 1831
1899 { 1832 {
1900 DARTSCOPE(isolate); 1833 DARTSCOPE(Thread::Current());
1901 1834
1902 { 1835 {
1903 StackZone zone(Thread::Current()); 1836 StackZone zone(Thread::Current());
1904 Smi& smi = Smi::Handle(); 1837 Smi& smi = Smi::Handle();
1905 smi ^= Api::UnwrapHandle(smi_result); 1838 smi ^= Api::UnwrapHandle(smi_result);
1906 uint8_t* buffer; 1839 uint8_t* buffer;
1907 MessageWriter writer(&buffer, &zone_allocator, false); 1840 MessageWriter writer(&buffer, &zone_allocator, false);
1908 writer.WriteMessage(smi); 1841 writer.WriteMessage(smi);
1909 intptr_t buffer_len = writer.BytesWritten(); 1842 intptr_t buffer_len = writer.BytesWritten();
1910 1843
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 1915
1983 TestCase::CreateTestIsolate(); 1916 TestCase::CreateTestIsolate();
1984 Isolate* isolate = Isolate::Current(); 1917 Isolate* isolate = Isolate::Current();
1985 EXPECT(isolate != NULL); 1918 EXPECT(isolate != NULL);
1986 Dart_EnterScope(); 1919 Dart_EnterScope();
1987 1920
1988 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1921 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1989 EXPECT_VALID(lib); 1922 EXPECT_VALID(lib);
1990 1923
1991 { 1924 {
1992 DARTSCOPE(isolate); 1925 DARTSCOPE(Thread::Current());
1993 StackZone zone(isolate); 1926 StackZone zone(isolate);
1994 intptr_t buf_len = 0; 1927 intptr_t buf_len = 0;
1995 { 1928 {
1996 // Generate a list of nulls from Dart code. 1929 // Generate a list of nulls from Dart code.
1997 uint8_t* buf = GetSerialized(lib, "getList", &buf_len); 1930 uint8_t* buf = GetSerialized(lib, "getList", &buf_len);
1998 ApiNativeScope scope; 1931 ApiNativeScope scope;
1999 Dart_CObject* root = GetDeserialized(buf, buf_len); 1932 Dart_CObject* root = GetDeserialized(buf, buf_len);
2000 EXPECT_NOTNULL(root); 1933 EXPECT_NOTNULL(root);
2001 EXPECT_EQ(Dart_CObject_kArray, root->type); 1934 EXPECT_EQ(Dart_CObject_kArray, root->type);
2002 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1935 EXPECT_EQ(kArrayLength, root->value.as_array.length);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 2039
2107 TestCase::CreateTestIsolate(); 2040 TestCase::CreateTestIsolate();
2108 Isolate* isolate = Isolate::Current(); 2041 Isolate* isolate = Isolate::Current();
2109 EXPECT(isolate != NULL); 2042 EXPECT(isolate != NULL);
2110 Dart_EnterScope(); 2043 Dart_EnterScope();
2111 2044
2112 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2045 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2113 EXPECT_VALID(lib); 2046 EXPECT_VALID(lib);
2114 2047
2115 { 2048 {
2116 DARTSCOPE(isolate); 2049 DARTSCOPE(Thread::Current());
2117 StackZone zone(isolate); 2050 StackZone zone(isolate);
2118 intptr_t buf_len = 0; 2051 intptr_t buf_len = 0;
2119 { 2052 {
2120 // Generate a list of nulls from Dart code. 2053 // Generate a list of nulls from Dart code.
2121 uint8_t* buf = GetSerialized(lib, "getList", &buf_len); 2054 uint8_t* buf = GetSerialized(lib, "getList", &buf_len);
2122 ApiNativeScope scope; 2055 ApiNativeScope scope;
2123 Dart_CObject* root = GetDeserialized(buf, buf_len); 2056 Dart_CObject* root = GetDeserialized(buf, buf_len);
2124 EXPECT_NOTNULL(root); 2057 EXPECT_NOTNULL(root);
2125 EXPECT_EQ(Dart_CObject_kArray, root->type); 2058 EXPECT_EQ(Dart_CObject_kArray, root->type);
2126 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2059 EXPECT_EQ(kArrayLength, root->value.as_array.length);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 2278
2346 TestCase::CreateTestIsolate(); 2279 TestCase::CreateTestIsolate();
2347 Isolate* isolate = Isolate::Current(); 2280 Isolate* isolate = Isolate::Current();
2348 EXPECT(isolate != NULL); 2281 EXPECT(isolate != NULL);
2349 Dart_EnterScope(); 2282 Dart_EnterScope();
2350 2283
2351 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2284 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2352 EXPECT_VALID(lib); 2285 EXPECT_VALID(lib);
2353 2286
2354 { 2287 {
2355 DARTSCOPE(isolate); 2288 DARTSCOPE(Thread::Current());
2356 StackZone zone(isolate); 2289 StackZone zone(isolate);
2357 intptr_t buf_len = 0; 2290 intptr_t buf_len = 0;
2358 { 2291 {
2359 // Generate a list of strings from Dart code. 2292 // Generate a list of strings from Dart code.
2360 uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len); 2293 uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len);
2361 ApiNativeScope scope; 2294 ApiNativeScope scope;
2362 Dart_CObject* root = GetDeserialized(buf, buf_len); 2295 Dart_CObject* root = GetDeserialized(buf, buf_len);
2363 EXPECT_NOTNULL(root); 2296 EXPECT_NOTNULL(root);
2364 EXPECT_EQ(Dart_CObject_kArray, root->type); 2297 EXPECT_EQ(Dart_CObject_kArray, root->type);
2365 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2298 EXPECT_EQ(kArrayLength, root->value.as_array.length);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
2570 2503
2571 TestCase::CreateTestIsolate(); 2504 TestCase::CreateTestIsolate();
2572 Isolate* isolate = Isolate::Current(); 2505 Isolate* isolate = Isolate::Current();
2573 EXPECT(isolate != NULL); 2506 EXPECT(isolate != NULL);
2574 Dart_EnterScope(); 2507 Dart_EnterScope();
2575 2508
2576 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2509 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2577 EXPECT_VALID(lib); 2510 EXPECT_VALID(lib);
2578 2511
2579 { 2512 {
2580 DARTSCOPE(isolate); 2513 DARTSCOPE(Thread::Current());
2581 StackZone zone(isolate); 2514 StackZone zone(isolate);
2582 intptr_t buf_len = 0; 2515 intptr_t buf_len = 0;
2583 { 2516 {
2584 // Generate a list of strings from Dart code. 2517 // Generate a list of strings from Dart code.
2585 uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len); 2518 uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len);
2586 ApiNativeScope scope; 2519 ApiNativeScope scope;
2587 Dart_CObject* root = GetDeserialized(buf, buf_len); 2520 Dart_CObject* root = GetDeserialized(buf, buf_len);
2588 EXPECT_NOTNULL(root); 2521 EXPECT_NOTNULL(root);
2589 EXPECT_EQ(Dart_CObject_kArray, root->type); 2522 EXPECT_EQ(Dart_CObject_kArray, root->type);
2590 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2523 EXPECT_EQ(kArrayLength, root->value.as_array.length);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2811 2744
2812 TestCase::CreateTestIsolate(); 2745 TestCase::CreateTestIsolate();
2813 Isolate* isolate = Isolate::Current(); 2746 Isolate* isolate = Isolate::Current();
2814 EXPECT(isolate != NULL); 2747 EXPECT(isolate != NULL);
2815 Dart_EnterScope(); 2748 Dart_EnterScope();
2816 2749
2817 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2750 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2818 EXPECT_VALID(lib); 2751 EXPECT_VALID(lib);
2819 2752
2820 { 2753 {
2821 DARTSCOPE(isolate); 2754 DARTSCOPE(Thread::Current());
2822 StackZone zone(isolate); 2755 StackZone zone(isolate);
2823 intptr_t buf_len = 0; 2756 intptr_t buf_len = 0;
2824 { 2757 {
2825 // Generate a list of Uint8Lists from Dart code. 2758 // Generate a list of Uint8Lists from Dart code.
2826 uint8_t* buf = GetSerialized(lib, "getTypedDataList", &buf_len); 2759 uint8_t* buf = GetSerialized(lib, "getTypedDataList", &buf_len);
2827 ApiNativeScope scope; 2760 ApiNativeScope scope;
2828 Dart_CObject* root = GetDeserialized(buf, buf_len); 2761 Dart_CObject* root = GetDeserialized(buf, buf_len);
2829 EXPECT_NOTNULL(root); 2762 EXPECT_NOTNULL(root);
2830 EXPECT_EQ(Dart_CObject_kArray, root->type); 2763 EXPECT_EQ(Dart_CObject_kArray, root->type);
2831 struct { 2764 struct {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
3054 StackZone zone(Thread::Current()); 2987 StackZone zone(Thread::Current());
3055 uint8_t* buffer; 2988 uint8_t* buffer;
3056 MessageWriter writer(&buffer, &zone_allocator, true); 2989 MessageWriter writer(&buffer, &zone_allocator, true);
3057 writer.WriteInlinedObjectHeader(kOmittedObjectId); 2990 writer.WriteInlinedObjectHeader(kOmittedObjectId);
3058 // For performance, we'd like single-byte headers when ids are omitted. 2991 // For performance, we'd like single-byte headers when ids are omitted.
3059 // If this starts failing, consider renumbering the snapshot ids. 2992 // If this starts failing, consider renumbering the snapshot ids.
3060 EXPECT_EQ(1, writer.BytesWritten()); 2993 EXPECT_EQ(1, writer.BytesWritten());
3061 } 2994 }
3062 2995
3063 } // namespace dart 2996 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698