OLD | NEW |
---|---|
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 24 matching lines...) Expand all Loading... | |
35 // Exit code indicating a compilation error. | 35 // Exit code indicating a compilation error. |
36 static const int kCompilationErrorExitCode = 254; | 36 static const int kCompilationErrorExitCode = 254; |
37 // Exit code indicating an unhandled error that is not a compilation error. | 37 // Exit code indicating an unhandled error that is not a compilation error. |
38 static const int kErrorExitCode = 255; | 38 static const int kErrorExitCode = 255; |
39 // Exit code indicating a vm restart request. Never returned to the user. | 39 // Exit code indicating a vm restart request. Never returned to the user. |
40 static const int kRestartRequestExitCode = 1000; | 40 static const int kRestartRequestExitCode = 1000; |
41 | 41 |
42 #define CHECK_RESULT(result) \ | 42 #define CHECK_RESULT(result) \ |
43 if (Dart_IsError(result)) { \ | 43 if (Dart_IsError(result)) { \ |
44 intptr_t exit_code = 0; \ | 44 intptr_t exit_code = 0; \ |
45 Log::PrintErr("Error: %s", Dart_GetError(result)); \ | 45 Log::PrintErr("Error: %s\n", Dart_GetError(result)); \ |
46 if (Dart_IsCompilationError(result)) { \ | 46 if (Dart_IsCompilationError(result)) { \ |
47 exit_code = kCompilationErrorExitCode; \ | 47 exit_code = kCompilationErrorExitCode; \ |
48 } else if (Dart_IsApiError(result)) { \ | 48 } else if (Dart_IsApiError(result)) { \ |
49 exit_code = kApiErrorExitCode; \ | 49 exit_code = kApiErrorExitCode; \ |
50 } else if (Dart_IsVMRestartRequest(result)) { \ | 50 } else if (Dart_IsVMRestartRequest(result)) { \ |
51 exit_code = kRestartRequestExitCode; \ | 51 exit_code = kRestartRequestExitCode; \ |
52 } else { \ | 52 } else { \ |
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 // The core snapshot to use when creating isolates. Normally NULL, but loaded | |
62 // from a file when creating script snapshots. | |
63 const uint8_t* isolate_snapshot_data = NULL; | |
64 | |
65 | |
61 // Global state that indicates whether a snapshot is to be created and | 66 // Global state that indicates whether a snapshot is to be created and |
62 // if so which file to write the snapshot into. | 67 // if so which file to write the snapshot into. |
68 enum SnapshotKind { | |
69 kNone, | |
70 kCore, | |
71 kScript, | |
72 kAppAOTBlobs, | |
73 kAppAOTAssembly, | |
74 }; | |
75 static SnapshotKind snapshot_kind = kNone; | |
siva
2017/02/15 11:29:32
why not start with a default of kCore, that way th
rmacnak
2017/02/15 22:26:11
Done.
| |
63 static const char* vm_snapshot_data_filename = NULL; | 76 static const char* vm_snapshot_data_filename = NULL; |
64 static const char* vm_snapshot_instructions_filename = NULL; | 77 static const char* vm_snapshot_instructions_filename = NULL; |
65 static const char* isolate_snapshot_data_filename = NULL; | 78 static const char* isolate_snapshot_data_filename = NULL; |
66 static const char* isolate_snapshot_instructions_filename = NULL; | 79 static const char* isolate_snapshot_instructions_filename = NULL; |
67 static const char* assembly_filename = NULL; | 80 static const char* assembly_filename = NULL; |
81 static const char* script_snapshot_filename = NULL; | |
68 | 82 |
69 | 83 |
70 // Value of the --package-root flag. | 84 // Value of the --package-root flag. |
71 // (This pointer points into an argv buffer and does not need to be | 85 // (This pointer points into an argv buffer and does not need to be |
72 // free'd.) | 86 // free'd.) |
73 static const char* commandline_package_root = NULL; | 87 static const char* commandline_package_root = NULL; |
74 | 88 |
75 // Value of the --packages flag. | 89 // Value of the --packages flag. |
76 // (This pointer points into an argv buffer and does not need to be | 90 // (This pointer points into an argv buffer and does not need to be |
77 // free'd.) | 91 // free'd.) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 | 196 |
183 static const char* ProcessOption(const char* option, const char* name) { | 197 static const char* ProcessOption(const char* option, const char* name) { |
184 const intptr_t length = strlen(name); | 198 const intptr_t length = strlen(name); |
185 if (strncmp(option, name, length) == 0) { | 199 if (strncmp(option, name, length) == 0) { |
186 return (option + length); | 200 return (option + length); |
187 } | 201 } |
188 return NULL; | 202 return NULL; |
189 } | 203 } |
190 | 204 |
191 | 205 |
206 static bool ProcessSnapshotKindOption(const char* option) { | |
207 const char* kind = ProcessOption(option, "--snapshot_kind="); | |
208 if (kind == NULL) { | |
209 return false; | |
210 } | |
211 if (strcmp(kind, "core") == 0) { | |
212 snapshot_kind = kCore; | |
213 return true; | |
214 } else if (strcmp(kind, "script") == 0) { | |
215 snapshot_kind = kScript; | |
216 return true; | |
217 } else if (strcmp(kind, "app-aot-blobs") == 0) { | |
218 snapshot_kind = kAppAOTBlobs; | |
219 return true; | |
220 } else if (strcmp(kind, "app-aot-assembly") == 0) { | |
221 snapshot_kind = kAppAOTAssembly; | |
222 return true; | |
223 } | |
224 Log::PrintErr( | |
225 "Unrecognized snapshot kind: '%s'\nValid kinds are: " | |
226 "core, script, app-aot-blobs, app-aot-assembly\n", | |
227 kind); | |
228 return false; | |
229 } | |
230 | |
231 | |
192 static bool ProcessVmSnapshotDataOption(const char* option) { | 232 static bool ProcessVmSnapshotDataOption(const char* option) { |
193 const char* name = ProcessOption(option, "--vm_snapshot_data="); | 233 const char* name = ProcessOption(option, "--vm_snapshot_data="); |
194 if (name != NULL) { | 234 if (name != NULL) { |
195 vm_snapshot_data_filename = name; | 235 vm_snapshot_data_filename = name; |
196 return true; | 236 return true; |
197 } | 237 } |
198 return false; | 238 return false; |
199 } | 239 } |
200 | 240 |
201 | 241 |
(...skipping 30 matching lines...) Expand all Loading... | |
232 static bool ProcessAssemblyOption(const char* option) { | 272 static bool ProcessAssemblyOption(const char* option) { |
233 const char* name = ProcessOption(option, "--assembly="); | 273 const char* name = ProcessOption(option, "--assembly="); |
234 if (name != NULL) { | 274 if (name != NULL) { |
235 assembly_filename = name; | 275 assembly_filename = name; |
236 return true; | 276 return true; |
237 } | 277 } |
238 return false; | 278 return false; |
239 } | 279 } |
240 | 280 |
241 | 281 |
282 static bool ProcessScriptSnapshotOption(const char* option) { | |
283 const char* name = ProcessOption(option, "--script_snapshot="); | |
284 if (name != NULL) { | |
285 script_snapshot_filename = name; | |
286 return true; | |
287 } | |
288 return false; | |
289 } | |
290 | |
291 | |
242 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) { | 292 static bool ProcessEmbedderEntryPointsManifestOption(const char* option) { |
243 const char* name = ProcessOption(option, "--embedder_entry_points_manifest="); | 293 const char* name = ProcessOption(option, "--embedder_entry_points_manifest="); |
244 if (name != NULL) { | 294 if (name != NULL) { |
245 entry_points_files->AddArgument(name); | 295 entry_points_files->AddArgument(name); |
246 return true; | 296 return true; |
247 } | 297 } |
248 return false; | 298 return false; |
249 } | 299 } |
250 | 300 |
251 | 301 |
(...skipping 27 matching lines...) Expand all Loading... | |
279 } | 329 } |
280 if (mapping != NULL) { | 330 if (mapping != NULL) { |
281 DartUtils::url_mapping->AddArgument(mapping); | 331 DartUtils::url_mapping->AddArgument(mapping); |
282 return true; | 332 return true; |
283 } | 333 } |
284 return false; | 334 return false; |
285 } | 335 } |
286 | 336 |
287 | 337 |
288 static bool IsSnapshottingForPrecompilation() { | 338 static bool IsSnapshottingForPrecompilation() { |
289 return (assembly_filename != NULL) || | 339 return (snapshot_kind == kAppAOTBlobs) || (snapshot_kind == kAppAOTAssembly); |
290 (vm_snapshot_instructions_filename != NULL); | |
291 } | 340 } |
292 | 341 |
293 | 342 |
294 // Parse out the command line arguments. Returns -1 if the arguments | 343 // Parse out the command line arguments. Returns -1 if the arguments |
295 // are incorrect, 0 otherwise. | 344 // are incorrect, 0 otherwise. |
296 static int ParseArguments(int argc, | 345 static int ParseArguments(int argc, |
297 char** argv, | 346 char** argv, |
298 CommandLineOptions* vm_options, | 347 CommandLineOptions* vm_options, |
299 char** script_name) { | 348 char** script_name) { |
300 const char* kPrefix = "-"; | 349 const char* kPrefix = "-"; |
301 const intptr_t kPrefixLen = strlen(kPrefix); | 350 const intptr_t kPrefixLen = strlen(kPrefix); |
302 | 351 |
303 // Skip the binary name. | 352 // Skip the binary name. |
304 int i = 1; | 353 int i = 1; |
305 | 354 |
306 // Parse out the vm options. | 355 // Parse out the vm options. |
307 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { | 356 while ((i < argc) && IsValidFlag(argv[i], kPrefix, kPrefixLen)) { |
308 if (ProcessVmSnapshotDataOption(argv[i]) || | 357 if (ProcessSnapshotKindOption(argv[i]) || |
358 ProcessVmSnapshotDataOption(argv[i]) || | |
309 ProcessVmSnapshotInstructionsOption(argv[i]) || | 359 ProcessVmSnapshotInstructionsOption(argv[i]) || |
310 ProcessIsolateSnapshotDataOption(argv[i]) || | 360 ProcessIsolateSnapshotDataOption(argv[i]) || |
311 ProcessIsolateSnapshotInstructionsOption(argv[i]) || | 361 ProcessIsolateSnapshotInstructionsOption(argv[i]) || |
312 ProcessAssemblyOption(argv[i]) || | 362 ProcessAssemblyOption(argv[i]) || |
363 ProcessScriptSnapshotOption(argv[i]) || | |
313 ProcessEmbedderEntryPointsManifestOption(argv[i]) || | 364 ProcessEmbedderEntryPointsManifestOption(argv[i]) || |
314 ProcessURLmappingOption(argv[i]) || ProcessPackageRootOption(argv[i]) || | 365 ProcessURLmappingOption(argv[i]) || ProcessPackageRootOption(argv[i]) || |
315 ProcessPackagesOption(argv[i]) || ProcessEnvironmentOption(argv[i])) { | 366 ProcessPackagesOption(argv[i]) || ProcessEnvironmentOption(argv[i])) { |
316 i += 1; | 367 i += 1; |
317 continue; | 368 continue; |
318 } | 369 } |
319 vm_options->AddArgument(argv[i]); | 370 vm_options->AddArgument(argv[i]); |
320 i += 1; | 371 i += 1; |
321 } | 372 } |
322 | 373 |
323 // Get the script name. | 374 // Get the script name. |
324 if (i < argc) { | 375 if (i < argc) { |
325 *script_name = argv[i]; | 376 *script_name = argv[i]; |
326 i += 1; | 377 i += 1; |
327 } else { | 378 } else { |
328 *script_name = NULL; | 379 *script_name = NULL; |
329 } | 380 } |
330 | 381 |
331 // Verify consistency of arguments. | 382 // Verify consistency of arguments. |
332 if ((commandline_package_root != NULL) && | 383 if ((commandline_package_root != NULL) && |
333 (commandline_packages_file != NULL)) { | 384 (commandline_packages_file != NULL)) { |
334 Log::PrintErr( | 385 Log::PrintErr( |
335 "Specifying both a packages directory and a packages " | 386 "Specifying both a packages directory and a packages " |
336 "file is invalid.\n"); | 387 "file is invalid.\n\n"); |
337 return -1; | 388 return -1; |
338 } | 389 } |
339 | 390 |
340 if (vm_snapshot_data_filename == NULL) { | 391 switch (snapshot_kind) { |
341 Log::PrintErr("No vm snapshot output file specified.\n\n"); | 392 case kNone: { |
393 Log::PrintErr("No snapshot kind specified.\n\n"); | |
394 return -1; | |
395 } | |
396 case kCore: { | |
397 if ((vm_snapshot_data_filename == NULL) || | |
398 (isolate_snapshot_data_filename == NULL)) { | |
399 Log::PrintErr( | |
400 "Building a core snapshot requires specifying output files for " | |
401 "--vm_snapshot_data and --isolate_snapshot_data.\n\n"); | |
402 return -1; | |
403 } | |
404 break; | |
405 } | |
406 case kScript: { | |
407 if ((vm_snapshot_data_filename == NULL) || | |
408 (isolate_snapshot_data_filename == NULL) || | |
409 (script_snapshot_filename == NULL) || (script_name == NULL)) { | |
410 Log::PrintErr( | |
411 "Building a script snapshot requires specifying input files for " | |
412 "--vm_snapshot_data and --isolate_snapshot_data, an output file " | |
413 "for --script-snapshot, and a Dart script.\n\n"); | |
414 return -1; | |
415 } | |
416 break; | |
417 } | |
418 case kAppAOTBlobs: { | |
419 if ((vm_snapshot_data_filename == NULL) || | |
420 (vm_snapshot_instructions_filename == NULL) || | |
421 (isolate_snapshot_data_filename == NULL) || | |
422 (isolate_snapshot_instructions_filename == NULL) || | |
423 (script_name == NULL)) { | |
424 Log::PrintErr( | |
425 "Building an AOT snapshot as blobs requires specifying output " | |
426 "files for --vm_snapshot_data, --vm_snapshot_instructions, " | |
427 "--isolate_snapshot_data and --isolate_snapshot_instructions and a " | |
428 "Dart script.\n\n"); | |
429 return -1; | |
430 } | |
431 break; | |
432 } | |
433 case kAppAOTAssembly: { | |
434 if ((assembly_filename == NULL) || (script_name == NULL)) { | |
435 Log::PrintErr( | |
436 "Building an AOT snapshot as assembly requires specifying " | |
437 "an output file for --assembly and a Dart script.\n\n"); | |
438 return -1; | |
439 } | |
440 break; | |
441 } | |
442 } | |
443 | |
444 if (IsSnapshottingForPrecompilation() && (entry_points_files->count() == 0)) { | |
445 Log::PrintErr( | |
446 "Building an AOT snapshot requires at least one embedder " | |
447 "entry points manifest.\n\n"); | |
342 return -1; | 448 return -1; |
343 } | 449 } |
344 | 450 |
345 if (isolate_snapshot_data_filename == NULL) { | |
346 Log::PrintErr("No isolate snapshot output file specified.\n\n"); | |
347 return -1; | |
348 } | |
349 | |
350 bool precompiled_as_assembly = assembly_filename != NULL; | |
351 bool precompiled_as_blobs = (vm_snapshot_instructions_filename != NULL) || | |
352 (isolate_snapshot_instructions_filename != NULL); | |
353 if (precompiled_as_assembly && precompiled_as_blobs) { | |
354 Log::PrintErr( | |
355 "Cannot request a precompiled snapshot simultaneously as " | |
356 "assembly (--assembly=<output.file>) and as blobs " | |
357 "(--instructions-blob=<output.file> and " | |
358 "--rodata-blob=<output.file>)\n\n"); | |
359 return -1; | |
360 } | |
361 if ((vm_snapshot_instructions_filename != NULL) != | |
362 (isolate_snapshot_instructions_filename != NULL)) { | |
363 Log::PrintErr( | |
364 "Requesting a precompiled snapshot as blobs requires both " | |
365 "(--vm_snapshot_instructions=<output.file> and " | |
366 "--isolate_snapshot_instructions=<output.file>)\n\n"); | |
367 return -1; | |
368 } | |
369 if (IsSnapshottingForPrecompilation() && (entry_points_files->count() == 0)) { | |
370 Log::PrintErr( | |
371 "Specifying an instructions snapshot filename indicates precompilation" | |
372 ". But no embedder entry points manifest was specified.\n\n"); | |
373 return -1; | |
374 } | |
375 | |
376 return 0; | 451 return 0; |
377 } | 452 } |
378 | 453 |
379 | 454 |
380 static void WriteSnapshotFile(const char* filename, | 455 static void WriteSnapshotFile(const char* filename, |
381 const uint8_t* buffer, | 456 const uint8_t* buffer, |
382 const intptr_t size) { | 457 const intptr_t size, |
458 bool write_magic_number = false) { | |
383 File* file = File::Open(filename, File::kWriteTruncate); | 459 File* file = File::Open(filename, File::kWriteTruncate); |
384 if (file == NULL) { | 460 if (file == NULL) { |
385 Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); | 461 Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); |
386 Dart_ExitScope(); | 462 Dart_ExitScope(); |
387 Dart_ShutdownIsolate(); | 463 Dart_ShutdownIsolate(); |
388 Dart_Cleanup(); | |
389 exit(kErrorExitCode); | 464 exit(kErrorExitCode); |
390 } | 465 } |
466 if (write_magic_number) { | |
467 // Write the magic number to indicate file is a script snapshot. | |
468 DartUtils::WriteMagicNumber(file); | |
469 } | |
391 if (!file->WriteFully(buffer, size)) { | 470 if (!file->WriteFully(buffer, size)) { |
392 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); | 471 Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); |
472 Dart_ExitScope(); | |
473 Dart_ShutdownIsolate(); | |
474 exit(kErrorExitCode); | |
393 } | 475 } |
394 file->Release(); | 476 file->Release(); |
395 } | 477 } |
396 | 478 |
397 | 479 |
398 class UriResolverIsolateScope { | 480 class UriResolverIsolateScope { |
399 public: | 481 public: |
400 UriResolverIsolateScope() { | 482 UriResolverIsolateScope() { |
401 ASSERT(isolate != NULL); | 483 ASSERT(isolate != NULL); |
402 snapshotted_isolate_ = Dart_CurrentIsolate(); | 484 snapshotted_isolate_ = Dart_CurrentIsolate(); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 if (Dart_IsError(resolved_uri)) { | 570 if (Dart_IsError(resolved_uri)) { |
489 return resolved_uri; | 571 return resolved_uri; |
490 } | 572 } |
491 // Now load the contents of the specified uri. | 573 // Now load the contents of the specified uri. |
492 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri); | 574 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri); |
493 Dart_Handle source = LoadUrlContents(resolved_uri_string); | 575 Dart_Handle source = LoadUrlContents(resolved_uri_string); |
494 | 576 |
495 if (Dart_IsError(source)) { | 577 if (Dart_IsError(source)) { |
496 return source; | 578 return source; |
497 } | 579 } |
498 if (IsSnapshottingForPrecompilation()) { | 580 if (snapshot_kind == kCore) { |
581 return Dart_LoadLibrary(resolved_uri, Dart_Null(), source, 0, 0); | |
582 } else { | |
499 return Dart_LoadScript(resolved_uri, Dart_Null(), source, 0, 0); | 583 return Dart_LoadScript(resolved_uri, Dart_Null(), source, 0, 0); |
500 } else { | |
501 return Dart_LoadLibrary(resolved_uri, Dart_Null(), source, 0, 0); | |
502 } | 584 } |
503 } | 585 } |
504 | 586 |
505 | 587 |
506 static Builtin::BuiltinLibraryId BuiltinId(const char* url) { | 588 static Builtin::BuiltinLibraryId BuiltinId(const char* url) { |
507 if (DartUtils::IsDartBuiltinLibURL(url)) { | 589 if (DartUtils::IsDartBuiltinLibURL(url)) { |
508 return Builtin::kBuiltinLibrary; | 590 return Builtin::kBuiltinLibrary; |
509 } | 591 } |
510 if (DartUtils::IsDartIOLibURL(url)) { | 592 if (DartUtils::IsDartIOLibURL(url)) { |
511 return Builtin::kIOLibrary; | 593 return Builtin::kIOLibrary; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 return lib; | 689 return lib; |
608 } | 690 } |
609 | 691 |
610 | 692 |
611 // clang-format off | 693 // clang-format off |
612 static void PrintUsage() { | 694 static void PrintUsage() { |
613 Log::PrintErr( | 695 Log::PrintErr( |
614 "Usage: \n" | 696 "Usage: \n" |
615 " gen_snapshot [<vm-flags>] [<options>] [<dart-script-file>] \n" | 697 " gen_snapshot [<vm-flags>] [<options>] [<dart-script-file>] \n" |
616 " \n" | 698 " \n" |
699 " Global options: \n" | |
700 " --package_root=<path> Where to find packages, that is, \n" | |
701 " package:... imports. \n" | |
702 " \n" | |
703 " --packages=<packages_file> Where to find a package spec file \n" | |
704 " \n" | |
705 " --url_mapping=<mapping> Uses the URL mapping(s) specified on \n" | |
706 " the command line to load the \n" | |
707 " libraries. \n" | |
708 " \n" | |
709 " To create a core snapshot: \n" | |
710 " --snapshot-kind=core \n" | |
711 " --vm_snapshot_data=<output-file> \n" | |
712 " --isolate_snapshot_data=<output-file> \n" | |
713 " [<dart-script-file>] \n" | |
714 " \n" | |
715 " Writes a snapshot of <dart-script-file> to the specified snapshot files. \n" | |
716 " If no <dart-script-file> is passed, a generic snapshot of all the corelibs \n" | |
717 " is created. \n" | |
718 " \n" | |
719 " To create a script snapshot with respect to a given core snapshot: \n" | |
720 " --snapshot-kind=script \n" | |
721 " --vm_snapshot_data=<intput-file> \n" | |
722 " --isolate_snapshot_data=<intput-file> \n" | |
723 " --script_snapshot=<output-file> \n" | |
724 " <dart-script-file> \n" | |
725 " \n" | |
617 " Writes a snapshot of <dart-script-file> to the specified snapshot files. \n" | 726 " Writes a snapshot of <dart-script-file> to the specified snapshot files. \n" |
618 " If no <dart-script-file> is passed, a generic snapshot of all the corelibs\n" | 727 " If no <dart-script-file> is passed, a generic snapshot of all the corelibs\n" |
619 " is created. It is required to specify the VM isolate snapshot and the \n" | 728 " is created. \n" |
620 " isolate snapshot. The other flags are related to precompilation and are \n" | |
621 " optional. \n" | |
622 " \n" | 729 " \n" |
623 " Precompilation: \n" | 730 " To create an AOT application snapshot as blobs suitable for loading with \n" |
624 " In order to configure the snapshotter for precompilation, either \n" | 731 " mmap: \n" |
625 " --assembly=outputfile or --instructions_blob=outputfile1 and \n" | 732 " --snapshot-kind=app-aot-blobs \n" |
626 " --rodata_blob=outputfile2 must be specified. If the former is choosen, \n" | 733 " --vm_snapshot_data=<output-file> \n" |
627 " assembly for the target architecture will be output into the given file, \n" | 734 " --vm_snapshot_instructions=<output-file> \n" |
628 " which must be compiled separately and either statically linked or \n" | 735 " --isolate_snapshot_data=<output-file> \n" |
629 " dynamically loaded in the target executable. The symbols \n" | 736 " --isolate_snapshot_instructions=<output-file> \n" |
630 " kInstructionsSnapshot and kDataSnapshot must be passed to Dart_Initialize.\n" | 737 " {--embedder_entry_points_manifest=<input-file>} \n" |
631 " If the latter is choosen, binary data is output into the given files, \n" | 738 " <dart-script-file> \n" |
632 " which should be mmapped and passed to Dart_Initialize, with the \n" | |
633 " instruction blob being mapped as executable. \n" | |
634 " In both cases, a entry points manifest must be given to list the places \n" | |
635 " in the Dart program the embedder calls from the C API (Dart_Invoke, etc). \n" | |
636 " Not specifying these may cause the tree shaker to remove them from the \n" | |
637 " program. The format of this manifest is as follows. Each line in the \n" | |
638 " manifest is a comma separated list of three elements. The first entry is \n" | |
639 " the library URI, the second entry is the class name and the final entry \n" | |
640 " the function name. The file must be terminated with a newline charater. \n" | |
641 " \n" | 739 " \n" |
642 " Example: \n" | 740 " To create an AOT application snapshot as assembly suitable for compilation \n" |
643 " dart:something,SomeClass,doSomething \n" | 741 " as a static or dynamic library: \n" |
742 " mmap: \n" | |
743 " --snapshot-kind=app-aot-blobs \n" | |
744 " --assembly=<output-file> \n" | |
745 " {--embedder_entry_points_manifest=<input-file>} \n" | |
746 " <dart-script-file> \n" | |
644 " \n" | 747 " \n" |
645 " Supported options: \n" | 748 " AOT snapshots require entry points manifest files, which list the places \n" |
646 " --vm_snapshot_data=<file> A full snapshot is a compact \n" | 749 " in the Dart program the embedder calls from the C API (Dart_Invoke, etc). \n" |
647 " --isolate_snapshot_data=<file> representation of the dart vm isolate \n" | 750 " Not specifying these may cause the tree shaker to remove them from the \n" |
648 " heap and dart isolate heap states. \n" | 751 " program. The format of this manifest is as follows. Each line in the \n" |
649 " Both these options are required \n" | 752 " manifest is a comma separated list of three elements. The first entry is \n" |
753 " the library URI, the second entry is the class name and the final entry \n" | |
754 " the function name. The file must be terminated with a newline charater. \n" | |
650 " \n" | 755 " \n" |
651 " --package_root=<path> Where to find packages, that is, \n" | 756 " Example: \n" |
652 " package:... imports. \n" | 757 " dart:something,SomeClass,doSomething \n" |
653 " \n" | |
654 " --packages=<packages_file> Where to find a package spec file \n" | |
655 " \n" | |
656 " --url_mapping=<mapping> Uses the URL mapping(s) specified on \n" | |
657 " the command line to load the \n" | |
658 " libraries. \n" | |
659 " \n" | |
660 " --assembly=<file> (Precompilation only) Contains the \n" | |
661 " assembly that must be linked into \n" | |
662 " the target binary \n" | |
663 " \n" | |
664 " --vm_snapshot_instructions=<file> (Precompilation only) Contains the \n" | |
665 " --isolate_snapshot_instructions=<file> instructions and read-only data \n" | |
666 " that must be mapped into the target \n" | |
667 " binary \n" | |
668 " \n" | |
669 " --embedder_entry_points_manifest=<file> (Precompilation or app \n" | |
670 " snapshots) Contains embedder's entry \n" | |
671 " points into Dart code from the C API. \n" | |
672 "\n"); | 758 "\n"); |
673 } | 759 } |
674 // clang-format on | 760 // clang-format on |
675 | 761 |
676 | 762 |
677 static void VerifyLoaded(Dart_Handle library) { | 763 static void VerifyLoaded(Dart_Handle library) { |
678 if (Dart_IsError(library)) { | 764 if (Dart_IsError(library)) { |
679 const char* err_msg = Dart_GetError(library); | 765 const char* err_msg = Dart_GetError(library); |
680 Log::PrintErr("Errors encountered while loading: %s\n", err_msg); | 766 Log::PrintErr("Errors encountered while loading: %s\n", err_msg); |
681 CHECK_RESULT(library); | 767 CHECK_RESULT(library); |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1021 Dart_QualifiedFunctionName* entries = ParseEntryPointsManifestFiles(); | 1107 Dart_QualifiedFunctionName* entries = ParseEntryPointsManifestFiles(); |
1022 if ((entries == NULL) && IsSnapshottingForPrecompilation()) { | 1108 if ((entries == NULL) && IsSnapshottingForPrecompilation()) { |
1023 Log::PrintErr( | 1109 Log::PrintErr( |
1024 "Could not find native embedder entry points during precompilation\n"); | 1110 "Could not find native embedder entry points during precompilation\n"); |
1025 exit(kErrorExitCode); | 1111 exit(kErrorExitCode); |
1026 } | 1112 } |
1027 return entries; | 1113 return entries; |
1028 } | 1114 } |
1029 | 1115 |
1030 | 1116 |
1031 static void CreateAndWriteSnapshot() { | 1117 static void CreateAndWriteCoreSnapshot() { |
1032 ASSERT(!IsSnapshottingForPrecompilation()); | 1118 ASSERT(snapshot_kind == kCore); |
1119 ASSERT(vm_snapshot_data_filename != NULL); | |
1120 ASSERT(isolate_snapshot_data_filename != NULL); | |
1121 | |
1033 Dart_Handle result; | 1122 Dart_Handle result; |
1034 uint8_t* vm_snapshot_data_buffer = NULL; | 1123 uint8_t* vm_snapshot_data_buffer = NULL; |
1035 intptr_t vm_snapshot_data_size = 0; | 1124 intptr_t vm_snapshot_data_size = 0; |
1036 uint8_t* isolate_snapshot_data_buffer = NULL; | 1125 uint8_t* isolate_snapshot_data_buffer = NULL; |
1037 intptr_t isolate_snapshot_data_size = 0; | 1126 intptr_t isolate_snapshot_data_size = 0; |
1038 | 1127 |
1039 // First create a snapshot. | 1128 // First create a snapshot. |
1040 result = Dart_CreateSnapshot(&vm_snapshot_data_buffer, &vm_snapshot_data_size, | 1129 result = Dart_CreateSnapshot(&vm_snapshot_data_buffer, &vm_snapshot_data_size, |
1041 &isolate_snapshot_data_buffer, | 1130 &isolate_snapshot_data_buffer, |
1042 &isolate_snapshot_data_size); | 1131 &isolate_snapshot_data_size); |
1043 CHECK_RESULT(result); | 1132 CHECK_RESULT(result); |
1044 | 1133 |
1045 // Now write the vm isolate and isolate snapshots out to the | 1134 // Now write the vm isolate and isolate snapshots out to the |
1046 // specified file and exit. | 1135 // specified file and exit. |
1047 WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer, | 1136 WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer, |
1048 vm_snapshot_data_size); | 1137 vm_snapshot_data_size); |
1049 WriteSnapshotFile(isolate_snapshot_data_filename, | 1138 WriteSnapshotFile(isolate_snapshot_data_filename, |
1050 isolate_snapshot_data_buffer, isolate_snapshot_data_size); | 1139 isolate_snapshot_data_buffer, isolate_snapshot_data_size); |
1051 Dart_ExitScope(); | |
1052 | |
1053 // Shutdown the isolate. | |
1054 Dart_ShutdownIsolate(); | |
1055 } | 1140 } |
1056 | 1141 |
1057 | 1142 |
1143 static void CreateAndWriteScriptSnapshot() { | |
1144 ASSERT(snapshot_kind == kScript); | |
1145 ASSERT(script_snapshot_filename != NULL); | |
1146 | |
1147 // First create a snapshot. | |
1148 uint8_t* buffer = NULL; | |
1149 intptr_t size = 0; | |
1150 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); | |
1151 CHECK_RESULT(result); | |
1152 | |
1153 // Now write it out to the specified file. | |
1154 WriteSnapshotFile(script_snapshot_filename, buffer, size, true); | |
1155 } | |
1156 | |
1157 | |
1058 static void CreateAndWritePrecompiledSnapshot( | 1158 static void CreateAndWritePrecompiledSnapshot( |
1059 Dart_QualifiedFunctionName* standalone_entry_points) { | 1159 Dart_QualifiedFunctionName* standalone_entry_points) { |
1060 ASSERT(IsSnapshottingForPrecompilation()); | 1160 ASSERT(IsSnapshottingForPrecompilation()); |
1061 Dart_Handle result; | 1161 Dart_Handle result; |
1062 | 1162 |
1063 // Precompile with specified embedder entry points | 1163 // Precompile with specified embedder entry points |
1064 result = Dart_Precompile(standalone_entry_points, NULL, 0); | 1164 result = Dart_Precompile(standalone_entry_points, NULL, 0); |
1065 CHECK_RESULT(result); | 1165 CHECK_RESULT(result); |
1066 | 1166 |
1067 // Create a precompiled snapshot. | 1167 // Create a precompiled snapshot. |
1068 bool as_assembly = assembly_filename != NULL; | 1168 bool as_assembly = assembly_filename != NULL; |
1069 if (as_assembly) { | 1169 if (as_assembly) { |
1170 ASSERT(snapshot_kind == kAppAOTAssembly); | |
1171 | |
1070 uint8_t* assembly_buffer = NULL; | 1172 uint8_t* assembly_buffer = NULL; |
1071 intptr_t assembly_size = 0; | 1173 intptr_t assembly_size = 0; |
1072 result = | 1174 result = |
1073 Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size); | 1175 Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size); |
1074 CHECK_RESULT(result); | 1176 CHECK_RESULT(result); |
1177 | |
1075 WriteSnapshotFile(assembly_filename, assembly_buffer, assembly_size); | 1178 WriteSnapshotFile(assembly_filename, assembly_buffer, assembly_size); |
1076 } else { | 1179 } else { |
1180 ASSERT(snapshot_kind == kAppAOTBlobs); | |
1181 | |
1077 uint8_t* vm_snapshot_data_buffer = NULL; | 1182 uint8_t* vm_snapshot_data_buffer = NULL; |
1078 intptr_t vm_snapshot_data_size = 0; | 1183 intptr_t vm_snapshot_data_size = 0; |
1079 uint8_t* vm_snapshot_instructions_buffer = NULL; | 1184 uint8_t* vm_snapshot_instructions_buffer = NULL; |
1080 intptr_t vm_snapshot_instructions_size = 0; | 1185 intptr_t vm_snapshot_instructions_size = 0; |
1081 uint8_t* isolate_snapshot_data_buffer = NULL; | 1186 uint8_t* isolate_snapshot_data_buffer = NULL; |
1082 intptr_t isolate_snapshot_data_size = 0; | 1187 intptr_t isolate_snapshot_data_size = 0; |
1083 uint8_t* isolate_snapshot_instructions_buffer = NULL; | 1188 uint8_t* isolate_snapshot_instructions_buffer = NULL; |
1084 intptr_t isolate_snapshot_instructions_size = 0; | 1189 intptr_t isolate_snapshot_instructions_size = 0; |
1085 result = Dart_CreateAppAOTSnapshotAsBlobs( | 1190 result = Dart_CreateAppAOTSnapshotAsBlobs( |
1086 &vm_snapshot_data_buffer, &vm_snapshot_data_size, | 1191 &vm_snapshot_data_buffer, &vm_snapshot_data_size, |
1087 &vm_snapshot_instructions_buffer, &vm_snapshot_instructions_size, | 1192 &vm_snapshot_instructions_buffer, &vm_snapshot_instructions_size, |
1088 &isolate_snapshot_data_buffer, &isolate_snapshot_data_size, | 1193 &isolate_snapshot_data_buffer, &isolate_snapshot_data_size, |
1089 &isolate_snapshot_instructions_buffer, | 1194 &isolate_snapshot_instructions_buffer, |
1090 &isolate_snapshot_instructions_size); | 1195 &isolate_snapshot_instructions_size); |
1091 CHECK_RESULT(result); | 1196 CHECK_RESULT(result); |
1197 | |
1092 WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer, | 1198 WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer, |
1093 vm_snapshot_data_size); | 1199 vm_snapshot_data_size); |
1094 WriteSnapshotFile(vm_snapshot_instructions_filename, | 1200 WriteSnapshotFile(vm_snapshot_instructions_filename, |
1095 vm_snapshot_instructions_buffer, | 1201 vm_snapshot_instructions_buffer, |
1096 vm_snapshot_instructions_size); | 1202 vm_snapshot_instructions_size); |
1097 WriteSnapshotFile(isolate_snapshot_data_filename, | 1203 WriteSnapshotFile(isolate_snapshot_data_filename, |
1098 isolate_snapshot_data_buffer, isolate_snapshot_data_size); | 1204 isolate_snapshot_data_buffer, isolate_snapshot_data_size); |
1099 WriteSnapshotFile(isolate_snapshot_instructions_filename, | 1205 WriteSnapshotFile(isolate_snapshot_instructions_filename, |
1100 isolate_snapshot_instructions_buffer, | 1206 isolate_snapshot_instructions_buffer, |
1101 isolate_snapshot_instructions_size); | 1207 isolate_snapshot_instructions_size); |
1102 } | 1208 } |
1103 | |
1104 Dart_ExitScope(); | |
1105 | |
1106 // Shutdown the isolate. | |
1107 Dart_ShutdownIsolate(); | |
1108 } | 1209 } |
1109 | 1210 |
1110 | 1211 |
1111 static void SetupForUriResolution() { | 1212 static void SetupForUriResolution() { |
1112 // Set up the library tag handler for this isolate. | 1213 // Set up the library tag handler for this isolate. |
1113 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | 1214 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
1114 if (Dart_IsError(result)) { | 1215 if (Dart_IsError(result)) { |
1115 Log::PrintErr("%s", Dart_GetError(result)); | 1216 Log::PrintErr("%s\n", Dart_GetError(result)); |
1116 Dart_ExitScope(); | 1217 Dart_ExitScope(); |
1117 Dart_ShutdownIsolate(); | 1218 Dart_ShutdownIsolate(); |
1118 exit(kErrorExitCode); | 1219 exit(kErrorExitCode); |
1119 } | 1220 } |
1120 // This is a generic dart snapshot which needs builtin library setup. | 1221 // This is a generic dart snapshot which needs builtin library setup. |
1121 Dart_Handle library = | 1222 Dart_Handle library = |
1122 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); | 1223 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); |
1123 VerifyLoaded(library); | 1224 VerifyLoaded(library); |
1124 } | 1225 } |
1125 | 1226 |
(...skipping 17 matching lines...) Expand all Loading... | |
1143 static Dart_Isolate CreateServiceIsolate(const char* script_uri, | 1244 static Dart_Isolate CreateServiceIsolate(const char* script_uri, |
1144 const char* main, | 1245 const char* main, |
1145 const char* package_root, | 1246 const char* package_root, |
1146 const char* package_config, | 1247 const char* package_config, |
1147 Dart_IsolateFlags* flags, | 1248 Dart_IsolateFlags* flags, |
1148 void* data, | 1249 void* data, |
1149 char** error) { | 1250 char** error) { |
1150 IsolateData* isolate_data = | 1251 IsolateData* isolate_data = |
1151 new IsolateData(script_uri, package_root, package_config); | 1252 new IsolateData(script_uri, package_root, package_config); |
1152 Dart_Isolate isolate = NULL; | 1253 Dart_Isolate isolate = NULL; |
1153 isolate = Dart_CreateIsolate(script_uri, main, NULL, NULL, NULL, isolate_data, | 1254 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, NULL, |
1154 error); | 1255 NULL, isolate_data, error); |
1155 | 1256 |
1156 if (isolate == NULL) { | 1257 if (isolate == NULL) { |
1157 Log::PrintErr("Error: Could not create service isolate"); | 1258 Log::PrintErr("Error: Could not create service isolate\n"); |
1158 return NULL; | 1259 return NULL; |
1159 } | 1260 } |
1160 | 1261 |
1161 Dart_EnterScope(); | 1262 Dart_EnterScope(); |
1162 if (!Dart_IsServiceIsolate(isolate)) { | 1263 if (!Dart_IsServiceIsolate(isolate)) { |
1163 Log::PrintErr("Error: We only expect to create the service isolate"); | 1264 Log::PrintErr("Error: We only expect to create the service isolate\n"); |
1164 return NULL; | 1265 return NULL; |
1165 } | 1266 } |
1166 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | 1267 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
1268 if (Dart_IsError(result)) { | |
1269 Log::PrintErr("Error: Could not set tag handler for service isolate\n"); | |
1270 return NULL; | |
1271 } | |
1167 // Setup the native resolver. | 1272 // Setup the native resolver. |
1168 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 1273 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
1169 Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 1274 Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
1170 if (Dart_IsError(result)) { | 1275 |
1171 Log::PrintErr("Error: Could not set tag handler for service isolate"); | |
1172 return NULL; | |
1173 } | |
1174 CHECK_RESULT(result); | |
1175 ASSERT(Dart_IsServiceIsolate(isolate)); | 1276 ASSERT(Dart_IsServiceIsolate(isolate)); |
1176 // Load embedder specific bits and return. Will not start http server. | 1277 // Load embedder specific bits and return. Will not start http server. |
1177 if (!VmService::Setup("127.0.0.1", -1, false /* running_precompiled */, | 1278 if (!VmService::Setup("127.0.0.1", -1, false /* running_precompiled */, |
1178 false /* server dev mode */)) { | 1279 false /* server dev mode */)) { |
1179 *error = strdup(VmService::GetErrorMessage()); | 1280 *error = strdup(VmService::GetErrorMessage()); |
1180 return NULL; | 1281 return NULL; |
1181 } | 1282 } |
1182 Dart_ExitScope(); | 1283 Dart_ExitScope(); |
1183 Dart_ExitIsolate(); | 1284 Dart_ExitIsolate(); |
1184 return isolate; | 1285 return isolate; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; | 1338 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; |
1238 if (app_script_name != NULL) { | 1339 if (app_script_name != NULL) { |
1239 init_params.create = CreateServiceIsolate; | 1340 init_params.create = CreateServiceIsolate; |
1240 } | 1341 } |
1241 init_params.file_open = DartUtils::OpenFile; | 1342 init_params.file_open = DartUtils::OpenFile; |
1242 init_params.file_read = DartUtils::ReadFile; | 1343 init_params.file_read = DartUtils::ReadFile; |
1243 init_params.file_write = DartUtils::WriteFile; | 1344 init_params.file_write = DartUtils::WriteFile; |
1244 init_params.file_close = DartUtils::CloseFile; | 1345 init_params.file_close = DartUtils::CloseFile; |
1245 init_params.entropy_source = DartUtils::EntropySource; | 1346 init_params.entropy_source = DartUtils::EntropySource; |
1246 | 1347 |
1348 if (snapshot_kind == kScript) { | |
1349 File* file = File::Open(vm_snapshot_data_filename, File::kRead); | |
1350 if (file == NULL) { | |
1351 Log::PrintErr("Failed to open: %s\n", vm_snapshot_data_filename); | |
1352 return kErrorExitCode; | |
1353 } | |
1354 void* buffer = file->Map(File::kReadOnly, 0, file->Length()); | |
1355 if (buffer == NULL) { | |
1356 Log::PrintErr("Failed to read: %s\n", vm_snapshot_data_filename); | |
1357 return kErrorExitCode; | |
1358 } | |
1359 file->Close(); | |
1360 init_params.vm_snapshot_data = reinterpret_cast<const uint8_t*>(buffer); | |
1361 | |
1362 file = File::Open(isolate_snapshot_data_filename, File::kRead); | |
1363 if (file == NULL) { | |
1364 Log::PrintErr("Failed to open: %s\n", isolate_snapshot_data_filename); | |
1365 return kErrorExitCode; | |
1366 } | |
1367 buffer = file->Map(File::kReadOnly, 0, file->Length()); | |
1368 if (buffer == NULL) { | |
1369 Log::PrintErr("Failed to read: %s\n", isolate_snapshot_data_filename); | |
1370 return kErrorExitCode; | |
1371 } | |
1372 file->Close(); | |
1373 isolate_snapshot_data = reinterpret_cast<const uint8_t*>(buffer); | |
1374 } | |
1375 | |
1247 char* error = Dart_Initialize(&init_params); | 1376 char* error = Dart_Initialize(&init_params); |
1248 if (error != NULL) { | 1377 if (error != NULL) { |
1249 Log::PrintErr("VM initialization failed: %s\n", error); | 1378 Log::PrintErr("VM initialization failed: %s\n", error); |
1250 free(error); | 1379 free(error); |
1251 return kErrorExitCode; | 1380 return kErrorExitCode; |
1252 } | 1381 } |
1253 | 1382 |
1254 IsolateData* isolate_data = new IsolateData(NULL, commandline_package_root, | 1383 IsolateData* isolate_data = new IsolateData(NULL, commandline_package_root, |
1255 commandline_packages_file); | 1384 commandline_packages_file); |
1256 Dart_Isolate isolate = | 1385 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, |
1257 Dart_CreateIsolate(NULL, NULL, NULL, NULL, NULL, isolate_data, &error); | 1386 NULL, NULL, isolate_data, &error); |
1258 if (isolate == NULL) { | 1387 if (isolate == NULL) { |
1259 Log::PrintErr("Error: %s", error); | 1388 Log::PrintErr("Error: %s\n", error); |
1260 free(error); | 1389 free(error); |
1261 exit(kErrorExitCode); | 1390 exit(kErrorExitCode); |
1262 } | 1391 } |
1263 | 1392 |
1264 Dart_Handle result; | 1393 Dart_Handle result; |
1265 Dart_Handle library; | 1394 Dart_Handle library; |
1266 Dart_EnterScope(); | 1395 Dart_EnterScope(); |
1267 | 1396 |
1268 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 1397 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
1269 CHECK_RESULT(result); | 1398 CHECK_RESULT(result); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1309 void* kernel_program = NULL; | 1438 void* kernel_program = NULL; |
1310 if (is_kernel_file) { | 1439 if (is_kernel_file) { |
1311 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length); | 1440 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length); |
1312 free(const_cast<uint8_t*>(kernel)); | 1441 free(const_cast<uint8_t*>(kernel)); |
1313 } | 1442 } |
1314 | 1443 |
1315 Dart_Isolate isolate = | 1444 Dart_Isolate isolate = |
1316 is_kernel_file | 1445 is_kernel_file |
1317 ? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL, | 1446 ? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL, |
1318 isolate_data, &error) | 1447 isolate_data, &error) |
1319 : Dart_CreateIsolate(NULL, NULL, NULL, NULL, NULL, isolate_data, | 1448 : Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, NULL, NULL, |
1320 &error); | 1449 isolate_data, &error); |
1321 if (isolate == NULL) { | 1450 if (isolate == NULL) { |
1322 Log::PrintErr("%s", error); | 1451 Log::PrintErr("%s\n", error); |
1323 free(error); | 1452 free(error); |
1324 exit(kErrorExitCode); | 1453 exit(kErrorExitCode); |
1325 } | 1454 } |
1326 Dart_EnterScope(); | 1455 Dart_EnterScope(); |
1327 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 1456 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
1328 CHECK_RESULT(result); | 1457 CHECK_RESULT(result); |
1329 | 1458 |
1330 // Set up the library tag handler in such a manner that it will use the | 1459 // Set up the library tag handler in such a manner that it will use the |
1331 // URL mapping specified on the command line to load the libraries. | 1460 // URL mapping specified on the command line to load the libraries. |
1332 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); | 1461 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); |
(...skipping 21 matching lines...) Expand all Loading... | |
1354 library = LoadSnapshotCreationScript(app_script_name); | 1483 library = LoadSnapshotCreationScript(app_script_name); |
1355 VerifyLoaded(library); | 1484 VerifyLoaded(library); |
1356 | 1485 |
1357 ImportNativeEntryPointLibrariesIntoRoot(entry_points); | 1486 ImportNativeEntryPointLibrariesIntoRoot(entry_points); |
1358 } | 1487 } |
1359 | 1488 |
1360 // Ensure that we mark all libraries as loaded. | 1489 // Ensure that we mark all libraries as loaded. |
1361 result = Dart_FinalizeLoading(false); | 1490 result = Dart_FinalizeLoading(false); |
1362 CHECK_RESULT(result); | 1491 CHECK_RESULT(result); |
1363 | 1492 |
1364 if (!IsSnapshottingForPrecompilation()) { | 1493 switch (snapshot_kind) { |
1365 CreateAndWriteSnapshot(); | 1494 case kCore: |
1366 } else { | 1495 CreateAndWriteCoreSnapshot(); |
1367 CreateAndWritePrecompiledSnapshot(entry_points); | 1496 break; |
1497 case kScript: | |
1498 CreateAndWriteScriptSnapshot(); | |
1499 break; | |
1500 case kAppAOTBlobs: | |
1501 case kAppAOTAssembly: | |
1502 CreateAndWritePrecompiledSnapshot(entry_points); | |
1503 break; | |
1504 default: | |
1505 UNREACHABLE(); | |
1368 } | 1506 } |
1369 | 1507 |
1508 Dart_ExitScope(); | |
1509 Dart_ShutdownIsolate(); | |
1510 | |
1370 CleanupEntryPointsCollection(entry_points); | 1511 CleanupEntryPointsCollection(entry_points); |
1371 | 1512 |
1372 Dart_EnterIsolate(UriResolverIsolateScope::isolate); | 1513 Dart_EnterIsolate(UriResolverIsolateScope::isolate); |
1373 Dart_ShutdownIsolate(); | 1514 Dart_ShutdownIsolate(); |
1374 } else { | 1515 } else { |
1375 SetupForGenericSnapshotCreation(); | 1516 SetupForGenericSnapshotCreation(); |
1376 CreateAndWriteSnapshot(); | 1517 CreateAndWriteCoreSnapshot(); |
1518 | |
1519 Dart_ExitScope(); | |
1520 Dart_ShutdownIsolate(); | |
1377 } | 1521 } |
1378 error = Dart_Cleanup(); | 1522 error = Dart_Cleanup(); |
1379 if (error != NULL) { | 1523 if (error != NULL) { |
1380 Log::PrintErr("VM cleanup failed: %s\n", error); | 1524 Log::PrintErr("VM cleanup failed: %s\n", error); |
1381 free(error); | 1525 free(error); |
1382 } | 1526 } |
1383 EventHandler::Stop(); | 1527 EventHandler::Stop(); |
1384 return 0; | 1528 return 0; |
1385 } | 1529 } |
1386 | 1530 |
1387 } // namespace bin | 1531 } // namespace bin |
1388 } // namespace dart | 1532 } // namespace dart |
1389 | 1533 |
1390 int main(int argc, char** argv) { | 1534 int main(int argc, char** argv) { |
1391 return dart::bin::main(argc, argv); | 1535 return dart::bin::main(argc, argv); |
1392 } | 1536 } |
OLD | NEW |