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