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 }; | |
siva
2017/02/14 03:56:09
why not move this to snapshot_utils.h and share it
| |
75 static SnapshotKind snapshot_kind = kNone; | |
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 } | |
siva
2017/02/14 03:56:09
Can this also be moved to snapshot_utils.cc and sh
rmacnak
2017/02/14 23:39:39
They're different: main.cc doesn't generate core s
| |
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 " | |
401 "files for --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)) { | |
410 Log::PrintErr( | |
411 "Building a script snapshot requires specifying input " | |
412 "files for --vm_snapshot_data and --isolate_snapshot_data and an " | |
413 "output file for --script-snapshot.\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 Log::PrintErr( | |
424 "Building an AOT snapshot as blobs requires specifying " | |
425 "output files for --vm_snapshot_data, --vm_snapshot_instructions, " | |
426 "--isolate_snapshot_data and --isolate_snapshot_instructions.\n\n"); | |
427 return -1; | |
428 } | |
429 break; | |
430 } | |
431 case kAppAOTAssembly: { | |
432 if (assembly_filename == NULL) { | |
433 Log::PrintErr( | |
434 "Building an AOT snapshot as assembly requires specifying " | |
435 "an output file for --assembly.\n\n"); | |
436 return -1; | |
437 } | |
438 break; | |
439 } | |
440 } | |
441 | |
442 if (IsSnapshottingForPrecompilation() && (entry_points_files->count() == 0)) { | |
443 Log::PrintErr( | |
444 "Building an AOT snapshot requires at least one embedder " | |
445 "entry points manifest.\n\n"); | |
342 return -1; | 446 return -1; |
343 } | 447 } |
344 | 448 |
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; | 449 return 0; |
377 } | 450 } |
378 | 451 |
379 | 452 |
380 static void WriteSnapshotFile(const char* filename, | 453 static void WriteSnapshotFile(const char* filename, |
381 const uint8_t* buffer, | 454 const uint8_t* buffer, |
382 const intptr_t size) { | 455 const intptr_t size, |
456 bool write_magic_number = false) { | |
383 File* file = File::Open(filename, File::kWriteTruncate); | 457 File* file = File::Open(filename, File::kWriteTruncate); |
384 if (file == NULL) { | 458 if (file == NULL) { |
385 Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); | 459 Log::PrintErr("Error: Unable to write snapshot file: %s\n\n", filename); |
386 Dart_ExitScope(); | 460 Dart_ExitScope(); |
387 Dart_ShutdownIsolate(); | 461 Dart_ShutdownIsolate(); |
388 Dart_Cleanup(); | 462 Dart_Cleanup(); |
389 exit(kErrorExitCode); | 463 exit(kErrorExitCode); |
390 } | 464 } |
465 if (write_magic_number) { | |
466 // Write the magic number to indicate file is a script snapshot. | |
467 DartUtils::WriteMagicNumber(file); | |
468 } | |
391 if (!file->WriteFully(buffer, size)) { | 469 if (!file->WriteFully(buffer, size)) { |
392 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); | 470 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); |
393 } | 471 } |
394 file->Release(); | 472 file->Release(); |
395 } | 473 } |
siva
2017/02/14 03:56:09
This function exists in snapshot_utils.cc, can we
rmacnak
2017/02/14 23:39:39
The shutdown logic is different between gen_snapsh
| |
396 | 474 |
397 | 475 |
398 class UriResolverIsolateScope { | 476 class UriResolverIsolateScope { |
399 public: | 477 public: |
400 UriResolverIsolateScope() { | 478 UriResolverIsolateScope() { |
401 ASSERT(isolate != NULL); | 479 ASSERT(isolate != NULL); |
402 snapshotted_isolate_ = Dart_CurrentIsolate(); | 480 snapshotted_isolate_ = Dart_CurrentIsolate(); |
403 Dart_ExitIsolate(); | 481 Dart_ExitIsolate(); |
404 Dart_EnterIsolate(isolate); | 482 Dart_EnterIsolate(isolate); |
405 Dart_EnterScope(); | 483 Dart_EnterScope(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 if (Dart_IsError(resolved_uri)) { | 566 if (Dart_IsError(resolved_uri)) { |
489 return resolved_uri; | 567 return resolved_uri; |
490 } | 568 } |
491 // Now load the contents of the specified uri. | 569 // Now load the contents of the specified uri. |
492 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri); | 570 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri); |
493 Dart_Handle source = LoadUrlContents(resolved_uri_string); | 571 Dart_Handle source = LoadUrlContents(resolved_uri_string); |
494 | 572 |
495 if (Dart_IsError(source)) { | 573 if (Dart_IsError(source)) { |
496 return source; | 574 return source; |
497 } | 575 } |
498 if (IsSnapshottingForPrecompilation()) { | 576 if (snapshot_kind == kCore) { |
577 return Dart_LoadLibrary(resolved_uri, Dart_Null(), source, 0, 0); | |
578 } else { | |
499 return Dart_LoadScript(resolved_uri, Dart_Null(), source, 0, 0); | 579 return Dart_LoadScript(resolved_uri, Dart_Null(), source, 0, 0); |
500 } else { | |
501 return Dart_LoadLibrary(resolved_uri, Dart_Null(), source, 0, 0); | |
502 } | 580 } |
503 } | 581 } |
504 | 582 |
505 | 583 |
506 static Builtin::BuiltinLibraryId BuiltinId(const char* url) { | 584 static Builtin::BuiltinLibraryId BuiltinId(const char* url) { |
507 if (DartUtils::IsDartBuiltinLibURL(url)) { | 585 if (DartUtils::IsDartBuiltinLibURL(url)) { |
508 return Builtin::kBuiltinLibrary; | 586 return Builtin::kBuiltinLibrary; |
509 } | 587 } |
510 if (DartUtils::IsDartIOLibURL(url)) { | 588 if (DartUtils::IsDartIOLibURL(url)) { |
511 return Builtin::kIOLibrary; | 589 return Builtin::kIOLibrary; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 return lib; | 685 return lib; |
608 } | 686 } |
609 | 687 |
610 | 688 |
611 // clang-format off | 689 // clang-format off |
612 static void PrintUsage() { | 690 static void PrintUsage() { |
613 Log::PrintErr( | 691 Log::PrintErr( |
614 "Usage: \n" | 692 "Usage: \n" |
615 " gen_snapshot [<vm-flags>] [<options>] [<dart-script-file>] \n" | 693 " gen_snapshot [<vm-flags>] [<options>] [<dart-script-file>] \n" |
616 " \n" | 694 " \n" |
695 " Global options: \n" | |
696 " --package_root=<path> Where to find packages, that is, \n" | |
697 " package:... imports. \n" | |
698 " \n" | |
699 " --packages=<packages_file> Where to find a package spec file \n" | |
700 " \n" | |
701 " --url_mapping=<mapping> Uses the URL mapping(s) specified on \n" | |
702 " the command line to load the \n" | |
703 " libraries. \n" | |
704 " \n" | |
705 " To create a core snapshot: \n" | |
706 " --snapshot-kind=core \n" | |
707 " --vm_snapshot_data=<output-file> \n" | |
708 " --isolate_snapshot_data=<output-file> \n" | |
709 " [<dart-script-file>] \n" | |
710 " \n" | |
711 " Writes a snapshot of <dart-script-file> to the specified snapshot files. \n" | |
712 " If no <dart-script-file> is passed, a generic snapshot of all the corelibs \n" | |
713 " is created. \n" | |
714 " \n" | |
715 " To create a script snapshot with respect to a given core snapshot: \n" | |
716 " --snapshot-kind=script \n" | |
717 " --vm_snapshot_data=<intput-file> \n" | |
718 " --isolate_snapshot_data=<intput-file> \n" | |
719 " --script_snapshot=<output-file> \n" | |
720 " <dart-script-file> \n" | |
721 " \n" | |
617 " Writes a snapshot of <dart-script-file> to the specified snapshot files. \n" | 722 " 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" | 723 " 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" | 724 " is created. \n" |
620 " isolate snapshot. The other flags are related to precompilation and are \n" | |
621 " optional. \n" | |
622 " \n" | 725 " \n" |
623 " Precompilation: \n" | 726 " To create an AOT application snapshot as blobs suitable for loading with \n" |
624 " In order to configure the snapshotter for precompilation, either \n" | 727 " mmap: \n" |
625 " --assembly=outputfile or --instructions_blob=outputfile1 and \n" | 728 " --snapshot-kind=app-aot-blobs \n" |
626 " --rodata_blob=outputfile2 must be specified. If the former is choosen, \n" | 729 " --vm_snapshot_data=<output-file> \n" |
627 " assembly for the target architecture will be output into the given file, \n" | 730 " --vm_snapshot_instructions=<output-file> \n" |
628 " which must be compiled separately and either statically linked or \n" | 731 " --isolate_snapshot_data=<output-file> \n" |
629 " dynamically loaded in the target executable. The symbols \n" | 732 " --isolate_snapshot_instructions=<output-file> \n" |
630 " kInstructionsSnapshot and kDataSnapshot must be passed to Dart_Initialize.\n" | 733 " {--embedder_entry_points_manifest=<input-file>} \n" |
631 " If the latter is choosen, binary data is output into the given files, \n" | 734 " <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" | 735 " \n" |
642 " Example: \n" | 736 " To create an AOT application snapshot as assembly suitable for compilation \n" |
643 " dart:something,SomeClass,doSomething \n" | 737 " as a static or dynamic library: \n" |
738 " mmap: \n" | |
739 " --snapshot-kind=app-aot-blobs \n" | |
740 " --assembly=<output-file> \n" | |
741 " {--embedder_entry_points_manifest=<input-file>} \n" | |
742 " <dart-script-file> \n" | |
644 " \n" | 743 " \n" |
645 " Supported options: \n" | 744 " AOT snapshots require entry points manifest files, which list the places \n" |
646 " --vm_snapshot_data=<file> A full snapshot is a compact \n" | 745 " 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" | 746 " Not specifying these may cause the tree shaker to remove them from the \n" |
648 " heap and dart isolate heap states. \n" | 747 " program. The format of this manifest is as follows. Each line in the \n" |
649 " Both these options are required \n" | 748 " manifest is a comma separated list of three elements. The first entry is \n" |
749 " the library URI, the second entry is the class name and the final entry \n" | |
750 " the function name. The file must be terminated with a newline charater. \n" | |
650 " \n" | 751 " \n" |
651 " --package_root=<path> Where to find packages, that is, \n" | 752 " Example: \n" |
652 " package:... imports. \n" | 753 " 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"); | 754 "\n"); |
673 } | 755 } |
674 // clang-format on | 756 // clang-format on |
675 | 757 |
676 | 758 |
677 static void VerifyLoaded(Dart_Handle library) { | 759 static void VerifyLoaded(Dart_Handle library) { |
678 if (Dart_IsError(library)) { | 760 if (Dart_IsError(library)) { |
679 const char* err_msg = Dart_GetError(library); | 761 const char* err_msg = Dart_GetError(library); |
680 Log::PrintErr("Errors encountered while loading: %s\n", err_msg); | 762 Log::PrintErr("Errors encountered while loading: %s\n", err_msg); |
681 CHECK_RESULT(library); | 763 CHECK_RESULT(library); |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1021 Dart_QualifiedFunctionName* entries = ParseEntryPointsManifestFiles(); | 1103 Dart_QualifiedFunctionName* entries = ParseEntryPointsManifestFiles(); |
1022 if ((entries == NULL) && IsSnapshottingForPrecompilation()) { | 1104 if ((entries == NULL) && IsSnapshottingForPrecompilation()) { |
1023 Log::PrintErr( | 1105 Log::PrintErr( |
1024 "Could not find native embedder entry points during precompilation\n"); | 1106 "Could not find native embedder entry points during precompilation\n"); |
1025 exit(kErrorExitCode); | 1107 exit(kErrorExitCode); |
1026 } | 1108 } |
1027 return entries; | 1109 return entries; |
1028 } | 1110 } |
1029 | 1111 |
1030 | 1112 |
1031 static void CreateAndWriteSnapshot() { | 1113 static void CreateAndWriteCoreSnapshot() { |
1032 ASSERT(!IsSnapshottingForPrecompilation()); | 1114 ASSERT(snapshot_kind == kCore); |
1115 ASSERT(vm_snapshot_data_filename != NULL); | |
1116 ASSERT(isolate_snapshot_data_filename != NULL); | |
1117 | |
1033 Dart_Handle result; | 1118 Dart_Handle result; |
1034 uint8_t* vm_snapshot_data_buffer = NULL; | 1119 uint8_t* vm_snapshot_data_buffer = NULL; |
1035 intptr_t vm_snapshot_data_size = 0; | 1120 intptr_t vm_snapshot_data_size = 0; |
1036 uint8_t* isolate_snapshot_data_buffer = NULL; | 1121 uint8_t* isolate_snapshot_data_buffer = NULL; |
1037 intptr_t isolate_snapshot_data_size = 0; | 1122 intptr_t isolate_snapshot_data_size = 0; |
1038 | 1123 |
1039 // First create a snapshot. | 1124 // First create a snapshot. |
1040 result = Dart_CreateSnapshot(&vm_snapshot_data_buffer, &vm_snapshot_data_size, | 1125 result = Dart_CreateSnapshot(&vm_snapshot_data_buffer, &vm_snapshot_data_size, |
1041 &isolate_snapshot_data_buffer, | 1126 &isolate_snapshot_data_buffer, |
1042 &isolate_snapshot_data_size); | 1127 &isolate_snapshot_data_size); |
1043 CHECK_RESULT(result); | 1128 CHECK_RESULT(result); |
1044 | 1129 |
1045 // Now write the vm isolate and isolate snapshots out to the | 1130 // Now write the vm isolate and isolate snapshots out to the |
1046 // specified file and exit. | 1131 // specified file and exit. |
1047 WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer, | 1132 WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer, |
1048 vm_snapshot_data_size); | 1133 vm_snapshot_data_size); |
1049 WriteSnapshotFile(isolate_snapshot_data_filename, | 1134 WriteSnapshotFile(isolate_snapshot_data_filename, |
1050 isolate_snapshot_data_buffer, isolate_snapshot_data_size); | 1135 isolate_snapshot_data_buffer, isolate_snapshot_data_size); |
1051 Dart_ExitScope(); | |
1052 | |
1053 // Shutdown the isolate. | |
1054 Dart_ShutdownIsolate(); | |
1055 } | 1136 } |
1056 | 1137 |
1057 | 1138 |
1139 static void CreateAndWriteScriptSnapshot() { | |
1140 ASSERT(snapshot_kind == kScript); | |
1141 ASSERT(script_snapshot_filename != NULL); | |
1142 | |
1143 // First create a snapshot. | |
1144 uint8_t* buffer = NULL; | |
1145 intptr_t size = 0; | |
1146 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); | |
1147 CHECK_RESULT(result); | |
1148 | |
1149 // Now write it out to the specified file. | |
1150 WriteSnapshotFile(script_snapshot_filename, buffer, size, true); | |
1151 } | |
1152 | |
1153 | |
1058 static void CreateAndWritePrecompiledSnapshot( | 1154 static void CreateAndWritePrecompiledSnapshot( |
1059 Dart_QualifiedFunctionName* standalone_entry_points) { | 1155 Dart_QualifiedFunctionName* standalone_entry_points) { |
1060 ASSERT(IsSnapshottingForPrecompilation()); | 1156 ASSERT(IsSnapshottingForPrecompilation()); |
1061 Dart_Handle result; | 1157 Dart_Handle result; |
1062 | 1158 |
1063 // Precompile with specified embedder entry points | 1159 // Precompile with specified embedder entry points |
1064 result = Dart_Precompile(standalone_entry_points, NULL, 0); | 1160 result = Dart_Precompile(standalone_entry_points, NULL, 0); |
1065 CHECK_RESULT(result); | 1161 CHECK_RESULT(result); |
1066 | 1162 |
1067 // Create a precompiled snapshot. | 1163 // Create a precompiled snapshot. |
1068 bool as_assembly = assembly_filename != NULL; | 1164 bool as_assembly = assembly_filename != NULL; |
1069 if (as_assembly) { | 1165 if (as_assembly) { |
1166 ASSERT(snapshot_kind == kAppAOTAssembly); | |
1167 | |
1070 uint8_t* assembly_buffer = NULL; | 1168 uint8_t* assembly_buffer = NULL; |
1071 intptr_t assembly_size = 0; | 1169 intptr_t assembly_size = 0; |
1072 result = | 1170 result = |
1073 Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size); | 1171 Dart_CreateAppAOTSnapshotAsAssembly(&assembly_buffer, &assembly_size); |
1074 CHECK_RESULT(result); | 1172 CHECK_RESULT(result); |
1173 | |
1075 WriteSnapshotFile(assembly_filename, assembly_buffer, assembly_size); | 1174 WriteSnapshotFile(assembly_filename, assembly_buffer, assembly_size); |
1076 } else { | 1175 } else { |
1176 ASSERT(snapshot_kind == kAppAOTBlobs); | |
1177 | |
1077 uint8_t* vm_snapshot_data_buffer = NULL; | 1178 uint8_t* vm_snapshot_data_buffer = NULL; |
1078 intptr_t vm_snapshot_data_size = 0; | 1179 intptr_t vm_snapshot_data_size = 0; |
1079 uint8_t* vm_snapshot_instructions_buffer = NULL; | 1180 uint8_t* vm_snapshot_instructions_buffer = NULL; |
1080 intptr_t vm_snapshot_instructions_size = 0; | 1181 intptr_t vm_snapshot_instructions_size = 0; |
1081 uint8_t* isolate_snapshot_data_buffer = NULL; | 1182 uint8_t* isolate_snapshot_data_buffer = NULL; |
1082 intptr_t isolate_snapshot_data_size = 0; | 1183 intptr_t isolate_snapshot_data_size = 0; |
1083 uint8_t* isolate_snapshot_instructions_buffer = NULL; | 1184 uint8_t* isolate_snapshot_instructions_buffer = NULL; |
1084 intptr_t isolate_snapshot_instructions_size = 0; | 1185 intptr_t isolate_snapshot_instructions_size = 0; |
1085 result = Dart_CreateAppAOTSnapshotAsBlobs( | 1186 result = Dart_CreateAppAOTSnapshotAsBlobs( |
1086 &vm_snapshot_data_buffer, &vm_snapshot_data_size, | 1187 &vm_snapshot_data_buffer, &vm_snapshot_data_size, |
1087 &vm_snapshot_instructions_buffer, &vm_snapshot_instructions_size, | 1188 &vm_snapshot_instructions_buffer, &vm_snapshot_instructions_size, |
1088 &isolate_snapshot_data_buffer, &isolate_snapshot_data_size, | 1189 &isolate_snapshot_data_buffer, &isolate_snapshot_data_size, |
1089 &isolate_snapshot_instructions_buffer, | 1190 &isolate_snapshot_instructions_buffer, |
1090 &isolate_snapshot_instructions_size); | 1191 &isolate_snapshot_instructions_size); |
1091 CHECK_RESULT(result); | 1192 CHECK_RESULT(result); |
1193 | |
1092 WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer, | 1194 WriteSnapshotFile(vm_snapshot_data_filename, vm_snapshot_data_buffer, |
1093 vm_snapshot_data_size); | 1195 vm_snapshot_data_size); |
1094 WriteSnapshotFile(vm_snapshot_instructions_filename, | 1196 WriteSnapshotFile(vm_snapshot_instructions_filename, |
1095 vm_snapshot_instructions_buffer, | 1197 vm_snapshot_instructions_buffer, |
1096 vm_snapshot_instructions_size); | 1198 vm_snapshot_instructions_size); |
1097 WriteSnapshotFile(isolate_snapshot_data_filename, | 1199 WriteSnapshotFile(isolate_snapshot_data_filename, |
1098 isolate_snapshot_data_buffer, isolate_snapshot_data_size); | 1200 isolate_snapshot_data_buffer, isolate_snapshot_data_size); |
1099 WriteSnapshotFile(isolate_snapshot_instructions_filename, | 1201 WriteSnapshotFile(isolate_snapshot_instructions_filename, |
1100 isolate_snapshot_instructions_buffer, | 1202 isolate_snapshot_instructions_buffer, |
1101 isolate_snapshot_instructions_size); | 1203 isolate_snapshot_instructions_size); |
1102 } | 1204 } |
1103 | |
1104 Dart_ExitScope(); | |
1105 | |
1106 // Shutdown the isolate. | |
1107 Dart_ShutdownIsolate(); | |
1108 } | 1205 } |
1109 | 1206 |
1110 | 1207 |
1111 static void SetupForUriResolution() { | 1208 static void SetupForUriResolution() { |
1112 // Set up the library tag handler for this isolate. | 1209 // Set up the library tag handler for this isolate. |
1113 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | 1210 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
1114 if (Dart_IsError(result)) { | 1211 if (Dart_IsError(result)) { |
1115 Log::PrintErr("%s", Dart_GetError(result)); | 1212 Log::PrintErr("%s\n", Dart_GetError(result)); |
1116 Dart_ExitScope(); | 1213 Dart_ExitScope(); |
1117 Dart_ShutdownIsolate(); | 1214 Dart_ShutdownIsolate(); |
1118 exit(kErrorExitCode); | 1215 exit(kErrorExitCode); |
1119 } | 1216 } |
1120 // This is a generic dart snapshot which needs builtin library setup. | 1217 // This is a generic dart snapshot which needs builtin library setup. |
1121 Dart_Handle library = | 1218 Dart_Handle library = |
1122 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); | 1219 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); |
1123 VerifyLoaded(library); | 1220 VerifyLoaded(library); |
1124 } | 1221 } |
1125 | 1222 |
(...skipping 17 matching lines...) Expand all Loading... | |
1143 static Dart_Isolate CreateServiceIsolate(const char* script_uri, | 1240 static Dart_Isolate CreateServiceIsolate(const char* script_uri, |
1144 const char* main, | 1241 const char* main, |
1145 const char* package_root, | 1242 const char* package_root, |
1146 const char* package_config, | 1243 const char* package_config, |
1147 Dart_IsolateFlags* flags, | 1244 Dart_IsolateFlags* flags, |
1148 void* data, | 1245 void* data, |
1149 char** error) { | 1246 char** error) { |
1150 IsolateData* isolate_data = | 1247 IsolateData* isolate_data = |
1151 new IsolateData(script_uri, package_root, package_config); | 1248 new IsolateData(script_uri, package_root, package_config); |
1152 Dart_Isolate isolate = NULL; | 1249 Dart_Isolate isolate = NULL; |
1153 isolate = Dart_CreateIsolate(script_uri, main, NULL, NULL, NULL, isolate_data, | 1250 isolate = Dart_CreateIsolate(script_uri, main, isolate_snapshot_data, NULL, |
1154 error); | 1251 NULL, isolate_data, error); |
1155 | 1252 |
1156 if (isolate == NULL) { | 1253 if (isolate == NULL) { |
1157 Log::PrintErr("Error: Could not create service isolate"); | 1254 Log::PrintErr("Error: Could not create service isolate\n"); |
1158 return NULL; | 1255 return NULL; |
1159 } | 1256 } |
1160 | 1257 |
1161 Dart_EnterScope(); | 1258 Dart_EnterScope(); |
1162 if (!Dart_IsServiceIsolate(isolate)) { | 1259 if (!Dart_IsServiceIsolate(isolate)) { |
1163 Log::PrintErr("Error: We only expect to create the service isolate"); | 1260 Log::PrintErr("Error: We only expect to create the service isolate\n"); |
1164 return NULL; | 1261 return NULL; |
1165 } | 1262 } |
1166 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | 1263 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
1264 if (Dart_IsError(result)) { | |
1265 Log::PrintErr("Error: Could not set tag handler for service isolate\n"); | |
1266 return NULL; | |
1267 } | |
1167 // Setup the native resolver. | 1268 // Setup the native resolver. |
1168 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 1269 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
1169 Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 1270 Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
1170 if (Dart_IsError(result)) { | 1271 |
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)); | 1272 ASSERT(Dart_IsServiceIsolate(isolate)); |
1176 // Load embedder specific bits and return. Will not start http server. | 1273 // Load embedder specific bits and return. Will not start http server. |
1177 if (!VmService::Setup("127.0.0.1", -1, false /* running_precompiled */, | 1274 if (!VmService::Setup("127.0.0.1", -1, false /* running_precompiled */, |
1178 false /* server dev mode */)) { | 1275 false /* server dev mode */)) { |
1179 *error = strdup(VmService::GetErrorMessage()); | 1276 *error = strdup(VmService::GetErrorMessage()); |
1180 return NULL; | 1277 return NULL; |
1181 } | 1278 } |
1182 Dart_ExitScope(); | 1279 Dart_ExitScope(); |
1183 Dart_ExitIsolate(); | 1280 Dart_ExitIsolate(); |
1184 return isolate; | 1281 return isolate; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; | 1334 init_params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; |
1238 if (app_script_name != NULL) { | 1335 if (app_script_name != NULL) { |
1239 init_params.create = CreateServiceIsolate; | 1336 init_params.create = CreateServiceIsolate; |
1240 } | 1337 } |
1241 init_params.file_open = DartUtils::OpenFile; | 1338 init_params.file_open = DartUtils::OpenFile; |
1242 init_params.file_read = DartUtils::ReadFile; | 1339 init_params.file_read = DartUtils::ReadFile; |
1243 init_params.file_write = DartUtils::WriteFile; | 1340 init_params.file_write = DartUtils::WriteFile; |
1244 init_params.file_close = DartUtils::CloseFile; | 1341 init_params.file_close = DartUtils::CloseFile; |
1245 init_params.entropy_source = DartUtils::EntropySource; | 1342 init_params.entropy_source = DartUtils::EntropySource; |
1246 | 1343 |
1344 if (snapshot_kind == kScript) { | |
1345 File* file = File::Open(vm_snapshot_data_filename, File::kRead); | |
1346 if (file == NULL) { | |
1347 Log::PrintErr("Failed to open: %s\n", vm_snapshot_data_filename); | |
1348 return kErrorExitCode; | |
1349 } | |
1350 void* buffer = file->Map(File::kReadOnly, 0, file->Length()); | |
1351 if (buffer == NULL) { | |
1352 Log::PrintErr("Failed to read: %s\n", vm_snapshot_data_filename); | |
1353 return kErrorExitCode; | |
1354 } | |
1355 file->Close(); | |
1356 init_params.vm_snapshot_data = reinterpret_cast<const uint8_t*>(buffer); | |
1357 | |
1358 file = File::Open(isolate_snapshot_data_filename, File::kRead); | |
1359 if (file == NULL) { | |
1360 Log::PrintErr("Failed to open: %s\n", isolate_snapshot_data_filename); | |
1361 return kErrorExitCode; | |
1362 } | |
1363 buffer = file->Map(File::kReadOnly, 0, file->Length()); | |
1364 if (buffer == NULL) { | |
1365 Log::PrintErr("Failed to read: %s\n", isolate_snapshot_data_filename); | |
1366 return kErrorExitCode; | |
1367 } | |
1368 file->Close(); | |
1369 isolate_snapshot_data = reinterpret_cast<const uint8_t*>(buffer); | |
1370 } | |
1371 | |
1247 char* error = Dart_Initialize(&init_params); | 1372 char* error = Dart_Initialize(&init_params); |
1248 if (error != NULL) { | 1373 if (error != NULL) { |
1249 Log::PrintErr("VM initialization failed: %s\n", error); | 1374 Log::PrintErr("VM initialization failed: %s\n", error); |
1250 free(error); | 1375 free(error); |
1251 return kErrorExitCode; | 1376 return kErrorExitCode; |
1252 } | 1377 } |
1253 | 1378 |
1254 IsolateData* isolate_data = new IsolateData(NULL, commandline_package_root, | 1379 IsolateData* isolate_data = new IsolateData(NULL, commandline_package_root, |
1255 commandline_packages_file); | 1380 commandline_packages_file); |
1256 Dart_Isolate isolate = | 1381 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, |
1257 Dart_CreateIsolate(NULL, NULL, NULL, NULL, NULL, isolate_data, &error); | 1382 NULL, NULL, isolate_data, &error); |
1258 if (isolate == NULL) { | 1383 if (isolate == NULL) { |
1259 Log::PrintErr("Error: %s", error); | 1384 Log::PrintErr("Error: %s\n", error); |
1260 free(error); | 1385 free(error); |
1261 exit(kErrorExitCode); | 1386 exit(kErrorExitCode); |
1262 } | 1387 } |
1263 | 1388 |
1264 Dart_Handle result; | 1389 Dart_Handle result; |
1265 Dart_Handle library; | 1390 Dart_Handle library; |
1266 Dart_EnterScope(); | 1391 Dart_EnterScope(); |
1267 | 1392 |
1268 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 1393 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
1269 CHECK_RESULT(result); | 1394 CHECK_RESULT(result); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1309 void* kernel_program = NULL; | 1434 void* kernel_program = NULL; |
1310 if (is_kernel_file) { | 1435 if (is_kernel_file) { |
1311 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length); | 1436 kernel_program = Dart_ReadKernelBinary(kernel, kernel_length); |
1312 free(const_cast<uint8_t*>(kernel)); | 1437 free(const_cast<uint8_t*>(kernel)); |
1313 } | 1438 } |
1314 | 1439 |
1315 Dart_Isolate isolate = | 1440 Dart_Isolate isolate = |
1316 is_kernel_file | 1441 is_kernel_file |
1317 ? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL, | 1442 ? Dart_CreateIsolateFromKernel(NULL, NULL, kernel_program, NULL, |
1318 isolate_data, &error) | 1443 isolate_data, &error) |
1319 : Dart_CreateIsolate(NULL, NULL, NULL, NULL, NULL, isolate_data, | 1444 : Dart_CreateIsolate(NULL, NULL, isolate_snapshot_data, NULL, NULL, |
1320 &error); | 1445 isolate_data, &error); |
1321 if (isolate == NULL) { | 1446 if (isolate == NULL) { |
1322 Log::PrintErr("%s", error); | 1447 Log::PrintErr("%s\n", error); |
1323 free(error); | 1448 free(error); |
1324 exit(kErrorExitCode); | 1449 exit(kErrorExitCode); |
1325 } | 1450 } |
1326 Dart_EnterScope(); | 1451 Dart_EnterScope(); |
1327 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 1452 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
1328 CHECK_RESULT(result); | 1453 CHECK_RESULT(result); |
1329 | 1454 |
1330 // Set up the library tag handler in such a manner that it will use the | 1455 // 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. | 1456 // URL mapping specified on the command line to load the libraries. |
1332 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); | 1457 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); |
(...skipping 21 matching lines...) Expand all Loading... | |
1354 library = LoadSnapshotCreationScript(app_script_name); | 1479 library = LoadSnapshotCreationScript(app_script_name); |
1355 VerifyLoaded(library); | 1480 VerifyLoaded(library); |
1356 | 1481 |
1357 ImportNativeEntryPointLibrariesIntoRoot(entry_points); | 1482 ImportNativeEntryPointLibrariesIntoRoot(entry_points); |
1358 } | 1483 } |
1359 | 1484 |
1360 // Ensure that we mark all libraries as loaded. | 1485 // Ensure that we mark all libraries as loaded. |
1361 result = Dart_FinalizeLoading(false); | 1486 result = Dart_FinalizeLoading(false); |
1362 CHECK_RESULT(result); | 1487 CHECK_RESULT(result); |
1363 | 1488 |
1364 if (!IsSnapshottingForPrecompilation()) { | 1489 switch (snapshot_kind) { |
1365 CreateAndWriteSnapshot(); | 1490 case kCore: |
1366 } else { | 1491 CreateAndWriteCoreSnapshot(); |
1367 CreateAndWritePrecompiledSnapshot(entry_points); | 1492 break; |
1493 case kScript: | |
1494 CreateAndWriteScriptSnapshot(); | |
1495 break; | |
1496 case kAppAOTBlobs: | |
1497 case kAppAOTAssembly: | |
1498 CreateAndWritePrecompiledSnapshot(entry_points); | |
1499 break; | |
1500 default: | |
1501 UNREACHABLE(); | |
1368 } | 1502 } |
1369 | 1503 |
1504 Dart_ExitScope(); | |
1505 Dart_ShutdownIsolate(); | |
1506 | |
1370 CleanupEntryPointsCollection(entry_points); | 1507 CleanupEntryPointsCollection(entry_points); |
1371 | 1508 |
1372 Dart_EnterIsolate(UriResolverIsolateScope::isolate); | 1509 Dart_EnterIsolate(UriResolverIsolateScope::isolate); |
1373 Dart_ShutdownIsolate(); | 1510 Dart_ShutdownIsolate(); |
1374 } else { | 1511 } else { |
1375 SetupForGenericSnapshotCreation(); | 1512 SetupForGenericSnapshotCreation(); |
1376 CreateAndWriteSnapshot(); | 1513 CreateAndWriteCoreSnapshot(); |
1514 | |
1515 Dart_ExitScope(); | |
1516 Dart_ShutdownIsolate(); | |
1377 } | 1517 } |
1378 error = Dart_Cleanup(); | 1518 error = Dart_Cleanup(); |
1379 if (error != NULL) { | 1519 if (error != NULL) { |
1380 Log::PrintErr("VM cleanup failed: %s\n", error); | 1520 Log::PrintErr("VM cleanup failed: %s\n", error); |
1381 free(error); | 1521 free(error); |
1382 } | 1522 } |
1383 EventHandler::Stop(); | 1523 EventHandler::Stop(); |
1384 return 0; | 1524 return 0; |
1385 } | 1525 } |
1386 | 1526 |
1387 } // namespace bin | 1527 } // namespace bin |
1388 } // namespace dart | 1528 } // namespace dart |
1389 | 1529 |
1390 int main(int argc, char** argv) { | 1530 int main(int argc, char** argv) { |
1391 return dart::bin::main(argc, argv); | 1531 return dart::bin::main(argc, argv); |
1392 } | 1532 } |
OLD | NEW |