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

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

Issue 1947783003: Simplify command line options for creating snapshots. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/testing/dart/compiler_configuration.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "include/dart_tools_api.h" 10 #include "include/dart_tools_api.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 * Global state used to control and store generation of application snapshots 45 * Global state used to control and store generation of application snapshots
46 * (script/full). 46 * (script/full).
47 * A full application snapshot can be generated and run using the following 47 * A full application snapshot can be generated and run using the following
48 * commands 48 * commands
49 * - Generating a full application snapshot : 49 * - Generating a full application snapshot :
50 * dart_bootstrap --full-snapshot-after-run=<filename> --package-root=<dirs> 50 * dart_bootstrap --full-snapshot-after-run=<filename> --package-root=<dirs>
51 * <script_uri> [<script_options>] 51 * <script_uri> [<script_options>]
52 * - Running the full application snapshot generated above : 52 * - Running the full application snapshot generated above :
53 * dart --run-full-snapshot=<filename> <script_uri> [<script_options>] 53 * dart --run-full-snapshot=<filename> <script_uri> [<script_options>]
54 */ 54 */
55 static bool generate_script_snapshot = false; 55 static bool run_app_snapshot = false;
56 static bool generate_full_snapshot_after_run = false;
57 static bool run_full_snapshot = false;
58 static const char* snapshot_filename = NULL; 56 static const char* snapshot_filename = NULL;
57 enum SnapshotKind {
58 kNone,
59 kScript,
60 kAppAOT,
61 kAppJITAfterRun,
62 kAppAfterRun,
63 };
64 static SnapshotKind gen_snapshot_kind = kNone;
59 65
60 // Value of the --package-root flag. 66 // Value of the --package-root flag.
61 // (This pointer points into an argv buffer and does not need to be 67 // (This pointer points into an argv buffer and does not need to be
62 // free'd.) 68 // free'd.)
63 static const char* commandline_package_root = NULL; 69 static const char* commandline_package_root = NULL;
64 70
65 // Value of the --packages flag. 71 // Value of the --packages flag.
66 // (This pointer points into an argv buffer and does not need to be 72 // (This pointer points into an argv buffer and does not need to be
67 // free'd.) 73 // free'd.)
68 static const char* commandline_packages_file = NULL; 74 static const char* commandline_packages_file = NULL;
69 75
70 76
71 // Global flag that is used to indicate that we want to compile all the 77 // Global flag that is used to indicate that we want to compile all the
72 // dart functions and not run anything. 78 // dart functions and not run anything.
73 static bool compile_all = false; 79 static bool compile_all = false;
74 80
75 81
76 // Global flag that is used to indicate that we want to compile all the
77 // dart functions before running main and not compile anything thereafter.
78 static bool gen_precompiled_snapshot = false;
79 static bool gen_precompiled_jit_snapshot = false;
80
81
82 // Global flag that is used to indicate that we want to run from a precompiled
83 // snapshot.
84 static bool run_precompiled_snapshot = false;
85 static bool run_precompiled_jit_snapshot = false;
86
87
88 // Global flag that is used to indicate that we want to use blobs/mmap instead 82 // Global flag that is used to indicate that we want to use blobs/mmap instead
89 // of assembly/shared libraries for precompilation. 83 // of assembly/shared libraries for precompilation.
90 static bool use_blobs = false; 84 static bool use_blobs = false;
91 85
92 86
93 // Value of the --gen/run_precompiled_snapshot flag.
94 // (This pointer points into an argv buffer and does not need to be
95 // free'd.)
96 static const char* precompiled_snapshot_directory = NULL;
97
98
99 // Global flag that is used to indicate that we want to compile everything in 87 // Global flag that is used to indicate that we want to compile everything in
100 // the same way as precompilation before main, then continue running in the 88 // the same way as precompilation before main, then continue running in the
101 // same process. 89 // same process.
102 // Always set this with dart_noopt. 90 // Always set this with dart_noopt.
103 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) 91 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT)
104 static const bool is_noopt = true; 92 static const bool is_noopt = true;
105 #else 93 #else
106 static const bool is_noopt = false; 94 static const bool is_noopt = false;
107 #endif 95 #endif
108 96
109 97
110 extern const char* kPrecompiledLibraryName; 98 extern const char* kPrecompiledLibraryName;
111 extern const char* kPrecompiledInstructionsSymbolName; 99 extern const char* kPrecompiledInstructionsSymbolName;
112 extern const char* kPrecompiledDataSymbolName; 100 extern const char* kPrecompiledDataSymbolName;
113 static const char* kPrecompiledVmIsolateName = "precompiled.vmisolate"; 101
114 static const char* kPrecompiledIsolateName = "precompiled.isolate"; 102 static const char* kVMIsolateSuffix = "snapshot.vmisolate";
115 static const char* kPrecompiledAssemblyName = "precompiled.S"; 103 static const char* kIsolateSuffix = "snapshot.isolate";
116 static const char* kPrecompiledInstructionsBlobName = 104 static const char* kAssemblySuffix = "snapshot.S";
117 "precompiled.instructions"; 105 static const char* kInstructionsSuffix = "snapshot.instructions";
118 static const char* kPrecompiledRodataBlobName = "precompiled.rodata"; 106 static const char* kRODataSuffix = "snapshot.rodata";
119 static const char* kVMIsolateSuffix = "vmisolate"; 107
120 static const char* kIsolateSuffix = "isolate";
121 108
122 // Global flag that is used to indicate that we want to trace resolution of 109 // Global flag that is used to indicate that we want to trace resolution of
123 // URIs and the loading of libraries, parts and scripts. 110 // URIs and the loading of libraries, parts and scripts.
124 static bool trace_loading = false; 111 static bool trace_loading = false;
125 112
126 113
127 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; 114 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1";
128 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; 115 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181;
129 // VM Service options. 116 // VM Service options.
130 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP; 117 static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 CommandLineOptions* vm_options) { 327 CommandLineOptions* vm_options) {
341 ASSERT(arg != NULL); 328 ASSERT(arg != NULL);
342 if (*arg != '\0') { 329 if (*arg != '\0') {
343 return false; 330 return false;
344 } 331 }
345 use_blobs = true; 332 use_blobs = true;
346 return true; 333 return true;
347 } 334 }
348 335
349 336
350 static bool ProcessGenPrecompiledSnapshotOption( 337 static bool ProcessSnapshotFilenameOption(const char* filename,
351 const char* arg, 338 CommandLineOptions* vm_options) {
352 CommandLineOptions* vm_options) {
353 #if !defined(DART_PRECOMPILER)
354 Log::PrintErr("Precompiled snapshots must be generated with "
355 "dart_bootstrap.\n");
356 return false;
357 #else // defined(DART_PRECOMPILER)
358 ASSERT(arg != NULL);
359 if ((arg[0] == '=') || (arg[0] == ':')) {
360 precompiled_snapshot_directory = &arg[1];
361 } else {
362 precompiled_snapshot_directory = arg;
363 }
364 gen_precompiled_snapshot = true;
365 vm_options->AddArgument("--precompilation");
366 return true;
367 #endif // defined(DART_PRECOMPILER)
368 }
369
370
371 static bool ProcessGenPrecompiledJITSnapshotOption(
372 const char* arg,
373 CommandLineOptions* vm_options) {
374 ASSERT(arg != NULL);
375 if ((arg[0] == '=') || (arg[0] == ':')) {
376 precompiled_snapshot_directory = &arg[1];
377 } else {
378 precompiled_snapshot_directory = arg;
379 }
380 gen_precompiled_jit_snapshot = true;
381 return true;
382 }
383
384
385 static bool ProcessRunPrecompiledSnapshotOption(
386 const char* arg,
387 CommandLineOptions* vm_options) {
388 ASSERT(arg != NULL);
389 precompiled_snapshot_directory = arg;
390 if ((precompiled_snapshot_directory[0] == '=') ||
391 (precompiled_snapshot_directory[0] == ':')) {
392 precompiled_snapshot_directory = &precompiled_snapshot_directory[1];
393 }
394 run_precompiled_snapshot = true;
395 vm_options->AddArgument("--precompilation");
396 return true;
397 }
398
399
400 static bool ProcessRunPrecompiledJITSnapshotOption(
401 const char* arg,
402 CommandLineOptions* vm_options) {
403 ASSERT(arg != NULL);
404 precompiled_snapshot_directory = arg;
405 if ((precompiled_snapshot_directory[0] == '=') ||
406 (precompiled_snapshot_directory[0] == ':')) {
407 precompiled_snapshot_directory = &precompiled_snapshot_directory[1];
408 }
409 run_precompiled_jit_snapshot = true;
410 return true;
411 }
412
413
414 static bool ProcessSnapshotOptionHelper(const char* filename,
415 bool* snapshot_option) {
416 ASSERT((filename != NULL) && (strlen(filename) != 0));
417 snapshot_filename = filename; 339 snapshot_filename = filename;
418 *snapshot_option = true; 340 if (gen_snapshot_kind == kNone) {
419 if (generate_script_snapshot && generate_full_snapshot_after_run) { 341 gen_snapshot_kind = kScript; // Default behavior.
420 Log::PrintErr("--snapshot and --snapshot-after-run options"
421 " cannot be specified at the same time\n");
422 *snapshot_option = false;
423 return false;
424 } 342 }
425 return true; 343 return true;
426 } 344 }
427 345
428 346
429 static bool ProcessScriptSnapshotOption(const char* filename, 347 static bool ProcessSnapshotKindOption(const char* kind,
430 CommandLineOptions* vm_options) { 348 CommandLineOptions* vm_options) {
431 if ((filename == NULL) || (strlen(filename) == 0)) { 349 if (strcmp(kind, "script") == 0) {
432 return false; 350 gen_snapshot_kind = kScript;
351 return true;
352 } else if (strcmp(kind, "app-aot") == 0) {
353 gen_snapshot_kind = kAppAOT;
354 return true;
355 } else if (strcmp(kind, "app-jit-after-run") == 0) {
356 gen_snapshot_kind = kAppJITAfterRun;
357 return true;
358 } else if (strcmp(kind, "app-after-run") == 0) {
359 gen_snapshot_kind = kAppAfterRun;
360 return true;
433 } 361 }
434 // Ensure that we are already running using a full snapshot. 362 Log::PrintErr("Unrecognized snapshot kind: '%s'\nValid kinds are: "
435 if (isolate_snapshot_buffer == NULL) { 363 "script, app-aot, app-jit-after-run, app-after-run\n", kind);
436 Log::PrintErr("Script snapshots cannot be generated in this version of" 364 return false;
437 " Dart\n");
438 return false;
439 }
440 return ProcessSnapshotOptionHelper(filename, &generate_script_snapshot);
441 } 365 }
442 366
443 367
444 static bool ProcessFullSnapshotAfterRunOption( 368 static bool ProcessRunAppSnapshotOption(
445 const char* filename, CommandLineOptions* vm_options) { 369 const char* filename, CommandLineOptions* vm_options) {
446 if ((filename == NULL) || (strlen(filename) == 0)) { 370 ASSERT(filename != NULL);
447 return false; 371 snapshot_filename = filename;
448 } 372 run_app_snapshot = true;
449 // Ensure that we are running 'dart_bootstrap'. 373 return true;
450 if (isolate_snapshot_buffer != NULL) {
451 Log::PrintErr("Full Application snapshots must be generated with"
452 " dart_bootstrap\n");
453 return false;
454 }
455 return ProcessSnapshotOptionHelper(filename,
456 &generate_full_snapshot_after_run);
457 } 374 }
458 375
459 376
460 static bool ProcessRunFullSnapshotOption(
461 const char* filename, CommandLineOptions* vm_options) {
462 #if !defined(PRODUCT)
463 Log::PrintErr("Full Application snapshots can only be be run with"
464 " product mode\n");
465 return false;
466 #else
467 return ProcessSnapshotOptionHelper(filename, &run_full_snapshot);
468 #endif // defined(PRODUCT)
469 }
470
471
472 static bool ProcessEnableVmServiceOption(const char* option_value, 377 static bool ProcessEnableVmServiceOption(const char* option_value,
473 CommandLineOptions* vm_options) { 378 CommandLineOptions* vm_options) {
474 ASSERT(option_value != NULL); 379 ASSERT(option_value != NULL);
475 380
476 if (!ExtractPortAndIP(option_value, 381 if (!ExtractPortAndIP(option_value,
477 &vm_service_server_port, 382 &vm_service_server_port,
478 &vm_service_server_ip, 383 &vm_service_server_ip,
479 DEFAULT_VM_SERVICE_SERVER_PORT, 384 DEFAULT_VM_SERVICE_SERVER_PORT,
480 DEFAULT_VM_SERVICE_SERVER_IP)) { 385 DEFAULT_VM_SERVICE_SERVER_IP)) {
481 Log::PrintErr("unrecognized --enable-vm-service option syntax. " 386 Log::PrintErr("unrecognized --enable-vm-service option syntax. "
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 { "-h", ProcessHelpOption }, 460 { "-h", ProcessHelpOption },
556 { "--help", ProcessHelpOption }, 461 { "--help", ProcessHelpOption },
557 { "--packages=", ProcessPackagesOption }, 462 { "--packages=", ProcessPackagesOption },
558 { "--package-root=", ProcessPackageRootOption }, 463 { "--package-root=", ProcessPackageRootOption },
559 { "-v", ProcessVerboseOption }, 464 { "-v", ProcessVerboseOption },
560 { "--verbose", ProcessVerboseOption }, 465 { "--verbose", ProcessVerboseOption },
561 { "--version", ProcessVersionOption }, 466 { "--version", ProcessVersionOption },
562 467
563 // VM specific options to the standalone dart program. 468 // VM specific options to the standalone dart program.
564 { "--compile_all", ProcessCompileAllOption }, 469 { "--compile_all", ProcessCompileAllOption },
565 { "--use_blobs", ProcessUseBlobsOption },
566 { "--enable-vm-service", ProcessEnableVmServiceOption }, 470 { "--enable-vm-service", ProcessEnableVmServiceOption },
567 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption },
568 { "--gen-precompiled-jit-snapshot", ProcessGenPrecompiledJITSnapshotOption },
569 { "--observe", ProcessObserveOption }, 471 { "--observe", ProcessObserveOption },
570 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption },
571 { "--run-precompiled-jit-snapshot", ProcessRunPrecompiledJITSnapshotOption },
572 { "--shutdown", ProcessShutdownOption }, 472 { "--shutdown", ProcessShutdownOption },
573 { "--snapshot=", ProcessScriptSnapshotOption }, 473 { "--snapshot=", ProcessSnapshotFilenameOption },
574 { "--full-snapshot-after-run=", ProcessFullSnapshotAfterRunOption }, 474 { "--snapshot-kind=", ProcessSnapshotKindOption },
575 { "--run-full-snapshot=", ProcessRunFullSnapshotOption }, 475 { "--run-app-snapshot=", ProcessRunAppSnapshotOption },
476 { "--use-blobs", ProcessUseBlobsOption },
576 { "--trace-loading", ProcessTraceLoadingOption }, 477 { "--trace-loading", ProcessTraceLoadingOption },
577 { NULL, NULL } 478 { NULL, NULL }
578 }; 479 };
579 480
580 481
581 static bool ProcessMainOptions(const char* option, 482 static bool ProcessMainOptions(const char* option,
582 CommandLineOptions* vm_options) { 483 CommandLineOptions* vm_options) {
583 int i = 0; 484 int i = 0;
584 const char* name = main_options[0].option_name; 485 const char* name = main_options[0].option_name;
585 int option_length = strlen(option); 486 int option_length = strlen(option);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 i++; 583 i++;
683 } 584 }
684 585
685 // Verify consistency of arguments. 586 // Verify consistency of arguments.
686 if ((commandline_package_root != NULL) && 587 if ((commandline_package_root != NULL) &&
687 (commandline_packages_file != NULL)) { 588 (commandline_packages_file != NULL)) {
688 Log::PrintErr("Specifying both a packages directory and a packages " 589 Log::PrintErr("Specifying both a packages directory and a packages "
689 "file is invalid.\n"); 590 "file is invalid.\n");
690 return -1; 591 return -1;
691 } 592 }
692 if (is_noopt) { 593 if (is_noopt && gen_snapshot_kind != kNone) {
693 if (gen_precompiled_snapshot) { 594 Log::PrintErr("Generating a snapshot with dart_noopt is invalid.\n");
694 Log::PrintErr("Running dart_noopt with --gen_precompiled_snapshot"
695 " is invalid.\n");
696 return -1;
697 }
698 if (run_precompiled_snapshot) {
699 Log::PrintErr("Running dart_noopt with --run_precompiled_snapshot"
700 " is invalid.\n");
701 return -1;
702 }
703 }
704 if (run_full_snapshot && run_precompiled_snapshot) {
705 Log::PrintErr("Specifying --run_full_snapshot and"
706 " --run_precompiled_snapshot is invalid.\n");
707 return -1; 595 return -1;
708 } 596 }
709 if ((generate_full_snapshot_after_run || gen_precompiled_snapshot) && 597 if ((gen_snapshot_kind != kNone) && (snapshot_filename == NULL)) {
710 (run_full_snapshot || run_precompiled_snapshot)) { 598 Log::PrintErr("Generating a snapshot requires a filename (--snapshot).\n");
599 return -1;
600 }
601 if ((gen_snapshot_kind != kNone) && run_app_snapshot) {
711 Log::PrintErr("Specifying an option to generate a snapshot and" 602 Log::PrintErr("Specifying an option to generate a snapshot and"
712 " run using a snapshot is invalid.\n"); 603 " run using a snapshot is invalid.\n");
713 return -1; 604 return -1;
714 } 605 }
715 606
716 return 0; 607 return 0;
717 } 608 }
718 609
719 610
720 static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) { 611 static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 // Returns true on success, false on failure. 682 // Returns true on success, false on failure.
792 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, 683 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
793 const char* main, 684 const char* main,
794 const char* package_root, 685 const char* package_root,
795 const char* packages_config, 686 const char* packages_config,
796 Dart_IsolateFlags* flags, 687 Dart_IsolateFlags* flags,
797 char** error, 688 char** error,
798 int* exit_code) { 689 int* exit_code) {
799 ASSERT(script_uri != NULL); 690 ASSERT(script_uri != NULL);
800 691
692 const bool needs_load_port = !run_app_snapshot;
801 #if defined(PRODUCT) 693 #if defined(PRODUCT)
802 const bool run_service_isolate = !run_full_snapshot && 694 const bool run_service_isolate = needs_load_port;
803 !run_precompiled_snapshot;
804 #else 695 #else
805 const bool run_service_isolate = !run_full_snapshot; 696 // Always create the service isolate in DEBUG and RELEASE modes for profiling,
697 // even if we don't need it for loading.
698 const bool run_service_isolate = true;
806 #endif // PRODUCT 699 #endif // PRODUCT
807 if (!run_service_isolate && 700 if (!run_service_isolate &&
808 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { 701 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) {
809 // We do not create a service isolate when running a full application
810 // snapshot or a precompiled snapshot in product mode.
811 return NULL; 702 return NULL;
812 } 703 }
813 704
814 IsolateData* isolate_data = new IsolateData(script_uri, 705 IsolateData* isolate_data = new IsolateData(script_uri,
815 package_root, 706 package_root,
816 packages_config); 707 packages_config);
817 Dart_Isolate isolate = Dart_CreateIsolate(script_uri, 708 Dart_Isolate isolate = Dart_CreateIsolate(script_uri,
818 main, 709 main,
819 isolate_snapshot_buffer, 710 isolate_snapshot_buffer,
820 flags, 711 flags,
(...skipping 11 matching lines...) Expand all
832 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 723 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
833 Builtin::SetNativeResolver(Builtin::kIOLibrary); 724 Builtin::SetNativeResolver(Builtin::kIOLibrary);
834 } 725 }
835 726
836 // Set up the library tag handler for this isolate. 727 // Set up the library tag handler for this isolate.
837 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); 728 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler);
838 CHECK_RESULT(result); 729 CHECK_RESULT(result);
839 730
840 if (Dart_IsServiceIsolate(isolate)) { 731 if (Dart_IsServiceIsolate(isolate)) {
841 // If this is the service isolate, load embedder specific bits and return. 732 // If this is the service isolate, load embedder specific bits and return.
842 bool skip_library_load = run_precompiled_snapshot || 733 bool skip_library_load = run_app_snapshot;
843 run_precompiled_jit_snapshot;
844 if (!VmService::Setup(vm_service_server_ip, 734 if (!VmService::Setup(vm_service_server_ip,
845 vm_service_server_port, 735 vm_service_server_port,
846 skip_library_load)) { 736 skip_library_load)) {
847 *error = strdup(VmService::GetErrorMessage()); 737 *error = strdup(VmService::GetErrorMessage());
848 return NULL; 738 return NULL;
849 } 739 }
850 if (compile_all) { 740 if (compile_all) {
851 result = Dart_CompileAll(); 741 result = Dart_CompileAll();
852 CHECK_RESULT(result); 742 CHECK_RESULT(result);
853 } 743 }
854 Dart_ExitScope(); 744 Dart_ExitScope();
855 Dart_ExitIsolate(); 745 Dart_ExitIsolate();
856 return isolate; 746 return isolate;
857 } 747 }
858 748
859 // Prepare builtin and other core libraries for use to resolve URIs. 749 // Prepare builtin and other core libraries for use to resolve URIs.
860 // Set up various closures, e.g: printing, timers etc. 750 // Set up various closures, e.g: printing, timers etc.
861 // Set up 'package root' for URI resolution. 751 // Set up 'package root' for URI resolution.
862 result = DartUtils::PrepareForScriptLoading(false, trace_loading); 752 result = DartUtils::PrepareForScriptLoading(false, trace_loading);
863 CHECK_RESULT(result); 753 CHECK_RESULT(result);
864 754
865 if (!run_precompiled_snapshot && 755 if (needs_load_port) {
866 !run_precompiled_jit_snapshot &&
867 !run_full_snapshot) {
868 // Set up the load port provided by the service isolate so that we can 756 // Set up the load port provided by the service isolate so that we can
869 // load scripts. 757 // load scripts.
870 // With a full snapshot or a precompiled snapshot in product mode, there is
871 // no service isolate. A precompiled snapshot in release or debug mode does
872 // have the service isolate, but it doesn't use it for loading.
873 result = DartUtils::SetupServiceLoadPort(); 758 result = DartUtils::SetupServiceLoadPort();
874 CHECK_RESULT(result); 759 CHECK_RESULT(result);
875 } 760 }
876 761
877 // Setup package root if specified. 762 // Setup package root if specified.
878 result = DartUtils::SetupPackageRoot(package_root, packages_config); 763 result = DartUtils::SetupPackageRoot(package_root, packages_config);
879 CHECK_RESULT(result); 764 CHECK_RESULT(result);
880 765
881 result = Dart_SetEnvironmentCallback(EnvironmentCallback); 766 result = Dart_SetEnvironmentCallback(EnvironmentCallback);
882 CHECK_RESULT(result); 767 CHECK_RESULT(result);
883 768
884 if (run_precompiled_snapshot) { 769 if (run_app_snapshot) {
885 // No setup.
886 } else if (run_full_snapshot || run_precompiled_jit_snapshot) {
887 result = DartUtils::SetupIOLibrary(script_uri); 770 result = DartUtils::SetupIOLibrary(script_uri);
888 CHECK_RESULT(result); 771 CHECK_RESULT(result);
889 } else { 772 } else {
890 // Load the specified application script into the newly created isolate. 773 // Load the specified application script into the newly created isolate.
891 result = DartUtils::LoadScript(script_uri); 774 result = DartUtils::LoadScript(script_uri);
892 CHECK_RESULT(result); 775 CHECK_RESULT(result);
893 776
894 // Run event-loop and wait for script loading to complete. 777 // Run event-loop and wait for script loading to complete.
895 result = Dart_RunLoop(); 778 result = Dart_RunLoop();
896 CHECK_RESULT(result); 779 CHECK_RESULT(result);
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 const char* qualified_libname; 1120 const char* qualified_libname;
1238 if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) { 1121 if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) {
1239 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, libname); 1122 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, libname);
1240 concat = new char[len + 1]; 1123 concat = new char[len + 1];
1241 snprintf(concat, len + 1, "%s/%s", snapshot_directory, libname); 1124 snprintf(concat, len + 1, "%s/%s", snapshot_directory, libname);
1242 qualified_libname = concat; 1125 qualified_libname = concat;
1243 } else { 1126 } else {
1244 qualified_libname = libname; 1127 qualified_libname = libname;
1245 } 1128 }
1246 void* library = Extensions::LoadExtensionLibrary(qualified_libname); 1129 void* library = Extensions::LoadExtensionLibrary(qualified_libname);
1247 if (library == NULL) {
1248 Log::PrintErr("Error: Failed to load library '%s'\n", qualified_libname);
1249 Platform::Exit(kErrorExitCode);
1250 }
1251 void* symbol = Extensions::ResolveSymbol(library, symname);
1252 if (symbol == NULL) {
1253 Log::PrintErr("Error: Failed to load symbol '%s'\n", symname);
1254 Platform::Exit(kErrorExitCode);
1255 }
1256 if (concat != NULL) { 1130 if (concat != NULL) {
1257 delete concat; 1131 delete concat;
1258 } 1132 }
1259 return symbol; 1133 if (library == NULL) {
1134 return NULL;
1135 }
1136 return Extensions::ResolveSymbol(library, symname);
1260 } 1137 }
1261 1138
1262 1139
1263 static void GenerateScriptSnapshot() { 1140 static void GenerateScriptSnapshot() {
1264 // First create a snapshot. 1141 // First create a snapshot.
1265 uint8_t* buffer = NULL; 1142 uint8_t* buffer = NULL;
1266 intptr_t size = 0; 1143 intptr_t size = 0;
1267 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); 1144 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size);
1268 if (Dart_IsError(result)) { 1145 if (Dart_IsError(result)) {
1269 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1146 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1270 } 1147 }
1271 1148
1272 WriteSnapshotFile(NULL, snapshot_filename, true, buffer, size); 1149 WriteSnapshotFile(NULL, snapshot_filename, true, buffer, size);
1273 } 1150 }
1274 1151
1275 1152
1276 static void ComputeSnapshotFilenames(const char* filename,
1277 char** vm_snapshot_fname,
1278 char** isolate_snapshot_fname) {
1279 intptr_t len = snprintf(NULL, 0, "%s.%s", filename, kVMIsolateSuffix);
1280 *vm_snapshot_fname = new char[len + 1];
1281 snprintf(*vm_snapshot_fname, len + 1, "%s.%s", filename, kVMIsolateSuffix);
1282
1283 len = snprintf(NULL, 0, "%s.%s", filename, kIsolateSuffix);
1284 *isolate_snapshot_fname = new char[len + 1];
1285 snprintf(*isolate_snapshot_fname, len + 1, "%s.%s", filename, kIsolateSuffix);
1286 }
1287
1288
1289 static void GeneratePrecompiledSnapshot() { 1153 static void GeneratePrecompiledSnapshot() {
1290 uint8_t* vm_isolate_buffer = NULL; 1154 uint8_t* vm_isolate_buffer = NULL;
1291 intptr_t vm_isolate_size = 0; 1155 intptr_t vm_isolate_size = 0;
1292 uint8_t* isolate_buffer = NULL; 1156 uint8_t* isolate_buffer = NULL;
1293 intptr_t isolate_size = 0; 1157 intptr_t isolate_size = 0;
1294 uint8_t* assembly_buffer = NULL; 1158 uint8_t* assembly_buffer = NULL;
1295 intptr_t assembly_size = 0; 1159 intptr_t assembly_size = 0;
1296 uint8_t* instructions_blob_buffer = NULL; 1160 uint8_t* instructions_blob_buffer = NULL;
1297 intptr_t instructions_blob_size = 0; 1161 intptr_t instructions_blob_size = 0;
1298 uint8_t* rodata_blob_buffer = NULL; 1162 uint8_t* rodata_blob_buffer = NULL;
(...skipping 14 matching lines...) Expand all
1313 &vm_isolate_buffer, 1177 &vm_isolate_buffer,
1314 &vm_isolate_size, 1178 &vm_isolate_size,
1315 &isolate_buffer, 1179 &isolate_buffer,
1316 &isolate_size, 1180 &isolate_size,
1317 &assembly_buffer, 1181 &assembly_buffer,
1318 &assembly_size); 1182 &assembly_size);
1319 } 1183 }
1320 if (Dart_IsError(result)) { 1184 if (Dart_IsError(result)) {
1321 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1185 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1322 } 1186 }
1323 WriteSnapshotFile(precompiled_snapshot_directory, 1187 WriteSnapshotFile(snapshot_filename, kVMIsolateSuffix,
1324 kPrecompiledVmIsolateName,
1325 false, 1188 false,
1326 vm_isolate_buffer, 1189 vm_isolate_buffer,
1327 vm_isolate_size); 1190 vm_isolate_size);
1328 WriteSnapshotFile(precompiled_snapshot_directory, 1191 WriteSnapshotFile(snapshot_filename, kIsolateSuffix,
1329 kPrecompiledIsolateName,
1330 false, 1192 false,
1331 isolate_buffer, 1193 isolate_buffer,
1332 isolate_size); 1194 isolate_size);
1333 if (use_blobs) { 1195 if (use_blobs) {
1334 WriteSnapshotFile(precompiled_snapshot_directory, 1196 WriteSnapshotFile(snapshot_filename, kInstructionsSuffix,
1335 kPrecompiledInstructionsBlobName,
1336 false, 1197 false,
1337 instructions_blob_buffer, 1198 instructions_blob_buffer,
1338 instructions_blob_size); 1199 instructions_blob_size);
1339 WriteSnapshotFile(precompiled_snapshot_directory, 1200 WriteSnapshotFile(snapshot_filename, kRODataSuffix,
1340 kPrecompiledRodataBlobName,
1341 false, 1201 false,
1342 rodata_blob_buffer, 1202 rodata_blob_buffer,
1343 rodata_blob_size); 1203 rodata_blob_size);
1344 } else { 1204 } else {
1345 WriteSnapshotFile(precompiled_snapshot_directory, 1205 WriteSnapshotFile(snapshot_filename, kAssemblySuffix,
1346 kPrecompiledAssemblyName,
1347 false, 1206 false,
1348 assembly_buffer, 1207 assembly_buffer,
1349 assembly_size); 1208 assembly_size);
1350 } 1209 }
1351 } 1210 }
1352 1211
1353 1212
1354 static void GeneratePrecompiledJITSnapshot() { 1213 static void GeneratePrecompiledJITSnapshot() {
1214 if (!use_blobs) {
1215 ErrorExit(kErrorExitCode,
1216 "Generating app JIT snapshots as assembly unimplemented\n");
1217 }
1355 uint8_t* vm_isolate_buffer = NULL; 1218 uint8_t* vm_isolate_buffer = NULL;
1356 intptr_t vm_isolate_size = 0; 1219 intptr_t vm_isolate_size = 0;
1357 uint8_t* isolate_buffer = NULL; 1220 uint8_t* isolate_buffer = NULL;
1358 intptr_t isolate_size = 0; 1221 intptr_t isolate_size = 0;
1359 uint8_t* instructions_blob_buffer = NULL; 1222 uint8_t* instructions_blob_buffer = NULL;
1360 intptr_t instructions_blob_size = 0; 1223 intptr_t instructions_blob_size = 0;
1361 uint8_t* rodata_blob_buffer = NULL; 1224 uint8_t* rodata_blob_buffer = NULL;
1362 intptr_t rodata_blob_size = 0; 1225 intptr_t rodata_blob_size = 0;
1363 Dart_Handle result = Dart_CreatePrecompiledJITSnapshotBlob( 1226 Dart_Handle result = Dart_CreatePrecompiledJITSnapshotBlob(
1364 &vm_isolate_buffer, 1227 &vm_isolate_buffer,
1365 &vm_isolate_size, 1228 &vm_isolate_size,
1366 &isolate_buffer, 1229 &isolate_buffer,
1367 &isolate_size, 1230 &isolate_size,
1368 &instructions_blob_buffer, 1231 &instructions_blob_buffer,
1369 &instructions_blob_size, 1232 &instructions_blob_size,
1370 &rodata_blob_buffer, 1233 &rodata_blob_buffer,
1371 &rodata_blob_size); 1234 &rodata_blob_size);
1372 if (Dart_IsError(result)) { 1235 if (Dart_IsError(result)) {
1373 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1236 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1374 } 1237 }
1375 WriteSnapshotFile(precompiled_snapshot_directory, 1238 WriteSnapshotFile(snapshot_filename, kVMIsolateSuffix,
1376 kPrecompiledVmIsolateName,
1377 false, 1239 false,
1378 vm_isolate_buffer, 1240 vm_isolate_buffer,
1379 vm_isolate_size); 1241 vm_isolate_size);
1380 WriteSnapshotFile(precompiled_snapshot_directory, 1242 WriteSnapshotFile(snapshot_filename, kIsolateSuffix,
1381 kPrecompiledIsolateName,
1382 false, 1243 false,
1383 isolate_buffer, 1244 isolate_buffer,
1384 isolate_size); 1245 isolate_size);
1385 WriteSnapshotFile(precompiled_snapshot_directory, 1246 WriteSnapshotFile(snapshot_filename, kInstructionsSuffix,
1386 kPrecompiledInstructionsBlobName,
1387 false, 1247 false,
1388 instructions_blob_buffer, 1248 instructions_blob_buffer,
1389 instructions_blob_size); 1249 instructions_blob_size);
1390 WriteSnapshotFile(precompiled_snapshot_directory, 1250 WriteSnapshotFile(snapshot_filename, kRODataSuffix,
1391 kPrecompiledRodataBlobName,
1392 false, 1251 false,
1393 rodata_blob_buffer, 1252 rodata_blob_buffer,
1394 rodata_blob_size); 1253 rodata_blob_size);
1395 } 1254 }
1396 1255
1397 1256
1398 static void GenerateFullSnapshot() { 1257 static void GenerateFullSnapshot() {
1399 // Create a full snapshot of the script. 1258 // Create a full snapshot of the script.
1400 Dart_Handle result; 1259 Dart_Handle result;
1401 uint8_t* vm_isolate_buffer = NULL; 1260 uint8_t* vm_isolate_buffer = NULL;
1402 intptr_t vm_isolate_size = 0; 1261 intptr_t vm_isolate_size = 0;
1403 uint8_t* isolate_buffer = NULL; 1262 uint8_t* isolate_buffer = NULL;
1404 intptr_t isolate_size = 0; 1263 intptr_t isolate_size = 0;
1405 char* vm_snapshot_fname = NULL;
1406 char* isolate_snapshot_fname = NULL;
1407 1264
1408 result = Dart_CreateSnapshot(&vm_isolate_buffer, 1265 result = Dart_CreateSnapshot(&vm_isolate_buffer,
1409 &vm_isolate_size, 1266 &vm_isolate_size,
1410 &isolate_buffer, 1267 &isolate_buffer,
1411 &isolate_size); 1268 &isolate_size);
1412 if (Dart_IsError(result)) { 1269 if (Dart_IsError(result)) {
1413 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1270 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1414 } 1271 }
1415 1272
1416 // Compute snapshot file names and write out the snapshot files. 1273 WriteSnapshotFile(snapshot_filename,
1417 ComputeSnapshotFilenames(snapshot_filename, 1274 kVMIsolateSuffix,
1418 &vm_snapshot_fname,
1419 &isolate_snapshot_fname);
1420 WriteSnapshotFile(NULL,
1421 vm_snapshot_fname,
1422 false, 1275 false,
1423 vm_isolate_buffer, 1276 vm_isolate_buffer,
1424 vm_isolate_size); 1277 vm_isolate_size);
1425 WriteSnapshotFile(NULL, 1278 WriteSnapshotFile(snapshot_filename,
1426 isolate_snapshot_fname, 1279 kIsolateSuffix,
1427 false, 1280 false,
1428 isolate_buffer, 1281 isolate_buffer,
1429 isolate_size); 1282 isolate_size);
1430 } 1283 }
1431 1284
1432 1285
1433 #define CHECK_RESULT(result) \ 1286 #define CHECK_RESULT(result) \
1434 if (Dart_IsError(result)) { \ 1287 if (Dart_IsError(result)) { \
1435 if (Dart_IsVMRestartRequest(result)) { \ 1288 if (Dart_IsVMRestartRequest(result)) { \
1436 Dart_ExitScope(); \ 1289 Dart_ExitScope(); \
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 } 1332 }
1480 delete [] isolate_name; 1333 delete [] isolate_name;
1481 1334
1482 Dart_EnterIsolate(isolate); 1335 Dart_EnterIsolate(isolate);
1483 ASSERT(isolate == Dart_CurrentIsolate()); 1336 ASSERT(isolate == Dart_CurrentIsolate());
1484 ASSERT(isolate != NULL); 1337 ASSERT(isolate != NULL);
1485 Dart_Handle result; 1338 Dart_Handle result;
1486 1339
1487 Dart_EnterScope(); 1340 Dart_EnterScope();
1488 1341
1489 if (generate_script_snapshot) { 1342 if (gen_snapshot_kind == kScript) {
1490 GenerateScriptSnapshot(); 1343 GenerateScriptSnapshot();
1491 } else { 1344 } else {
1492 // Lookup the library of the root script. 1345 // Lookup the library of the root script.
1493 Dart_Handle root_lib = Dart_RootLibrary(); 1346 Dart_Handle root_lib = Dart_RootLibrary();
1494 // Import the root library into the builtin library so that we can easily 1347 // Import the root library into the builtin library so that we can easily
1495 // lookup the main entry point exported from the root library. 1348 // lookup the main entry point exported from the root library.
1496 IsolateData* isolate_data = 1349 IsolateData* isolate_data =
1497 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); 1350 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate));
1498 result = Dart_LibraryImportLibrary( 1351 result = Dart_LibraryImportLibrary(
1499 isolate_data->builtin_lib(), root_lib, Dart_Null()); 1352 isolate_data->builtin_lib(), root_lib, Dart_Null());
1500 #if !defined(PRODUCT) 1353 #if !defined(PRODUCT)
1501 if (is_noopt || gen_precompiled_snapshot || gen_precompiled_jit_snapshot) { 1354 if (is_noopt ||
1355 (gen_snapshot_kind == kAppAfterRun) ||
1356 (gen_snapshot_kind == kAppAOT) ||
1357 (gen_snapshot_kind == kAppJITAfterRun)) {
1502 // Load the embedder's portion of the VM service's Dart code so it will 1358 // Load the embedder's portion of the VM service's Dart code so it will
1503 // be included in the precompiled snapshot. 1359 // be included in the app snapshot.
1504 if (!VmService::LoadForGenPrecompiled()) { 1360 if (!VmService::LoadForGenPrecompiled()) {
1505 fprintf(stderr, 1361 fprintf(stderr,
1506 "VM service loading failed: %s\n", 1362 "VM service loading failed: %s\n",
1507 VmService::GetErrorMessage()); 1363 VmService::GetErrorMessage());
1508 fflush(stderr); 1364 fflush(stderr);
1509 exit(kErrorExitCode); 1365 exit(kErrorExitCode);
1510 } 1366 }
1511 } 1367 }
1512 #endif // PRODUCT 1368 #endif // PRODUCT
1513 1369
1514 if (compile_all) { 1370 if (compile_all) {
1515 result = Dart_CompileAll(); 1371 result = Dart_CompileAll();
1516 CHECK_RESULT(result); 1372 CHECK_RESULT(result);
1517 } 1373 }
1518 1374
1519 if (is_noopt || gen_precompiled_snapshot) { 1375 if (is_noopt || (gen_snapshot_kind == kAppAOT)) {
1520 Dart_QualifiedFunctionName standalone_entry_points[] = { 1376 Dart_QualifiedFunctionName standalone_entry_points[] = {
1521 { "dart:_builtin", "::", "_getMainClosure" }, 1377 { "dart:_builtin", "::", "_getMainClosure" },
1522 { "dart:_builtin", "::", "_getPrintClosure" }, 1378 { "dart:_builtin", "::", "_getPrintClosure" },
1523 { "dart:_builtin", "::", "_getUriBaseClosure" }, 1379 { "dart:_builtin", "::", "_getUriBaseClosure" },
1524 { "dart:_builtin", "::", "_resolveUri" }, 1380 { "dart:_builtin", "::", "_resolveUri" },
1525 { "dart:_builtin", "::", "_setWorkingDirectory" }, 1381 { "dart:_builtin", "::", "_setWorkingDirectory" },
1526 { "dart:_builtin", "::", "_setPackageRoot" }, 1382 { "dart:_builtin", "::", "_setPackageRoot" },
1527 { "dart:_builtin", "::", "_loadPackagesMap" }, 1383 { "dart:_builtin", "::", "_loadPackagesMap" },
1528 { "dart:_builtin", "::", "_loadDataAsync" }, 1384 { "dart:_builtin", "::", "_loadDataAsync" },
1529 { "dart:io", "::", "_makeUint8ListView" }, 1385 { "dart:io", "::", "_makeUint8ListView" },
(...skipping 14 matching lines...) Expand all
1544 { "dart:io", "_ProcessStartStatus", "set:_errorCode" }, 1400 { "dart:io", "_ProcessStartStatus", "set:_errorCode" },
1545 { "dart:io", "_ProcessStartStatus", "set:_errorMessage" }, 1401 { "dart:io", "_ProcessStartStatus", "set:_errorMessage" },
1546 { "dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE" }, 1402 { "dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE" },
1547 { "dart:io", "_SecureFilterImpl", "get:SIZE" }, 1403 { "dart:io", "_SecureFilterImpl", "get:SIZE" },
1548 #if !defined(PRODUCT) 1404 #if !defined(PRODUCT)
1549 { "dart:vmservice_io", "::", "main" }, 1405 { "dart:vmservice_io", "::", "main" },
1550 #endif // !PRODUCT 1406 #endif // !PRODUCT
1551 { NULL, NULL, NULL } // Must be terminated with NULL entries. 1407 { NULL, NULL, NULL } // Must be terminated with NULL entries.
1552 }; 1408 };
1553 1409
1554 const bool reset_fields = gen_precompiled_snapshot; 1410 const bool reset_fields = gen_snapshot_kind == kAppAOT;
1555 result = Dart_Precompile(standalone_entry_points, reset_fields); 1411 result = Dart_Precompile(standalone_entry_points, reset_fields);
1556 CHECK_RESULT(result); 1412 CHECK_RESULT(result);
1557 } 1413 }
1558 1414
1559 if (gen_precompiled_snapshot) { 1415 if (gen_snapshot_kind == kAppAOT) {
1560 GeneratePrecompiledSnapshot(); 1416 GeneratePrecompiledSnapshot();
1561 } else { 1417 } else {
1562 if (Dart_IsNull(root_lib)) { 1418 if (Dart_IsNull(root_lib)) {
1563 ErrorExit(kErrorExitCode, 1419 ErrorExit(kErrorExitCode,
1564 "Unable to find root library for '%s'\n", 1420 "Unable to find root library for '%s'\n",
1565 script_name); 1421 script_name);
1566 } 1422 }
1567 1423
1568 // The helper function _getMainClosure creates a closure for the main 1424 // The helper function _getMainClosure creates a closure for the main
1569 // entry point which is either explicitly or implictly exported from the 1425 // entry point which is either explicitly or implictly exported from the
(...skipping 11 matching lines...) Expand all
1581 1437
1582 Dart_Handle isolate_lib = 1438 Dart_Handle isolate_lib =
1583 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate")); 1439 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate"));
1584 result = Dart_Invoke(isolate_lib, 1440 result = Dart_Invoke(isolate_lib,
1585 Dart_NewStringFromCString("_startMainIsolate"), 1441 Dart_NewStringFromCString("_startMainIsolate"),
1586 kNumIsolateArgs, isolate_args); 1442 kNumIsolateArgs, isolate_args);
1587 CHECK_RESULT(result); 1443 CHECK_RESULT(result);
1588 1444
1589 // Keep handling messages until the last active receive port is closed. 1445 // Keep handling messages until the last active receive port is closed.
1590 result = Dart_RunLoop(); 1446 result = Dart_RunLoop();
1591 // Generate a full snapshot after execution if specified. 1447 // Generate an app snapshot after execution if specified.
1592 if (generate_full_snapshot_after_run || gen_precompiled_jit_snapshot) { 1448 if ((gen_snapshot_kind == kAppAfterRun) ||
1449 (gen_snapshot_kind == kAppJITAfterRun)) {
1593 if (!Dart_IsCompilationError(result) && 1450 if (!Dart_IsCompilationError(result) &&
1594 !Dart_IsVMRestartRequest(result)) { 1451 !Dart_IsVMRestartRequest(result)) {
1595 if (generate_full_snapshot_after_run) { 1452 if (gen_snapshot_kind == kAppAfterRun) {
1596 GenerateFullSnapshot(); 1453 GenerateFullSnapshot();
1597 } else { 1454 } else {
1598 Dart_Handle prepare_result = Dart_PrecompileJIT(); 1455 Dart_Handle prepare_result = Dart_PrecompileJIT();
1599 CHECK_RESULT(prepare_result); 1456 CHECK_RESULT(prepare_result);
1600 GeneratePrecompiledJITSnapshot(); 1457 GeneratePrecompiledJITSnapshot();
1601 } 1458 }
1602 } 1459 }
1603 } 1460 }
1604 CHECK_RESULT(result); 1461 CHECK_RESULT(result);
1605 } 1462 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 1606
1750 Thread::InitOnce(); 1607 Thread::InitOnce();
1751 1608
1752 if (!DartUtils::SetOriginalWorkingDirectory()) { 1609 if (!DartUtils::SetOriginalWorkingDirectory()) {
1753 OSError err; 1610 OSError err;
1754 fprintf(stderr, "Error determining current directory: %s\n", err.message()); 1611 fprintf(stderr, "Error determining current directory: %s\n", err.message());
1755 fflush(stderr); 1612 fflush(stderr);
1756 Platform::Exit(kErrorExitCode); 1613 Platform::Exit(kErrorExitCode);
1757 } 1614 }
1758 1615
1759 #if !defined(PRODUCT) 1616 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
1760 // Constant true in PRODUCT mode. 1617 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME.
1761 if (generate_script_snapshot || 1618 if ((gen_snapshot_kind != kNone) || run_app_snapshot) {
1762 generate_full_snapshot_after_run ||
1763 run_full_snapshot ||
1764 gen_precompiled_jit_snapshot ||
1765 run_precompiled_jit_snapshot) {
1766 vm_options.AddArgument("--load_deferred_eagerly"); 1619 vm_options.AddArgument("--load_deferred_eagerly");
1767 } 1620 }
1768 #endif 1621 #endif
1769 1622
1770 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) 1623 if ((gen_snapshot_kind == kAppAOT) || is_noopt) {
1771 // Always set --precompilation with dart_noopt. 1624 vm_options.AddArgument("--precompilation");
1772 ASSERT(!gen_precompiled_snapshot && !run_precompiled_snapshot); 1625 }
1626 #if defined(DART_PRECOMPILED_RUNTIME)
1773 vm_options.AddArgument("--precompilation"); 1627 vm_options.AddArgument("--precompilation");
1774 #endif 1628 #endif
1775 1629
1776 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 1630 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
1777 1631
1778 // Start event handler. 1632 // Start event handler.
1779 TimerUtils::InitOnce(); 1633 TimerUtils::InitOnce();
1780 EventHandler::Start(); 1634 EventHandler::Start();
1781 1635
1782 const uint8_t* instructions_snapshot = NULL; 1636 const uint8_t* instructions_snapshot = NULL;
1783 const uint8_t* data_snapshot = NULL; 1637 const uint8_t* data_snapshot = NULL;
1784 if (run_precompiled_snapshot || run_precompiled_jit_snapshot) { 1638 if (run_app_snapshot) {
1785 ReadSnapshotFile(precompiled_snapshot_directory, 1639 ReadSnapshotFile(snapshot_filename, kVMIsolateSuffix,
1786 kPrecompiledVmIsolateName,
1787 &vm_isolate_snapshot_buffer); 1640 &vm_isolate_snapshot_buffer);
1788 ReadSnapshotFile(precompiled_snapshot_directory, 1641 ReadSnapshotFile(snapshot_filename, kIsolateSuffix,
1789 kPrecompiledIsolateName,
1790 &isolate_snapshot_buffer); 1642 &isolate_snapshot_buffer);
1791 if (use_blobs) { 1643 if (use_blobs) {
1792 ReadExecutableSnapshotFile(precompiled_snapshot_directory, 1644 ReadExecutableSnapshotFile(snapshot_filename,
1793 kPrecompiledInstructionsBlobName, 1645 kInstructionsSuffix,
1794 &instructions_snapshot); 1646 &instructions_snapshot);
1795 ReadSnapshotFile(precompiled_snapshot_directory, 1647 ReadSnapshotFile(snapshot_filename, kRODataSuffix,
1796 kPrecompiledRodataBlobName,
1797 &data_snapshot); 1648 &data_snapshot);
1798 } else { 1649 } else {
1799 instructions_snapshot = reinterpret_cast<const uint8_t*>( 1650 instructions_snapshot = reinterpret_cast<const uint8_t*>(
1800 LoadLibrarySymbol(precompiled_snapshot_directory, 1651 LoadLibrarySymbol(snapshot_filename,
1801 kPrecompiledLibraryName, 1652 kPrecompiledLibraryName,
1802 kPrecompiledInstructionsSymbolName)); 1653 kPrecompiledInstructionsSymbolName));
1803 data_snapshot = reinterpret_cast<const uint8_t*>( 1654 data_snapshot = reinterpret_cast<const uint8_t*>(
1804 LoadLibrarySymbol(precompiled_snapshot_directory, 1655 LoadLibrarySymbol(snapshot_filename,
1805 kPrecompiledLibraryName, 1656 kPrecompiledLibraryName,
1806 kPrecompiledDataSymbolName)); 1657 kPrecompiledDataSymbolName));
1807 } 1658 }
1808 } else if (run_full_snapshot) {
1809 char* vm_snapshot_fname;
1810 char* isolate_snapshot_fname;
1811
1812 // Compute file names.
1813 ComputeSnapshotFilenames(snapshot_filename,
1814 &vm_snapshot_fname,
1815 &isolate_snapshot_fname);
1816
1817 ReadSnapshotFile(NULL, vm_snapshot_fname, &vm_isolate_snapshot_buffer);
1818 ReadSnapshotFile(NULL, isolate_snapshot_fname, &isolate_snapshot_buffer);
1819 delete vm_snapshot_fname;
1820 delete isolate_snapshot_fname;
1821 } 1659 }
1822 1660
1823 // Initialize the Dart VM. 1661 // Initialize the Dart VM.
1824 char* error = Dart_Initialize( 1662 char* error = Dart_Initialize(
1825 vm_isolate_snapshot_buffer, instructions_snapshot, data_snapshot, 1663 vm_isolate_snapshot_buffer, instructions_snapshot, data_snapshot,
1826 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, 1664 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate,
1827 NULL, 1665 NULL,
1828 DartUtils::OpenFile, 1666 DartUtils::OpenFile,
1829 DartUtils::ReadFile, 1667 DartUtils::ReadFile,
1830 DartUtils::WriteFile, 1668 DartUtils::WriteFile,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 Platform::Exit(Process::GlobalExitCode()); 1722 Platform::Exit(Process::GlobalExitCode());
1885 } 1723 }
1886 1724
1887 } // namespace bin 1725 } // namespace bin
1888 } // namespace dart 1726 } // namespace dart
1889 1727
1890 int main(int argc, char** argv) { 1728 int main(int argc, char** argv) {
1891 dart::bin::main(argc, argv); 1729 dart::bin::main(argc, argv);
1892 UNREACHABLE(); 1730 UNREACHABLE();
1893 } 1731 }
OLDNEW
« no previous file with comments | « no previous file | tools/testing/dart/compiler_configuration.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698