| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 188 } |
| 189 virtual int Position() { | 189 virtual int Position() { |
| 190 return ftell(fp_); | 190 return ftell(fp_); |
| 191 } | 191 } |
| 192 void WriteSpaceUsed( | 192 void WriteSpaceUsed( |
| 193 int new_space_used, | 193 int new_space_used, |
| 194 int pointer_space_used, | 194 int pointer_space_used, |
| 195 int data_space_used, | 195 int data_space_used, |
| 196 int code_space_used, | 196 int code_space_used, |
| 197 int map_space_used, | 197 int map_space_used, |
| 198 int cell_space_used); | 198 int cell_space_used, |
| 199 int property_cell_space_used); |
| 199 | 200 |
| 200 private: | 201 private: |
| 201 FILE* fp_; | 202 FILE* fp_; |
| 202 const char* file_name_; | 203 const char* file_name_; |
| 203 }; | 204 }; |
| 204 | 205 |
| 205 | 206 |
| 206 void FileByteSink::WriteSpaceUsed( | 207 void FileByteSink::WriteSpaceUsed( |
| 207 int new_space_used, | 208 int new_space_used, |
| 208 int pointer_space_used, | 209 int pointer_space_used, |
| 209 int data_space_used, | 210 int data_space_used, |
| 210 int code_space_used, | 211 int code_space_used, |
| 211 int map_space_used, | 212 int map_space_used, |
| 212 int cell_space_used) { | 213 int cell_space_used, |
| 214 int property_cell_space_used) { |
| 213 int file_name_length = StrLength(file_name_) + 10; | 215 int file_name_length = StrLength(file_name_) + 10; |
| 214 Vector<char> name = Vector<char>::New(file_name_length + 1); | 216 Vector<char> name = Vector<char>::New(file_name_length + 1); |
| 215 OS::SNPrintF(name, "%s.size", file_name_); | 217 OS::SNPrintF(name, "%s.size", file_name_); |
| 216 FILE* fp = OS::FOpen(name.start(), "w"); | 218 FILE* fp = OS::FOpen(name.start(), "w"); |
| 217 name.Dispose(); | 219 name.Dispose(); |
| 218 fprintf(fp, "new %d\n", new_space_used); | 220 fprintf(fp, "new %d\n", new_space_used); |
| 219 fprintf(fp, "pointer %d\n", pointer_space_used); | 221 fprintf(fp, "pointer %d\n", pointer_space_used); |
| 220 fprintf(fp, "data %d\n", data_space_used); | 222 fprintf(fp, "data %d\n", data_space_used); |
| 221 fprintf(fp, "code %d\n", code_space_used); | 223 fprintf(fp, "code %d\n", code_space_used); |
| 222 fprintf(fp, "map %d\n", map_space_used); | 224 fprintf(fp, "map %d\n", map_space_used); |
| 223 fprintf(fp, "cell %d\n", cell_space_used); | 225 fprintf(fp, "cell %d\n", cell_space_used); |
| 226 fprintf(fp, "property cell %d\n", property_cell_space_used); |
| 224 fclose(fp); | 227 fclose(fp); |
| 225 } | 228 } |
| 226 | 229 |
| 227 | 230 |
| 228 static bool WriteToFile(const char* snapshot_file) { | 231 static bool WriteToFile(const char* snapshot_file) { |
| 229 FileByteSink file(snapshot_file); | 232 FileByteSink file(snapshot_file); |
| 230 StartupSerializer ser(&file); | 233 StartupSerializer ser(&file); |
| 231 ser.Serialize(); | 234 ser.Serialize(); |
| 232 | 235 |
| 233 file.WriteSpaceUsed( | 236 file.WriteSpaceUsed( |
| 234 ser.CurrentAllocationAddress(NEW_SPACE), | 237 ser.CurrentAllocationAddress(NEW_SPACE), |
| 235 ser.CurrentAllocationAddress(OLD_POINTER_SPACE), | 238 ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 236 ser.CurrentAllocationAddress(OLD_DATA_SPACE), | 239 ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 237 ser.CurrentAllocationAddress(CODE_SPACE), | 240 ser.CurrentAllocationAddress(CODE_SPACE), |
| 238 ser.CurrentAllocationAddress(MAP_SPACE), | 241 ser.CurrentAllocationAddress(MAP_SPACE), |
| 239 ser.CurrentAllocationAddress(CELL_SPACE)); | 242 ser.CurrentAllocationAddress(CELL_SPACE), |
| 243 ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); |
| 240 | 244 |
| 241 return true; | 245 return true; |
| 242 } | 246 } |
| 243 | 247 |
| 244 | 248 |
| 245 static void Serialize() { | 249 static void Serialize() { |
| 246 // We have to create one context. One reason for this is so that the builtins | 250 // We have to create one context. One reason for this is so that the builtins |
| 247 // can be loaded from v8natives.js and their addresses can be processed. This | 251 // can be loaded from v8natives.js and their addresses can be processed. This |
| 248 // will clear the pending fixups array, which would otherwise contain GC roots | 252 // will clear the pending fixups array, which would otherwise contain GC roots |
| 249 // that would confuse the serialization/deserialization process. | 253 // that would confuse the serialization/deserialization process. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 PartialSerializer p_ser(&startup_serializer, &partial_sink); | 422 PartialSerializer p_ser(&startup_serializer, &partial_sink); |
| 419 p_ser.Serialize(&raw_foo); | 423 p_ser.Serialize(&raw_foo); |
| 420 startup_serializer.SerializeWeakReferences(); | 424 startup_serializer.SerializeWeakReferences(); |
| 421 | 425 |
| 422 partial_sink.WriteSpaceUsed( | 426 partial_sink.WriteSpaceUsed( |
| 423 p_ser.CurrentAllocationAddress(NEW_SPACE), | 427 p_ser.CurrentAllocationAddress(NEW_SPACE), |
| 424 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), | 428 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 425 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), | 429 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 426 p_ser.CurrentAllocationAddress(CODE_SPACE), | 430 p_ser.CurrentAllocationAddress(CODE_SPACE), |
| 427 p_ser.CurrentAllocationAddress(MAP_SPACE), | 431 p_ser.CurrentAllocationAddress(MAP_SPACE), |
| 428 p_ser.CurrentAllocationAddress(CELL_SPACE)); | 432 p_ser.CurrentAllocationAddress(CELL_SPACE), |
| 433 p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); |
| 429 | 434 |
| 430 startup_sink.WriteSpaceUsed( | 435 startup_sink.WriteSpaceUsed( |
| 431 startup_serializer.CurrentAllocationAddress(NEW_SPACE), | 436 startup_serializer.CurrentAllocationAddress(NEW_SPACE), |
| 432 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), | 437 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 433 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), | 438 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 434 startup_serializer.CurrentAllocationAddress(CODE_SPACE), | 439 startup_serializer.CurrentAllocationAddress(CODE_SPACE), |
| 435 startup_serializer.CurrentAllocationAddress(MAP_SPACE), | 440 startup_serializer.CurrentAllocationAddress(MAP_SPACE), |
| 436 startup_serializer.CurrentAllocationAddress(CELL_SPACE)); | 441 startup_serializer.CurrentAllocationAddress(CELL_SPACE), |
| 442 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); |
| 437 startup_name.Dispose(); | 443 startup_name.Dispose(); |
| 438 } | 444 } |
| 439 } | 445 } |
| 440 | 446 |
| 441 | 447 |
| 442 static void ReserveSpaceForSnapshot(Deserializer* deserializer, | 448 static void ReserveSpaceForSnapshot(Deserializer* deserializer, |
| 443 const char* file_name) { | 449 const char* file_name) { |
| 444 int file_name_length = StrLength(file_name) + 10; | 450 int file_name_length = StrLength(file_name) + 10; |
| 445 Vector<char> name = Vector<char>::New(file_name_length + 1); | 451 Vector<char> name = Vector<char>::New(file_name_length + 1); |
| 446 OS::SNPrintF(name, "%s.size", file_name); | 452 OS::SNPrintF(name, "%s.size", file_name); |
| 447 FILE* fp = OS::FOpen(name.start(), "r"); | 453 FILE* fp = OS::FOpen(name.start(), "r"); |
| 448 name.Dispose(); | 454 name.Dispose(); |
| 449 int new_size, pointer_size, data_size, code_size, map_size, cell_size; | 455 int new_size, pointer_size, data_size, code_size, map_size, cell_size, |
| 456 property_cell_size; |
| 450 #ifdef _MSC_VER | 457 #ifdef _MSC_VER |
| 451 // Avoid warning about unsafe fscanf from MSVC. | 458 // Avoid warning about unsafe fscanf from MSVC. |
| 452 // Please note that this is only fine if %c and %s are not being used. | 459 // Please note that this is only fine if %c and %s are not being used. |
| 453 #define fscanf fscanf_s | 460 #define fscanf fscanf_s |
| 454 #endif | 461 #endif |
| 455 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size)); | 462 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size)); |
| 456 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size)); | 463 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size)); |
| 457 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); | 464 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size)); |
| 458 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); | 465 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size)); |
| 459 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); | 466 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size)); |
| 460 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); | 467 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size)); |
| 468 CHECK_EQ(1, fscanf(fp, "property cell %d\n", &property_cell_size)); |
| 461 #ifdef _MSC_VER | 469 #ifdef _MSC_VER |
| 462 #undef fscanf | 470 #undef fscanf |
| 463 #endif | 471 #endif |
| 464 fclose(fp); | 472 fclose(fp); |
| 465 deserializer->set_reservation(NEW_SPACE, new_size); | 473 deserializer->set_reservation(NEW_SPACE, new_size); |
| 466 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size); | 474 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size); |
| 467 deserializer->set_reservation(OLD_DATA_SPACE, data_size); | 475 deserializer->set_reservation(OLD_DATA_SPACE, data_size); |
| 468 deserializer->set_reservation(CODE_SPACE, code_size); | 476 deserializer->set_reservation(CODE_SPACE, code_size); |
| 469 deserializer->set_reservation(MAP_SPACE, map_size); | 477 deserializer->set_reservation(MAP_SPACE, map_size); |
| 470 deserializer->set_reservation(CELL_SPACE, cell_size); | 478 deserializer->set_reservation(CELL_SPACE, cell_size); |
| 479 deserializer->set_reservation(PROPERTY_CELL_SPACE, property_cell_size); |
| 471 } | 480 } |
| 472 | 481 |
| 473 | 482 |
| 474 DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { | 483 DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { |
| 475 if (!Snapshot::IsEnabled()) { | 484 if (!Snapshot::IsEnabled()) { |
| 476 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 485 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 477 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | 486 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 478 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 487 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 479 | 488 |
| 480 CHECK(Snapshot::Initialize(startup_name.start())); | 489 CHECK(Snapshot::Initialize(startup_name.start())); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 | 549 |
| 541 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 550 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 542 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | 551 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 543 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 552 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| 544 | 553 |
| 545 { | 554 { |
| 546 v8::HandleScope handle_scope(v8_isolate); | 555 v8::HandleScope handle_scope(v8_isolate); |
| 547 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); | 556 v8::Local<v8::Context>::New(v8_isolate, env)->Exit(); |
| 548 } | 557 } |
| 549 | 558 |
| 550 Object* raw_context = *(v8::Utils::OpenHandle(*env)); | 559 i::Object* raw_context = *v8::Utils::OpenPersistent(env); |
| 551 | 560 |
| 552 env.Dispose(v8_isolate); | 561 env.Dispose(v8_isolate); |
| 553 | 562 |
| 554 FileByteSink startup_sink(startup_name.start()); | 563 FileByteSink startup_sink(startup_name.start()); |
| 555 StartupSerializer startup_serializer(&startup_sink); | 564 StartupSerializer startup_serializer(&startup_sink); |
| 556 startup_serializer.SerializeStrongReferences(); | 565 startup_serializer.SerializeStrongReferences(); |
| 557 | 566 |
| 558 FileByteSink partial_sink(FLAG_testing_serialization_file); | 567 FileByteSink partial_sink(FLAG_testing_serialization_file); |
| 559 PartialSerializer p_ser(&startup_serializer, &partial_sink); | 568 PartialSerializer p_ser(&startup_serializer, &partial_sink); |
| 560 p_ser.Serialize(&raw_context); | 569 p_ser.Serialize(&raw_context); |
| 561 startup_serializer.SerializeWeakReferences(); | 570 startup_serializer.SerializeWeakReferences(); |
| 562 | 571 |
| 563 partial_sink.WriteSpaceUsed( | 572 partial_sink.WriteSpaceUsed( |
| 564 p_ser.CurrentAllocationAddress(NEW_SPACE), | 573 p_ser.CurrentAllocationAddress(NEW_SPACE), |
| 565 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), | 574 p_ser.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 566 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), | 575 p_ser.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 567 p_ser.CurrentAllocationAddress(CODE_SPACE), | 576 p_ser.CurrentAllocationAddress(CODE_SPACE), |
| 568 p_ser.CurrentAllocationAddress(MAP_SPACE), | 577 p_ser.CurrentAllocationAddress(MAP_SPACE), |
| 569 p_ser.CurrentAllocationAddress(CELL_SPACE)); | 578 p_ser.CurrentAllocationAddress(CELL_SPACE), |
| 579 p_ser.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); |
| 570 | 580 |
| 571 startup_sink.WriteSpaceUsed( | 581 startup_sink.WriteSpaceUsed( |
| 572 startup_serializer.CurrentAllocationAddress(NEW_SPACE), | 582 startup_serializer.CurrentAllocationAddress(NEW_SPACE), |
| 573 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), | 583 startup_serializer.CurrentAllocationAddress(OLD_POINTER_SPACE), |
| 574 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), | 584 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), |
| 575 startup_serializer.CurrentAllocationAddress(CODE_SPACE), | 585 startup_serializer.CurrentAllocationAddress(CODE_SPACE), |
| 576 startup_serializer.CurrentAllocationAddress(MAP_SPACE), | 586 startup_serializer.CurrentAllocationAddress(MAP_SPACE), |
| 577 startup_serializer.CurrentAllocationAddress(CELL_SPACE)); | 587 startup_serializer.CurrentAllocationAddress(CELL_SPACE), |
| 588 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); |
| 578 startup_name.Dispose(); | 589 startup_name.Dispose(); |
| 579 } | 590 } |
| 580 } | 591 } |
| 581 | 592 |
| 582 | 593 |
| 583 DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { | 594 DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { |
| 584 if (!Snapshot::HaveASnapshotToStartFrom()) { | 595 if (!Snapshot::HaveASnapshotToStartFrom()) { |
| 585 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; | 596 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; |
| 586 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); | 597 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); |
| 587 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); | 598 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 TEST(TestThatAlwaysFails) { | 637 TEST(TestThatAlwaysFails) { |
| 627 bool ArtificialFailure = false; | 638 bool ArtificialFailure = false; |
| 628 CHECK(ArtificialFailure); | 639 CHECK(ArtificialFailure); |
| 629 } | 640 } |
| 630 | 641 |
| 631 | 642 |
| 632 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { | 643 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { |
| 633 bool ArtificialFailure2 = false; | 644 bool ArtificialFailure2 = false; |
| 634 CHECK(ArtificialFailure2); | 645 CHECK(ArtificialFailure2); |
| 635 } | 646 } |
| OLD | NEW |