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

Side by Side Diff: src/snapshot/mksnapshot.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/deserializer.cc ('k') | src/snapshot/partial-serializer.h » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <errno.h> 5 #include <errno.h>
6 #include <signal.h> 6 #include <signal.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "include/libplatform/libplatform.h" 9 #include "include/libplatform/libplatform.h"
10 #include "src/assembler.h" 10 #include "src/assembler.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 i::PrintF("Unable to open file \"%s\" for writing.\n", filename); 102 i::PrintF("Unable to open file \"%s\" for writing.\n", filename);
103 exit(1); 103 exit(1);
104 } 104 }
105 return fp; 105 return fp;
106 } 106 }
107 107
108 FILE* fp_; 108 FILE* fp_;
109 FILE* startup_blob_file_; 109 FILE* startup_blob_file_;
110 }; 110 };
111 111
112 112 char* GetExtraCode(char* filename, const char* description) {
113 char* GetExtraCode(char* filename) {
114 if (filename == NULL || strlen(filename) == 0) return NULL; 113 if (filename == NULL || strlen(filename) == 0) return NULL;
115 ::printf("Embedding extra script: %s\n", filename); 114 if (strcmp(filename, "-") == 0) return NULL;
115 ::printf("Loading script for %s: %s\n", description, filename);
116 FILE* file = base::OS::FOpen(filename, "rb"); 116 FILE* file = base::OS::FOpen(filename, "rb");
117 if (file == NULL) { 117 if (file == NULL) {
118 fprintf(stderr, "Failed to open '%s': errno %d\n", filename, errno); 118 fprintf(stderr, "Failed to open '%s': errno %d\n", filename, errno);
119 exit(1); 119 exit(1);
120 } 120 }
121 fseek(file, 0, SEEK_END); 121 fseek(file, 0, SEEK_END);
122 size_t size = ftell(file); 122 size_t size = ftell(file);
123 rewind(file); 123 rewind(file);
124 char* chars = new char[size + 1]; 124 char* chars = new char[size + 1];
125 chars[size] = '\0'; 125 chars[size] = '\0';
(...skipping 11 matching lines...) Expand all
137 137
138 138
139 int main(int argc, char** argv) { 139 int main(int argc, char** argv) {
140 // By default, log code create information in the snapshot. 140 // By default, log code create information in the snapshot.
141 i::FLAG_log_code = true; 141 i::FLAG_log_code = true;
142 i::FLAG_logfile_per_isolate = false; 142 i::FLAG_logfile_per_isolate = false;
143 143
144 // Print the usage if an error occurs when parsing the command line 144 // Print the usage if an error occurs when parsing the command line
145 // flags or if the help flag is set. 145 // flags or if the help flag is set.
146 int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true); 146 int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true);
147 if (result > 0 || (argc != 1 && argc != 2) || i::FLAG_help) { 147 if (result > 0 || (argc > 3) || i::FLAG_help) {
148 ::printf("Usage: %s --startup_src=... --startup_blob=... [extras]\n", 148 ::printf("Usage: %s --startup_src=... --startup_blob=... [extras]\n",
149 argv[0]); 149 argv[0]);
150 i::FlagList::PrintHelp(); 150 i::FlagList::PrintHelp();
151 return !i::FLAG_help; 151 return !i::FLAG_help;
152 } 152 }
153 153
154 i::CpuFeatures::Probe(true); 154 i::CpuFeatures::Probe(true);
155 V8::InitializeICU(); 155 V8::InitializeICU();
156 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); 156 v8::Platform* platform = v8::platform::CreateDefaultPlatform();
157 v8::V8::InitializePlatform(platform); 157 v8::V8::InitializePlatform(platform);
158 v8::V8::Initialize(); 158 v8::V8::Initialize();
159 159
160 { 160 {
161 SnapshotWriter writer; 161 SnapshotWriter writer;
162 if (i::FLAG_startup_src) writer.SetSnapshotFile(i::FLAG_startup_src); 162 if (i::FLAG_startup_src) writer.SetSnapshotFile(i::FLAG_startup_src);
163 if (i::FLAG_startup_blob) writer.SetStartupBlobFile(i::FLAG_startup_blob); 163 if (i::FLAG_startup_blob) writer.SetStartupBlobFile(i::FLAG_startup_blob);
164 char* extra_code = GetExtraCode(argc == 2 ? argv[1] : NULL); 164
165 StartupData blob = v8::V8::CreateSnapshotDataBlob(extra_code); 165 char* embed_script = GetExtraCode(argc >= 2 ? argv[1] : NULL, "embedding");
166 StartupData blob = v8::V8::CreateSnapshotDataBlob(embed_script);
167 delete[] embed_script;
168
169 char* warmup_script = GetExtraCode(argc >= 3 ? argv[2] : NULL, "warm up");
170 if (warmup_script) {
171 StartupData cold = blob;
172 blob = v8::V8::WarmUpSnapshotDataBlob(cold, warmup_script);
173 delete[] cold.data;
174 delete[] warmup_script;
175 }
176
166 CHECK(blob.data); 177 CHECK(blob.data);
167 writer.WriteSnapshot(blob); 178 writer.WriteSnapshot(blob);
168 delete[] extra_code;
169 delete[] blob.data; 179 delete[] blob.data;
170 } 180 }
171 181
172 V8::Dispose(); 182 V8::Dispose();
173 V8::ShutdownPlatform(); 183 V8::ShutdownPlatform();
174 delete platform; 184 delete platform;
175 return 0; 185 return 0;
176 } 186 }
OLDNEW
« no previous file with comments | « src/snapshot/deserializer.cc ('k') | src/snapshot/partial-serializer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698