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

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

Issue 1805903002: [serializer] Add API to warm up startup snapshot with an additional script. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix comment Created 4 years, 9 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/startup-serializer.cc ('k') | tools/gyp/v8.gyp » ('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 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 " a = a[1];" 776 " a = a[1];"
777 "}" 777 "}"
778 "sum"; 778 "sum";
779 v8::Maybe<int32_t> result = 779 v8::Maybe<int32_t> result =
780 CompileRun(test)->Int32Value(isolate->GetCurrentContext()); 780 CompileRun(test)->Int32Value(isolate->GetCurrentContext());
781 CHECK_EQ(9999 * 5000, result.FromJust()); 781 CHECK_EQ(9999 * 5000, result.FromJust());
782 } 782 }
783 isolate->Dispose(); 783 isolate->Dispose();
784 } 784 }
785 785
786 bool IsCompiled(const char* name) {
787 return i::Handle<i::JSFunction>::cast(
788 v8::Utils::OpenHandle(*CompileRun(name)))
789 ->shared()
790 ->is_compiled();
791 }
792
793 TEST(SnapshotDataBlobWithWarmup) {
794 DisableTurbofan();
795 const char* warmup = "Math.tan(1); Math.sin = 1;";
796
797 v8::StartupData cold = v8::V8::CreateSnapshotDataBlob();
798 v8::StartupData warm = v8::V8::WarmUpSnapshotDataBlob(cold, warmup);
799 delete[] cold.data;
800
801 v8::Isolate::CreateParams params;
802 params.snapshot_blob = &warm;
803 params.array_buffer_allocator = CcTest::array_buffer_allocator();
804
805 v8::Isolate* isolate = v8::Isolate::New(params);
806 {
807 v8::Isolate::Scope i_scope(isolate);
808 v8::HandleScope h_scope(isolate);
809 v8::Local<v8::Context> context = v8::Context::New(isolate);
810 delete[] warm.data;
811 v8::Context::Scope c_scope(context);
812 // Running the warmup script has effect on whether functions are
813 // pre-compiled, but does not pollute the context.
814 CHECK(IsCompiled("Math.tan"));
815 CHECK(!IsCompiled("Math.cos"));
816 CHECK(CompileRun("Math.sin")->IsFunction());
817 }
818 isolate->Dispose();
819 }
820
821 TEST(CustomSnapshotDataBlobWithWarmup) {
822 DisableTurbofan();
823 const char* source =
824 "function f() { return Math.sin(1); }\n"
825 "function g() { return Math.cos(1); }\n"
826 "Math.tan(1);"
827 "var a = 5";
828 const char* warmup = "a = f()";
829
830 v8::StartupData cold = v8::V8::CreateSnapshotDataBlob(source);
831 v8::StartupData warm = v8::V8::WarmUpSnapshotDataBlob(cold, warmup);
832 delete[] cold.data;
833
834 v8::Isolate::CreateParams params;
835 params.snapshot_blob = &warm;
836 params.array_buffer_allocator = CcTest::array_buffer_allocator();
837
838 v8::Isolate* isolate = v8::Isolate::New(params);
839 {
840 v8::Isolate::Scope i_scope(isolate);
841 v8::HandleScope h_scope(isolate);
842 v8::Local<v8::Context> context = v8::Context::New(isolate);
843 delete[] warm.data;
844 v8::Context::Scope c_scope(context);
845 // Running the warmup script has effect on whether functions are
846 // pre-compiled, but does not pollute the context.
847 CHECK(IsCompiled("f"));
848 CHECK(IsCompiled("Math.sin"));
849 CHECK(!IsCompiled("g"));
850 CHECK(!IsCompiled("Math.cos"));
851 CHECK(!IsCompiled("Math.tan"));
852 CHECK_EQ(5, CompileRun("a")->Int32Value(context).FromJust());
853 }
854 isolate->Dispose();
855 }
786 856
787 TEST(TestThatAlwaysSucceeds) { 857 TEST(TestThatAlwaysSucceeds) {
788 } 858 }
789 859
790 860
791 TEST(TestThatAlwaysFails) { 861 TEST(TestThatAlwaysFails) {
792 bool ArtificialFailure = false; 862 bool ArtificialFailure = false;
793 CHECK(ArtificialFailure); 863 CHECK(ArtificialFailure);
794 } 864 }
795 865
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 delete script_data; 1803 delete script_data;
1734 } 1804 }
1735 1805
1736 1806
1737 TEST(SerializationMemoryStats) { 1807 TEST(SerializationMemoryStats) {
1738 FLAG_profile_deserialization = true; 1808 FLAG_profile_deserialization = true;
1739 FLAG_always_opt = false; 1809 FLAG_always_opt = false;
1740 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); 1810 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob();
1741 delete[] blob.data; 1811 delete[] blob.data;
1742 } 1812 }
OLDNEW
« no previous file with comments | « src/snapshot/startup-serializer.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698