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

Side by Side Diff: test/cctest/test-serialize.cc

Issue 293993021: Support external startup data in V8. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Final rebase (I hope) w/ various fixes. Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/snapshot-source-sink.cc ('k') | tools/concatenate-files.py » ('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 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 v8::V8::Initialize(); 276 v8::V8::Initialize();
277 Serialize(); 277 Serialize();
278 Serialize(); 278 Serialize();
279 } 279 }
280 } 280 }
281 281
282 282
283 //---------------------------------------------------------------------------- 283 //----------------------------------------------------------------------------
284 // Tests that the heap can be deserialized. 284 // Tests that the heap can be deserialized.
285 285
286 static void Deserialize() { 286
287 CHECK(Snapshot::Initialize(FLAG_testing_serialization_file)); 287 static void ReserveSpaceForSnapshot(Deserializer* deserializer,
288 const char* file_name) {
289 int file_name_length = StrLength(file_name) + 10;
290 Vector<char> name = Vector<char>::New(file_name_length + 1);
291 OS::SNPrintF(name, "%s.size", file_name);
292 FILE* fp = OS::FOpen(name.start(), "r");
293 name.Dispose();
294 int new_size, pointer_size, data_size, code_size, map_size, cell_size,
295 property_cell_size;
296 #ifdef _MSC_VER
297 // Avoid warning about unsafe fscanf from MSVC.
298 // Please note that this is only fine if %c and %s are not being used.
299 #define fscanf fscanf_s
300 #endif
301 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size));
302 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size));
303 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size));
304 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size));
305 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size));
306 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size));
307 CHECK_EQ(1, fscanf(fp, "property cell %d\n", &property_cell_size));
308 #ifdef _MSC_VER
309 #undef fscanf
310 #endif
311 fclose(fp);
312 deserializer->set_reservation(NEW_SPACE, new_size);
313 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size);
314 deserializer->set_reservation(OLD_DATA_SPACE, data_size);
315 deserializer->set_reservation(CODE_SPACE, code_size);
316 deserializer->set_reservation(MAP_SPACE, map_size);
317 deserializer->set_reservation(CELL_SPACE, cell_size);
318 deserializer->set_reservation(PROPERTY_CELL_SPACE, property_cell_size);
288 } 319 }
289 320
290 321
322 bool InitializeFromFile(const char* snapshot_file) {
323 int len;
324 byte* str = ReadBytes(snapshot_file, &len);
325 if (!str) return false;
326 bool success;
327 {
328 SnapshotByteSource source(str, len);
329 Deserializer deserializer(&source);
330 ReserveSpaceForSnapshot(&deserializer, snapshot_file);
331 success = V8::Initialize(&deserializer);
332 }
333 DeleteArray(str);
334 return success;
335 }
336
337
338 static void Deserialize() {
339 CHECK(InitializeFromFile(FLAG_testing_serialization_file));
340 }
341
342
291 static void SanityCheck() { 343 static void SanityCheck() {
292 Isolate* isolate = CcTest::i_isolate(); 344 Isolate* isolate = CcTest::i_isolate();
293 v8::HandleScope scope(CcTest::isolate()); 345 v8::HandleScope scope(CcTest::isolate());
294 #ifdef VERIFY_HEAP 346 #ifdef VERIFY_HEAP
295 CcTest::heap()->Verify(); 347 CcTest::heap()->Verify();
296 #endif 348 #endif
297 CHECK(isolate->global_object()->IsJSObject()); 349 CHECK(isolate->global_object()->IsJSObject());
298 CHECK(isolate->native_context()->IsContext()); 350 CHECK(isolate->native_context()->IsContext());
299 CHECK(CcTest::heap()->string_table()->IsStringTable()); 351 CHECK(CcTest::heap()->string_table()->IsStringTable());
300 isolate->factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty")); 352 isolate->factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR("Empty"));
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE), 488 startup_serializer.CurrentAllocationAddress(OLD_DATA_SPACE),
437 startup_serializer.CurrentAllocationAddress(CODE_SPACE), 489 startup_serializer.CurrentAllocationAddress(CODE_SPACE),
438 startup_serializer.CurrentAllocationAddress(MAP_SPACE), 490 startup_serializer.CurrentAllocationAddress(MAP_SPACE),
439 startup_serializer.CurrentAllocationAddress(CELL_SPACE), 491 startup_serializer.CurrentAllocationAddress(CELL_SPACE),
440 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE)); 492 startup_serializer.CurrentAllocationAddress(PROPERTY_CELL_SPACE));
441 startup_name.Dispose(); 493 startup_name.Dispose();
442 } 494 }
443 } 495 }
444 496
445 497
446 static void ReserveSpaceForSnapshot(Deserializer* deserializer,
447 const char* file_name) {
448 int file_name_length = StrLength(file_name) + 10;
449 Vector<char> name = Vector<char>::New(file_name_length + 1);
450 OS::SNPrintF(name, "%s.size", file_name);
451 FILE* fp = OS::FOpen(name.start(), "r");
452 name.Dispose();
453 int new_size, pointer_size, data_size, code_size, map_size, cell_size,
454 property_cell_size;
455 #ifdef _MSC_VER
456 // Avoid warning about unsafe fscanf from MSVC.
457 // Please note that this is only fine if %c and %s are not being used.
458 #define fscanf fscanf_s
459 #endif
460 CHECK_EQ(1, fscanf(fp, "new %d\n", &new_size));
461 CHECK_EQ(1, fscanf(fp, "pointer %d\n", &pointer_size));
462 CHECK_EQ(1, fscanf(fp, "data %d\n", &data_size));
463 CHECK_EQ(1, fscanf(fp, "code %d\n", &code_size));
464 CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size));
465 CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size));
466 CHECK_EQ(1, fscanf(fp, "property cell %d\n", &property_cell_size));
467 #ifdef _MSC_VER
468 #undef fscanf
469 #endif
470 fclose(fp);
471 deserializer->set_reservation(NEW_SPACE, new_size);
472 deserializer->set_reservation(OLD_POINTER_SPACE, pointer_size);
473 deserializer->set_reservation(OLD_DATA_SPACE, data_size);
474 deserializer->set_reservation(CODE_SPACE, code_size);
475 deserializer->set_reservation(MAP_SPACE, map_size);
476 deserializer->set_reservation(CELL_SPACE, cell_size);
477 deserializer->set_reservation(PROPERTY_CELL_SPACE, property_cell_size);
478 }
479
480
481 DEPENDENT_TEST(PartialDeserialization, PartialSerialization) { 498 DEPENDENT_TEST(PartialDeserialization, PartialSerialization) {
482 if (!Snapshot::IsEnabled()) { 499 if (!Snapshot::HaveASnapshotToStartFrom()) {
483 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; 500 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
484 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); 501 Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
485 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); 502 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
486 503
487 CHECK(Snapshot::Initialize(startup_name.start())); 504 CHECK(InitializeFromFile(startup_name.start()));
488 startup_name.Dispose(); 505 startup_name.Dispose();
489 506
490 const char* file_name = FLAG_testing_serialization_file; 507 const char* file_name = FLAG_testing_serialization_file;
491 508
492 int snapshot_size = 0; 509 int snapshot_size = 0;
493 byte* snapshot = ReadBytes(file_name, &snapshot_size); 510 byte* snapshot = ReadBytes(file_name, &snapshot_size);
494 511
495 Isolate* isolate = CcTest::i_isolate(); 512 Isolate* isolate = CcTest::i_isolate();
496 Object* root; 513 Object* root;
497 { 514 {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 } 606 }
590 } 607 }
591 608
592 609
593 DEPENDENT_TEST(ContextDeserialization, ContextSerialization) { 610 DEPENDENT_TEST(ContextDeserialization, ContextSerialization) {
594 if (!Snapshot::HaveASnapshotToStartFrom()) { 611 if (!Snapshot::HaveASnapshotToStartFrom()) {
595 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10; 612 int file_name_length = StrLength(FLAG_testing_serialization_file) + 10;
596 Vector<char> startup_name = Vector<char>::New(file_name_length + 1); 613 Vector<char> startup_name = Vector<char>::New(file_name_length + 1);
597 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file); 614 OS::SNPrintF(startup_name, "%s.startup", FLAG_testing_serialization_file);
598 615
599 CHECK(Snapshot::Initialize(startup_name.start())); 616 CHECK(InitializeFromFile(startup_name.start()));
600 startup_name.Dispose(); 617 startup_name.Dispose();
601 618
602 const char* file_name = FLAG_testing_serialization_file; 619 const char* file_name = FLAG_testing_serialization_file;
603 620
604 int snapshot_size = 0; 621 int snapshot_size = 0;
605 byte* snapshot = ReadBytes(file_name, &snapshot_size); 622 byte* snapshot = ReadBytes(file_name, &snapshot_size);
606 623
607 Isolate* isolate = CcTest::i_isolate(); 624 Isolate* isolate = CcTest::i_isolate();
608 Object* root; 625 Object* root;
609 { 626 {
(...skipping 27 matching lines...) Expand all
637 TEST(TestThatAlwaysFails) { 654 TEST(TestThatAlwaysFails) {
638 bool ArtificialFailure = false; 655 bool ArtificialFailure = false;
639 CHECK(ArtificialFailure); 656 CHECK(ArtificialFailure);
640 } 657 }
641 658
642 659
643 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { 660 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) {
644 bool ArtificialFailure2 = false; 661 bool ArtificialFailure2 = false;
645 CHECK(ArtificialFailure2); 662 CHECK(ArtificialFailure2);
646 } 663 }
OLDNEW
« no previous file with comments | « src/snapshot-source-sink.cc ('k') | tools/concatenate-files.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698