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

Side by Side Diff: runtime/bin/gen_snapshot.cc

Issue 2622053002: Refactor snapshots pieces to include a section for loading instructions into the heap of a regular … (Closed)
Patch Set: . Created 3 years, 11 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 | « runtime/bin/extensions_win.cc ('k') | runtime/bin/main.cc » ('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 (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Generate a snapshot file after loading all the scripts specified on the 5 // Generate a snapshot file after loading all the scripts specified on the
6 // command line. 6 // command line.
7 7
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 exit_code = kErrorExitCode; \ 53 exit_code = kErrorExitCode; \
54 } \ 54 } \
55 Dart_ExitScope(); \ 55 Dart_ExitScope(); \
56 Dart_ShutdownIsolate(); \ 56 Dart_ShutdownIsolate(); \
57 exit(exit_code); \ 57 exit(exit_code); \
58 } 58 }
59 59
60 60
61 // Global state that indicates whether a snapshot is to be created and 61 // Global state that indicates whether a snapshot is to be created and
62 // if so which file to write the snapshot into. 62 // if so which file to write the snapshot into.
63 static const char* vm_isolate_snapshot_filename = NULL; 63 static const char* vm_snapshot_data_filename = NULL;
64 static const char* isolate_snapshot_filename = NULL; 64 static const char* vm_snapshot_instructions_filename = NULL;
65 static const char* isolate_snapshot_data_filename = NULL;
66 static const char* isolate_snapshot_instructions_filename = NULL;
65 static const char* assembly_filename = NULL; 67 static const char* assembly_filename = NULL;
66 static const char* instructions_blob_filename = NULL;
67 static const char* rodata_blob_filename = NULL;
68 68
69 69
70 // Value of the --package-root flag. 70 // Value of the --package-root flag.
71 // (This pointer points into an argv buffer and does not need to be 71 // (This pointer points into an argv buffer and does not need to be
72 // free'd.) 72 // free'd.)
73 static const char* commandline_package_root = NULL; 73 static const char* commandline_package_root = NULL;
74 74
75 // Value of the --packages flag. 75 // Value of the --packages flag.
76 // (This pointer points into an argv buffer and does not need to be 76 // (This pointer points into an argv buffer and does not need to be
77 // free'd.) 77 // free'd.)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 static const char* ProcessOption(const char* option, const char* name) { 183 static const char* ProcessOption(const char* option, const char* name) {
184 const intptr_t length = strlen(name); 184 const intptr_t length = strlen(name);
185 if (strncmp(option, name, length) == 0) { 185 if (strncmp(option, name, length) == 0) {
186 return (option + length); 186 return (option + length);
187 } 187 }
188 return NULL; 188 return NULL;
189 } 189 }
190 190
191 191
192 static bool ProcessVmIsolateSnapshotOption(const char* option) { 192 static bool ProcessVmSnapshotDataOption(const char* option) {
193 const char* name = ProcessOption(option, "--vm_isolate_snapshot="); 193 const char* name = ProcessOption(option, "--vm_snapshot_data=");
194 if (name != NULL) { 194 if (name != NULL) {
195 vm_isolate_snapshot_filename = name; 195 vm_snapshot_data_filename = name;
196 return true; 196 return true;
197 } 197 }
198 return false; 198 return false;
199 } 199 }
200 200
201 201
202 static bool ProcessIsolateSnapshotOption(const char* option) { 202 static bool ProcessVmSnapshotInstructionsOption(const char* option) {
203 const char* name = ProcessOption(option, "--isolate_snapshot="); 203 const char* name = ProcessOption(option, "--vm_snapshot_instructions=");
204 if (name != NULL) { 204 if (name != NULL) {
205 isolate_snapshot_filename = name; 205 vm_snapshot_instructions_filename = name;
206 return true;
207 }
208 return false;
209 }
210
211
212 static bool ProcessIsolateSnapshotDataOption(const char* option) {
213 const char* name = ProcessOption(option, "--isolate_snapshot_data=");
214 if (name != NULL) {
215 isolate_snapshot_data_filename = name;
216 return true;
217 }
218 return false;
219 }
220
221
222 static bool ProcessIsolateSnapshotInstructionsOption(const char* option) {
223 const char* name = ProcessOption(option, "--isolate_snapshot_instructions=");
224 if (name != NULL) {
225 isolate_snapshot_instructions_filename = name;
206 return true; 226 return true;
207 } 227 }
208 return false; 228 return false;
209 } 229 }
210 230
211 231
212 static bool ProcessAssemblyOption(const char* option) { 232 static bool ProcessAssemblyOption(const char* option) {
213 const char* name = ProcessOption(option, "--assembly="); 233 const char* name = ProcessOption(option, "--assembly=");
214 if (name != NULL) { 234 if (name != NULL) {
215 assembly_filename = name; 235 assembly_filename = name;
216 return true; 236 return true;
217 } 237 }
218 return false; 238 return false;
219 }
220
221
222 static bool ProcessInstructionsBlobOption(const char* option) {
223 const char* name = ProcessOption(option, "--instructions_blob=");
224 if (name != NULL) {
225 instructions_blob_filename = name;
226 return true;
227 }
228 return false;
229 }
230
231
232 static bool ProcessRodataBlobOption(const char* option) {
233 const char* name = ProcessOption(option, "--rodata_blob=");
234 if (name != NULL) {
235 rodata_blob_filename = name;
236 return true;
237 }
238 return false;
239 } 239 }
240 240
241 241
242 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) { 242 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) {
243 const char* name = ProcessOption(option, "--embedder_entry_points_manifest="); 243 const char* name = ProcessOption(option, "--embedder_entry_points_manifest=");
244 if (name != NULL) { 244 if (name != NULL) {
245 entry_points_files->AddArgument(name); 245 entry_points_files->AddArgument(name);
246 return true; 246 return true;
247 } 247 }
248 return false; 248 return false;
(...skipping 30 matching lines...) Expand all
279 } 279 }
280 if (mapping != NULL) { 280 if (mapping != NULL) {
281 DartUtils::url_mapping->AddArgument(mapping); 281 DartUtils::url_mapping->AddArgument(mapping);
282 return true; 282 return true;
283 } 283 }
284 return false; 284 return false;
285 } 285 }
286 286
287 287
288 static bool IsSnapshottingForPrecompilation() { 288 static bool IsSnapshottingForPrecompilation() {
289 return (assembly_filename != NULL) || (instructions_blob_filename != NULL); 289 return (assembly_filename != NULL) ||
290 (vm_snapshot_instructions_filename != NULL);
290 } 291 }
291 292
292 293
293 // Parse out the command line arguments. Returns -1 if the arguments 294 // Parse out the command line arguments. Returns -1 if the arguments
294 // are incorrect, 0 otherwise. 295 // are incorrect, 0 otherwise.
295 static int ParseArguments(int argc, 296 static int ParseArguments(int argc,
296 char** argv, 297 char** argv,
297 CommandLineOptions* vm_options, 298 CommandLineOptions* vm_options,
298 char** script_name) { 299 char** script_name) {
299 const char* kPrefix = "-"; 300 const char* kPrefix = "-";
300 const intptr_t kPrefixLen = strlen(kPrefix); 301 const intptr_t kPrefixLen = strlen(kPrefix);
301 302
302 // Skip the binary name. 303 // Skip the binary name.
303 int i = 1; 304 int i = 1;
304 305
305 // Parse out the vm options. 306 // Parse out the vm options.
306 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { 307 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) {
307 if (ProcessVmIsolateSnapshotOption(argv[i]) || 308 if (ProcessVmSnapshotDataOption(argv[i]) ||
308 ProcessIsolateSnapshotOption(argv[i]) || 309 ProcessVmSnapshotInstructionsOption(argv[i]) ||
310 ProcessIsolateSnapshotDataOption(argv[i]) ||
311 ProcessIsolateSnapshotInstructionsOption(argv[i]) ||
309 ProcessAssemblyOption(argv[i]) || 312 ProcessAssemblyOption(argv[i]) ||
310 ProcessInstructionsBlobOption(argv[i]) ||
311 ProcessRodataBlobOption(argv[i]) ||
312 ProcessEmbedderEntryPointsManifestOption(argv[i]) || 313 ProcessEmbedderEntryPointsManifestOption(argv[i]) ||
313 ProcessURLmappingOption(argv[i]) || ProcessPackageRootOption(argv[i]) || 314 ProcessURLmappingOption(argv[i]) || ProcessPackageRootOption(argv[i]) ||
314 ProcessPackagesOption(argv[i]) || ProcessEnvironmentOption(argv[i])) { 315 ProcessPackagesOption(argv[i]) || ProcessEnvironmentOption(argv[i])) {
315 i += 1; 316 i += 1;
316 continue; 317 continue;
317 } 318 }
318 vm_options->AddArgument(argv[i]); 319 vm_options->AddArgument(argv[i]);
319 i += 1; 320 i += 1;
320 } 321 }
321 322
322 // Get the script name. 323 // Get the script name.
323 if (i < argc) { 324 if (i < argc) {
324 *script_name = argv[i]; 325 *script_name = argv[i];
325 i += 1; 326 i += 1;
326 } else { 327 } else {
327 *script_name = NULL; 328 *script_name = NULL;
328 } 329 }
329 330
330 // Verify consistency of arguments. 331 // Verify consistency of arguments.
331 if ((commandline_package_root != NULL) && 332 if ((commandline_package_root != NULL) &&
332 (commandline_packages_file != NULL)) { 333 (commandline_packages_file != NULL)) {
333 Log::PrintErr( 334 Log::PrintErr(
334 "Specifying both a packages directory and a packages " 335 "Specifying both a packages directory and a packages "
335 "file is invalid.\n"); 336 "file is invalid.\n");
336 return -1; 337 return -1;
337 } 338 }
338 339
339 if (vm_isolate_snapshot_filename == NULL) { 340 if (vm_snapshot_data_filename == NULL) {
340 Log::PrintErr("No vm isolate snapshot output file specified.\n\n"); 341 Log::PrintErr("No vm snapshot output file specified.\n\n");
341 return -1; 342 return -1;
342 } 343 }
343 344
344 if (isolate_snapshot_filename == NULL) { 345 if (isolate_snapshot_data_filename == NULL) {
345 Log::PrintErr("No isolate snapshot output file specified.\n\n"); 346 Log::PrintErr("No isolate snapshot output file specified.\n\n");
346 return -1; 347 return -1;
347 } 348 }
348 349
349 bool precompiled_as_assembly = assembly_filename != NULL; 350 bool precompiled_as_assembly = assembly_filename != NULL;
350 bool precompiled_as_blobs = 351 bool precompiled_as_blobs = (vm_snapshot_instructions_filename != NULL) ||
351 (instructions_blob_filename != NULL) || (rodata_blob_filename != NULL); 352 (isolate_snapshot_instructions_filename != NULL);
352 if (precompiled_as_assembly && precompiled_as_blobs) { 353 if (precompiled_as_assembly && precompiled_as_blobs) {
353 Log::PrintErr( 354 Log::PrintErr(
354 "Cannot request a precompiled snapshot simultaneously as " 355 "Cannot request a precompiled snapshot simultaneously as "
355 "assembly (--assembly=<output.file>) and as blobs " 356 "assembly (--assembly=<output.file>) and as blobs "
356 "(--instructions-blob=<output.file> and " 357 "(--instructions-blob=<output.file> and "
357 "--rodata-blob=<output.file>)\n\n"); 358 "--rodata-blob=<output.file>)\n\n");
358 return -1; 359 return -1;
359 } 360 }
360 if ((instructions_blob_filename != NULL) != (rodata_blob_filename != NULL)) { 361 if ((vm_snapshot_instructions_filename != NULL) !=
362 (isolate_snapshot_instructions_filename != NULL)) {
361 Log::PrintErr( 363 Log::PrintErr(
362 "Requesting a precompiled snapshot as blobs requires both " 364 "Requesting a precompiled snapshot as blobs requires both "
363 "(--instructions-blob=<output.file> and " 365 "(--vm_snapshot_instructions=<output.file> and "
364 "--rodata-blob=<output.file>)\n\n"); 366 "--isolate_snapshot_instructions=<output.file>)\n\n");
365 return -1; 367 return -1;
366 } 368 }
367 if (IsSnapshottingForPrecompilation() && (entry_points_files->count() == 0)) { 369 if (IsSnapshottingForPrecompilation() && (entry_points_files->count() == 0)) {
368 Log::PrintErr( 370 Log::PrintErr(
369 "Specifying an instructions snapshot filename indicates precompilation" 371 "Specifying an instructions snapshot filename indicates precompilation"
370 ". But no embedder entry points manifest was specified.\n\n"); 372 ". But no embedder entry points manifest was specified.\n\n");
371 return -1; 373 return -1;
372 } 374 }
373 375
374 return 0; 376 return 0;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 " Not specifying these may cause the tree shaker to remove them from the \n" 635 " Not specifying these may cause the tree shaker to remove them from the \n"
634 " program. The format of this manifest is as follows. Each line in the \n" 636 " program. The format of this manifest is as follows. Each line in the \n"
635 " manifest is a comma separated list of three elements. The first entry is \n" 637 " manifest is a comma separated list of three elements. The first entry is \n"
636 " the library URI, the second entry is the class name and the final entry \n" 638 " the library URI, the second entry is the class name and the final entry \n"
637 " the function name. The file must be terminated with a newline charater. \n" 639 " the function name. The file must be terminated with a newline charater. \n"
638 " \n" 640 " \n"
639 " Example: \n" 641 " Example: \n"
640 " dart:something,SomeClass,doSomething \n" 642 " dart:something,SomeClass,doSomething \n"
641 " \n" 643 " \n"
642 " Supported options: \n" 644 " Supported options: \n"
643 " --vm_isolate_snapshot=<file> A full snapshot is a compact \n" 645 " --vm_snapshot_data=<file> A full snapshot is a compact \n"
644 " --isolate_snapshot=<file> representation of the dart vm isolate \n" 646 " --isolate_snapshot_data=<file> representation of the dart vm isolate \n"
645 " heap and dart isolate heap states. \n" 647 " heap and dart isolate heap states. \n"
646 " Both these options are required \n" 648 " Both these options are required \n"
647 " \n" 649 " \n"
648 " --package_root=<path> Where to find packages, that is, \n" 650 " --package_root=<path> Where to find packages, that is, \n"
649 " package:... imports. \n" 651 " package:... imports. \n"
650 " \n" 652 " \n"
651 " --packages=<packages_file> Where to find a package spec file \n" 653 " --packages=<packages_file> Where to find a package spec file \n"
652 " \n" 654 " \n"
653 " --url_mapping=<mapping> Uses the URL mapping(s) specified on \n" 655 " --url_mapping=<mapping> Uses the URL mapping(s) specified on \n"
654 " the command line to load the \n" 656 " the command line to load the \n"
655 " libraries. \n" 657 " libraries. \n"
656 " \n" 658 " \n"
657 " --assembly=<file> (Precompilation only) Contains the \n" 659 " --assembly=<file> (Precompilation only) Contains the \n"
658 " assembly that must be linked into \n" 660 " assembly that must be linked into \n"
659 " the target binary \n" 661 " the target binary \n"
660 " \n" 662 " \n"
661 " --instructions_blob=<file> (Precompilation only) Contains the \n" 663 " --vm_snapshot_instructions=<file> (Precompilation only) Contains the \n"
662 " --rodata_blob=<file> instructions and read-only data that \n" 664 " --isolate_snapshot_instructions=<file> instructions and read-only data \n"
663 " must be mapped into the target binary \n" 665 " that must be mapped into the target \n"
666 " binary \n"
664 " \n" 667 " \n"
665 " --embedder_entry_points_manifest=<file> (Precompilation or app \n" 668 " --embedder_entry_points_manifest=<file> (Precompilation or app \n"
666 " snapshots) Contains embedder's entry \n" 669 " snapshots) Contains embedder's entry \n"
667 " points into Dart code from the C API. \n" 670 " points into Dart code from the C API. \n"
668 "\n"); 671 "\n");
669 } 672 }
670 // clang-format on 673 // clang-format on
671 674
672 675
673 static void VerifyLoaded(Dart_Handle library) { 676 static void VerifyLoaded(Dart_Handle library) {
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 "Could not find native embedder entry points during precompilation\n"); 1023 "Could not find native embedder entry points during precompilation\n");
1021 exit(kErrorExitCode); 1024 exit(kErrorExitCode);
1022 } 1025 }
1023 return entries; 1026 return entries;
1024 } 1027 }
1025 1028
1026 1029
1027 static void CreateAndWriteSnapshot() { 1030 static void CreateAndWriteSnapshot() {
1028 ASSERT(!IsSnapshottingForPrecompilation()); 1031 ASSERT(!IsSnapshottingForPrecompilation());
1029 Dart_Handle result; 1032 Dart_Handle result;
1030 uint8_t* vm_isolate_buffer = NULL; 1033 uint8_t* vm_snapshot_data_buffer = NULL;
1031 intptr_t vm_isolate_size = 0; 1034 intptr_t vm_snapshot_data_size = 0;
1032 uint8_t* isolate_buffer = NULL; 1035 uint8_t* isolate_snapshot_data_buffer = NULL;
1033 intptr_t isolate_size = 0; 1036 intptr_t isolate_snapshot_data_size = 0;
1034 1037
1035 // First create a snapshot. 1038 // First create a snapshot.
1036 result = Dart_CreateSnapshot(&vm_isolate_buffer, &vm_isolate_size, 1039 result = Dart_CreateSnapshot(&vm_snapshot_data_buffer, &vm_snapshot_data_size,
1037 &isolate_buffer, &isolate_size); 1040 &isolate_snapshot_data_buffer,
1041 &isolate_snapshot_data_size);
1038 CHECK_RESULT(result); 1042 CHECK_RESULT(result);
1039 1043
1040 // Now write the vm isolate and isolate snapshots out to the 1044 // Now write the vm isolate and isolate snapshots out to the
1041 // specified file and exit. 1045 // specified file and exit.
1042 WriteSnapshotFile(vm_isolate_snapshot_filename, vm_isolate_buffer, 1046 WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer,
1043 vm_isolate_size); 1047 vm_snapshot_data_size);
1044 WriteSnapshotFile(isolate_snapshot_filename, isolate_buffer, isolate_size); 1048 WriteSnapshotFile(isolate_snapshot_data_filename,
1049 isolate_snapshot_data_buffer, isolate_snapshot_data_size);
1045 Dart_ExitScope(); 1050 Dart_ExitScope();
1046 1051
1047 // Shutdown the isolate. 1052 // Shutdown the isolate.
1048 Dart_ShutdownIsolate(); 1053 Dart_ShutdownIsolate();
1049 } 1054 }
1050 1055
1051 1056
1052 static void CreateAndWritePrecompiledSnapshot( 1057 static void CreateAndWritePrecompiledSnapshot(
1053 Dart_QualifiedFunctionName* standalone_entry_points) { 1058 Dart_QualifiedFunctionName* standalone_entry_points) {
1054 ASSERT(IsSnapshottingForPrecompilation()); 1059 ASSERT(IsSnapshottingForPrecompilation());
1055 Dart_Handle result; 1060 Dart_Handle result;
1056 1061
1057 // Precompile with specified embedder entry points 1062 // Precompile with specified embedder entry points
1058 result = Dart_Precompile(standalone_entry_points, NULL, 0); 1063 result = Dart_Precompile(standalone_entry_points, NULL, 0);
1059 CHECK_RESULT(result); 1064 CHECK_RESULT(result);
1060 1065
1061 // Create a precompiled snapshot. 1066 // Create a precompiled snapshot.
1062 bool as_assembly = assembly_filename != NULL; 1067 bool as_assembly = assembly_filename != NULL;
1063 if (as_assembly) { 1068 if (as_assembly) {
1064 uint8_t* assembly_buffer = NULL; 1069 uint8_t* assembly_buffer = NULL;
1065 intptr_t assembly_size = 0; 1070 intptr_t assembly_size = 0;
1066 result = 1071 result =
1067 Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size); 1072 Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size);
1068 CHECK_RESULT(result); 1073 CHECK_RESULT(result);
1069 WriteSnapshotFile(assembly_filename, assembly_buffer, assembly_size); 1074 WriteSnapshotFile(assembly_filename, assembly_buffer, assembly_size);
1070 } else { 1075 } else {
1071 uint8_t* vm_isolate_buffer = NULL; 1076 uint8_t* vm_snapshot_data_buffer = NULL;
1072 intptr_t vm_isolate_size = 0; 1077 intptr_t vm_snapshot_data_size = 0;
1073 uint8_t* isolate_buffer = NULL; 1078 uint8_t* vm_snapshot_instructions_buffer = NULL;
1074 intptr_t isolate_size = 0; 1079 intptr_t vm_snapshot_instructions_size = 0;
1075 uint8_t* instructions_blob_buffer = NULL; 1080 uint8_t* isolate_snapshot_data_buffer = NULL;
1076 intptr_t instructions_blob_size = 0; 1081 intptr_t isolate_snapshot_data_size = 0;
1077 uint8_t* rodata_blob_buffer = NULL; 1082 uint8_t* isolate_snapshot_instructions_buffer = NULL;
1078 intptr_t rodata_blob_size = 0; 1083 intptr_t isolate_snapshot_instructions_size = 0;
1079 result = Dart_CreateAppAOTSnapshotAsBlobs( 1084 result = Dart_CreateAppAOTSnapshotAsBlobs(
1080 &vm_isolate_buffer, &vm_isolate_size, &isolate_buffer, &isolate_size, 1085 &vm_snapshot_data_buffer, &vm_snapshot_data_size,
1081 &instructions_blob_buffer, &instructions_blob_size, &rodata_blob_buffer, 1086 &vm_snapshot_instructions_buffer, &vm_snapshot_instructions_size,
1082 &rodata_blob_size); 1087 &isolate_snapshot_data_buffer, &isolate_snapshot_data_size,
1088 &isolate_snapshot_instructions_buffer,
1089 &isolate_snapshot_instructions_size);
1083 CHECK_RESULT(result); 1090 CHECK_RESULT(result);
1084 WriteSnapshotFile(vm_isolate_snapshot_filename, vm_isolate_buffer, 1091 WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer,
1085 vm_isolate_size); 1092 vm_snapshot_data_size);
1086 WriteSnapshotFile(isolate_snapshot_filename, isolate_buffer, isolate_size); 1093 WriteSnapshotFile(vm_snapshot_instructions_filename,
1087 WriteSnapshotFile(instructions_blob_filename, instructions_blob_buffer, 1094 vm_snapshot_instructions_buffer,
1088 instructions_blob_size); 1095 vm_snapshot_instructions_size);
1089 WriteSnapshotFile(rodata_blob_filename, rodata_blob_buffer, 1096 WriteSnapshotFile(isolate_snapshot_data_filename,
1090 rodata_blob_size); 1097 isolate_snapshot_data_buffer, isolate_snapshot_data_size);
1098 WriteSnapshotFile(isolate_snapshot_instructions_filename,
1099 isolate_snapshot_instructions_buffer,
1100 isolate_snapshot_instructions_size);
1091 } 1101 }
1092 1102
1093 Dart_ExitScope(); 1103 Dart_ExitScope();
1094 1104
1095 // Shutdown the isolate. 1105 // Shutdown the isolate.
1096 Dart_ShutdownIsolate(); 1106 Dart_ShutdownIsolate();
1097 } 1107 }
1098 1108
1099 1109
1100 static void SetupForUriResolution() { 1110 static void SetupForUriResolution() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 static Dart_Isolate CreateServiceIsolate(const char* script_uri, 1142 static Dart_Isolate CreateServiceIsolate(const char* script_uri,
1133 const char* main, 1143 const char* main,
1134 const char* package_root, 1144 const char* package_root,
1135 const char* package_config, 1145 const char* package_config,
1136 Dart_IsolateFlags* flags, 1146 Dart_IsolateFlags* flags,
1137 void* data, 1147 void* data,
1138 char** error) { 1148 char** error) {
1139 IsolateData* isolate_data = 1149 IsolateData* isolate_data =
1140 new IsolateData(script_uri, package_root, package_config); 1150 new IsolateData(script_uri, package_root, package_config);
1141 Dart_Isolate isolate = NULL; 1151 Dart_Isolate isolate = NULL;
1142 isolate = 1152 isolate = Dart_CreateIsolate(script_uri, main, NULL, NULL, NULL, isolate_data,
1143 Dart_CreateIsolate(script_uri, main, NULL, NULL, isolate_data, error); 1153 error);
1144 1154
1145 if (isolate == NULL) { 1155 if (isolate == NULL) {
1146 Log::PrintErr("Error: Could not create service isolate"); 1156 Log::PrintErr("Error: Could not create service isolate");
1147 return NULL; 1157 return NULL;
1148 } 1158 }
1149 1159
1150 Dart_EnterScope(); 1160 Dart_EnterScope();
1151 if (!Dart_IsServiceIsolate(isolate)) { 1161 if (!Dart_IsServiceIsolate(isolate)) {
1152 Log::PrintErr("Error: We only expect to create the service isolate"); 1162 Log::PrintErr("Error: We only expect to create the service isolate");
1153 return NULL; 1163 return NULL;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 char* error = Dart_Initialize(&init_params); 1246 char* error = Dart_Initialize(&init_params);
1237 if (error != NULL) { 1247 if (error != NULL) {
1238 Log::PrintErr("VM initialization failed: %s\n", error); 1248 Log::PrintErr("VM initialization failed: %s\n", error);
1239 free(error); 1249 free(error);
1240 return kErrorExitCode; 1250 return kErrorExitCode;
1241 } 1251 }
1242 1252
1243 IsolateData* isolate_data = new IsolateData(NULL, commandline_package_root, 1253 IsolateData* isolate_data = new IsolateData(NULL, commandline_package_root,
1244 commandline_packages_file); 1254 commandline_packages_file);
1245 Dart_Isolate isolate = 1255 Dart_Isolate isolate =
1246 Dart_CreateIsolate(NULL, NULL, NULL, NULL, isolate_data, &error); 1256 Dart_CreateIsolate(NULL, NULL, NULL, NULL, NULL, isolate_data, &error);
1247 if (isolate == NULL) { 1257 if (isolate == NULL) {
1248 Log::PrintErr("Error: %s", error); 1258 Log::PrintErr("Error: %s", error);
1249 free(error); 1259 free(error);
1250 exit(kErrorExitCode); 1260 exit(kErrorExitCode);
1251 } 1261 }
1252 1262
1253 Dart_Handle result; 1263 Dart_Handle result;
1254 Dart_Handle library; 1264 Dart_Handle library;
1255 Dart_EnterScope(); 1265 Dart_EnterScope();
1256 1266
1257 result = Dart_SetEnvironmentCallback(EnvironmentCallback); 1267 result = Dart_SetEnvironmentCallback(EnvironmentCallback);
1258 CHECK_RESULT(result); 1268 CHECK_RESULT(result);
1259 1269
1260 ASSERT(vm_isolate_snapshot_filename != NULL); 1270 ASSERT(vm_snapshot_data_filename != NULL);
1261 ASSERT(isolate_snapshot_filename != NULL); 1271 ASSERT(isolate_snapshot_data_filename != NULL);
1262 // Load up the script before a snapshot is created. 1272 // Load up the script before a snapshot is created.
1263 if (app_script_name != NULL) { 1273 if (app_script_name != NULL) {
1264 // This is the case of a custom embedder (e.g: dartium) trying to 1274 // This is the case of a custom embedder (e.g: dartium) trying to
1265 // create a full snapshot. The current isolate is set up so that we can 1275 // create a full snapshot. The current isolate is set up so that we can
1266 // invoke the dart uri resolution code like _resolveURI. App script is 1276 // invoke the dart uri resolution code like _resolveURI. App script is
1267 // loaded into a separate isolate. 1277 // loaded into a separate isolate.
1268 SetupForUriResolution(); 1278 SetupForUriResolution();
1269 1279
1270 // Prepare builtin and its dependent libraries for use to resolve URIs. 1280 // Prepare builtin and its dependent libraries for use to resolve URIs.
1271 // Set up various closures, e.g: printing, timers etc. 1281 // Set up various closures, e.g: printing, timers etc.
(...skipping 26 matching lines...) Expand all
1298 void* kernel_program = NULL; 1308 void* kernel_program = NULL;
1299 if (is_kernel_file) { 1309 if (is_kernel_file) {
1300 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length); 1310 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length);
1301 free(const_cast<uint8_t*>(kernel)); 1311 free(const_cast<uint8_t*>(kernel));
1302 } 1312 }
1303 1313
1304 Dart_Isolate isolate = 1314 Dart_Isolate isolate =
1305 is_kernel_file 1315 is_kernel_file
1306 ? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL, 1316 ? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL,
1307 isolate_data, &error) 1317 isolate_data, &error)
1308 : Dart_CreateIsolate(NULL, NULL, NULL, NULL, isolate_data, &error); 1318 : Dart_CreateIsolate(NULL, NULL, NULL, NULL, NULL, isolate_data,
1319 &error);
1309 if (isolate == NULL) { 1320 if (isolate == NULL) {
1310 Log::PrintErr("%s", error); 1321 Log::PrintErr("%s", error);
1311 free(error); 1322 free(error);
1312 exit(kErrorExitCode); 1323 exit(kErrorExitCode);
1313 } 1324 }
1314 Dart_EnterScope(); 1325 Dart_EnterScope();
1315 result = Dart_SetEnvironmentCallback(EnvironmentCallback); 1326 result = Dart_SetEnvironmentCallback(EnvironmentCallback);
1316 CHECK_RESULT(result); 1327 CHECK_RESULT(result);
1317 1328
1318 // Set up the library tag handler in such a manner that it will use the 1329 // Set up the library tag handler in such a manner that it will use the
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 EventHandler::Stop(); 1382 EventHandler::Stop();
1372 return 0; 1383 return 0;
1373 } 1384 }
1374 1385
1375 } // namespace bin 1386 } // namespace bin
1376 } // namespace dart 1387 } // namespace dart
1377 1388
1378 int main(int argc, char** argv) { 1389 int main(int argc, char** argv) {
1379 return dart::bin::main(argc, argv); 1390 return dart::bin::main(argc, argv);
1380 } 1391 }
OLDNEW
« no previous file with comments | « runtime/bin/extensions_win.cc ('k') | runtime/bin/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698