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

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: Address review comments 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
« no previous file with comments | « runtime/vm/snapshot.cc ('k') | runtime/vm/thread_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "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 { \
781 StackZone zone(Thread::Current()); \ 728 StackZone zone(thread); \
782 const int kArrayLength = 127; \ 729 const int kArrayLength = 127; \
783 TypedData& array = TypedData::Handle( \ 730 TypedData& array = TypedData::Handle( \
784 TypedData::New(kTypedData##darttype##ArrayCid, kArrayLength)); \ 731 TypedData::New(kTypedData##darttype##ArrayCid, kArrayLength)); \
785 intptr_t scale = array.ElementSizeInBytes(); \ 732 intptr_t scale = array.ElementSizeInBytes(); \
786 for (int i = 0; i < kArrayLength; i++) { \ 733 for (int i = 0; i < kArrayLength; i++) { \
787 array.Set##darttype((i * scale), i); \ 734 array.Set##darttype((i * scale), i); \
788 } \ 735 } \
789 uint8_t* buffer; \ 736 uint8_t* buffer; \
790 MessageWriter writer(&buffer, &zone_allocator, true); \ 737 MessageWriter writer(&buffer, &zone_allocator, true); \
791 writer.WriteMessage(array); \ 738 writer.WriteMessage(array); \
792 intptr_t buffer_len = writer.BytesWritten(); \ 739 intptr_t buffer_len = writer.BytesWritten(); \
793 MessageSnapshotReader reader(buffer, buffer_len, \ 740 MessageSnapshotReader reader(buffer, buffer_len, thread); \
794 Isolate::Current(), \ 741 TypedData& serialized_array = TypedData::Handle(); \
795 zone.GetZone()); \ 742 serialized_array ^= reader.ReadObject(); \
796 TypedData& serialized_array = TypedData::Handle(); \ 743 for (int i = 0; i < kArrayLength; i++) { \
797 serialized_array ^= reader.ReadObject(); \ 744 EXPECT_EQ(static_cast<ctype>(i), \
798 for (int i = 0; i < kArrayLength; i++) { \ 745 serialized_array.Get##darttype(i*scale)); \
799 EXPECT_EQ(static_cast<ctype>(i), \ 746 } \
800 serialized_array.Get##darttype(i*scale)); \
801 } \
802 } 747 }
803 748
804 749
805 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \ 750 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \
806 { \ 751 { \
807 StackZone zone(Thread::Current()); \ 752 StackZone zone(thread); \
808 ctype data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; \ 753 ctype data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; \
809 intptr_t length = ARRAY_SIZE(data); \ 754 intptr_t length = ARRAY_SIZE(data); \
810 ExternalTypedData& array = ExternalTypedData::Handle( \ 755 ExternalTypedData& array = ExternalTypedData::Handle( \
811 ExternalTypedData::New(kExternalTypedData##darttype##ArrayCid, \ 756 ExternalTypedData::New(kExternalTypedData##darttype##ArrayCid, \
812 reinterpret_cast<uint8_t*>(data), length)); \ 757 reinterpret_cast<uint8_t*>(data), length)); \
813 intptr_t scale = array.ElementSizeInBytes(); \ 758 intptr_t scale = array.ElementSizeInBytes(); \
814 uint8_t* buffer; \ 759 uint8_t* buffer; \
815 MessageWriter writer(&buffer, &zone_allocator, true); \ 760 MessageWriter writer(&buffer, &zone_allocator, true); \
816 writer.WriteMessage(array); \ 761 writer.WriteMessage(array); \
817 intptr_t buffer_len = writer.BytesWritten(); \ 762 intptr_t buffer_len = writer.BytesWritten(); \
818 MessageSnapshotReader reader(buffer, buffer_len, \ 763 MessageSnapshotReader reader(buffer, buffer_len, thread); \
819 Isolate::Current(), \ 764 TypedData& serialized_array = TypedData::Handle(); \
820 zone.GetZone()); \ 765 serialized_array ^= reader.ReadObject(); \
821 TypedData& serialized_array = TypedData::Handle(); \ 766 for (int i = 0; i < length; i++) { \
822 serialized_array ^= reader.ReadObject(); \ 767 EXPECT_EQ(static_cast<ctype>(data[i]), \
823 for (int i = 0; i < length; i++) { \ 768 serialized_array.Get##darttype(i*scale)); \
824 EXPECT_EQ(static_cast<ctype>(data[i]), \ 769 } \
825 serialized_array.Get##darttype(i*scale)); \
826 } \
827 } 770 }
828 771
829 772
830 TEST_CASE(SerializeTypedArray) { 773 TEST_CASE(SerializeTypedArray) {
831 TEST_TYPED_ARRAY(Int8, int8_t); 774 TEST_TYPED_ARRAY(Int8, int8_t);
832 TEST_TYPED_ARRAY(Uint8, uint8_t); 775 TEST_TYPED_ARRAY(Uint8, uint8_t);
833 TEST_TYPED_ARRAY(Int16, int16_t); 776 TEST_TYPED_ARRAY(Int16, int16_t);
834 TEST_TYPED_ARRAY(Uint16, uint16_t); 777 TEST_TYPED_ARRAY(Uint16, uint16_t);
835 TEST_TYPED_ARRAY(Int32, int32_t); 778 TEST_TYPED_ARRAY(Int32, int32_t);
836 TEST_TYPED_ARRAY(Uint32, uint32_t); 779 TEST_TYPED_ARRAY(Uint32, uint32_t);
(...skipping 12 matching lines...) Expand all
849 TEST_EXTERNAL_TYPED_ARRAY(Int32, int32_t); 792 TEST_EXTERNAL_TYPED_ARRAY(Int32, int32_t);
850 TEST_EXTERNAL_TYPED_ARRAY(Uint32, uint32_t); 793 TEST_EXTERNAL_TYPED_ARRAY(Uint32, uint32_t);
851 TEST_EXTERNAL_TYPED_ARRAY(Int64, int64_t); 794 TEST_EXTERNAL_TYPED_ARRAY(Int64, int64_t);
852 TEST_EXTERNAL_TYPED_ARRAY(Uint64, uint64_t); 795 TEST_EXTERNAL_TYPED_ARRAY(Uint64, uint64_t);
853 TEST_EXTERNAL_TYPED_ARRAY(Float32, float); 796 TEST_EXTERNAL_TYPED_ARRAY(Float32, float);
854 TEST_EXTERNAL_TYPED_ARRAY(Float64, double); 797 TEST_EXTERNAL_TYPED_ARRAY(Float64, double);
855 } 798 }
856 799
857 800
858 TEST_CASE(SerializeEmptyByteArray) { 801 TEST_CASE(SerializeEmptyByteArray) {
859 StackZone zone(Thread::Current());
860
861 // Write snapshot with object content. 802 // Write snapshot with object content.
862 const int kTypedDataLength = 0; 803 const int kTypedDataLength = 0;
863 TypedData& typed_data = TypedData::Handle( 804 TypedData& typed_data = TypedData::Handle(
864 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); 805 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength));
865 uint8_t* buffer; 806 uint8_t* buffer;
866 MessageWriter writer(&buffer, &zone_allocator, true); 807 MessageWriter writer(&buffer, &zone_allocator, true);
867 writer.WriteMessage(typed_data); 808 writer.WriteMessage(typed_data);
868 intptr_t buffer_len = writer.BytesWritten(); 809 intptr_t buffer_len = writer.BytesWritten();
869 810
870 // Read object back from the snapshot. 811 // Read object back from the snapshot.
871 MessageSnapshotReader reader(buffer, 812 MessageSnapshotReader reader(buffer, buffer_len, thread);
872 buffer_len,
873 Isolate::Current(),
874 zone.GetZone());
875 TypedData& serialized_typed_data = TypedData::Handle(); 813 TypedData& serialized_typed_data = TypedData::Handle();
876 serialized_typed_data ^= reader.ReadObject(); 814 serialized_typed_data ^= reader.ReadObject();
877 EXPECT(serialized_typed_data.IsTypedData()); 815 EXPECT(serialized_typed_data.IsTypedData());
878 816
879 // Read object back from the snapshot into a C structure. 817 // Read object back from the snapshot into a C structure.
880 ApiNativeScope scope; 818 ApiNativeScope scope;
881 ApiMessageReader api_reader(buffer, buffer_len); 819 ApiMessageReader api_reader(buffer, buffer_len);
882 Dart_CObject* root = api_reader.ReadMessage(); 820 Dart_CObject* root = api_reader.ReadMessage();
883 EXPECT_EQ(Dart_CObject_kTypedData, root->type); 821 EXPECT_EQ(Dart_CObject_kTypedData, root->type);
884 EXPECT_EQ(Dart_TypedData_kUint8, root->value.as_typed_data.type); 822 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)); 941 Library& lib = Library::Handle(Library::New(lib_url));
1004 lib.Register(); 942 lib.Register();
1005 EXPECT(CompilerTest::TestCompileScript(lib, script)); 943 EXPECT(CompilerTest::TestCompileScript(lib, script));
1006 944
1007 // Write snapshot with script content. 945 // Write snapshot with script content.
1008 uint8_t* buffer; 946 uint8_t* buffer;
1009 TestSnapshotWriter writer(&buffer, &malloc_allocator); 947 TestSnapshotWriter writer(&buffer, &malloc_allocator);
1010 writer.WriteScript(script); 948 writer.WriteScript(script);
1011 949
1012 // Read object back from the snapshot. 950 // Read object back from the snapshot.
1013 ScriptSnapshotReader reader(buffer, 951 ScriptSnapshotReader reader(buffer, writer.BytesWritten(), thread);
1014 writer.BytesWritten(), 952 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(); 953 serialized_script ^= reader.ReadObject();
1019 954
1020 // Check if the serialized script object matches the original script. 955 // Check if the serialized script object matches the original script.
1021 String& expected_literal = String::Handle(); 956 String& expected_literal = String::Handle();
1022 String& actual_literal = String::Handle(); 957 String& actual_literal = String::Handle();
1023 String& str = String::Handle(); 958 String& str = String::Handle();
1024 str ^= serialized_script.url(); 959 str ^= serialized_script.url();
1025 EXPECT(url.Equals(str)); 960 EXPECT(url.Equals(str));
1026 961
1027 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); 962 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; 1161 uint8_t* isolate_snapshot_buffer;
1227 1162
1228 // Start an Isolate, load a script and create a full snapshot. 1163 // Start an Isolate, load a script and create a full snapshot.
1229 Timer timer1(true, "Snapshot_test"); 1164 Timer timer1(true, "Snapshot_test");
1230 timer1.Start(); 1165 timer1.Start();
1231 { 1166 {
1232 TestIsolateScope __test_isolate__; 1167 TestIsolateScope __test_isolate__;
1233 1168
1234 Isolate* isolate = Isolate::Current(); 1169 Isolate* isolate = Isolate::Current();
1235 StackZone zone(isolate); 1170 StackZone zone(isolate);
1236 HandleScope scope(isolate); 1171 HandleScope scope(Thread::Current());
1237 1172
1238 // Create a test library and Load up a test script in it. 1173 // Create a test library and Load up a test script in it.
1239 TestCase::LoadTestScript(kScriptChars, NULL); 1174 TestCase::LoadTestScript(kScriptChars, NULL);
1240 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate)); 1175 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate));
1241 timer1.Stop(); 1176 timer1.Stop();
1242 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); 1177 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime());
1243 1178
1244 // Write snapshot with object content. 1179 // Write snapshot with object content.
1245 { 1180 {
1246 FullSnapshotWriter writer(NULL, 1181 FullSnapshotWriter writer(NULL,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 uint8_t* isolate_snapshot_buffer; 1220 uint8_t* isolate_snapshot_buffer;
1286 1221
1287 // Start an Isolate, load a script and create a full snapshot. 1222 // Start an Isolate, load a script and create a full snapshot.
1288 Timer timer1(true, "Snapshot_test"); 1223 Timer timer1(true, "Snapshot_test");
1289 timer1.Start(); 1224 timer1.Start();
1290 { 1225 {
1291 TestIsolateScope __test_isolate__; 1226 TestIsolateScope __test_isolate__;
1292 1227
1293 Isolate* isolate = Isolate::Current(); 1228 Isolate* isolate = Isolate::Current();
1294 StackZone zone(isolate); 1229 StackZone zone(isolate);
1295 HandleScope scope(isolate); 1230 HandleScope scope(Thread::Current());
1296 1231
1297 // Create a test library and Load up a test script in it. 1232 // Create a test library and Load up a test script in it.
1298 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1233 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1299 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate)); 1234 EXPECT_VALID(Api::CheckAndFinalizePendingClasses(isolate));
1300 timer1.Stop(); 1235 timer1.Stop();
1301 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime()); 1236 OS::PrintErr("Without Snapshot: %" Pd64 "us\n", timer1.TotalElapsedTime());
1302 1237
1303 // Write snapshot with object content. 1238 // Write snapshot with object content.
1304 { 1239 {
1305 FullSnapshotWriter writer(NULL, 1240 FullSnapshotWriter writer(NULL,
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 EXPECT_VALID(surrogates_string_result); 1825 EXPECT_VALID(surrogates_string_result);
1891 EXPECT(Dart_IsString(surrogates_string_result)); 1826 EXPECT(Dart_IsString(surrogates_string_result));
1892 1827
1893 Dart_Handle crappy_string_result; 1828 Dart_Handle crappy_string_result;
1894 crappy_string_result = 1829 crappy_string_result =
1895 Dart_Invoke(lib, NewString("getCrappyString"), 0, NULL); 1830 Dart_Invoke(lib, NewString("getCrappyString"), 0, NULL);
1896 EXPECT_VALID(crappy_string_result); 1831 EXPECT_VALID(crappy_string_result);
1897 EXPECT(Dart_IsString(crappy_string_result)); 1832 EXPECT(Dart_IsString(crappy_string_result));
1898 1833
1899 { 1834 {
1900 DARTSCOPE(isolate); 1835 DARTSCOPE(Thread::Current());
1901 1836
1902 { 1837 {
1903 StackZone zone(Thread::Current()); 1838 StackZone zone(Thread::Current());
1904 Smi& smi = Smi::Handle(); 1839 Smi& smi = Smi::Handle();
1905 smi ^= Api::UnwrapHandle(smi_result); 1840 smi ^= Api::UnwrapHandle(smi_result);
1906 uint8_t* buffer; 1841 uint8_t* buffer;
1907 MessageWriter writer(&buffer, &zone_allocator, false); 1842 MessageWriter writer(&buffer, &zone_allocator, false);
1908 writer.WriteMessage(smi); 1843 writer.WriteMessage(smi);
1909 intptr_t buffer_len = writer.BytesWritten(); 1844 intptr_t buffer_len = writer.BytesWritten();
1910 1845
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 1917
1983 TestCase::CreateTestIsolate(); 1918 TestCase::CreateTestIsolate();
1984 Isolate* isolate = Isolate::Current(); 1919 Isolate* isolate = Isolate::Current();
1985 EXPECT(isolate != NULL); 1920 EXPECT(isolate != NULL);
1986 Dart_EnterScope(); 1921 Dart_EnterScope();
1987 1922
1988 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1923 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1989 EXPECT_VALID(lib); 1924 EXPECT_VALID(lib);
1990 1925
1991 { 1926 {
1992 DARTSCOPE(isolate); 1927 DARTSCOPE(Thread::Current());
1993 StackZone zone(isolate); 1928 StackZone zone(isolate);
1994 intptr_t buf_len = 0; 1929 intptr_t buf_len = 0;
1995 { 1930 {
1996 // Generate a list of nulls from Dart code. 1931 // Generate a list of nulls from Dart code.
1997 uint8_t* buf = GetSerialized(lib, "getList", &buf_len); 1932 uint8_t* buf = GetSerialized(lib, "getList", &buf_len);
1998 ApiNativeScope scope; 1933 ApiNativeScope scope;
1999 Dart_CObject* root = GetDeserialized(buf, buf_len); 1934 Dart_CObject* root = GetDeserialized(buf, buf_len);
2000 EXPECT_NOTNULL(root); 1935 EXPECT_NOTNULL(root);
2001 EXPECT_EQ(Dart_CObject_kArray, root->type); 1936 EXPECT_EQ(Dart_CObject_kArray, root->type);
2002 EXPECT_EQ(kArrayLength, root->value.as_array.length); 1937 EXPECT_EQ(kArrayLength, root->value.as_array.length);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 2041
2107 TestCase::CreateTestIsolate(); 2042 TestCase::CreateTestIsolate();
2108 Isolate* isolate = Isolate::Current(); 2043 Isolate* isolate = Isolate::Current();
2109 EXPECT(isolate != NULL); 2044 EXPECT(isolate != NULL);
2110 Dart_EnterScope(); 2045 Dart_EnterScope();
2111 2046
2112 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2047 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2113 EXPECT_VALID(lib); 2048 EXPECT_VALID(lib);
2114 2049
2115 { 2050 {
2116 DARTSCOPE(isolate); 2051 DARTSCOPE(Thread::Current());
2117 StackZone zone(isolate); 2052 StackZone zone(isolate);
2118 intptr_t buf_len = 0; 2053 intptr_t buf_len = 0;
2119 { 2054 {
2120 // Generate a list of nulls from Dart code. 2055 // Generate a list of nulls from Dart code.
2121 uint8_t* buf = GetSerialized(lib, "getList", &buf_len); 2056 uint8_t* buf = GetSerialized(lib, "getList", &buf_len);
2122 ApiNativeScope scope; 2057 ApiNativeScope scope;
2123 Dart_CObject* root = GetDeserialized(buf, buf_len); 2058 Dart_CObject* root = GetDeserialized(buf, buf_len);
2124 EXPECT_NOTNULL(root); 2059 EXPECT_NOTNULL(root);
2125 EXPECT_EQ(Dart_CObject_kArray, root->type); 2060 EXPECT_EQ(Dart_CObject_kArray, root->type);
2126 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2061 EXPECT_EQ(kArrayLength, root->value.as_array.length);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 2280
2346 TestCase::CreateTestIsolate(); 2281 TestCase::CreateTestIsolate();
2347 Isolate* isolate = Isolate::Current(); 2282 Isolate* isolate = Isolate::Current();
2348 EXPECT(isolate != NULL); 2283 EXPECT(isolate != NULL);
2349 Dart_EnterScope(); 2284 Dart_EnterScope();
2350 2285
2351 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2286 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2352 EXPECT_VALID(lib); 2287 EXPECT_VALID(lib);
2353 2288
2354 { 2289 {
2355 DARTSCOPE(isolate); 2290 DARTSCOPE(Thread::Current());
2356 StackZone zone(isolate); 2291 StackZone zone(isolate);
2357 intptr_t buf_len = 0; 2292 intptr_t buf_len = 0;
2358 { 2293 {
2359 // Generate a list of strings from Dart code. 2294 // Generate a list of strings from Dart code.
2360 uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len); 2295 uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len);
2361 ApiNativeScope scope; 2296 ApiNativeScope scope;
2362 Dart_CObject* root = GetDeserialized(buf, buf_len); 2297 Dart_CObject* root = GetDeserialized(buf, buf_len);
2363 EXPECT_NOTNULL(root); 2298 EXPECT_NOTNULL(root);
2364 EXPECT_EQ(Dart_CObject_kArray, root->type); 2299 EXPECT_EQ(Dart_CObject_kArray, root->type);
2365 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2300 EXPECT_EQ(kArrayLength, root->value.as_array.length);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
2570 2505
2571 TestCase::CreateTestIsolate(); 2506 TestCase::CreateTestIsolate();
2572 Isolate* isolate = Isolate::Current(); 2507 Isolate* isolate = Isolate::Current();
2573 EXPECT(isolate != NULL); 2508 EXPECT(isolate != NULL);
2574 Dart_EnterScope(); 2509 Dart_EnterScope();
2575 2510
2576 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2511 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2577 EXPECT_VALID(lib); 2512 EXPECT_VALID(lib);
2578 2513
2579 { 2514 {
2580 DARTSCOPE(isolate); 2515 DARTSCOPE(Thread::Current());
2581 StackZone zone(isolate); 2516 StackZone zone(isolate);
2582 intptr_t buf_len = 0; 2517 intptr_t buf_len = 0;
2583 { 2518 {
2584 // Generate a list of strings from Dart code. 2519 // Generate a list of strings from Dart code.
2585 uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len); 2520 uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len);
2586 ApiNativeScope scope; 2521 ApiNativeScope scope;
2587 Dart_CObject* root = GetDeserialized(buf, buf_len); 2522 Dart_CObject* root = GetDeserialized(buf, buf_len);
2588 EXPECT_NOTNULL(root); 2523 EXPECT_NOTNULL(root);
2589 EXPECT_EQ(Dart_CObject_kArray, root->type); 2524 EXPECT_EQ(Dart_CObject_kArray, root->type);
2590 EXPECT_EQ(kArrayLength, root->value.as_array.length); 2525 EXPECT_EQ(kArrayLength, root->value.as_array.length);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2811 2746
2812 TestCase::CreateTestIsolate(); 2747 TestCase::CreateTestIsolate();
2813 Isolate* isolate = Isolate::Current(); 2748 Isolate* isolate = Isolate::Current();
2814 EXPECT(isolate != NULL); 2749 EXPECT(isolate != NULL);
2815 Dart_EnterScope(); 2750 Dart_EnterScope();
2816 2751
2817 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2752 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2818 EXPECT_VALID(lib); 2753 EXPECT_VALID(lib);
2819 2754
2820 { 2755 {
2821 DARTSCOPE(isolate); 2756 DARTSCOPE(Thread::Current());
2822 StackZone zone(isolate); 2757 StackZone zone(isolate);
2823 intptr_t buf_len = 0; 2758 intptr_t buf_len = 0;
2824 { 2759 {
2825 // Generate a list of Uint8Lists from Dart code. 2760 // Generate a list of Uint8Lists from Dart code.
2826 uint8_t* buf = GetSerialized(lib, "getTypedDataList", &buf_len); 2761 uint8_t* buf = GetSerialized(lib, "getTypedDataList", &buf_len);
2827 ApiNativeScope scope; 2762 ApiNativeScope scope;
2828 Dart_CObject* root = GetDeserialized(buf, buf_len); 2763 Dart_CObject* root = GetDeserialized(buf, buf_len);
2829 EXPECT_NOTNULL(root); 2764 EXPECT_NOTNULL(root);
2830 EXPECT_EQ(Dart_CObject_kArray, root->type); 2765 EXPECT_EQ(Dart_CObject_kArray, root->type);
2831 struct { 2766 struct {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
3054 StackZone zone(Thread::Current()); 2989 StackZone zone(Thread::Current());
3055 uint8_t* buffer; 2990 uint8_t* buffer;
3056 MessageWriter writer(&buffer, &zone_allocator, true); 2991 MessageWriter writer(&buffer, &zone_allocator, true);
3057 writer.WriteInlinedObjectHeader(kOmittedObjectId); 2992 writer.WriteInlinedObjectHeader(kOmittedObjectId);
3058 // For performance, we'd like single-byte headers when ids are omitted. 2993 // For performance, we'd like single-byte headers when ids are omitted.
3059 // If this starts failing, consider renumbering the snapshot ids. 2994 // If this starts failing, consider renumbering the snapshot ids.
3060 EXPECT_EQ(1, writer.BytesWritten()); 2995 EXPECT_EQ(1, writer.BytesWritten());
3061 } 2996 }
3062 2997
3063 } // namespace dart 2998 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/snapshot.cc ('k') | runtime/vm/thread_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698