OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 151 |
152 // Write snapshot with object content. | 152 // Write snapshot with object content. |
153 uint8_t* buffer; | 153 uint8_t* buffer; |
154 MessageWriter writer(&buffer, &zone_allocator, true); | 154 MessageWriter writer(&buffer, &zone_allocator, true); |
155 const Object& null_object = Object::Handle(); | 155 const Object& null_object = Object::Handle(); |
156 writer.WriteMessage(null_object); | 156 writer.WriteMessage(null_object); |
157 intptr_t buffer_len = writer.BytesWritten(); | 157 intptr_t buffer_len = writer.BytesWritten(); |
158 | 158 |
159 // Read object back from the snapshot. | 159 // Read object back from the snapshot. |
160 SnapshotReader reader(buffer, buffer_len, | 160 SnapshotReader reader(buffer, buffer_len, |
161 Snapshot::kMessage, Isolate::Current()); | 161 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); |
162 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 162 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
163 EXPECT(Equals(null_object, serialized_object)); | 163 EXPECT(Equals(null_object, serialized_object)); |
164 | 164 |
165 // Read object back from the snapshot into a C structure. | 165 // Read object back from the snapshot into a C structure. |
166 ApiNativeScope scope; | 166 ApiNativeScope scope; |
167 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 167 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
168 Dart_CObject* root = api_reader.ReadMessage(); | 168 Dart_CObject* root = api_reader.ReadMessage(); |
169 EXPECT_NOTNULL(root); | 169 EXPECT_NOTNULL(root); |
170 EXPECT_EQ(Dart_CObject_kNull, root->type); | 170 EXPECT_EQ(Dart_CObject_kNull, root->type); |
171 CheckEncodeDecodeMessage(root); | 171 CheckEncodeDecodeMessage(root); |
172 } | 172 } |
173 | 173 |
174 | 174 |
175 TEST_CASE(SerializeSmi1) { | 175 TEST_CASE(SerializeSmi1) { |
176 StackZone zone(Isolate::Current()); | 176 StackZone zone(Isolate::Current()); |
177 | 177 |
178 // Write snapshot with object content. | 178 // Write snapshot with object content. |
179 uint8_t* buffer; | 179 uint8_t* buffer; |
180 MessageWriter writer(&buffer, &zone_allocator, true); | 180 MessageWriter writer(&buffer, &zone_allocator, true); |
181 const Smi& smi = Smi::Handle(Smi::New(124)); | 181 const Smi& smi = Smi::Handle(Smi::New(124)); |
182 writer.WriteMessage(smi); | 182 writer.WriteMessage(smi); |
183 intptr_t buffer_len = writer.BytesWritten(); | 183 intptr_t buffer_len = writer.BytesWritten(); |
184 | 184 |
185 // Read object back from the snapshot. | 185 // Read object back from the snapshot. |
186 SnapshotReader reader(buffer, buffer_len, | 186 SnapshotReader reader(buffer, buffer_len, |
187 Snapshot::kMessage, Isolate::Current()); | 187 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); |
188 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 188 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
189 EXPECT(Equals(smi, serialized_object)); | 189 EXPECT(Equals(smi, serialized_object)); |
190 | 190 |
191 // Read object back from the snapshot into a C structure. | 191 // Read object back from the snapshot into a C structure. |
192 ApiNativeScope scope; | 192 ApiNativeScope scope; |
193 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 193 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
194 Dart_CObject* root = api_reader.ReadMessage(); | 194 Dart_CObject* root = api_reader.ReadMessage(); |
195 EXPECT_NOTNULL(root); | 195 EXPECT_NOTNULL(root); |
196 EXPECT_EQ(Dart_CObject_kInt32, root->type); | 196 EXPECT_EQ(Dart_CObject_kInt32, root->type); |
197 EXPECT_EQ(smi.Value(), root->value.as_int32); | 197 EXPECT_EQ(smi.Value(), root->value.as_int32); |
198 CheckEncodeDecodeMessage(root); | 198 CheckEncodeDecodeMessage(root); |
199 } | 199 } |
200 | 200 |
201 | 201 |
202 TEST_CASE(SerializeSmi2) { | 202 TEST_CASE(SerializeSmi2) { |
203 StackZone zone(Isolate::Current()); | 203 StackZone zone(Isolate::Current()); |
204 | 204 |
205 // Write snapshot with object content. | 205 // Write snapshot with object content. |
206 uint8_t* buffer; | 206 uint8_t* buffer; |
207 MessageWriter writer(&buffer, &zone_allocator, true); | 207 MessageWriter writer(&buffer, &zone_allocator, true); |
208 const Smi& smi = Smi::Handle(Smi::New(-1)); | 208 const Smi& smi = Smi::Handle(Smi::New(-1)); |
209 writer.WriteMessage(smi); | 209 writer.WriteMessage(smi); |
210 intptr_t buffer_len = writer.BytesWritten(); | 210 intptr_t buffer_len = writer.BytesWritten(); |
211 | 211 |
212 // Read object back from the snapshot. | 212 // Read object back from the snapshot. |
213 SnapshotReader reader(buffer, buffer_len, | 213 SnapshotReader reader(buffer, buffer_len, |
214 Snapshot::kMessage, Isolate::Current()); | 214 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); |
215 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 215 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
216 EXPECT(Equals(smi, serialized_object)); | 216 EXPECT(Equals(smi, serialized_object)); |
217 | 217 |
218 // Read object back from the snapshot into a C structure. | 218 // Read object back from the snapshot into a C structure. |
219 ApiNativeScope scope; | 219 ApiNativeScope scope; |
220 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 220 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
221 Dart_CObject* root = api_reader.ReadMessage(); | 221 Dart_CObject* root = api_reader.ReadMessage(); |
222 EXPECT_NOTNULL(root); | 222 EXPECT_NOTNULL(root); |
223 EXPECT_EQ(Dart_CObject_kInt32, root->type); | 223 EXPECT_EQ(Dart_CObject_kInt32, root->type); |
224 EXPECT_EQ(smi.Value(), root->value.as_int32); | 224 EXPECT_EQ(smi.Value(), root->value.as_int32); |
225 CheckEncodeDecodeMessage(root); | 225 CheckEncodeDecodeMessage(root); |
226 } | 226 } |
227 | 227 |
228 | 228 |
229 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) { | 229 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) { |
230 // Write snapshot with object content. | 230 // Write snapshot with object content. |
231 uint8_t* buffer; | 231 uint8_t* buffer; |
232 MessageWriter writer(&buffer, &zone_allocator, true); | 232 MessageWriter writer(&buffer, &zone_allocator, true); |
233 writer.WriteMessage(mint); | 233 writer.WriteMessage(mint); |
234 intptr_t buffer_len = writer.BytesWritten(); | 234 intptr_t buffer_len = writer.BytesWritten(); |
235 | 235 |
236 // Read object back from the snapshot. | 236 // Read object back from the snapshot. |
237 SnapshotReader reader(buffer, buffer_len, | 237 SnapshotReader reader(buffer, buffer_len, |
238 Snapshot::kMessage, Isolate::Current()); | 238 Snapshot::kMessage, Isolate::Current(), |
| 239 Thread::Current()->zone()); |
239 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 240 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
240 EXPECT(serialized_object.IsMint()); | 241 EXPECT(serialized_object.IsMint()); |
241 | 242 |
242 // Read object back from the snapshot into a C structure. | 243 // Read object back from the snapshot into a C structure. |
243 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 244 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
244 Dart_CObject* root = api_reader.ReadMessage(); | 245 Dart_CObject* root = api_reader.ReadMessage(); |
245 EXPECT_NOTNULL(root); | 246 EXPECT_NOTNULL(root); |
246 CheckEncodeDecodeMessage(root); | 247 CheckEncodeDecodeMessage(root); |
247 return root; | 248 return root; |
248 } | 249 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 | 300 |
300 // Write snapshot with object content. | 301 // Write snapshot with object content. |
301 uint8_t* buffer; | 302 uint8_t* buffer; |
302 MessageWriter writer(&buffer, &zone_allocator, true); | 303 MessageWriter writer(&buffer, &zone_allocator, true); |
303 const Double& dbl = Double::Handle(Double::New(101.29)); | 304 const Double& dbl = Double::Handle(Double::New(101.29)); |
304 writer.WriteMessage(dbl); | 305 writer.WriteMessage(dbl); |
305 intptr_t buffer_len = writer.BytesWritten(); | 306 intptr_t buffer_len = writer.BytesWritten(); |
306 | 307 |
307 // Read object back from the snapshot. | 308 // Read object back from the snapshot. |
308 SnapshotReader reader(buffer, buffer_len, | 309 SnapshotReader reader(buffer, buffer_len, |
309 Snapshot::kMessage, Isolate::Current()); | 310 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); |
310 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 311 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
311 EXPECT(Equals(dbl, serialized_object)); | 312 EXPECT(Equals(dbl, serialized_object)); |
312 | 313 |
313 // Read object back from the snapshot into a C structure. | 314 // Read object back from the snapshot into a C structure. |
314 ApiNativeScope scope; | 315 ApiNativeScope scope; |
315 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 316 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
316 Dart_CObject* root = api_reader.ReadMessage(); | 317 Dart_CObject* root = api_reader.ReadMessage(); |
317 EXPECT_NOTNULL(root); | 318 EXPECT_NOTNULL(root); |
318 EXPECT_EQ(Dart_CObject_kDouble, root->type); | 319 EXPECT_EQ(Dart_CObject_kDouble, root->type); |
319 EXPECT_EQ(dbl.value(), root->value.as_double); | 320 EXPECT_EQ(dbl.value(), root->value.as_double); |
320 CheckEncodeDecodeMessage(root); | 321 CheckEncodeDecodeMessage(root); |
321 } | 322 } |
322 | 323 |
323 | 324 |
324 TEST_CASE(SerializeTrue) { | 325 TEST_CASE(SerializeTrue) { |
325 StackZone zone(Isolate::Current()); | 326 StackZone zone(Isolate::Current()); |
326 | 327 |
327 // Write snapshot with true object. | 328 // Write snapshot with true object. |
328 uint8_t* buffer; | 329 uint8_t* buffer; |
329 MessageWriter writer(&buffer, &zone_allocator, true); | 330 MessageWriter writer(&buffer, &zone_allocator, true); |
330 const Bool& bl = Bool::True(); | 331 const Bool& bl = Bool::True(); |
331 writer.WriteMessage(bl); | 332 writer.WriteMessage(bl); |
332 intptr_t buffer_len = writer.BytesWritten(); | 333 intptr_t buffer_len = writer.BytesWritten(); |
333 | 334 |
334 // Read object back from the snapshot. | 335 // Read object back from the snapshot. |
335 SnapshotReader reader(buffer, buffer_len, | 336 SnapshotReader reader(buffer, buffer_len, |
336 Snapshot::kMessage, Isolate::Current()); | 337 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); |
337 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 338 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
338 fprintf(stderr, "%s / %s\n", bl.ToCString(), serialized_object.ToCString()); | 339 fprintf(stderr, "%s / %s\n", bl.ToCString(), serialized_object.ToCString()); |
339 | 340 |
340 EXPECT(Equals(bl, serialized_object)); | 341 EXPECT(Equals(bl, serialized_object)); |
341 | 342 |
342 // Read object back from the snapshot into a C structure. | 343 // Read object back from the snapshot into a C structure. |
343 ApiNativeScope scope; | 344 ApiNativeScope scope; |
344 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 345 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
345 Dart_CObject* root = api_reader.ReadMessage(); | 346 Dart_CObject* root = api_reader.ReadMessage(); |
346 EXPECT_NOTNULL(root); | 347 EXPECT_NOTNULL(root); |
347 EXPECT_EQ(Dart_CObject_kBool, root->type); | 348 EXPECT_EQ(Dart_CObject_kBool, root->type); |
348 EXPECT_EQ(true, root->value.as_bool); | 349 EXPECT_EQ(true, root->value.as_bool); |
349 CheckEncodeDecodeMessage(root); | 350 CheckEncodeDecodeMessage(root); |
350 } | 351 } |
351 | 352 |
352 | 353 |
353 TEST_CASE(SerializeFalse) { | 354 TEST_CASE(SerializeFalse) { |
354 StackZone zone(Isolate::Current()); | 355 StackZone zone(Isolate::Current()); |
355 | 356 |
356 // Write snapshot with false object. | 357 // Write snapshot with false object. |
357 uint8_t* buffer; | 358 uint8_t* buffer; |
358 MessageWriter writer(&buffer, &zone_allocator, true); | 359 MessageWriter writer(&buffer, &zone_allocator, true); |
359 const Bool& bl = Bool::False(); | 360 const Bool& bl = Bool::False(); |
360 writer.WriteMessage(bl); | 361 writer.WriteMessage(bl); |
361 intptr_t buffer_len = writer.BytesWritten(); | 362 intptr_t buffer_len = writer.BytesWritten(); |
362 | 363 |
363 // Read object back from the snapshot. | 364 // Read object back from the snapshot. |
364 SnapshotReader reader(buffer, buffer_len, | 365 SnapshotReader reader(buffer, buffer_len, |
365 Snapshot::kMessage, Isolate::Current()); | 366 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); |
366 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 367 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
367 EXPECT(Equals(bl, serialized_object)); | 368 EXPECT(Equals(bl, serialized_object)); |
368 | 369 |
369 // Read object back from the snapshot into a C structure. | 370 // Read object back from the snapshot into a C structure. |
370 ApiNativeScope scope; | 371 ApiNativeScope scope; |
371 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 372 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
372 Dart_CObject* root = api_reader.ReadMessage(); | 373 Dart_CObject* root = api_reader.ReadMessage(); |
373 EXPECT_NOTNULL(root); | 374 EXPECT_NOTNULL(root); |
374 EXPECT_EQ(Dart_CObject_kBool, root->type); | 375 EXPECT_EQ(Dart_CObject_kBool, root->type); |
375 EXPECT_EQ(false, root->value.as_bool); | 376 EXPECT_EQ(false, root->value.as_bool); |
(...skipping 14 matching lines...) Expand all Loading... |
390 MessageWriter writer(&buffer, &zone_allocator, true); | 391 MessageWriter writer(&buffer, &zone_allocator, true); |
391 const char* cstr = "0x270FFFFFFFFFFFFFD8F0"; | 392 const char* cstr = "0x270FFFFFFFFFFFFFD8F0"; |
392 const String& str = String::Handle(String::New(cstr)); | 393 const String& str = String::Handle(String::New(cstr)); |
393 Bigint& bigint = Bigint::Handle(); | 394 Bigint& bigint = Bigint::Handle(); |
394 bigint ^= Integer::NewCanonical(str); | 395 bigint ^= Integer::NewCanonical(str); |
395 writer.WriteMessage(bigint); | 396 writer.WriteMessage(bigint); |
396 intptr_t buffer_len = writer.BytesWritten(); | 397 intptr_t buffer_len = writer.BytesWritten(); |
397 | 398 |
398 // Read object back from the snapshot. | 399 // Read object back from the snapshot. |
399 SnapshotReader reader(buffer, buffer_len, | 400 SnapshotReader reader(buffer, buffer_len, |
400 Snapshot::kMessage, Isolate::Current()); | 401 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); |
401 Bigint& obj = Bigint::Handle(); | 402 Bigint& obj = Bigint::Handle(); |
402 obj ^= reader.ReadObject(); | 403 obj ^= reader.ReadObject(); |
403 | 404 |
404 EXPECT_STREQ(bigint.ToHexCString(allocator), obj.ToHexCString(allocator)); | 405 EXPECT_STREQ(bigint.ToHexCString(allocator), obj.ToHexCString(allocator)); |
405 | 406 |
406 // Read object back from the snapshot into a C structure. | 407 // Read object back from the snapshot into a C structure. |
407 ApiNativeScope scope; | 408 ApiNativeScope scope; |
408 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 409 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
409 Dart_CObject* root = api_reader.ReadMessage(); | 410 Dart_CObject* root = api_reader.ReadMessage(); |
410 EXPECT_NOTNULL(root); | 411 EXPECT_NOTNULL(root); |
411 EXPECT_EQ(Dart_CObject_kBigint, root->type); | 412 EXPECT_EQ(Dart_CObject_kBigint, root->type); |
412 char* hex_value = TestCase::BigintToHexValue(root); | 413 char* hex_value = TestCase::BigintToHexValue(root); |
413 EXPECT_STREQ(cstr, hex_value); | 414 EXPECT_STREQ(cstr, hex_value); |
414 free(hex_value); | 415 free(hex_value); |
415 CheckEncodeDecodeMessage(root); | 416 CheckEncodeDecodeMessage(root); |
416 } | 417 } |
417 | 418 |
418 | 419 |
419 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { | 420 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { |
420 // Write snapshot with object content. | 421 // Write snapshot with object content. |
421 uint8_t* buffer; | 422 uint8_t* buffer; |
422 MessageWriter writer(&buffer, &zone_allocator, true); | 423 MessageWriter writer(&buffer, &zone_allocator, true); |
423 writer.WriteMessage(bigint); | 424 writer.WriteMessage(bigint); |
424 intptr_t buffer_len = writer.BytesWritten(); | 425 intptr_t buffer_len = writer.BytesWritten(); |
425 | 426 |
426 // Read object back from the snapshot. | 427 // Read object back from the snapshot. |
427 SnapshotReader reader(buffer, buffer_len, | 428 SnapshotReader reader(buffer, buffer_len, |
428 Snapshot::kMessage, Isolate::Current()); | 429 Snapshot::kMessage, Isolate::Current(), |
| 430 Thread::Current()->zone()); |
429 Bigint& serialized_bigint = Bigint::Handle(); | 431 Bigint& serialized_bigint = Bigint::Handle(); |
430 serialized_bigint ^= reader.ReadObject(); | 432 serialized_bigint ^= reader.ReadObject(); |
431 const char* str1 = bigint.ToHexCString(allocator); | 433 const char* str1 = bigint.ToHexCString(allocator); |
432 const char* str2 = serialized_bigint.ToHexCString(allocator); | 434 const char* str2 = serialized_bigint.ToHexCString(allocator); |
433 EXPECT_STREQ(str1, str2); | 435 EXPECT_STREQ(str1, str2); |
434 free(const_cast<char*>(str1)); | 436 free(const_cast<char*>(str1)); |
435 free(const_cast<char*>(str2)); | 437 free(const_cast<char*>(str2)); |
436 | 438 |
437 // Read object back from the snapshot into a C structure. | 439 // Read object back from the snapshot into a C structure. |
438 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 440 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 writer.WriteObject(Object::code_class()); | 484 writer.WriteObject(Object::code_class()); |
483 writer.WriteObject(Object::instructions_class()); | 485 writer.WriteObject(Object::instructions_class()); |
484 writer.WriteObject(Object::pc_descriptors_class()); | 486 writer.WriteObject(Object::pc_descriptors_class()); |
485 writer.WriteObject(Object::exception_handlers_class()); | 487 writer.WriteObject(Object::exception_handlers_class()); |
486 writer.WriteObject(Object::context_class()); | 488 writer.WriteObject(Object::context_class()); |
487 writer.WriteObject(Object::context_scope_class()); | 489 writer.WriteObject(Object::context_scope_class()); |
488 intptr_t buffer_len = writer.BytesWritten(); | 490 intptr_t buffer_len = writer.BytesWritten(); |
489 | 491 |
490 // Read object back from the snapshot. | 492 // Read object back from the snapshot. |
491 SnapshotReader reader(buffer, buffer_len, Snapshot::kMessage, | 493 SnapshotReader reader(buffer, buffer_len, Snapshot::kMessage, |
492 Isolate::Current()); | 494 Isolate::Current(), Thread::Current()->zone()); |
493 EXPECT(Object::class_class() == reader.ReadObject()); | 495 EXPECT(Object::class_class() == reader.ReadObject()); |
494 EXPECT(Object::type_arguments_class() == reader.ReadObject()); | 496 EXPECT(Object::type_arguments_class() == reader.ReadObject()); |
495 EXPECT(Object::function_class() == reader.ReadObject()); | 497 EXPECT(Object::function_class() == reader.ReadObject()); |
496 EXPECT(Object::field_class() == reader.ReadObject()); | 498 EXPECT(Object::field_class() == reader.ReadObject()); |
497 EXPECT(Object::token_stream_class() == reader.ReadObject()); | 499 EXPECT(Object::token_stream_class() == reader.ReadObject()); |
498 EXPECT(Object::script_class() == reader.ReadObject()); | 500 EXPECT(Object::script_class() == reader.ReadObject()); |
499 EXPECT(Object::library_class() == reader.ReadObject()); | 501 EXPECT(Object::library_class() == reader.ReadObject()); |
500 EXPECT(Object::code_class() == reader.ReadObject()); | 502 EXPECT(Object::code_class() == reader.ReadObject()); |
501 EXPECT(Object::instructions_class() == reader.ReadObject()); | 503 EXPECT(Object::instructions_class() == reader.ReadObject()); |
502 EXPECT(Object::pc_descriptors_class() == reader.ReadObject()); | 504 EXPECT(Object::pc_descriptors_class() == reader.ReadObject()); |
(...skipping 10 matching lines...) Expand all Loading... |
513 EXPECT(Utf8::IsValid(reinterpret_cast<const uint8_t*>(cstr), strlen(cstr))); | 515 EXPECT(Utf8::IsValid(reinterpret_cast<const uint8_t*>(cstr), strlen(cstr))); |
514 // Write snapshot with object content. | 516 // Write snapshot with object content. |
515 uint8_t* buffer; | 517 uint8_t* buffer; |
516 MessageWriter writer(&buffer, &zone_allocator, true); | 518 MessageWriter writer(&buffer, &zone_allocator, true); |
517 String& str = String::Handle(String::New(cstr)); | 519 String& str = String::Handle(String::New(cstr)); |
518 writer.WriteMessage(str); | 520 writer.WriteMessage(str); |
519 intptr_t buffer_len = writer.BytesWritten(); | 521 intptr_t buffer_len = writer.BytesWritten(); |
520 | 522 |
521 // Read object back from the snapshot. | 523 // Read object back from the snapshot. |
522 SnapshotReader reader(buffer, buffer_len, | 524 SnapshotReader reader(buffer, buffer_len, |
523 Snapshot::kMessage, Isolate::Current()); | 525 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); |
524 String& serialized_str = String::Handle(); | 526 String& serialized_str = String::Handle(); |
525 serialized_str ^= reader.ReadObject(); | 527 serialized_str ^= reader.ReadObject(); |
526 EXPECT(str.Equals(serialized_str)); | 528 EXPECT(str.Equals(serialized_str)); |
527 | 529 |
528 // Read object back from the snapshot into a C structure. | 530 // Read object back from the snapshot into a C structure. |
529 ApiNativeScope scope; | 531 ApiNativeScope scope; |
530 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 532 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
531 Dart_CObject* root = api_reader.ReadMessage(); | 533 Dart_CObject* root = api_reader.ReadMessage(); |
532 EXPECT_EQ(Dart_CObject_kString, root->type); | 534 EXPECT_EQ(Dart_CObject_kString, root->type); |
533 EXPECT_STREQ(cstr, root->value.as_string); | 535 EXPECT_STREQ(cstr, root->value.as_string); |
(...skipping 27 matching lines...) Expand all Loading... |
561 Smi& smi = Smi::Handle(); | 563 Smi& smi = Smi::Handle(); |
562 for (int i = 0; i < kArrayLength; i++) { | 564 for (int i = 0; i < kArrayLength; i++) { |
563 smi ^= Smi::New(i); | 565 smi ^= Smi::New(i); |
564 array.SetAt(i, smi); | 566 array.SetAt(i, smi); |
565 } | 567 } |
566 writer.WriteMessage(array); | 568 writer.WriteMessage(array); |
567 intptr_t buffer_len = writer.BytesWritten(); | 569 intptr_t buffer_len = writer.BytesWritten(); |
568 | 570 |
569 // Read object back from the snapshot. | 571 // Read object back from the snapshot. |
570 SnapshotReader reader(buffer, buffer_len, | 572 SnapshotReader reader(buffer, buffer_len, |
571 Snapshot::kMessage, Isolate::Current()); | 573 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); |
572 Array& serialized_array = Array::Handle(); | 574 Array& serialized_array = Array::Handle(); |
573 serialized_array ^= reader.ReadObject(); | 575 serialized_array ^= reader.ReadObject(); |
574 EXPECT(array.CanonicalizeEquals(serialized_array)); | 576 EXPECT(array.CanonicalizeEquals(serialized_array)); |
575 | 577 |
576 // Read object back from the snapshot into a C structure. | 578 // Read object back from the snapshot into a C structure. |
577 ApiNativeScope scope; | 579 ApiNativeScope scope; |
578 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 580 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
579 Dart_CObject* root = api_reader.ReadMessage(); | 581 Dart_CObject* root = api_reader.ReadMessage(); |
580 EXPECT_EQ(Dart_CObject_kArray, root->type); | 582 EXPECT_EQ(Dart_CObject_kArray, root->type); |
581 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 583 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 // Write snapshot with object content. | 648 // Write snapshot with object content. |
647 uint8_t* buffer; | 649 uint8_t* buffer; |
648 MessageWriter writer(&buffer, &zone_allocator, true); | 650 MessageWriter writer(&buffer, &zone_allocator, true); |
649 const int kArrayLength = 0; | 651 const int kArrayLength = 0; |
650 Array& array = Array::Handle(Array::New(kArrayLength)); | 652 Array& array = Array::Handle(Array::New(kArrayLength)); |
651 writer.WriteMessage(array); | 653 writer.WriteMessage(array); |
652 intptr_t buffer_len = writer.BytesWritten(); | 654 intptr_t buffer_len = writer.BytesWritten(); |
653 | 655 |
654 // Read object back from the snapshot. | 656 // Read object back from the snapshot. |
655 SnapshotReader reader(buffer, buffer_len, | 657 SnapshotReader reader(buffer, buffer_len, |
656 Snapshot::kMessage, Isolate::Current()); | 658 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); |
657 Array& serialized_array = Array::Handle(); | 659 Array& serialized_array = Array::Handle(); |
658 serialized_array ^= reader.ReadObject(); | 660 serialized_array ^= reader.ReadObject(); |
659 EXPECT(array.CanonicalizeEquals(serialized_array)); | 661 EXPECT(array.CanonicalizeEquals(serialized_array)); |
660 | 662 |
661 // Read object back from the snapshot into a C structure. | 663 // Read object back from the snapshot into a C structure. |
662 ApiNativeScope scope; | 664 ApiNativeScope scope; |
663 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 665 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
664 Dart_CObject* root = api_reader.ReadMessage(); | 666 Dart_CObject* root = api_reader.ReadMessage(); |
665 EXPECT_EQ(Dart_CObject_kArray, root->type); | 667 EXPECT_EQ(Dart_CObject_kArray, root->type); |
666 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 668 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
(...skipping 12 matching lines...) Expand all Loading... |
679 TypedData& typed_data = TypedData::Handle( | 681 TypedData& typed_data = TypedData::Handle( |
680 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); | 682 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); |
681 for (int i = 0; i < kTypedDataLength; i++) { | 683 for (int i = 0; i < kTypedDataLength; i++) { |
682 typed_data.SetUint8(i, i); | 684 typed_data.SetUint8(i, i); |
683 } | 685 } |
684 writer.WriteMessage(typed_data); | 686 writer.WriteMessage(typed_data); |
685 intptr_t buffer_len = writer.BytesWritten(); | 687 intptr_t buffer_len = writer.BytesWritten(); |
686 | 688 |
687 // Read object back from the snapshot. | 689 // Read object back from the snapshot. |
688 SnapshotReader reader(buffer, buffer_len, | 690 SnapshotReader reader(buffer, buffer_len, |
689 Snapshot::kMessage, Isolate::Current()); | 691 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); |
690 TypedData& serialized_typed_data = TypedData::Handle(); | 692 TypedData& serialized_typed_data = TypedData::Handle(); |
691 serialized_typed_data ^= reader.ReadObject(); | 693 serialized_typed_data ^= reader.ReadObject(); |
692 EXPECT(serialized_typed_data.IsTypedData()); | 694 EXPECT(serialized_typed_data.IsTypedData()); |
693 | 695 |
694 // Read object back from the snapshot into a C structure. | 696 // Read object back from the snapshot into a C structure. |
695 ApiNativeScope scope; | 697 ApiNativeScope scope; |
696 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 698 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
697 Dart_CObject* root = api_reader.ReadMessage(); | 699 Dart_CObject* root = api_reader.ReadMessage(); |
698 EXPECT_EQ(Dart_CObject_kTypedData, root->type); | 700 EXPECT_EQ(Dart_CObject_kTypedData, root->type); |
699 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); | 701 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); |
(...skipping 12 matching lines...) Expand all Loading... |
712 const int kArrayLength = 127; \ | 714 const int kArrayLength = 127; \ |
713 TypedData& array = TypedData::Handle( \ | 715 TypedData& array = TypedData::Handle( \ |
714 TypedData::New(kTypedData##darttype##ArrayCid, kArrayLength)); \ | 716 TypedData::New(kTypedData##darttype##ArrayCid, kArrayLength)); \ |
715 intptr_t scale = array.ElementSizeInBytes(); \ | 717 intptr_t scale = array.ElementSizeInBytes(); \ |
716 for (int i = 0; i < kArrayLength; i++) { \ | 718 for (int i = 0; i < kArrayLength; i++) { \ |
717 array.Set##darttype((i * scale), i); \ | 719 array.Set##darttype((i * scale), i); \ |
718 } \ | 720 } \ |
719 writer.WriteMessage(array); \ | 721 writer.WriteMessage(array); \ |
720 intptr_t buffer_len = writer.BytesWritten(); \ | 722 intptr_t buffer_len = writer.BytesWritten(); \ |
721 SnapshotReader reader(buffer, buffer_len, \ | 723 SnapshotReader reader(buffer, buffer_len, \ |
722 Snapshot::kMessage, Isolate::Current()); \ | 724 Snapshot::kMessage, Isolate::Current(), \ |
| 725 zone.GetZone()); \ |
723 TypedData& serialized_array = TypedData::Handle(); \ | 726 TypedData& serialized_array = TypedData::Handle(); \ |
724 serialized_array ^= reader.ReadObject(); \ | 727 serialized_array ^= reader.ReadObject(); \ |
725 for (int i = 0; i < kArrayLength; i++) { \ | 728 for (int i = 0; i < kArrayLength; i++) { \ |
726 EXPECT_EQ(static_cast<ctype>(i), \ | 729 EXPECT_EQ(static_cast<ctype>(i), \ |
727 serialized_array.Get##darttype(i*scale)); \ | 730 serialized_array.Get##darttype(i*scale)); \ |
728 } \ | 731 } \ |
729 } | 732 } |
730 | 733 |
731 | 734 |
732 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \ | 735 #define TEST_EXTERNAL_TYPED_ARRAY(darttype, ctype) \ |
733 { \ | 736 { \ |
734 StackZone zone(Isolate::Current()); \ | 737 StackZone zone(Isolate::Current()); \ |
735 ctype data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; \ | 738 ctype data[] = { 0, 11, 22, 33, 44, 55, 66, 77 }; \ |
736 intptr_t length = ARRAY_SIZE(data); \ | 739 intptr_t length = ARRAY_SIZE(data); \ |
737 ExternalTypedData& array = ExternalTypedData::Handle( \ | 740 ExternalTypedData& array = ExternalTypedData::Handle( \ |
738 ExternalTypedData::New(kExternalTypedData##darttype##ArrayCid, \ | 741 ExternalTypedData::New(kExternalTypedData##darttype##ArrayCid, \ |
739 reinterpret_cast<uint8_t*>(data), length)); \ | 742 reinterpret_cast<uint8_t*>(data), length)); \ |
740 intptr_t scale = array.ElementSizeInBytes(); \ | 743 intptr_t scale = array.ElementSizeInBytes(); \ |
741 uint8_t* buffer; \ | 744 uint8_t* buffer; \ |
742 MessageWriter writer(&buffer, &zone_allocator, true); \ | 745 MessageWriter writer(&buffer, &zone_allocator, true); \ |
743 writer.WriteMessage(array); \ | 746 writer.WriteMessage(array); \ |
744 intptr_t buffer_len = writer.BytesWritten(); \ | 747 intptr_t buffer_len = writer.BytesWritten(); \ |
745 SnapshotReader reader(buffer, buffer_len, \ | 748 SnapshotReader reader(buffer, buffer_len, \ |
746 Snapshot::kMessage, Isolate::Current()); \ | 749 Snapshot::kMessage, Isolate::Current(), \ |
| 750 zone.GetZone()); \ |
747 TypedData& serialized_array = TypedData::Handle(); \ | 751 TypedData& serialized_array = TypedData::Handle(); \ |
748 serialized_array ^= reader.ReadObject(); \ | 752 serialized_array ^= reader.ReadObject(); \ |
749 for (int i = 0; i < length; i++) { \ | 753 for (int i = 0; i < length; i++) { \ |
750 EXPECT_EQ(static_cast<ctype>(data[i]), \ | 754 EXPECT_EQ(static_cast<ctype>(data[i]), \ |
751 serialized_array.Get##darttype(i*scale)); \ | 755 serialized_array.Get##darttype(i*scale)); \ |
752 } \ | 756 } \ |
753 } | 757 } |
754 | 758 |
755 | 759 |
756 TEST_CASE(SerializeTypedArray) { | 760 TEST_CASE(SerializeTypedArray) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 uint8_t* buffer; | 792 uint8_t* buffer; |
789 MessageWriter writer(&buffer, &zone_allocator, true); | 793 MessageWriter writer(&buffer, &zone_allocator, true); |
790 const int kTypedDataLength = 0; | 794 const int kTypedDataLength = 0; |
791 TypedData& typed_data = TypedData::Handle( | 795 TypedData& typed_data = TypedData::Handle( |
792 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); | 796 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); |
793 writer.WriteMessage(typed_data); | 797 writer.WriteMessage(typed_data); |
794 intptr_t buffer_len = writer.BytesWritten(); | 798 intptr_t buffer_len = writer.BytesWritten(); |
795 | 799 |
796 // Read object back from the snapshot. | 800 // Read object back from the snapshot. |
797 SnapshotReader reader(buffer, buffer_len, | 801 SnapshotReader reader(buffer, buffer_len, |
798 Snapshot::kMessage, Isolate::Current()); | 802 Snapshot::kMessage, Isolate::Current(), zone.GetZone()); |
799 TypedData& serialized_typed_data = TypedData::Handle(); | 803 TypedData& serialized_typed_data = TypedData::Handle(); |
800 serialized_typed_data ^= reader.ReadObject(); | 804 serialized_typed_data ^= reader.ReadObject(); |
801 EXPECT(serialized_typed_data.IsTypedData()); | 805 EXPECT(serialized_typed_data.IsTypedData()); |
802 | 806 |
803 // Read object back from the snapshot into a C structure. | 807 // Read object back from the snapshot into a C structure. |
804 ApiNativeScope scope; | 808 ApiNativeScope scope; |
805 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 809 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
806 Dart_CObject* root = api_reader.ReadMessage(); | 810 Dart_CObject* root = api_reader.ReadMessage(); |
807 EXPECT_EQ(Dart_CObject_kTypedData, root->type); | 811 EXPECT_EQ(Dart_CObject_kTypedData, root->type); |
808 EXPECT_EQ(Dart_TypedData_kUint8, root->value.as_typed_data.type); | 812 EXPECT_EQ(Dart_TypedData_kUint8, root->value.as_typed_data.type); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 lib.Register(); | 923 lib.Register(); |
920 EXPECT(CompilerTest::TestCompileScript(lib, script)); | 924 EXPECT(CompilerTest::TestCompileScript(lib, script)); |
921 | 925 |
922 // Write snapshot with script content. | 926 // Write snapshot with script content. |
923 uint8_t* buffer; | 927 uint8_t* buffer; |
924 TestSnapshotWriter writer(&buffer, &malloc_allocator); | 928 TestSnapshotWriter writer(&buffer, &malloc_allocator); |
925 writer.WriteScript(script); | 929 writer.WriteScript(script); |
926 | 930 |
927 // Read object back from the snapshot. | 931 // Read object back from the snapshot. |
928 SnapshotReader reader(buffer, writer.BytesWritten(), | 932 SnapshotReader reader(buffer, writer.BytesWritten(), |
929 Snapshot::kScript, Isolate::Current()); | 933 Snapshot::kScript, Isolate::Current(), |
| 934 Thread::Current()->zone()); |
930 Script& serialized_script = Script::Handle(); | 935 Script& serialized_script = Script::Handle(); |
931 serialized_script ^= reader.ReadObject(); | 936 serialized_script ^= reader.ReadObject(); |
932 | 937 |
933 // Check if the serialized script object matches the original script. | 938 // Check if the serialized script object matches the original script. |
934 String& expected_literal = String::Handle(); | 939 String& expected_literal = String::Handle(); |
935 String& actual_literal = String::Handle(); | 940 String& actual_literal = String::Handle(); |
936 String& str = String::Handle(); | 941 String& str = String::Handle(); |
937 str ^= serialized_script.url(); | 942 str ^= serialized_script.url(); |
938 EXPECT(url.Equals(str)); | 943 EXPECT(url.Equals(str)); |
939 | 944 |
(...skipping 1786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2726 StackZone zone(Isolate::Current()); | 2731 StackZone zone(Isolate::Current()); |
2727 uint8_t* buffer; | 2732 uint8_t* buffer; |
2728 MessageWriter writer(&buffer, &zone_allocator, true); | 2733 MessageWriter writer(&buffer, &zone_allocator, true); |
2729 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 2734 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
2730 // For performance, we'd like single-byte headers when ids are omitted. | 2735 // For performance, we'd like single-byte headers when ids are omitted. |
2731 // If this starts failing, consider renumbering the snapshot ids. | 2736 // If this starts failing, consider renumbering the snapshot ids. |
2732 EXPECT_EQ(1, writer.BytesWritten()); | 2737 EXPECT_EQ(1, writer.BytesWritten()); |
2733 } | 2738 } |
2734 | 2739 |
2735 } // namespace dart | 2740 } // namespace dart |
OLD | NEW |