| OLD | NEW |
| 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 21 matching lines...) Expand all Loading... |
| 32 namespace bin { | 32 namespace bin { |
| 33 | 33 |
| 34 // vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we | 34 // vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we |
| 35 // link in a snapshot otherwise it is initialized to NULL. | 35 // link in a snapshot otherwise it is initialized to NULL. |
| 36 extern const uint8_t* vm_isolate_snapshot_buffer; | 36 extern const uint8_t* vm_isolate_snapshot_buffer; |
| 37 | 37 |
| 38 // isolate_snapshot_buffer points to a snapshot for an isolate if we link in a | 38 // isolate_snapshot_buffer points to a snapshot for an isolate if we link in a |
| 39 // snapshot otherwise it is initialized to NULL. | 39 // snapshot otherwise it is initialized to NULL. |
| 40 extern const uint8_t* isolate_snapshot_buffer; | 40 extern const uint8_t* isolate_snapshot_buffer; |
| 41 | 41 |
| 42 // Global state that stores a pointer to the application script snapshot. | 42 /** |
| 43 * Global state used to control and store generation of application snapshots |
| 44 * (script/full). |
| 45 * A full application snapshot can be generated and run using the following |
| 46 * commands |
| 47 * - Generating a full application snapshot : |
| 48 * dart_no_snapshot --full-snapshot-after-run=<filename> --package-root=<dirs> |
| 49 * <script_uri> [<script_options>] |
| 50 * - Running the full application snapshot generated above : |
| 51 * dart --run-full-snapshot=<filename> <script_uri> [<script_options>] |
| 52 */ |
| 43 static bool generate_script_snapshot = false; | 53 static bool generate_script_snapshot = false; |
| 44 static bool generate_script_snapshot_after_run = false; | 54 static bool generate_full_snapshot_after_run = false; |
| 55 static bool run_full_snapshot = false; |
| 45 static const char* snapshot_filename = NULL; | 56 static const char* snapshot_filename = NULL; |
| 46 | 57 |
| 47 | |
| 48 // Value of the --package-root flag. | 58 // Value of the --package-root flag. |
| 49 // (This pointer points into an argv buffer and does not need to be | 59 // (This pointer points into an argv buffer and does not need to be |
| 50 // free'd.) | 60 // free'd.) |
| 51 static const char* commandline_package_root = NULL; | 61 static const char* commandline_package_root = NULL; |
| 52 | 62 |
| 53 // Value of the --packages flag. | 63 // Value of the --packages flag. |
| 54 // (This pointer points into an argv buffer and does not need to be | 64 // (This pointer points into an argv buffer and does not need to be |
| 55 // free'd.) | 65 // free'd.) |
| 56 static const char* commandline_packages_file = NULL; | 66 static const char* commandline_packages_file = NULL; |
| 57 | 67 |
| 58 | 68 |
| 59 // Global flag that is used to indicate that we want to compile all the | 69 // Global flag that is used to indicate that we want to compile all the |
| 60 // dart functions and not run anything. | 70 // dart functions and not run anything. |
| 61 static bool has_compile_all = false; | 71 static bool compile_all = false; |
| 62 | 72 |
| 63 | 73 |
| 64 // Global flag that is used to indicate that we want to compile all the | 74 // Global flag that is used to indicate that we want to compile all the |
| 65 // dart functions before running main and not compile anything thereafter. | 75 // dart functions before running main and not compile anything thereafter. |
| 66 static bool has_gen_precompiled_snapshot = false; | 76 static bool gen_precompiled_snapshot = false; |
| 67 | 77 |
| 68 | 78 |
| 69 // Global flag that is used to indicate that we want to run from a precompiled | 79 // Global flag that is used to indicate that we want to run from a precompiled |
| 70 // snapshot. | 80 // snapshot. |
| 71 static bool has_run_precompiled_snapshot = false; | 81 static bool run_precompiled_snapshot = false; |
| 72 | 82 |
| 73 | 83 |
| 74 // Value of the --gen/run_precompiled_snapshot flag. | 84 // Value of the --gen/run_precompiled_snapshot flag. |
| 75 // (This pointer points into an argv buffer and does not need to be | 85 // (This pointer points into an argv buffer and does not need to be |
| 76 // free'd.) | 86 // free'd.) |
| 77 static const char* precompiled_snapshot_directory = NULL; | 87 static const char* precompiled_snapshot_directory = NULL; |
| 78 | 88 |
| 79 | 89 |
| 80 // Global flag that is used to indicate that we want to compile everything in | 90 // Global flag that is used to indicate that we want to compile everything in |
| 81 // the same way as precompilation before main, then continue running in the | 91 // the same way as precompilation before main, then continue running in the |
| 82 // same process. | 92 // same process. |
| 83 // Always set this with dart_noopt. | 93 // Always set this with dart_noopt. |
| 84 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) | 94 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) |
| 85 static const bool has_noopt = true; | 95 static const bool is_noopt = true; |
| 86 #else | 96 #else |
| 87 static const bool has_noopt = false; | 97 static const bool is_noopt = false; |
| 88 #endif | 98 #endif |
| 89 | 99 |
| 90 | 100 |
| 91 extern const char* kPrecompiledLibraryName; | 101 extern const char* kPrecompiledLibraryName; |
| 92 extern const char* kPrecompiledSymbolName; | 102 extern const char* kPrecompiledSymbolName; |
| 93 static const char* kPrecompiledVmIsolateName = "precompiled.vmisolate"; | 103 static const char* kPrecompiledVmIsolateName = "precompiled.vmisolate"; |
| 94 static const char* kPrecompiledIsolateName = "precompiled.isolate"; | 104 static const char* kPrecompiledIsolateName = "precompiled.isolate"; |
| 95 static const char* kPrecompiledInstructionsName = "precompiled.S"; | 105 static const char* kPrecompiledInstructionsName = "precompiled.S"; |
| 96 | 106 static const char* kVMIsolateSuffix = "vmisolate"; |
| 107 static const char* kIsolateSuffix = "isolate"; |
| 97 | 108 |
| 98 // 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 |
| 99 // URIs and the loading of libraries, parts and scripts. | 110 // URIs and the loading of libraries, parts and scripts. |
| 100 static bool has_trace_loading = false; | 111 static bool trace_loading = false; |
| 101 | 112 |
| 102 | 113 |
| 103 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"; |
| 104 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; | 115 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; |
| 105 // VM Service options. | 116 // VM Service options. |
| 106 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; |
| 107 // The 0 port is a magic value which results in the first available port | 118 // The 0 port is a magic value which results in the first available port |
| 108 // being allocated. | 119 // being allocated. |
| 109 static int vm_service_server_port = -1; | 120 static int vm_service_server_port = -1; |
| 110 | 121 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 164 |
| 154 static bool IsValidFlag(const char* name, | 165 static bool IsValidFlag(const char* name, |
| 155 const char* prefix, | 166 const char* prefix, |
| 156 intptr_t prefix_length) { | 167 intptr_t prefix_length) { |
| 157 intptr_t name_length = strlen(name); | 168 intptr_t name_length = strlen(name); |
| 158 return ((name_length > prefix_length) && | 169 return ((name_length > prefix_length) && |
| 159 (strncmp(name, prefix, prefix_length) == 0)); | 170 (strncmp(name, prefix, prefix_length) == 0)); |
| 160 } | 171 } |
| 161 | 172 |
| 162 | 173 |
| 163 static bool has_version_option = false; | 174 static bool version_option = false; |
| 164 static bool ProcessVersionOption(const char* arg, | 175 static bool ProcessVersionOption(const char* arg, |
| 165 CommandLineOptions* vm_options) { | 176 CommandLineOptions* vm_options) { |
| 166 if (*arg != '\0') { | 177 if (*arg != '\0') { |
| 167 return false; | 178 return false; |
| 168 } | 179 } |
| 169 has_version_option = true; | 180 version_option = true; |
| 170 return true; | 181 return true; |
| 171 } | 182 } |
| 172 | 183 |
| 173 | 184 |
| 174 static bool has_help_option = false; | 185 static bool help_option = false; |
| 175 static bool ProcessHelpOption(const char* arg, CommandLineOptions* vm_options) { | 186 static bool ProcessHelpOption(const char* arg, CommandLineOptions* vm_options) { |
| 176 if (*arg != '\0') { | 187 if (*arg != '\0') { |
| 177 return false; | 188 return false; |
| 178 } | 189 } |
| 179 has_help_option = true; | 190 help_option = true; |
| 180 return true; | 191 return true; |
| 181 } | 192 } |
| 182 | 193 |
| 183 | 194 |
| 184 static bool has_verbose_option = false; | 195 static bool verbose_option = false; |
| 185 static bool ProcessVerboseOption(const char* arg, | 196 static bool ProcessVerboseOption(const char* arg, |
| 186 CommandLineOptions* vm_options) { | 197 CommandLineOptions* vm_options) { |
| 187 if (*arg != '\0') { | 198 if (*arg != '\0') { |
| 188 return false; | 199 return false; |
| 189 } | 200 } |
| 190 has_verbose_option = true; | 201 verbose_option = true; |
| 191 return true; | 202 return true; |
| 192 } | 203 } |
| 193 | 204 |
| 194 | 205 |
| 195 static bool ProcessPackageRootOption(const char* arg, | 206 static bool ProcessPackageRootOption(const char* arg, |
| 196 CommandLineOptions* vm_options) { | 207 CommandLineOptions* vm_options) { |
| 197 ASSERT(arg != NULL); | 208 ASSERT(arg != NULL); |
| 198 if (*arg == '\0' || *arg == '-') { | 209 if (*arg == '\0' || *arg == '-') { |
| 199 return false; | 210 return false; |
| 200 } | 211 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 return true; | 311 return true; |
| 301 } | 312 } |
| 302 | 313 |
| 303 | 314 |
| 304 static bool ProcessCompileAllOption(const char* arg, | 315 static bool ProcessCompileAllOption(const char* arg, |
| 305 CommandLineOptions* vm_options) { | 316 CommandLineOptions* vm_options) { |
| 306 ASSERT(arg != NULL); | 317 ASSERT(arg != NULL); |
| 307 if (*arg != '\0') { | 318 if (*arg != '\0') { |
| 308 return false; | 319 return false; |
| 309 } | 320 } |
| 310 has_compile_all = true; | 321 compile_all = true; |
| 311 return true; | 322 return true; |
| 312 } | 323 } |
| 313 | 324 |
| 314 | 325 |
| 315 static bool ProcessGenPrecompiledSnapshotOption( | 326 static bool ProcessGenPrecompiledSnapshotOption( |
| 316 const char* arg, | 327 const char* arg, |
| 317 CommandLineOptions* vm_options) { | 328 CommandLineOptions* vm_options) { |
| 318 // Ensure that we are not already running using a full snapshot. | 329 // Ensure that we are not already running using a full snapshot. |
| 319 if (isolate_snapshot_buffer != NULL) { | 330 if (isolate_snapshot_buffer != NULL) { |
| 320 Log::PrintErr("Precompiled snapshots must be generated with" | 331 Log::PrintErr("Precompiled snapshots must be generated with" |
| 321 " dart_no_snapshot.\n"); | 332 " dart_no_snapshot.\n"); |
| 322 return false; | 333 return false; |
| 323 } | 334 } |
| 324 ASSERT(arg != NULL); | 335 ASSERT(arg != NULL); |
| 325 if ((arg[0] == '=') || (arg[0] == ':')) { | 336 if ((arg[0] == '=') || (arg[0] == ':')) { |
| 326 precompiled_snapshot_directory = &arg[1]; | 337 precompiled_snapshot_directory = &arg[1]; |
| 327 } else { | 338 } else { |
| 328 precompiled_snapshot_directory = arg; | 339 precompiled_snapshot_directory = arg; |
| 329 } | 340 } |
| 330 has_gen_precompiled_snapshot = true; | 341 gen_precompiled_snapshot = true; |
| 331 vm_options->AddArgument("--precompilation"); | 342 vm_options->AddArgument("--precompilation"); |
| 332 return true; | 343 return true; |
| 333 } | 344 } |
| 334 | 345 |
| 335 | 346 |
| 336 static bool ProcessRunPrecompiledSnapshotOption( | 347 static bool ProcessRunPrecompiledSnapshotOption( |
| 337 const char* arg, | 348 const char* arg, |
| 338 CommandLineOptions* vm_options) { | 349 CommandLineOptions* vm_options) { |
| 339 ASSERT(arg != NULL); | 350 ASSERT(arg != NULL); |
| 340 precompiled_snapshot_directory = arg; | 351 precompiled_snapshot_directory = arg; |
| 341 if ((precompiled_snapshot_directory[0] == '=') || | 352 if ((precompiled_snapshot_directory[0] == '=') || |
| 342 (precompiled_snapshot_directory[0] == ':')) { | 353 (precompiled_snapshot_directory[0] == ':')) { |
| 343 precompiled_snapshot_directory = &precompiled_snapshot_directory[1]; | 354 precompiled_snapshot_directory = &precompiled_snapshot_directory[1]; |
| 344 } | 355 } |
| 345 has_run_precompiled_snapshot = true; | 356 run_precompiled_snapshot = true; |
| 346 vm_options->AddArgument("--precompilation"); | 357 vm_options->AddArgument("--precompilation"); |
| 347 return true; | 358 return true; |
| 348 } | 359 } |
| 349 | 360 |
| 350 | 361 |
| 351 static bool ProcessScriptSnapshotOptionHelper(const char* filename, | 362 static bool ProcessSnapshotOptionHelper(const char* filename, |
| 352 bool* snapshot_option) { | 363 bool* snapshot_option) { |
| 353 *snapshot_option = false; | 364 ASSERT((filename != NULL) && (strlen(filename) != 0)); |
| 354 if ((filename != NULL) && (strlen(filename) != 0)) { | 365 snapshot_filename = filename; |
| 355 // Ensure that we are already running using a full snapshot. | 366 *snapshot_option = true; |
| 356 if (isolate_snapshot_buffer == NULL) { | 367 if (generate_script_snapshot && generate_full_snapshot_after_run) { |
| 357 Log::PrintErr("Script snapshots cannot be generated in this version of" | 368 Log::PrintErr("--snapshot and --snapshot-after-run options" |
| 358 " dart\n"); | 369 " cannot be specified at the same time\n"); |
| 359 return false; | 370 *snapshot_option = false; |
| 360 } | 371 return false; |
| 361 snapshot_filename = filename; | |
| 362 *snapshot_option = true; | |
| 363 if (generate_script_snapshot && generate_script_snapshot_after_run) { | |
| 364 Log::PrintErr("--snapshot and --snapshot-after-run options" | |
| 365 " cannot be specified at the same time\n"); | |
| 366 return false; | |
| 367 } | |
| 368 return true; | |
| 369 } | 372 } |
| 370 return false; | 373 return true; |
| 371 } | 374 } |
| 372 | 375 |
| 373 | 376 |
| 374 static bool ProcessScriptSnapshotOption(const char* filename, | 377 static bool ProcessScriptSnapshotOption(const char* filename, |
| 375 CommandLineOptions* vm_options) { | 378 CommandLineOptions* vm_options) { |
| 376 return ProcessScriptSnapshotOptionHelper(filename, &generate_script_snapshot); | 379 if ((filename == NULL) || (strlen(filename) == 0)) { |
| 380 return false; |
| 381 } |
| 382 // Ensure that we are already running using a full snapshot. |
| 383 if (isolate_snapshot_buffer == NULL) { |
| 384 Log::PrintErr("Script snapshots cannot be generated in this version of" |
| 385 " Dart\n"); |
| 386 return false; |
| 387 } |
| 388 return ProcessSnapshotOptionHelper(filename, &generate_script_snapshot); |
| 377 } | 389 } |
| 378 | 390 |
| 379 | 391 |
| 380 static bool ProcessScriptSnapshotAfterRunOption( | 392 static bool ProcessFullSnapshotAfterRunOption( |
| 381 const char* filename, CommandLineOptions* vm_options) { | 393 const char* filename, CommandLineOptions* vm_options) { |
| 382 return ProcessScriptSnapshotOptionHelper(filename, | 394 if ((filename == NULL) || (strlen(filename) == 0)) { |
| 383 &generate_script_snapshot_after_run); | 395 return false; |
| 396 } |
| 397 // Ensure that we are running 'dart_no_snapshot'. |
| 398 if (isolate_snapshot_buffer != NULL) { |
| 399 Log::PrintErr("Full Application snapshots must be generated with" |
| 400 " dart_no_snapshot\n"); |
| 401 return false; |
| 402 } |
| 403 return ProcessSnapshotOptionHelper(filename, |
| 404 &generate_full_snapshot_after_run); |
| 384 } | 405 } |
| 385 | 406 |
| 386 | 407 |
| 408 static bool ProcessRunFullSnapshotOption( |
| 409 const char* filename, CommandLineOptions* vm_options) { |
| 410 // Ensure that we are not running 'dart_no_snapshot'. |
| 411 if (isolate_snapshot_buffer == NULL) { |
| 412 Log::PrintErr("Full Application snapshots cannot be run with" |
| 413 " dart_no_snapshot\n"); |
| 414 return false; |
| 415 } |
| 416 return ProcessSnapshotOptionHelper(filename, &run_full_snapshot); |
| 417 } |
| 418 |
| 419 |
| 387 static bool ProcessEnableVmServiceOption(const char* option_value, | 420 static bool ProcessEnableVmServiceOption(const char* option_value, |
| 388 CommandLineOptions* vm_options) { | 421 CommandLineOptions* vm_options) { |
| 389 ASSERT(option_value != NULL); | 422 ASSERT(option_value != NULL); |
| 390 | 423 |
| 391 if (!ExtractPortAndIP(option_value, | 424 if (!ExtractPortAndIP(option_value, |
| 392 &vm_service_server_port, | 425 &vm_service_server_port, |
| 393 &vm_service_server_ip, | 426 &vm_service_server_ip, |
| 394 DEFAULT_VM_SERVICE_SERVER_PORT, | 427 DEFAULT_VM_SERVICE_SERVER_PORT, |
| 395 DEFAULT_VM_SERVICE_SERVER_IP)) { | 428 DEFAULT_VM_SERVICE_SERVER_IP)) { |
| 396 Log::PrintErr("unrecognized --enable-vm-service option syntax. " | 429 Log::PrintErr("unrecognized --enable-vm-service option syntax. " |
| (...skipping 24 matching lines...) Expand all Loading... |
| 421 vm_options->AddArgument("--warn-on-pause-with-no-debugger"); | 454 vm_options->AddArgument("--warn-on-pause-with-no-debugger"); |
| 422 return true; | 455 return true; |
| 423 } | 456 } |
| 424 | 457 |
| 425 | 458 |
| 426 static bool ProcessTraceLoadingOption(const char* arg, | 459 static bool ProcessTraceLoadingOption(const char* arg, |
| 427 CommandLineOptions* vm_options) { | 460 CommandLineOptions* vm_options) { |
| 428 if (*arg != '\0') { | 461 if (*arg != '\0') { |
| 429 return false; | 462 return false; |
| 430 } | 463 } |
| 431 has_trace_loading = true; | 464 trace_loading = true; |
| 432 return true; | 465 return true; |
| 433 } | 466 } |
| 434 | 467 |
| 435 | 468 |
| 436 | 469 |
| 437 static bool ProcessShutdownOption(const char* arg, | 470 static bool ProcessShutdownOption(const char* arg, |
| 438 CommandLineOptions* vm_options) { | 471 CommandLineOptions* vm_options) { |
| 439 ASSERT(arg != NULL); | 472 ASSERT(arg != NULL); |
| 440 if (*arg == '\0') { | 473 if (*arg == '\0') { |
| 441 do_vm_shutdown = true; | 474 do_vm_shutdown = true; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 { "--version", ProcessVersionOption }, | 509 { "--version", ProcessVersionOption }, |
| 477 | 510 |
| 478 // VM specific options to the standalone dart program. | 511 // VM specific options to the standalone dart program. |
| 479 { "--compile_all", ProcessCompileAllOption }, | 512 { "--compile_all", ProcessCompileAllOption }, |
| 480 { "--enable-vm-service", ProcessEnableVmServiceOption }, | 513 { "--enable-vm-service", ProcessEnableVmServiceOption }, |
| 481 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption }, | 514 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption }, |
| 482 { "--observe", ProcessObserveOption }, | 515 { "--observe", ProcessObserveOption }, |
| 483 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption }, | 516 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption }, |
| 484 { "--shutdown", ProcessShutdownOption }, | 517 { "--shutdown", ProcessShutdownOption }, |
| 485 { "--snapshot=", ProcessScriptSnapshotOption }, | 518 { "--snapshot=", ProcessScriptSnapshotOption }, |
| 486 { "--snapshot-after-run=", ProcessScriptSnapshotAfterRunOption }, | 519 { "--full-snapshot-after-run=", ProcessFullSnapshotAfterRunOption }, |
| 520 { "--run-full-snapshot=", ProcessRunFullSnapshotOption }, |
| 487 { "--trace-loading", ProcessTraceLoadingOption }, | 521 { "--trace-loading", ProcessTraceLoadingOption }, |
| 488 { NULL, NULL } | 522 { NULL, NULL } |
| 489 }; | 523 }; |
| 490 | 524 |
| 491 | 525 |
| 492 static bool ProcessMainOptions(const char* option, | 526 static bool ProcessMainOptions(const char* option, |
| 493 CommandLineOptions* vm_options) { | 527 CommandLineOptions* vm_options) { |
| 494 int i = 0; | 528 int i = 0; |
| 495 const char* name = main_options[0].option_name; | 529 const char* name = main_options[0].option_name; |
| 496 int option_length = strlen(option); | 530 int option_length = strlen(option); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 i++; | 627 i++; |
| 594 } | 628 } |
| 595 | 629 |
| 596 // Verify consistency of arguments. | 630 // Verify consistency of arguments. |
| 597 if ((commandline_package_root != NULL) && | 631 if ((commandline_package_root != NULL) && |
| 598 (commandline_packages_file != NULL)) { | 632 (commandline_packages_file != NULL)) { |
| 599 Log::PrintErr("Specifying both a packages directory and a packages " | 633 Log::PrintErr("Specifying both a packages directory and a packages " |
| 600 "file is invalid.\n"); | 634 "file is invalid.\n"); |
| 601 return -1; | 635 return -1; |
| 602 } | 636 } |
| 603 if (has_noopt) { | 637 if (is_noopt) { |
| 604 if (has_gen_precompiled_snapshot) { | 638 if (gen_precompiled_snapshot) { |
| 605 Log::PrintErr("Running dart_noopt with --gen_precompiled_snapshot" | 639 Log::PrintErr("Running dart_noopt with --gen_precompiled_snapshot" |
| 606 " is invalid.\n"); | 640 " is invalid.\n"); |
| 607 return -1; | 641 return -1; |
| 608 } | 642 } |
| 609 if (has_run_precompiled_snapshot) { | 643 if (run_precompiled_snapshot) { |
| 610 Log::PrintErr("Running dart_noopt with --run_precompiled_snapshot" | 644 Log::PrintErr("Running dart_noopt with --run_precompiled_snapshot" |
| 611 " is invalid.\n"); | 645 " is invalid.\n"); |
| 612 return -1; | 646 return -1; |
| 613 } | 647 } |
| 614 } | 648 } |
| 615 if (has_gen_precompiled_snapshot && has_run_precompiled_snapshot) { | 649 if (run_full_snapshot && run_precompiled_snapshot) { |
| 616 Log::PrintErr("Specifying --gen_precompiled_snapshot and" | 650 Log::PrintErr("Specifying --run_full_snapshot and" |
| 617 " --run_precompiled_snapshot is invalid.\n"); | 651 " --run_precompiled_snapshot is invalid.\n"); |
| 618 return -1; | 652 return -1; |
| 619 } | 653 } |
| 654 if ((generate_full_snapshot_after_run || gen_precompiled_snapshot) && |
| 655 (run_full_snapshot || run_precompiled_snapshot)) { |
| 656 Log::PrintErr("Specifying an option to generate a snapshot and" |
| 657 " run using a snapshot is invalid.\n"); |
| 658 return -1; |
| 659 } |
| 620 | 660 |
| 621 return 0; | 661 return 0; |
| 622 } | 662 } |
| 623 | 663 |
| 624 | 664 |
| 625 static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) { | 665 static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) { |
| 626 int options_count = options->count(); | 666 int options_count = options->count(); |
| 627 Dart_Handle dart_arguments = Dart_NewList(options_count); | 667 Dart_Handle dart_arguments = Dart_NewList(options_count); |
| 628 if (Dart_IsError(dart_arguments)) { | 668 if (Dart_IsError(dart_arguments)) { |
| 629 return dart_arguments; | 669 return dart_arguments; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 | 735 |
| 696 // Returns true on success, false on failure. | 736 // Returns true on success, false on failure. |
| 697 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, | 737 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, |
| 698 const char* main, | 738 const char* main, |
| 699 const char* package_root, | 739 const char* package_root, |
| 700 const char* packages_config, | 740 const char* packages_config, |
| 701 Dart_IsolateFlags* flags, | 741 Dart_IsolateFlags* flags, |
| 702 char** error, | 742 char** error, |
| 703 int* exit_code) { | 743 int* exit_code) { |
| 704 ASSERT(script_uri != NULL); | 744 ASSERT(script_uri != NULL); |
| 745 if (run_full_snapshot && |
| 746 !strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME)) { |
| 747 // We do not create a service isolate when running a full application |
| 748 // snapshot. |
| 749 return NULL; |
| 750 } |
| 705 IsolateData* isolate_data = new IsolateData(script_uri, | 751 IsolateData* isolate_data = new IsolateData(script_uri, |
| 706 package_root, | 752 package_root, |
| 707 packages_config); | 753 packages_config); |
| 708 Dart_Isolate isolate = NULL; | 754 Dart_Isolate isolate = NULL; |
| 709 | 755 |
| 710 isolate = Dart_CreateIsolate(script_uri, | 756 isolate = Dart_CreateIsolate(script_uri, |
| 711 main, | 757 main, |
| 712 isolate_snapshot_buffer, | 758 isolate_snapshot_buffer, |
| 713 flags, | 759 flags, |
| 714 isolate_data, | 760 isolate_data, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 728 } | 774 } |
| 729 | 775 |
| 730 // Set up the library tag handler for this isolate. | 776 // Set up the library tag handler for this isolate. |
| 731 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); | 777 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); |
| 732 CHECK_RESULT(result); | 778 CHECK_RESULT(result); |
| 733 | 779 |
| 734 if (Dart_IsServiceIsolate(isolate)) { | 780 if (Dart_IsServiceIsolate(isolate)) { |
| 735 // If this is the service isolate, load embedder specific bits and return. | 781 // If this is the service isolate, load embedder specific bits and return. |
| 736 if (!VmService::Setup(vm_service_server_ip, | 782 if (!VmService::Setup(vm_service_server_ip, |
| 737 vm_service_server_port, | 783 vm_service_server_port, |
| 738 has_run_precompiled_snapshot)) { | 784 run_precompiled_snapshot)) { |
| 739 *error = strdup(VmService::GetErrorMessage()); | 785 *error = strdup(VmService::GetErrorMessage()); |
| 740 return NULL; | 786 return NULL; |
| 741 } | 787 } |
| 742 if (has_compile_all) { | 788 if (compile_all) { |
| 743 result = Dart_CompileAll(); | 789 result = Dart_CompileAll(); |
| 744 CHECK_RESULT(result); | 790 CHECK_RESULT(result); |
| 745 } | 791 } |
| 746 Dart_ExitScope(); | 792 Dart_ExitScope(); |
| 747 Dart_ExitIsolate(); | 793 Dart_ExitIsolate(); |
| 748 return isolate; | 794 return isolate; |
| 749 } | 795 } |
| 750 | 796 |
| 751 // Prepare builtin and other core libraries for use to resolve URIs. | 797 // Prepare builtin and other core libraries for use to resolve URIs. |
| 752 // Set up various closures, e.g: printing, timers etc. | 798 // Set up various closures, e.g: printing, timers etc. |
| 753 // Set up 'package root' for URI resolution. | 799 // Set up 'package root' for URI resolution. |
| 754 result = DartUtils::PrepareForScriptLoading(false, has_trace_loading); | 800 result = DartUtils::PrepareForScriptLoading(false, trace_loading); |
| 755 CHECK_RESULT(result); | 801 CHECK_RESULT(result); |
| 756 | 802 |
| 757 // Set up the load port provided by the service isolate so that we can | 803 if (!run_full_snapshot) { |
| 758 // load scripts. | 804 // Set up the load port provided by the service isolate so that we can |
| 759 result = DartUtils::SetupServiceLoadPort(); | 805 // load scripts. |
| 760 CHECK_RESULT(result); | 806 result = DartUtils::SetupServiceLoadPort(); |
| 807 CHECK_RESULT(result); |
| 808 } |
| 761 | 809 |
| 762 // Setup package root if specified. | 810 // Setup package root if specified. |
| 763 result = DartUtils::SetupPackageRoot(package_root, packages_config); | 811 result = DartUtils::SetupPackageRoot(package_root, packages_config); |
| 764 CHECK_RESULT(result); | 812 CHECK_RESULT(result); |
| 765 | 813 |
| 766 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 814 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
| 767 CHECK_RESULT(result); | 815 CHECK_RESULT(result); |
| 768 | 816 |
| 769 if (!has_run_precompiled_snapshot) { | 817 if (!run_precompiled_snapshot && !run_full_snapshot) { |
| 770 // Load the specified application script into the newly created isolate. | 818 // Load the specified application script into the newly created isolate. |
| 771 | |
| 772 // Load the script. | |
| 773 result = DartUtils::LoadScript(script_uri); | 819 result = DartUtils::LoadScript(script_uri); |
| 774 CHECK_RESULT(result); | 820 CHECK_RESULT(result); |
| 775 | 821 |
| 776 // Run event-loop and wait for script loading to complete. | 822 // Run event-loop and wait for script loading to complete. |
| 777 result = Dart_RunLoop(); | 823 result = Dart_RunLoop(); |
| 778 CHECK_RESULT(result); | 824 CHECK_RESULT(result); |
| 779 | 825 |
| 780 if (isolate_data->load_async_id >= 0) { | 826 if (isolate_data->load_async_id >= 0) { |
| 781 Dart_TimelineAsyncEnd("LoadScript", isolate_data->load_async_id); | 827 Dart_TimelineAsyncEnd("LoadScript", isolate_data->load_async_id); |
| 782 } | 828 } |
| 783 | 829 |
| 784 result = DartUtils::SetupIOLibrary(script_uri); | 830 result = DartUtils::SetupIOLibrary(script_uri); |
| 785 CHECK_RESULT(result); | 831 CHECK_RESULT(result); |
| 832 } else if (run_full_snapshot) { |
| 833 result = DartUtils::SetupIOLibrary(script_uri); |
| 834 CHECK_RESULT(result); |
| 786 } | 835 } |
| 787 | 836 |
| 788 // Make the isolate runnable so that it is ready to handle messages. | 837 // Make the isolate runnable so that it is ready to handle messages. |
| 789 Dart_ExitScope(); | 838 Dart_ExitScope(); |
| 790 Dart_ExitIsolate(); | 839 Dart_ExitIsolate(); |
| 791 bool retval = Dart_IsolateMakeRunnable(isolate); | 840 bool retval = Dart_IsolateMakeRunnable(isolate); |
| 792 if (!retval) { | 841 if (!retval) { |
| 793 *error = strdup("Invalid isolate state - Unable to make it runnable"); | 842 *error = strdup("Invalid isolate state - Unable to make it runnable"); |
| 794 Dart_EnterIsolate(isolate); | 843 Dart_EnterIsolate(isolate); |
| 795 Dart_ShutdownIsolate(); | 844 Dart_ShutdownIsolate(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); | 881 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); |
| 833 } | 882 } |
| 834 | 883 |
| 835 | 884 |
| 836 static void PrintUsage() { | 885 static void PrintUsage() { |
| 837 Log::PrintErr( | 886 Log::PrintErr( |
| 838 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n" | 887 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n" |
| 839 "\n" | 888 "\n" |
| 840 "Executes the Dart script passed as <dart-script-file>.\n" | 889 "Executes the Dart script passed as <dart-script-file>.\n" |
| 841 "\n"); | 890 "\n"); |
| 842 if (!has_verbose_option) { | 891 if (!verbose_option) { |
| 843 Log::PrintErr( | 892 Log::PrintErr( |
| 844 "Common options:\n" | 893 "Common options:\n" |
| 845 "--checked or -c\n" | 894 "--checked or -c\n" |
| 846 " Insert runtime type checks and enable assertions (checked mode).\n" | 895 " Insert runtime type checks and enable assertions (checked mode).\n" |
| 847 "--help or -h\n" | 896 "--help or -h\n" |
| 848 " Display this message (add -v or --verbose for information about\n" | 897 " Display this message (add -v or --verbose for information about\n" |
| 849 " all VM options).\n" | 898 " all VM options).\n" |
| 850 "--package-root=<path> or -p<path>\n" | 899 "--package-root=<path> or -p<path>\n" |
| 851 " Where to find packages, that is, \"package:...\" imports.\n" | 900 " Where to find packages, that is, \"package:...\" imports.\n" |
| 852 "--packages=<path>\n" | 901 "--packages=<path>\n" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 | 1050 |
| 1002 static void ServiceStreamCancelCallback(const char* stream_id) { | 1051 static void ServiceStreamCancelCallback(const char* stream_id) { |
| 1003 if (strcmp(stream_id, kStdoutStreamId) == 0) { | 1052 if (strcmp(stream_id, kStdoutStreamId) == 0) { |
| 1004 SetCaptureStdout(false); | 1053 SetCaptureStdout(false); |
| 1005 } else if (strcmp(stream_id, kStderrStreamId) == 0) { | 1054 } else if (strcmp(stream_id, kStderrStreamId) == 0) { |
| 1006 SetCaptureStderr(false); | 1055 SetCaptureStderr(false); |
| 1007 } | 1056 } |
| 1008 } | 1057 } |
| 1009 | 1058 |
| 1010 | 1059 |
| 1011 static void WritePrecompiledSnapshotFile(const char* filename, | 1060 static void WriteSnapshotFile(const char* snapshot_directory, |
| 1012 const uint8_t* buffer, | 1061 const char* filename, |
| 1013 const intptr_t size) { | 1062 bool write_magic_number, |
| 1063 const uint8_t* buffer, |
| 1064 const intptr_t size) { |
| 1014 char* concat = NULL; | 1065 char* concat = NULL; |
| 1015 const char* qualified_filename; | 1066 const char* qualified_filename; |
| 1016 if (strlen(precompiled_snapshot_directory) > 0) { | 1067 if ((snapshot_directory != NULL) && strlen(snapshot_directory) > 0) { |
| 1017 intptr_t len = snprintf(NULL, 0, "%s/%s", | 1068 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, filename); |
| 1018 precompiled_snapshot_directory, filename); | |
| 1019 concat = new char[len + 1]; | 1069 concat = new char[len + 1]; |
| 1020 snprintf(concat, len + 1, "%s/%s", | 1070 snprintf(concat, len + 1, "%s/%s", snapshot_directory, filename); |
| 1021 precompiled_snapshot_directory, filename); | |
| 1022 qualified_filename = concat; | 1071 qualified_filename = concat; |
| 1023 } else { | 1072 } else { |
| 1024 qualified_filename = filename; | 1073 qualified_filename = filename; |
| 1025 } | 1074 } |
| 1026 | 1075 |
| 1027 File* file = File::Open(qualified_filename, File::kWriteTruncate); | 1076 File* file = File::Open(qualified_filename, File::kWriteTruncate); |
| 1028 ASSERT(file != NULL); | 1077 ASSERT(file != NULL); |
| 1078 |
| 1079 if (write_magic_number) { |
| 1080 // Write the magic number to indicate file is a script snapshot. |
| 1081 DartUtils::WriteMagicNumber(file); |
| 1082 } |
| 1083 |
| 1029 if (!file->WriteFully(buffer, size)) { | 1084 if (!file->WriteFully(buffer, size)) { |
| 1030 ErrorExit(kErrorExitCode, | 1085 ErrorExit(kErrorExitCode, |
| 1031 "Unable to open file %s for writing snapshot\n", | 1086 "Unable to open file %s for writing snapshot\n", |
| 1032 qualified_filename); | 1087 qualified_filename); |
| 1033 } | 1088 } |
| 1034 delete file; | 1089 delete file; |
| 1035 if (concat != NULL) { | 1090 if (concat != NULL) { |
| 1036 delete concat; | 1091 delete concat; |
| 1037 } | 1092 } |
| 1038 } | 1093 } |
| 1039 | 1094 |
| 1040 | 1095 |
| 1041 static void ReadPrecompiledSnapshotFile(const char* filename, | 1096 static void ReadSnapshotFile(const char* snapshot_directory, |
| 1042 const uint8_t** buffer) { | 1097 const char* filename, |
| 1098 const uint8_t** buffer) { |
| 1043 char* concat = NULL; | 1099 char* concat = NULL; |
| 1044 const char* qualified_filename; | 1100 const char* qualified_filename; |
| 1045 if (strlen(precompiled_snapshot_directory) > 0) { | 1101 if ((snapshot_directory != NULL) && strlen(snapshot_directory) > 0) { |
| 1046 intptr_t len = snprintf(NULL, 0, "%s/%s", | 1102 intptr_t len = snprintf(NULL, 0, "%s/%s", snapshot_directory, filename); |
| 1047 precompiled_snapshot_directory, filename); | |
| 1048 concat = new char[len + 1]; | 1103 concat = new char[len + 1]; |
| 1049 snprintf(concat, len + 1, "%s/%s", | 1104 snprintf(concat, len + 1, "%s/%s", snapshot_directory, filename); |
| 1050 precompiled_snapshot_directory, filename); | |
| 1051 qualified_filename = concat; | 1105 qualified_filename = concat; |
| 1052 } else { | 1106 } else { |
| 1053 qualified_filename = filename; | 1107 qualified_filename = filename; |
| 1054 } | 1108 } |
| 1055 | 1109 |
| 1056 void* file = DartUtils::OpenFile(qualified_filename, false); | 1110 void* file = DartUtils::OpenFile(qualified_filename, false); |
| 1057 if (file == NULL) { | 1111 if (file == NULL) { |
| 1058 ErrorExit(kErrorExitCode, | 1112 ErrorExit(kErrorExitCode, |
| 1059 "Error: Unable to open file %s for reading snapshot\n", | 1113 "Error: Unable to open file %s for reading snapshot\n", |
| 1060 qualified_filename); | 1114 qualified_filename); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1089 | 1143 |
| 1090 static void GenerateScriptSnapshot() { | 1144 static void GenerateScriptSnapshot() { |
| 1091 // First create a snapshot. | 1145 // First create a snapshot. |
| 1092 uint8_t* buffer = NULL; | 1146 uint8_t* buffer = NULL; |
| 1093 intptr_t size = 0; | 1147 intptr_t size = 0; |
| 1094 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); | 1148 Dart_Handle result = Dart_CreateScriptSnapshot(&buffer, &size); |
| 1095 if (Dart_IsError(result)) { | 1149 if (Dart_IsError(result)) { |
| 1096 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1150 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
| 1097 } | 1151 } |
| 1098 | 1152 |
| 1099 // Open the snapshot file. | 1153 WriteSnapshotFile(NULL, snapshot_filename, true, buffer, size); |
| 1100 File* snapshot_file = File::Open(snapshot_filename, File::kWriteTruncate); | |
| 1101 if (snapshot_file == NULL) { | |
| 1102 ErrorExit(kErrorExitCode, | |
| 1103 "Unable to open file %s for writing the snapshot\n", | |
| 1104 snapshot_filename); | |
| 1105 } | |
| 1106 | |
| 1107 // Write the magic number to indicate file is a script snapshot. | |
| 1108 DartUtils::WriteMagicNumber(snapshot_file); | |
| 1109 | |
| 1110 // Now write the snapshot out to specified file. | |
| 1111 bool bytes_written = snapshot_file->WriteFully(buffer, size); | |
| 1112 ASSERT(bytes_written); | |
| 1113 delete snapshot_file; | |
| 1114 snapshot_file = NULL; | |
| 1115 } | 1154 } |
| 1116 | 1155 |
| 1117 | 1156 |
| 1157 static void ComputeSnapshotFilenames(const char* filename, |
| 1158 char** vm_snapshot_fname, |
| 1159 char** isolate_snapshot_fname) { |
| 1160 intptr_t len = snprintf(NULL, 0, "%s.%s", filename, kVMIsolateSuffix); |
| 1161 *vm_snapshot_fname = new char[len + 1]; |
| 1162 snprintf(*vm_snapshot_fname, len + 1, "%s.%s", filename, kVMIsolateSuffix); |
| 1163 |
| 1164 len = snprintf(NULL, 0, "%s.%s", filename, kIsolateSuffix); |
| 1165 *isolate_snapshot_fname = new char[len + 1]; |
| 1166 snprintf(*isolate_snapshot_fname, len + 1, "%s.%s", filename, kIsolateSuffix); |
| 1167 } |
| 1168 |
| 1169 static void GenerateFullSnapshot() { |
| 1170 // Create a full snapshot of the script. |
| 1171 Dart_Handle result; |
| 1172 uint8_t* vm_isolate_buffer = NULL; |
| 1173 intptr_t vm_isolate_size = 0; |
| 1174 uint8_t* isolate_buffer = NULL; |
| 1175 intptr_t isolate_size = 0; |
| 1176 char* vm_snapshot_fname = NULL; |
| 1177 char* isolate_snapshot_fname = NULL; |
| 1178 |
| 1179 result = Dart_CreateSnapshot(&vm_isolate_buffer, |
| 1180 &vm_isolate_size, |
| 1181 &isolate_buffer, |
| 1182 &isolate_size); |
| 1183 if (Dart_IsError(result)) { |
| 1184 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
| 1185 } |
| 1186 |
| 1187 // Compute snapshot file names and write out the snapshot files. |
| 1188 ComputeSnapshotFilenames(snapshot_filename, |
| 1189 &vm_snapshot_fname, |
| 1190 &isolate_snapshot_fname); |
| 1191 WriteSnapshotFile(NULL, |
| 1192 vm_snapshot_fname, |
| 1193 false, |
| 1194 vm_isolate_buffer, |
| 1195 vm_isolate_size); |
| 1196 WriteSnapshotFile(NULL, |
| 1197 isolate_snapshot_fname, |
| 1198 false, |
| 1199 isolate_buffer, |
| 1200 isolate_size); |
| 1201 } |
| 1202 |
| 1203 |
| 1118 #define CHECK_RESULT(result) \ | 1204 #define CHECK_RESULT(result) \ |
| 1119 if (Dart_IsError(result)) { \ | 1205 if (Dart_IsError(result)) { \ |
| 1120 if (Dart_IsVMRestartRequest(result)) { \ | 1206 if (Dart_IsVMRestartRequest(result)) { \ |
| 1121 Dart_ExitScope(); \ | 1207 Dart_ExitScope(); \ |
| 1122 Dart_ShutdownIsolate(); \ | 1208 Dart_ShutdownIsolate(); \ |
| 1123 return true; \ | 1209 return true; \ |
| 1124 } \ | 1210 } \ |
| 1125 const int exit_code = Dart_IsCompilationError(result) ? \ | 1211 const int exit_code = Dart_IsCompilationError(result) ? \ |
| 1126 kCompilationErrorExitCode : kErrorExitCode; \ | 1212 kCompilationErrorExitCode : kErrorExitCode; \ |
| 1127 ErrorExit(exit_code, "%s\n", Dart_GetError(result)); \ | 1213 ErrorExit(exit_code, "%s\n", Dart_GetError(result)); \ |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 GenerateScriptSnapshot(); | 1261 GenerateScriptSnapshot(); |
| 1176 } else { | 1262 } else { |
| 1177 // Lookup the library of the root script. | 1263 // Lookup the library of the root script. |
| 1178 Dart_Handle root_lib = Dart_RootLibrary(); | 1264 Dart_Handle root_lib = Dart_RootLibrary(); |
| 1179 // Import the root library into the builtin library so that we can easily | 1265 // Import the root library into the builtin library so that we can easily |
| 1180 // lookup the main entry point exported from the root library. | 1266 // lookup the main entry point exported from the root library. |
| 1181 IsolateData* isolate_data = | 1267 IsolateData* isolate_data = |
| 1182 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); | 1268 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); |
| 1183 result = Dart_LibraryImportLibrary( | 1269 result = Dart_LibraryImportLibrary( |
| 1184 isolate_data->builtin_lib(), root_lib, Dart_Null()); | 1270 isolate_data->builtin_lib(), root_lib, Dart_Null()); |
| 1185 if (has_noopt || has_gen_precompiled_snapshot) { | 1271 if (is_noopt || gen_precompiled_snapshot) { |
| 1186 // Load the embedder's portion of the VM service's Dart code so it will | 1272 // Load the embedder's portion of the VM service's Dart code so it will |
| 1187 // be included in the precompiled snapshot. | 1273 // be included in the precompiled snapshot. |
| 1188 if (!VmService::LoadForGenPrecompiled()) { | 1274 if (!VmService::LoadForGenPrecompiled()) { |
| 1189 fprintf(stderr, | 1275 fprintf(stderr, |
| 1190 "VM service loading failed: %s\n", | 1276 "VM service loading failed: %s\n", |
| 1191 VmService::GetErrorMessage()); | 1277 VmService::GetErrorMessage()); |
| 1192 fflush(stderr); | 1278 fflush(stderr); |
| 1193 exit(kErrorExitCode); | 1279 exit(kErrorExitCode); |
| 1194 } | 1280 } |
| 1195 } | 1281 } |
| 1196 | 1282 |
| 1197 if (has_compile_all) { | 1283 if (compile_all) { |
| 1198 result = Dart_CompileAll(); | 1284 result = Dart_CompileAll(); |
| 1199 CHECK_RESULT(result); | 1285 CHECK_RESULT(result); |
| 1200 } | 1286 } |
| 1201 | 1287 |
| 1202 if (has_noopt || has_gen_precompiled_snapshot) { | 1288 if (is_noopt || gen_precompiled_snapshot) { |
| 1203 Dart_QualifiedFunctionName standalone_entry_points[] = { | 1289 Dart_QualifiedFunctionName standalone_entry_points[] = { |
| 1204 { "dart:_builtin", "::", "_getMainClosure" }, | 1290 { "dart:_builtin", "::", "_getMainClosure" }, |
| 1205 { "dart:_builtin", "::", "_getPrintClosure" }, | 1291 { "dart:_builtin", "::", "_getPrintClosure" }, |
| 1206 { "dart:_builtin", "::", "_getUriBaseClosure" }, | 1292 { "dart:_builtin", "::", "_getUriBaseClosure" }, |
| 1207 { "dart:_builtin", "::", "_resolveUri" }, | 1293 { "dart:_builtin", "::", "_resolveUri" }, |
| 1208 { "dart:_builtin", "::", "_setWorkingDirectory" }, | 1294 { "dart:_builtin", "::", "_setWorkingDirectory" }, |
| 1209 { "dart:_builtin", "::", "_setPackageRoot" }, | 1295 { "dart:_builtin", "::", "_setPackageRoot" }, |
| 1210 { "dart:_builtin", "::", "_loadPackagesMap" }, | 1296 { "dart:_builtin", "::", "_loadPackagesMap" }, |
| 1211 { "dart:_builtin", "::", "_loadDataAsync" }, | 1297 { "dart:_builtin", "::", "_loadDataAsync" }, |
| 1212 { "dart:io", "::", "_makeUint8ListView" }, | 1298 { "dart:io", "::", "_makeUint8ListView" }, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1225 { "dart:io", "_ExternalBuffer", "set:data" }, | 1311 { "dart:io", "_ExternalBuffer", "set:data" }, |
| 1226 { "dart:io", "_Platform", "set:_nativeScript" }, | 1312 { "dart:io", "_Platform", "set:_nativeScript" }, |
| 1227 { "dart:io", "_ProcessStartStatus", "set:_errorCode" }, | 1313 { "dart:io", "_ProcessStartStatus", "set:_errorCode" }, |
| 1228 { "dart:io", "_ProcessStartStatus", "set:_errorMessage" }, | 1314 { "dart:io", "_ProcessStartStatus", "set:_errorMessage" }, |
| 1229 { "dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE" }, | 1315 { "dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE" }, |
| 1230 { "dart:io", "_SecureFilterImpl", "get:SIZE" }, | 1316 { "dart:io", "_SecureFilterImpl", "get:SIZE" }, |
| 1231 { "dart:vmservice_io", "::", "main" }, | 1317 { "dart:vmservice_io", "::", "main" }, |
| 1232 { NULL, NULL, NULL } // Must be terminated with NULL entries. | 1318 { NULL, NULL, NULL } // Must be terminated with NULL entries. |
| 1233 }; | 1319 }; |
| 1234 | 1320 |
| 1235 const bool reset_fields = has_gen_precompiled_snapshot; | 1321 const bool reset_fields = gen_precompiled_snapshot; |
| 1236 result = Dart_Precompile(standalone_entry_points, reset_fields); | 1322 result = Dart_Precompile(standalone_entry_points, reset_fields); |
| 1237 CHECK_RESULT(result); | 1323 CHECK_RESULT(result); |
| 1238 } | 1324 } |
| 1239 | 1325 |
| 1240 if (has_gen_precompiled_snapshot) { | 1326 if (gen_precompiled_snapshot) { |
| 1241 uint8_t* vm_isolate_buffer = NULL; | 1327 uint8_t* vm_isolate_buffer = NULL; |
| 1242 intptr_t vm_isolate_size = 0; | 1328 intptr_t vm_isolate_size = 0; |
| 1243 uint8_t* isolate_buffer = NULL; | 1329 uint8_t* isolate_buffer = NULL; |
| 1244 intptr_t isolate_size = 0; | 1330 intptr_t isolate_size = 0; |
| 1245 uint8_t* instructions_buffer = NULL; | 1331 uint8_t* instructions_buffer = NULL; |
| 1246 intptr_t instructions_size = 0; | 1332 intptr_t instructions_size = 0; |
| 1247 result = Dart_CreatePrecompiledSnapshot(&vm_isolate_buffer, | 1333 result = Dart_CreatePrecompiledSnapshot(&vm_isolate_buffer, |
| 1248 &vm_isolate_size, | 1334 &vm_isolate_size, |
| 1249 &isolate_buffer, | 1335 &isolate_buffer, |
| 1250 &isolate_size, | 1336 &isolate_size, |
| 1251 &instructions_buffer, | 1337 &instructions_buffer, |
| 1252 &instructions_size); | 1338 &instructions_size); |
| 1253 CHECK_RESULT(result); | 1339 CHECK_RESULT(result); |
| 1254 WritePrecompiledSnapshotFile(kPrecompiledVmIsolateName, | 1340 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1255 vm_isolate_buffer, | 1341 kPrecompiledVmIsolateName, |
| 1256 vm_isolate_size); | 1342 false, |
| 1257 WritePrecompiledSnapshotFile(kPrecompiledIsolateName, | 1343 vm_isolate_buffer, |
| 1258 isolate_buffer, | 1344 vm_isolate_size); |
| 1259 isolate_size); | 1345 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1260 WritePrecompiledSnapshotFile(kPrecompiledInstructionsName, | 1346 kPrecompiledIsolateName, |
| 1261 instructions_buffer, | 1347 false, |
| 1262 instructions_size); | 1348 isolate_buffer, |
| 1349 isolate_size); |
| 1350 WriteSnapshotFile(precompiled_snapshot_directory, |
| 1351 kPrecompiledInstructionsName, |
| 1352 false, |
| 1353 instructions_buffer, |
| 1354 instructions_size); |
| 1263 } else { | 1355 } else { |
| 1264 if (Dart_IsNull(root_lib)) { | 1356 if (Dart_IsNull(root_lib)) { |
| 1265 ErrorExit(kErrorExitCode, | 1357 ErrorExit(kErrorExitCode, |
| 1266 "Unable to find root library for '%s'\n", | 1358 "Unable to find root library for '%s'\n", |
| 1267 script_name); | 1359 script_name); |
| 1268 } | 1360 } |
| 1269 | 1361 |
| 1270 // The helper function _getMainClosure creates a closure for the main | 1362 // The helper function _getMainClosure creates a closure for the main |
| 1271 // entry point which is either explicitly or implictly exported from the | 1363 // entry point which is either explicitly or implictly exported from the |
| 1272 // root library. | 1364 // root library. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1285 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate")); | 1377 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate")); |
| 1286 result = Dart_Invoke(isolate_lib, | 1378 result = Dart_Invoke(isolate_lib, |
| 1287 Dart_NewStringFromCString("_startMainIsolate"), | 1379 Dart_NewStringFromCString("_startMainIsolate"), |
| 1288 kNumIsolateArgs, isolate_args); | 1380 kNumIsolateArgs, isolate_args); |
| 1289 CHECK_RESULT(result); | 1381 CHECK_RESULT(result); |
| 1290 | 1382 |
| 1291 // Keep handling messages until the last active receive port is closed. | 1383 // Keep handling messages until the last active receive port is closed. |
| 1292 result = Dart_RunLoop(); | 1384 result = Dart_RunLoop(); |
| 1293 CHECK_RESULT(result); | 1385 CHECK_RESULT(result); |
| 1294 | 1386 |
| 1295 // Generate a script snapshot after execution if specified. | 1387 // Generate a full snapshot after execution if specified. |
| 1296 if (generate_script_snapshot_after_run) { | 1388 if (generate_full_snapshot_after_run) { |
| 1297 GenerateScriptSnapshot(); | 1389 GenerateFullSnapshot(); |
| 1298 } | 1390 } |
| 1299 } | 1391 } |
| 1300 } | 1392 } |
| 1301 | 1393 |
| 1302 Dart_ExitScope(); | 1394 Dart_ExitScope(); |
| 1303 // Shutdown the isolate. | 1395 // Shutdown the isolate. |
| 1304 Dart_ShutdownIsolate(); | 1396 Dart_ShutdownIsolate(); |
| 1305 | 1397 |
| 1306 // No restart. | 1398 // No restart. |
| 1307 return false; | 1399 return false; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1411 bool argv_converted = ShellUtils::GetUtf8Argv(argc, argv); | 1503 bool argv_converted = ShellUtils::GetUtf8Argv(argc, argv); |
| 1412 | 1504 |
| 1413 // Parse command line arguments. | 1505 // Parse command line arguments. |
| 1414 if (ParseArguments(argc, | 1506 if (ParseArguments(argc, |
| 1415 argv, | 1507 argv, |
| 1416 &vm_options, | 1508 &vm_options, |
| 1417 &script_name, | 1509 &script_name, |
| 1418 &dart_options, | 1510 &dart_options, |
| 1419 &print_flags_seen, | 1511 &print_flags_seen, |
| 1420 &verbose_debug_seen) < 0) { | 1512 &verbose_debug_seen) < 0) { |
| 1421 if (has_help_option) { | 1513 if (help_option) { |
| 1422 PrintUsage(); | 1514 PrintUsage(); |
| 1423 Platform::Exit(0); | 1515 Platform::Exit(0); |
| 1424 } else if (has_version_option) { | 1516 } else if (version_option) { |
| 1425 PrintVersion(); | 1517 PrintVersion(); |
| 1426 Platform::Exit(0); | 1518 Platform::Exit(0); |
| 1427 } else if (print_flags_seen) { | 1519 } else if (print_flags_seen) { |
| 1428 // Will set the VM flags, print them out and then we exit as no | 1520 // Will set the VM flags, print them out and then we exit as no |
| 1429 // script was specified on the command line. | 1521 // script was specified on the command line. |
| 1430 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1522 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
| 1431 Platform::Exit(0); | 1523 Platform::Exit(0); |
| 1432 } else { | 1524 } else { |
| 1433 PrintUsage(); | 1525 PrintUsage(); |
| 1434 Platform::Exit(kErrorExitCode); | 1526 Platform::Exit(kErrorExitCode); |
| 1435 } | 1527 } |
| 1436 } | 1528 } |
| 1437 | 1529 |
| 1438 Thread::InitOnce(); | 1530 Thread::InitOnce(); |
| 1439 | 1531 |
| 1440 if (!DartUtils::SetOriginalWorkingDirectory()) { | 1532 if (!DartUtils::SetOriginalWorkingDirectory()) { |
| 1441 OSError err; | 1533 OSError err; |
| 1442 fprintf(stderr, "Error determining current directory: %s\n", err.message()); | 1534 fprintf(stderr, "Error determining current directory: %s\n", err.message()); |
| 1443 fflush(stderr); | 1535 fflush(stderr); |
| 1444 Platform::Exit(kErrorExitCode); | 1536 Platform::Exit(kErrorExitCode); |
| 1445 } | 1537 } |
| 1446 | 1538 |
| 1447 if (generate_script_snapshot) { | 1539 if (generate_script_snapshot || generate_full_snapshot_after_run) { |
| 1448 vm_options.AddArgument("--load_deferred_eagerly"); | 1540 vm_options.AddArgument("--load_deferred_eagerly"); |
| 1449 } | 1541 } |
| 1450 | 1542 |
| 1451 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) | 1543 #if defined(DART_PRECOMPILER) && !defined(DART_NO_SNAPSHOT) |
| 1452 // Always set --precompilation with dart_noopt. | 1544 // Always set --precompilation with dart_noopt. |
| 1453 ASSERT(!has_gen_precompiled_snapshot && !has_run_precompiled_snapshot); | 1545 ASSERT(!gen_precompiled_snapshot && !run_precompiled_snapshot); |
| 1454 vm_options.AddArgument("--precompilation"); | 1546 vm_options.AddArgument("--precompilation"); |
| 1455 #endif | 1547 #endif |
| 1456 | 1548 |
| 1457 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1549 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
| 1458 | 1550 |
| 1459 // Start event handler. | 1551 // Start event handler. |
| 1460 TimerUtils::InitOnce(); | 1552 TimerUtils::InitOnce(); |
| 1461 EventHandler::Start(); | 1553 EventHandler::Start(); |
| 1462 | 1554 |
| 1463 const uint8_t* instructions_snapshot = NULL; | 1555 const uint8_t* instructions_snapshot = NULL; |
| 1464 if (has_run_precompiled_snapshot) { | 1556 if (run_precompiled_snapshot) { |
| 1465 instructions_snapshot = reinterpret_cast<const uint8_t*>( | 1557 instructions_snapshot = reinterpret_cast<const uint8_t*>( |
| 1466 LoadLibrarySymbol(kPrecompiledLibraryName, kPrecompiledSymbolName)); | 1558 LoadLibrarySymbol(kPrecompiledLibraryName, kPrecompiledSymbolName)); |
| 1467 ReadPrecompiledSnapshotFile(kPrecompiledVmIsolateName, | 1559 ReadSnapshotFile(precompiled_snapshot_directory, |
| 1468 &vm_isolate_snapshot_buffer); | 1560 kPrecompiledVmIsolateName, |
| 1469 ReadPrecompiledSnapshotFile(kPrecompiledIsolateName, | 1561 &vm_isolate_snapshot_buffer); |
| 1470 &isolate_snapshot_buffer); | 1562 ReadSnapshotFile(precompiled_snapshot_directory, |
| 1563 kPrecompiledIsolateName, |
| 1564 &isolate_snapshot_buffer); |
| 1565 } else if (run_full_snapshot) { |
| 1566 char* vm_snapshot_fname; |
| 1567 char* isolate_snapshot_fname; |
| 1568 |
| 1569 // Compute file names. |
| 1570 ComputeSnapshotFilenames(snapshot_filename, |
| 1571 &vm_snapshot_fname, |
| 1572 &isolate_snapshot_fname); |
| 1573 |
| 1574 ReadSnapshotFile(NULL, vm_snapshot_fname, &vm_isolate_snapshot_buffer); |
| 1575 ReadSnapshotFile(NULL, isolate_snapshot_fname, &isolate_snapshot_buffer); |
| 1576 delete vm_snapshot_fname; |
| 1577 delete isolate_snapshot_fname; |
| 1471 } | 1578 } |
| 1472 | 1579 |
| 1473 // Initialize the Dart VM. | 1580 // Initialize the Dart VM. |
| 1474 char* error = Dart_Initialize( | 1581 char* error = Dart_Initialize( |
| 1475 vm_isolate_snapshot_buffer, instructions_snapshot, | 1582 vm_isolate_snapshot_buffer, instructions_snapshot, |
| 1476 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, | 1583 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, |
| 1477 DartUtils::OpenFile, | 1584 DartUtils::OpenFile, |
| 1478 DartUtils::ReadFile, | 1585 DartUtils::ReadFile, |
| 1479 DartUtils::WriteFile, | 1586 DartUtils::WriteFile, |
| 1480 DartUtils::CloseFile, | 1587 DartUtils::CloseFile, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1531 Platform::Exit(Process::GlobalExitCode()); | 1638 Platform::Exit(Process::GlobalExitCode()); |
| 1532 } | 1639 } |
| 1533 | 1640 |
| 1534 } // namespace bin | 1641 } // namespace bin |
| 1535 } // namespace dart | 1642 } // namespace dart |
| 1536 | 1643 |
| 1537 int main(int argc, char** argv) { | 1644 int main(int argc, char** argv) { |
| 1538 dart::bin::main(argc, argv); | 1645 dart::bin::main(argc, argv); |
| 1539 UNREACHABLE(); | 1646 UNREACHABLE(); |
| 1540 } | 1647 } |
| OLD | NEW |