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

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

Issue 1256503004: Version 4.4.63.24 (cherry-pick) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@4.4
Patch Set: Created 5 years, 5 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 | « src/snapshot/serialize.cc ('k') | no next file » | 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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 322
323 SnapshotByteSink startup_sink; 323 SnapshotByteSink startup_sink;
324 StartupSerializer startup_serializer(isolate, &startup_sink); 324 StartupSerializer startup_serializer(isolate, &startup_sink);
325 startup_serializer.SerializeStrongReferences(); 325 startup_serializer.SerializeStrongReferences();
326 326
327 SnapshotByteSink partial_sink; 327 SnapshotByteSink partial_sink;
328 PartialSerializer partial_serializer(isolate, &startup_serializer, 328 PartialSerializer partial_serializer(isolate, &startup_serializer,
329 &partial_sink); 329 &partial_sink);
330 partial_serializer.Serialize(&raw_foo); 330 partial_serializer.Serialize(&raw_foo);
331 331
332 startup_serializer.SerializeWeakReferences(); 332 startup_serializer.SerializeWeakReferencesAndDeferred();
333 333
334 SnapshotData startup_snapshot(startup_serializer); 334 SnapshotData startup_snapshot(startup_serializer);
335 SnapshotData partial_snapshot(partial_serializer); 335 SnapshotData partial_snapshot(partial_serializer);
336 336
337 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file); 337 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file);
338 WritePayload(startup_snapshot.RawData(), startup_name.start()); 338 WritePayload(startup_snapshot.RawData(), startup_name.start());
339 339
340 startup_name.Dispose(); 340 startup_name.Dispose();
341 } 341 }
342 v8_isolate->Exit(); 342 v8_isolate->Exit();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 env.Reset(); 440 env.Reset();
441 441
442 SnapshotByteSink startup_sink; 442 SnapshotByteSink startup_sink;
443 StartupSerializer startup_serializer(isolate, &startup_sink); 443 StartupSerializer startup_serializer(isolate, &startup_sink);
444 startup_serializer.SerializeStrongReferences(); 444 startup_serializer.SerializeStrongReferences();
445 445
446 SnapshotByteSink partial_sink; 446 SnapshotByteSink partial_sink;
447 PartialSerializer partial_serializer(isolate, &startup_serializer, 447 PartialSerializer partial_serializer(isolate, &startup_serializer,
448 &partial_sink); 448 &partial_sink);
449 partial_serializer.Serialize(&raw_context); 449 partial_serializer.Serialize(&raw_context);
450 startup_serializer.SerializeWeakReferences(); 450 startup_serializer.SerializeWeakReferencesAndDeferred();
451 451
452 SnapshotData startup_snapshot(startup_serializer); 452 SnapshotData startup_snapshot(startup_serializer);
453 SnapshotData partial_snapshot(partial_serializer); 453 SnapshotData partial_snapshot(partial_serializer);
454 454
455 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file); 455 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file);
456 WritePayload(startup_snapshot.RawData(), startup_name.start()); 456 WritePayload(startup_snapshot.RawData(), startup_name.start());
457 457
458 startup_name.Dispose(); 458 startup_name.Dispose();
459 } 459 }
460 v8_isolate->Dispose(); 460 v8_isolate->Dispose();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 env.Reset(); 575 env.Reset();
576 576
577 SnapshotByteSink startup_sink; 577 SnapshotByteSink startup_sink;
578 StartupSerializer startup_serializer(isolate, &startup_sink); 578 StartupSerializer startup_serializer(isolate, &startup_sink);
579 startup_serializer.SerializeStrongReferences(); 579 startup_serializer.SerializeStrongReferences();
580 580
581 SnapshotByteSink partial_sink; 581 SnapshotByteSink partial_sink;
582 PartialSerializer partial_serializer(isolate, &startup_serializer, 582 PartialSerializer partial_serializer(isolate, &startup_serializer,
583 &partial_sink); 583 &partial_sink);
584 partial_serializer.Serialize(&raw_context); 584 partial_serializer.Serialize(&raw_context);
585 startup_serializer.SerializeWeakReferences(); 585 startup_serializer.SerializeWeakReferencesAndDeferred();
586 586
587 SnapshotData startup_snapshot(startup_serializer); 587 SnapshotData startup_snapshot(startup_serializer);
588 SnapshotData partial_snapshot(partial_serializer); 588 SnapshotData partial_snapshot(partial_serializer);
589 589
590 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file); 590 WritePayload(partial_snapshot.RawData(), FLAG_testing_serialization_file);
591 WritePayload(startup_snapshot.RawData(), startup_name.start()); 591 WritePayload(startup_snapshot.RawData(), startup_name.start());
592 592
593 startup_name.Dispose(); 593 startup_name.Dispose();
594 } 594 }
595 v8_isolate->Dispose(); 595 v8_isolate->Dispose();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 v8::Local<v8::Context> context = v8::Context::New(isolate2); 695 v8::Local<v8::Context> context = v8::Context::New(isolate2);
696 delete[] data2.data; // We can dispose of the snapshot blob now. 696 delete[] data2.data; // We can dispose of the snapshot blob now.
697 v8::Context::Scope c_scope(context); 697 v8::Context::Scope c_scope(context);
698 CHECK_EQ(86, CompileRun("f()")->ToInt32(isolate2)->Int32Value()); 698 CHECK_EQ(86, CompileRun("f()")->ToInt32(isolate2)->Int32Value());
699 CHECK_EQ(43, CompileRun("g()")->ToInt32(isolate2)->Int32Value()); 699 CHECK_EQ(43, CompileRun("g()")->ToInt32(isolate2)->Int32Value());
700 } 700 }
701 isolate2->Dispose(); 701 isolate2->Dispose();
702 } 702 }
703 703
704 704
705 static void SerializationFunctionTemplate(
706 const v8::FunctionCallbackInfo<v8::Value>& args) {
707 args.GetReturnValue().Set(args[0]);
708 }
709
710
711 TEST(PerIsolateSnapshotBlobsOutdatedContextWithOverflow) {
712 DisableTurbofan();
713
714 const char* source1 =
715 "var o = {};"
716 "(function() {"
717 " function f1(x) { return f2(x) instanceof Array; }"
718 " function f2(x) { return foo.bar(x); }"
719 " o.a = f2.bind(null);"
720 " o.b = 1;"
721 " o.c = 2;"
722 " o.d = 3;"
723 " o.e = 4;"
724 "})();\n";
725
726 const char* source2 = "o.a(42)";
727
728 v8::StartupData data = v8::V8::CreateSnapshotDataBlob(source1);
729
730 v8::Isolate::CreateParams params;
731 params.snapshot_blob = &data;
732 params.array_buffer_allocator = CcTest::array_buffer_allocator();
733
734 v8::Isolate* isolate = v8::Isolate::New(params);
735 {
736 v8::Isolate::Scope i_scope(isolate);
737 v8::HandleScope h_scope(isolate);
738
739 v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
740 v8::Local<v8::ObjectTemplate> property = v8::ObjectTemplate::New(isolate);
741 v8::Local<v8::FunctionTemplate> function =
742 v8::FunctionTemplate::New(isolate, SerializationFunctionTemplate);
743 property->Set(isolate, "bar", function);
744 global->Set(isolate, "foo", property);
745
746 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
747 delete[] data.data; // We can dispose of the snapshot blob now.
748 v8::Context::Scope c_scope(context);
749 v8::Local<v8::Value> result = CompileRun(source2);
750 CHECK(v8_str("42")->Equals(result));
751 }
752 isolate->Dispose();
753 }
754
755
705 TEST(PerIsolateSnapshotBlobsWithLocker) { 756 TEST(PerIsolateSnapshotBlobsWithLocker) {
706 DisableTurbofan(); 757 DisableTurbofan();
707 v8::Isolate::CreateParams create_params; 758 v8::Isolate::CreateParams create_params;
708 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); 759 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
709 v8::Isolate* isolate0 = v8::Isolate::New(create_params); 760 v8::Isolate* isolate0 = v8::Isolate::New(create_params);
710 { 761 {
711 v8::Locker locker(isolate0); 762 v8::Locker locker(isolate0);
712 v8::Isolate::Scope i_scope(isolate0); 763 v8::Isolate::Scope i_scope(isolate0);
713 v8::HandleScope h_scope(isolate0); 764 v8::HandleScope h_scope(isolate0);
714 v8::Local<v8::Context> context = v8::Context::New(isolate0); 765 v8::Local<v8::Context> context = v8::Context::New(isolate0);
(...skipping 16 matching lines...) Expand all
731 v8::HandleScope h_scope(isolate1); 782 v8::HandleScope h_scope(isolate1);
732 v8::Local<v8::Context> context = v8::Context::New(isolate1); 783 v8::Local<v8::Context> context = v8::Context::New(isolate1);
733 delete[] data1.data; // We can dispose of the snapshot blob now. 784 delete[] data1.data; // We can dispose of the snapshot blob now.
734 v8::Context::Scope c_scope(context); 785 v8::Context::Scope c_scope(context);
735 CHECK_EQ(42, CompileRun("f()")->ToInt32(isolate1)->Int32Value()); 786 CHECK_EQ(42, CompileRun("f()")->ToInt32(isolate1)->Int32Value());
736 } 787 }
737 isolate1->Dispose(); 788 isolate1->Dispose();
738 } 789 }
739 790
740 791
792 TEST(SnapshotBlobsStackOverflow) {
793 DisableTurbofan();
794 const char* source =
795 "var a = [0];"
796 "var b = a;"
797 "for (var i = 0; i < 10000; i++) {"
798 " var c = [i];"
799 " b.push(c);"
800 " b.push(c);"
801 " b = c;"
802 "}";
803
804 v8::StartupData data = v8::V8::CreateSnapshotDataBlob(source);
805
806 v8::Isolate::CreateParams params;
807 params.snapshot_blob = &data;
808 params.array_buffer_allocator = CcTest::array_buffer_allocator();
809
810 v8::Isolate* isolate = v8::Isolate::New(params);
811 {
812 v8::Isolate::Scope i_scope(isolate);
813 v8::HandleScope h_scope(isolate);
814 v8::Local<v8::Context> context = v8::Context::New(isolate);
815 delete[] data.data; // We can dispose of the snapshot blob now.
816 v8::Context::Scope c_scope(context);
817 const char* test =
818 "var sum = 0;"
819 "while (a) {"
820 " sum += a[0];"
821 " a = a[1];"
822 "}"
823 "sum";
824 CHECK_EQ(9999 * 5000, CompileRun(test)->ToInt32(isolate)->Int32Value());
825 }
826 isolate->Dispose();
827 }
828
829
741 TEST(TestThatAlwaysSucceeds) { 830 TEST(TestThatAlwaysSucceeds) {
742 } 831 }
743 832
744 833
745 TEST(TestThatAlwaysFails) { 834 TEST(TestThatAlwaysFails) {
746 bool ArtificialFailure = false; 835 bool ArtificialFailure = false;
747 CHECK(ArtificialFailure); 836 CHECK(ArtificialFailure);
748 } 837 }
749 838
750 839
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 isolate->Dispose(); 1658 isolate->Dispose();
1570 } 1659 }
1571 1660
1572 1661
1573 TEST(SerializationMemoryStats) { 1662 TEST(SerializationMemoryStats) {
1574 FLAG_profile_deserialization = true; 1663 FLAG_profile_deserialization = true;
1575 FLAG_always_opt = false; 1664 FLAG_always_opt = false;
1576 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); 1665 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob();
1577 delete[] blob.data; 1666 delete[] blob.data;
1578 } 1667 }
OLDNEW
« no previous file with comments | « src/snapshot/serialize.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698