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

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

Issue 2803903002: Revert of [snapshot] Move builtins generation into mksnapshot (Closed)
Patch Set: rebased Created 3 years, 8 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 | « test/cctest/setup-isolate-for-tests.cc ('k') | test/unittests/BUILD.gn » ('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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "src/objects-inl.h" 42 #include "src/objects-inl.h"
43 #include "src/runtime/runtime.h" 43 #include "src/runtime/runtime.h"
44 #include "src/snapshot/code-serializer.h" 44 #include "src/snapshot/code-serializer.h"
45 #include "src/snapshot/deserializer.h" 45 #include "src/snapshot/deserializer.h"
46 #include "src/snapshot/natives.h" 46 #include "src/snapshot/natives.h"
47 #include "src/snapshot/partial-serializer.h" 47 #include "src/snapshot/partial-serializer.h"
48 #include "src/snapshot/snapshot.h" 48 #include "src/snapshot/snapshot.h"
49 #include "src/snapshot/startup-serializer.h" 49 #include "src/snapshot/startup-serializer.h"
50 #include "test/cctest/cctest.h" 50 #include "test/cctest/cctest.h"
51 #include "test/cctest/heap/heap-utils.h" 51 #include "test/cctest/heap/heap-utils.h"
52 #include "test/cctest/setup-isolate-for-tests.h"
53 52
54 using namespace v8::internal; 53 using namespace v8::internal;
55 54
56 void DisableAlwaysOpt() { 55 void DisableAlwaysOpt() {
57 // Isolates prepared for serialization do not optimize. The only exception is 56 // Isolates prepared for serialization do not optimize. The only exception is
58 // with the flag --always-opt. 57 // with the flag --always-opt.
59 FLAG_always_opt = false; 58 FLAG_always_opt = false;
60 } 59 }
61 60
62 61
63 // TestIsolate is used for testing isolate serialization. 62 // TestIsolate is used for testing isolate serialization.
64 class TestIsolate : public Isolate { 63 class TestIsolate : public Isolate {
65 public: 64 public:
66 static v8::Isolate* NewInitialized(bool enable_serializer) { 65 static v8::Isolate* NewInitialized(bool enable_serializer) {
67 i::Isolate* isolate = new TestIsolate(enable_serializer); 66 i::Isolate* isolate = new TestIsolate(enable_serializer);
68 isolate->setup_delegate_ = new SetupIsolateDelegateForTests();
69 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); 67 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
70 v8::Isolate::Scope isolate_scope(v8_isolate); 68 v8::Isolate::Scope isolate_scope(v8_isolate);
71 isolate->Init(NULL); 69 isolate->Init(NULL);
72 return v8_isolate; 70 return v8_isolate;
73 } 71 }
74 // Wraps v8::Isolate::New, but with a TestIsolate under the hood.
75 // Allows flexibility to bootstrap with or without snapshot even when
76 // the production Isolate class has one or the other behavior baked in.
77 static v8::Isolate* New(const v8::Isolate::CreateParams& params) {
78 i::Isolate* isolate = new TestIsolate(false);
79 isolate->setup_delegate_ = new SetupIsolateDelegateForTests();
80 return v8::IsolateNewImpl(isolate, params);
81 }
82 explicit TestIsolate(bool enable_serializer) : Isolate(enable_serializer) { 72 explicit TestIsolate(bool enable_serializer) : Isolate(enable_serializer) {
83 set_array_buffer_allocator(CcTest::array_buffer_allocator()); 73 set_array_buffer_allocator(CcTest::array_buffer_allocator());
84 } 74 }
85 void CreateSetupDelegateForTests() {
86 setup_delegate_ = new SetupIsolateDelegateForTests();
87 }
88 }; 75 };
89 76
90 static Vector<const byte> WritePayload(const Vector<const byte>& payload) { 77 static Vector<const byte> WritePayload(const Vector<const byte>& payload) {
91 int length = payload.length(); 78 int length = payload.length();
92 byte* blob = NewArray<byte>(length); 79 byte* blob = NewArray<byte>(length);
93 memcpy(blob, payload.begin(), length); 80 memcpy(blob, payload.begin(), length);
94 return Vector<const byte>(const_cast<const byte*>(blob), length); 81 return Vector<const byte>(const_cast<const byte*>(blob), length);
95 } 82 }
96 83
97 static Vector<const byte> Serialize(v8::Isolate* isolate) { 84 static Vector<const byte> Serialize(v8::Isolate* isolate) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 tail.length()); 118 tail.length());
132 return Vector<const uint8_t>(const_cast<const uint8_t*>(source), 119 return Vector<const uint8_t>(const_cast<const uint8_t*>(source),
133 source_length); 120 source_length);
134 } 121 }
135 122
136 v8::Isolate* InitializeFromBlob(Vector<const byte> blob) { 123 v8::Isolate* InitializeFromBlob(Vector<const byte> blob) {
137 v8::Isolate* v8_isolate = NULL; 124 v8::Isolate* v8_isolate = NULL;
138 { 125 {
139 SnapshotData snapshot_data(blob); 126 SnapshotData snapshot_data(blob);
140 Deserializer deserializer(&snapshot_data); 127 Deserializer deserializer(&snapshot_data);
141 TestIsolate* isolate = new TestIsolate(false); 128 Isolate* isolate = new TestIsolate(false);
142 v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); 129 v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
143 v8::Isolate::Scope isolate_scope(v8_isolate); 130 v8::Isolate::Scope isolate_scope(v8_isolate);
144 isolate->CreateSetupDelegateForTests();
145 isolate->Init(&deserializer); 131 isolate->Init(&deserializer);
146 } 132 }
147 return v8_isolate; 133 return v8_isolate;
148 } 134 }
149 135
150 static v8::Isolate* Deserialize(Vector<const byte> blob) { 136 static v8::Isolate* Deserialize(Vector<const byte> blob) {
151 v8::Isolate* isolate = InitializeFromBlob(blob); 137 v8::Isolate* isolate = InitializeFromBlob(blob);
152 CHECK(isolate); 138 CHECK(isolate);
153 return isolate; 139 return isolate;
154 } 140 }
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 TEST(CustomSnapshotDataBlob1) { 626 TEST(CustomSnapshotDataBlob1) {
641 DisableAlwaysOpt(); 627 DisableAlwaysOpt();
642 const char* source1 = "function f() { return 42; }"; 628 const char* source1 = "function f() { return 42; }";
643 629
644 v8::StartupData data1 = v8::V8::CreateSnapshotDataBlob(source1); 630 v8::StartupData data1 = v8::V8::CreateSnapshotDataBlob(source1);
645 631
646 v8::Isolate::CreateParams params1; 632 v8::Isolate::CreateParams params1;
647 params1.snapshot_blob = &data1; 633 params1.snapshot_blob = &data1;
648 params1.array_buffer_allocator = CcTest::array_buffer_allocator(); 634 params1.array_buffer_allocator = CcTest::array_buffer_allocator();
649 635
650 // Test-appropriate equivalent of v8::Isolate::New. 636 v8::Isolate* isolate1 = v8::Isolate::New(params1);
651 v8::Isolate* isolate1 = TestIsolate::New(params1);
652 { 637 {
653 v8::Isolate::Scope i_scope(isolate1); 638 v8::Isolate::Scope i_scope(isolate1);
654 v8::HandleScope h_scope(isolate1); 639 v8::HandleScope h_scope(isolate1);
655 v8::Local<v8::Context> context = v8::Context::New(isolate1); 640 v8::Local<v8::Context> context = v8::Context::New(isolate1);
656 delete[] data1.data; // We can dispose of the snapshot blob now. 641 delete[] data1.data; // We can dispose of the snapshot blob now.
657 v8::Context::Scope c_scope(context); 642 v8::Context::Scope c_scope(context);
658 v8::Maybe<int32_t> result = 643 v8::Maybe<int32_t> result =
659 CompileRun("f()")->Int32Value(isolate1->GetCurrentContext()); 644 CompileRun("f()")->Int32Value(isolate1->GetCurrentContext());
660 CHECK_EQ(42, result.FromJust()); 645 CHECK_EQ(42, result.FromJust());
661 CHECK(CompileRun("this.g")->IsUndefined()); 646 CHECK(CompileRun("this.g")->IsUndefined());
662 } 647 }
663 isolate1->Dispose(); 648 isolate1->Dispose();
664 } 649 }
665 650
666 TEST(CustomSnapshotDataBlob2) { 651 TEST(CustomSnapshotDataBlob2) {
667 DisableAlwaysOpt(); 652 DisableAlwaysOpt();
668 const char* source2 = 653 const char* source2 =
669 "function f() { return g() * 2; }" 654 "function f() { return g() * 2; }"
670 "function g() { return 43; }" 655 "function g() { return 43; }"
671 "/./.test('a')"; 656 "/./.test('a')";
672 657
673 v8::StartupData data2 = v8::V8::CreateSnapshotDataBlob(source2); 658 v8::StartupData data2 = v8::V8::CreateSnapshotDataBlob(source2);
674 659
675 v8::Isolate::CreateParams params2; 660 v8::Isolate::CreateParams params2;
676 params2.snapshot_blob = &data2; 661 params2.snapshot_blob = &data2;
677 params2.array_buffer_allocator = CcTest::array_buffer_allocator(); 662 params2.array_buffer_allocator = CcTest::array_buffer_allocator();
678 // Test-appropriate equivalent of v8::Isolate::New. 663 v8::Isolate* isolate2 = v8::Isolate::New(params2);
679 v8::Isolate* isolate2 = TestIsolate::New(params2);
680 { 664 {
681 v8::Isolate::Scope i_scope(isolate2); 665 v8::Isolate::Scope i_scope(isolate2);
682 v8::HandleScope h_scope(isolate2); 666 v8::HandleScope h_scope(isolate2);
683 v8::Local<v8::Context> context = v8::Context::New(isolate2); 667 v8::Local<v8::Context> context = v8::Context::New(isolate2);
684 delete[] data2.data; // We can dispose of the snapshot blob now. 668 delete[] data2.data; // We can dispose of the snapshot blob now.
685 v8::Context::Scope c_scope(context); 669 v8::Context::Scope c_scope(context);
686 v8::Maybe<int32_t> result = 670 v8::Maybe<int32_t> result =
687 CompileRun("f()")->Int32Value(isolate2->GetCurrentContext()); 671 CompileRun("f()")->Int32Value(isolate2->GetCurrentContext());
688 CHECK_EQ(86, result.FromJust()); 672 CHECK_EQ(86, result.FromJust());
689 result = CompileRun("g()")->Int32Value(isolate2->GetCurrentContext()); 673 result = CompileRun("g()")->Int32Value(isolate2->GetCurrentContext());
(...skipping 22 matching lines...) Expand all
712 "})();\n"; 696 "})();\n";
713 697
714 const char* source2 = "o.a(42)"; 698 const char* source2 = "o.a(42)";
715 699
716 v8::StartupData data = v8::V8::CreateSnapshotDataBlob(source1); 700 v8::StartupData data = v8::V8::CreateSnapshotDataBlob(source1);
717 701
718 v8::Isolate::CreateParams params; 702 v8::Isolate::CreateParams params;
719 params.snapshot_blob = &data; 703 params.snapshot_blob = &data;
720 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 704 params.array_buffer_allocator = CcTest::array_buffer_allocator();
721 705
722 // Test-appropriate equivalent of v8::Isolate::New. 706 v8::Isolate* isolate = v8::Isolate::New(params);
723 v8::Isolate* isolate = TestIsolate::New(params);
724 { 707 {
725 v8::Isolate::Scope i_scope(isolate); 708 v8::Isolate::Scope i_scope(isolate);
726 v8::HandleScope h_scope(isolate); 709 v8::HandleScope h_scope(isolate);
727 710
728 v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); 711 v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
729 v8::Local<v8::ObjectTemplate> property = v8::ObjectTemplate::New(isolate); 712 v8::Local<v8::ObjectTemplate> property = v8::ObjectTemplate::New(isolate);
730 v8::Local<v8::FunctionTemplate> function = 713 v8::Local<v8::FunctionTemplate> function =
731 v8::FunctionTemplate::New(isolate, SerializationFunctionTemplate); 714 v8::FunctionTemplate::New(isolate, SerializationFunctionTemplate);
732 property->Set(isolate, "bar", function); 715 property->Set(isolate, "bar", function);
733 global->Set(isolate, "foo", property); 716 global->Set(isolate, "foo", property);
(...skipping 26 matching lines...) Expand all
760 } 743 }
761 isolate0->Dispose(); 744 isolate0->Dispose();
762 745
763 const char* source1 = "function f() { return 42; }"; 746 const char* source1 = "function f() { return 42; }";
764 747
765 v8::StartupData data1 = v8::V8::CreateSnapshotDataBlob(source1); 748 v8::StartupData data1 = v8::V8::CreateSnapshotDataBlob(source1);
766 749
767 v8::Isolate::CreateParams params1; 750 v8::Isolate::CreateParams params1;
768 params1.snapshot_blob = &data1; 751 params1.snapshot_blob = &data1;
769 params1.array_buffer_allocator = CcTest::array_buffer_allocator(); 752 params1.array_buffer_allocator = CcTest::array_buffer_allocator();
770 // Test-appropriate equivalent of v8::Isolate::New. 753 v8::Isolate* isolate1 = v8::Isolate::New(params1);
771 v8::Isolate* isolate1 = TestIsolate::New(params1);
772 { 754 {
773 v8::Locker locker(isolate1); 755 v8::Locker locker(isolate1);
774 v8::Isolate::Scope i_scope(isolate1); 756 v8::Isolate::Scope i_scope(isolate1);
775 v8::HandleScope h_scope(isolate1); 757 v8::HandleScope h_scope(isolate1);
776 v8::Local<v8::Context> context = v8::Context::New(isolate1); 758 v8::Local<v8::Context> context = v8::Context::New(isolate1);
777 delete[] data1.data; // We can dispose of the snapshot blob now. 759 delete[] data1.data; // We can dispose of the snapshot blob now.
778 v8::Context::Scope c_scope(context); 760 v8::Context::Scope c_scope(context);
779 v8::Maybe<int32_t> result = CompileRun("f()")->Int32Value(context); 761 v8::Maybe<int32_t> result = CompileRun("f()")->Int32Value(context);
780 CHECK_EQ(42, result.FromJust()); 762 CHECK_EQ(42, result.FromJust());
781 } 763 }
(...skipping 11 matching lines...) Expand all
793 " b.push(c);" 775 " b.push(c);"
794 " b = c;" 776 " b = c;"
795 "}"; 777 "}";
796 778
797 v8::StartupData data = v8::V8::CreateSnapshotDataBlob(source); 779 v8::StartupData data = v8::V8::CreateSnapshotDataBlob(source);
798 780
799 v8::Isolate::CreateParams params; 781 v8::Isolate::CreateParams params;
800 params.snapshot_blob = &data; 782 params.snapshot_blob = &data;
801 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 783 params.array_buffer_allocator = CcTest::array_buffer_allocator();
802 784
803 // Test-appropriate equivalent of v8::Isolate::New. 785 v8::Isolate* isolate = v8::Isolate::New(params);
804 v8::Isolate* isolate = TestIsolate::New(params);
805 { 786 {
806 v8::Isolate::Scope i_scope(isolate); 787 v8::Isolate::Scope i_scope(isolate);
807 v8::HandleScope h_scope(isolate); 788 v8::HandleScope h_scope(isolate);
808 v8::Local<v8::Context> context = v8::Context::New(isolate); 789 v8::Local<v8::Context> context = v8::Context::New(isolate);
809 delete[] data.data; // We can dispose of the snapshot blob now. 790 delete[] data.data; // We can dispose of the snapshot blob now.
810 v8::Context::Scope c_scope(context); 791 v8::Context::Scope c_scope(context);
811 const char* test = 792 const char* test =
812 "var sum = 0;" 793 "var sum = 0;"
813 "while (a) {" 794 "while (a) {"
814 " sum += a[0];" 795 " sum += a[0];"
(...skipping 19 matching lines...) Expand all
834 const char* warmup = "Math.abs(1); Math.random = 1;"; 815 const char* warmup = "Math.abs(1); Math.random = 1;";
835 816
836 v8::StartupData cold = v8::V8::CreateSnapshotDataBlob(); 817 v8::StartupData cold = v8::V8::CreateSnapshotDataBlob();
837 v8::StartupData warm = v8::V8::WarmUpSnapshotDataBlob(cold, warmup); 818 v8::StartupData warm = v8::V8::WarmUpSnapshotDataBlob(cold, warmup);
838 delete[] cold.data; 819 delete[] cold.data;
839 820
840 v8::Isolate::CreateParams params; 821 v8::Isolate::CreateParams params;
841 params.snapshot_blob = &warm; 822 params.snapshot_blob = &warm;
842 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 823 params.array_buffer_allocator = CcTest::array_buffer_allocator();
843 824
844 // Test-appropriate equivalent of v8::Isolate::New. 825 v8::Isolate* isolate = v8::Isolate::New(params);
845 v8::Isolate* isolate = TestIsolate::New(params);
846 { 826 {
847 v8::Isolate::Scope i_scope(isolate); 827 v8::Isolate::Scope i_scope(isolate);
848 v8::HandleScope h_scope(isolate); 828 v8::HandleScope h_scope(isolate);
849 v8::Local<v8::Context> context = v8::Context::New(isolate); 829 v8::Local<v8::Context> context = v8::Context::New(isolate);
850 delete[] warm.data; 830 delete[] warm.data;
851 v8::Context::Scope c_scope(context); 831 v8::Context::Scope c_scope(context);
852 // Running the warmup script has effect on whether functions are 832 // Running the warmup script has effect on whether functions are
853 // pre-compiled, but does not pollute the context. 833 // pre-compiled, but does not pollute the context.
854 CHECK(IsCompiled("Math.abs")); 834 CHECK(IsCompiled("Math.abs"));
855 CHECK(!IsCompiled("String.raw")); 835 CHECK(!IsCompiled("String.raw"));
(...skipping 12 matching lines...) Expand all
868 const char* warmup = "a = f()"; 848 const char* warmup = "a = f()";
869 849
870 v8::StartupData cold = v8::V8::CreateSnapshotDataBlob(source); 850 v8::StartupData cold = v8::V8::CreateSnapshotDataBlob(source);
871 v8::StartupData warm = v8::V8::WarmUpSnapshotDataBlob(cold, warmup); 851 v8::StartupData warm = v8::V8::WarmUpSnapshotDataBlob(cold, warmup);
872 delete[] cold.data; 852 delete[] cold.data;
873 853
874 v8::Isolate::CreateParams params; 854 v8::Isolate::CreateParams params;
875 params.snapshot_blob = &warm; 855 params.snapshot_blob = &warm;
876 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 856 params.array_buffer_allocator = CcTest::array_buffer_allocator();
877 857
878 // Test-appropriate equivalent of v8::Isolate::New. 858 v8::Isolate* isolate = v8::Isolate::New(params);
879 v8::Isolate* isolate = TestIsolate::New(params);
880 { 859 {
881 v8::Isolate::Scope i_scope(isolate); 860 v8::Isolate::Scope i_scope(isolate);
882 v8::HandleScope h_scope(isolate); 861 v8::HandleScope h_scope(isolate);
883 v8::Local<v8::Context> context = v8::Context::New(isolate); 862 v8::Local<v8::Context> context = v8::Context::New(isolate);
884 delete[] warm.data; 863 delete[] warm.data;
885 v8::Context::Scope c_scope(context); 864 v8::Context::Scope c_scope(context);
886 // Running the warmup script has effect on whether functions are 865 // Running the warmup script has effect on whether functions are
887 // pre-compiled, but does not pollute the context. 866 // pre-compiled, but does not pollute the context.
888 CHECK(IsCompiled("f")); 867 CHECK(IsCompiled("f"));
889 CHECK(IsCompiled("Math.abs")); 868 CHECK(IsCompiled("Math.abs"));
(...skipping 15 matching lines...) Expand all
905 STATIC_CHAR_VECTOR("a.push(function() {return 7});"), 884 STATIC_CHAR_VECTOR("a.push(function() {return 7});"),
906 STATIC_CHAR_VECTOR("\0"), 10000); 885 STATIC_CHAR_VECTOR("\0"), 10000);
907 886
908 v8::StartupData data = v8::V8::CreateSnapshotDataBlob( 887 v8::StartupData data = v8::V8::CreateSnapshotDataBlob(
909 reinterpret_cast<const char*>(source.start())); 888 reinterpret_cast<const char*>(source.start()));
910 889
911 v8::Isolate::CreateParams params; 890 v8::Isolate::CreateParams params;
912 params.snapshot_blob = &data; 891 params.snapshot_blob = &data;
913 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 892 params.array_buffer_allocator = CcTest::array_buffer_allocator();
914 893
915 // Test-appropriate equivalent of v8::Isolate::New. 894 v8::Isolate* isolate = v8::Isolate::New(params);
916 v8::Isolate* isolate = TestIsolate::New(params);
917 { 895 {
918 v8::Isolate::Scope i_scope(isolate); 896 v8::Isolate::Scope i_scope(isolate);
919 v8::HandleScope h_scope(isolate); 897 v8::HandleScope h_scope(isolate);
920 v8::Local<v8::Context> context = v8::Context::New(isolate); 898 v8::Local<v8::Context> context = v8::Context::New(isolate);
921 delete[] data.data; // We can dispose of the snapshot blob now. 899 delete[] data.data; // We can dispose of the snapshot blob now.
922 v8::Context::Scope c_scope(context); 900 v8::Context::Scope c_scope(context);
923 CHECK_EQ(7, CompileRun("a[0]()")->Int32Value(context).FromJust()); 901 CHECK_EQ(7, CompileRun("a[0]()")->Int32Value(context).FromJust());
924 } 902 }
925 isolate->Dispose(); 903 isolate->Dispose();
926 source.Dispose(); 904 source.Dispose();
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 v8::Local<v8::Context> context = v8::Context::New(isolate); 1899 v8::Local<v8::Context> context = v8::Context::New(isolate);
1922 CHECK_EQ(1u, creator.AddContext(context)); 1900 CHECK_EQ(1u, creator.AddContext(context));
1923 } 1901 }
1924 blob = 1902 blob =
1925 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); 1903 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
1926 } 1904 }
1927 1905
1928 v8::Isolate::CreateParams params; 1906 v8::Isolate::CreateParams params;
1929 params.snapshot_blob = &blob; 1907 params.snapshot_blob = &blob;
1930 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 1908 params.array_buffer_allocator = CcTest::array_buffer_allocator();
1931 // Test-appropriate equivalent of v8::Isolate::New. 1909 v8::Isolate* isolate = v8::Isolate::New(params);
1932 v8::Isolate* isolate = TestIsolate::New(params);
1933 { 1910 {
1934 v8::Isolate::Scope isolate_scope(isolate); 1911 v8::Isolate::Scope isolate_scope(isolate);
1935 { 1912 {
1936 v8::HandleScope handle_scope(isolate); 1913 v8::HandleScope handle_scope(isolate);
1937 v8::Local<v8::Context> context = v8::Context::New(isolate); 1914 v8::Local<v8::Context> context = v8::Context::New(isolate);
1938 v8::Context::Scope context_scope(context); 1915 v8::Context::Scope context_scope(context);
1939 ExpectInt32("f()", 1); 1916 ExpectInt32("f()", 1);
1940 } 1917 }
1941 { 1918 {
1942 v8::HandleScope handle_scope(isolate); 1919 v8::HandleScope handle_scope(isolate);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 blob = 2021 blob =
2045 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); 2022 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
2046 } 2023 }
2047 2024
2048 // Deserialize with the original external reference. 2025 // Deserialize with the original external reference.
2049 { 2026 {
2050 v8::Isolate::CreateParams params; 2027 v8::Isolate::CreateParams params;
2051 params.snapshot_blob = &blob; 2028 params.snapshot_blob = &blob;
2052 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 2029 params.array_buffer_allocator = CcTest::array_buffer_allocator();
2053 params.external_references = original_external_references; 2030 params.external_references = original_external_references;
2054 // Test-appropriate equivalent of v8::Isolate::New. 2031 v8::Isolate* isolate = v8::Isolate::New(params);
2055 v8::Isolate* isolate = TestIsolate::New(params);
2056 { 2032 {
2057 v8::Isolate::Scope isolate_scope(isolate); 2033 v8::Isolate::Scope isolate_scope(isolate);
2058 v8::HandleScope handle_scope(isolate); 2034 v8::HandleScope handle_scope(isolate);
2059 v8::Local<v8::Context> context = v8::Context::New(isolate); 2035 v8::Local<v8::Context> context = v8::Context::New(isolate);
2060 v8::Context::Scope context_scope(context); 2036 v8::Context::Scope context_scope(context);
2061 ExpectInt32("f()", 42); 2037 ExpectInt32("f()", 42);
2062 } 2038 }
2063 isolate->Dispose(); 2039 isolate->Dispose();
2064 } 2040 }
2065 2041
2066 // Deserialize with the some other external reference. 2042 // Deserialize with the some other external reference.
2067 { 2043 {
2068 v8::Isolate::CreateParams params; 2044 v8::Isolate::CreateParams params;
2069 params.snapshot_blob = &blob; 2045 params.snapshot_blob = &blob;
2070 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 2046 params.array_buffer_allocator = CcTest::array_buffer_allocator();
2071 params.external_references = replaced_external_references; 2047 params.external_references = replaced_external_references;
2072 // Test-appropriate equivalent of v8::Isolate::New. 2048 v8::Isolate* isolate = v8::Isolate::New(params);
2073 v8::Isolate* isolate = TestIsolate::New(params);
2074 { 2049 {
2075 v8::Isolate::Scope isolate_scope(isolate); 2050 v8::Isolate::Scope isolate_scope(isolate);
2076 v8::HandleScope handle_scope(isolate); 2051 v8::HandleScope handle_scope(isolate);
2077 v8::Local<v8::Context> context = v8::Context::New(isolate); 2052 v8::Local<v8::Context> context = v8::Context::New(isolate);
2078 v8::Context::Scope context_scope(context); 2053 v8::Context::Scope context_scope(context);
2079 ExpectInt32("f()", 1337); 2054 ExpectInt32("f()", 1337);
2080 } 2055 }
2081 isolate->Dispose(); 2056 isolate->Dispose();
2082 } 2057 }
2083 delete[] blob.data; 2058 delete[] blob.data;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2196 delete a1; 2171 delete a1;
2197 delete b0; 2172 delete b0;
2198 delete c0; 2173 delete c0;
2199 } 2174 }
2200 2175
2201 { 2176 {
2202 v8::Isolate::CreateParams params; 2177 v8::Isolate::CreateParams params;
2203 params.snapshot_blob = &blob; 2178 params.snapshot_blob = &blob;
2204 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 2179 params.array_buffer_allocator = CcTest::array_buffer_allocator();
2205 params.external_references = original_external_references; 2180 params.external_references = original_external_references;
2206 // Test-appropriate equivalent of v8::Isolate::New. 2181 v8::Isolate* isolate = v8::Isolate::New(params);
2207 v8::Isolate* isolate = TestIsolate::New(params);
2208 { 2182 {
2209 v8::Isolate::Scope isolate_scope(isolate); 2183 v8::Isolate::Scope isolate_scope(isolate);
2210 { 2184 {
2211 // Create a new context without a new object template. 2185 // Create a new context without a new object template.
2212 v8::HandleScope handle_scope(isolate); 2186 v8::HandleScope handle_scope(isolate);
2213 v8::Local<v8::Context> context = 2187 v8::Local<v8::Context> context =
2214 v8::Context::FromSnapshot( 2188 v8::Context::FromSnapshot(
2215 isolate, 0, 2189 isolate, 0,
2216 v8::DeserializeInternalFieldsCallback( 2190 v8::DeserializeInternalFieldsCallback(
2217 DeserializeInternalFields, reinterpret_cast<void*>(2017))) 2191 DeserializeInternalFields, reinterpret_cast<void*>(2017)))
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2374 } 2348 }
2375 blob = 2349 blob =
2376 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); 2350 creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
2377 } 2351 }
2378 2352
2379 { 2353 {
2380 v8::Isolate::CreateParams params; 2354 v8::Isolate::CreateParams params;
2381 params.snapshot_blob = &blob; 2355 params.snapshot_blob = &blob;
2382 params.array_buffer_allocator = CcTest::array_buffer_allocator(); 2356 params.array_buffer_allocator = CcTest::array_buffer_allocator();
2383 params.external_references = original_external_references; 2357 params.external_references = original_external_references;
2384 // Test-appropriate equivalent of v8::Isolate::New. 2358 v8::Isolate* isolate = v8::Isolate::New(params);
2385 v8::Isolate* isolate = TestIsolate::New(params);
2386 { 2359 {
2387 v8::Isolate::Scope isolate_scope(isolate); 2360 v8::Isolate::Scope isolate_scope(isolate);
2388 // We can introduce new extensions, which could override the already 2361 // We can introduce new extensions, which could override the already
2389 // snapshotted extension. 2362 // snapshotted extension.
2390 v8::Extension* extension = new v8::Extension("new extension", 2363 v8::Extension* extension = new v8::Extension("new extension",
2391 "function i() { return 24; }" 2364 "function i() { return 24; }"
2392 "function j() { return 25; }" 2365 "function j() { return 25; }"
2393 "if (o.p == 7) o.p++;"); 2366 "if (o.p == 7) o.p++;");
2394 extension->set_auto_enable(true); 2367 extension->set_auto_enable(true);
2395 v8::RegisterExtension(extension); 2368 v8::RegisterExtension(extension);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2486 } 2459 }
2487 delete[] blob.data; 2460 delete[] blob.data;
2488 } 2461 }
2489 2462
2490 TEST(SerializationMemoryStats) { 2463 TEST(SerializationMemoryStats) {
2491 FLAG_profile_deserialization = true; 2464 FLAG_profile_deserialization = true;
2492 FLAG_always_opt = false; 2465 FLAG_always_opt = false;
2493 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); 2466 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob();
2494 delete[] blob.data; 2467 delete[] blob.data;
2495 } 2468 }
OLDNEW
« no previous file with comments | « test/cctest/setup-isolate-for-tests.cc ('k') | test/unittests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698