| OLD | NEW |
| 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 partial_sink.WriteSpaceUsed(p_ser.CurrentAllocationAddress(NEW_SPACE), | 387 partial_sink.WriteSpaceUsed(p_ser.CurrentAllocationAddress(NEW_SPACE), |
| 388 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), | 388 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 389 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), | 389 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 390 p_ser.CurrentAllocationAddress(CODE_SPACE), | 390 p_ser.CurrentAllocationAddress(CODE_SPACE), |
| 391 p_ser.CurrentAllocationAddress(MAP_SPACE), | 391 p_ser.CurrentAllocationAddress(MAP_SPACE), |
| 392 p_ser.CurrentAllocationAddress(CELL_SPACE), | 392 p_ser.CurrentAllocationAddress(CELL_SPACE), |
| 393 p_ser.CurrentAllocationAddress(LO_SPACE)); | 393 p_ser.CurrentAllocationAddress(LO_SPACE)); |
| 394 } | 394 } |
| 395 | 395 |
| 396 | 396 |
| 397 DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { | 397 static void ReserveSpaceForPartialSnapshot(const char* file_name) { |
| 398 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 398 int file_name_length = StrLength(file_name) + 10; |
| 399 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | |
| 400 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | |
| 401 | |
| 402 CHECK(Snapshot::Initialize(startup_name.start())); | |
| 403 | |
| 404 const char* file_name = FLAG_testing_serialization_file; | |
| 405 Vector<char> name = Vector<char>::New(file_name_length + 1); | 399 Vector<char> name = Vector<char>::New(file_name_length + 1); |
| 406 OS::SNPrintF(name, "%s.size", file_name); | 400 OS::SNPrintF(name, "%s.size", file_name); |
| 407 FILE* fp = OS::FOpen(name.start(), "r"); | 401 FILE* fp = OS::FOpen(name.start(), "r"); |
| 408 int new_size, pointer_size, data_size, code_size, map_size, cell_size; | 402 int new_size, pointer_size, data_size, code_size, map_size, cell_size; |
| 409 int large_size; | 403 int large_size; |
| 410 #ifdef _MSC_VER | 404 #ifdef _MSC_VER |
| 411 // Avoid warning about unsafe fscanf from MSVC. | 405 // Avoid warning about unsafe fscanf from MSVC. |
| 412 // Please note that this is only fine if %c and %s are not being used. | 406 // Please note that this is only fine if %c and %s are not being used. |
| 413 #define fscanf fscanf_s | 407 #define fscanf fscanf_s |
| 414 #endif | 408 #endif |
| 415 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size)); | 409 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size)); |
| 416 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size)); | 410 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size)); |
| 417 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); | 411 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); |
| 418 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); | 412 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); |
| 419 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); | 413 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); |
| 420 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); | 414 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); |
| 421 CHECK_EQ(1, fscanf(fp, "large %d\n", &large_size)); | 415 CHECK_EQ(1, fscanf(fp, "large %d\n", &large_size)); |
| 422 #ifdef _MSC_VER | 416 #ifdef _MSC_VER |
| 423 #undef fscanf | 417 #undef fscanf |
| 424 #endif | 418 #endif |
| 425 fclose(fp); | 419 fclose(fp); |
| 426 Heap::ReserveSpace(new_size, | 420 Heap::ReserveSpace(new_size, |
| 427 pointer_size, | 421 pointer_size, |
| 428 data_size, | 422 data_size, |
| 429 code_size, | 423 code_size, |
| 430 map_size, | 424 map_size, |
| 431 cell_size, | 425 cell_size, |
| 432 large_size); | 426 large_size); |
| 427 } |
| 428 |
| 429 |
| 430 DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { |
| 431 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 432 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 433 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 434 |
| 435 CHECK(Snapshot::Initialize(startup_name.start())); |
| 436 |
| 437 const char* file_name = FLAG_testing_serialization_file; |
| 438 ReserveSpaceForPartialSnapshot(file_name); |
| 439 |
| 433 int snapshot_size = 0; | 440 int snapshot_size = 0; |
| 434 byte* snapshot = ReadBytes(file_name, &snapshot_size); | 441 byte* snapshot = ReadBytes(file_name, &snapshot_size); |
| 435 | 442 |
| 436 Object* root; | 443 Object* root; |
| 437 { | 444 { |
| 438 SnapshotByteSource source(snapshot, snapshot_size); | 445 SnapshotByteSource source(snapshot, snapshot_size); |
| 439 Deserializer deserializer(&source); | 446 Deserializer deserializer(&source); |
| 440 deserializer.DeserializePartial(&root); | 447 deserializer.DeserializePartial(&root); |
| 441 CHECK(root->IsString()); | 448 CHECK(root->IsString()); |
| 442 } | 449 } |
| 443 v8::HandleScope handle_scope; | 450 v8::HandleScope handle_scope; |
| 444 Handle<Object>root_handle(root); | 451 Handle<Object>root_handle(root); |
| 445 | 452 |
| 446 Object* root2; | 453 Object* root2; |
| 447 { | 454 { |
| 448 SnapshotByteSource source(snapshot, snapshot_size); | 455 SnapshotByteSource source(snapshot, snapshot_size); |
| 449 Deserializer deserializer(&source); | 456 Deserializer deserializer(&source); |
| 450 deserializer.DeserializePartial(&root2); | 457 deserializer.DeserializePartial(&root2); |
| 451 CHECK(root2->IsString()); | 458 CHECK(root2->IsString()); |
| 452 CHECK(*root_handle == root2); | 459 CHECK(*root_handle == root2); |
| 453 } | 460 } |
| 454 } | 461 } |
| 455 | 462 |
| 456 | 463 |
| 464 TEST(ContextSerialization) { |
| 465 Serializer::Enable(); |
| 466 v8::V8::Initialize(); |
| 467 |
| 468 v8::Persistent<v8::Context> env = v8::Context::New(); |
| 469 ASSERT(!env.IsEmpty()); |
| 470 env->Enter(); |
| 471 // Make sure all builtin scripts are cached. |
| 472 { HandleScope scope; |
| 473 for (int i = 0; i < Natives::GetBuiltinsCount(); i++) { |
| 474 Bootstrapper::NativesSourceLookup(i); |
| 475 } |
| 476 } |
| 477 // If we don't do this then we end up with a stray root pointing at the |
| 478 // context even after we have disposed of env. |
| 479 Heap::CollectAllGarbage(true); |
| 480 |
| 481 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 482 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 483 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 484 |
| 485 env->Exit(); |
| 486 |
| 487 Object* raw_context = *(v8::Utils::OpenHandle(*env)); |
| 488 |
| 489 env.Dispose(); |
| 490 |
| 491 FileByteSink startup_sink(startup_name.start()); |
| 492 StartupSerializer startup_serializer(&startup_sink); |
| 493 startup_serializer.SerializeStrongReferences(); |
| 494 |
| 495 FileByteSink partial_sink(FLAG_testing_serialization_file); |
| 496 PartialSerializer p_ser(&startup_serializer, &partial_sink); |
| 497 p_ser.Serialize(&raw_context); |
| 498 startup_serializer.SerializeWeakReferences(); |
| 499 partial_sink.WriteSpaceUsed(p_ser.CurrentAllocationAddress(NEW_SPACE), |
| 500 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 501 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 502 p_ser.CurrentAllocationAddress(CODE_SPACE), |
| 503 p_ser.CurrentAllocationAddress(MAP_SPACE), |
| 504 p_ser.CurrentAllocationAddress(CELL_SPACE), |
| 505 p_ser.CurrentAllocationAddress(LO_SPACE)); |
| 506 } |
| 507 |
| 508 |
| 509 DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { |
| 510 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 511 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 512 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 513 |
| 514 CHECK(Snapshot::Initialize(startup_name.start())); |
| 515 |
| 516 const char* file_name = FLAG_testing_serialization_file; |
| 517 ReserveSpaceForPartialSnapshot(file_name); |
| 518 |
| 519 int snapshot_size = 0; |
| 520 byte* snapshot = ReadBytes(file_name, &snapshot_size); |
| 521 |
| 522 Object* root; |
| 523 { |
| 524 SnapshotByteSource source(snapshot, snapshot_size); |
| 525 Deserializer deserializer(&source); |
| 526 deserializer.DeserializePartial(&root); |
| 527 CHECK(root->IsContext()); |
| 528 } |
| 529 v8::HandleScope handle_scope; |
| 530 Handle<Object>root_handle(root); |
| 531 |
| 532 Object* root2; |
| 533 { |
| 534 SnapshotByteSource source(snapshot, snapshot_size); |
| 535 Deserializer deserializer(&source); |
| 536 deserializer.DeserializePartial(&root2); |
| 537 CHECK(root2->IsContext()); |
| 538 CHECK(*root_handle != root2); |
| 539 } |
| 540 } |
| 541 |
| 542 |
| 457 TEST(LinearAllocation) { | 543 TEST(LinearAllocation) { |
| 458 v8::V8::Initialize(); | 544 v8::V8::Initialize(); |
| 459 int new_space_max = 512 * KB; | 545 int new_space_max = 512 * KB; |
| 460 for (int size = 1000; size < 5 * MB; size += size >> 1) { | 546 for (int size = 1000; size < 5 * MB; size += size >> 1) { |
| 461 int new_space_size = (size < new_space_max) ? size : new_space_max; | 547 int new_space_size = (size < new_space_max) ? size : new_space_max; |
| 462 Heap::ReserveSpace( | 548 Heap::ReserveSpace( |
| 463 new_space_size, | 549 new_space_size, |
| 464 size, // Old pointer space. | 550 size, // Old pointer space. |
| 465 size, // Old data space. | 551 size, // Old data space. |
| 466 size, // Code space. | 552 size, // Code space. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 TEST(TestThatAlwaysFails) { | 648 TEST(TestThatAlwaysFails) { |
| 563 bool ArtificialFailure = false; | 649 bool ArtificialFailure = false; |
| 564 CHECK(ArtificialFailure); | 650 CHECK(ArtificialFailure); |
| 565 } | 651 } |
| 566 | 652 |
| 567 | 653 |
| 568 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { | 654 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { |
| 569 bool ArtificialFailure2 = false; | 655 bool ArtificialFailure2 = false; |
| 570 CHECK(ArtificialFailure2); | 656 CHECK(ArtificialFailure2); |
| 571 } | 657 } |
| OLD | NEW |