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

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;
56 static bool generate_full_snapshot_after_run = false;
57 static bool run_full_snapshot = false; 55 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 kPrecompiled,
61 kPrecompiledJIT,
62 kFullAfterRun,
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, "precompiled") == 0) {
353 gen_snapshot_kind = kPrecompiled;
354 return true;
355 } else if (strcmp(kind, "precompiled-jit") == 0) {
356 gen_snapshot_kind = kPrecompiledJIT;
357 return true;
358 } else if (strcmp(kind, "full-after-run") == 0) {
359 gen_snapshot_kind = kFullAfterRun;
360 return true;
433 } 361 }
siva 2016/05/05 22:38:43 As discussed offline, I am wondering if this list
rmacnak 2016/05/06 00:19:46 Updated the names and changed --run-full-snapshot
434 // Ensure that we are already running using a full snapshot. 362 return false;
435 if (isolate_snapshot_buffer == NULL) {
436 Log::PrintErr("Script snapshots cannot be generated in this version of"
437 " Dart\n");
438 return false;
439 }
440 return ProcessSnapshotOptionHelper(filename, &generate_script_snapshot);
441 }
442
443
444 static bool ProcessFullSnapshotAfterRunOption(
445 const char* filename, CommandLineOptions* vm_options) {
446 if ((filename == NULL) || (strlen(filename) == 0)) {
447 return false;
448 }
449 // Ensure that we are running 'dart_bootstrap'.
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 } 363 }
458 364
459 365
460 static bool ProcessRunFullSnapshotOption( 366 static bool ProcessRunFullSnapshotOption(
461 const char* filename, CommandLineOptions* vm_options) { 367 const char* filename, CommandLineOptions* vm_options) {
462 #if !defined(PRODUCT) 368 ASSERT(filename != NULL);
463 Log::PrintErr("Full Application snapshots can only be be run with" 369 snapshot_filename = filename;
464 " product mode\n"); 370 run_full_snapshot = true;
465 return false; 371 return true;
466 #else
467 return ProcessSnapshotOptionHelper(filename, &run_full_snapshot);
468 #endif // defined(PRODUCT)
469 } 372 }
470 373
471 374
472 static bool ProcessEnableVmServiceOption(const char* option_value, 375 static bool ProcessEnableVmServiceOption(const char* option_value,
473 CommandLineOptions* vm_options) { 376 CommandLineOptions* vm_options) {
474 ASSERT(option_value != NULL); 377 ASSERT(option_value != NULL);
475 378
476 if (!ExtractPortAndIP(option_value, 379 if (!ExtractPortAndIP(option_value,
477 &vm_service_server_port, 380 &vm_service_server_port,
478 &vm_service_server_ip, 381 &vm_service_server_ip,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 { "-h", ProcessHelpOption }, 458 { "-h", ProcessHelpOption },
556 { "--help", ProcessHelpOption }, 459 { "--help", ProcessHelpOption },
557 { "--packages=", ProcessPackagesOption }, 460 { "--packages=", ProcessPackagesOption },
558 { "--package-root=", ProcessPackageRootOption }, 461 { "--package-root=", ProcessPackageRootOption },
559 { "-v", ProcessVerboseOption }, 462 { "-v", ProcessVerboseOption },
560 { "--verbose", ProcessVerboseOption }, 463 { "--verbose", ProcessVerboseOption },
561 { "--version", ProcessVersionOption }, 464 { "--version", ProcessVersionOption },
562 465
563 // VM specific options to the standalone dart program. 466 // VM specific options to the standalone dart program.
564 { "--compile_all", ProcessCompileAllOption }, 467 { "--compile_all", ProcessCompileAllOption },
565 { "--use_blobs", ProcessUseBlobsOption },
566 { "--enable-vm-service", ProcessEnableVmServiceOption }, 468 { "--enable-vm-service", ProcessEnableVmServiceOption },
567 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption },
568 { "--gen-precompiled-jit-snapshot", ProcessGenPrecompiledJITSnapshotOption },
569 { "--observe", ProcessObserveOption }, 469 { "--observe", ProcessObserveOption },
570 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption },
571 { "--run-precompiled-jit-snapshot", ProcessRunPrecompiledJITSnapshotOption },
572 { "--shutdown", ProcessShutdownOption }, 470 { "--shutdown", ProcessShutdownOption },
573 { "--snapshot=", ProcessScriptSnapshotOption }, 471 { "--snapshot=", ProcessSnapshotFilenameOption },
574 { "--full-snapshot-after-run=", ProcessFullSnapshotAfterRunOption }, 472 { "--snapshot-kind=", ProcessSnapshotKindOption },
575 { "--run-full-snapshot=", ProcessRunFullSnapshotOption }, 473 { "--run-full-snapshot=", ProcessRunFullSnapshotOption },
474 { "--use-blobs", ProcessUseBlobsOption },
576 { "--trace-loading", ProcessTraceLoadingOption }, 475 { "--trace-loading", ProcessTraceLoadingOption },
577 { NULL, NULL } 476 { NULL, NULL }
578 }; 477 };
579 478
580 479
581 static bool ProcessMainOptions(const char* option, 480 static bool ProcessMainOptions(const char* option,
582 CommandLineOptions* vm_options) { 481 CommandLineOptions* vm_options) {
583 int i = 0; 482 int i = 0;
584 const char* name = main_options[0].option_name; 483 const char* name = main_options[0].option_name;
585 int option_length = strlen(option); 484 int option_length = strlen(option);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 i++; 581 i++;
683 } 582 }
684 583
685 // Verify consistency of arguments. 584 // Verify consistency of arguments.
686 if ((commandline_package_root != NULL) && 585 if ((commandline_package_root != NULL) &&
687 (commandline_packages_file != NULL)) { 586 (commandline_packages_file != NULL)) {
688 Log::PrintErr("Specifying both a packages directory and a packages " 587 Log::PrintErr("Specifying both a packages directory and a packages "
689 "file is invalid.\n"); 588 "file is invalid.\n");
690 return -1; 589 return -1;
691 } 590 }
692 if (is_noopt) { 591 if (is_noopt && gen_snapshot_kind != kNone) {
693 if (gen_precompiled_snapshot) { 592 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; 593 return -1;
708 } 594 }
709 if ((generate_full_snapshot_after_run || gen_precompiled_snapshot) && 595 if ((gen_snapshot_kind != kNone) && (snapshot_filename == NULL)) {
710 (run_full_snapshot || run_precompiled_snapshot)) { 596 Log::PrintErr("Generating a snapshot requires a filename (--snapshot).\n");
597 return -1;
598 }
599 if ((gen_snapshot_kind != kNone) && run_full_snapshot) {
711 Log::PrintErr("Specifying an option to generate a snapshot and" 600 Log::PrintErr("Specifying an option to generate a snapshot and"
712 " run using a snapshot is invalid.\n"); 601 " run using a snapshot is invalid.\n");
713 return -1; 602 return -1;
714 } 603 }
715 604
716 return 0; 605 return 0;
717 } 606 }
718 607
719 608
720 static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) { 609 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. 680 // Returns true on success, false on failure.
792 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, 681 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
793 const char* main, 682 const char* main,
794 const char* package_root, 683 const char* package_root,
795 const char* packages_config, 684 const char* packages_config,
796 Dart_IsolateFlags* flags, 685 Dart_IsolateFlags* flags,
797 char** error, 686 char** error,
798 int* exit_code) { 687 int* exit_code) {
799 ASSERT(script_uri != NULL); 688 ASSERT(script_uri != NULL);
800 689
690 const bool needs_load_port = !run_full_snapshot;
801 #if defined(PRODUCT) 691 #if defined(PRODUCT)
802 const bool run_service_isolate = !run_full_snapshot && 692 const bool run_service_isolate = needs_load_port;
803 !run_precompiled_snapshot;
804 #else 693 #else
805 const bool run_service_isolate = !run_full_snapshot; 694 // Always create the service isolate in DEBUG and RELEASE modes for profiling,
695 // even if we don't need it for loading.
696 const bool run_service_isolate = true;
806 #endif // PRODUCT 697 #endif // PRODUCT
807 if (!run_service_isolate && 698 if (!run_service_isolate &&
808 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { 699 (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; 700 return NULL;
812 } 701 }
813 702
814 IsolateData* isolate_data = new IsolateData(script_uri, 703 IsolateData* isolate_data = new IsolateData(script_uri,
815 package_root, 704 package_root,
816 packages_config); 705 packages_config);
817 Dart_Isolate isolate = Dart_CreateIsolate(script_uri, 706 Dart_Isolate isolate = Dart_CreateIsolate(script_uri,
818 main, 707 main,
819 isolate_snapshot_buffer, 708 isolate_snapshot_buffer,
820 flags, 709 flags,
(...skipping 11 matching lines...) Expand all
832 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 721 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
833 Builtin::SetNativeResolver(Builtin::kIOLibrary); 722 Builtin::SetNativeResolver(Builtin::kIOLibrary);
834 } 723 }
835 724
836 // Set up the library tag handler for this isolate. 725 // Set up the library tag handler for this isolate.
837 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); 726 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler);
838 CHECK_RESULT(result); 727 CHECK_RESULT(result);
839 728
840 if (Dart_IsServiceIsolate(isolate)) { 729 if (Dart_IsServiceIsolate(isolate)) {
841 // If this is the service isolate, load embedder specific bits and return. 730 // If this is the service isolate, load embedder specific bits and return.
842 bool skip_library_load = run_precompiled_snapshot || 731 bool skip_library_load = run_full_snapshot;
843 run_precompiled_jit_snapshot;
844 if (!VmService::Setup(vm_service_server_ip, 732 if (!VmService::Setup(vm_service_server_ip,
845 vm_service_server_port, 733 vm_service_server_port,
846 skip_library_load)) { 734 skip_library_load)) {
847 *error = strdup(VmService::GetErrorMessage()); 735 *error = strdup(VmService::GetErrorMessage());
848 return NULL; 736 return NULL;
849 } 737 }
850 if (compile_all) { 738 if (compile_all) {
851 result = Dart_CompileAll(); 739 result = Dart_CompileAll();
852 CHECK_RESULT(result); 740 CHECK_RESULT(result);
853 } 741 }
854 Dart_ExitScope(); 742 Dart_ExitScope();
855 Dart_ExitIsolate(); 743 Dart_ExitIsolate();
856 return isolate; 744 return isolate;
857 } 745 }
858 746
859 // Prepare builtin and other core libraries for use to resolve URIs. 747 // Prepare builtin and other core libraries for use to resolve URIs.
860 // Set up various closures, e.g: printing, timers etc. 748 // Set up various closures, e.g: printing, timers etc.
861 // Set up 'package root' for URI resolution. 749 // Set up 'package root' for URI resolution.
862 result = DartUtils::PrepareForScriptLoading(false, trace_loading); 750 result = DartUtils::PrepareForScriptLoading(false, trace_loading);
863 CHECK_RESULT(result); 751 CHECK_RESULT(result);
864 752
865 if (!run_precompiled_snapshot && 753 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 754 // Set up the load port provided by the service isolate so that we can
869 // load scripts. 755 // load scripts.
870 // With a full snapshot or a precompiled snapshot in product mode, there is 756 // 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 757 // 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. 758 // have the service isolate, but it doesn't use it for loading.
873 result = DartUtils::SetupServiceLoadPort(); 759 result = DartUtils::SetupServiceLoadPort();
874 CHECK_RESULT(result); 760 CHECK_RESULT(result);
875 } 761 }
876 762
877 // Setup package root if specified. 763 // Setup package root if specified.
878 result = DartUtils::SetupPackageRoot(package_root, packages_config); 764 result = DartUtils::SetupPackageRoot(package_root, packages_config);
879 CHECK_RESULT(result); 765 CHECK_RESULT(result);
880 766
881 result = Dart_SetEnvironmentCallback(EnvironmentCallback); 767 result = Dart_SetEnvironmentCallback(EnvironmentCallback);
882 CHECK_RESULT(result); 768 CHECK_RESULT(result);
883 769
884 if (run_precompiled_snapshot) { 770 if (run_full_snapshot) {
885 // No setup.
886 } else if (run_full_snapshot || run_precompiled_jit_snapshot) {
887 result = DartUtils::SetupIOLibrary(script_uri); 771 result = DartUtils::SetupIOLibrary(script_uri);
888 CHECK_RESULT(result); 772 CHECK_RESULT(result);
889 } else { 773 } else {
890 // Load the specified application script into the newly created isolate. 774 // Load the specified application script into the newly created isolate.
891 result = DartUtils::LoadScript(script_uri); 775 result = DartUtils::LoadScript(script_uri);
892 CHECK_RESULT(result); 776 CHECK_RESULT(result);
893 777
894 // Run event-loop and wait for script loading to complete. 778 // Run event-loop and wait for script loading to complete.
895 result = Dart_RunLoop(); 779 result = Dart_RunLoop();
896 CHECK_RESULT(result); 780 CHECK_RESULT(result);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 "--observe[=<port>[/<bind-address>]]\n" 878 "--observe[=<port>[/<bind-address>]]\n"
995 " The observe flag is used to run a program with a default set of options\n" 879 " The observe flag is used to run a program with a default set of options\n"
996 " for debugging under Observatory. With the default options, Observatory\n" 880 " for debugging under Observatory. With the default options, Observatory\n"
997 " will be available at http://127.0.0.1:8181/ (default port is 8181,\n" 881 " will be available at http://127.0.0.1:8181/ (default port is 8181,\n"
998 " default bind address is 127.0.0.1). Isolates will pause at exit and\n" 882 " default bind address is 127.0.0.1). Isolates will pause at exit and\n"
999 " when they throw unhandled exceptions.\n" 883 " when they throw unhandled exceptions.\n"
1000 "--version\n" 884 "--version\n"
1001 " Print the VM version.\n" 885 " Print the VM version.\n"
1002 "\n" 886 "\n"
1003 "--snapshot=<file_name>\n" 887 "--snapshot=<file_name>\n"
1004 " loads Dart script and generates a snapshot in the specified file\n" 888 " loads Dart script and generates a snapshot in the specified file\n"
siva 2016/05/05 22:38:43 we should remember to add help information here fo
1005 "\n" 889 "\n"
1006 "--trace-loading\n" 890 "--trace-loading\n"
1007 " enables tracing of library and script loading\n" 891 " enables tracing of library and script loading\n"
1008 "\n" 892 "\n"
1009 "--enable-vm-service[:<port>[/<bind-address>]]\n" 893 "--enable-vm-service[:<port>[/<bind-address>]]\n"
1010 " enables the VM service and listens on specified port for connections\n" 894 " enables the VM service and listens on specified port for connections\n"
1011 " (default port number is 8181, default bind address is 127.0.0.1).\n" 895 " (default port number is 8181, default bind address is 127.0.0.1).\n"
1012 "\n" 896 "\n"
1013 "The following options are only used for VM development and may\n" 897 "The following options are only used for VM development and may\n"
1014 "be changed in any future version:\n"); 898 "be changed in any future version:\n");
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 const char* qualified_libname; 1121 const char* qualified_libname;
1238 if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) { 1122 if ((snapshot_directory != NULL) && (strlen(snapshot_directory) > 0)) {
1239 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, libname); 1123 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, libname);
1240 concat = new char[len + 1]; 1124 concat = new char[len + 1];
1241 snprintf(concat, len + 1, "%s/%s", snapshot_directory, libname); 1125 snprintf(concat, len + 1, "%s/%s", snapshot_directory, libname);
1242 qualified_libname = concat; 1126 qualified_libname = concat;
1243 } else { 1127 } else {
1244 qualified_libname = libname; 1128 qualified_libname = libname;
1245 } 1129 }
1246 void* library = Extensions::LoadExtensionLibrary(qualified_libname); 1130 void* library = Extensions::LoadExtensionLibrary(qualified_libname);
1131 if (concat != NULL) {
1132 delete concat;
1133 }
1247 if (library == NULL) { 1134 if (library == NULL) {
1248 Log::PrintErr("Error: Failed to load library '%s'\n", qualified_libname); 1135 return NULL;
1249 Platform::Exit(kErrorExitCode);
1250 } 1136 }
1251 void* symbol = Extensions::ResolveSymbol(library, symname); 1137 void* symbol = Extensions::ResolveSymbol(library, symname);
1252 if (symbol == NULL) { 1138 if (symbol == NULL) {
1253 Log::PrintErr("Error: Failed to load symbol '%s'\n", symname); 1139 return NULL;
1254 Platform::Exit(kErrorExitCode);
1255 }
1256 if (concat != NULL) {
1257 delete concat;
1258 } 1140 }
1259 return symbol; 1141 return symbol;
siva 2016/05/05 22:38:43 why do you have the NULL check and return NULL why
rmacnak 2016/05/06 00:19:46 Done.
1260 } 1142 }
1261 1143
1262 1144
1263 static void GenerateScriptSnapshot() { 1145 static void GenerateScriptSnapshot() {
1264 // First create a snapshot. 1146 // First create a snapshot.
1265 uint8_t* buffer = NULL; 1147 uint8_t* buffer = NULL;
1266 intptr_t size = 0; 1148 intptr_t size = 0;
1267 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); 1149 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size);
1268 if (Dart_IsError(result)) { 1150 if (Dart_IsError(result)) {
1269 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1151 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1270 } 1152 }
1271 1153
1272 WriteSnapshotFile(NULL, snapshot_filename, true, buffer, size); 1154 WriteSnapshotFile(NULL, snapshot_filename, true, buffer, size);
1273 } 1155 }
1274 1156
1275 1157
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() { 1158 static void GeneratePrecompiledSnapshot() {
1290 uint8_t* vm_isolate_buffer = NULL; 1159 uint8_t* vm_isolate_buffer = NULL;
1291 intptr_t vm_isolate_size = 0; 1160 intptr_t vm_isolate_size = 0;
1292 uint8_t* isolate_buffer = NULL; 1161 uint8_t* isolate_buffer = NULL;
1293 intptr_t isolate_size = 0; 1162 intptr_t isolate_size = 0;
1294 uint8_t* assembly_buffer = NULL; 1163 uint8_t* assembly_buffer = NULL;
1295 intptr_t assembly_size = 0; 1164 intptr_t assembly_size = 0;
1296 uint8_t* instructions_blob_buffer = NULL; 1165 uint8_t* instructions_blob_buffer = NULL;
1297 intptr_t instructions_blob_size = 0; 1166 intptr_t instructions_blob_size = 0;
1298 uint8_t* rodata_blob_buffer = NULL; 1167 uint8_t* rodata_blob_buffer = NULL;
(...skipping 14 matching lines...) Expand all
1313 &vm_isolate_buffer, 1182 &vm_isolate_buffer,
1314 &vm_isolate_size, 1183 &vm_isolate_size,
1315 &isolate_buffer, 1184 &isolate_buffer,
1316 &isolate_size, 1185 &isolate_size,
1317 &assembly_buffer, 1186 &assembly_buffer,
1318 &assembly_size); 1187 &assembly_size);
1319 } 1188 }
1320 if (Dart_IsError(result)) { 1189 if (Dart_IsError(result)) {
1321 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1190 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1322 } 1191 }
1323 WriteSnapshotFile(precompiled_snapshot_directory, 1192 WriteSnapshotFile(snapshot_filename, kVMIsolateSuffix,
1324 kPrecompiledVmIsolateName,
1325 false, 1193 false,
1326 vm_isolate_buffer, 1194 vm_isolate_buffer,
1327 vm_isolate_size); 1195 vm_isolate_size);
1328 WriteSnapshotFile(precompiled_snapshot_directory, 1196 WriteSnapshotFile(snapshot_filename, kIsolateSuffix,
1329 kPrecompiledIsolateName,
1330 false, 1197 false,
1331 isolate_buffer, 1198 isolate_buffer,
1332 isolate_size); 1199 isolate_size);
1333 if (use_blobs) { 1200 if (use_blobs) {
1334 WriteSnapshotFile(precompiled_snapshot_directory, 1201 WriteSnapshotFile(snapshot_filename, kInstructionsSuffix,
1335 kPrecompiledInstructionsBlobName,
1336 false, 1202 false,
1337 instructions_blob_buffer, 1203 instructions_blob_buffer,
1338 instructions_blob_size); 1204 instructions_blob_size);
1339 WriteSnapshotFile(precompiled_snapshot_directory, 1205 WriteSnapshotFile(snapshot_filename, kRODataSuffix,
1340 kPrecompiledRodataBlobName,
1341 false, 1206 false,
1342 rodata_blob_buffer, 1207 rodata_blob_buffer,
1343 rodata_blob_size); 1208 rodata_blob_size);
1344 } else { 1209 } else {
1345 WriteSnapshotFile(precompiled_snapshot_directory, 1210 WriteSnapshotFile(snapshot_filename, kAssemblySuffix,
1346 kPrecompiledAssemblyName,
1347 false, 1211 false,
1348 assembly_buffer, 1212 assembly_buffer,
1349 assembly_size); 1213 assembly_size);
1350 } 1214 }
1351 } 1215 }
1352 1216
1353 1217
1354 static void GeneratePrecompiledJITSnapshot() { 1218 static void GeneratePrecompiledJITSnapshot() {
1355 uint8_t* vm_isolate_buffer = NULL; 1219 uint8_t* vm_isolate_buffer = NULL;
1356 intptr_t vm_isolate_size = 0; 1220 intptr_t vm_isolate_size = 0;
1357 uint8_t* isolate_buffer = NULL; 1221 uint8_t* isolate_buffer = NULL;
1358 intptr_t isolate_size = 0; 1222 intptr_t isolate_size = 0;
1359 uint8_t* instructions_blob_buffer = NULL; 1223 uint8_t* instructions_blob_buffer = NULL;
1360 intptr_t instructions_blob_size = 0; 1224 intptr_t instructions_blob_size = 0;
1361 uint8_t* rodata_blob_buffer = NULL; 1225 uint8_t* rodata_blob_buffer = NULL;
1362 intptr_t rodata_blob_size = 0; 1226 intptr_t rodata_blob_size = 0;
1363 Dart_Handle result = Dart_CreatePrecompiledJITSnapshotBlob( 1227 Dart_Handle result = Dart_CreatePrecompiledJITSnapshotBlob(
1364 &vm_isolate_buffer, 1228 &vm_isolate_buffer,
1365 &vm_isolate_size, 1229 &vm_isolate_size,
1366 &isolate_buffer, 1230 &isolate_buffer,
1367 &isolate_size, 1231 &isolate_size,
1368 &instructions_blob_buffer, 1232 &instructions_blob_buffer,
1369 &instructions_blob_size, 1233 &instructions_blob_size,
1370 &rodata_blob_buffer, 1234 &rodata_blob_buffer,
1371 &rodata_blob_size); 1235 &rodata_blob_size);
1372 if (Dart_IsError(result)) { 1236 if (Dart_IsError(result)) {
1373 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1237 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1374 } 1238 }
1375 WriteSnapshotFile(precompiled_snapshot_directory, 1239 WriteSnapshotFile(snapshot_filename, kVMIsolateSuffix,
1376 kPrecompiledVmIsolateName,
1377 false, 1240 false,
1378 vm_isolate_buffer, 1241 vm_isolate_buffer,
1379 vm_isolate_size); 1242 vm_isolate_size);
1380 WriteSnapshotFile(precompiled_snapshot_directory, 1243 WriteSnapshotFile(snapshot_filename, kIsolateSuffix,
1381 kPrecompiledIsolateName,
1382 false, 1244 false,
1383 isolate_buffer, 1245 isolate_buffer,
1384 isolate_size); 1246 isolate_size);
1385 WriteSnapshotFile(precompiled_snapshot_directory, 1247 WriteSnapshotFile(snapshot_filename, kInstructionsSuffix,
1386 kPrecompiledInstructionsBlobName,
1387 false, 1248 false,
1388 instructions_blob_buffer, 1249 instructions_blob_buffer,
1389 instructions_blob_size); 1250 instructions_blob_size);
1390 WriteSnapshotFile(precompiled_snapshot_directory, 1251 WriteSnapshotFile(snapshot_filename, kRODataSuffix,
1391 kPrecompiledRodataBlobName,
1392 false, 1252 false,
1393 rodata_blob_buffer, 1253 rodata_blob_buffer,
1394 rodata_blob_size); 1254 rodata_blob_size);
1395 } 1255 }
1396 1256
1397 1257
1398 static void GenerateFullSnapshot() { 1258 static void GenerateFullSnapshot() {
1399 // Create a full snapshot of the script. 1259 // Create a full snapshot of the script.
1400 Dart_Handle result; 1260 Dart_Handle result;
1401 uint8_t* vm_isolate_buffer = NULL; 1261 uint8_t* vm_isolate_buffer = NULL;
1402 intptr_t vm_isolate_size = 0; 1262 intptr_t vm_isolate_size = 0;
1403 uint8_t* isolate_buffer = NULL; 1263 uint8_t* isolate_buffer = NULL;
1404 intptr_t isolate_size = 0; 1264 intptr_t isolate_size = 0;
1405 char* vm_snapshot_fname = NULL;
1406 char* isolate_snapshot_fname = NULL;
1407 1265
1408 result = Dart_CreateSnapshot(&vm_isolate_buffer, 1266 result = Dart_CreateSnapshot(&vm_isolate_buffer,
1409 &vm_isolate_size, 1267 &vm_isolate_size,
1410 &isolate_buffer, 1268 &isolate_buffer,
1411 &isolate_size); 1269 &isolate_size);
1412 if (Dart_IsError(result)) { 1270 if (Dart_IsError(result)) {
1413 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); 1271 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result));
1414 } 1272 }
1415 1273
1416 // Compute snapshot file names and write out the snapshot files. 1274 WriteSnapshotFile(snapshot_filename,
1417 ComputeSnapshotFilenames(snapshot_filename, 1275 kVMIsolateSuffix,
1418 &vm_snapshot_fname,
1419 &isolate_snapshot_fname);
1420 WriteSnapshotFile(NULL,
1421 vm_snapshot_fname,
1422 false, 1276 false,
1423 vm_isolate_buffer, 1277 vm_isolate_buffer,
1424 vm_isolate_size); 1278 vm_isolate_size);
1425 WriteSnapshotFile(NULL, 1279 WriteSnapshotFile(snapshot_filename,
1426 isolate_snapshot_fname, 1280 kIsolateSuffix,
1427 false, 1281 false,
1428 isolate_buffer, 1282 isolate_buffer,
1429 isolate_size); 1283 isolate_size);
1430 } 1284 }
1431 1285
1432 1286
1433 #define CHECK_RESULT(result) \ 1287 #define CHECK_RESULT(result) \
1434 if (Dart_IsError(result)) { \ 1288 if (Dart_IsError(result)) { \
1435 if (Dart_IsVMRestartRequest(result)) { \ 1289 if (Dart_IsVMRestartRequest(result)) { \
1436 Dart_ExitScope(); \ 1290 Dart_ExitScope(); \
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 } 1333 }
1480 delete [] isolate_name; 1334 delete [] isolate_name;
1481 1335
1482 Dart_EnterIsolate(isolate); 1336 Dart_EnterIsolate(isolate);
1483 ASSERT(isolate == Dart_CurrentIsolate()); 1337 ASSERT(isolate == Dart_CurrentIsolate());
1484 ASSERT(isolate != NULL); 1338 ASSERT(isolate != NULL);
1485 Dart_Handle result; 1339 Dart_Handle result;
1486 1340
1487 Dart_EnterScope(); 1341 Dart_EnterScope();
1488 1342
1489 if (generate_script_snapshot) { 1343 if (gen_snapshot_kind == kScript) {
1490 GenerateScriptSnapshot(); 1344 GenerateScriptSnapshot();
1491 } else { 1345 } else {
1492 // Lookup the library of the root script. 1346 // Lookup the library of the root script.
1493 Dart_Handle root_lib = Dart_RootLibrary(); 1347 Dart_Handle root_lib = Dart_RootLibrary();
1494 // Import the root library into the builtin library so that we can easily 1348 // Import the root library into the builtin library so that we can easily
1495 // lookup the main entry point exported from the root library. 1349 // lookup the main entry point exported from the root library.
1496 IsolateData* isolate_data = 1350 IsolateData* isolate_data =
1497 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); 1351 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate));
1498 result = Dart_LibraryImportLibrary( 1352 result = Dart_LibraryImportLibrary(
1499 isolate_data->builtin_lib(), root_lib, Dart_Null()); 1353 isolate_data->builtin_lib(), root_lib, Dart_Null());
1500 #if !defined(PRODUCT) 1354 #if !defined(PRODUCT)
1501 if (is_noopt || gen_precompiled_snapshot || gen_precompiled_jit_snapshot) { 1355 if (is_noopt ||
1356 (gen_snapshot_kind == kFullAfterRun) ||
1357 (gen_snapshot_kind == kPrecompiled) ||
1358 (gen_snapshot_kind == kPrecompiledJIT)) {
1502 // Load the embedder's portion of the VM service's Dart code so it will 1359 // Load the embedder's portion of the VM service's Dart code so it will
1503 // be included in the precompiled snapshot. 1360 // be included in the precompiled snapshot.
siva 2016/05/05 22:38:44 the comment says precompiled snapshot but should p
rmacnak 2016/05/06 00:19:46 Changed to 'app snapshot'
1504 if (!VmService::LoadForGenPrecompiled()) { 1361 if (!VmService::LoadForGenPrecompiled()) {
1505 fprintf(stderr, 1362 fprintf(stderr,
1506 "VM service loading failed: %s\n", 1363 "VM service loading failed: %s\n",
1507 VmService::GetErrorMessage()); 1364 VmService::GetErrorMessage());
1508 fflush(stderr); 1365 fflush(stderr);
1509 exit(kErrorExitCode); 1366 exit(kErrorExitCode);
1510 } 1367 }
1511 } 1368 }
1512 #endif // PRODUCT 1369 #endif // PRODUCT
1513 1370
1514 if (compile_all) { 1371 if (compile_all) {
1515 result = Dart_CompileAll(); 1372 result = Dart_CompileAll();
1516 CHECK_RESULT(result); 1373 CHECK_RESULT(result);
1517 } 1374 }
1518 1375
1519 if (is_noopt || gen_precompiled_snapshot) { 1376 if (is_noopt || (gen_snapshot_kind == kPrecompiled)) {
1520 Dart_QualifiedFunctionName standalone_entry_points[] = { 1377 Dart_QualifiedFunctionName standalone_entry_points[] = {
1521 { "dart:_builtin", "::", "_getMainClosure" }, 1378 { "dart:_builtin", "::", "_getMainClosure" },
1522 { "dart:_builtin", "::", "_getPrintClosure" }, 1379 { "dart:_builtin", "::", "_getPrintClosure" },
1523 { "dart:_builtin", "::", "_getUriBaseClosure" }, 1380 { "dart:_builtin", "::", "_getUriBaseClosure" },
1524 { "dart:_builtin", "::", "_resolveUri" }, 1381 { "dart:_builtin", "::", "_resolveUri" },
1525 { "dart:_builtin", "::", "_setWorkingDirectory" }, 1382 { "dart:_builtin", "::", "_setWorkingDirectory" },
1526 { "dart:_builtin", "::", "_setPackageRoot" }, 1383 { "dart:_builtin", "::", "_setPackageRoot" },
1527 { "dart:_builtin", "::", "_loadPackagesMap" }, 1384 { "dart:_builtin", "::", "_loadPackagesMap" },
1528 { "dart:_builtin", "::", "_loadDataAsync" }, 1385 { "dart:_builtin", "::", "_loadDataAsync" },
1529 { "dart:io", "::", "_makeUint8ListView" }, 1386 { "dart:io", "::", "_makeUint8ListView" },
(...skipping 14 matching lines...) Expand all
1544 { "dart:io", "_ProcessStartStatus", "set:_errorCode" }, 1401 { "dart:io", "_ProcessStartStatus", "set:_errorCode" },
1545 { "dart:io", "_ProcessStartStatus", "set:_errorMessage" }, 1402 { "dart:io", "_ProcessStartStatus", "set:_errorMessage" },
1546 { "dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE" }, 1403 { "dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE" },
1547 { "dart:io", "_SecureFilterImpl", "get:SIZE" }, 1404 { "dart:io", "_SecureFilterImpl", "get:SIZE" },
1548 #if !defined(PRODUCT) 1405 #if !defined(PRODUCT)
1549 { "dart:vmservice_io", "::", "main" }, 1406 { "dart:vmservice_io", "::", "main" },
1550 #endif // !PRODUCT 1407 #endif // !PRODUCT
1551 { NULL, NULL, NULL } // Must be terminated with NULL entries. 1408 { NULL, NULL, NULL } // Must be terminated with NULL entries.
1552 }; 1409 };
1553 1410
1554 const bool reset_fields = gen_precompiled_snapshot; 1411 const bool reset_fields = gen_snapshot_kind == kPrecompiled;
1555 result = Dart_Precompile(standalone_entry_points, reset_fields); 1412 result = Dart_Precompile(standalone_entry_points, reset_fields);
1556 CHECK_RESULT(result); 1413 CHECK_RESULT(result);
1557 } 1414 }
1558 1415
1559 if (gen_precompiled_snapshot) { 1416 if (gen_snapshot_kind == kPrecompiled) {
1560 GeneratePrecompiledSnapshot(); 1417 GeneratePrecompiledSnapshot();
1561 } else { 1418 } else {
1562 if (Dart_IsNull(root_lib)) { 1419 if (Dart_IsNull(root_lib)) {
1563 ErrorExit(kErrorExitCode, 1420 ErrorExit(kErrorExitCode,
1564 "Unable to find root library for '%s'\n", 1421 "Unable to find root library for '%s'\n",
1565 script_name); 1422 script_name);
1566 } 1423 }
1567 1424
1568 // The helper function _getMainClosure creates a closure for the main 1425 // The helper function _getMainClosure creates a closure for the main
1569 // entry point which is either explicitly or implictly exported from the 1426 // entry point which is either explicitly or implictly exported from the
(...skipping 12 matching lines...) Expand all
1582 Dart_Handle isolate_lib = 1439 Dart_Handle isolate_lib =
1583 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate")); 1440 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate"));
1584 result = Dart_Invoke(isolate_lib, 1441 result = Dart_Invoke(isolate_lib,
1585 Dart_NewStringFromCString("_startMainIsolate"), 1442 Dart_NewStringFromCString("_startMainIsolate"),
1586 kNumIsolateArgs, isolate_args); 1443 kNumIsolateArgs, isolate_args);
1587 CHECK_RESULT(result); 1444 CHECK_RESULT(result);
1588 1445
1589 // Keep handling messages until the last active receive port is closed. 1446 // Keep handling messages until the last active receive port is closed.
1590 result = Dart_RunLoop(); 1447 result = Dart_RunLoop();
1591 // Generate a full snapshot after execution if specified. 1448 // Generate a full snapshot after execution if specified.
1592 if (generate_full_snapshot_after_run || gen_precompiled_jit_snapshot) { 1449 if ((gen_snapshot_kind == kFullAfterRun) ||
1450 (gen_snapshot_kind == kPrecompiledJIT)) {
1593 if (!Dart_IsCompilationError(result) && 1451 if (!Dart_IsCompilationError(result) &&
1594 !Dart_IsVMRestartRequest(result)) { 1452 !Dart_IsVMRestartRequest(result)) {
1595 if (generate_full_snapshot_after_run) { 1453 if (gen_snapshot_kind == kFullAfterRun) {
1596 GenerateFullSnapshot(); 1454 GenerateFullSnapshot();
1597 } else { 1455 } else {
1598 Dart_Handle prepare_result = Dart_PrecompileJIT(); 1456 Dart_Handle prepare_result = Dart_PrecompileJIT();
1599 CHECK_RESULT(prepare_result); 1457 CHECK_RESULT(prepare_result);
1600 GeneratePrecompiledJITSnapshot(); 1458 GeneratePrecompiledJITSnapshot();
1601 } 1459 }
1602 } 1460 }
1603 } 1461 }
1604 CHECK_RESULT(result); 1462 CHECK_RESULT(result);
1605 } 1463 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 1607
1750 Thread::InitOnce(); 1608 Thread::InitOnce();
1751 1609
1752 if (!DartUtils::SetOriginalWorkingDirectory()) { 1610 if (!DartUtils::SetOriginalWorkingDirectory()) {
1753 OSError err; 1611 OSError err;
1754 fprintf(stderr, "Error determining current directory: %s\n", err.message()); 1612 fprintf(stderr, "Error determining current directory: %s\n", err.message());
1755 fflush(stderr); 1613 fflush(stderr);
1756 Platform::Exit(kErrorExitCode); 1614 Platform::Exit(kErrorExitCode);
1757 } 1615 }
1758 1616
1759 #if !defined(PRODUCT) 1617 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
1760 // Constant true in PRODUCT mode. 1618 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME.
1761 if (generate_script_snapshot || 1619 if ((gen_snapshot_kind != kNone) || run_full_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"); 1620 vm_options.AddArgument("--load_deferred_eagerly");
1767 } 1621 }
1768 #endif 1622 #endif
1769 1623
1770 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) 1624 if ((gen_snapshot_kind == kPrecompiled) || is_noopt) {
1771 // Always set --precompilation with dart_noopt. 1625 vm_options.AddArgument("--precompilation");
1772 ASSERT(!gen_precompiled_snapshot && !run_precompiled_snapshot); 1626 }
1627 #if defined(DART_PRECOMPILED_RUNTIME)
1773 vm_options.AddArgument("--precompilation"); 1628 vm_options.AddArgument("--precompilation");
1774 #endif 1629 #endif
1775 1630
1776 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 1631 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
1777 1632
1778 // Start event handler. 1633 // Start event handler.
1779 TimerUtils::InitOnce(); 1634 TimerUtils::InitOnce();
1780 EventHandler::Start(); 1635 EventHandler::Start();
1781 1636
1782 const uint8_t* instructions_snapshot = NULL; 1637 const uint8_t* instructions_snapshot = NULL;
1783 const uint8_t* data_snapshot = NULL; 1638 const uint8_t* data_snapshot = NULL;
1784 if (run_precompiled_snapshot || run_precompiled_jit_snapshot) { 1639 if (run_full_snapshot) {
1785 ReadSnapshotFile(precompiled_snapshot_directory, 1640 ReadSnapshotFile(snapshot_filename, kVMIsolateSuffix,
1786 kPrecompiledVmIsolateName,
1787 &vm_isolate_snapshot_buffer); 1641 &vm_isolate_snapshot_buffer);
1788 ReadSnapshotFile(precompiled_snapshot_directory, 1642 ReadSnapshotFile(snapshot_filename, kIsolateSuffix,
1789 kPrecompiledIsolateName,
1790 &isolate_snapshot_buffer); 1643 &isolate_snapshot_buffer);
1791 if (use_blobs) { 1644 if (use_blobs) {
1792 ReadExecutableSnapshotFile(precompiled_snapshot_directory, 1645 ReadExecutableSnapshotFile(snapshot_filename,
1793 kPrecompiledInstructionsBlobName, 1646 kInstructionsSuffix,
1794 &instructions_snapshot); 1647 &instructions_snapshot);
1795 ReadSnapshotFile(precompiled_snapshot_directory, 1648 ReadSnapshotFile(snapshot_filename, kRODataSuffix,
1796 kPrecompiledRodataBlobName,
1797 &data_snapshot); 1649 &data_snapshot);
1798 } else { 1650 } else {
1799 instructions_snapshot = reinterpret_cast<const uint8_t*>( 1651 instructions_snapshot = reinterpret_cast<const uint8_t*>(
1800 LoadLibrarySymbol(precompiled_snapshot_directory, 1652 LoadLibrarySymbol(snapshot_filename,
1801 kPrecompiledLibraryName, 1653 kPrecompiledLibraryName,
1802 kPrecompiledInstructionsSymbolName)); 1654 kPrecompiledInstructionsSymbolName));
1803 data_snapshot = reinterpret_cast<const uint8_t*>( 1655 data_snapshot = reinterpret_cast<const uint8_t*>(
1804 LoadLibrarySymbol(precompiled_snapshot_directory, 1656 LoadLibrarySymbol(snapshot_filename,
1805 kPrecompiledLibraryName, 1657 kPrecompiledLibraryName,
1806 kPrecompiledDataSymbolName)); 1658 kPrecompiledDataSymbolName));
1807 } 1659 }
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 } 1660 }
1822 1661
1823 // Initialize the Dart VM. 1662 // Initialize the Dart VM.
1824 char* error = Dart_Initialize( 1663 char* error = Dart_Initialize(
1825 vm_isolate_snapshot_buffer, instructions_snapshot, data_snapshot, 1664 vm_isolate_snapshot_buffer, instructions_snapshot, data_snapshot,
1826 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, 1665 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate,
1827 NULL, 1666 NULL,
1828 DartUtils::OpenFile, 1667 DartUtils::OpenFile,
1829 DartUtils::ReadFile, 1668 DartUtils::ReadFile,
1830 DartUtils::WriteFile, 1669 DartUtils::WriteFile,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 Platform::Exit(Process::GlobalExitCode()); 1723 Platform::Exit(Process::GlobalExitCode());
1885 } 1724 }
1886 1725
1887 } // namespace bin 1726 } // namespace bin
1888 } // namespace dart 1727 } // namespace dart
1889 1728
1890 int main(int argc, char** argv) { 1729 int main(int argc, char** argv) {
1891 dart::bin::main(argc, argv); 1730 dart::bin::main(argc, argv);
1892 UNREACHABLE(); 1731 UNREACHABLE();
1893 } 1732 }
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