| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 commandline_packages_file = arg; | 216 commandline_packages_file = arg; |
| 217 return true; | 217 return true; |
| 218 } | 218 } |
| 219 | 219 |
| 220 | 220 |
| 221 static void* GetHashmapKeyFromString(char* key) { | 221 static void* GetHashmapKeyFromString(char* key) { |
| 222 return reinterpret_cast<void*>(key); | 222 return reinterpret_cast<void*>(key); |
| 223 } | 223 } |
| 224 | 224 |
| 225 | 225 |
| 226 static bool ExtractPortAndIP(const char *option_value, | 226 static bool ExtractPortAndIP(const char* option_value, |
| 227 int *out_port, | 227 int* out_port, |
| 228 const char **out_ip, | 228 const char** out_ip, |
| 229 int default_port, | 229 int default_port, |
| 230 const char *default_ip) { | 230 const char* default_ip) { |
| 231 // [option_value] has to be one of the following formats: | 231 // [option_value] has to be one of the following formats: |
| 232 // - "" | 232 // - "" |
| 233 // - ":8181" | 233 // - ":8181" |
| 234 // - "=8181" | 234 // - "=8181" |
| 235 // - ":8181/192.168.0.1" | 235 // - ":8181/192.168.0.1" |
| 236 // - "=8181/192.168.0.1" | 236 // - "=8181/192.168.0.1" |
| 237 | 237 |
| 238 if (*option_value== '\0') { | 238 if (*option_value == '\0') { |
| 239 *out_ip = default_ip; | 239 *out_ip = default_ip; |
| 240 *out_port = default_port; | 240 *out_port = default_port; |
| 241 return true; | 241 return true; |
| 242 } | 242 } |
| 243 | 243 |
| 244 if ((*option_value != '=') && (*option_value != ':')) { | 244 if ((*option_value != '=') && (*option_value != ':')) { |
| 245 return false; | 245 return false; |
| 246 } | 246 } |
| 247 | 247 |
| 248 int port = atoi(option_value + 1); | 248 int port = atoi(option_value + 1); |
| 249 const char *slash = strstr(option_value, "/"); | 249 const char* slash = strstr(option_value, "/"); |
| 250 if (slash == NULL) { | 250 if (slash == NULL) { |
| 251 *out_ip = default_ip; | 251 *out_ip = default_ip; |
| 252 *out_port = port; | 252 *out_port = port; |
| 253 return true; | 253 return true; |
| 254 } | 254 } |
| 255 | 255 |
| 256 int _, n; | 256 int _, n; |
| 257 if (sscanf(option_value + 1, "%d/%d.%d.%d.%d%n", // NOLINT(runtime/printf) | 257 if (sscanf(option_value + 1, "%d/%d.%d.%d.%d%n", // NOLINT(runtime/printf) |
| 258 &_, &_, &_, &_, &_, &n)) { | 258 &_, &_, &_, &_, &_, &n)) { |
| 259 if (option_value[1 + n] == '\0') { | 259 if (option_value[1 + n] == '\0') { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 290 return true; | 290 return true; |
| 291 } | 291 } |
| 292 // Split name=value into name and value. | 292 // Split name=value into name and value. |
| 293 name = reinterpret_cast<char*>(malloc(name_len + 1)); | 293 name = reinterpret_cast<char*>(malloc(name_len + 1)); |
| 294 strncpy(name, arg, name_len); | 294 strncpy(name, arg, name_len); |
| 295 name[name_len] = '\0'; | 295 name[name_len] = '\0'; |
| 296 value = strdup(equals_pos + 1); | 296 value = strdup(equals_pos + 1); |
| 297 if (environment == NULL) { | 297 if (environment == NULL) { |
| 298 environment = new HashMap(&HashMap::SameStringValue, 4); | 298 environment = new HashMap(&HashMap::SameStringValue, 4); |
| 299 } | 299 } |
| 300 HashMap::Entry* entry = environment->Lookup( | 300 HashMap::Entry* entry = environment->Lookup(GetHashmapKeyFromString(name), |
| 301 GetHashmapKeyFromString(name), HashMap::StringHash(name), true); | 301 HashMap::StringHash(name), true); |
| 302 ASSERT(entry != NULL); // Lookup adds an entry if key not found. | 302 ASSERT(entry != NULL); // Lookup adds an entry if key not found. |
| 303 if (entry->value != NULL) { | 303 if (entry->value != NULL) { |
| 304 free(name); | 304 free(name); |
| 305 free(entry->value); | 305 free(entry->value); |
| 306 } | 306 } |
| 307 entry->value = value; | 307 entry->value = value; |
| 308 return true; | 308 return true; |
| 309 } | 309 } |
| 310 | 310 |
| 311 | 311 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 if (strcmp(kind, "script") == 0) { | 357 if (strcmp(kind, "script") == 0) { |
| 358 gen_snapshot_kind = kScript; | 358 gen_snapshot_kind = kScript; |
| 359 return true; | 359 return true; |
| 360 } else if (strcmp(kind, "app-aot") == 0) { | 360 } else if (strcmp(kind, "app-aot") == 0) { |
| 361 gen_snapshot_kind = kAppAOT; | 361 gen_snapshot_kind = kAppAOT; |
| 362 return true; | 362 return true; |
| 363 } else if (strcmp(kind, "app-jit") == 0) { | 363 } else if (strcmp(kind, "app-jit") == 0) { |
| 364 gen_snapshot_kind = kAppJIT; | 364 gen_snapshot_kind = kAppJIT; |
| 365 return true; | 365 return true; |
| 366 } | 366 } |
| 367 Log::PrintErr("Unrecognized snapshot kind: '%s'\nValid kinds are: " | 367 Log::PrintErr( |
| 368 "script, app-aot, app-jit\n", kind); | 368 "Unrecognized snapshot kind: '%s'\nValid kinds are: " |
| 369 "script, app-aot, app-jit\n", |
| 370 kind); |
| 369 return false; | 371 return false; |
| 370 } | 372 } |
| 371 | 373 |
| 372 | 374 |
| 373 static bool ProcessEnableVmServiceOption(const char* option_value, | 375 static bool ProcessEnableVmServiceOption(const char* option_value, |
| 374 CommandLineOptions* vm_options) { | 376 CommandLineOptions* vm_options) { |
| 375 ASSERT(option_value != NULL); | 377 ASSERT(option_value != NULL); |
| 376 | 378 |
| 377 if (!ExtractPortAndIP(option_value, | 379 if (!ExtractPortAndIP(option_value, &vm_service_server_port, |
| 378 &vm_service_server_port, | 380 &vm_service_server_ip, DEFAULT_VM_SERVICE_SERVER_PORT, |
| 379 &vm_service_server_ip, | |
| 380 DEFAULT_VM_SERVICE_SERVER_PORT, | |
| 381 DEFAULT_VM_SERVICE_SERVER_IP)) { | 381 DEFAULT_VM_SERVICE_SERVER_IP)) { |
| 382 Log::PrintErr("unrecognized --enable-vm-service option syntax. " | 382 Log::PrintErr( |
| 383 "Use --enable-vm-service[=<port number>[/<IPv4 address>]]\n"); | 383 "unrecognized --enable-vm-service option syntax. " |
| 384 "Use --enable-vm-service[=<port number>[/<IPv4 address>]]\n"); |
| 384 return false; | 385 return false; |
| 385 } | 386 } |
| 386 | 387 |
| 387 return true; | 388 return true; |
| 388 } | 389 } |
| 389 | 390 |
| 390 | 391 |
| 391 static bool ProcessDisableServiceOriginCheckOption( | 392 static bool ProcessDisableServiceOriginCheckOption( |
| 392 const char* option_value, CommandLineOptions* vm_options) { | 393 const char* option_value, |
| 394 CommandLineOptions* vm_options) { |
| 393 ASSERT(option_value != NULL); | 395 ASSERT(option_value != NULL); |
| 394 Log::PrintErr("WARNING: You are running with the service protocol in an " | 396 Log::PrintErr( |
| 395 "insecure mode.\n"); | 397 "WARNING: You are running with the service protocol in an " |
| 398 "insecure mode.\n"); |
| 396 vm_service_dev_mode = true; | 399 vm_service_dev_mode = true; |
| 397 return true; | 400 return true; |
| 398 } | 401 } |
| 399 | 402 |
| 400 | 403 |
| 401 static bool ProcessObserveOption(const char* option_value, | 404 static bool ProcessObserveOption(const char* option_value, |
| 402 CommandLineOptions* vm_options) { | 405 CommandLineOptions* vm_options) { |
| 403 ASSERT(option_value != NULL); | 406 ASSERT(option_value != NULL); |
| 404 | 407 |
| 405 if (!ExtractPortAndIP(option_value, | 408 if (!ExtractPortAndIP(option_value, &vm_service_server_port, |
| 406 &vm_service_server_port, | 409 &vm_service_server_ip, DEFAULT_VM_SERVICE_SERVER_PORT, |
| 407 &vm_service_server_ip, | |
| 408 DEFAULT_VM_SERVICE_SERVER_PORT, | |
| 409 DEFAULT_VM_SERVICE_SERVER_IP)) { | 410 DEFAULT_VM_SERVICE_SERVER_IP)) { |
| 410 Log::PrintErr("unrecognized --observe option syntax. " | 411 Log::PrintErr( |
| 411 "Use --observe[=<port number>[/<IPv4 address>]]\n"); | 412 "unrecognized --observe option syntax. " |
| 413 "Use --observe[=<port number>[/<IPv4 address>]]\n"); |
| 412 return false; | 414 return false; |
| 413 } | 415 } |
| 414 | 416 |
| 415 // These options should also be documented in the help message. | 417 // These options should also be documented in the help message. |
| 416 vm_options->AddArgument("--pause-isolates-on-exit"); | 418 vm_options->AddArgument("--pause-isolates-on-exit"); |
| 417 vm_options->AddArgument("--pause-isolates-on-unhandled-exceptions"); | 419 vm_options->AddArgument("--pause-isolates-on-unhandled-exceptions"); |
| 418 vm_options->AddArgument("--warn-on-pause-with-no-debugger"); | 420 vm_options->AddArgument("--warn-on-pause-with-no-debugger"); |
| 419 return true; | 421 return true; |
| 420 } | 422 } |
| 421 | 423 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 445 // Reload less frequently as time goes on. | 447 // Reload less frequently as time goes on. |
| 446 vm_options->AddArgument("--reload_every_back_off"); | 448 vm_options->AddArgument("--reload_every_back_off"); |
| 447 // Ensure that every isolate has reloaded once before exiting. | 449 // Ensure that every isolate has reloaded once before exiting. |
| 448 vm_options->AddArgument("--check_reloaded"); | 450 vm_options->AddArgument("--check_reloaded"); |
| 449 | 451 |
| 450 return true; | 452 return true; |
| 451 } | 453 } |
| 452 | 454 |
| 453 | 455 |
| 454 static bool ProcessHotReloadRollbackTestModeOption( | 456 static bool ProcessHotReloadRollbackTestModeOption( |
| 455 const char* arg, | 457 const char* arg, |
| 456 CommandLineOptions* vm_options) { | 458 CommandLineOptions* vm_options) { |
| 457 // Identity reload. | 459 // Identity reload. |
| 458 vm_options->AddArgument("--identity_reload"); | 460 vm_options->AddArgument("--identity_reload"); |
| 459 // Start reloading quickly. | 461 // Start reloading quickly. |
| 460 vm_options->AddArgument("--reload_every=4"); | 462 vm_options->AddArgument("--reload_every=4"); |
| 461 // Reload from optimized and unoptimized code. | 463 // Reload from optimized and unoptimized code. |
| 462 vm_options->AddArgument("--reload_every_optimized=false"); | 464 vm_options->AddArgument("--reload_every_optimized=false"); |
| 463 // Reload less frequently as time goes on. | 465 // Reload less frequently as time goes on. |
| 464 vm_options->AddArgument("--reload_every_back_off"); | 466 vm_options->AddArgument("--reload_every_back_off"); |
| 465 // Ensure that every isolate has reloaded once before exiting. | 467 // Ensure that every isolate has reloaded once before exiting. |
| 466 vm_options->AddArgument("--check_reloaded"); | 468 vm_options->AddArgument("--check_reloaded"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 493 extern const char* commandline_root_certs_file; | 495 extern const char* commandline_root_certs_file; |
| 494 extern const char* commandline_root_certs_cache; | 496 extern const char* commandline_root_certs_cache; |
| 495 | 497 |
| 496 static bool ProcessRootCertsFileOption(const char* arg, | 498 static bool ProcessRootCertsFileOption(const char* arg, |
| 497 CommandLineOptions* vm_options) { | 499 CommandLineOptions* vm_options) { |
| 498 ASSERT(arg != NULL); | 500 ASSERT(arg != NULL); |
| 499 if (*arg == '-') { | 501 if (*arg == '-') { |
| 500 return false; | 502 return false; |
| 501 } | 503 } |
| 502 if (commandline_root_certs_cache != NULL) { | 504 if (commandline_root_certs_cache != NULL) { |
| 503 Log::PrintErr("Only one of --root-certs-file and --root-certs-cache " | 505 Log::PrintErr( |
| 504 "may be specified"); | 506 "Only one of --root-certs-file and --root-certs-cache " |
| 507 "may be specified"); |
| 505 return false; | 508 return false; |
| 506 } | 509 } |
| 507 commandline_root_certs_file = arg; | 510 commandline_root_certs_file = arg; |
| 508 return true; | 511 return true; |
| 509 } | 512 } |
| 510 | 513 |
| 511 | 514 |
| 512 static bool ProcessRootCertsCacheOption(const char* arg, | 515 static bool ProcessRootCertsCacheOption(const char* arg, |
| 513 CommandLineOptions* vm_options) { | 516 CommandLineOptions* vm_options) { |
| 514 ASSERT(arg != NULL); | 517 ASSERT(arg != NULL); |
| 515 if (*arg == '-') { | 518 if (*arg == '-') { |
| 516 return false; | 519 return false; |
| 517 } | 520 } |
| 518 if (commandline_root_certs_file != NULL) { | 521 if (commandline_root_certs_file != NULL) { |
| 519 Log::PrintErr("Only one of --root-certs-file and --root-certs-cache " | 522 Log::PrintErr( |
| 520 "may be specified"); | 523 "Only one of --root-certs-file and --root-certs-cache " |
| 524 "may be specified"); |
| 521 return false; | 525 return false; |
| 522 } | 526 } |
| 523 commandline_root_certs_cache = arg; | 527 commandline_root_certs_cache = arg; |
| 524 return true; | 528 return true; |
| 525 } | 529 } |
| 526 #endif // !defined(TARGET_OS_MACOS) | 530 #endif // !defined(TARGET_OS_MACOS) |
| 527 | 531 |
| 528 | 532 |
| 529 static struct { | 533 static struct { |
| 530 const char* option_name; | 534 const char* option_name; |
| 531 bool (*process)(const char* option, CommandLineOptions* vm_options); | 535 bool (*process)(const char* option, CommandLineOptions* vm_options); |
| 532 } main_options[] = { | 536 } main_options[] = { |
| 533 // Standard options shared with dart2js. | 537 // Standard options shared with dart2js. |
| 534 { "-D", ProcessEnvironmentOption }, | 538 {"-D", ProcessEnvironmentOption}, |
| 535 { "-h", ProcessHelpOption }, | 539 {"-h", ProcessHelpOption}, |
| 536 { "--help", ProcessHelpOption }, | 540 {"--help", ProcessHelpOption}, |
| 537 { "--packages=", ProcessPackagesOption }, | 541 {"--packages=", ProcessPackagesOption}, |
| 538 { "--package-root=", ProcessPackageRootOption }, | 542 {"--package-root=", ProcessPackageRootOption}, |
| 539 { "-v", ProcessVerboseOption }, | 543 {"-v", ProcessVerboseOption}, |
| 540 { "--verbose", ProcessVerboseOption }, | 544 {"--verbose", ProcessVerboseOption}, |
| 541 { "--version", ProcessVersionOption }, | 545 {"--version", ProcessVersionOption}, |
| 542 | 546 |
| 543 // VM specific options to the standalone dart program. | 547 // VM specific options to the standalone dart program. |
| 544 { "--compile_all", ProcessCompileAllOption }, | 548 {"--compile_all", ProcessCompileAllOption}, |
| 545 { "--parse_all", ProcessParseAllOption }, | 549 {"--parse_all", ProcessParseAllOption}, |
| 546 { "--enable-vm-service", ProcessEnableVmServiceOption }, | 550 {"--enable-vm-service", ProcessEnableVmServiceOption}, |
| 547 { "--disable-service-origin-check", ProcessDisableServiceOriginCheckOption }, | 551 {"--disable-service-origin-check", ProcessDisableServiceOriginCheckOption}, |
| 548 { "--observe", ProcessObserveOption }, | 552 {"--observe", ProcessObserveOption}, |
| 549 { "--snapshot=", ProcessSnapshotFilenameOption }, | 553 {"--snapshot=", ProcessSnapshotFilenameOption}, |
| 550 { "--snapshot-kind=", ProcessSnapshotKindOption }, | 554 {"--snapshot-kind=", ProcessSnapshotKindOption}, |
| 551 { "--use-blobs", ProcessUseBlobsOption }, | 555 {"--use-blobs", ProcessUseBlobsOption}, |
| 552 { "--trace-loading", ProcessTraceLoadingOption }, | 556 {"--trace-loading", ProcessTraceLoadingOption}, |
| 553 { "--hot-reload-test-mode", ProcessHotReloadTestModeOption }, | 557 {"--hot-reload-test-mode", ProcessHotReloadTestModeOption}, |
| 554 { "--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption }, | 558 {"--hot-reload-rollback-test-mode", ProcessHotReloadRollbackTestModeOption}, |
| 555 { "--short_socket_read", ProcessShortSocketReadOption }, | 559 {"--short_socket_read", ProcessShortSocketReadOption}, |
| 556 { "--short_socket_write", ProcessShortSocketWriteOption }, | 560 {"--short_socket_write", ProcessShortSocketWriteOption}, |
| 557 #if !defined(TARGET_OS_MACOS) | 561 #if !defined(TARGET_OS_MACOS) |
| 558 { "--root-certs-file=", ProcessRootCertsFileOption }, | 562 {"--root-certs-file=", ProcessRootCertsFileOption}, |
| 559 { "--root-certs-cache=", ProcessRootCertsCacheOption }, | 563 {"--root-certs-cache=", ProcessRootCertsCacheOption}, |
| 560 #endif // !defined(TARGET_OS_MACOS) | 564 #endif // !defined(TARGET_OS_MACOS) |
| 561 { NULL, NULL } | 565 {NULL, NULL}}; |
| 562 }; | |
| 563 | 566 |
| 564 | 567 |
| 565 static bool ProcessMainOptions(const char* option, | 568 static bool ProcessMainOptions(const char* option, |
| 566 CommandLineOptions* vm_options) { | 569 CommandLineOptions* vm_options) { |
| 567 int i = 0; | 570 int i = 0; |
| 568 const char* name = main_options[0].option_name; | 571 const char* name = main_options[0].option_name; |
| 569 int option_length = strlen(option); | 572 int option_length = strlen(option); |
| 570 while (name != NULL) { | 573 while (name != NULL) { |
| 571 int length = strlen(name); | 574 int length = strlen(name); |
| 572 if ((option_length >= length) && (strncmp(option, name, length) == 0)) { | 575 if ((option_length >= length) && (strncmp(option, name, length) == 0)) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 i++; | 608 i++; |
| 606 } else { | 609 } else { |
| 607 // Check if this flag is a potentially valid VM flag. | 610 // Check if this flag is a potentially valid VM flag. |
| 608 const char* kChecked = "-c"; | 611 const char* kChecked = "-c"; |
| 609 const char* kPackageRoot = "-p"; | 612 const char* kPackageRoot = "-p"; |
| 610 if (strncmp(argv[i], kPackageRoot, strlen(kPackageRoot)) == 0) { | 613 if (strncmp(argv[i], kPackageRoot, strlen(kPackageRoot)) == 0) { |
| 611 if (!ProcessPackageRootOption(argv[i] + strlen(kPackageRoot), | 614 if (!ProcessPackageRootOption(argv[i] + strlen(kPackageRoot), |
| 612 vm_options)) { | 615 vm_options)) { |
| 613 i++; | 616 i++; |
| 614 if ((argv[i] == NULL) || | 617 if ((argv[i] == NULL) || |
| 615 !ProcessPackageRootOption(argv[i], vm_options)) { | 618 !ProcessPackageRootOption(argv[i], vm_options)) { |
| 616 Log::PrintErr("Invalid option specification : '%s'\n", argv[i - 1]); | 619 Log::PrintErr("Invalid option specification : '%s'\n", argv[i - 1]); |
| 617 i++; | 620 i++; |
| 618 break; | 621 break; |
| 619 } | 622 } |
| 620 } | 623 } |
| 621 i++; | 624 i++; |
| 622 continue; // '-p' is not a VM flag so don't add to vm options. | 625 continue; // '-p' is not a VM flag so don't add to vm options. |
| 623 } else if (strncmp(argv[i], kChecked, strlen(kChecked)) == 0) { | 626 } else if (strncmp(argv[i], kChecked, strlen(kChecked)) == 0) { |
| 624 vm_options->AddArgument("--checked"); | 627 vm_options->AddArgument("--checked"); |
| 625 i++; | 628 i++; |
| 626 continue; // '-c' is not a VM flag so don't add to vm options. | 629 continue; // '-c' is not a VM flag so don't add to vm options. |
| 627 } else if (!IsValidFlag(argv[i], kPrefix, kPrefixLen)) { | 630 } else if (!IsValidFlag(argv[i], kPrefix, kPrefixLen)) { |
| 628 break; | 631 break; |
| 629 } | 632 } |
| 630 // The following two flags are processed by both the embedder and | 633 // The following two flags are processed by both the embedder and |
| 631 // the VM. | 634 // the VM. |
| 632 const char* kPrintFlags1 = "--print-flags"; | 635 const char* kPrintFlags1 = "--print-flags"; |
| 633 const char* kPrintFlags2 = "--print_flags"; | 636 const char* kPrintFlags2 = "--print_flags"; |
| 634 const char* kVerboseDebug1 = "--verbose_debug"; | 637 const char* kVerboseDebug1 = "--verbose_debug"; |
| 635 const char* kVerboseDebug2 = "--verbose-debug"; | 638 const char* kVerboseDebug2 = "--verbose-debug"; |
| 636 if ((strncmp(argv[i], kPrintFlags1, strlen(kPrintFlags1)) == 0) || | 639 if ((strncmp(argv[i], kPrintFlags1, strlen(kPrintFlags1)) == 0) || |
| 637 (strncmp(argv[i], kPrintFlags2, strlen(kPrintFlags2)) == 0)) { | 640 (strncmp(argv[i], kPrintFlags2, strlen(kPrintFlags2)) == 0)) { |
| 638 *print_flags_seen = true; | 641 *print_flags_seen = true; |
| 639 } else if ((strncmp(argv[i], | 642 } else if ((strncmp(argv[i], kVerboseDebug1, strlen(kVerboseDebug1)) == |
| 640 kVerboseDebug1, | 643 0) || |
| 641 strlen(kVerboseDebug1)) == 0) || | 644 (strncmp(argv[i], kVerboseDebug2, strlen(kVerboseDebug2)) == |
| 642 (strncmp(argv[i], | 645 0)) { |
| 643 kVerboseDebug2, | |
| 644 strlen(kVerboseDebug2)) == 0)) { | |
| 645 *verbose_debug_seen = true; | 646 *verbose_debug_seen = true; |
| 646 } | 647 } |
| 647 vm_options->AddArgument(argv[i]); | 648 vm_options->AddArgument(argv[i]); |
| 648 i++; | 649 i++; |
| 649 } | 650 } |
| 650 } | 651 } |
| 651 | 652 |
| 652 // The arguments to the VM are at positions 1 through i-1 in argv. | 653 // The arguments to the VM are at positions 1 through i-1 in argv. |
| 653 Platform::SetExecutableArguments(i, argv); | 654 Platform::SetExecutableArguments(i, argv); |
| 654 | 655 |
| 655 // Get the script name. | 656 // Get the script name. |
| 656 if (i < argc) { | 657 if (i < argc) { |
| 657 *script_name = argv[i]; | 658 *script_name = argv[i]; |
| 658 i++; | 659 i++; |
| 659 } else { | 660 } else { |
| 660 return -1; | 661 return -1; |
| 661 } | 662 } |
| 662 | 663 |
| 663 // Parse out options to be passed to dart main. | 664 // Parse out options to be passed to dart main. |
| 664 while (i < argc) { | 665 while (i < argc) { |
| 665 dart_options->AddArgument(argv[i]); | 666 dart_options->AddArgument(argv[i]); |
| 666 i++; | 667 i++; |
| 667 } | 668 } |
| 668 | 669 |
| 669 // Verify consistency of arguments. | 670 // Verify consistency of arguments. |
| 670 if ((commandline_package_root != NULL) && | 671 if ((commandline_package_root != NULL) && |
| 671 (commandline_packages_file != NULL)) { | 672 (commandline_packages_file != NULL)) { |
| 672 Log::PrintErr("Specifying both a packages directory and a packages " | 673 Log::PrintErr( |
| 673 "file is invalid.\n"); | 674 "Specifying both a packages directory and a packages " |
| 675 "file is invalid.\n"); |
| 674 return -1; | 676 return -1; |
| 675 } | 677 } |
| 676 if ((commandline_package_root != NULL) && | 678 if ((commandline_package_root != NULL) && |
| 677 (strlen(commandline_package_root) == 0)) { | 679 (strlen(commandline_package_root) == 0)) { |
| 678 Log::PrintErr("Empty package root specified.\n"); | 680 Log::PrintErr("Empty package root specified.\n"); |
| 679 return -1; | 681 return -1; |
| 680 } | 682 } |
| 681 if ((commandline_packages_file != NULL) && | 683 if ((commandline_packages_file != NULL) && |
| 682 (strlen(commandline_packages_file) == 0)) { | 684 (strlen(commandline_packages_file) == 0)) { |
| 683 Log::PrintErr("Empty package file name specified.\n"); | 685 Log::PrintErr("Empty package file name specified.\n"); |
| 684 return -1; | 686 return -1; |
| 685 } | 687 } |
| 686 if (is_noopt && gen_snapshot_kind != kNone) { | 688 if (is_noopt && gen_snapshot_kind != kNone) { |
| 687 Log::PrintErr("Generating a snapshot with dart_noopt is invalid.\n"); | 689 Log::PrintErr("Generating a snapshot with dart_noopt is invalid.\n"); |
| 688 return -1; | 690 return -1; |
| 689 } | 691 } |
| 690 if ((gen_snapshot_kind != kNone) && (snapshot_filename == NULL)) { | 692 if ((gen_snapshot_kind != kNone) && (snapshot_filename == NULL)) { |
| 691 Log::PrintErr("Generating a snapshot requires a filename (--snapshot).\n"); | 693 Log::PrintErr("Generating a snapshot requires a filename (--snapshot).\n"); |
| 692 return -1; | 694 return -1; |
| 693 } | 695 } |
| 694 if ((gen_snapshot_kind != kNone) && run_app_snapshot) { | 696 if ((gen_snapshot_kind != kNone) && run_app_snapshot) { |
| 695 Log::PrintErr("Specifying an option to generate a snapshot and" | 697 Log::PrintErr( |
| 696 " run using a snapshot is invalid.\n"); | 698 "Specifying an option to generate a snapshot and" |
| 699 " run using a snapshot is invalid.\n"); |
| 697 return -1; | 700 return -1; |
| 698 } | 701 } |
| 699 | 702 |
| 700 return 0; | 703 return 0; |
| 701 } | 704 } |
| 702 | 705 |
| 703 | 706 |
| 704 static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) { | 707 static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) { |
| 705 int options_count = options->count(); | 708 int options_count = options->count(); |
| 706 Dart_Handle dart_arguments = Dart_NewList(options_count); | 709 Dart_Handle dart_arguments = Dart_NewList(options_count); |
| 707 if (Dart_IsError(dart_arguments)) { | 710 if (Dart_IsError(dart_arguments)) { |
| 708 return dart_arguments; | 711 return dart_arguments; |
| 709 } | 712 } |
| 710 for (int i = 0; i < options_count; i++) { | 713 for (int i = 0; i < options_count; i++) { |
| 711 Dart_Handle argument_value = | 714 Dart_Handle argument_value = DartUtils::NewString(options->GetArgument(i)); |
| 712 DartUtils::NewString(options->GetArgument(i)); | |
| 713 if (Dart_IsError(argument_value)) { | 715 if (Dart_IsError(argument_value)) { |
| 714 return argument_value; | 716 return argument_value; |
| 715 } | 717 } |
| 716 Dart_Handle result = Dart_ListSetAt(dart_arguments, i, argument_value); | 718 Dart_Handle result = Dart_ListSetAt(dart_arguments, i, argument_value); |
| 717 if (Dart_IsError(result)) { | 719 if (Dart_IsError(result)) { |
| 718 return result; | 720 return result; |
| 719 } | 721 } |
| 720 } | 722 } |
| 721 return dart_arguments; | 723 return dart_arguments; |
| 722 } | 724 } |
| 723 | 725 |
| 724 | 726 |
| 725 static Dart_Handle EnvironmentCallback(Dart_Handle name) { | 727 static Dart_Handle EnvironmentCallback(Dart_Handle name) { |
| 726 uint8_t* utf8_array; | 728 uint8_t* utf8_array; |
| 727 intptr_t utf8_len; | 729 intptr_t utf8_len; |
| 728 Dart_Handle result = Dart_Null(); | 730 Dart_Handle result = Dart_Null(); |
| 729 Dart_Handle handle = Dart_StringToUTF8(name, &utf8_array, &utf8_len); | 731 Dart_Handle handle = Dart_StringToUTF8(name, &utf8_array, &utf8_len); |
| 730 if (Dart_IsError(handle)) { | 732 if (Dart_IsError(handle)) { |
| 731 handle = Dart_ThrowException( | 733 handle = Dart_ThrowException( |
| 732 DartUtils::NewDartArgumentError(Dart_GetError(handle))); | 734 DartUtils::NewDartArgumentError(Dart_GetError(handle))); |
| 733 } else { | 735 } else { |
| 734 char* name_chars = reinterpret_cast<char*>(malloc(utf8_len + 1)); | 736 char* name_chars = reinterpret_cast<char*>(malloc(utf8_len + 1)); |
| 735 memmove(name_chars, utf8_array, utf8_len); | 737 memmove(name_chars, utf8_array, utf8_len); |
| 736 name_chars[utf8_len] = '\0'; | 738 name_chars[utf8_len] = '\0'; |
| 737 const char* value = NULL; | 739 const char* value = NULL; |
| 738 if (environment != NULL) { | 740 if (environment != NULL) { |
| 739 HashMap::Entry* entry = environment->Lookup( | 741 HashMap::Entry* entry = |
| 740 GetHashmapKeyFromString(name_chars), | 742 environment->Lookup(GetHashmapKeyFromString(name_chars), |
| 741 HashMap::StringHash(name_chars), | 743 HashMap::StringHash(name_chars), false); |
| 742 false); | |
| 743 if (entry != NULL) { | 744 if (entry != NULL) { |
| 744 value = reinterpret_cast<char*>(entry->value); | 745 value = reinterpret_cast<char*>(entry->value); |
| 745 } | 746 } |
| 746 } | 747 } |
| 747 if (value != NULL) { | 748 if (value != NULL) { |
| 748 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value), | 749 result = Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(value), |
| 749 strlen(value)); | 750 strlen(value)); |
| 750 } | 751 } |
| 751 free(name_chars); | 752 free(name_chars); |
| 752 } | 753 } |
| 753 return result; | 754 return result; |
| 754 } | 755 } |
| 755 | 756 |
| 756 | 757 |
| 757 #define CHECK_RESULT(result) \ | 758 #define CHECK_RESULT(result) \ |
| 758 if (Dart_IsError(result)) { \ | 759 if (Dart_IsError(result)) { \ |
| 759 *error = strdup(Dart_GetError(result)); \ | 760 *error = strdup(Dart_GetError(result)); \ |
| 760 if (Dart_IsCompilationError(result)) { \ | 761 if (Dart_IsCompilationError(result)) { \ |
| 761 *exit_code = kCompilationErrorExitCode; \ | 762 *exit_code = kCompilationErrorExitCode; \ |
| 762 } else if (Dart_IsApiError(result)) { \ | 763 } else if (Dart_IsApiError(result)) { \ |
| 763 *exit_code = kApiErrorExitCode; \ | 764 *exit_code = kApiErrorExitCode; \ |
| 764 } else if (Dart_IsVMRestartRequest(result)) { \ | 765 } else if (Dart_IsVMRestartRequest(result)) { \ |
| 765 *exit_code = kRestartRequestExitCode; \ | 766 *exit_code = kRestartRequestExitCode; \ |
| 766 } else { \ | 767 } else { \ |
| 767 *exit_code = kErrorExitCode; \ | 768 *exit_code = kErrorExitCode; \ |
| 768 } \ | 769 } \ |
| 769 Dart_ExitScope(); \ | 770 Dart_ExitScope(); \ |
| 770 Dart_ShutdownIsolate(); \ | 771 Dart_ShutdownIsolate(); \ |
| 771 return NULL; \ | 772 return NULL; \ |
| 772 } \ | 773 } |
| 773 | 774 |
| 774 | 775 |
| 775 static void SnapshotOnExitHook(int64_t exit_code); | 776 static void SnapshotOnExitHook(int64_t exit_code); |
| 776 | 777 |
| 777 | 778 |
| 778 // Returns true on success, false on failure. | 779 // Returns true on success, false on failure. |
| 779 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, | 780 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, |
| 780 const char* main, | 781 const char* main, |
| 781 const char* package_root, | 782 const char* package_root, |
| 782 const char* packages_config, | 783 const char* packages_config, |
| 783 Dart_IsolateFlags* flags, | 784 Dart_IsolateFlags* flags, |
| 784 char** error, | 785 char** error, |
| 785 int* exit_code) { | 786 int* exit_code) { |
| 786 ASSERT(script_uri != NULL); | 787 ASSERT(script_uri != NULL); |
| 787 | 788 |
| 788 const bool needs_load_port = true; | 789 const bool needs_load_port = true; |
| 789 #if defined(PRODUCT) | 790 #if defined(PRODUCT) |
| 790 const bool run_service_isolate = needs_load_port; | 791 const bool run_service_isolate = needs_load_port; |
| 791 #else | 792 #else |
| 792 // Always create the service isolate in DEBUG and RELEASE modes for profiling, | 793 // Always create the service isolate in DEBUG and RELEASE modes for profiling, |
| 793 // even if we don't need it for loading. | 794 // even if we don't need it for loading. |
| 794 const bool run_service_isolate = true; | 795 const bool run_service_isolate = true; |
| 795 #endif // PRODUCT | 796 #endif // PRODUCT |
| 796 if (!run_service_isolate && | 797 if (!run_service_isolate && |
| 797 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { | 798 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { |
| 798 return NULL; | 799 return NULL; |
| 799 } | 800 } |
| 800 | 801 |
| 801 IsolateData* isolate_data = new IsolateData(script_uri, | 802 IsolateData* isolate_data = |
| 802 package_root, | 803 new IsolateData(script_uri, package_root, packages_config); |
| 803 packages_config); | 804 Dart_Isolate isolate = Dart_CreateIsolate( |
| 804 Dart_Isolate isolate = Dart_CreateIsolate(script_uri, | 805 script_uri, main, isolate_snapshot_buffer, flags, isolate_data, error); |
| 805 main, | |
| 806 isolate_snapshot_buffer, | |
| 807 flags, | |
| 808 isolate_data, | |
| 809 error); | |
| 810 if (isolate == NULL) { | 806 if (isolate == NULL) { |
| 811 delete isolate_data; | 807 delete isolate_data; |
| 812 return NULL; | 808 return NULL; |
| 813 } | 809 } |
| 814 | 810 |
| 815 Dart_EnterScope(); | 811 Dart_EnterScope(); |
| 816 | 812 |
| 817 if (isolate_snapshot_buffer != NULL) { | 813 if (isolate_snapshot_buffer != NULL) { |
| 818 // Setup the native resolver as the snapshot does not carry it. | 814 // Setup the native resolver as the snapshot does not carry it. |
| 819 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 815 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 820 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 816 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 821 } | 817 } |
| 822 | 818 |
| 823 // Set up the library tag handler for this isolate. | 819 // Set up the library tag handler for this isolate. |
| 824 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | 820 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); |
| 825 CHECK_RESULT(result); | 821 CHECK_RESULT(result); |
| 826 | 822 |
| 827 if (Dart_IsServiceIsolate(isolate)) { | 823 if (Dart_IsServiceIsolate(isolate)) { |
| 828 // If this is the service isolate, load embedder specific bits and return. | 824 // If this is the service isolate, load embedder specific bits and return. |
| 829 bool skip_library_load = run_app_snapshot; | 825 bool skip_library_load = run_app_snapshot; |
| 830 if (!VmService::Setup(vm_service_server_ip, | 826 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port, |
| 831 vm_service_server_port, | 827 skip_library_load, vm_service_dev_mode)) { |
| 832 skip_library_load, | |
| 833 vm_service_dev_mode)) { | |
| 834 *error = strdup(VmService::GetErrorMessage()); | 828 *error = strdup(VmService::GetErrorMessage()); |
| 835 return NULL; | 829 return NULL; |
| 836 } | 830 } |
| 837 if (compile_all) { | 831 if (compile_all) { |
| 838 result = Dart_CompileAll(); | 832 result = Dart_CompileAll(); |
| 839 CHECK_RESULT(result); | 833 CHECK_RESULT(result); |
| 840 } | 834 } |
| 841 Dart_ExitScope(); | 835 Dart_ExitScope(); |
| 842 Dart_ExitIsolate(); | 836 Dart_ExitIsolate(); |
| 843 return isolate; | 837 return isolate; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 865 | 859 |
| 866 if (run_app_snapshot) { | 860 if (run_app_snapshot) { |
| 867 result = DartUtils::SetupIOLibrary(script_uri); | 861 result = DartUtils::SetupIOLibrary(script_uri); |
| 868 CHECK_RESULT(result); | 862 CHECK_RESULT(result); |
| 869 Loader::InitForSnapshot(script_uri); | 863 Loader::InitForSnapshot(script_uri); |
| 870 } else { | 864 } else { |
| 871 // Load the specified application script into the newly created isolate. | 865 // Load the specified application script into the newly created isolate. |
| 872 Dart_Handle uri = | 866 Dart_Handle uri = |
| 873 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); | 867 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); |
| 874 CHECK_RESULT(uri); | 868 CHECK_RESULT(uri); |
| 875 result = Loader::LibraryTagHandler(Dart_kScriptTag, | 869 result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri); |
| 876 Dart_Null(), | |
| 877 uri); | |
| 878 CHECK_RESULT(result); | 870 CHECK_RESULT(result); |
| 879 | 871 |
| 880 Dart_TimelineEvent("LoadScript", | 872 Dart_TimelineEvent("LoadScript", Dart_TimelineGetMicros(), |
| 881 Dart_TimelineGetMicros(), | 873 Dart_GetMainPortId(), Dart_Timeline_Event_Async_End, 0, |
| 882 Dart_GetMainPortId(), | 874 NULL, NULL); |
| 883 Dart_Timeline_Event_Async_End, | |
| 884 0, NULL, NULL); | |
| 885 | 875 |
| 886 result = DartUtils::SetupIOLibrary(script_uri); | 876 result = DartUtils::SetupIOLibrary(script_uri); |
| 887 CHECK_RESULT(result); | 877 CHECK_RESULT(result); |
| 888 } | 878 } |
| 889 | 879 |
| 890 // Make the isolate runnable so that it is ready to handle messages. | 880 // Make the isolate runnable so that it is ready to handle messages. |
| 891 Dart_ExitScope(); | 881 Dart_ExitScope(); |
| 892 Dart_ExitIsolate(); | 882 Dart_ExitIsolate(); |
| 893 bool retval = Dart_IsolateMakeRunnable(isolate); | 883 bool retval = Dart_IsolateMakeRunnable(isolate); |
| 894 if (!retval) { | 884 if (!retval) { |
| 895 *error = strdup("Invalid isolate state - Unable to make it runnable"); | 885 *error = strdup("Invalid isolate state - Unable to make it runnable"); |
| 896 Dart_EnterIsolate(isolate); | 886 Dart_EnterIsolate(isolate); |
| 897 Dart_ShutdownIsolate(); | 887 Dart_ShutdownIsolate(); |
| 898 return NULL; | 888 return NULL; |
| 899 } | 889 } |
| 900 | 890 |
| 901 return isolate; | 891 return isolate; |
| 902 } | 892 } |
| 903 | 893 |
| 904 #undef CHECK_RESULT | 894 #undef CHECK_RESULT |
| 905 | 895 |
| 906 | 896 |
| 907 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, | 897 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, |
| 908 const char* main, | 898 const char* main, |
| 909 const char* package_root, | 899 const char* package_root, |
| 910 const char* package_config, | 900 const char* package_config, |
| 911 Dart_IsolateFlags* flags, | 901 Dart_IsolateFlags* flags, |
| 912 void* data, char** error) { | 902 void* data, |
| 903 char** error) { |
| 913 // The VM should never call the isolate helper with a NULL flags. | 904 // The VM should never call the isolate helper with a NULL flags. |
| 914 ASSERT(flags != NULL); | 905 ASSERT(flags != NULL); |
| 915 ASSERT(flags->version == DART_FLAGS_CURRENT_VERSION); | 906 ASSERT(flags->version == DART_FLAGS_CURRENT_VERSION); |
| 916 if ((package_root != NULL) && (package_config != NULL)) { | 907 if ((package_root != NULL) && (package_config != NULL)) { |
| 917 *error = strdup("Invalid arguments - Cannot simultaneously specify " | 908 *error = strdup( |
| 918 "package root and package map."); | 909 "Invalid arguments - Cannot simultaneously specify " |
| 910 "package root and package map."); |
| 919 return NULL; | 911 return NULL; |
| 920 } | 912 } |
| 921 | 913 |
| 922 int exit_code = 0; | 914 int exit_code = 0; |
| 923 return CreateIsolateAndSetupHelper(script_uri, | 915 return CreateIsolateAndSetupHelper(script_uri, main, package_root, |
| 924 main, | 916 package_config, flags, error, &exit_code); |
| 925 package_root, | |
| 926 package_config, | |
| 927 flags, | |
| 928 error, | |
| 929 &exit_code); | |
| 930 } | 917 } |
| 931 | 918 |
| 932 | 919 |
| 933 static void PrintVersion() { | 920 static void PrintVersion() { |
| 934 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); | 921 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); |
| 935 } | 922 } |
| 936 | 923 |
| 937 | 924 |
| 925 // clang-format off |
| 938 static void PrintUsage() { | 926 static void PrintUsage() { |
| 939 Log::PrintErr( | 927 Log::PrintErr( |
| 940 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n" | 928 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n" |
| 941 "\n" | 929 "\n" |
| 942 "Executes the Dart script passed as <dart-script-file>.\n" | 930 "Executes the Dart script passed as <dart-script-file>.\n" |
| 943 "\n"); | 931 "\n"); |
| 944 if (!verbose_option) { | 932 if (!verbose_option) { |
| 945 Log::PrintErr( | 933 Log::PrintErr( |
| 946 "Common options:\n" | 934 "Common options:\n" |
| 947 "--checked or -c\n" | 935 "--checked or -c\n" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 " The path to a cache directory containing the trusted root certificates to\n" | 1007 " The path to a cache directory containing the trusted root certificates to\n" |
| 1020 " use for secure socket connections.\n" | 1008 " use for secure socket connections.\n" |
| 1021 #endif // !defined(TARGET_OS_MACOS) | 1009 #endif // !defined(TARGET_OS_MACOS) |
| 1022 "\n" | 1010 "\n" |
| 1023 "The following options are only used for VM development and may\n" | 1011 "The following options are only used for VM development and may\n" |
| 1024 "be changed in any future version:\n"); | 1012 "be changed in any future version:\n"); |
| 1025 const char* print_flags = "--print_flags"; | 1013 const char* print_flags = "--print_flags"; |
| 1026 Dart_SetVMFlags(1, &print_flags); | 1014 Dart_SetVMFlags(1, &print_flags); |
| 1027 } | 1015 } |
| 1028 } | 1016 } |
| 1017 // clang-format on |
| 1029 | 1018 |
| 1030 | 1019 |
| 1031 char* BuildIsolateName(const char* script_name, | 1020 char* BuildIsolateName(const char* script_name, const char* func_name) { |
| 1032 const char* func_name) { | |
| 1033 // Skip past any slashes in the script name. | 1021 // Skip past any slashes in the script name. |
| 1034 const char* last_slash = strrchr(script_name, '/'); | 1022 const char* last_slash = strrchr(script_name, '/'); |
| 1035 if (last_slash != NULL) { | 1023 if (last_slash != NULL) { |
| 1036 script_name = last_slash + 1; | 1024 script_name = last_slash + 1; |
| 1037 } | 1025 } |
| 1038 | 1026 |
| 1039 const char* kFormat = "%s/%s"; | 1027 const char* kFormat = "%s/%s"; |
| 1040 intptr_t len = strlen(script_name) + strlen(func_name) + 2; | 1028 intptr_t len = strlen(script_name) + strlen(func_name) + 2; |
| 1041 char* buffer = new char[len]; | 1029 char* buffer = new char[len]; |
| 1042 ASSERT(buffer != NULL); | 1030 ASSERT(buffer != NULL); |
| 1043 snprintf(buffer, len, kFormat, script_name, func_name); | 1031 snprintf(buffer, len, kFormat, script_name, func_name); |
| 1044 return buffer; | 1032 return buffer; |
| 1045 } | 1033 } |
| 1046 | 1034 |
| 1047 static void ShutdownIsolate(void* callback_data) { | 1035 static void ShutdownIsolate(void* callback_data) { |
| 1048 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); | 1036 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); |
| 1049 delete isolate_data; | 1037 delete isolate_data; |
| 1050 } | 1038 } |
| 1051 | 1039 |
| 1052 | 1040 |
| 1053 static const char* InternalJsonRpcError(Dart_Handle error) { | 1041 static const char* InternalJsonRpcError(Dart_Handle error) { |
| 1054 TextBuffer buffer(128); | 1042 TextBuffer buffer(128); |
| 1055 buffer.Printf("{\"code\":-32603," | 1043 buffer.Printf( |
| 1056 "\"message\":\"Internal error\"," | 1044 "{\"code\":-32603," |
| 1057 "\"details\": \"%s\"}", | 1045 "\"message\":\"Internal error\"," |
| 1058 Dart_GetError(error)); | 1046 "\"details\": \"%s\"}", |
| 1047 Dart_GetError(error)); |
| 1059 return buffer.Steal(); | 1048 return buffer.Steal(); |
| 1060 } | 1049 } |
| 1061 | 1050 |
| 1062 | 1051 |
| 1063 class DartScope { | 1052 class DartScope { |
| 1064 public: | 1053 public: |
| 1065 DartScope() { Dart_EnterScope(); } | 1054 DartScope() { Dart_EnterScope(); } |
| 1066 ~DartScope() { Dart_ExitScope(); } | 1055 ~DartScope() { Dart_ExitScope(); } |
| 1067 }; | 1056 }; |
| 1068 | 1057 |
| 1069 | 1058 |
| 1070 static bool ServiceGetIOHandler( | 1059 static bool ServiceGetIOHandler(const char* method, |
| 1071 const char* method, | 1060 const char** param_keys, |
| 1072 const char** param_keys, | 1061 const char** param_values, |
| 1073 const char** param_values, | 1062 intptr_t num_params, |
| 1074 intptr_t num_params, | 1063 void* user_data, |
| 1075 void* user_data, | 1064 const char** response) { |
| 1076 const char** response) { | |
| 1077 DartScope scope; | 1065 DartScope scope; |
| 1078 // TODO(ajohnsen): Store the library/function in isolate data or user_data. | 1066 // TODO(ajohnsen): Store the library/function in isolate data or user_data. |
| 1079 Dart_Handle dart_io_str = Dart_NewStringFromCString("dart:io"); | 1067 Dart_Handle dart_io_str = Dart_NewStringFromCString("dart:io"); |
| 1080 if (Dart_IsError(dart_io_str)) { | 1068 if (Dart_IsError(dart_io_str)) { |
| 1081 *response = InternalJsonRpcError(dart_io_str); | 1069 *response = InternalJsonRpcError(dart_io_str); |
| 1082 return false; | 1070 return false; |
| 1083 } | 1071 } |
| 1084 | 1072 |
| 1085 Dart_Handle io_lib = Dart_LookupLibrary(dart_io_str); | 1073 Dart_Handle io_lib = Dart_LookupLibrary(dart_io_str); |
| 1086 if (Dart_IsError(io_lib)) { | 1074 if (Dart_IsError(io_lib)) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1104 Dart_ListSetAt(keys, i, Dart_NewStringFromCString(param_keys[i])); | 1092 Dart_ListSetAt(keys, i, Dart_NewStringFromCString(param_keys[i])); |
| 1105 Dart_ListSetAt(values, i, Dart_NewStringFromCString(param_values[i])); | 1093 Dart_ListSetAt(values, i, Dart_NewStringFromCString(param_values[i])); |
| 1106 } | 1094 } |
| 1107 Dart_Handle args[] = {paths, keys, values}; | 1095 Dart_Handle args[] = {paths, keys, values}; |
| 1108 Dart_Handle result = Dart_Invoke(io_lib, handler_function_name, 3, args); | 1096 Dart_Handle result = Dart_Invoke(io_lib, handler_function_name, 3, args); |
| 1109 if (Dart_IsError(result)) { | 1097 if (Dart_IsError(result)) { |
| 1110 *response = InternalJsonRpcError(result); | 1098 *response = InternalJsonRpcError(result); |
| 1111 return false; | 1099 return false; |
| 1112 } | 1100 } |
| 1113 | 1101 |
| 1114 const char *json; | 1102 const char* json; |
| 1115 result = Dart_StringToCString(result, &json); | 1103 result = Dart_StringToCString(result, &json); |
| 1116 if (Dart_IsError(result)) { | 1104 if (Dart_IsError(result)) { |
| 1117 *response = InternalJsonRpcError(result); | 1105 *response = InternalJsonRpcError(result); |
| 1118 return false; | 1106 return false; |
| 1119 } | 1107 } |
| 1120 *response = strdup(json); | 1108 *response = strdup(json); |
| 1121 return true; | 1109 return true; |
| 1122 } | 1110 } |
| 1123 | 1111 |
| 1124 | 1112 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 } | 1151 } |
| 1164 | 1152 |
| 1165 | 1153 |
| 1166 static void WriteSnapshotFile(const char* filename, | 1154 static void WriteSnapshotFile(const char* filename, |
| 1167 bool write_magic_number, | 1155 bool write_magic_number, |
| 1168 const uint8_t* buffer, | 1156 const uint8_t* buffer, |
| 1169 const intptr_t size) { | 1157 const intptr_t size) { |
| 1170 char* concat = NULL; | 1158 char* concat = NULL; |
| 1171 File* file = File::Open(filename, File::kWriteTruncate); | 1159 File* file = File::Open(filename, File::kWriteTruncate); |
| 1172 if (file == NULL) { | 1160 if (file == NULL) { |
| 1173 ErrorExit(kErrorExitCode, | 1161 ErrorExit(kErrorExitCode, "Unable to open file %s for writing snapshot\n", |
| 1174 "Unable to open file %s for writing snapshot\n", | |
| 1175 filename); | 1162 filename); |
| 1176 } | 1163 } |
| 1177 | 1164 |
| 1178 if (write_magic_number) { | 1165 if (write_magic_number) { |
| 1179 // Write the magic number to indicate file is a script snapshot. | 1166 // Write the magic number to indicate file is a script snapshot. |
| 1180 DartUtils::WriteMagicNumber(file); | 1167 DartUtils::WriteMagicNumber(file); |
| 1181 } | 1168 } |
| 1182 | 1169 |
| 1183 if (!file->WriteFully(buffer, size)) { | 1170 if (!file->WriteFully(buffer, size)) { |
| 1184 ErrorExit(kErrorExitCode, | 1171 ErrorExit(kErrorExitCode, "Unable to write file %s for writing snapshot\n", |
| 1185 "Unable to write file %s for writing snapshot\n", | |
| 1186 filename); | 1172 filename); |
| 1187 } | 1173 } |
| 1188 file->Release(); | 1174 file->Release(); |
| 1189 if (concat != NULL) { | 1175 if (concat != NULL) { |
| 1190 delete concat; | 1176 delete concat; |
| 1191 } | 1177 } |
| 1192 } | 1178 } |
| 1193 | 1179 |
| 1194 | 1180 |
| 1195 static const int64_t kAppSnapshotHeaderSize = 5 * sizeof(int64_t); // NOLINT | 1181 static const int64_t kAppSnapshotHeaderSize = 5 * sizeof(int64_t); // NOLINT |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1224 int64_t vmisolate_position = | 1210 int64_t vmisolate_position = |
| 1225 Utils::RoundUp(file->Position(), kAppSnapshotPageSize); | 1211 Utils::RoundUp(file->Position(), kAppSnapshotPageSize); |
| 1226 int64_t isolate_position = | 1212 int64_t isolate_position = |
| 1227 Utils::RoundUp(vmisolate_position + header[1], kAppSnapshotPageSize); | 1213 Utils::RoundUp(vmisolate_position + header[1], kAppSnapshotPageSize); |
| 1228 int64_t rodata_position = | 1214 int64_t rodata_position = |
| 1229 Utils::RoundUp(isolate_position + header[2], kAppSnapshotPageSize); | 1215 Utils::RoundUp(isolate_position + header[2], kAppSnapshotPageSize); |
| 1230 int64_t instructions_position = | 1216 int64_t instructions_position = |
| 1231 Utils::RoundUp(rodata_position + header[3], kAppSnapshotPageSize); | 1217 Utils::RoundUp(rodata_position + header[3], kAppSnapshotPageSize); |
| 1232 | 1218 |
| 1233 void* read_only_buffer = | 1219 void* read_only_buffer = |
| 1234 file->Map(File::kReadOnly, vmisolate_position, | 1220 file->Map(File::kReadOnly, vmisolate_position, |
| 1235 instructions_position - vmisolate_position); | 1221 instructions_position - vmisolate_position); |
| 1236 if (read_only_buffer == NULL) { | 1222 if (read_only_buffer == NULL) { |
| 1237 Log::PrintErr("Failed to memory map snapshot\n"); | 1223 Log::PrintErr("Failed to memory map snapshot\n"); |
| 1238 Platform::Exit(kErrorExitCode); | 1224 Platform::Exit(kErrorExitCode); |
| 1239 } | 1225 } |
| 1240 | 1226 |
| 1241 *vmisolate_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) | 1227 *vmisolate_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) + |
| 1242 + (vmisolate_position - vmisolate_position); | 1228 (vmisolate_position - vmisolate_position); |
| 1243 *isolate_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) | 1229 *isolate_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) + |
| 1244 + (isolate_position - vmisolate_position); | 1230 (isolate_position - vmisolate_position); |
| 1245 if (header[3] == 0) { | 1231 if (header[3] == 0) { |
| 1246 *rodata_buffer = NULL; | 1232 *rodata_buffer = NULL; |
| 1247 } else { | 1233 } else { |
| 1248 *rodata_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) | 1234 *rodata_buffer = reinterpret_cast<const uint8_t*>(read_only_buffer) + |
| 1249 + (rodata_position - vmisolate_position); | 1235 (rodata_position - vmisolate_position); |
| 1250 } | 1236 } |
| 1251 | 1237 |
| 1252 if (header[4] == 0) { | 1238 if (header[4] == 0) { |
| 1253 *instructions_buffer = NULL; | 1239 *instructions_buffer = NULL; |
| 1254 } else { | 1240 } else { |
| 1255 *instructions_buffer = reinterpret_cast<const uint8_t*>( | 1241 *instructions_buffer = reinterpret_cast<const uint8_t*>( |
| 1256 file->Map(File::kReadExecute, instructions_position, header[4])); | 1242 file->Map(File::kReadExecute, instructions_position, header[4])); |
| 1257 if (*instructions_buffer == NULL) { | 1243 if (*instructions_buffer == NULL) { |
| 1258 Log::PrintErr("Failed to memory map snapshot\n"); | 1244 Log::PrintErr("Failed to memory map snapshot\n"); |
| 1259 Platform::Exit(kErrorExitCode); | 1245 Platform::Exit(kErrorExitCode); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1315 const uint8_t** vmisolate_buffer, | 1301 const uint8_t** vmisolate_buffer, |
| 1316 const uint8_t** isolate_buffer, | 1302 const uint8_t** isolate_buffer, |
| 1317 const uint8_t** instructions_buffer, | 1303 const uint8_t** instructions_buffer, |
| 1318 const uint8_t** rodata_buffer) { | 1304 const uint8_t** rodata_buffer) { |
| 1319 if (File::GetType(script_name, true) != File::kIsFile) { | 1305 if (File::GetType(script_name, true) != File::kIsFile) { |
| 1320 // If 'script_name' refers to a pipe, don't read to check for an app | 1306 // If 'script_name' refers to a pipe, don't read to check for an app |
| 1321 // snapshot since we cannot rewind if it isn't (and couldn't mmap it in | 1307 // snapshot since we cannot rewind if it isn't (and couldn't mmap it in |
| 1322 // anyway if it was). | 1308 // anyway if it was). |
| 1323 return false; | 1309 return false; |
| 1324 } | 1310 } |
| 1325 if (ReadAppSnapshotBlobs(script_name, | 1311 if (ReadAppSnapshotBlobs(script_name, vmisolate_buffer, isolate_buffer, |
| 1326 vmisolate_buffer, | 1312 instructions_buffer, rodata_buffer)) { |
| 1327 isolate_buffer, | |
| 1328 instructions_buffer, | |
| 1329 rodata_buffer)) { | |
| 1330 return true; | 1313 return true; |
| 1331 } | 1314 } |
| 1332 return ReadAppSnapshotDynamicLibrary(script_name, | 1315 return ReadAppSnapshotDynamicLibrary(script_name, vmisolate_buffer, |
| 1333 vmisolate_buffer, | 1316 isolate_buffer, instructions_buffer, |
| 1334 isolate_buffer, | |
| 1335 instructions_buffer, | |
| 1336 rodata_buffer); | 1317 rodata_buffer); |
| 1337 } | 1318 } |
| 1338 | 1319 |
| 1339 | 1320 |
| 1340 static bool WriteInt64(File* file, int64_t size) { | 1321 static bool WriteInt64(File* file, int64_t size) { |
| 1341 return file->WriteFully(&size, sizeof(size)); | 1322 return file->WriteFully(&size, sizeof(size)); |
| 1342 } | 1323 } |
| 1343 | 1324 |
| 1344 | 1325 |
| 1345 static void WriteAppSnapshot(const char* filename, | 1326 static void WriteAppSnapshot(const char* filename, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 intptr_t isolate_size = 0; | 1395 intptr_t isolate_size = 0; |
| 1415 uint8_t* assembly_buffer = NULL; | 1396 uint8_t* assembly_buffer = NULL; |
| 1416 intptr_t assembly_size = 0; | 1397 intptr_t assembly_size = 0; |
| 1417 uint8_t* instructions_blob_buffer = NULL; | 1398 uint8_t* instructions_blob_buffer = NULL; |
| 1418 intptr_t instructions_blob_size = 0; | 1399 intptr_t instructions_blob_size = 0; |
| 1419 uint8_t* rodata_blob_buffer = NULL; | 1400 uint8_t* rodata_blob_buffer = NULL; |
| 1420 intptr_t rodata_blob_size = 0; | 1401 intptr_t rodata_blob_size = 0; |
| 1421 Dart_Handle result; | 1402 Dart_Handle result; |
| 1422 if (use_blobs) { | 1403 if (use_blobs) { |
| 1423 result = Dart_CreatePrecompiledSnapshotBlob( | 1404 result = Dart_CreatePrecompiledSnapshotBlob( |
| 1424 &vm_isolate_buffer, | 1405 &vm_isolate_buffer, &vm_isolate_size, &isolate_buffer, &isolate_size, |
| 1425 &vm_isolate_size, | 1406 &instructions_blob_buffer, &instructions_blob_size, &rodata_blob_buffer, |
| 1426 &isolate_buffer, | |
| 1427 &isolate_size, | |
| 1428 &instructions_blob_buffer, | |
| 1429 &instructions_blob_size, | |
| 1430 &rodata_blob_buffer, | |
| 1431 &rodata_blob_size); | 1407 &rodata_blob_size); |
| 1432 } else { | 1408 } else { |
| 1433 result = Dart_CreatePrecompiledSnapshotAssembly( | 1409 result = Dart_CreatePrecompiledSnapshotAssembly(&assembly_buffer, |
| 1434 &assembly_buffer, | 1410 &assembly_size); |
| 1435 &assembly_size); | |
| 1436 } | 1411 } |
| 1437 if (Dart_IsError(result)) { | 1412 if (Dart_IsError(result)) { |
| 1438 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1413 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
| 1439 } | 1414 } |
| 1440 if (use_blobs) { | 1415 if (use_blobs) { |
| 1441 WriteAppSnapshot(snapshot_filename, | 1416 WriteAppSnapshot(snapshot_filename, vm_isolate_buffer, vm_isolate_size, |
| 1442 vm_isolate_buffer, | 1417 isolate_buffer, isolate_size, instructions_blob_buffer, |
| 1443 vm_isolate_size, | 1418 instructions_blob_size, rodata_blob_buffer, |
| 1444 isolate_buffer, | |
| 1445 isolate_size, | |
| 1446 instructions_blob_buffer, | |
| 1447 instructions_blob_size, | |
| 1448 rodata_blob_buffer, | |
| 1449 rodata_blob_size); | 1419 rodata_blob_size); |
| 1450 } else { | 1420 } else { |
| 1451 WriteSnapshotFile(snapshot_filename, | 1421 WriteSnapshotFile(snapshot_filename, false, assembly_buffer, assembly_size); |
| 1452 false, | |
| 1453 assembly_buffer, | |
| 1454 assembly_size); | |
| 1455 } | 1422 } |
| 1456 } | 1423 } |
| 1457 | 1424 |
| 1458 | 1425 |
| 1459 #if defined(TARGET_ARCH_X64) | 1426 #if defined(TARGET_ARCH_X64) |
| 1460 static void GeneratePrecompiledJITSnapshot() { | 1427 static void GeneratePrecompiledJITSnapshot() { |
| 1461 uint8_t* vm_isolate_buffer = NULL; | 1428 uint8_t* vm_isolate_buffer = NULL; |
| 1462 intptr_t vm_isolate_size = 0; | 1429 intptr_t vm_isolate_size = 0; |
| 1463 uint8_t* isolate_buffer = NULL; | 1430 uint8_t* isolate_buffer = NULL; |
| 1464 intptr_t isolate_size = 0; | 1431 intptr_t isolate_size = 0; |
| 1465 uint8_t* instructions_blob_buffer = NULL; | 1432 uint8_t* instructions_blob_buffer = NULL; |
| 1466 intptr_t instructions_blob_size = 0; | 1433 intptr_t instructions_blob_size = 0; |
| 1467 uint8_t* rodata_blob_buffer = NULL; | 1434 uint8_t* rodata_blob_buffer = NULL; |
| 1468 intptr_t rodata_blob_size = 0; | 1435 intptr_t rodata_blob_size = 0; |
| 1469 Dart_Handle result = Dart_CreateAppJITSnapshot( | 1436 Dart_Handle result = Dart_CreateAppJITSnapshot( |
| 1470 &vm_isolate_buffer, | 1437 &vm_isolate_buffer, &vm_isolate_size, &isolate_buffer, &isolate_size, |
| 1471 &vm_isolate_size, | 1438 &instructions_blob_buffer, &instructions_blob_size, &rodata_blob_buffer, |
| 1472 &isolate_buffer, | |
| 1473 &isolate_size, | |
| 1474 &instructions_blob_buffer, | |
| 1475 &instructions_blob_size, | |
| 1476 &rodata_blob_buffer, | |
| 1477 &rodata_blob_size); | 1439 &rodata_blob_size); |
| 1478 if (Dart_IsError(result)) { | 1440 if (Dart_IsError(result)) { |
| 1479 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1441 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
| 1480 } | 1442 } |
| 1481 WriteAppSnapshot(snapshot_filename, | 1443 WriteAppSnapshot(snapshot_filename, vm_isolate_buffer, vm_isolate_size, |
| 1482 vm_isolate_buffer, | 1444 isolate_buffer, isolate_size, instructions_blob_buffer, |
| 1483 vm_isolate_size, | 1445 instructions_blob_size, rodata_blob_buffer, |
| 1484 isolate_buffer, | |
| 1485 isolate_size, | |
| 1486 instructions_blob_buffer, | |
| 1487 instructions_blob_size, | |
| 1488 rodata_blob_buffer, | |
| 1489 rodata_blob_size); | 1446 rodata_blob_size); |
| 1490 } | 1447 } |
| 1491 #endif // defined(TARGET_ARCH_X64) | 1448 #endif // defined(TARGET_ARCH_X64) |
| 1492 | 1449 |
| 1493 | 1450 |
| 1494 static void GenerateAppSnapshot() { | 1451 static void GenerateAppSnapshot() { |
| 1495 Dart_Handle result; | 1452 Dart_Handle result; |
| 1496 #if defined(TARGET_ARCH_X64) | 1453 #if defined(TARGET_ARCH_X64) |
| 1497 result = Dart_PrecompileJIT(); | 1454 result = Dart_PrecompileJIT(); |
| 1498 if (Dart_IsError(result)) { | 1455 if (Dart_IsError(result)) { |
| 1499 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1456 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
| 1500 } | 1457 } |
| 1501 GeneratePrecompiledJITSnapshot(); | 1458 GeneratePrecompiledJITSnapshot(); |
| 1502 #else | 1459 #else |
| 1503 // Create an application snapshot of the script. | 1460 // Create an application snapshot of the script. |
| 1504 uint8_t* vm_isolate_buffer = NULL; | 1461 uint8_t* vm_isolate_buffer = NULL; |
| 1505 intptr_t vm_isolate_size = 0; | 1462 intptr_t vm_isolate_size = 0; |
| 1506 uint8_t* isolate_buffer = NULL; | 1463 uint8_t* isolate_buffer = NULL; |
| 1507 intptr_t isolate_size = 0; | 1464 intptr_t isolate_size = 0; |
| 1508 | 1465 |
| 1509 result = Dart_CreateSnapshot(&vm_isolate_buffer, | 1466 result = Dart_CreateSnapshot(&vm_isolate_buffer, &vm_isolate_size, |
| 1510 &vm_isolate_size, | 1467 &isolate_buffer, &isolate_size); |
| 1511 &isolate_buffer, | |
| 1512 &isolate_size); | |
| 1513 if (Dart_IsError(result)) { | 1468 if (Dart_IsError(result)) { |
| 1514 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); | 1469 ErrorExit(kErrorExitCode, "%s\n", Dart_GetError(result)); |
| 1515 } | 1470 } |
| 1516 | 1471 |
| 1517 WriteAppSnapshot(snapshot_filename, | 1472 WriteAppSnapshot(snapshot_filename, vm_isolate_buffer, vm_isolate_size, |
| 1518 vm_isolate_buffer, | 1473 isolate_buffer, isolate_size, NULL, 0, NULL, 0); |
| 1519 vm_isolate_size, | |
| 1520 isolate_buffer, | |
| 1521 isolate_size, | |
| 1522 NULL, 0, NULL, 0); | |
| 1523 #endif // defined(TARGET_ARCH_X64) | 1474 #endif // defined(TARGET_ARCH_X64) |
| 1524 } | 1475 } |
| 1525 | 1476 |
| 1526 | 1477 |
| 1527 | |
| 1528 #define CHECK_RESULT(result) \ | 1478 #define CHECK_RESULT(result) \ |
| 1529 if (Dart_IsError(result)) { \ | 1479 if (Dart_IsError(result)) { \ |
| 1530 if (Dart_IsVMRestartRequest(result)) { \ | 1480 if (Dart_IsVMRestartRequest(result)) { \ |
| 1531 Dart_ExitScope(); \ | 1481 Dart_ExitScope(); \ |
| 1532 Dart_ShutdownIsolate(); \ | 1482 Dart_ShutdownIsolate(); \ |
| 1533 return true; \ | 1483 return true; \ |
| 1534 } \ | 1484 } \ |
| 1535 const int exit_code = Dart_IsCompilationError(result) ? \ | 1485 const int exit_code = Dart_IsCompilationError(result) \ |
| 1536 kCompilationErrorExitCode : kErrorExitCode; \ | 1486 ? kCompilationErrorExitCode \ |
| 1487 : kErrorExitCode; \ |
| 1537 ErrorExit(exit_code, "%s\n", Dart_GetError(result)); \ | 1488 ErrorExit(exit_code, "%s\n", Dart_GetError(result)); \ |
| 1538 } | 1489 } |
| 1539 | 1490 |
| 1540 | 1491 |
| 1541 static void SnapshotOnExitHook(int64_t exit_code) { | 1492 static void SnapshotOnExitHook(int64_t exit_code) { |
| 1542 if (Dart_CurrentIsolate() != main_isolate) { | 1493 if (Dart_CurrentIsolate() != main_isolate) { |
| 1543 Log::PrintErr("A snapshot was requested, but a secondary isolate " | 1494 Log::PrintErr( |
| 1544 "performed a hard exit (%" Pd64 ").\n", exit_code); | 1495 "A snapshot was requested, but a secondary isolate " |
| 1496 "performed a hard exit (%" Pd64 ").\n", |
| 1497 exit_code); |
| 1545 Platform::Exit(kErrorExitCode); | 1498 Platform::Exit(kErrorExitCode); |
| 1546 } | 1499 } |
| 1547 if (exit_code == 0) { | 1500 if (exit_code == 0) { |
| 1548 GenerateAppSnapshot(); | 1501 GenerateAppSnapshot(); |
| 1549 } | 1502 } |
| 1550 } | 1503 } |
| 1551 | 1504 |
| 1552 | 1505 |
| 1553 bool RunMainIsolate(const char* script_name, | 1506 bool RunMainIsolate(const char* script_name, CommandLineOptions* dart_options) { |
| 1554 CommandLineOptions* dart_options) { | |
| 1555 // Call CreateIsolateAndSetup which creates an isolate and loads up | 1507 // Call CreateIsolateAndSetup which creates an isolate and loads up |
| 1556 // the specified application script. | 1508 // the specified application script. |
| 1557 char* error = NULL; | 1509 char* error = NULL; |
| 1558 int exit_code = 0; | 1510 int exit_code = 0; |
| 1559 char* isolate_name = BuildIsolateName(script_name, "main"); | 1511 char* isolate_name = BuildIsolateName(script_name, "main"); |
| 1560 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, | 1512 Dart_Isolate isolate = CreateIsolateAndSetupHelper( |
| 1561 "main", | 1513 script_name, "main", commandline_package_root, commandline_packages_file, |
| 1562 commandline_package_root, | 1514 NULL, &error, &exit_code); |
| 1563 commandline_packages_file, | |
| 1564 NULL, | |
| 1565 &error, | |
| 1566 &exit_code); | |
| 1567 if (isolate == NULL) { | 1515 if (isolate == NULL) { |
| 1568 delete [] isolate_name; | 1516 delete[] isolate_name; |
| 1569 if (exit_code == kRestartRequestExitCode) { | 1517 if (exit_code == kRestartRequestExitCode) { |
| 1570 free(error); | 1518 free(error); |
| 1571 return true; | 1519 return true; |
| 1572 } | 1520 } |
| 1573 Log::PrintErr("%s\n", error); | 1521 Log::PrintErr("%s\n", error); |
| 1574 free(error); | 1522 free(error); |
| 1575 error = NULL; | 1523 error = NULL; |
| 1576 Process::TerminateExitCodeHandler(); | 1524 Process::TerminateExitCodeHandler(); |
| 1577 error = Dart_Cleanup(); | 1525 error = Dart_Cleanup(); |
| 1578 if (error != NULL) { | 1526 if (error != NULL) { |
| 1579 Log::PrintErr("VM cleanup failed: %s\n", error); | 1527 Log::PrintErr("VM cleanup failed: %s\n", error); |
| 1580 free(error); | 1528 free(error); |
| 1581 } | 1529 } |
| 1582 EventHandler::Stop(); | 1530 EventHandler::Stop(); |
| 1583 Platform::Exit((exit_code != 0) ? exit_code : kErrorExitCode); | 1531 Platform::Exit((exit_code != 0) ? exit_code : kErrorExitCode); |
| 1584 } | 1532 } |
| 1585 main_isolate = isolate; | 1533 main_isolate = isolate; |
| 1586 delete [] isolate_name; | 1534 delete[] isolate_name; |
| 1587 | 1535 |
| 1588 Dart_EnterIsolate(isolate); | 1536 Dart_EnterIsolate(isolate); |
| 1589 ASSERT(isolate == Dart_CurrentIsolate()); | 1537 ASSERT(isolate == Dart_CurrentIsolate()); |
| 1590 ASSERT(isolate != NULL); | 1538 ASSERT(isolate != NULL); |
| 1591 Dart_Handle result; | 1539 Dart_Handle result; |
| 1592 | 1540 |
| 1593 Dart_EnterScope(); | 1541 Dart_EnterScope(); |
| 1594 | 1542 |
| 1595 if (gen_snapshot_kind == kScript) { | 1543 if (gen_snapshot_kind == kScript) { |
| 1596 GenerateScriptSnapshot(); | 1544 GenerateScriptSnapshot(); |
| 1597 } else { | 1545 } else { |
| 1598 // Lookup the library of the root script. | 1546 // Lookup the library of the root script. |
| 1599 Dart_Handle root_lib = Dart_RootLibrary(); | 1547 Dart_Handle root_lib = Dart_RootLibrary(); |
| 1600 // Import the root library into the builtin library so that we can easily | 1548 // Import the root library into the builtin library so that we can easily |
| 1601 // lookup the main entry point exported from the root library. | 1549 // lookup the main entry point exported from the root library. |
| 1602 IsolateData* isolate_data = | 1550 IsolateData* isolate_data = |
| 1603 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); | 1551 reinterpret_cast<IsolateData*>(Dart_IsolateData(isolate)); |
| 1604 result = Dart_LibraryImportLibrary( | 1552 result = Dart_LibraryImportLibrary(isolate_data->builtin_lib(), root_lib, |
| 1605 isolate_data->builtin_lib(), root_lib, Dart_Null()); | 1553 Dart_Null()); |
| 1606 if (is_noopt || | 1554 if (is_noopt || (gen_snapshot_kind == kAppAOT) || |
| 1607 (gen_snapshot_kind == kAppAOT) || | |
| 1608 (gen_snapshot_kind == kAppJIT)) { | 1555 (gen_snapshot_kind == kAppJIT)) { |
| 1609 // Load the embedder's portion of the VM service's Dart code so it will | 1556 // Load the embedder's portion of the VM service's Dart code so it will |
| 1610 // be included in the app snapshot. | 1557 // be included in the app snapshot. |
| 1611 if (!VmService::LoadForGenPrecompiled()) { | 1558 if (!VmService::LoadForGenPrecompiled()) { |
| 1612 fprintf(stderr, | 1559 fprintf(stderr, "VM service loading failed: %s\n", |
| 1613 "VM service loading failed: %s\n", | |
| 1614 VmService::GetErrorMessage()); | 1560 VmService::GetErrorMessage()); |
| 1615 fflush(stderr); | 1561 fflush(stderr); |
| 1616 exit(kErrorExitCode); | 1562 exit(kErrorExitCode); |
| 1617 } | 1563 } |
| 1618 } | 1564 } |
| 1619 | 1565 |
| 1620 if (compile_all) { | 1566 if (compile_all) { |
| 1621 result = Dart_CompileAll(); | 1567 result = Dart_CompileAll(); |
| 1622 CHECK_RESULT(result); | 1568 CHECK_RESULT(result); |
| 1623 } | 1569 } |
| 1624 | 1570 |
| 1625 if (parse_all) { | 1571 if (parse_all) { |
| 1626 result = Dart_ParseAll(); | 1572 result = Dart_ParseAll(); |
| 1627 CHECK_RESULT(result); | 1573 CHECK_RESULT(result); |
| 1628 Dart_ExitScope(); | 1574 Dart_ExitScope(); |
| 1629 // Shutdown the isolate. | 1575 // Shutdown the isolate. |
| 1630 Dart_ShutdownIsolate(); | 1576 Dart_ShutdownIsolate(); |
| 1631 return false; | 1577 return false; |
| 1632 } | 1578 } |
| 1633 | 1579 |
| 1634 if (is_noopt || (gen_snapshot_kind == kAppAOT)) { | 1580 if (is_noopt || (gen_snapshot_kind == kAppAOT)) { |
| 1635 Dart_QualifiedFunctionName standalone_entry_points[] = { | 1581 Dart_QualifiedFunctionName standalone_entry_points[] = { |
| 1636 { "dart:_builtin", "::", "_getMainClosure" }, | 1582 {"dart:_builtin", "::", "_getMainClosure"}, |
| 1637 { "dart:_builtin", "::", "_getPrintClosure" }, | 1583 {"dart:_builtin", "::", "_getPrintClosure"}, |
| 1638 { "dart:_builtin", "::", "_getUriBaseClosure" }, | 1584 {"dart:_builtin", "::", "_getUriBaseClosure"}, |
| 1639 { "dart:_builtin", "::", "_resolveInWorkingDirectory" }, | 1585 {"dart:_builtin", "::", "_resolveInWorkingDirectory"}, |
| 1640 { "dart:_builtin", "::", "_setWorkingDirectory" }, | 1586 {"dart:_builtin", "::", "_setWorkingDirectory"}, |
| 1641 { "dart:_builtin", "::", "_setPackageRoot" }, | 1587 {"dart:_builtin", "::", "_setPackageRoot"}, |
| 1642 { "dart:_builtin", "::", "_setPackagesMap" }, | 1588 {"dart:_builtin", "::", "_setPackagesMap"}, |
| 1643 { "dart:_builtin", "::", "_libraryFilePath" }, | 1589 {"dart:_builtin", "::", "_libraryFilePath"}, |
| 1644 { "dart:io", "::", "_makeUint8ListView" }, | 1590 {"dart:io", "::", "_makeUint8ListView"}, |
| 1645 { "dart:io", "::", "_makeDatagram" }, | 1591 {"dart:io", "::", "_makeDatagram"}, |
| 1646 { "dart:io", "::", "_setupHooks" }, | 1592 {"dart:io", "::", "_setupHooks"}, |
| 1647 { "dart:io", "::", "_getWatchSignalInternal" }, | 1593 {"dart:io", "::", "_getWatchSignalInternal"}, |
| 1648 { "dart:io", "CertificateException", "CertificateException." }, | 1594 {"dart:io", "CertificateException", "CertificateException."}, |
| 1649 { "dart:io", "Directory", "Directory." }, | 1595 {"dart:io", "Directory", "Directory."}, |
| 1650 { "dart:io", "File", "File." }, | 1596 {"dart:io", "File", "File."}, |
| 1651 { "dart:io", "FileSystemException", "FileSystemException." }, | 1597 {"dart:io", "FileSystemException", "FileSystemException."}, |
| 1652 { "dart:io", "HandshakeException", "HandshakeException." }, | 1598 {"dart:io", "HandshakeException", "HandshakeException."}, |
| 1653 { "dart:io", "Link", "Link." }, | 1599 {"dart:io", "Link", "Link."}, |
| 1654 { "dart:io", "OSError", "OSError." }, | 1600 {"dart:io", "OSError", "OSError."}, |
| 1655 { "dart:io", "TlsException", "TlsException." }, | 1601 {"dart:io", "TlsException", "TlsException."}, |
| 1656 { "dart:io", "X509Certificate", "X509Certificate._" }, | 1602 {"dart:io", "X509Certificate", "X509Certificate._"}, |
| 1657 { "dart:io", "_ExternalBuffer", "set:data" }, | 1603 {"dart:io", "_ExternalBuffer", "set:data"}, |
| 1658 { "dart:io", "_ExternalBuffer", "get:start" }, | 1604 {"dart:io", "_ExternalBuffer", "get:start"}, |
| 1659 { "dart:io", "_ExternalBuffer", "set:start" }, | 1605 {"dart:io", "_ExternalBuffer", "set:start"}, |
| 1660 { "dart:io", "_ExternalBuffer", "get:end" }, | 1606 {"dart:io", "_ExternalBuffer", "get:end"}, |
| 1661 { "dart:io", "_ExternalBuffer", "set:end" }, | 1607 {"dart:io", "_ExternalBuffer", "set:end"}, |
| 1662 { "dart:io", "_Platform", "set:_nativeScript" }, | 1608 {"dart:io", "_Platform", "set:_nativeScript"}, |
| 1663 { "dart:io", "_ProcessStartStatus", "set:_errorCode" }, | 1609 {"dart:io", "_ProcessStartStatus", "set:_errorCode"}, |
| 1664 { "dart:io", "_ProcessStartStatus", "set:_errorMessage" }, | 1610 {"dart:io", "_ProcessStartStatus", "set:_errorMessage"}, |
| 1665 { "dart:io", "_SecureFilterImpl", "get:buffers" }, | 1611 {"dart:io", "_SecureFilterImpl", "get:buffers"}, |
| 1666 { "dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE" }, | 1612 {"dart:io", "_SecureFilterImpl", "get:ENCRYPTED_SIZE"}, |
| 1667 { "dart:io", "_SecureFilterImpl", "get:SIZE" }, | 1613 {"dart:io", "_SecureFilterImpl", "get:SIZE"}, |
| 1668 { "dart:vmservice_io", "::", "main" }, | 1614 {"dart:vmservice_io", "::", "main"}, |
| 1669 { NULL, NULL, NULL } // Must be terminated with NULL entries. | 1615 {NULL, NULL, NULL} // Must be terminated with NULL entries. |
| 1670 }; | 1616 }; |
| 1671 | 1617 |
| 1672 const bool reset_fields = gen_snapshot_kind == kAppAOT; | 1618 const bool reset_fields = gen_snapshot_kind == kAppAOT; |
| 1673 result = Dart_Precompile(standalone_entry_points, reset_fields); | 1619 result = Dart_Precompile(standalone_entry_points, reset_fields); |
| 1674 CHECK_RESULT(result); | 1620 CHECK_RESULT(result); |
| 1675 } | 1621 } |
| 1676 | 1622 |
| 1677 if (gen_snapshot_kind == kAppAOT) { | 1623 if (gen_snapshot_kind == kAppAOT) { |
| 1678 GeneratePrecompiledSnapshot(); | 1624 GeneratePrecompiledSnapshot(); |
| 1679 } else { | 1625 } else { |
| 1680 if (Dart_IsNull(root_lib)) { | 1626 if (Dart_IsNull(root_lib)) { |
| 1681 ErrorExit(kErrorExitCode, | 1627 ErrorExit(kErrorExitCode, "Unable to find root library for '%s'\n", |
| 1682 "Unable to find root library for '%s'\n", | |
| 1683 script_name); | 1628 script_name); |
| 1684 } | 1629 } |
| 1685 | 1630 |
| 1686 // The helper function _getMainClosure creates a closure for the main | 1631 // The helper function _getMainClosure creates a closure for the main |
| 1687 // entry point which is either explicitly or implictly exported from the | 1632 // entry point which is either explicitly or implictly exported from the |
| 1688 // root library. | 1633 // root library. |
| 1689 Dart_Handle main_closure = Dart_Invoke(isolate_data->builtin_lib(), | 1634 Dart_Handle main_closure = |
| 1690 Dart_NewStringFromCString("_getMainClosure"), 0, NULL); | 1635 Dart_Invoke(isolate_data->builtin_lib(), |
| 1636 Dart_NewStringFromCString("_getMainClosure"), 0, NULL); |
| 1691 CHECK_RESULT(main_closure); | 1637 CHECK_RESULT(main_closure); |
| 1692 | 1638 |
| 1693 // Call _startIsolate in the isolate library to enable dispatching the | 1639 // Call _startIsolate in the isolate library to enable dispatching the |
| 1694 // initial startup message. | 1640 // initial startup message. |
| 1695 const intptr_t kNumIsolateArgs = 2; | 1641 const intptr_t kNumIsolateArgs = 2; |
| 1696 Dart_Handle isolate_args[kNumIsolateArgs]; | 1642 Dart_Handle isolate_args[kNumIsolateArgs]; |
| 1697 isolate_args[0] = main_closure; // entryPoint | 1643 isolate_args[0] = main_closure; // entryPoint |
| 1698 isolate_args[1] = CreateRuntimeOptions(dart_options); // args | 1644 isolate_args[1] = CreateRuntimeOptions(dart_options); // args |
| 1699 | 1645 |
| 1700 Dart_Handle isolate_lib = | 1646 Dart_Handle isolate_lib = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1730 | 1676 |
| 1731 // Observatory assets are only needed in the regular dart binary. | 1677 // Observatory assets are only needed in the regular dart binary. |
| 1732 #if !defined(DART_PRECOMPILER) && !defined(NO_OBSERVATORY) | 1678 #if !defined(DART_PRECOMPILER) && !defined(NO_OBSERVATORY) |
| 1733 extern unsigned int observatory_assets_archive_len; | 1679 extern unsigned int observatory_assets_archive_len; |
| 1734 extern const uint8_t* observatory_assets_archive; | 1680 extern const uint8_t* observatory_assets_archive; |
| 1735 | 1681 |
| 1736 | 1682 |
| 1737 // |input| is assumed to be a gzipped stream. | 1683 // |input| is assumed to be a gzipped stream. |
| 1738 // This function allocates the output buffer in the C heap and the caller | 1684 // This function allocates the output buffer in the C heap and the caller |
| 1739 // is responsible for freeing it. | 1685 // is responsible for freeing it. |
| 1740 void Decompress(const uint8_t* input, unsigned int input_len, | 1686 void Decompress(const uint8_t* input, |
| 1741 uint8_t** output, unsigned int* output_length) { | 1687 unsigned int input_len, |
| 1688 uint8_t** output, |
| 1689 unsigned int* output_length) { |
| 1742 ASSERT(input != NULL); | 1690 ASSERT(input != NULL); |
| 1743 ASSERT(input_len > 0); | 1691 ASSERT(input_len > 0); |
| 1744 ASSERT(output != NULL); | 1692 ASSERT(output != NULL); |
| 1745 ASSERT(output_length != NULL); | 1693 ASSERT(output_length != NULL); |
| 1746 | 1694 |
| 1747 // Initialize output. | 1695 // Initialize output. |
| 1748 *output = NULL; | 1696 *output = NULL; |
| 1749 *output_length = 0; | 1697 *output_length = 0; |
| 1750 | 1698 |
| 1751 const unsigned int kChunkSize = 256 * 1024; | 1699 const unsigned int kChunkSize = 256 * 1024; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1794 // We're finished decompressing when zlib tells us. | 1742 // We're finished decompressing when zlib tells us. |
| 1795 } while (ret != Z_STREAM_END); | 1743 } while (ret != Z_STREAM_END); |
| 1796 | 1744 |
| 1797 inflateEnd(&strm); | 1745 inflateEnd(&strm); |
| 1798 } | 1746 } |
| 1799 | 1747 |
| 1800 | 1748 |
| 1801 Dart_Handle GetVMServiceAssetsArchiveCallback() { | 1749 Dart_Handle GetVMServiceAssetsArchiveCallback() { |
| 1802 uint8_t* decompressed = NULL; | 1750 uint8_t* decompressed = NULL; |
| 1803 unsigned int decompressed_len = 0; | 1751 unsigned int decompressed_len = 0; |
| 1804 Decompress(observatory_assets_archive, | 1752 Decompress(observatory_assets_archive, observatory_assets_archive_len, |
| 1805 observatory_assets_archive_len, | 1753 &decompressed, &decompressed_len); |
| 1806 &decompressed, | 1754 Dart_Handle tar_file = |
| 1807 &decompressed_len); | 1755 DartUtils::MakeUint8Array(decompressed, decompressed_len); |
| 1808 Dart_Handle tar_file = DartUtils::MakeUint8Array(decompressed, | |
| 1809 decompressed_len); | |
| 1810 // Free decompressed memory as it has been copied into a Dart array. | 1756 // Free decompressed memory as it has been copied into a Dart array. |
| 1811 free(decompressed); | 1757 free(decompressed); |
| 1812 return tar_file; | 1758 return tar_file; |
| 1813 } | 1759 } |
| 1814 #else // !defined(DART_PRECOMPILER) | 1760 #else // !defined(DART_PRECOMPILER) |
| 1815 static Dart_GetVMServiceAssetsArchive GetVMServiceAssetsArchiveCallback = NULL; | 1761 static Dart_GetVMServiceAssetsArchive GetVMServiceAssetsArchiveCallback = NULL; |
| 1816 #endif // !defined(DART_PRECOMPILER) | 1762 #endif // !defined(DART_PRECOMPILER) |
| 1817 | 1763 |
| 1818 | 1764 |
| 1819 void main(int argc, char** argv) { | 1765 void main(int argc, char** argv) { |
| 1820 char* script_name; | 1766 char* script_name; |
| 1821 const int EXTRA_VM_ARGUMENTS = 8; | 1767 const int EXTRA_VM_ARGUMENTS = 8; |
| 1822 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); | 1768 CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS); |
| 1823 CommandLineOptions dart_options(argc); | 1769 CommandLineOptions dart_options(argc); |
| 1824 bool print_flags_seen = false; | 1770 bool print_flags_seen = false; |
| 1825 bool verbose_debug_seen = false; | 1771 bool verbose_debug_seen = false; |
| 1826 | 1772 |
| 1827 vm_options.AddArgument("--no_write_protect_code"); | 1773 vm_options.AddArgument("--no_write_protect_code"); |
| 1828 // Perform platform specific initialization. | 1774 // Perform platform specific initialization. |
| 1829 if (!Platform::Initialize()) { | 1775 if (!Platform::Initialize()) { |
| 1830 Log::PrintErr("Initialization failed\n"); | 1776 Log::PrintErr("Initialization failed\n"); |
| 1831 } | 1777 } |
| 1832 | 1778 |
| 1833 // On Windows, the argv strings are code page encoded and not | 1779 // On Windows, the argv strings are code page encoded and not |
| 1834 // utf8. We need to convert them to utf8. | 1780 // utf8. We need to convert them to utf8. |
| 1835 bool argv_converted = ShellUtils::GetUtf8Argv(argc, argv); | 1781 bool argv_converted = ShellUtils::GetUtf8Argv(argc, argv); |
| 1836 | 1782 |
| 1837 // Parse command line arguments. | 1783 // Parse command line arguments. |
| 1838 if (ParseArguments(argc, | 1784 if (ParseArguments(argc, argv, &vm_options, &script_name, &dart_options, |
| 1839 argv, | 1785 &print_flags_seen, &verbose_debug_seen) < 0) { |
| 1840 &vm_options, | |
| 1841 &script_name, | |
| 1842 &dart_options, | |
| 1843 &print_flags_seen, | |
| 1844 &verbose_debug_seen) < 0) { | |
| 1845 if (help_option) { | 1786 if (help_option) { |
| 1846 PrintUsage(); | 1787 PrintUsage(); |
| 1847 Platform::Exit(0); | 1788 Platform::Exit(0); |
| 1848 } else if (version_option) { | 1789 } else if (version_option) { |
| 1849 PrintVersion(); | 1790 PrintVersion(); |
| 1850 Platform::Exit(0); | 1791 Platform::Exit(0); |
| 1851 } else if (print_flags_seen) { | 1792 } else if (print_flags_seen) { |
| 1852 // Will set the VM flags, print them out and then we exit as no | 1793 // Will set the VM flags, print them out and then we exit as no |
| 1853 // script was specified on the command line. | 1794 // script was specified on the command line. |
| 1854 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1795 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1866 if (!DartUtils::SetOriginalWorkingDirectory()) { | 1807 if (!DartUtils::SetOriginalWorkingDirectory()) { |
| 1867 OSError err; | 1808 OSError err; |
| 1868 fprintf(stderr, "Error determining current directory: %s\n", err.message()); | 1809 fprintf(stderr, "Error determining current directory: %s\n", err.message()); |
| 1869 fflush(stderr); | 1810 fflush(stderr); |
| 1870 Platform::Exit(kErrorExitCode); | 1811 Platform::Exit(kErrorExitCode); |
| 1871 } | 1812 } |
| 1872 | 1813 |
| 1873 const uint8_t* instructions_snapshot = NULL; | 1814 const uint8_t* instructions_snapshot = NULL; |
| 1874 const uint8_t* data_snapshot = NULL; | 1815 const uint8_t* data_snapshot = NULL; |
| 1875 | 1816 |
| 1876 if (ReadAppSnapshot(script_name, | 1817 if (ReadAppSnapshot(script_name, &vm_isolate_snapshot_buffer, |
| 1877 &vm_isolate_snapshot_buffer, | 1818 &isolate_snapshot_buffer, &instructions_snapshot, |
| 1878 &isolate_snapshot_buffer, | |
| 1879 &instructions_snapshot, | |
| 1880 &data_snapshot)) { | 1819 &data_snapshot)) { |
| 1881 run_app_snapshot = true; | 1820 run_app_snapshot = true; |
| 1882 } | 1821 } |
| 1883 | 1822 |
| 1884 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) | 1823 #if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME) |
| 1885 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME. | 1824 // Constant true if PRODUCT or DART_PRECOMPILED_RUNTIME. |
| 1886 if ((gen_snapshot_kind != kNone) || run_app_snapshot) { | 1825 if ((gen_snapshot_kind != kNone) || run_app_snapshot) { |
| 1887 vm_options.AddArgument("--load_deferred_eagerly"); | 1826 vm_options.AddArgument("--load_deferred_eagerly"); |
| 1888 } | 1827 } |
| 1889 #endif | 1828 #endif |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1925 | 1864 |
| 1926 char* error = Dart_Initialize(&init_params); | 1865 char* error = Dart_Initialize(&init_params); |
| 1927 if (error != NULL) { | 1866 if (error != NULL) { |
| 1928 EventHandler::Stop(); | 1867 EventHandler::Stop(); |
| 1929 fprintf(stderr, "VM initialization failed: %s\n", error); | 1868 fprintf(stderr, "VM initialization failed: %s\n", error); |
| 1930 fflush(stderr); | 1869 fflush(stderr); |
| 1931 free(error); | 1870 free(error); |
| 1932 Platform::Exit(kErrorExitCode); | 1871 Platform::Exit(kErrorExitCode); |
| 1933 } | 1872 } |
| 1934 | 1873 |
| 1935 Dart_RegisterIsolateServiceRequestCallback( | 1874 Dart_RegisterIsolateServiceRequestCallback("getIO", &ServiceGetIOHandler, |
| 1936 "getIO", &ServiceGetIOHandler, NULL); | 1875 NULL); |
| 1937 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, | 1876 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, |
| 1938 &ServiceStreamCancelCallback); | 1877 &ServiceStreamCancelCallback); |
| 1939 Dart_SetFileModifiedCallback(&FileModifiedCallback); | 1878 Dart_SetFileModifiedCallback(&FileModifiedCallback); |
| 1940 | 1879 |
| 1941 // Run the main isolate until we aren't told to restart. | 1880 // Run the main isolate until we aren't told to restart. |
| 1942 while (RunMainIsolate(script_name, &dart_options)) { | 1881 while (RunMainIsolate(script_name, &dart_options)) { |
| 1943 Log::PrintErr("Restarting VM\n"); | 1882 Log::PrintErr("Restarting VM\n"); |
| 1944 } | 1883 } |
| 1945 | 1884 |
| 1946 // Terminate process exit-code handler. | 1885 // Terminate process exit-code handler. |
| 1947 Process::TerminateExitCodeHandler(); | 1886 Process::TerminateExitCodeHandler(); |
| 1948 | 1887 |
| 1949 error = Dart_Cleanup(); | 1888 error = Dart_Cleanup(); |
| 1950 if (error != NULL) { | 1889 if (error != NULL) { |
| 1951 Log::PrintErr("VM cleanup failed: %s\n", error); | 1890 Log::PrintErr("VM cleanup failed: %s\n", error); |
| 1952 free(error); | 1891 free(error); |
| 1953 } | 1892 } |
| 1954 EventHandler::Stop(); | 1893 EventHandler::Stop(); |
| 1955 | 1894 |
| 1956 // Free copied argument strings if converted. | 1895 // Free copied argument strings if converted. |
| 1957 if (argv_converted) { | 1896 if (argv_converted) { |
| 1958 for (int i = 0; i < argc; i++) { | 1897 for (int i = 0; i < argc; i++) { |
| 1959 free(argv[i]); | 1898 free(argv[i]); |
| 1960 } | 1899 } |
| 1961 } | 1900 } |
| 1962 | 1901 |
| 1963 // Free environment if any. | 1902 // Free environment if any. |
| 1964 if (environment != NULL) { | 1903 if (environment != NULL) { |
| 1965 for (HashMap::Entry* p = environment->Start(); | 1904 for (HashMap::Entry* p = environment->Start(); p != NULL; |
| 1966 p != NULL; | |
| 1967 p = environment->Next(p)) { | 1905 p = environment->Next(p)) { |
| 1968 free(p->key); | 1906 free(p->key); |
| 1969 free(p->value); | 1907 free(p->value); |
| 1970 } | 1908 } |
| 1971 delete environment; | 1909 delete environment; |
| 1972 } | 1910 } |
| 1973 | 1911 |
| 1974 Platform::Exit(Process::GlobalExitCode()); | 1912 Platform::Exit(Process::GlobalExitCode()); |
| 1975 } | 1913 } |
| 1976 | 1914 |
| 1977 } // namespace bin | 1915 } // namespace bin |
| 1978 } // namespace dart | 1916 } // namespace dart |
| 1979 | 1917 |
| 1980 int main(int argc, char** argv) { | 1918 int main(int argc, char** argv) { |
| 1981 dart::bin::main(argc, argv); | 1919 dart::bin::main(argc, argv); |
| 1982 UNREACHABLE(); | 1920 UNREACHABLE(); |
| 1983 } | 1921 } |
| OLD | NEW |