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